From 192e0f80bd2da45f1c612411fded2e805ac205de Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 26 May 2008 13:56:30 +0000 Subject: Completed the prefilling of the fields, from the db and pentominos, according to their timestamps. --- server/src/widgetgenerator.cc | 44 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'server/src/widgetgenerator.cc') diff --git a/server/src/widgetgenerator.cc b/server/src/widgetgenerator.cc index 5211188..52752cc 100644 --- a/server/src/widgetgenerator.cc +++ b/server/src/widgetgenerator.cc @@ -31,11 +31,15 @@ static void send_macro_widget(Macro ¯o, TCPSocket &socket, std::string tabs, LUAQueryMapper &mapper, - Database &db) + Values &values) { + std::string prefilled; + time_t timestamp = 0; + socket.write(tabs + "<" + widget.attributes["type"]); std::map< std::string, std::string >::iterator p = widget.attributes.begin(); + // Check if the field has a map, and fill in the value if it has... if(widget.attributes.find("map") != widget.attributes.end()) { std::string luamap; @@ -50,10 +54,22 @@ static void send_macro_widget(Macro ¯o, // printf("LUAMAP: %s\n", luamap.c_str()); fflush(stdout); - if(luamap != "") widget.attributes["value"] = mapper.map(luamap); + if(luamap != "") { + Value value = mapper.map(luamap); + widget.attributes["value"] = value.value; + timestamp = value.timestamp; + prefilled = "pentominos"; + } // widget.attributes.erase(widget.attributes.find("map")); } + // Check if there is a previously stored value in the db... + if(values.find(widget.attributes["name"]) != values.end() && + (prefilled == "" || values[widget.attributes["name"]].timestamp > timestamp)) { + widget.attributes["value"] = values[widget.attributes["name"]].value; + prefilled = "pracro"; + } + while(p != widget.attributes.end()) { if(p->first != "type" && p->first != "map") { socket.write(" " + p->first + "=\"" + p->second + "\""); @@ -61,6 +77,8 @@ static void send_macro_widget(Macro ¯o, p++; } + if(prefilled != "") socket.write(" prefilled=\"" + prefilled + "\""); + if(widget.widgets.size() == 0) { // If node is empty, use short tag form socket.write("/>\n"); return; @@ -70,13 +88,31 @@ static void send_macro_widget(Macro ¯o, std::vector< Widget >::iterator w = widget.widgets.begin(); while(w != widget.widgets.end()) { - send_macro_widget(macro, *w, socket, tabs + " ", mapper, db); + send_macro_widget(macro, *w, socket, tabs + " ", mapper, values); w++; } socket.write(tabs + "\n"); } +static void get_fields(Widget &widget, Fieldnames &fields) +{ + if(widget.attributes.find("value") != widget.attributes.end()) { + fields.push_back(widget.attributes["name"]); + } + + std::vector< Widget >::iterator w = widget.widgets.begin(); + while(w != widget.widgets.end()) { + get_fields(*w, fields); + w++; + } +} + void widgetgenerator(TCPSocket &socket, Macro ¯o, LUAQueryMapper &mapper, Database &db) { - send_macro_widget(macro, macro.window, socket, " ", mapper, db); + Fieldnames fields; + get_fields(macro.window, fields); + + Values values = db.getValues("2003791613", fields); + + send_macro_widget(macro, macro.window, socket, " ", mapper, values); } -- cgit v1.2.3