X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fupdater%2Fupdater.js;h=b28a05bf5ded2078a82759db69b028bf97c1631a;hb=d8f20800f3709f4958493d2e1e1f8a8a98b0e29a;hp=8102c4d6070fb18fbd83f755db1bd4d6dac1ae4b;hpb=d1562e0ec66c4b185d47037310dca3f6c2b91455;p=myslice.git diff --git a/plugins/updater/updater.js b/plugins/updater/updater.js index 8102c4d6..b28a05bf 100644 --- a/plugins/updater/updater.js +++ b/plugins/updater/updater.js @@ -28,7 +28,6 @@ /* Subscribe to query updates */ var results_channel = '/results/' + options.query_uuid + '/changed'; $.subscribe(results_channel, function (e,rows) { updater.update_slice (e,rows); } ); - updater.arm_button(); }); }, destroy : function( ) { @@ -52,99 +51,104 @@ // implementation wouldn't fly // we keep this for a later improvement var query=manifold.find_query (options.query_uuid); + messages.info("retrieved query " + query.__repr()); // very rough way of filling this for now this.update_query = new ManifoldQuery ("update", query.subject, null, query.filters, {}, // params query.fields, undefined, /* unique */ - query.query_uuid, /* tmp */ + Math.uuid(32,16), undefined, undefined /* maybe some day I'll get that one */); + manifold.insert_query (this.update_query); + // arm button once document is loaded + (function(updater) {$(document).ready(function(){updater.arm_button()})})(this); this.arm_button = function () { $('#updater-' + this.options.plugin_uuid).click(this, this.submit_update_request); }, this.submit_update_request = function (e) { + messages.debug("submit_update_request"); + var query_uuid = e.data.options.query_uuid; var update_query = e.data.update_query; - $.publish("messages:debug","Updater.submit_update_request " + update_query.__repr()); - // xxx here - we need a valid query_uuid so the results will make it - manifold.asynchroneous_exec ( [ {'query_uuid': xxx, 'id': null}]); + messages.debug("Updater.submit_update_request " + update_query.__repr()); + // actually send the Update query, but publish results as if coming from the original query + manifold.asynchroneous_exec ( [ {'query_uuid': update_query.query_uuid, 'publish_uuid' : query_uuid} ]); // looks like a previous attempt to disable the button while the query is flying //$('#updateslice-' + options.plugin_uuid).prop('disabled', true); - } - }; + }, - /* Private methods */ + update_resources = function (e, resources, change) { + data = e.data.instance.data().Slices; - function update_resources(e, resources, change) { - data = e.data.instance.data().Slices; - - data.update_query.params['resource'] = resources - $.publish('/update/' + data.options.query_uuid, [data.update_query, true]); - } + data.update_query.params['resource'] = resources + $.publish('/update/' + data.options.query_uuid, [data.update_query, true]); + }, - function update_leases(e, leases, change) { - data = e.data.instance.data().Slices; - - data.update_query.params['lease'] = leases - $.publish('/update/' + data.options.query_uuid, [data.update_query, true]); - } + update_leases = function (e, leases, change) { + data = e.data.instance.data().Slices; + + data.update_query.params['lease'] = leases + $.publish('/update/' + data.options.query_uuid, [data.update_query, true]); + }, - function update_slice(e, rows, query) { - /* This function is called twice : get and update */ - - var data = e.data.instance.data().Slices; + update_slice = function (e, rows, query) { + + /* This function is called twice : get and update */ + - /* Update placeholders and trigger subqueries updates */ - if (rows.length == 0) { - alert("no result"); - return; - } - var slice = rows[0]; + var data = e.data.instance.data().Slices; - /* for get */ - if (data.update_query == null) { - data.update_query = new Query('update','slice', 'now', query.filter, {"resource": null, "lease": null}, query.fields, 0, data.options.query_uuid); - } - /* In case of update the list of resources and leases should be updated accordingly */ + /* Update placeholders and trigger subqueries updates */ + if (rows.length == 0) { + alert("no result"); + return; + } + var slice = rows[0]; - /* only for get ? */ - $.each(slice, function(key, value) { - if (typeof value == 'string') { - $('#myslice__' + key).html(value); - } - }); + /* for get */ + if (data.update_query == null) { + data.update_query = new Query('update','slice', 'now', query.filter, {"resource": null, "lease": null}, query.fields, 0, data.options.query_uuid); + } + /* In case of update the list of resources and leases should be updated accordingly */ - /* TODO avoid repetitions + made this code generic and plugin-independent */ + /* only for get ? */ + $.each(slice, function(key, value) { + if (typeof value == 'string') { + $('#myslice__' + key).html(value); + } + }); - if (query.method == 'update') { - // XXX NON, les uuid doivent etre les memes que dans la query Get, cet appel devrait etre fait avant. - query.analyzed_subqueries(); - } + /* TODO avoid repetitions + made this code generic and plugin-independent */ + + if (query.method == 'update') { + // XXX NON, les uuid doivent etre les memes que dans la query Get, cet appel devrait etre fait avant. + query.analyzed_subqueries(); + } - /* NOTE: Dans le cadre d'un update, on n'a pas besoin de refaire tout - * le query plan et obtenir toutes les infos, par contre on ne peut pas - * savoir d'avance quels parametres ont été accordés, changés, etc. - * Dans le cas général, ca pourrait affecter le query plan... - * Par contre on n'a pas d'information sur toutes les resources, mais - * uniquement celles dans la liste. Comment gérer ? - */ - - /* Inform child plugins about their respective parts of the results */ - /* Only for get */ - var r_subq = query.analyzed_query.subqueries['resource']; - var l_subq = query.analyzed_query.subqueries['lease']; - $.publish('/results/' + r_subq.uuid + '/changed', [slice['resource'], r_subq]); - $.publish('/results/' + l_subq.uuid + '/changed', [slice['lease'], l_subq]); - - /* Subscribe to get notifications from child plugins */ - if (!data.child_subscribe) { - $.subscribe('/update-set/' + r_subq.uuid, {instance: e.data.instance}, update_resources); - $.subscribe('/update-set/' + l_subq.uuid, {instance: e.data.instance}, update_leases); - data.child_subscribe = true - } - + /* NOTE: Dans le cadre d'un update, on n'a pas besoin de refaire tout + * le query plan et obtenir toutes les infos, par contre on ne peut pas + * savoir d'avance quels parametres ont été accordés, changés, etc. + * Dans le cas général, ca pourrait affecter le query plan... + * Par contre on n'a pas d'information sur toutes les resources, mais + * uniquement celles dans la liste. Comment gérer ? + */ + + /* Inform child plugins about their respective parts of the results */ + /* Only for get */ + var r_subq = query.analyzed_query.subqueries['resource']; + var l_subq = query.analyzed_query.subqueries['lease']; + $.publish('/results/' + r_subq.uuid + '/changed', [slice['resource'], r_subq]); + $.publish('/results/' + l_subq.uuid + '/changed', [slice['lease'], l_subq]); + + /* Subscribe to get notifications from child plugins */ + if (!data.child_subscribe) { + $.subscribe('/update-set/' + r_subq.uuid, {instance: e.data.instance}, update_resources); + $.subscribe('/update-set/' + l_subq.uuid, {instance: e.data.instance}, update_leases); + data.child_subscribe = true + } + + } } - })( jQuery );