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 != 0) && (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()
138 console.log('query network DONE');
139 $("[id^='testbeds-filter_']").on('click',function(e) {
140 $(this).toggleClass("active");
142 // avoid multiple calls when an event is raised to manifold.js
145 value = this.dataset['platform'];
146 // handle the hrn that include . in their name (has to be in sync with the data from SFA)
147 //value = value.replace(/\./g,"\\.");
150 return $(this).hasClass('active') ? self._addFilter(key, op, value) : self._removeFilter(key, op, value);
155 /* INTERNAL FUNCTIONS */
157 set_networks: function()
159 var scope = this._get_scope();
160 var query_ext = manifold.query_store.find_analyzed_query_ext(this.options.query_networks_uuid);
161 scope.testbeds = query_ext.records.values();
162 $.each(scope.testbeds, function(i, testbed) { testbed.active = true });
166 _get_scope : function()
168 return angular.element('[ng-controller=TestbedsCtrl]').scope()
171 _addFilter: function(key, op, value)
174 // get the previous list of values for this key, ex: [ple,nitos]
175 // remove the previous filter
176 network_filter = $.grep(this.filters, function(x) {
177 return x[0] == "network_hrn";
179 if(network_filter.length > 0){
180 $.each(network_filter, function(i,f){
184 // Add the new value to list of values, ex: wilab
187 // Update the filter with the new list of values, ex: [ple,nitos,wilab]
188 manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]);
190 _removeFilter: function(key, op, value)
192 console.log("remove "+value);
195 // get the previous list of values for this key, ex: [ple,nitos,wilab]
196 // remove the previous filter
197 network_filter = $.grep(this.filters, function(x) {
198 return x[0] == "network_hrn";
200 if(network_filter.length > 0){
201 $.each(network_filter, function(i,f){
203 manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, [key, op, values]);
207 // remove the value from the list of values, ex: wilab
208 values = $.grep(values, function(x) {
212 // Update the filter with the new list of values, ex: [ple,nitos]
213 manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]);
219 /* Plugin registration */
220 $.plugin('TestbedsPlugin', TestbedsPlugin);
222 // TODO Here use cases for instanciating plugins in different ways like in the pastie.