From: Malte S. <mal...@co...> - 2011-05-14 07:18:04
|
Hi Frank, please find attached the code which takes a SQL generated e.g. by im_timesheet_component and makes a Hierarchical JSON out of it. This is needed as well as we not only deal with the flat json data stores but also hierachical ones. And as timesheet tasks and projects, which are hierarchical are high on your todo list for sencha, I thought I give you a headstart. Best wishes Malte P.S.: Are you using the OpenACS JSON procs or did you build your own stuff? # We ignore view_name and table_header as we don't bother with # this. We only want to get the variables into json :-). db_multirow task_list_multirow task_list_sql $sql { # Perform the following steps in addition to calculating the multirow: # The list of all projects set all_projects_hash($child_project_id) 1 # The list of projects that have a sub-project set parents_hash($child_parent_id) 1 } # Store results in hash array for faster join # Only store positive "closed" branches in the hash to save space+time. # Determine the sub-projects that are also closed. set user_id [ad_get_user_id] set oc_sub_sql " select child.project_id as child_id from im_projects child, im_projects parent where parent.project_id in ( select ohs.object_id from im_biz_object_tree_status ohs where ohs.open_p = 'c' and ohs.user_id = :user_id and ohs.page_url = 'default' and ohs.object_id in ( select child_project_id from ($sql) p ) ) and child.tree_sortkey between parent.tree_sortkey and tree_right(parent.tree_sortkey) " db_foreach oc_sub $oc_sub_sql { set closed_projects_hash($child_id) 1 } # Calculate the list of leaf projects set all_projects_list [array names all_projects_hash] set parents_list [array names parents_hash] set leafs_list [set_difference $all_projects_list $parents_list] foreach leaf_id $leafs_list { set leafs_hash($leaf_id) 1 } set parents [list] template::multirow foreach task_list_multirow { set variable_list($child_project_id) [list task $task_name duration $planned_units_subtotal user $project_lead] if {[info exists leafs_hash($child_project_id)]} { # This is a leave, set the json object set leaf_list [list iconCls "task" leaf "true"] set json_list [concat $variable_list($child_project_id) $leaf_list] regsub -all "\"" $json_list {\"} json_list set json_object($child_project_id) [util::json::object::create $json_list] } else { # create a parents list which is buttom up, so we can go # through this list and correctly build the json arrays set parents [concat $child_project_id $parents] } if {$child_parent_id ne ""} { # Add the leave to the parent list lappend children($child_parent_id) $child_project_id } } ds_comment "Parents:: $parents" foreach parent $parents { # build the json array # Build the children set json_objects [list] foreach child $children($parent) { lappend json_objects $json_object($child) } set json_array(children) [util::json::array::create $json_objects] # build the own entry set json_array(inconCls) "task-folder" if {![info exists closed_projects_hash($parent)]} { set json_array(expanded) "true" } set json_list [concat $variable_list($parent) [array get json_array]] set json_object($parent) [util::json::object::create $json_list] array unset json_array # Set the top_id to the parent so we can figure out what is # actually the last and therefore topmost json_object set top_id $parent } ds_comment "JSON:: $json_object($top_id)" ns_return 200 text/text [util::json::gen $json_object($top_id)] ad_script_abort } Am 13.05.2011 um 11:36 schrieb Frank Bergmann: > Hi Malte, > > Yes, the code is committed in intranet-rest and intranet-sencha in HEAD. > Please see below for a screenshot with the first JSON data coming out of intranet-rest. > However, I'm still actively developing, so intranet-rest is highly unstable right now. > > The idea is to define a "proxy" for a Sencha data store like the one below > (taken from intranet-sencha/www/rest-proxy-example.adp) and leave everything else > to Sencha: > > proxy: { > type: 'rest', > url: '/intranet-rest/user', > appendId: true, > extraParams: {format: 'json', format_variant: 'sencha'}, > reader: { > type: 'json', > root: 'data' > }, > writer: { > type: 'json' > } > }, > > Btw., I believe I've found a solution to work around the ns_conn issue with a PUT HTTP request. > > Cheers! > Frank > > <Outlook.jpg> > > -----Ursprüngliche Nachricht----- > Von: Malte Sussdorff [mailto:mal...@co...] > Gesendet: Freitag, 13. Mai 2011 08:10 > An: Frank Bergmann > Betreff: Re: [ns_conn user_id] doesn't work with HTTP "PUT" verb? > > Moin Frank, > > ich weiß nicht ob AOLserver bei PUT calls eine connection_id hat. Aber da kann ich leider wirklich nicht weiter helfen :). > > Ansonsten die Nachfrage ob Du auch ordentliches JSON zurück lieferst für Hierarchische Objekte? > > Ganz liebe Grüße > Malte > > P.S.: Ist der Kram committed ? > > Am 12.05.2011 um 21:42 schrieb Frank Bergmann: > > > Hi Malte, > > > > hast Du 'ne Ahnung? > > http://www.openacs.org/forums/message-view?message_id=3627857 > > > > > > Best regards > > Frank > > > > --- > > Frank Bergmann > > Dipl.-Ing., MBA > > Founder ]project-open[ > > Tel: +34 933 250 914 > > Cell: +34 609 953 751 > > Fax: +34 932 890 729 > > mailto:fra...@pr... > > http://www.project-open.com/ > > > > -- > > Malte Sussdorff > > cognovís GmbH > Schrödersweg 27 > D-22453 Hamburg > Mobil: +49 (0)151 / 230 33 826 > Fon: +49 (0)40 / 386 60 521 > Fax: +49 (0)40 / 386 60 523 > www.cognovis.de > > -- Malte Sussdorff cognovís GmbH Schrödersweg 27 D-22453 Hamburg Mobil: +49 (0)151 / 230 33 826 Fon: +49 (0)40 / 386 60 521 Fax: +49 (0)40 / 386 60 523 www.cognovis.de HRB Hamburg 28909 Geschäftsführer: Malte Sussdorff Diese Nachricht ist streng vertraulich und enthält rechtlich geschützte Informationen. Sie ist nur für die Adressaten bestimmt. Falls Sie diese Mail fälschlicherweise erhalten haben, bitten wir Sie freundlicherweise uns umgehend telefonisch oder per E-Mail zu informieren und den Inhalt dieser Nachricht in Ihrem System zu löschen. Diese Nachricht ist anfällig für Datenkorruption, Abfangen von Daten, nicht autorisierte Änderungen, Verfälschung und Viren. Wir senden und empfangen E-Mails nur auf der Grundlage, dass wir nicht für solche Datenkorruption, Abfangen von Daten, nicht autorisierte Änderungen, Verfälschung und Viren und deren Konsequenzen haften. This e-mail is confidential and may contain legally privileged information. It is intended only for the addressees. If you have received this e-mail in error, kindly notify us immediately by telephone or e-mail and delete the message from your system. E-Mail is susceptible to data corruption, interception, unauthorised amendment, tampering and viruses, and we only send and receive e-mails on the basis that we are not liable for any such corruption, interception, unauthorised amendment, tampering and viruses or any consequences thereof. |