Commit 754a525b97c657c57d081b5cff90341704fb5113

Authored by Anchit Jindal
1 parent cefbd3ffaa
Exists in master

fixed schedular issues

Showing 1 changed file with 7 additions and 24 deletions   Show diff stats
app/partials/scheduler/scheduler.controller.js
1 'use strict'; 1 'use strict';
2 2
3 angular.module('acufuel') 3 angular.module('acufuel')
4 4
5 .controller('schedulerController', ['$scope','$compile', 'uiCalendarConfig', 'schedulerService', function($scope, $compile, uiCalendarConfig, schedulerService) { 5 .controller('schedulerController', ['$scope','$compile', 'uiCalendarConfig', 'schedulerService', function($scope, $compile, uiCalendarConfig, schedulerService) {
6 6
7 7
8 $scope.showLoader = true; 8 $scope.showLoader = true;
9 getEventsList(); 9 getEventsList();
10 10
11 /*---get events on calendar---*/ 11 /*---get events on calendar---*/
12 $scope.events = []; 12 $scope.events = [];
13 function getEventsList(){ 13 function getEventsList(){
14 schedulerService.getEvents().then(function(result) { 14 schedulerService.getEvents().then(function(result) {
15 //console.log('----kd events-------',result);
16 //console.log("==length===",result.length);
17 15
18 for (var i = 0; i < result.length; i++) { 16 for (var i = 0; i < result.length; i++) {
19 var newTime = new Date(result[i].deployDate);
20 // console.log("deployDate",result[i].deployDate)
21 var dmonth = newTime.getUTCMonth() + 1; //months from 1-12
22 var dday = newTime.getUTCDate();
23 var dyear = newTime.getUTCFullYear();
24 /*
25 $scope.events.push({
26 'id': result[i].id,
27 'title': result[i].aircraft +',\n' + result[i].make +'/' + result[i].model +',\n' + result[i].requestedVolume +',' +result[i].priceQuote,
28 'start': dyear+'-'+dmonth+'-'+dday
29
30 })*/
31 $scope.events.push({ 17 $scope.events.push({
32 'id': result[i].id, 18 'id': result[i].id,
33 'title': result[i].aircraft +'\n' + '(' + result[i].make +'/' + result[i].model + ')' + '\n' + 'for' + ' ' + result[i].requestedVolume + ' ' + 'gal.' + ' ' +'@' + ' ' +'$'+result[i].priceQuote, 19 'title': result[i].aircraft +'\n' + '(' + result[i].make +'/' + result[i].model + ')' + '\n' + 'for' + ' ' + result[i].requestedVolume + ' ' + 'gal.' + ' ' +'@' + ' ' +'$'+result[i].priceQuote,
34 'start': dyear+'-'+dmonth+'-'+dday 20 'start': result[i].deployDate
35 21
36 }) 22 })
37 // $scope.showEventsList();
38 $scope.showLoader = false; 23 $scope.showLoader = false;
39
40 } 24 }
41 25
42 $('#my-calendar').fullCalendar('removeEvents'); 26 $('#my-calendar').fullCalendar('removeEvents');
43 $('#my-calendar').fullCalendar('addEventSource',$scope.events);
44 // $scope.eventSources = [$scope.events, $scope.eventSource, $scope.eventsF];
45
46 // console.log('==eventSource are====',$scope.eventSources);
47 // $scope.newFuelPricing[i].futureFuelPricing.deployDate = dmonth+'/'+dday+'/'+dyear;
48 }) 27 })
49 } 28 }
50 29
51 30
52 31
53 $scope.newEvent = {}; 32 $scope.newEvent = {};
54 $scope.addNewEvent = function(){ 33 $scope.addNewEvent = function(){
55 //console.log('newEvent', $scope.newEvent); 34 //console.log('newEvent', $scope.newEvent);
56 $scope.showLoader = true; 35 $scope.showLoader = true;
57 if ($scope.newEvent.deployDate != undefined) { 36 if ($scope.newEvent.deployDate != undefined) {
58 $scope.newEvent.deployDate = new Date($scope.newEvent.deployDate); 37 $scope.newEvent.deployDate = new Date($scope.newEvent.deployDate);
59 $scope.newEvent.deployDate = $scope.newEvent.deployDate.getTime(); 38 $scope.newEvent.deployDate = $scope.newEvent.deployDate.getTime();
60 } 39 }
61 //var data = 'aircraft='+$scope.newEvent.aircraft+'&deployDate='+$scope.newEvent.deployDate; 40 //var data = 'aircraft='+$scope.newEvent.aircraft+'&deployDate='+$scope.newEvent.deployDate;
62 schedulerService.addNewEventService($scope.newEvent).then(function(response){ 41 schedulerService.addNewEventService($scope.newEvent).then(function(response){
63 $scope.newEvent = {}; 42 $scope.newEvent = {};
64 $('#addEvent').modal('hide'); 43 $('#addEvent').modal('hide');
65 $scope.events = []; 44 $scope.events = [];
66 getEventsList(); 45 getEventsList();
67 }) 46 })
68 } 47 }
69 48
70 $scope.cancelAdd = function(){ 49 $scope.cancelAdd = function(){
71 $scope.newEvent = {}; 50 $scope.newEvent = {};
72 } 51 }
73 52
74 $scope.editData = {}; 53 $scope.editData = {};
75 $scope.editEvent = function(data){ 54 $scope.editEvent = function(data){
76 $scope.editData = data; 55 $scope.editData = data;
77 $('#editEvent').modal('show'); 56 $('#editEvent').modal('show');
78 } 57 }
79 $scope.updateEvent = function(){ 58 $scope.updateEvent = function(){
80 $scope.showLoader = true; 59 $scope.showLoader = true;
81 $scope.updatedData = {}; 60 $scope.updatedData = {};
82 $scope.updatedData.id = $scope.editData.id; 61 $scope.updatedData.id = $scope.editData.id;
83 $scope.updatedData.deployDate = $scope.editData.start; 62 $scope.updatedData.deployDate = $scope.editData.start;
84 if ($scope.updatedData.deployDate != undefined) { 63 if ($scope.updatedData.deployDate != undefined) {
85 $scope.updatedData.deployDate = new Date($scope.updatedData.deployDate); 64 $scope.updatedData.deployDate = new Date($scope.updatedData.deployDate);
86 $scope.updatedData.deployDate = $scope.updatedData.deployDate.getTime(); 65 $scope.updatedData.deployDate = $scope.updatedData.deployDate.getTime();
87 } 66 }
88 schedulerService.updateScheduledEvent($scope.updatedData).then(function(response){ 67 schedulerService.updateScheduledEvent($scope.updatedData).then(function(response){
89 //console.log('response', response); 68 //console.log('response', response);
90 $scope.updatedData = {}; 69 $scope.updatedData = {};
91 $('#editEvent').modal('hide'); 70 $('#editEvent').modal('hide');
92 toastr.success('Updated Successfully', { 71 toastr.success('Updated Successfully', {
93 closeButton: true 72 closeButton: true
94 }) 73 })
95 $scope.events = []; 74 $scope.events = [];
96 getEventsList(); 75 getEventsList();
97 }) 76 })
98 } 77 }
99 78
100 79
101 /* code for calendar */ 80 /* code for calendar */
102 81
103 var date = new Date(); 82 var date = new Date();
104 var d = date.getDate(); 83 var d = date.getDate();
105 var m = date.getMonth(); 84 var m = date.getMonth();
106 var y = date.getFullYear(); 85 var y = date.getFullYear();
107 86
108 $scope.changeTo = 'Hungarian'; 87 $scope.changeTo = 'Hungarian';
109 88
110 $scope.eventSource = {}; 89 $scope.eventSource = {};
111 90
112 $scope.eventsF = function (start, end, timezone, callback) { 91 $scope.eventsF = function (start, end, timezone, callback) {
113 var s = new Date(start).getTime() / 1000; 92 var s = new Date(start).getTime() / 1000;
114 var e = new Date(end).getTime() / 1000; 93 var e = new Date(end).getTime() / 1000;
115 var m = new Date(start).getMonth(); 94 var m = new Date(start).getMonth();
116 var events = [{title: 'Feed Me ' + m,start: s + (50000),end: s + (100000),allDay: false, className: ['customFeed']}]; 95 var events = [{title: 'Feed Me ' + m,start: s + (50000),end: s + (100000),allDay: false, className: ['customFeed']}];
117 callback(events); 96 callback(events);
118 }; 97 };
119 98
120 $scope.calEventsExt = { 99 $scope.calEventsExt = {
121 color: '#f00', 100 color: '#f00',
122 textColor: 'yellow', 101 textColor: 'yellow',
123 events: [] 102 events: []
124 }; 103 };
125 104
126 $scope.alertOnEventClick = function( date, jsEvent, view){ 105 $scope.alertOnEventClick = function( date, jsEvent, view){
127 $scope.alertMessage = (date.title + ' was clicked '); 106 $scope.alertMessage = (date.title + ' was clicked ');
128 }; 107 };
129 108
130 $scope.alertOnDrop = function(event, delta, revertFunc, jsEvent, ui, view){ 109 $scope.alertOnDrop = function(event, delta, revertFunc, jsEvent, ui, view){
131 var dmonth = event.start._d.getUTCMonth() + 1; //months from 1-12 110 var dmonth = event.start._d.getUTCMonth() + 1; //months from 1-12
132 var dday = event.start._d.getUTCDate(); 111 var dday = event.start._d.getUTCDate();
133 var dyear = event.start._d.getUTCFullYear(); 112 var dyear = event.start._d.getUTCFullYear();
134 //console.log('date', dyear+'-'+dmonth+'-'+dday); 113 var setDeploy = new Date();
114 var hours = setDeploy.getHours();
115 var min = setDeploy.getMinutes();
116 var sec = setDeploy.getSeconds();
117
135 for (var i = 0; i < $scope.events.length; i++) { 118 for (var i = 0; i < $scope.events.length; i++) {
136 if ($scope.events[i].id == event.id) { 119 if ($scope.events[i].id == event.id) {
137 120
138 //console.log('events', $scope.events[i]); 121 //console.log('events', $scope.events[i]);
139 //$scope.events[i].start = dyear+'-'+dmonth+'-'+dday; 122 //$scope.events[i].start = dyear+'-'+dmonth+'-'+dday;
140 $scope.showLoader = true; 123 $scope.showLoader = true;
141 $scope.updatedDataDrop = {}; 124 $scope.updatedDataDrop = {};
142 $scope.updatedDataDrop.id = $scope.events[i].id; 125 $scope.updatedDataDrop.id = $scope.events[i].id;
143 $scope.updatedDataDrop.aircraft = $scope.events[i].title; 126 $scope.updatedDataDrop.aircraft = $scope.events[i].title;
144 $scope.updatedDataDrop.deployDate = dyear+'-'+dmonth+'-'+dday; 127 $scope.updatedDataDrop.deployDate = dyear+'-'+dmonth+'-'+dday + ' ' + hours + ':' + min + ':' + sec;
145 if ($scope.updatedDataDrop.deployDate != undefined) { 128 if ($scope.updatedDataDrop.deployDate != undefined) {
146 $scope.updatedDataDrop.deployDate = new Date($scope.updatedDataDrop.deployDate); 129 $scope.updatedDataDrop.deployDate = new Date($scope.updatedDataDrop.deployDate);
147 $scope.updatedDataDrop.deployDate = $scope.updatedDataDrop.deployDate.getTime(); 130 $scope.updatedDataDrop.deployDate = $scope.updatedDataDrop.deployDate.getTime();
148 } 131 }
149 schedulerService.updateScheduledEvent($scope.updatedDataDrop).then(function(response){ 132 schedulerService.updateScheduledEvent($scope.updatedDataDrop).then(function(response){
150 // console.log('response', response); 133 // console.log('response', response);
151 $scope.updatedDataDrop = {}; 134 $scope.updatedDataDrop = {};
152 $('#editEvent').modal('hide'); 135 $('#editEvent').modal('hide');
153 toastr.success('Updated Successfully', { 136 toastr.success('Updated Successfully', {
154 closeButton: true 137 closeButton: true
155 }) 138 })
156 $scope.events = []; 139 $scope.events = [];
157 getEventsList(); 140 getEventsList();
158 }) 141 })
159 142
160 } 143 }
161 } 144 }
162 //console.log('$scope.events new', $scope.events); 145 //console.log('$scope.events new', $scope.events);
163 $scope.alertMessage = ('Event Droped to make dayDelta ' + delta); 146 $scope.alertMessage = ('Event Droped to make dayDelta ' + delta);
164 }; 147 };
165 148
166 $scope.alertOnResize = function(event, delta, revertFunc, jsEvent, ui, view ){ 149 $scope.alertOnResize = function(event, delta, revertFunc, jsEvent, ui, view ){
167 $scope.alertMessage = ('Event Resized to make dayDelta ' + delta); 150 $scope.alertMessage = ('Event Resized to make dayDelta ' + delta);
168 }; 151 };
169 152
170 $scope.addRemoveEventSource = function(sources,source) { 153 $scope.addRemoveEventSource = function(sources,source) {
171 var canAdd = 0; 154 var canAdd = 0;
172 angular.forEach(sources,function(value, key){ 155 angular.forEach(sources,function(value, key){
173 if(sources[key] === source){ 156 if(sources[key] === source){
174 sources.splice(key,1); 157 sources.splice(key,1);
175 canAdd = 1; 158 canAdd = 1;
176 } 159 }
177 }); 160 });
178 if(canAdd === 0){ 161 if(canAdd === 0){
179 sources.push(source); 162 sources.push(source);
180 } 163 }
181 }; 164 };
182 165
183 $scope.addEvent = function() { 166 $scope.addEvent = function() {
184 $scope.events.push({ 167 $scope.events.push({
185 title: 'Open Sesame', 168 title: 'Open Sesame',
186 start: new Date(y, m, 28), 169 start: new Date(y, m, 28),
187 end: new Date(y, m, 29), 170 end: new Date(y, m, 29),
188 className: ['openSesame'] 171 className: ['openSesame']
189 }); 172 });
190 }; 173 };
191 174
192 $scope.remove = function(index) { 175 $scope.remove = function(index) {
193 $scope.events.splice(index,1); 176 $scope.events.splice(index,1);
194 }; 177 };
195 178
196 $scope.changeView = function(view,calendar) { 179 $scope.changeView = function(view,calendar) {
197 uiCalendarConfig.calendars[calendar].fullCalendar('changeView',view); 180 uiCalendarConfig.calendars[calendar].fullCalendar('changeView',view);
198 }; 181 };
199 182
200 $scope.renderCalender = function(calendar) { 183 $scope.renderCalender = function(calendar) {
201 if(uiCalendarConfig.calendars[calendar]){ 184 if(uiCalendarConfig.calendars[calendar]){
202 uiCalendarConfig.calendars[calendar].fullCalendar('render'); 185 uiCalendarConfig.calendars[calendar].fullCalendar('render');
203 } 186 }
204 }; 187 };
205 188
206 $scope.eventRender = function( event, element, view ) { 189 $scope.eventRender = function( event, element, view ) {
207 element.attr({'tooltip': event.title, 190 element.attr({'tooltip': event.title,
208 'tooltip-append-to-body': true}); 191 'tooltip-append-to-body': true});
209 $compile(element)($scope); 192 $compile(element)($scope);
210 }; 193 };
211 194
212 $scope.uiConfig = { 195 $scope.uiConfig = {
213 calendar:{ 196 calendar:{
214 height: 450, 197 height: 450,
215 editable: true, 198 editable: true,
216 droppable: true, 199 droppable: true,
217 drop: function (event, delta, revertFunc, jsEvent, ui, view) { 200 drop: function (event, delta, revertFunc, jsEvent, ui, view) {
218 }, 201 },
219 header:{ 202 header:{
220 right: 'month basicWeek basicDay', 203 right: 'month basicWeek basicDay',
221 center: 'title', 204 center: 'title',
222 left: 'prev,next, today' 205 left: 'prev,next, today'
223 }, 206 },
224 eventClick: $scope.alertOnEventClick, 207 eventClick: $scope.alertOnEventClick,
225 eventDrop: $scope.alertOnDrop, 208 eventDrop: $scope.alertOnDrop,
226 eventResize: $scope.alertOnResize, 209 eventResize: $scope.alertOnResize,
227 eventRender: $scope.eventRender 210 eventRender: $scope.eventRender
228 } 211 }
229 }; 212 };
230 213
231 $scope.addEvent = function(index) { 214 $scope.addEvent = function(index) {
232 //console.log('INDEX', index); 215 //console.log('INDEX', index);
233 //console.log('EVENTS', $scope.eventSources); 216 //console.log('EVENTS', $scope.eventSources);
234 // $scope.events.push($scope.eventList[index]); 217 // $scope.events.push($scope.eventList[index]);
235 } 218 }
236 219
237 /*$scope.showEventsList = function(){ 220 /*$scope.showEventsList = function(){
238 console.log('testing', $scope.eventsF); 221 console.log('testing', $scope.eventsF);
239 222
240 };*/ 223 };*/
241 224
242 // $scope.eventSources = [$scope.events, $scope.eventSource, $scope.eventsF]; 225 // $scope.eventSources = [$scope.events, $scope.eventSource, $scope.eventsF];
243 226