From 928d9b692b74f7ebc2a6abaae24c00d9b2618acf Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 19 Mar 2013 16:41:01 +0100 Subject: [PATCH] renamed plugin.js into metadata.js, rewritten --- README | 2 +- manifold/js/manifold-query.js | 14 ++------ plugins/lists/simplelist.py | 2 +- plugins/querycode/querycode.py | 2 +- plugins/quickfilter/quickfilter.js | 10 +++--- plugins/quickfilter/quickfilter.py | 8 +++-- unfold/js/metadata.js | 53 ++++++++++++++++++++++++++++++ unfold/js/plugin.js | 50 ---------------------------- unfold/page.py | 6 ++-- 9 files changed, 71 insertions(+), 76 deletions(-) create mode 100644 unfold/js/metadata.js delete mode 100644 unfold/js/plugin.js diff --git a/README b/README index 724fa20b..a5d09f1a 100644 --- a/README +++ b/README @@ -104,7 +104,7 @@ I've tried to keep track of the version I picked and to have an easy upgrade pat . urls.py * manifold: - the code for dealing with queries, sending them to the backend, and offering the /manifold/api/ proxy URL + the code for dealing with queries, sending them to the backend, and offering the /manifold/proxy/ URL * unfold: the code for building / rendering plugins diff --git a/manifold/js/manifold-query.js b/manifold/js/manifold-query.js index 09ba089f..4e146ada 100644 --- a/manifold/js/manifold-query.js +++ b/manifold/js/manifold-query.js @@ -1,32 +1,22 @@ function ManifoldQuery(action, method, timestamp, filters, params, fields, unique, query_uuid, aq, sq) { - // get, update, delete, create var action; - - // slice, user, network... : Metadata + // slice, user, network... var method; - // timestamp, now, latest(cache) : date of the results queried var timestamp; - // key(field),op(=<>),value var filters; - // todo var params; - - // hostname, ip,... : Metadata + // hostname, ip,... var fields; - // 0,1 : list of element of an object or single object var unique; - // query_uuid : unique identifier of a query var query_uuid; - // Query : root query (no sub-Query) var analyzed_query; - // {} : Assoc Table of sub-queries ["resources"->subQ1, "users"->subQ2] var subqueries; diff --git a/plugins/lists/simplelist.py b/plugins/lists/simplelist.py index 75c35966..b5a4faf8 100644 --- a/plugins/lists/simplelist.py +++ b/plugins/lists/simplelist.py @@ -21,7 +21,7 @@ class SimpleList (Plugin) : def requirements (self): reqs = { - 'js_files' : [ "js/simplelist.js", "js/plugin.js", + 'js_files' : [ "js/simplelist.js", "js/manifold.js", "js/manifold-query.js", "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", "js/myslice.js", diff --git a/plugins/querycode/querycode.py b/plugins/querycode/querycode.py index 4a6e6b2b..eaa231da 100644 --- a/plugins/querycode/querycode.py +++ b/plugins/querycode/querycode.py @@ -13,7 +13,7 @@ class QueryCode (Plugin): def requirements (self): return { - 'js_files' : [ "js/querycode.js", "js/plugin.js", + 'js_files' : [ "js/querycode.js", "js/manifold.js", "js/manifold-query.js", "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", diff --git a/plugins/quickfilter/quickfilter.js b/plugins/quickfilter/quickfilter.js index f32c0c9e..686b13c9 100644 --- a/plugins/quickfilter/quickfilter.js +++ b/plugins/quickfilter/quickfilter.js @@ -6,7 +6,7 @@ * Copyright (c) 2012 UPMC Sorbonne Universite - INRIA * License: GPLv3 */ - +// global metadata from js/metadata.js ( function($){ var debug=false; @@ -141,7 +141,7 @@ var removed_filters = tmp.removed; $.each(removed_filters, function(i,filter){ console.log(filter[0]); - allowedValues=getMetadata_property('resource', filter[0], 'allowed_values'); + allowedValues=metadata.property('resource', filter[0], 'allowed_values'); if (allowedValues!='' && allowedValues!="N/A") { //if(MANIFOLD_METADATA[filter[0]]['allowed_values']!=''){ $('#QuickFilter_select_field').val("#"); @@ -192,7 +192,7 @@ }); } }else{ - headers=getMetadata_fields('resource'); + headers=metadata.fields('resource'); $.each (headers, function (key, value) { $('#QuickFilter_select_field').append(""); }); @@ -209,10 +209,10 @@ }else{ $('#QuickFilter_select_value_container').show(); $.publish('debug','field selected = '+field); - valType=getMetadata_property('resource', field, 'value_type'); + valType=metadata.property('resource', field, 'value_type'); if (valType == 'string' || valType=="N/A") { // If this key has predefined values, build a select with each allowed values as options - allowedValues=getMetadata_property('resource', field, 'allowed_values'); + allowedValues=metadata.property('resource', field, 'allowed_values'); if (allowedValues!='' && allowedValues!="N/A") { $('#QuickFilter_string_value_div').hide(); $('#QuickFilter_int_value_div').hide(); diff --git a/plugins/quickfilter/quickfilter.py b/plugins/quickfilter/quickfilter.py index cd6ff6ed..9ac95ae1 100644 --- a/plugins/quickfilter/quickfilter.py +++ b/plugins/quickfilter/quickfilter.py @@ -10,9 +10,11 @@ class QuickFilter (Plugin) : def template_file (self): return "quickfilter.html" def requirements (self): - return { 'js_files' : "js/quickfilter.js", - 'css_files': "css/quickfilter.css", - } + return { + 'js_files' : [ "js/quickfilter.js", "js/metadata.js", + ], + 'css_files': "css/quickfilter.css", + } def json_settings_list (self): return ['criterias','plugin_uuid'] diff --git a/unfold/js/metadata.js b/unfold/js/metadata.js new file mode 100644 index 00000000..57940b11 --- /dev/null +++ b/unfold/js/metadata.js @@ -0,0 +1,53 @@ +// MANIFOLD_METADATA was formerly known as all_headers +var metadata = { + get : function () { + return MANIFOLD_METADATA; + }, + // returns all fields of a given method + fields : function (method) { + var result=new Array(); + jQuery.each(MANIFOLD_METADATA, function(m,obj){ + if(m==method){ + jQuery.each(obj['column'], function(i,f){ + result.push(f); + }); + return false; + } + }); + result.sort(sort_by('column', false, function(a){return a.toUpperCase()})); + //result=jQuery(result).sort("column", "asc"); + return result; + }, + // returns all properties of a given field + field : function (method, field) { + var result=new Array(); + jQuery.each(MANIFOLD_METADATA, function(m,obj){ + if(m==method){ + jQuery.each(obj['column'], function(i,f){ + if(f['column']==field){ + result.push(f); + return false; + } + }); + return false; + } + }); + return result[0]; + }, + // returns the value of a property from a field within a method (type of object : resource,node,lease,slice...) + property : function (method, field, property) { + var result=null; + jQuery.each(MANIFOLD_METADATA, function(m,obj){ + if(m==method){ + jQuery.each(obj['column'], function(i,f){ + if(f['column']==field){ + result=f[property]; + return false; + } + }); + return false; + } + }); + return result; + }, +} // metadata object diff --git a/unfold/js/plugin.js b/unfold/js/plugin.js deleted file mode 100644 index 76683d1d..00000000 --- a/unfold/js/plugin.js +++ /dev/null @@ -1,50 +0,0 @@ -function getMetadata(){ - return MANIFOLD_METADATA; -} -// returns all fields of a given method -function getMetadata_fields(method){ - var result=new Array(); - jQuery.each(MANIFOLD_METADATA, function(m,obj){ - if(m==method){ - jQuery.each(obj['column'], function(i,f){ - result.push(f); - }); - return false; - } - }); - result.sort(sort_by('column', false, function(a){return a.toUpperCase()})); - //result=jQuery(result).sort("column", "asc"); - return result; -} -// returns all properties of a given field -function getMetadata_field(method, field){ - var result=new Array(); - jQuery.each(MANIFOLD_METADATA, function(m,obj){ - if(m==method){ - jQuery.each(obj['column'], function(i,f){ - if(f['column']==field){ - result.push(f); - return false; - } - }); - return false; - } - }); - return result[0]; -} -// returns the value of a property from a field within a method (type of object : resource,node,lease,slice...) -function getMetadata_property(method, field, property){ - var result=null; - jQuery.each(MANIFOLD_METADATA, function(m,obj){ - if(m==method){ - jQuery.each(obj['column'], function(i,f){ - if(f['column']==field){ - result=f[property]; - return false; - } - }); - return false; - } - }); - return result; -} diff --git a/unfold/page.py b/unfold/page.py index 157e0046..9c1c4123 100644 --- a/unfold/page.py +++ b/unfold/page.py @@ -98,14 +98,14 @@ class Page: request.session['metadata'] = self._metadata -# javascript = "all_headers=" + json.dumps(self._metadata) + ";" -# self.add_js_chunks(javascript) + javascript = "var MANIFOLD_METADATA =" + json.dumps(self._metadata) + ";" + self.add_js_chunks(javascript) def metadata_get_fields(self, method): return self._metadata[method]['column'].sort() def expose_js_manifold_config (self): - self.add_js_chunks(Config.manifold_js_export()+"\n") + self.add_js_chunks(Config.manifold_js_export()) #################### requirements/prelude management # just forward to self.prelude - see decorator above -- 2.43.0