2 * TestbedsPlugin: List of testbeds plugin
4 * Description: TODO -> generalize to a list of possible filters
5 * This file is part of the Manifold project
6 * Requires: js/plugin.js
7 * URL: http://www.myslice.info
8 * Author: Loïc Baron <loic.baron@lip6.fr>
9 * Copyright: Copyright 2012-2013 UPMC Sorbonne Universités
13 // XXX Inherit from an AngularPlugin class ?
16 // Define our Controller constructor.
17 function Controller($scope) {
21 $scope.instance = null;
24 $scope.testbeds = Array();
27 $scope.select = function(testbed)
29 var selected, prev_selected, num, num_selected, num_prev_selected, filter;
31 prev_selected = $.map($scope.testbeds, function(x, i) {
32 return x.active ? x.network_hrn : null;
35 testbed.active = !testbed.active;
37 selected = $.map($scope.testbeds, function(x, i) {
38 return x.active ? x.network_hrn : null;
41 num = $scope.testbeds.length;
42 prev_num_selected = prev_selected.length;
43 num_selected = selected.length;
46 if ((prev_num_selected != 0) && (prev_num_selected != num)) {
47 // Remove previous filter
48 filter = ['network_hrn', 'included', prev_selected];
49 manifold.raise_event($scope.instance.options.query_uuid, FILTER_REMOVED, filter);
52 if (num_selected != num) {
53 filter = ['network_hrn', 'included', selected];
54 manifold.raise_event($scope.instance.options.query_uuid, FILTER_ADDED, filter);
58 /* Return object reference */
62 // Define the Controller as the constructor function.
63 app.controller("TestbedsCtrl", Controller);
65 })(angular, ManifoldApp);
68 var TestbedsPlugin = Plugin.extend({
71 * @brief Plugin constructor
72 * @param options : an associative array of setting values
74 * @return : a jQuery collection of objects on which the plugin is
75 * applied, which allows to maintain chainability of calls
77 init: function(options, element)
79 // Call the parent constructor, see FAQ when forgotten
80 this._super(options, element);
82 /* Member variables */
83 this.filters = Array();
84 this.testbeds = Array();
86 this._get_scope().instance = this;
89 this.listen_query(options.query_uuid);
90 this.listen_query(options.query_networks_uuid, 'networks');
96 /* When a filter is added/removed, update the list of filters local to the plugin */
97 on_filter_added: function(filter)
99 this.filters.push(filter);
100 if(filter[0]=='network_hrn'){
101 if(filter[1]=='included'){
102 $.each(filter[2], function(value){
103 $("#testbeds-filter_"+value).addClass("active");
105 }else if(filter[1]=='=' || filter[1]=='=='){
106 $("#testbeds-filter_"+filter[2]).addClass("active");
109 // XXX How to display unsupported filters
110 // XXX Constants for operators
113 on_filter_removed: function(filter)
115 this.filters = $.grep(this.filters, function(x) {
118 if(filter[0]=='network_hrn'){
119 if(filter[1]=='included'){
120 $.each(filter[2], function(value){
121 $("#testbeds-filter_"+value).removeClass("active");
123 }else if(filter[1]=='=' || filter[1]=='=='){
124 $("#testbeds-filter_"+filter[2]).removeClass("active");
129 // ... be sure to list all events here
131 on_networks_query_done: function()
136 /* INTERNAL FUNCTIONS */
138 set_networks: function()
140 var scope = this._get_scope();
141 var query_ext = manifold.query_store.find_analyzed_query_ext(this.options.query_networks_uuid);
142 scope.testbeds = query_ext.records.values();
143 $.each(scope.testbeds, function(i, testbed) { testbed.active = true });
147 _get_scope : function()
149 return angular.element('[ng-controller=TestbedsCtrl]').scope()
153 _addFilter: function(key, op, value)
156 // get the previous list of values for this key, ex: [ple,nitos]
157 // remove the previous filter
158 network_filter = $.grep(this.filters, function(x) {
159 return x[0] == "network_hrn";
161 if(network_filter.length > 0){
162 $.each(network_filter, function(i,f){
166 // Add the new value to list of values, ex: wilab
169 // Update the filter with the new list of values, ex: [ple,nitos,wilab]
170 manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]);
173 _removeFilter: function(key, op, value)
175 console.log("remove "+value);
178 // get the previous list of values for this key, ex: [ple,nitos,wilab]
179 // remove the previous filter
180 network_filter = $.grep(this.filters, function(x) {
181 return x[0] == "network_hrn";
183 if(network_filter.length > 0){
184 $.each(network_filter, function(i,f){
186 manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, [key, op, values]);
190 // remove the value from the list of values, ex: wilab
191 values = $.grep(values, function(x) {
195 // Update the filter with the new list of values, ex: [ple,nitos]
196 manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]);
202 /* Plugin registration */
203 $.plugin('TestbedsPlugin', TestbedsPlugin);
205 // TODO Here use cases for instanciating plugins in different ways like in the pastie.