From: Jordan Augé Date: Thu, 11 Jul 2013 12:48:46 +0000 (+0200) Subject: wip metadata X-Git-Tag: myslice-0.2-1~94 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=4c7212bd04ddb65511c42aac5bae6fc3044cd846 wip metadata --- diff --git a/manifold/js/manifold-query.js b/manifold/js/manifold-query.js index c6ebaabf..77925c4e 100644 --- a/manifold/js/manifold-query.js +++ b/manifold/js/manifold-query.js @@ -99,19 +99,22 @@ INSERT INTO object VALUES(field=value) return {'added':added, 'removed':removed}; } + // Callaback received 3 parameters: query, data, parent_query this.iter_subqueries = function(callback, data) { - rec = function(query, callback, data) { + rec = function(query, callback, data, parent_query) { jQuery.each(query.subqueries, function(object, subquery) { - rec(subquery, callback); + rec(subquery, callback, data, query); }); - callback(query, data); + callback(query, data, parent_query); }; + if (this.analyzed_query !== undefined) query = this.analyzed_query; else - query = this - rec(query, callback, data); + query = this; + + rec(query, callback, data, null); } // we send queries as a json string now diff --git a/manifold/js/manifold.js b/manifold/js/manifold.js index 5c43e71f..94b64428 100644 --- a/manifold/js/manifold.js +++ b/manifold/js/manifold.js @@ -35,12 +35,78 @@ var DONE = 102; var SET_ADD = 201; var SET_REMOVED = 202; +// A structure for storing queries + +function QueryExt(query, parent_query, main_query) { + + /* Constructor */ + if (typeof query == "undefined") + throw "Must pass a query in QueryExt constructor"; + this.query = query + this.parent_query = (typeof parent_query == "undefined") ? false : parent_query + this.main_query = (typeof main_query == "undefined") ? false : main_query + + // How to link to an update query ? they both have the same UUID !! + +} + +function QueryStore() { + + var main_queries = {}; + var analyzed_queries = {}; + + /* Insertion */ + + this.insert = function(query) + { + if (query.analyzed_query == null) { + query.analyze_subqueries(); + } + + query_ext = QueryExt(query, null, null) + manifold.query_store.main_queries[query.query_uuid] = query_ext; + + // We also need to insert all queries and subqueries from the analyzed_query + query.iter_subqueries(function(sq, data, parent_query) { + parent_query_ext = this.find_analyzed_query_ext(parent_query.query_uuid); + sq_ext = QueryExt(sq, parent_query_ext, query_ext) + this.analyzed_queries[sq.query_uuid] = sq_ext; + }); + } + + /* Searching */ + + this.find_query_ext = function(query_uuid) + { + return this.main_queries[query_uuid]; + } + + this.find_query = function(query_uuid) + { + return this.find_query_ext(query_uuid).query; + } + + this.find_analyzed_query_ext = function(query_uuid) + { + return this.analyzed_queries[query_uuid]; + } + + this.find_analyzed_query = function(query_uuid) + { + return this.find_analyzed_query_ext(query_uuid).query; + } +} + /*! * This namespace holds functions for globally managing query objects * \Class Manifold */ var manifold = { + /************************************************************************** + * Helper functions + **************************************************************************/ + spin_presets: {}, spin: function(locator, active /*= true */) { @@ -54,6 +120,14 @@ var manifold = { } catch (err) { messages.debug("Cannot turn spins on/off " + err); } }, + /************************************************************************** + * Query management + **************************************************************************/ + + query_store: QueryStore(), + + // XXX Remaining functions are deprecated since they are replaced by the query store + /*! * Associative array storing the set of queries active on the page * \memberof Manifold @@ -84,6 +158,10 @@ var manifold = { return manifold.all_queries[query_uuid]; }, + /************************************************************************** + * Query execution + **************************************************************************/ + // trigger a query asynchroneously proxy_url : '/manifold/proxy/json/', @@ -160,34 +238,6 @@ var manifold = { return true; }, - raise_event_handler: function(type, query_uuid, event_type, value) - { - if (type == 'query') { - var channels = [ manifold.get_query_channel(query_uuid), manifold.get_query_channel('*') ]; - } else if (type == 'record') { - var channels = [ manifold.get_record_channel(query_uuid), manifold.get_record_channel('*') ]; - - } else { - throw 'Incorrect type for manifold.raise_event()'; - } - $.each(channels, function(i, channel) { - if (value === undefined) - $('.plugin').trigger(channel, [event_type]); - else - $('.plugin').trigger(channel, [event_type, value]); - }); - }, - - raise_query_event: function(query_uuid, event_type, value) - { - manifold.raise_event_handler('query', query_uuid, event_type, value); - }, - - raise_record_event: function(query_uuid, event_type, value) - { - manifold.raise_event_handler('record', query_uuid, event_type, value); - }, - /*! * Publish result * \fn publish_result(query, results) @@ -287,11 +337,48 @@ var manifold = { } }, - raise_event: function(uuid, event_type, value) + /************************************************************************** + * Plugin API helpers + **************************************************************************/ + + raise_event_handler: function(type, query_uuid, event_type, value) + { + if (type == 'query') { + var channels = [ manifold.get_query_channel(query_uuid), manifold.get_query_channel('*') ]; + } else if (type == 'record') { + var channels = [ manifold.get_record_channel(query_uuid), manifold.get_record_channel('*') ]; + + } else { + throw 'Incorrect type for manifold.raise_event()'; + } + $.each(channels, function(i, channel) { + if (value === undefined) + $('.plugin').trigger(channel, [event_type]); + else + $('.plugin').trigger(channel, [event_type, value]); + }); + }, + + raise_query_event: function(query_uuid, event_type, value) + { + manifold.raise_event_handler('query', query_uuid, event_type, value); + }, + + raise_record_event: function(query_uuid, event_type, value) + { + manifold.raise_event_handler('record', query_uuid, event_type, value); + }, + + + raise_event: function(query_uuid, event_type, value) { switch(event_type) { case SET_ADD: // Query uuid has been updated with the key of a new element + query = manifold.find_query(query_uuid); + + // XXX We need to find the parent to update the property + // XXX We need to find the non-analyzed query so that it can be updated also break; case SET_REMOVED: // Query uuid has been updated with the key of a removed element diff --git a/manifold/metadata.py b/manifold/metadata.py index 41a16f31..04f8511f 100644 --- a/manifold/metadata.py +++ b/manifold/metadata.py @@ -32,18 +32,18 @@ class MetaData: 'column.resource_type', 'column.value_type', 'column.allowed_values', 'column.platforms.platform', 'column.platforms.platform_url'] - rows_result = manifold_api.Get({ + result = manifold_api.Get({ 'object': 'local:object', # proposed to replace metadata:table 'fields': fields }) - if row_results['code'] == 1: # warning + if result['code'] == 1: # warning messages.warning(request, result['description']) - elif row_results['code'] == 2: + elif result['code'] == 2: messages.error(request, result['description']) # XXX FAIL HERE XXX - rows = rows_result.ok_value() + rows = result.ok_value() # API errors will be handled by the outer logic # if not rows: # print "Failed to retrieve metadata",rows_result.error()