[13754] | 1 |
|
---|
[13860] | 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 |
|
---|
[13758] | 21 | angular.module('wjm', ['ui.bootstrap', 'ui.calendar', 'angularTreeview', 'ngDialog']).
|
---|
[13754] | 22 |
|
---|
[13768] | 23 | controller('resourceCtrl', function ($rootScope, $scope, uiCalendarConfig, $compile, ngDialog, $timeout) {
|
---|
[13754] | 24 | var vm = $scope;
|
---|
| 25 |
|
---|
| 26 | var date = new Date();
|
---|
| 27 |
|
---|
| 28 | var d = date.getDate();
|
---|
| 29 | var m = date.getMonth();
|
---|
| 30 | var y = date.getFullYear();
|
---|
| 31 | var hubber = $.connection.calendarHub;
|
---|
[13775] | 32 |
|
---|
[13805] | 33 | vm.currentcal = [];//Reference to current calendar (treeview.currentNode.calendar)
|
---|
| 34 | $scope.permissionview = false;//Show permissions or not
|
---|
| 35 | $scope.resaddview = false;//Show add resources or not
|
---|
| 36 | vm.selectedEventId = -1;//Selected downtime (-1 for none)
|
---|
| 37 | vm.groups = []; //All resource groups
|
---|
| 38 | vm.clients = []; //All resources
|
---|
[13754] | 39 | vm.init = function () {
|
---|
| 40 |
|
---|
| 41 | var v = document.getElementById("userId").innerHTML;
|
---|
| 42 | $.connection.hub.qs = { 'userid': v };
|
---|
[13805] | 43 | //Connection string set to identify the unique session ID for the user
|
---|
[13754] | 44 | $.connection.hub.start().done(function () {
|
---|
[13805] | 45 | hubber.server.requestInfo();//initial data request
|
---|
[13754] | 46 | });
|
---|
[13805] | 47 |
|
---|
| 48 | //Process all initial data needed (heavy load)
|
---|
[13795] | 49 | hubber.client.processData = function (data, users, groups) {
|
---|
[13754] | 50 | vm.data = JSON.parse(data);
|
---|
[13795] | 51 | vm.permUsers = JSON.parse(users);
|
---|
| 52 | vm.permGroups = JSON.parse(groups);
|
---|
[13754] | 53 | $scope.buildTree();
|
---|
[13795] | 54 |
|
---|
[13754] | 55 | $scope.$apply();
|
---|
| 56 | };
|
---|
[13805] | 57 |
|
---|
| 58 | //Saving from current graph is done -> refresh it
|
---|
[13768] | 59 | hubber.client.savingCurrentDone = function () {
|
---|
[13782] | 60 | vm.calendarSaver = false;
|
---|
[13768] | 61 | $scope.clearCurrentCalendar();
|
---|
| 62 | $scope.$apply();
|
---|
| 63 | };
|
---|
[13805] | 64 |
|
---|
| 65 | //Saving all graphs done -> clear everything
|
---|
[13768] | 66 | hubber.client.savingAllDone = function () {
|
---|
[13782] | 67 | vm.calendarSaver = false;
|
---|
[13768] | 68 | clearAllCalendarsFunc();
|
---|
| 69 | $scope.$apply();
|
---|
| 70 | };
|
---|
[13805] | 71 |
|
---|
| 72 | //Dispose toggle refresh for current
|
---|
[13782] | 73 | hubber.client.processDispose = function (disp) {
|
---|
| 74 | vm.treeview.currentNode.IsDisposable = disp;
|
---|
| 75 | $scope.calendarDispose = false;
|
---|
| 76 | $scope.$apply();
|
---|
| 77 | }
|
---|
[13805] | 78 |
|
---|
| 79 | //Permissions refresh for specific resource
|
---|
[13795] | 80 | hubber.client.processPermissions = function (id, perm) {
|
---|
| 81 | var json = JSON.parse(perm);
|
---|
| 82 |
|
---|
| 83 | $scope.treeview.currentNode.permissions = json;
|
---|
| 84 | refreshPermissions();
|
---|
| 85 | $scope.permissionLoader = false;
|
---|
| 86 | $scope.$apply();
|
---|
| 87 | }
|
---|
[13805] | 88 |
|
---|
| 89 | //Process downtimes for a resource. Data conversion
|
---|
[13754] | 90 | hubber.client.processDowntime = function (id, down) {
|
---|
| 91 | var json = JSON.parse(down);
|
---|
| 92 | var arrdown = [];
|
---|
[13758] | 93 | var str = "";
|
---|
[13754] | 94 | for (var i = 0; i < json.length; i++) {
|
---|
[13758] | 95 | if (json[i].DowntimeType === 0) {
|
---|
| 96 | str = "Unavailable";
|
---|
| 97 | col = "#006080";
|
---|
| 98 | }
|
---|
| 99 | else {
|
---|
| 100 | str = "Shutdown";
|
---|
| 101 | col = "#993300";
|
---|
| 102 | }
|
---|
[13754] | 103 | arrdown.push({
|
---|
| 104 | id: json[i].Id,
|
---|
[13758] | 105 | title: str,
|
---|
| 106 | start: new Date(json[i].StartDate),
|
---|
| 107 | end: new Date(json[i].EndDate),
|
---|
| 108 | allDay: json[i].AllDayEvent,
|
---|
[13768] | 109 | color: col,
|
---|
[13775] | 110 | rec: {
|
---|
| 111 | recurrence: json[i].Recurring,
|
---|
| 112 | recid: json[i].RecurringId,
|
---|
| 113 | days: [false, false, false, false, false, false, false],
|
---|
| 114 | start: new Date(json[i].StartDate),
|
---|
| 115 | end: new Date(json[i].EndDate)
|
---|
| 116 |
|
---|
| 117 | },
|
---|
[13768] | 118 | changed: false
|
---|
[13754] | 119 | });
|
---|
| 120 | }
|
---|
| 121 | var dat = { 'id': id, 'down': [arrdown] };
|
---|
| 122 | $scope.treeview.currentNode.calendar = dat;
|
---|
[13758] | 123 |
|
---|
[13754] | 124 | $scope.currentcal = $scope.treeview.currentNode.calendar;
|
---|
[13775] | 125 | $("#resourcecalendar").fullCalendar('refresh');
|
---|
[13754] | 126 | $scope.$apply();
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[13805] | 129 | //Initial function to build the resource tree
|
---|
| 130 | $scope.buildTree = function () {
|
---|
| 131 | vm.tree = [];
|
---|
| 132 | vm.temptree = [];
|
---|
| 133 | vm.top = false;
|
---|
| 134 | var ungrouped = {
|
---|
| 135 | children: [],
|
---|
| 136 | Name: 'Ungrouped'
|
---|
| 137 | }
|
---|
| 138 | for (; vm.data.length > 0;) {
|
---|
| 139 |
|
---|
| 140 | if (vm.data[0].ParentResourceId == null && vm.data[0].IsDisposable !== undefined) {
|
---|
| 141 | var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
|
---|
| 142 | vm.clients.push(curr);
|
---|
| 143 | ungrouped.children.push(curr);
|
---|
| 144 | }
|
---|
| 145 | else if (vm.data[0].ParentResourceId == null) {
|
---|
| 146 | var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
|
---|
| 147 | vm.groups.push(curr);
|
---|
| 148 | vm.tree.push(curr);
|
---|
| 149 | }
|
---|
| 150 | else {
|
---|
| 151 | var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
|
---|
| 152 | if (curr.IsDisposable !== undefined)
|
---|
| 153 | vm.clients.push(curr);
|
---|
| 154 | else
|
---|
| 155 | vm.groups.push(curr);
|
---|
| 156 | vm.temptree.push(curr);
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 | vm.tree.push(ungrouped);
|
---|
| 160 |
|
---|
| 161 | };//End for hubber init
|
---|
| 162 |
|
---|
| 163 | //menu navigation
|
---|
| 164 | $scope.menuchange = function (i) {
|
---|
| 165 | switch (i) {
|
---|
| 166 | case 0:
|
---|
| 167 | $scope.permissionview = false;
|
---|
| 168 | $scope.resaddview = false;
|
---|
| 169 | break;
|
---|
| 170 | case 1:
|
---|
| 171 | $scope.permissionview = true;
|
---|
| 172 | $scope.resaddview = false;
|
---|
| 173 | break;
|
---|
| 174 | case 2:
|
---|
| 175 | $scope.permissionview = false;
|
---|
| 176 | $scope.resaddview = true;
|
---|
| 177 | break;
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | //Seeks for children, used recursively for building the treeview
|
---|
| 182 | $scope.seekChildren = function (current) {
|
---|
| 183 | current.calendar = [];
|
---|
| 184 | current.children = [];
|
---|
| 185 | current.todelete = [];
|
---|
| 186 | current.changes = false;
|
---|
| 187 | current.collapsed = true;
|
---|
| 188 | for (var t = 0; t < vm.temptree.length;) {
|
---|
| 189 | if (current.Id == vm.temptree[t].ParentResourceId) {
|
---|
| 190 | current.children.push(vm.temptree.splice(t, 1)[0]);
|
---|
| 191 | }
|
---|
| 192 | else {
|
---|
| 193 | t++;
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | var childc = current.children.length;//Remembers count of children received from temp tree;
|
---|
| 197 | for (var t = 0; t < vm.data.length;) {
|
---|
| 198 | if (current.Id == vm.data[t].ParentResourceId) {
|
---|
| 199 | if (vm.data[t].IsDisposable !== undefined)
|
---|
| 200 | vm.clients.push(vm.data[t]);
|
---|
| 201 | else
|
---|
| 202 | vm.groups.push(vm.data[t]);
|
---|
| 203 | current.children.push(vm.data.splice(t, 1)[0]);
|
---|
| 204 | }
|
---|
| 205 | else {
|
---|
| 206 | t++;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 | for (var t = childc; t < current.children.length; t++) {
|
---|
| 210 | current.children[t] = $scope.seekChildren(current.children[t]);
|
---|
| 211 | }
|
---|
| 212 | return current;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | //Change to another resource
|
---|
[13754] | 216 | $scope.$watch("treeview.currentNode", function (newValue, oldValue) {
|
---|
| 217 | $scope.currentcal = [];
|
---|
[13805] | 218 | $scope.resaddview = false;
|
---|
[13758] | 219 | $(".selected.ng-binding").addClass('loaded');
|
---|
[13754] | 220 | $scope.selectedEventId = -1;
|
---|
[13795] | 221 |
|
---|
[13805] | 222 | //Check if resource already has downtime data loaded
|
---|
[13782] | 223 | if ($scope.treeview.currentNode != null && $scope.treeview.currentNode.Id != undefined) {
|
---|
[13754] | 224 | if ($scope.treeview.currentNode.calendar.length === 0) {
|
---|
[13805] | 225 | //Reach out to server to receive resource data
|
---|
[13795] | 226 | hubber.server.requestPermissions(vm.treeview.currentNode.Id);
|
---|
[13754] | 227 | hubber.server.requestDownTime(vm.treeview.currentNode.Id);
|
---|
[13795] | 228 | vm.permissionLoader = true;
|
---|
[13754] | 229 | }
|
---|
| 230 | else {
|
---|
| 231 | $timeout(function () {
|
---|
[13795] | 232 | refreshPermissions();
|
---|
[13805] | 233 | //set previously loaded data
|
---|
[13754] | 234 | $scope.currentcal = $scope.treeview.currentNode.calendar;
|
---|
| 235 | }, 0);
|
---|
[13758] | 236 |
|
---|
[13754] | 237 | }
|
---|
[13805] | 238 | $scope.refreshAdds();
|
---|
[13754] | 239 | }
|
---|
| 240 |
|
---|
| 241 | });
|
---|
| 242 | }
|
---|
[13805] | 243 |
|
---|
| 244 | //Resets the add resources menu
|
---|
| 245 | $scope.refreshAdds = function() {
|
---|
| 246 | for (var i = 0; i < $scope.clients.length; i++) {
|
---|
| 247 | $scope.clients[i].add = false;
|
---|
| 248 | for (var j = 0; j < $scope.treeview.currentNode.children.length; j++) {
|
---|
| 249 | if ($scope.clients[i].Id === $scope.treeview.currentNode.children[j].Id)
|
---|
| 250 | $scope.clients[i].add = true;
|
---|
| 251 | }
|
---|
| 252 | }
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | //Resets the permissions menu
|
---|
[13795] | 256 | function refreshPermissions() {
|
---|
| 257 | for (var i = 0; i < $scope.permUsers.length; i++){
|
---|
| 258 | $scope.permUsers[i].state = false;
|
---|
| 259 | for (var j = 0; j < $scope.treeview.currentNode.permissions.length; j++) {
|
---|
| 260 | if($scope.permUsers[i].Id === $scope.treeview.currentNode.permissions[j].GrantedUserId)
|
---|
| 261 | $scope.permUsers[i].state = true;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | for (var i = 0; i < $scope.permGroups.length; i++) {
|
---|
| 265 | $scope.permGroups[i].state = false;
|
---|
| 266 | for (var j = 0; j < $scope.treeview.currentNode.permissions.length; j++) {
|
---|
| 267 | if ($scope.permGroups[i].Id === $scope.treeview.currentNode.permissions[j].GrantedUserId)
|
---|
| 268 | $scope.permGroups[i].state = true;
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 | }
|
---|
[13805] | 272 |
|
---|
| 273 | //Add resource group show by clearing the tree
|
---|
[13782] | 274 | $scope.clearTreeSelect = function () {
|
---|
| 275 | if (vm.treeview.currentNode != undefined) {
|
---|
| 276 | vm.treeview.currentNode.selected = undefined;
|
---|
| 277 | vm.treeview.currentNode = undefined;
|
---|
| 278 | vm.selectedEventId = -1;
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
[13754] | 281 |
|
---|
[13805] | 282 | //Reach out to server to toggle disposable for current calendar
|
---|
[13782] | 283 | $scope.toggleDisposable = function () {
|
---|
| 284 | $scope.calendarDispose = true;
|
---|
| 285 | hubber.server.toggleDisposable(vm.treeview.currentNode.Id);
|
---|
| 286 | }
|
---|
[13805] | 287 |
|
---|
| 288 | //Pushes permissions to server
|
---|
[13795] | 289 | $scope.pushPermissions = function () {
|
---|
| 290 | var perms = [];
|
---|
| 291 | $scope.permissionLoader = true;
|
---|
| 292 | var node = $scope.treeview.currentNode;
|
---|
| 293 | for (var i = 0; i < $scope.permGroups.length; i++) {
|
---|
| 294 | if ($scope.permGroups[i].state === true)
|
---|
| 295 | perms.push($scope.permGroups[i].Id);
|
---|
| 296 | }
|
---|
| 297 | for (var i = 0; i < $scope.permUsers.length; i++) {
|
---|
| 298 | if ($scope.permUsers[i].state === true)
|
---|
| 299 | perms.push($scope.permUsers[i].Id);
|
---|
| 300 | }
|
---|
| 301 | hubber.server.changePermissions(perms, node.Id);
|
---|
| 302 | }
|
---|
[13805] | 303 |
|
---|
| 304 | //Collects all data from a single resource to save to the server
|
---|
[13768] | 305 | function collectInfoToSave(node, refresh, last) {
|
---|
| 306 | var arr = node.calendar.down[0];
|
---|
| 307 | var toadd = [];
|
---|
| 308 | var todel = node.todelete;
|
---|
| 309 | var toupd = [];
|
---|
| 310 | for (var i = 0; i < arr.length; i++) {
|
---|
| 311 | if (arr[i].id === '00000000-0000-0000-0000-000000000000') {
|
---|
[13805] | 312 | //NEW DOWNTIME
|
---|
[13768] | 313 | var t = arr[i].allDay.toString();
|
---|
| 314 | toadd.push([
|
---|
[13775] | 315 | arr[i].title,//status
|
---|
| 316 | "" + Date.parse(arr[i].start),//start
|
---|
| 317 | "" + Date.parse(arr[i].end),//end
|
---|
| 318 | t,// allday
|
---|
| 319 | node.Id, //resource id
|
---|
| 320 | arr[i].rec.recurrence.toString(),//true on recur
|
---|
| 321 | arr[i].rec.recid,//recur id
|
---|
| 322 | "" + Date.parse(arr[i].rec.start),
|
---|
| 323 | "" + Date.parse(arr[i].rec.end),
|
---|
| 324 | arr[i].rec.days.join(",")
|
---|
| 325 |
|
---|
[13782] | 326 |
|
---|
[13768] | 327 | ]);
|
---|
| 328 | }
|
---|
| 329 | else if (arr[i].changed === true) {
|
---|
[13805] | 330 | //EDIT EXISTING DOWNTIME
|
---|
[13768] | 331 | var t = arr[i].allDay.toString();
|
---|
| 332 | toupd.push([
|
---|
[13775] | 333 | arr[i].id,//id to update
|
---|
| 334 | arr[i].title,//status
|
---|
| 335 | "" + Date.parse(arr[i].start),//start
|
---|
| 336 | "" + Date.parse(arr[i].end),//end
|
---|
| 337 | t,//allday
|
---|
| 338 | arr[i].rec.recurrence.toString(),//true on recur
|
---|
| 339 | arr[i].rec.recid,//recur id
|
---|
| 340 | "" + Date.parse(arr[i].rec.start),
|
---|
| 341 | "" + Date.parse(arr[i].rec.end),
|
---|
| 342 | arr[i].rec.days.join(",")
|
---|
[13782] | 343 |
|
---|
[13768] | 344 | ]);
|
---|
| 345 | }
|
---|
[13758] | 346 | }
|
---|
[13775] | 347 | vm.sendtoserv = [todel, toadd, toupd];
|
---|
[13768] | 348 | hubber.server.saveCalendar(node.Id, todel, toadd, toupd, refresh, last);
|
---|
[13758] | 349 | }
|
---|
[13805] | 350 |
|
---|
| 351 | //Save current calendar
|
---|
[13768] | 352 | $scope.saveCurrentCalendar = function () {
|
---|
[13782] | 353 | vm.calendarSaver = true;
|
---|
[13805] | 354 | collectInfoToSave(vm.treeview.currentNode, true, false);//true for refresh, false for save all
|
---|
[13768] | 355 | //true for refresh, false for showing it's only one calendar saved.
|
---|
| 356 | }
|
---|
[13805] | 357 |
|
---|
| 358 | //Save all changed calendars
|
---|
[13768] | 359 | $scope.saveAllCalendars = function () {
|
---|
[13782] | 360 |
|
---|
[13768] | 361 | $scope.allSave = [];
|
---|
| 362 | for (var i = 0; i < $scope.tree.length; i++)
|
---|
| 363 | createSaveRequests($scope.tree[i]);
|
---|
| 364 | ngDialog.openConfirm({
|
---|
| 365 | template:
|
---|
| 366 | '<p>Are you sure you want to save all changes made to ' + $scope.allSave.length + ' calendars?</p>' +
|
---|
| 367 | '<div>' +
|
---|
| 368 | '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
|
---|
| 369 | '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
|
---|
| 370 | '</button></div>',
|
---|
| 371 | plain: true
|
---|
| 372 | }).then(function (success) {
|
---|
[13782] | 373 | vm.calendarSaver = true;
|
---|
[13805] | 374 |
|
---|
[13768] | 375 | for (var i = 0; i < $scope.allSave.length; i++) {
|
---|
| 376 | if (i >= $scope.allSave.length - 1)
|
---|
| 377 | collectInfoToSave($scope.allSave[i], false, true);
|
---|
| 378 | else
|
---|
| 379 | collectInfoToSave($scope.allSave[i], false, false);
|
---|
| 380 | }
|
---|
| 381 | });
|
---|
[13775] | 382 |
|
---|
| 383 |
|
---|
[13768] | 384 | }
|
---|
[13805] | 385 |
|
---|
| 386 | //Checks treeview for edits and builds new array containing these (recurse for children)
|
---|
[13768] | 387 | function createSaveRequests(node) {
|
---|
| 388 | if (node.changes === true)
|
---|
| 389 | $scope.allSave.push(node);
|
---|
| 390 | for (var i = 0; i < node.children.length; i++) {
|
---|
| 391 | createSaveRequests(node.children[i]);
|
---|
| 392 | }
|
---|
| 393 | }
|
---|
[13805] | 394 |
|
---|
| 395 | //Clears and refreshes calendar for current resource (delete current changes)
|
---|
[13768] | 396 | $scope.clearCurrentCalendar = function () {
|
---|
[13775] | 397 |
|
---|
[13768] | 398 | $scope.selectedEventId = -1;
|
---|
| 399 | $scope.treeview.currentNode.calendar = null;
|
---|
| 400 | $scope.treeview.currentNode.todelete = [];
|
---|
| 401 | $scope.treeview.currentNode.changes = false;
|
---|
| 402 | $scope.currentcal = [];
|
---|
| 403 | hubber.server.requestDownTime(vm.treeview.currentNode.Id);
|
---|
[13795] | 404 | $(".selected.ng-scope").removeClass('changed');
|
---|
[13768] | 405 | $(".selected.ng-binding").removeClass('changed');
|
---|
| 406 |
|
---|
| 407 |
|
---|
| 408 | }
|
---|
[13805] | 409 |
|
---|
| 410 | //Clears all calendars and refreshes current (Deletes all changes)
|
---|
[13768] | 411 | $scope.clearAllCalendars = function () {
|
---|
| 412 | ngDialog.openConfirm({
|
---|
| 413 | template:
|
---|
| 414 | '<p>Are you sure you want to delete all calendar changes?</p>' +
|
---|
| 415 | '<div>' +
|
---|
| 416 | '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
|
---|
| 417 | '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
|
---|
| 418 | '</button></div>',
|
---|
| 419 | plain: true
|
---|
| 420 | }).then(function (success) {
|
---|
| 421 | clearAllCalendarsFunc();
|
---|
| 422 | });
|
---|
| 423 |
|
---|
| 424 | }
|
---|
[13805] | 425 |
|
---|
| 426 | //Function that clears all calendar (separate so dialog is not called when saveAll is finished)
|
---|
[13768] | 427 | function clearAllCalendarsFunc() {
|
---|
| 428 | $(".ng-binding.changed").removeClass('changed');
|
---|
[13795] | 429 | $(".ng-scope.changed").removeClass('changed');
|
---|
[13768] | 430 | $(".ng-binding.loaded").removeClass('loaded');
|
---|
[13795] | 431 | $(".ng-scope.loaded").removeClass('loaded');
|
---|
[13768] | 432 | $scope.selectedEventId = -1;
|
---|
| 433 | $scope.treeview.currentNode.calendar = null;
|
---|
| 434 | $scope.currentcal = [];
|
---|
| 435 | for (var i = 0; i < $scope.tree.length; i++)
|
---|
[13782] | 436 | clearCalendarsRecurse($scope.tree[i]);
|
---|
[13768] | 437 | hubber.server.requestDownTime(vm.treeview.currentNode.Id);
|
---|
| 438 | $(".selected.ng-binding").addClass('loaded');
|
---|
[13795] | 439 | $(".selected.ng-scope").addClass('loaded');
|
---|
[13768] | 440 | }
|
---|
[13805] | 441 |
|
---|
| 442 | //Recurse trough tree view
|
---|
[13782] | 443 | function clearCalendarsRecurse(node) {
|
---|
[13768] | 444 |
|
---|
| 445 | node.calendar = [];
|
---|
| 446 | node.todelete = [];
|
---|
| 447 | node.changes = false;
|
---|
| 448 | for (var i = 0; i < node.children.length; i++) {
|
---|
[13782] | 449 | clearCalendarsRecurse(node.children[i]);
|
---|
[13768] | 450 | }
|
---|
| 451 | }
|
---|
[13805] | 452 |
|
---|
| 453 | //Delete all downtimes from current resource
|
---|
[13782] | 454 | $scope.deleteAllEvents = function () {
|
---|
| 455 | vm.calendarDeleter = true;
|
---|
| 456 | vm.selectedEventId = -1;
|
---|
| 457 | var node = vm.treeview.currentNode.calendar.down[0];
|
---|
| 458 | for (var i = 0; i < node.length;) {
|
---|
| 459 | if (node[i].id != '00000000-0000-0000-0000-000000000000')
|
---|
| 460 | vm.treeview.currentNode.todelete.push(node[i].id);
|
---|
| 461 | $scope.setChanged(vm.selectedEventId);
|
---|
| 462 | node.splice(i, 1);
|
---|
| 463 | }
|
---|
| 464 | vm.calendarDeleter = false;
|
---|
| 465 | ngDialog.open({
|
---|
| 466 | template:
|
---|
| 467 | '<p>All events have been deleted. Save the changes to confirm deletion, clearing will restore all the events from the server</p>',
|
---|
| 468 | plain: true
|
---|
| 469 | });
|
---|
| 470 | }
|
---|
[13805] | 471 |
|
---|
| 472 | //Delete all past events
|
---|
[13768] | 473 | $scope.deleteAllPreviousEvents = function () {
|
---|
[13782] | 474 | vm.calendarDeleter = true;
|
---|
[13768] | 475 | vm.selectedEventId = -1;
|
---|
| 476 | var node = vm.treeview.currentNode.calendar.down[0];
|
---|
| 477 | for (var i = 0; i < node.length;) {
|
---|
| 478 | if (node[i].end < Date.now()) {
|
---|
| 479 | if (node[i].id != '00000000-0000-0000-0000-000000000000')
|
---|
[13775] | 480 | vm.treeview.currentNode.todelete.push(node[i].id);
|
---|
| 481 | $scope.setChanged(vm.selectedEventId);
|
---|
[13768] | 482 | node.splice(i, 1);
|
---|
| 483 | }
|
---|
| 484 | else
|
---|
| 485 | i++;
|
---|
| 486 | }
|
---|
[13782] | 487 | vm.calendarDeleter = false;
|
---|
[13768] | 488 | ngDialog.open({
|
---|
| 489 | template:
|
---|
| 490 | '<p>All previous events have been deleted. Save the changes to confirm deletion</p>',
|
---|
| 491 | plain: true
|
---|
| 492 | });
|
---|
| 493 | }
|
---|
| 494 |
|
---|
[13805] | 495 | //Sets the status of a downtime AND the current resource to changed
|
---|
[13775] | 496 | $scope.setChanged = function (id) {
|
---|
| 497 | if (id != -1) {
|
---|
| 498 | if (vm.treeview.currentNode.calendar.down[0][id].title === "Unavailable")
|
---|
| 499 | vm.treeview.currentNode.calendar.down[0][id].color = '#0099cc';
|
---|
[13768] | 500 | else
|
---|
[13775] | 501 | vm.treeview.currentNode.calendar.down[0][id].color = '#ff5500';
|
---|
[13768] | 502 |
|
---|
[13775] | 503 | vm.treeview.currentNode.calendar.down[0][id].changed = true;
|
---|
[13768] | 504 | }
|
---|
[13758] | 505 | vm.treeview.currentNode.changes = true;
|
---|
[13795] | 506 | $(".selected").addClass('changed');
|
---|
[13758] | 507 | }
|
---|
[13805] | 508 |
|
---|
| 509 | //Adds event by click on empty space
|
---|
[13758] | 510 | $scope.calendarClick = function (date, jsEvent, view) {
|
---|
[13768] | 511 |
|
---|
[13758] | 512 | var newid = 0;
|
---|
| 513 | if (vm.treeview.currentNode.calendar.down[0].length != 0)
|
---|
| 514 | newid = vm.treeview.currentNode.calendar.down[0][(vm.treeview.currentNode.calendar.down[0].length - 1)]._id + 1;
|
---|
[13768] | 515 | var dat = date.toDate();
|
---|
| 516 | var end = new Date(dat);
|
---|
| 517 | end.setHours(dat.getHours() + 2);
|
---|
[13758] | 518 | vm.treeview.currentNode.calendar.down[0].push({
|
---|
[13805] | 519 | id: '00000000-0000-0000-0000-000000000000',//Makes it recognizable as new for the server
|
---|
[13758] | 520 | title: 'Unavailable',
|
---|
[13768] | 521 | start: dat,
|
---|
| 522 | end: end,
|
---|
[13758] | 523 | allDay: date._ambigTime,
|
---|
[13775] | 524 | rec: {
|
---|
| 525 | recurrence: false,
|
---|
| 526 | recid: '0',
|
---|
| 527 | days: [false, false, false, false, false, false, false],
|
---|
| 528 | start: dat,
|
---|
| 529 | end: end
|
---|
| 530 |
|
---|
| 531 | },
|
---|
[13758] | 532 | _id: (newid)
|
---|
| 533 | });
|
---|
| 534 | vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1;
|
---|
[13775] | 535 | vm.setChanged(vm.selectedEventId);
|
---|
[13782] | 536 | $scope.currentcal = [];
|
---|
| 537 | $scope.currentcal = vm.treeview.currentNode.calendar;
|
---|
[13758] | 538 |
|
---|
[13782] | 539 |
|
---|
[13758] | 540 | }
|
---|
[13805] | 541 |
|
---|
| 542 | //Finds array index for specific _id
|
---|
[13768] | 543 | function checkId(id) {
|
---|
| 544 | for (var i = 0; i < vm.treeview.currentNode.calendar.down[0].length ; i++) {
|
---|
| 545 | if (vm.treeview.currentNode.calendar.down[0][i]._id === id)
|
---|
| 546 | return i;
|
---|
| 547 | }
|
---|
| 548 | return -1;
|
---|
| 549 | }
|
---|
[13805] | 550 | //Set selected downtime
|
---|
[13768] | 551 | $scope.eventClick = function (date, jsEvent, view) {
|
---|
[13758] | 552 | vm.selectedEventId = checkId(date._id);
|
---|
[13754] | 553 | };
|
---|
[13805] | 554 | //Sets selected downtime by clicking on the button at bottom on the page, moves to date
|
---|
[13782] | 555 | $scope.eventClickBtn = function (id) {
|
---|
| 556 | vm.selectedEventId = checkId(id);
|
---|
| 557 | vm.goToDate();
|
---|
| 558 | };
|
---|
[13805] | 559 |
|
---|
| 560 | //Drag and drop downtime
|
---|
[13768] | 561 | $scope.dragandDrop = function (event, delta, revertFunc, jsEvent, ui, view) {
|
---|
[13758] | 562 | vm.selectedEventId = checkId(event._id);
|
---|
[13775] | 563 | vm.setChanged(vm.selectedEventId);
|
---|
[13768] | 564 | if (event.end == null) {
|
---|
| 565 | event.end = moment(event.start).add(2, 'hours');
|
---|
| 566 | }
|
---|
[13758] | 567 | if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay && event.start._ambigTime == false) {
|
---|
| 568 | event.allDay = false;
|
---|
| 569 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay = false;
|
---|
| 570 | }
|
---|
| 571 | else if (!vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay && event.start._ambigTime == true) {
|
---|
| 572 | event.allDay = true;
|
---|
| 573 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay = true;
|
---|
[13768] | 574 | //vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = null;
|
---|
[13758] | 575 | }
|
---|
| 576 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start);
|
---|
[13768] | 577 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end);
|
---|
[13754] | 578 | };
|
---|
[13805] | 579 | //Resize downtime
|
---|
[13768] | 580 | $scope.resizeEvent = function (event, delta, revertFunc, jsEvent, ui, view) {
|
---|
[13758] | 581 | vm.selectedEventId = checkId(event._id);
|
---|
[13775] | 582 | vm.setChanged(vm.selectedEventId);
|
---|
[13758] | 583 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start);
|
---|
| 584 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end);
|
---|
[13754] | 585 | };
|
---|
| 586 |
|
---|
[13805] | 587 | //Removes a downtime from client (existing downtime gets referenced in todelete
|
---|
[13754] | 588 | $scope.remove = function (index) {
|
---|
[13758] | 589 | vm.selectedEventId = -1;
|
---|
[13775] | 590 | vm.setChanged(vm.selectedEventId);
|
---|
[13758] | 591 | if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") {
|
---|
[13768] | 592 | vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id);
|
---|
[13758] | 593 | }
|
---|
| 594 | vm.treeview.currentNode.calendar.down[0].splice(index, 1);
|
---|
| 595 |
|
---|
| 596 |
|
---|
[13754] | 597 | };
|
---|
[13805] | 598 | //Remove trough list view at bottom
|
---|
[13782] | 599 | $scope.removeList = function (id) {
|
---|
| 600 | var index = checkId(id);
|
---|
| 601 | vm.selectedEventId = -1;
|
---|
| 602 | vm.setChanged(vm.selectedEventId);
|
---|
| 603 | if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") {
|
---|
| 604 | vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id);
|
---|
| 605 | }
|
---|
| 606 | vm.treeview.currentNode.calendar.down[0].splice(index, 1);
|
---|
[13775] | 607 |
|
---|
[13782] | 608 |
|
---|
| 609 | };
|
---|
[13805] | 610 | //Check if start is before end AND start is after now (recursion)
|
---|
[13775] | 611 | $scope.checkDateStartEnd = function () {
|
---|
| 612 | if ($scope.currentcal.down[0][vm.selectedEventId].rec.start > $scope.currentcal.down[0][vm.selectedEventId].rec.end ||
|
---|
| 613 | $scope.currentcal.down[0][vm.selectedEventId].rec.end === undefined) {
|
---|
[13782] | 614 |
|
---|
[13775] | 615 | $scope.currentcal.down[0][vm.selectedEventId].rec.end = new Date($scope.currentcal.down[0][vm.selectedEventId].rec.start);
|
---|
[13782] | 616 |
|
---|
[13775] | 617 | }
|
---|
| 618 | if ($scope.currentcal.down[0][vm.selectedEventId].rec.start < Date.now())
|
---|
| 619 | $scope.currentcal.down[0][vm.selectedEventId].rec.start = new Date();
|
---|
[13782] | 620 | }
|
---|
[13805] | 621 | //pushes all changes to other existing recurs and creates new downtimes where needed
|
---|
[13775] | 622 | $scope.pushRecurChanges = function (recid) {
|
---|
| 623 | ngDialog.openConfirm({
|
---|
| 624 | template:
|
---|
| 625 | '<p>This will change all existing recurrences and create new recurrences where needed. Are you sure?</p>' +
|
---|
| 626 | '<div>' +
|
---|
| 627 | '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
|
---|
| 628 | '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
|
---|
| 629 | '</button></div>',
|
---|
| 630 | plain: true
|
---|
| 631 | }).then(function (success) {
|
---|
[13805] | 632 |
|
---|
[13775] | 633 | var arr = vm.treeview.currentNode.calendar.down[0];
|
---|
[13805] | 634 | //Deep copy of downtime for referencing
|
---|
[13775] | 635 | var ob = $.extend(true, {}, arr[vm.selectedEventId]);
|
---|
[13805] | 636 |
|
---|
| 637 | for (var i = 0; i < arr.length;) {//Go trough downtimes and find all recurrences
|
---|
[13775] | 638 | if (arr[i].rec.recid === recid) {
|
---|
| 639 | if (new Date(arr[i].start) < new Date(ob.rec.start) ||
|
---|
| 640 | new Date(arr[i].end) > new Date(ob.rec.end) ||
|
---|
| 641 | !ob.rec.days[new Date(arr[i].start).getDay()]) {
|
---|
[13805] | 642 | //Downtime is out of recurrence boundaries
|
---|
| 643 | //Before start date OR After end date OR Not on right day of the week
|
---|
| 644 | vm.remove(i);//NO I++ -> REMOVE SPLICES ARRAY
|
---|
[13775] | 645 | vm.selectedEventId = -1;
|
---|
| 646 |
|
---|
| 647 | }
|
---|
| 648 | else {
|
---|
[13805] | 649 | //Edit downtime when it is within the bounds
|
---|
[13775] | 650 | arr[i].start.setHours(ob.start.getHours(), ob.start.getMinutes());
|
---|
| 651 | arr[i].end.setHours(ob.end.getHours(), ob.end.getMinutes());
|
---|
| 652 | arr[i].title = ob.title;
|
---|
| 653 | arr[i].rec = ob.rec;
|
---|
| 654 | arr[i].allDay = ob.allDay;
|
---|
| 655 | vm.setChanged(i);
|
---|
| 656 | i++;
|
---|
| 657 | }
|
---|
| 658 | }
|
---|
| 659 | else
|
---|
| 660 | i++;
|
---|
| 661 | }
|
---|
[13805] | 662 | //init for new downtimes.
|
---|
[13775] | 663 | var start = new Date(ob.rec.start);
|
---|
[13805] | 664 | start.setHours(2, 0, 0, 0);//Beginning of the day + time conversion +02
|
---|
[13775] | 665 | var end = new Date(ob.rec.end);
|
---|
[13805] | 666 | end = new Date(end.setHours(24, 0, 0, 0) + 1000 * 3600 * 2);//End of the day + time conversion +02
|
---|
[13775] | 667 |
|
---|
[13805] | 668 | loop1: //Loop start to end with single day increment
|
---|
[13775] | 669 | for (var d = (start.getTime()) ; d < (end.getTime()) ;) {
|
---|
| 670 | var tog = ob.rec.days[new Date(d).getDay()];
|
---|
[13805] | 671 | //Check if day of the week is included in recursion
|
---|
[13775] | 672 | if (tog) {
|
---|
[13805] | 673 | loop2://Loop checking existing downtime array to see if day is already filled or not
|
---|
[13775] | 674 | for (var i = 0; i < arr.length; i++) {
|
---|
[13782] | 675 |
|
---|
[13775] | 676 | if (arr[i].rec.recid === recid) {
|
---|
[13782] | 677 | var dend = (d + 1000 * 3600 * 24);
|
---|
[13775] | 678 | if (arr[i].start.getTime() >= d &&
|
---|
| 679 | arr[i].end.getTime() <= dend) {
|
---|
[13805] | 680 | d += (1000 * 3600 * 24);//add day to loop 1
|
---|
| 681 | continue loop1;//breaks out of loop2 and skips to next day
|
---|
[13775] | 682 | }
|
---|
| 683 | }
|
---|
| 684 | }
|
---|
[13805] | 685 | //Made it here = new event needed: init
|
---|
[13775] | 686 | var ts = new Date(d);
|
---|
| 687 | ts.setHours(new Date(ob.start).getHours(), new Date(ob.start).getMinutes());
|
---|
| 688 | var te = new Date(d);
|
---|
| 689 | te.setHours(new Date(ob.end).getHours(), new Date(ob.end).getMinutes());
|
---|
| 690 | arr.push({
|
---|
| 691 | id: '00000000-0000-0000-0000-000000000000',
|
---|
| 692 | title: ob.title,
|
---|
| 693 | start: ts,
|
---|
| 694 | end: te,
|
---|
| 695 | allDay: ob.allDay,
|
---|
| 696 | rec: ob.rec
|
---|
| 697 | });
|
---|
| 698 | vm.setChanged(arr.length - 1);
|
---|
| 699 |
|
---|
| 700 | }
|
---|
[13782] | 701 |
|
---|
[13805] | 702 | d += (1000 * 3600 * 24);// adds one day
|
---|
[13782] | 703 |
|
---|
[13775] | 704 | }
|
---|
| 705 | });
|
---|
| 706 | }
|
---|
[13805] | 707 |
|
---|
| 708 | //Delete all bound recurrences
|
---|
[13775] | 709 | $scope.deleteAllRecurrences = function (recid) {
|
---|
| 710 | ngDialog.openConfirm({
|
---|
| 711 | template:
|
---|
| 712 | '<p>This will delete every found recurrence. Are you sure?</p>' +
|
---|
| 713 | '<div>' +
|
---|
| 714 | '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
|
---|
| 715 | '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
|
---|
| 716 | '</button></div>',
|
---|
| 717 | plain: true
|
---|
| 718 | }).then(function (success) {
|
---|
| 719 | var arr = vm.treeview.currentNode.calendar.down[0];
|
---|
| 720 | for (var i = 0; i < arr.length;) {
|
---|
| 721 | if (arr[i].rec.recid === recid)
|
---|
| 722 | vm.remove(i);
|
---|
| 723 | else
|
---|
| 724 | i++;
|
---|
| 725 | }
|
---|
| 726 | });
|
---|
| 727 | }
|
---|
| 728 |
|
---|
[13805] | 729 | //Moves calendar to selected date
|
---|
[13782] | 730 | $scope.goToDate = function () {
|
---|
| 731 | $("#resourcecalendar").fullCalendar('gotoDate', vm.currentcal.down[0][vm.selectedEventId].start);
|
---|
| 732 | }
|
---|
[13805] | 733 | /* Renders Tooltip */
|
---|
[13754] | 734 | $scope.eventRender = function (event, element, view) {
|
---|
| 735 | element.attr({
|
---|
| 736 | 'tooltip': event.title,
|
---|
| 737 | 'tooltip-append-to-body': true
|
---|
| 738 | });
|
---|
| 739 | //$compile(element)($scope);
|
---|
| 740 | };
|
---|
[13805] | 741 | //Calendar configuration
|
---|
[13754] | 742 | $scope.uiConfig = {
|
---|
| 743 | calendar: {
|
---|
[13758] | 744 | height: 500,
|
---|
[13754] | 745 | editable: true,
|
---|
[13758] | 746 | defaultView: 'agendaWeek',
|
---|
| 747 | firstDay: 1,
|
---|
[13754] | 748 | header: {
|
---|
| 749 | left: 'title',
|
---|
[13782] | 750 | center: 'agendaWeek, agendaDay',
|
---|
[13754] | 751 | right: 'today prev,next'
|
---|
| 752 | },
|
---|
| 753 | timezone: 'UTC',
|
---|
| 754 | timeFormat: 'HH:mm',
|
---|
[13768] | 755 | eventClick: $scope.eventClick,
|
---|
| 756 | eventDrop: $scope.dragandDrop,
|
---|
| 757 | eventResize: $scope.resizeEvent,
|
---|
[13754] | 758 | eventRender: $scope.eventRender,
|
---|
| 759 | dayClick: $scope.calendarClick
|
---|
| 760 |
|
---|
[13758] | 761 |
|
---|
[13782] | 762 |
|
---|
[13754] | 763 | }
|
---|
| 764 | };
|
---|
| 765 |
|
---|
[13805] | 766 |
|
---|
[13775] | 767 |
|
---|
| 768 |
|
---|
[13805] | 769 |
|
---|
[13782] | 770 | }).filter('disp', function () {
|
---|
[13805] | 771 | return function (input) {//Filter boolean to string
|
---|
[13782] | 772 | return input ? 'Disposable' : 'Not disposable';
|
---|
| 773 | }
|
---|
| 774 | }).directive('animateOnChange', function ($timeout) {
|
---|
[13805] | 775 | return function (scope, element, attr) {//Animation on downtime info to show change
|
---|
[13782] | 776 | scope.$watch(attr.animateOnChange, function (nv, ov) {
|
---|
| 777 |
|
---|
| 778 | if (nv != ov) {
|
---|
| 779 | if (scope.currentcal.down[0][scope.selectedEventId].title === "Unavailable") {
|
---|
| 780 | element.addClass('changed');
|
---|
| 781 | $timeout(function () {
|
---|
| 782 | element.removeClass('changed');
|
---|
[13805] | 783 | }, 250);
|
---|
[13782] | 784 | }
|
---|
| 785 | else {
|
---|
| 786 | element.addClass('changedshut');
|
---|
| 787 | $timeout(function () {
|
---|
| 788 | element.removeClass('changedshut');
|
---|
[13805] | 789 | }, 250);
|
---|
[13782] | 790 | }
|
---|
| 791 | }
|
---|
| 792 | });
|
---|
| 793 | };
|
---|
[13754] | 794 | });
|
---|
| 795 |
|
---|
| 796 |
|
---|