Changeset 13768
- Timestamp:
- 04/15/16 15:53:02 (9 years ago)
- Location:
- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/CalendarHub.cs
r13754 r13768 6 6 using System.Collections.Generic; 7 7 using System.Linq; 8 using System.Threading; 8 9 using System.Threading.Tasks; 9 10 … … 47 48 Clients.Caller.processDowntime(id, down); 48 49 } 50 public void saveCalendar(string id, string[] del, string[][] add, string[][] upd, bool fresh, bool last) 51 { 52 loader(); 53 var calid = Guid.Parse(id); 54 adminClient.Refresh(); 55 adminClient.DowntimeForResourceId = calid; 56 adminClient.RefreshCalendar(); 57 var downlist = adminClient.Downtimes.ToList(); 58 foreach(var s in del) 59 { 60 var gu = Guid.Parse(s); 61 var el = downlist.Find(x => x.Id == gu); 62 adminClient.Delete(el); 63 } 64 foreach (var s in add) 65 { 66 var obj = new Downtime(); 67 obj.Id = Guid.Empty; 68 if (s[0] == "Unavailable") 69 obj.DowntimeType = DowntimeType.Offline; 70 else 71 obj.DowntimeType = DowntimeType.Shutdown; 72 obj.StartDate = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[1])); 73 obj.EndDate = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[2])); 74 if (s[3] == "true") 75 obj.AllDayEvent = true; 76 else 77 obj.AllDayEvent = false; 78 obj.ResourceId = Guid.Parse(s[4]); 79 adminClient.Store(obj, CancellationToken.None); 80 } 81 foreach(var s in upd) 82 { 83 var obj = downlist.Find(x => x.Id == Guid.Parse(s[0])); 84 if (s[1] == "Unavailable") 85 obj.DowntimeType = DowntimeType.Offline; 86 else 87 obj.DowntimeType = DowntimeType.Shutdown; 88 obj.StartDate = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[2])); 89 obj.EndDate = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[3])); 90 if (s[4] == "true") 91 obj.AllDayEvent = true; 92 else 93 obj.AllDayEvent = false; 94 //adminClient.Store(obj, CancellationToken.None); Throws error 95 } 96 if( last) 97 { 98 Clients.Caller.savingAllDone(); 99 } 100 else if (fresh) 101 { 102 Clients.Caller.savingCurrentDone(); 103 } 104 } 49 105 } 50 106 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/CalendarHubber.js
r13758 r13768 2 2 angular.module('wjm', ['ui.bootstrap', 'ui.calendar', 'angularTreeview', 'ngDialog']). 3 3 4 controller('resourceCtrl', function ($ scope, uiCalendarConfig, $compile, ngDialog, $timeout) {4 controller('resourceCtrl', function ($rootScope, $scope, uiCalendarConfig, $compile, ngDialog, $timeout) { 5 5 var vm = $scope; 6 6 … … 29 29 $scope.buildTree(); 30 30 31 $scope.$apply(); 32 }; 33 hubber.client.savingCurrentDone = function () { 34 $scope.clearCurrentCalendar(); 35 $scope.$apply(); 36 }; 37 hubber.client.savingAllDone = function () { 38 clearAllCalendarsFunc(); 31 39 $scope.$apply(); 32 40 }; … … 51 59 end: new Date(json[i].EndDate), 52 60 allDay: json[i].AllDayEvent, 53 color: col 61 color: col, 62 changed: false 54 63 }); 55 64 } … … 81 90 }); 82 91 } 92 $scope.buildTree = function () { 93 vm.tree = []; 94 vm.temptree = []; 95 vm.top = false; 96 for (; vm.data.length > 0;) { 97 98 if (vm.data[0].ParentResourceId == null) { 99 var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]); 100 vm.tree.push(curr); 101 } 102 else { 103 var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]); 104 vm.temptree.push(curr); 105 } 106 } 107 108 }; 109 110 $scope.seekChildren = function (current) { 111 current.calendar = []; 112 current.children = []; 113 current.todelete = []; 114 current.changes = false; 115 current.collapsed = true; 116 for (var t = 0; t < vm.temptree.length;) { 117 if (current.Id == vm.temptree[t].ParentResourceId) { 118 current.children.push(vm.temptree.splice(t, 1)[0]); 119 } 120 else { 121 t++; 122 } 123 } 124 var childc = current.children.length;//Remembers count of children received from temp tree; 125 for (var t = 0; t < vm.data.length;) { 126 if (current.Id == vm.data[t].ParentResourceId) { 127 current.children.push(vm.data.splice(t, 1)[0]); 128 } 129 else { 130 t++; 131 } 132 } 133 for (var t = childc; t < current.children.length; t++) { 134 current.children[t] = $scope.seekChildren(current.children[t]); 135 } 136 return current; 137 } 138 function collectInfoToSave(node, refresh, last) { 139 var arr = node.calendar.down[0]; 140 var toadd = []; 141 var todel = node.todelete; 142 var toupd = []; 143 for (var i = 0; i < arr.length; i++) { 144 if (arr[i].id === '00000000-0000-0000-0000-000000000000') { 145 var t = arr[i].allDay.toString(); 146 toadd.push([ 147 arr[i].title, 148 "" + Date.parse(arr[i].start), 149 "" + Date.parse(arr[i].end), 150 t, 151 node.Id 152 ]); 153 } 154 else if (arr[i].changed === true) { 155 var t = arr[i].allDay.toString(); 156 toupd.push([ 157 arr[i].id, 158 arr[i].title, 159 "" + Date.parse(arr[i].start), 160 "" + Date.parse(arr[i].end), 161 t 162 ]); 163 } 164 } 165 vm.sendtoserv = [toadd, toupd, todel]; 166 hubber.server.saveCalendar(node.Id, todel, toadd, toupd, refresh, last); 167 } 83 168 $scope.saveCurrentCalendar = function () { 84 console.log("Save Current cal"); 169 collectInfoToSave(vm.treeview.currentNode, true, false); 170 //true for refresh, false for showing it's only one calendar saved. 85 171 } 86 172 $scope.saveAllCalendars = function () { 87 console.log("Save all"); 173 $scope.allSave = []; 174 for (var i = 0; i < $scope.tree.length; i++) 175 createSaveRequests($scope.tree[i]); 176 ngDialog.openConfirm({ 177 template: 178 '<p>Are you sure you want to save all changes made to ' + $scope.allSave.length + ' calendars?</p>' + 179 '<div>' + 180 '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' + 181 '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' + 182 '</button></div>', 183 plain: true 184 }).then(function (success) { 185 for (var i = 0; i < $scope.allSave.length; i++) { 186 if (i >= $scope.allSave.length - 1) 187 collectInfoToSave($scope.allSave[i], false, true); 188 else 189 collectInfoToSave($scope.allSave[i], false, false); 190 } 191 }); 192 193 194 } 195 function createSaveRequests(node) { 196 if (node.changes === true) 197 $scope.allSave.push(node); 198 for (var i = 0; i < node.children.length; i++) { 199 createSaveRequests(node.children[i]); 200 } 88 201 } 89 202 $scope.clearCurrentCalendar = function () { … … 91 204 $scope.selectedEventId = -1; 92 205 $scope.treeview.currentNode.calendar = null; 206 $scope.treeview.currentNode.todelete = []; 207 $scope.treeview.currentNode.changes = false; 93 208 $scope.currentcal = []; 94 209 hubber.server.requestDownTime(vm.treeview.currentNode.Id); 95 210 $(".selected.ng-binding").removeClass('changed'); 211 212 96 213 } 97 214 $scope.clearAllCalendars = function () { … … 105 222 plain: true 106 223 }).then(function (success) { 107 $(".ng-binding.changed").removeClass('changed'); 108 $(".ng-binding.loaded").removeClass('loaded'); 109 $scope.selectedEventId = -1; 110 $scope.treeview.currentNode.calendar = null; 111 $scope.currentcal = []; 112 for (var i = 0; i < $scope.tree.length; i++) 113 removeCalendarsRecurse($scope.tree[i]); 114 hubber.server.requestDownTime(vm.treeview.currentNode.Id); 115 $(".selected.ng-binding").addClass('loaded'); 116 }); 117 224 clearAllCalendarsFunc(); 225 }); 226 227 } 228 function clearAllCalendarsFunc() { 229 $(".ng-binding.changed").removeClass('changed'); 230 $(".ng-binding.loaded").removeClass('loaded'); 231 $scope.selectedEventId = -1; 232 $scope.treeview.currentNode.calendar = null; 233 $scope.currentcal = []; 234 for (var i = 0; i < $scope.tree.length; i++) 235 removeCalendarsRecurse($scope.tree[i]); 236 hubber.server.requestDownTime(vm.treeview.currentNode.Id); 237 $(".selected.ng-binding").addClass('loaded'); 118 238 } 119 239 function removeCalendarsRecurse(node) { … … 121 241 node.calendar = []; 122 242 node.todelete = []; 123 243 node.changes = false; 124 244 for (var i = 0; i < node.children.length; i++) { 125 245 removeCalendarsRecurse(node.children[i]); … … 127 247 } 128 248 129 $scope.buildTree = function () { 130 vm.tree = []; 131 vm.temptree = []; 132 vm.top = false; 133 for (; vm.data.length > 0;) { 134 135 if (vm.data[0].ParentResourceId == null) { 136 var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]); 137 vm.tree.push(curr); 138 } 139 else { 140 var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]); 141 vm.temptree.push(curr); 142 } 143 } 144 145 }; 146 147 $scope.seekChildren = function (current) { 148 current.calendar = []; 149 current.children = []; 150 current.todelete = []; 151 current.collapsed = true; 152 for (var t = 0; t < vm.temptree.length;) { 153 if (current.Id == vm.temptree[t].ParentResourceId) { 154 current.children.push(vm.temptree.splice(t, 1)[0]); 155 } 156 else { 157 t++; 158 } 159 } 160 var childc = current.children.length;//Remembers count of children received from temp tree; 161 for (var t = 0; t < vm.data.length;) { 162 if (current.Id == vm.data[t].ParentResourceId) { 163 current.children.push(vm.data.splice(t, 1)[0]); 164 } 165 else { 166 t++; 167 } 168 } 169 for (var t = childc; t < current.children.length; t++) { 170 current.children[t] = $scope.seekChildren(current.children[t]); 171 } 172 return current; 249 $scope.deleteAllPreviousEvents = function () { 250 vm.selectedEventId = -1; 251 var node = vm.treeview.currentNode.calendar.down[0]; 252 for (var i = 0; i < node.length;) { 253 if (node[i].end < Date.now()) { 254 if (node[i].id != '00000000-0000-0000-0000-000000000000') 255 vm.treeview.currentNode.todelete.push(node[i].id); 256 $scope.setChanged(); 257 node.splice(i, 1); 258 } 259 else 260 i++; 261 } 262 ngDialog.open({ 263 template: 264 '<p>All previous events have been deleted. Save the changes to confirm deletion</p>', 265 plain: true 266 }); 267 } 268 269 270 $scope.setChanged = function () { 271 if (vm.selectedEventId != -1) { 272 if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].title === "Unavailable") 273 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#0099cc'; 274 else 275 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#ff5500'; 276 277 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].changed = true; 278 } 279 vm.treeview.currentNode.changes = true; 280 $(".selected.ng-binding").addClass('changed'); 281 } 282 //*Add event by click 283 $scope.calendarClick = function (date, jsEvent, view) { 284 285 var newid = 0; 286 if (vm.treeview.currentNode.calendar.down[0].length != 0) 287 newid = vm.treeview.currentNode.calendar.down[0][(vm.treeview.currentNode.calendar.down[0].length - 1)]._id + 1; 288 var dat = date.toDate(); 289 var end = new Date(dat); 290 end.setHours(dat.getHours() + 2); 291 console.log(end); 292 vm.treeview.currentNode.calendar.down[0].push({ 293 id: '00000000-0000-0000-0000-000000000000', 294 title: 'Unavailable', 295 start: dat, 296 end: end, 297 allDay: date._ambigTime, 298 _id: (newid) 299 }); 300 vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1; 301 vm.setChanged(); 302 // $("#resourcecalendar").fullCalendar('refetchEvents'); 303 173 304 } 174 305 function checkId(id) { … … 179 310 return -1; 180 311 } 181 $scope.setChanged = function () {182 if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].title === "Unavailable")183 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#0099cc';184 else185 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#ff5500';186 vm.treeview.currentNode.changes = true;187 $(".selected.ng-binding").addClass('changed');188 }189 //*Add event by click190 $scope.calendarClick = function (date, jsEvent, view) {191 var newid = 0;192 if (vm.treeview.currentNode.calendar.down[0].length != 0)193 newid = vm.treeview.currentNode.calendar.down[0][(vm.treeview.currentNode.calendar.down[0].length - 1)]._id + 1;194 vm.treeview.currentNode.calendar.down[0].push({195 id: '00000000-0000-0000-0000-000000000000',196 title: 'Unavailable',197 start: date.toDate(),198 end: null,199 allDay: date._ambigTime,200 _id: (newid)201 });202 203 vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1;204 vm.setChanged();205 206 }207 312 /* alert on eventClick */ 208 $scope. alertOnEventClick = function (date, jsEvent, view) {313 $scope.eventClick = function (date, jsEvent, view) { 209 314 vm.selectedEventId = checkId(date._id); 210 315 }; 211 316 /* alert on Drop */ 212 $scope. alertOnDrop = function (event, delta, revertFunc, jsEvent, ui, view) {317 $scope.dragandDrop = function (event, delta, revertFunc, jsEvent, ui, view) { 213 318 vm.selectedEventId = checkId(event._id); 214 319 vm.setChanged(); 320 if (event.end == null) { 321 event.end = moment(event.start).add(2, 'hours'); 322 } 215 323 if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay && event.start._ambigTime == false) { 216 324 event.allDay = false; 217 325 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay = false; 218 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = null;219 326 } 220 327 else if (!vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay && event.start._ambigTime == true) { 221 328 event.allDay = true; 222 329 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay = true; 223 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = null;330 //vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = null; 224 331 } 225 332 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start); 226 if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end != null) 227 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end); 333 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end); 228 334 }; 229 335 /* alert on Resize */ 230 $scope. alertOnResize= function (event, delta, revertFunc, jsEvent, ui, view) {336 $scope.resizeEvent = function (event, delta, revertFunc, jsEvent, ui, view) { 231 337 vm.selectedEventId = checkId(event._id); 232 338 vm.setChanged(); … … 235 341 }; 236 342 237 /* add custom event*/238 $scope.addEvent = function () {239 240 };241 242 343 /* remove event */ 243 344 $scope.remove = function (index) { 244 345 vm.selectedEventId = -1; 346 vm.setChanged(); 245 347 if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") { 246 vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index - 1].id);348 vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id); 247 349 } 248 350 vm.treeview.currentNode.calendar.down[0].splice(index, 1); … … 272 374 timezone: 'UTC', 273 375 timeFormat: 'HH:mm', 274 eventClick: $scope. alertOnEventClick,275 eventDrop: $scope. alertOnDrop,276 eventResize: $scope. alertOnResize,376 eventClick: $scope.eventClick, 377 eventDrop: $scope.dragandDrop, 378 eventResize: $scope.resizeEvent, 277 379 eventRender: $scope.eventRender, 278 380 dayClick: $scope.calendarClick … … 281 383 } 282 384 }; 385 $rootScope.$on('$locationChangeStart', function (event, newUrl, oldUrl) { 386 console.log($(".changed").length); 387 if ($(".changed").length != 0) { 388 ngDialog.openConfirm({ 389 template: 390 '<p>You have unsaved changes. Are you sure you want to leave this page? All changes will be lost. </p>' + 391 '<div>' + 392 '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' + 393 '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' + 394 '</button></div>', 395 plain: true 396 }).then(function (success) { 397 $rootScope.allowNavigation(); 398 }); 399 } 400 401 event.preventDefault(); // This prevents the navigation from happening 402 } 403 ); 283 404 284 405 }); -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Resource/Index.cshtml
r13758 r13768 5 5 @Html.Partial("Navbar", new HeuristicLab.Clients.Hive.WebJobManager.ViewModels.NavbarViewModel("Resource")) 6 6 7 <p>Alert: {{alertMessage}} {{treeview.currentNode.Name}}</p>7 8 8 9 9 <div class="col-sm-4"> … … 17 17 </div> 18 18 </div> 19 <div ng-if="treeview.currentNode" class="col-sm-8 panel panel-primary" >19 <div ng-if="treeview.currentNode" class="col-sm-8 panel panel-primary" style="margin-bottom:200px"> 20 20 <div class="row panel-heading"> 21 21 <h3>{{treeview.currentNode.Name}} <span ng-if="treeview.currentNode.IsDisposable === undefined"> - Client group</span></h3> … … 66 66 <button class="btn btn-warning" ng-click="clearAllCalendars()">Clear all changes</button> 67 67 </div> 68 <div class="row" style="padding-bottom:30px;"> 69 <button class="btn btn-info" ng-click="deleteAllPreviousEvents()">Delete all previous events to date</button> 70 </div> 68 71 <i ng-if="currentcal.length === 0" class="fa fa-cog fa-5x fa-spin"></i> 69 72 <div ng-if="currentcal.length != 0" … … 87 90 </td> 88 91 <td ng-if="currentcal.down[0][selectedEventId].allDay"> 89 {{currentcal.down[0][selectedEventId].start | date : 'dd/MM/yy' : 'utc'}}92 All day {{currentcal.down[0][selectedEventId].start | date : 'dd/MM/yy' : 'utc'}} 90 93 <span ng-if="currentcal.down[0][selectedEventId].end"> 91 94 to {{currentcal.down[0][selectedEventId].end | date : 'dd/MM/yy': 'utc'}} -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/gruntfile.js
r13758 r13768 1 /// <binding BeforeBuild='copy:angular, cssmin:all, uglify' Clean='default, copy:angular' />1 /// <binding BeforeBuild='copy:angular, cssmin:all, cssmin, copy' Clean='default, copy:angular, cssmin, copy' /> 2 2 /// <reference path="bower_components/angular/angular.min.js" /> 3 3 /// <reference path="bower_components/angular/angular.js" /> -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/hubs/calendarhubber.js
r13758 r13768 2 2 angular.module('wjm', ['ui.bootstrap', 'ui.calendar', 'angularTreeview', 'ngDialog']). 3 3 4 controller('resourceCtrl', function ($ scope, uiCalendarConfig, $compile, ngDialog, $timeout) {4 controller('resourceCtrl', function ($rootScope, $scope, uiCalendarConfig, $compile, ngDialog, $timeout) { 5 5 var vm = $scope; 6 6 … … 29 29 $scope.buildTree(); 30 30 31 $scope.$apply(); 32 }; 33 hubber.client.savingCurrentDone = function () { 34 $scope.clearCurrentCalendar(); 35 $scope.$apply(); 36 }; 37 hubber.client.savingAllDone = function () { 38 clearAllCalendarsFunc(); 31 39 $scope.$apply(); 32 40 }; … … 51 59 end: new Date(json[i].EndDate), 52 60 allDay: json[i].AllDayEvent, 53 color: col 61 color: col, 62 changed: false 54 63 }); 55 64 } … … 81 90 }); 82 91 } 92 $scope.buildTree = function () { 93 vm.tree = []; 94 vm.temptree = []; 95 vm.top = false; 96 for (; vm.data.length > 0;) { 97 98 if (vm.data[0].ParentResourceId == null) { 99 var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]); 100 vm.tree.push(curr); 101 } 102 else { 103 var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]); 104 vm.temptree.push(curr); 105 } 106 } 107 108 }; 109 110 $scope.seekChildren = function (current) { 111 current.calendar = []; 112 current.children = []; 113 current.todelete = []; 114 current.changes = false; 115 current.collapsed = true; 116 for (var t = 0; t < vm.temptree.length;) { 117 if (current.Id == vm.temptree[t].ParentResourceId) { 118 current.children.push(vm.temptree.splice(t, 1)[0]); 119 } 120 else { 121 t++; 122 } 123 } 124 var childc = current.children.length;//Remembers count of children received from temp tree; 125 for (var t = 0; t < vm.data.length;) { 126 if (current.Id == vm.data[t].ParentResourceId) { 127 current.children.push(vm.data.splice(t, 1)[0]); 128 } 129 else { 130 t++; 131 } 132 } 133 for (var t = childc; t < current.children.length; t++) { 134 current.children[t] = $scope.seekChildren(current.children[t]); 135 } 136 return current; 137 } 138 function collectInfoToSave(node, refresh, last) { 139 var arr = node.calendar.down[0]; 140 var toadd = []; 141 var todel = node.todelete; 142 var toupd = []; 143 for (var i = 0; i < arr.length; i++) { 144 if (arr[i].id === '00000000-0000-0000-0000-000000000000') { 145 var t = arr[i].allDay.toString(); 146 toadd.push([ 147 arr[i].title, 148 "" + Date.parse(arr[i].start), 149 "" + Date.parse(arr[i].end), 150 t, 151 node.Id 152 ]); 153 } 154 else if (arr[i].changed === true) { 155 var t = arr[i].allDay.toString(); 156 toupd.push([ 157 arr[i].id, 158 arr[i].title, 159 "" + Date.parse(arr[i].start), 160 "" + Date.parse(arr[i].end), 161 t 162 ]); 163 } 164 } 165 vm.sendtoserv = [toadd, toupd, todel]; 166 hubber.server.saveCalendar(node.Id, todel, toadd, toupd, refresh, last); 167 } 83 168 $scope.saveCurrentCalendar = function () { 84 console.log("Save Current cal"); 169 collectInfoToSave(vm.treeview.currentNode, true, false); 170 //true for refresh, false for showing it's only one calendar saved. 85 171 } 86 172 $scope.saveAllCalendars = function () { 87 console.log("Save all"); 173 $scope.allSave = []; 174 for (var i = 0; i < $scope.tree.length; i++) 175 createSaveRequests($scope.tree[i]); 176 ngDialog.openConfirm({ 177 template: 178 '<p>Are you sure you want to save all changes made to ' + $scope.allSave.length + ' calendars?</p>' + 179 '<div>' + 180 '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' + 181 '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' + 182 '</button></div>', 183 plain: true 184 }).then(function (success) { 185 for (var i = 0; i < $scope.allSave.length; i++) { 186 if (i >= $scope.allSave.length - 1) 187 collectInfoToSave($scope.allSave[i], false, true); 188 else 189 collectInfoToSave($scope.allSave[i], false, false); 190 } 191 }); 192 193 194 } 195 function createSaveRequests(node) { 196 if (node.changes === true) 197 $scope.allSave.push(node); 198 for (var i = 0; i < node.children.length; i++) { 199 createSaveRequests(node.children[i]); 200 } 88 201 } 89 202 $scope.clearCurrentCalendar = function () { … … 91 204 $scope.selectedEventId = -1; 92 205 $scope.treeview.currentNode.calendar = null; 206 $scope.treeview.currentNode.todelete = []; 207 $scope.treeview.currentNode.changes = false; 93 208 $scope.currentcal = []; 94 209 hubber.server.requestDownTime(vm.treeview.currentNode.Id); 95 210 $(".selected.ng-binding").removeClass('changed'); 211 212 96 213 } 97 214 $scope.clearAllCalendars = function () { … … 105 222 plain: true 106 223 }).then(function (success) { 107 $(".ng-binding.changed").removeClass('changed'); 108 $(".ng-binding.loaded").removeClass('loaded'); 109 $scope.selectedEventId = -1; 110 $scope.treeview.currentNode.calendar = null; 111 $scope.currentcal = []; 112 for (var i = 0; i < $scope.tree.length; i++) 113 removeCalendarsRecurse($scope.tree[i]); 114 hubber.server.requestDownTime(vm.treeview.currentNode.Id); 115 $(".selected.ng-binding").addClass('loaded'); 116 }); 117 224 clearAllCalendarsFunc(); 225 }); 226 227 } 228 function clearAllCalendarsFunc() { 229 $(".ng-binding.changed").removeClass('changed'); 230 $(".ng-binding.loaded").removeClass('loaded'); 231 $scope.selectedEventId = -1; 232 $scope.treeview.currentNode.calendar = null; 233 $scope.currentcal = []; 234 for (var i = 0; i < $scope.tree.length; i++) 235 removeCalendarsRecurse($scope.tree[i]); 236 hubber.server.requestDownTime(vm.treeview.currentNode.Id); 237 $(".selected.ng-binding").addClass('loaded'); 118 238 } 119 239 function removeCalendarsRecurse(node) { … … 121 241 node.calendar = []; 122 242 node.todelete = []; 123 243 node.changes = false; 124 244 for (var i = 0; i < node.children.length; i++) { 125 245 removeCalendarsRecurse(node.children[i]); … … 127 247 } 128 248 129 $scope.buildTree = function () { 130 vm.tree = []; 131 vm.temptree = []; 132 vm.top = false; 133 for (; vm.data.length > 0;) { 134 135 if (vm.data[0].ParentResourceId == null) { 136 var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]); 137 vm.tree.push(curr); 138 } 139 else { 140 var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]); 141 vm.temptree.push(curr); 142 } 143 } 144 145 }; 146 147 $scope.seekChildren = function (current) { 148 current.calendar = []; 149 current.children = []; 150 current.todelete = []; 151 current.collapsed = true; 152 for (var t = 0; t < vm.temptree.length;) { 153 if (current.Id == vm.temptree[t].ParentResourceId) { 154 current.children.push(vm.temptree.splice(t, 1)[0]); 155 } 156 else { 157 t++; 158 } 159 } 160 var childc = current.children.length;//Remembers count of children received from temp tree; 161 for (var t = 0; t < vm.data.length;) { 162 if (current.Id == vm.data[t].ParentResourceId) { 163 current.children.push(vm.data.splice(t, 1)[0]); 164 } 165 else { 166 t++; 167 } 168 } 169 for (var t = childc; t < current.children.length; t++) { 170 current.children[t] = $scope.seekChildren(current.children[t]); 171 } 172 return current; 249 $scope.deleteAllPreviousEvents = function () { 250 vm.selectedEventId = -1; 251 var node = vm.treeview.currentNode.calendar.down[0]; 252 for (var i = 0; i < node.length;) { 253 if (node[i].end < Date.now()) { 254 if (node[i].id != '00000000-0000-0000-0000-000000000000') 255 vm.treeview.currentNode.todelete.push(node[i].id); 256 $scope.setChanged(); 257 node.splice(i, 1); 258 } 259 else 260 i++; 261 } 262 ngDialog.open({ 263 template: 264 '<p>All previous events have been deleted. Save the changes to confirm deletion</p>', 265 plain: true 266 }); 267 } 268 269 270 $scope.setChanged = function () { 271 if (vm.selectedEventId != -1) { 272 if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].title === "Unavailable") 273 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#0099cc'; 274 else 275 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#ff5500'; 276 277 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].changed = true; 278 } 279 vm.treeview.currentNode.changes = true; 280 $(".selected.ng-binding").addClass('changed'); 281 } 282 //*Add event by click 283 $scope.calendarClick = function (date, jsEvent, view) { 284 285 var newid = 0; 286 if (vm.treeview.currentNode.calendar.down[0].length != 0) 287 newid = vm.treeview.currentNode.calendar.down[0][(vm.treeview.currentNode.calendar.down[0].length - 1)]._id + 1; 288 var dat = date.toDate(); 289 var end = new Date(dat); 290 end.setHours(dat.getHours() + 2); 291 console.log(end); 292 vm.treeview.currentNode.calendar.down[0].push({ 293 id: '00000000-0000-0000-0000-000000000000', 294 title: 'Unavailable', 295 start: dat, 296 end: end, 297 allDay: date._ambigTime, 298 _id: (newid) 299 }); 300 vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1; 301 vm.setChanged(); 302 // $("#resourcecalendar").fullCalendar('refetchEvents'); 303 173 304 } 174 305 function checkId(id) { … … 179 310 return -1; 180 311 } 181 $scope.setChanged = function () {182 if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].title === "Unavailable")183 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#0099cc';184 else185 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#ff5500';186 vm.treeview.currentNode.changes = true;187 $(".selected.ng-binding").addClass('changed');188 }189 //*Add event by click190 $scope.calendarClick = function (date, jsEvent, view) {191 var newid = 0;192 if (vm.treeview.currentNode.calendar.down[0].length != 0)193 newid = vm.treeview.currentNode.calendar.down[0][(vm.treeview.currentNode.calendar.down[0].length - 1)]._id + 1;194 vm.treeview.currentNode.calendar.down[0].push({195 id: '00000000-0000-0000-0000-000000000000',196 title: 'Unavailable',197 start: date.toDate(),198 end: null,199 allDay: date._ambigTime,200 _id: (newid)201 });202 203 vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1;204 vm.setChanged();205 206 }207 312 /* alert on eventClick */ 208 $scope. alertOnEventClick = function (date, jsEvent, view) {313 $scope.eventClick = function (date, jsEvent, view) { 209 314 vm.selectedEventId = checkId(date._id); 210 315 }; 211 316 /* alert on Drop */ 212 $scope. alertOnDrop = function (event, delta, revertFunc, jsEvent, ui, view) {317 $scope.dragandDrop = function (event, delta, revertFunc, jsEvent, ui, view) { 213 318 vm.selectedEventId = checkId(event._id); 214 319 vm.setChanged(); 320 if (event.end == null) { 321 event.end = moment(event.start).add(2, 'hours'); 322 } 215 323 if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay && event.start._ambigTime == false) { 216 324 event.allDay = false; 217 325 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay = false; 218 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = null;219 326 } 220 327 else if (!vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay && event.start._ambigTime == true) { 221 328 event.allDay = true; 222 329 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay = true; 223 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = null;330 //vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = null; 224 331 } 225 332 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start); 226 if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end != null) 227 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end); 333 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end); 228 334 }; 229 335 /* alert on Resize */ 230 $scope. alertOnResize= function (event, delta, revertFunc, jsEvent, ui, view) {336 $scope.resizeEvent = function (event, delta, revertFunc, jsEvent, ui, view) { 231 337 vm.selectedEventId = checkId(event._id); 232 338 vm.setChanged(); … … 235 341 }; 236 342 237 /* add custom event*/238 $scope.addEvent = function () {239 240 };241 242 343 /* remove event */ 243 344 $scope.remove = function (index) { 244 345 vm.selectedEventId = -1; 346 vm.setChanged(); 245 347 if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") { 246 vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index - 1].id);348 vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id); 247 349 } 248 350 vm.treeview.currentNode.calendar.down[0].splice(index, 1); … … 272 374 timezone: 'UTC', 273 375 timeFormat: 'HH:mm', 274 eventClick: $scope. alertOnEventClick,275 eventDrop: $scope. alertOnDrop,276 eventResize: $scope. alertOnResize,376 eventClick: $scope.eventClick, 377 eventDrop: $scope.dragandDrop, 378 eventResize: $scope.resizeEvent, 277 379 eventRender: $scope.eventRender, 278 380 dayClick: $scope.calendarClick … … 281 383 } 282 384 }; 385 $rootScope.$on('$locationChangeStart', function (event, newUrl, oldUrl) { 386 console.log($(".changed").length); 387 if ($(".changed").length != 0) { 388 ngDialog.openConfirm({ 389 template: 390 '<p>You have unsaved changes. Are you sure you want to leave this page? All changes will be lost. </p>' + 391 '<div>' + 392 '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' + 393 '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' + 394 '</button></div>', 395 plain: true 396 }).then(function (success) { 397 $rootScope.allowNavigation(); 398 }); 399 } 400 401 event.preventDefault(); // This prevents the navigation from happening 402 } 403 ); 283 404 284 405 });
Note: See TracChangeset
for help on using the changeset viewer.