2 * Description: Manage query updates
3 * Copyright (c) 2012-2013 UPMC Sorbonne Universite - INRIA
12 var Updater = Plugin.extend({
14 init: function(options, element)
16 this._super(options, element);
18 this.listen_query(options.query_uuid);
22 /*************************** PLUGIN EVENTS ****************************/
24 /***************************** GUI EVENTS *****************************/
26 arm_button: function()
28 this.elmt('updater').click(this, this.submit_update_request);
31 submit_update_request: function (e)
35 manifold.raise_event(self.options.query_uuid, RUN_UPDATE);
39 /************************** GUI MANIPULATION **************************/
41 disable_update_button: function()
43 this.elmt('updater').attr('disabled', 'disabled');
46 /*************************** QUERY HANDLER ****************************/
48 /*************************** RECORD HANDLER ***************************/
50 /************************** PRIVATE METHODS ***************************/
52 /******************************** TODO ********************************/
55 query_failed: function (e, code, output)
58 var updater=plugindiv.data('Updater');
59 $('#updater-' + updater.options.plugin_uuid).removeAttr('disabled');
60 // just as a means to deom how to retrieve the stuff passed on the channel
62 messages.debug("retrieved error code " + code + " and output " + output);
65 update_resources: function (e, resources, change)
67 data = e.data.instance.data().Slices;
69 data.update_query.params['resource'] = resources
70 $.publish('/update/' + data.options.query_uuid, [data.update_query, true]);
73 update_leases: function (e, leases, change)
75 data = e.data.instance.data().Slices;
77 data.update_query.params['lease'] = leases
78 $.publish('/update/' + data.options.query_uuid, [data.update_query, true]);
81 query_completed: function (e, rows, query)
84 // This function is called twice : get and update
85 messages.info("updater.query_completed - not implemented yet");
88 var data = e.data.instance.data().Slices;
90 // Update placeholders and trigger subqueries updates
91 if (rows.length == 0) {
98 if (data.update_query == null) {
99 data.update_query = new Query('update','slice', 'now', query.filter, {"resource": null, "lease": null}, query.fields, 0, data.options.query_uuid);
101 // In case of update the list of resources and leases should be updated accordingly
104 $.each(slice, function(key, value) {
105 if (typeof value == 'string') {
106 $('#myslice__' + key).html(value);
110 // TODO avoid repetitions + made this code generic and plugin-independent
112 if (query.method == 'update') {
113 // XXX NON, les uuid doivent etre les memes que dans la query Get, cet appel devrait etre fait avant.
114 query.analyzed_subqueries();
117 // NOTE: Dans le cadre d'un update, on n'a pas besoin de refaire tout
118 // le query plan et obtenir toutes les infos, par contre on ne peut pas
119 // savoir d'avance quels parametres ont été accordés, changés, etc.
120 // Dans le cas général, ca pourrait affecter le query plan...
121 // Par contre on n'a pas d'information sur toutes les resources, mais
122 // uniquement celles dans la liste. Comment gérer ?
124 // Inform child plugins about their respective parts of the results
126 var r_subq = query.analyzed_query.subqueries['resource'];
127 var l_subq = query.analyzed_query.subqueries['lease'];
128 $.publish('/results/' + r_subq.uuid + '/changed', [slice['resource'], r_subq]);
129 $.publish('/results/' + l_subq.uuid + '/changed', [slice['lease'], l_subq]);
131 // Subscribe to get notifications from child plugins
132 if (!data.child_subscribe) {
133 $.subscribe('/update-set/' + r_subq.uuid, {instance: e.data.instance}, update_resources);
134 $.subscribe('/update-set/' + l_subq.uuid, {instance: e.data.instance}, update_leases);
135 data.child_subscribe = true
142 $.plugin('Updater', Updater);