X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Ftestbeds%2Fstatic%2Fjs%2Ftestbeds.js;h=e21446cfe02117127a44e7ecd47f33f396fd5c13;hb=7e2459e0dc1cef399e9b010d99381e38da5c5556;hp=e424c248468685dd0d1d815cf53114a9fd41a8ef;hpb=94529a211d33decf965c5d20ff709285ff35bf23;p=unfold.git diff --git a/plugins/testbeds/static/js/testbeds.js b/plugins/testbeds/static/js/testbeds.js index e424c248..e21446cf 100644 --- a/plugins/testbeds/static/js/testbeds.js +++ b/plugins/testbeds/static/js/testbeds.js @@ -10,8 +10,61 @@ * License: GPLv3 */ -(function($){ +// XXX Inherit from an AngularPlugin class ? +(function (ng, app) { + + // Define our Controller constructor. + function Controller($scope) { + /* Contructor */ + + /* Plugin instance */ + $scope.instance = null; + + /* Models */ + $scope.testbeds = Array(); + + /* Click event */ + $scope.select = function(testbed) + { + var selected, prev_selected, num, num_selected, num_prev_selected, filter; + + prev_selected = $.map($scope.testbeds, function(x, i) { + return x.active ? x.network_hrn : null; + }); + + testbed.active = !testbed.active; + + selected = $.map($scope.testbeds, function(x, i) { + return x.active ? x.network_hrn : null; + }); + + num = $scope.testbeds.length; + prev_num_selected = prev_selected.length; + num_selected = selected.length; + + + if ((prev_num_selected != 0) && (prev_num_selected != num)) { + // Remove previous filter + filter = ['network_hrn', 'included', prev_selected]; + manifold.raise_event($scope.instance.options.query_uuid, FILTER_REMOVED, filter); + } + if (num_selected != num) { + filter = ['network_hrn', 'included', selected]; + manifold.raise_event($scope.instance.options.query_uuid, FILTER_ADDED, filter); + } + }; + + /* Return object reference */ + return (this); + } + + // Define the Controller as the constructor function. + app.controller("TestbedsCtrl", Controller); + +})(angular, ManifoldApp); + +(function($){ var TestbedsPlugin = Plugin.extend({ /** XXX to check @@ -21,88 +74,129 @@ * @return : a jQuery collection of objects on which the plugin is * applied, which allows to maintain chainability of calls */ - init: function(options, element) { - // for debugging tools - this.classname="testbedsplugin"; + init: function(options, element) + { // Call the parent constructor, see FAQ when forgotten this._super(options, element); /* Member variables */ + this.filters = Array(); + this.testbeds = Array(); - /* Plugin events */ - - /* Setup query and record handlers */ + this._get_scope().instance = this; - // Explain this will allow query events to be handled - // What happens when we don't define some events ? - // Some can be less efficient + /* Handlers */ this.listen_query(options.query_uuid); - this.listen_query(options.query_all_uuid, 'all'); - this.listen_query(options.query_network_uuid, 'network'); - - /* GUI setup and event binding */ - // call function - + this.listen_query(options.query_networks_uuid, 'networks'); }, - /* PLUGIN EVENTS */ - // on_show like in querytable - - /* GUI EVENTS */ + /* HANDLERS */ - // a function to bind events here: click change - // how to raise manifold events - - - /* GUI MANIPULATION */ - - // We advise you to write function to change behaviour of the GUI - // Will use naming helpers to access content _inside_ the plugin - // always refer to these functions in the remaining of the code - - show_hide_button: function() + /* When a filter is added/removed, update the list of filters local to the plugin */ + on_filter_added: function(filter) { - // this.id, this.el, this.cl, this.elts - // same output as a jquery selector with some guarantees + this.filters.push(filter); + if(filter[0]=='network_hrn'){ + if(filter[1]=='included'){ + $.each(filter[2], function(value){ + $("#testbeds-filter_"+value).addClass("active"); + }); + }else if(filter[1]=='=' || filter[1]=='=='){ + $("#testbeds-filter_"+filter[2]).addClass("active"); + } + // XXX NAMING + // XXX How to display unsupported filters + // XXX Constants for operators + } + }, + on_filter_removed: function(filter) + { + this.filters = $.grep(this.filters, function(x) { + return x == filter; + }); + if(filter[0]=='network_hrn'){ + if(filter[1]=='included'){ + $.each(filter[2], function(value){ + $("#testbeds-filter_"+value).removeClass("active"); + }); + }else if(filter[1]=='=' || filter[1]=='=='){ + $("#testbeds-filter_"+filter[2]).removeClass("active"); + } + } }, - /* TEMPLATES */ - - // see in the html template - // How to load a template, use of mustache - - /* QUERY HANDLERS */ + // ... be sure to list all events here - // How to make sure the plugin is not desynchronized - // He should manifest its interest in filters, fields or records - // functions triggered only if the proper listen is done + on_networks_query_done: function() + { + this.set_networks(); + }, - // no prefix + /* INTERNAL FUNCTIONS */ - on_filter_added: function(filter) + set_networks: function() { - + var scope = this._get_scope(); + var query_ext = manifold.query_store.find_analyzed_query_ext(this.options.query_networks_uuid); + scope.testbeds = query_ext.records.values(); + $.each(scope.testbeds, function(i, testbed) { testbed.active = true }); + scope.$apply(); }, - // ... be sure to list all events here - - /* RECORD HANDLERS */ - on_network_new_record: function(record) + _get_scope : function() { - console.log(record); - row = ''; - row += ''+record["platform"]+''; - //row += ''+record["network_hrn"]+''; - row += '

'+record["network_hrn"]+'

'; - $('#testbeds-filter').append(row); + return angular.element('[ng-controller=TestbedsCtrl]').scope() }, - /* INTERNAL FUNCTIONS */ - _dummy: function() { - // only convention, not strictly enforced at the moment +/* + _addFilter: function(key, op, value) + { + values = Array(); + // get the previous list of values for this key, ex: [ple,nitos] + // remove the previous filter + network_filter = $.grep(this.filters, function(x) { + return x[0] == "network_hrn"; + }); + if(network_filter.length > 0){ + $.each(network_filter, function(i,f){ + values = f[2]; + }); + } + // Add the new value to list of values, ex: wilab + values.push(value); + + // Update the filter with the new list of values, ex: [ple,nitos,wilab] + manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]); }, + _removeFilter: function(key, op, value) + { + console.log("remove "+value); + var self = this; + values = Array(); + // get the previous list of values for this key, ex: [ple,nitos,wilab] + // remove the previous filter + network_filter = $.grep(this.filters, function(x) { + return x[0] == "network_hrn"; + }); + if(network_filter.length > 0){ + $.each(network_filter, function(i,f){ + values = f[2]; + manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, [key, op, values]); + }); + } + + // remove the value from the list of values, ex: wilab + values = $.grep(values, function(x) { + return x != value; + }); + if(values.length>0){ + // Update the filter with the new list of values, ex: [ple,nitos] + manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]); + } + } +*/ }); /* Plugin registration */