import js files from joomla as is
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 4 Mar 2013 14:10:54 +0000 (15:10 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 4 Mar 2013 14:10:54 +0000 (15:10 +0100)
engine/static/js/plugin.js [new file with mode: 0644]
engine/static/js/query.js [new file with mode: 0644]
plugins/static/js/simplelist.js

diff --git a/engine/static/js/plugin.js b/engine/static/js/plugin.js
new file mode 100644 (file)
index 0000000..0a8bd44
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * This file is included in includes/js_libraries.php
+ */
+
+function getMetadata(){
+    return all_headers;
+}
+// returns all fields of a given method
+function getMetadata_fields(method){
+    var result=new Array();
+    jQuery.each(all_headers, 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){
+    //console.log(all_headers);
+    var result=new Array();
+    jQuery.each(all_headers, 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){
+    //console.log(all_headers);
+    var result=null;
+    jQuery.each(all_headers, 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;
+    //all_headers[method]['column']
+    //[field][]
+}
diff --git a/engine/static/js/query.js b/engine/static/js/query.js
new file mode 100644 (file)
index 0000000..dc58cb7
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * This file is included in tophat_render.php
+ */
+
+function Query(action, method, ts, filter, params, fields, unique, uuid, aq, sq)
+{  
+    // get, update, delete, create
+    var action;
+    
+    // slice, user, network... : Metadata
+    var method; 
+    
+    // timestamp, now, latest(cache) : date of the results queried    
+    var ts;
+    
+    // key(field),op(=<>),value
+    var filter;
+
+    // todo
+    var params;
+    
+    // hostname, ip,... : Metadata
+    var fields;
+    
+    // 0,1 : list of element of an object or single object  
+    var unique;
+    
+    // uuid : unique identifier of a query
+    var uuid;
+    
+    // Query : root query (no sub-Query)
+    var analyzed_query;
+    
+    // {} : Assoc Table of sub-queries ["resources"->subQ1, "users"->subQ2]
+    var subqueries;
+
+/*-------------------------------------------------------------
+              Query properties are SQL like : 
+---------------------------------------------------------------
+SELECT fields FROM method WHERE filter;
+UPDATE method SET field=value WHERE filter; / returns SELECT 
+DELETE FROM method WHERE filter
+INSERT INTO method VALUES(field=value)
+-------------------------------------------------------------*/
+    
+    this.clone = function() {
+        q = new Query();
+        return jQuery.extend(true, q, this);
+    }
+    this.add_filter = function(key, op, value) {
+        this.filter.push(new Array(key, op, value));
+    }
+    this.update_filter = function(key, op, value) {
+        // Need to be improved...
+        // remove all occurrences of key if operation is not defined
+        if(!op){
+            this.filter = jQuery.grep(this.filter, function(val, i) {
+                return val[0] != key; 
+            });
+        // Else remove the key+op filter
+        }else{
+            this.filter = jQuery.grep(this.filter, function(val, i) {return (val[0] != key || val[1] != op);});
+        }
+        this.filter.push(new Array(key, op, value));
+    }
+    this.remove_filter = function (key,op,value){
+        // if operator is null then remove all occurences of this key
+        if(!op){
+            this.filter = jQuery.grep(this.filter, function(val, i) { 
+                return val[0] != key; 
+            });
+        }else{
+            this.filter = jQuery.grep(this.filter, function(val, i) {return (val[0] != key || val[1] != op);});
+        }
+    }
+    // FIXME These functions computing diff's between queries are meant to be shared
+    this.diff_fields = function (otherQuery)
+    {
+        var f1 = this.fields;
+        var f2 = otherQuery.fields;
+
+        /* added elements are the ones in f2 not in f1 */
+        var added   = jQuery.grep(f2, function (x) { return jQuery.inArray(x, f1) == -1 }); 
+        /* removed elements are the ones in f1 not in f2 */
+        var removed = jQuery.grep(f1, function (x) { return jQuery.inArray(x, f2) == -1 }); 
+        
+        return {'added':added, 'removed':removed};
+    }    
+    // FIXME Modify filter to filters
+    this.diff_filter = function (otherQuery)
+    {
+        var f1 = this.filter;
+        var f2 = otherQuery.filter;
+        
+        /* added elements are the ones in f2 not in f1 */
+        var added   = jQuery.grep(f2, function (x) { return !arrayInArray(x, f1)}); 
+        /* removed elements are the ones in f1 not in f2 */
+        var removed = jQuery.grep(f1, function (x) { return !arrayInArray(x, f2)}); 
+        
+        return {'added':added, 'removed':removed};
+    } 
+    this.to_hash = function() {
+        return {'action': this.action, 'method': this.method, 'ts': this.ts, 'filters': this.filter, 'params': this.params, 'fields': this.fields};
+    }
+
+    this.analyze_subqueries = function() {
+        /* adapted from the PHP function in com_tophat/includes/query.php */
+        var q = new Query();
+        q.uuid = this.uuid;
+        q.action = this.action;
+        q.method = this.method;
+        q.ts = this.ts;
+
+        /* Filters */
+        jQuery.each(this.filters, function(i, filter) {
+            var k = filter[0];
+            var op = filter[1];
+            var v = filter[2];
+            var pos = k.indexOf('.');
+            if (pos != -1) {
+                var method = k.substr(0, pos);
+                var field = k.substr(pos+1);
+                if (jQuery.inArray(this.method, q.subqueries) == -1) {
+                    q.subqueries[this.method] = new Query();
+                    q.subqueries[this.method].action = this.action;
+                    q.subqueries[this.method].method = this.method;
+                    q.subqueries[this.method].ts = this.ts;
+                }
+                q.subqueries[this.method].filters.push(Array(field, op, v));
+            } else {
+                q.filters.push(this.filter);
+            }
+        });
+
+        /* Params */
+        jQuery.each(this.params, function(param, value) {
+            var pos = param.indexOf('.');
+            if (pos != -1) {
+                var method = param.substr(0, pos);
+                var field = param.substr(pos+1);
+                if (jQuery.inArray(this.method, q.subqueries) == -1) {
+                    q.subqueries[this.method] = new Query();
+                    q.subqueries[this.method].action = this.action;
+                    q.subqueries[this.method].method = this.method;
+                    q.subqueries[this.method].ts = this.ts;
+                }
+                q.subqueries[this.method].params[field] = value;
+            } else {
+                q.params[field] = value;
+            }
+        });
+
+        /* Fields */
+        jQuery.each(this.fields, function(i, v) {
+            var pos = v.indexOf('.');
+            if (pos != -1) {
+                var method = v.substr(0, pos);
+                var field = v.substr(pos+1);
+                if (jQuery.inArray(this.method, q.subqueries) == -1) {
+                    q.subqueries[this.method] = new Query();
+                    q.subqueries[this.method].action = this.action;
+                    q.subqueries[this.method].method = this.method;
+                    q.subqueries[this.method].ts = this.ts;
+                }
+                q.subqueries[this.method].fields.push(field);
+            } else {
+                q.fields.push(v);
+            }
+        });
+        this.analyzed_query = q;
+    }
+    /* constructor */
+    this.action = action;
+    this.method = method;
+    this.ts = ts;
+    this.filter = filter;
+    this.params = params;
+    this.fields = fields;
+    this.unique = unique;
+    this.uuid = uuid;
+    this.analyzed_query = aq;
+    this.subqueries = sq;
+}  
index 282f6b8..b916d11 100644 (file)
@@ -1 +1,136 @@
-/* simplelist.js */
+/**
+ * MySlice SimpleList plugin
+ * Version: 0.1.0
+ * URL: http://www.myslice.info
+ * Description: Google maps display of geolocated data
+ * Requires: 
+ * Author: The MySlice Team
+ * Copyright: Copyright 2012 UPMC Sorbonne Universités
+ * License: GPLv3
+ */
+
+(function(jQuery){
+
+  var methods = {
+     init : function( options ) {
+
+       return this.each(function(){
+         
+         var $this = jQuery(this),
+             data = $this.data('SimpleList'), SimpleList = jQuery('<div />', { text : $this.attr('title') });
+         
+         // If the plugin hasn't been initialized yet
+         if ( ! data ) {
+         
+            /* Plugin initialization */
+
+            /* Subscribe to query updates */
+            jQuery.subscribe('/results/' + options.query_uuid + '/changed', {instance: $this}, update_list);
+
+            /* End of plugin initialization */
+
+            $this.data('SimpleList', {
+                options: options,
+                target : $this,
+                SimpleList : SimpleList
+            });
+
+         }
+       });
+     },
+    destroy : function( ) {
+
+        return this.each(function(){
+            var $this = jQuery(this), data = $this.data('SimpleList');
+            jQuery(window).unbind('SimpleList');
+            data.SimpleList.remove();
+            $this.removeData('SimpleList');
+        })
+
+    },
+/*
+    reposition : function( ) { // ... },
+    show : function( ) { // ... },
+    hide : function( ) { // ... },
+*/
+    update : function( content ) { }
+  };
+
+    jQuery.fn.SimpleList = function( method ) {
+        /* Method calling logic */
+        if ( methods[method] ) {
+            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
+        } else if ( typeof method === 'object' || ! method ) {
+            return methods.init.apply( this, arguments );
+        } else {
+            jQuery.error( 'Method ' +  method + ' does not exist on jQuery.SimpleList' );
+        }    
+
+    };
+
+    /* Private methods */
+
+    function update_list(e, rows)
+    {
+        if (rows.length == 0) {
+            e.data.instance.html('No result !');
+            return;
+        }
+        if (typeof rows[0].error != 'undefined') {
+            e.data.instance.html('ERROR: ' + rows[0].error);
+            return;
+        }
+        options = e.data.instance.data().SimpleList.options;
+        is_cached = options.query.ts != 'now' ? true : false;
+        e.data.instance.html(myslice_html_ul(rows, options.key, options.value, is_cached)+"<br/>");
+        
+    }
+
+    function myslice_html_li(type, value, is_cached) {
+        var cached = '';
+        //if (is_cached)
+        //    cached='<div class="cache"><span><b>Cached information from the database</b><br/>Timestamp: XX/XX/XX XX:XX:XX<br/><br/><i>Refresh in progress...</i></span></div>';
+        if (type == 'slice_hrn') {
+            return "<li class='icn icn-play'><a href='/view/slice/" + value + "'>" + value + cached + "</a></li>";
+        } else if (type == 'network_hrn') {
+            return "<li class='icn icn-play'>" + value + cached + "</li>";
+        } else {
+            return "<li>" + value + "</li>";
+        }
+    }
+
+
+    function myslice_html_ul(data, key, value, is_cached) {
+        var out = "<ul>";
+        for (var i = 0; i < data.length; i++) {
+            out += myslice_html_li(key, data[i][value], is_cached);
+            //out += myslice_html_li(key, myslice_html_a(data[i][key], data[i][value], key), is_cached);
+        }
+        out += "</ul>";
+
+        return out;
+    }
+
+    /*
+    function myslice_async_render_list(data, key, value, is_cached) {
+        // we suppose we only have one column, or we need more precisions
+        var col = [];
+        if (myslice_array_size(data[0]) == 1) {
+            for (var k in data[0]) {
+                key = k;
+                value = k;
+            }
+        } else {
+            for (var k in data[0]) {
+                if (k.substr(-4) == '_hrn') {
+                    key = k;
+                } else {
+                    value = k;
+                }
+            }
+        }
+        return myslice_html_ul(data, key, value, is_cached);
+    }
+    */
+
+})( jQuery );