3 # Copyright (c) 2013 NITLab, University of Thessaly, CERTH, Greece
\r
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 # of this software and associated documentation files (the "Software"), to deal
\r
7 # in the Software without restriction, including without limitation the rights
\r
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 # copies of the Software, and to permit persons to whom the Software is
\r
10 # furnished to do so, subject to the following conditions:
\r
12 # The above copyright notice and this permission notice shall be included in
\r
13 # all copies or substantial portions of the Software.
\r
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 # This is a MySlice plugin for the NITOS Scheduler
\r
25 # Nitos Scheduler v1
\r
30 //is ctrl keyboard button pressed
\r
31 var schedulerCtrlPressed = false;
\r
33 var schedulerTblId = "scheduler-reservation-table";
\r
34 var schedulerTblFirstColWidth = 150;
\r
36 var schedulerSlotsPerHour = 6;
\r
37 var schedulerMaxRows = 12;
\r
38 var SchedulerData = [];
\r
39 var SchedulerSlots = [];
\r
40 var SchedulerDataViewData = [];
\r
41 var SchedulerSlotsViewData = [];
\r
42 var SchedulerTotalCells;
\r
43 var SchedulerTotalVisibleCells;
\r
45 var _schedulerCurrentCellPosition = 0;
\r
46 var _leasesDone = false;
\r
47 var _resourcesDone = false;
\r
49 var schedulerDebug = false;
\r
51 var tmpSchedulerLeases = [];
\r
54 var scheduler2 = Plugin.extend({
\r
57 * @brief Plugin constructor
\r
58 * @param options : an associative array of setting values
\r
60 * @return : a jQuery collection of objects on which the plugin is
\r
61 * applied, which allows to maintain chainability of calls
\r
63 init: function (options, element) {
\r
64 this.classname="scheduler2";
\r
65 // Call the parent constructor, see FAQ when forgotten
\r
66 this._super(options, element);
\r
68 SchedulerSlots = schedulerGetSlots(60/schedulerSlotsPerHour);
\r
69 //selection from table
\r
70 $(window).keydown(function (evt) {
\r
71 if (evt.which == 17) { // ctrl
\r
72 schedulerCtrlPressed = true;
\r
74 }).keyup(function (evt) {
\r
75 if (evt.which == 17) { // ctrl
\r
76 schedulerCtrlPressed = false;
\r
79 $("#" + schedulerTblId).on('mousedown', 'td', rangeMouseDown).on('mouseup', 'td', rangeMouseUp).on('mousemove', 'td', rangeMouseMove);
\r
81 // Explain this will allow query events to be handled
\r
82 // What happens when we don't define some events ?
\r
83 // Some can be less efficient
\r
85 if (schedulerDebug) console.time("Listening_to_queries");
\r
86 /* Listening to queries */
\r
87 this.listen_query(options.query_uuid, 'all_ev');
\r
88 this.listen_query(options.query_all_resources_uuid, 'all_resources');
\r
89 this.listen_query(options.query_lease_uuid, 'lease');
\r
90 //this.listen_query(options.query_lease_uuid, 'lease');
\r
91 if (schedulerDebug) console.timeEnd("Listening_to_queries");
\r
97 /* all_ev QUERY HANDLERS Start */
\r
98 on_all_ev_clear_records: function (data) {
\r
99 //alert('all_ev clear_records');
\r
101 on_all_ev_query_in_progress: function (data) {
\r
102 // alert('all_ev query_in_progress');
\r
104 on_all_ev_new_record: function (data) {
\r
105 //alert('all_ev new_record');
\r
107 on_all_ev_query_done: function (data) {
\r
108 //alert('all_ev query_done');
\r
110 //another plugin has modified something, that requires you to update your display.
\r
111 on_all_ev_field_state_changed: function (data) {
\r
112 //alert('all_ev query_done');
\r
114 /* all_ev QUERY HANDLERS End */
\r
115 /* all_resources QUERY HANDLERS Start */
\r
116 on_all_resources_clear_records: function (data) {
\r
117 //data is empty on load
\r
119 on_all_resources_query_in_progress: function (data) {
\r
120 //data is empty on load
\r
122 on_all_resources_new_record: function (data) {
\r
123 //alert(data.toSource());
\r
124 if (data.exclusive == null)
\r
125 SchedulerData.push({ id: data.urn, index: SchedulerData.length, name: data.hrn, granularity: data.granularity, leases: schedulerGetLeases(60 / schedulerSlotsPerHour), type: data.type });
\r
126 //alert(data.toSource());
\r
129 on_all_resources_query_done: function (data) {
\r
130 _resourcesDone = true;
\r
131 this._initScheduler();
\r
133 //another plugin has modified something, that requires you to update your display.
\r
134 on_all_resources_field_state_changed: function (data) {
\r
135 //alert('all_resources query_done');
\r
137 /* all_resources QUERY HANDLERS End */
\r
138 /* lease QUERY HANDLERS Start */
\r
139 on_lease_clear_records: function (data) { console.log('clear_records'); },
\r
140 on_lease_query_in_progress: function (data) { console.log('lease_query_in_progress'); },
\r
141 on_lease_new_record: function (data) {
\r
142 tmpSchedulerLeases.push({
\r
143 id: schedulerGetSlotId(data.start_time, data.duration, data.granularity),
\r
145 status: 'reserved',
\r
146 resource: data.resource,
\r
147 network: data.network,
\r
148 start_time: data.start_time,
\r
149 lease_type: data.lease_type,
\r
150 granularity: data.granularity,
\r
151 duration: data.duration
\r
153 //console.log(data.toSource()); console.log('lease_new_record');
\r
155 on_lease_query_done: function (data) {
\r
156 _leasesDone = true;
\r
157 this._initScheduler();
\r
158 // console.log('lease_query_done');
\r
160 //another plugin has modified something, that requires you to update your display.
\r
161 on_lease_field_state_changed: function (data) { console.log('lease_field_state_changed'); },
\r
162 /* lease QUERY HANDLERS End */
\r
166 on_filter_added: function (filter) {
\r
167 var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope();
\r
168 tmpScope.initSchedulerResources(schedulerMaxRows, filter);
\r
171 // ... be sure to list all events here
\r
173 /* RECORD HANDLERS */
\r
174 on_all_new_record: function (record) {
\r
175 //alert('on_all_new_record');
\r
178 debug : function (logTxt) {
\r
179 if (typeof window.console != 'undefined') {
\r
180 console.debug(logTxt);
\r
184 /* INTERNAL FUNCTIONS */
\r
185 _initScheduler: function () {
\r
186 if (_resourcesDone && _leasesDone)
\r
188 /* GUI setup and event binding */
\r
194 _initUI: function () {
\r
196 if (schedulerDebug) console.time("_initUI");
\r
197 //init DatePicker Start
\r
198 $("#DateToRes").datepicker({
\r
199 dateFormat: "yy-mm-dd",
\r
202 }).change(function () {
\r
203 //Scheduler2.loadWithDate();
\r
204 }).click(function () {
\r
205 $("#ui-datepicker-div").css("z-index", 5);
\r
207 //End init DatePicker
\r
214 $('#tblSlider').slider({
\r
216 max: SchedulerTotalCells - SchedulerTotalVisibleCells - 1,
\r
218 slide: function (event, ui) {
\r
219 //$("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);
\r
220 //console.log(ui.value);
\r
221 var angScope = angular.element(document.getElementById('SchedulerCtrl')).scope();
\r
222 if (_schedulerCurrentCellPosition > ui.value)
\r
223 angScope.moveBackSlot(ui.value, ui.value + SchedulerTotalVisibleCells);
\r
224 else if (_schedulerCurrentCellPosition < ui.value)
\r
225 angScope.moveFrontSlot(ui.value, ui.value + SchedulerTotalVisibleCells);
\r
226 _schedulerCurrentCellPosition = ui.value;
\r
232 $("#plugin-scheduler-loader").hide();
\r
233 $("#plugin-scheduler").show();
\r
234 //fixOddEvenClasses();
\r
235 //$("#" + schedulerTblId + " td:not([class])").addClass("free");
\r
236 if (schedulerDebug) console.timeEnd("_initUI");
\r
239 _FixLeases : function () {
\r
240 for (var i = 0; i < tmpSchedulerLeases.length; i++) {
\r
241 var tmpLea = tmpSchedulerLeases[i];
\r
242 var tmpRes = schedulerFindResourceById(SchedulerData, tmpLea.resource);
\r
243 if (tmpRes != null) {
\r
244 //alert(tmpLea.id + '-' + tmpLea.start_time);
\r
245 tmpRes.leases[tmpLea.id] = tmpLea;
\r
250 _FixTable: function () {
\r
252 SchedulerTotalCells = SchedulerSlots.length;
\r
253 $('#' + schedulerTblId + ' thead tr th:eq(0)').css("width", schedulerTblFirstColWidth);
\r
254 //this get width might need fix depending on the template
\r
255 var tblwidth = $('#scheduler-tab').parent().outerWidth();
\r
256 SchedulerTotalVisibleCells = parseInt((tblwidth - schedulerTblFirstColWidth) / colWidth);
\r
258 //if (SchedulerData.length == 0) {
\r
259 // //puth some test data
\r
260 // SchedulerData.push({ name: 'xyz+aaa', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+aaa', type: 'node' });
\r
261 // SchedulerData.push({ name: 'xyz+bbb', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+bbb', type: 'node' });
\r
262 // SchedulerData.push({ name: 'xyz+ccc', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+ccc', type: 'node' });
\r
263 // SchedulerData.push({ name: 'nitos1', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'nitos1', type: 'node' });
\r
265 var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope();
\r
266 tmpScope.initSchedulerResources(schedulerMaxRows, null);
\r
268 _SetPeriodInPage: function (start, end) {
\r
272 //Sched2 = new Scheduler2();
\r
274 /* Plugin registration */
\r
275 $.plugin('Scheduler2', scheduler2);
\r
277 // TODO Here use cases for instanciating plugins in different ways like in the pastie.
\r