Blame view

app/partials/scheduler/scheduler.controller.js 7.66 KB
feacde5ff   Rishav   setup acuefuel in...
1
  'use strict';
a55ef20b5   Swarn Singh   schedular added
2
  angular.module('acufuel')
feacde5ff   Rishav   setup acuefuel in...
3

4728ddfdd   Swarn Singh   schedule module f...
4
  .controller('schedulerController', ['$scope','$compile', 'uiCalendarConfig', 'schedulerService', function($scope, $compile, uiCalendarConfig, schedulerService) {
a49ef5361   Kuldeep Arora   dashboard & Sched...
5
      
4728ddfdd   Swarn Singh   schedule module f...
6
    $scope.showLoader = true;
a49ef5361   Kuldeep Arora   dashboard & Sched...
7
8
9
     getEventsList();
    
    /*---get events on calendar---*/
4728ddfdd   Swarn Singh   schedule module f...
10
11
12
    $scope.events = [];
    function getEventsList(){
      schedulerService.getEvents().then(function(result) {
a49ef5361   Kuldeep Arora   dashboard & Sched...
13
      	//console.log('----kd events-------',result);
565570086   Kuldeep Arora   highcharts(MFS,CS...
14
15
      	//console.log("==length===",result.length);
        
4728ddfdd   Swarn Singh   schedule module f...
16
17
        for (var i = 0; i < result.length; i++) {
          var newTime = new Date(result[i].deployDate);
961a97a2f   Kuldeep Arora   Enhancement in de...
18
         // console.log("deployDate",result[i].deployDate)
4728ddfdd   Swarn Singh   schedule module f...
19
          var dmonth = newTime.getUTCMonth() + 1; //months from 1-12
961a97a2f   Kuldeep Arora   Enhancement in de...
20
          var dday = newTime.getUTCDate()+1;
4728ddfdd   Swarn Singh   schedule module f...
21
          var dyear = newTime.getUTCFullYear();
961a97a2f   Kuldeep Arora   Enhancement in de...
22
        //  console.log("--date--",dday)
4728ddfdd   Swarn Singh   schedule module f...
23
24
          $scope.events.push({
            'id': result[i].id,
a49ef5361   Kuldeep Arora   dashboard & Sched...
25
26
27
            'title': result[i].aircraft +',
  ' + result[i].make +'/' + result[i].model +',
  ' + result[i].requestedVolume +',' +result[i].priceQuote,
4728ddfdd   Swarn Singh   schedule module f...
28
            'start': dyear+'-'+dmonth+'-'+dday
961a97a2f   Kuldeep Arora   Enhancement in de...
29
              
4728ddfdd   Swarn Singh   schedule module f...
30
          })
a49ef5361   Kuldeep Arora   dashboard & Sched...
31
        //  $scope.showEventsList();
961a97a2f   Kuldeep Arora   Enhancement in de...
32
          //console.log('==kd events after push===', $scope.events)
a49ef5361   Kuldeep Arora   dashboard & Sched...
33
34
35
           $scope.showLoader = false;
          
       }
565570086   Kuldeep Arora   highcharts(MFS,CS...
36
   
961a97a2f   Kuldeep Arora   Enhancement in de...
37
38
          $('#my-calendar').fullCalendar('removeEvents');
          $('#my-calendar').fullCalendar('addEventSource',$scope.events);
a49ef5361   Kuldeep Arora   dashboard & Sched...
39
40
41
42
43
44
      // $scope.eventSources = [$scope.events, $scope.eventSource, $scope.eventsF];
      
         // console.log('==eventSource are====',$scope.eventSources);      
      // $scope.newFuelPricing[i].futureFuelPricing.deployDate = dmonth+'/'+dday+'/'+dyear;
     })
  }
4728ddfdd   Swarn Singh   schedule module f...
45

4728ddfdd   Swarn Singh   schedule module f...
46
47
48
  
    $scope.newEvent = {};
    $scope.addNewEvent = function(){
565570086   Kuldeep Arora   highcharts(MFS,CS...
49
      //console.log('newEvent', $scope.newEvent);
4728ddfdd   Swarn Singh   schedule module f...
50
51
52
53
54
55
56
      $scope.showLoader = true;
      if ($scope.newEvent.deployDate != undefined) {
        $scope.newEvent.deployDate = new Date($scope.newEvent.deployDate);
        $scope.newEvent.deployDate = $scope.newEvent.deployDate.getTime();
      }
      //var data = 'aircraft='+$scope.newEvent.aircraft+'&deployDate='+$scope.newEvent.deployDate;
      schedulerService.addNewEventService($scope.newEvent).then(function(response){
4728ddfdd   Swarn Singh   schedule module f...
57
58
        $scope.newEvent = {};
        $('#addEvent').modal('hide');
c622f8e75   Swarn Singh   drog-drop and upd...
59
        $scope.events = [];
4728ddfdd   Swarn Singh   schedule module f...
60
61
62
63
64
65
66
        getEventsList();
      })
    }
  
    $scope.cancelAdd = function(){
      $scope.newEvent = {};
    }
956e0d9ed   Swarn Singh   contact view effe...
67

4728ddfdd   Swarn Singh   schedule module f...
68
69
    $scope.editData = {};
    $scope.editEvent = function(data){
4728ddfdd   Swarn Singh   schedule module f...
70
      $scope.editData = data;
4728ddfdd   Swarn Singh   schedule module f...
71
      $('#editEvent').modal('show');
4728ddfdd   Swarn Singh   schedule module f...
72
    }
956e0d9ed   Swarn Singh   contact view effe...
73
74
75
76
77
78
79
80
81
82
83
    $scope.updateEvent = function(){
      $scope.showLoader = true;
      $scope.updatedData = {};
      $scope.updatedData.id = $scope.editData.id;
      $scope.updatedData.aircraft = $scope.editData.title;
      $scope.updatedData.deployDate = $scope.editData.start;
      if ($scope.updatedData.deployDate != undefined) {
        $scope.updatedData.deployDate = new Date($scope.updatedData.deployDate);
        $scope.updatedData.deployDate = $scope.updatedData.deployDate.getTime();
      }
      schedulerService.updateScheduledEvent($scope.updatedData).then(function(response){
565570086   Kuldeep Arora   highcharts(MFS,CS...
84
        //console.log('response', response);
956e0d9ed   Swarn Singh   contact view effe...
85
86
87
88
89
        $scope.updatedData = {};
        $('#editEvent').modal('hide');
        toastr.success('Updated Successfully', {
          closeButton: true
        })
c622f8e75   Swarn Singh   drog-drop and upd...
90
        $scope.events = [];
956e0d9ed   Swarn Singh   contact view effe...
91
92
93
        getEventsList();
      })
    }
4728ddfdd   Swarn Singh   schedule module f...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  
  
    /*  code for calendar  */
  
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
  
    $scope.changeTo = 'Hungarian';
  
    $scope.eventSource = {};
  
    $scope.eventsF = function (start, end, timezone, callback) {
      var s = new Date(start).getTime() / 1000;
      var e = new Date(end).getTime() / 1000;
      var m = new Date(start).getMonth();
      var events = [{title: 'Feed Me ' + m,start: s + (50000),end: s + (100000),allDay: false, className: ['customFeed']}];
      callback(events);
    };
  
    $scope.calEventsExt = {
     color: '#f00',
     textColor: 'yellow',
     events: []
   };
  
   $scope.alertOnEventClick = function( date, jsEvent, view){
    $scope.alertMessage = (date.title + ' was clicked ');
  };
  
  $scope.alertOnDrop = function(event, delta, revertFunc, jsEvent, ui, view){
        var dmonth = event.start._d.getUTCMonth() + 1; //months from 1-12
        var dday = event.start._d.getUTCDate();
        var dyear = event.start._d.getUTCFullYear();
565570086   Kuldeep Arora   highcharts(MFS,CS...
129
        //console.log('date', dyear+'-'+dmonth+'-'+dday);
4728ddfdd   Swarn Singh   schedule module f...
130
131
        for (var i = 0; i < $scope.events.length; i++) {
          if ($scope.events[i].id == event.id) {
c622f8e75   Swarn Singh   drog-drop and upd...
132

565570086   Kuldeep Arora   highcharts(MFS,CS...
133
            //console.log('events', $scope.events[i]);
c622f8e75   Swarn Singh   drog-drop and upd...
134
135
136
137
138
139
140
141
142
143
144
            //$scope.events[i].start = dyear+'-'+dmonth+'-'+dday;
            $scope.showLoader = true;
            $scope.updatedDataDrop = {};
            $scope.updatedDataDrop.id = $scope.events[i].id;
            $scope.updatedDataDrop.aircraft = $scope.events[i].title;
            $scope.updatedDataDrop.deployDate = dyear+'-'+dmonth+'-'+dday;
            if ($scope.updatedDataDrop.deployDate != undefined) {
              $scope.updatedDataDrop.deployDate = new Date($scope.updatedDataDrop.deployDate);
              $scope.updatedDataDrop.deployDate = $scope.updatedDataDrop.deployDate.getTime();
            }
            schedulerService.updateScheduledEvent($scope.updatedDataDrop).then(function(response){
565570086   Kuldeep Arora   highcharts(MFS,CS...
145
             // console.log('response', response);
c622f8e75   Swarn Singh   drog-drop and upd...
146
147
148
149
150
151
152
153
              $scope.updatedDataDrop = {};
              $('#editEvent').modal('hide');
              toastr.success('Updated Successfully', {
                closeButton: true
              })
              $scope.events = [];
              getEventsList();
            })
a55ef20b5   Swarn Singh   schedular added
154
          }
03cf7c388   Swarn Singh   minor changes due...
155
        }
565570086   Kuldeep Arora   highcharts(MFS,CS...
156
        //console.log('$scope.events new', $scope.events);
4728ddfdd   Swarn Singh   schedule module f...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
        $scope.alertMessage = ('Event Droped to make dayDelta ' + delta);
      };
      
      $scope.alertOnResize = function(event, delta, revertFunc, jsEvent, ui, view ){
       $scope.alertMessage = ('Event Resized to make dayDelta ' + delta);
     };
  
     $scope.addRemoveEventSource = function(sources,source) {
      var canAdd = 0;
      angular.forEach(sources,function(value, key){
        if(sources[key] === source){
          sources.splice(key,1);
          canAdd = 1;
        }
      });
      if(canAdd === 0){
        sources.push(source);
      }
    };
  
    $scope.addEvent = function() {
      $scope.events.push({
        title: 'Open Sesame',
        start: new Date(y, m, 28),
        end: new Date(y, m, 29),
        className: ['openSesame']
      });
    };
  
    $scope.remove = function(index) {
      $scope.events.splice(index,1);
    };
  
    $scope.changeView = function(view,calendar) {
      uiCalendarConfig.calendars[calendar].fullCalendar('changeView',view);
    };
  
    $scope.renderCalender = function(calendar) {
      if(uiCalendarConfig.calendars[calendar]){
        uiCalendarConfig.calendars[calendar].fullCalendar('render');
      }
    };
  
    $scope.eventRender = function( event, element, view ) { 
      element.attr({'tooltip': event.title,
       'tooltip-append-to-body': true});
      $compile(element)($scope);
    };
  
    $scope.uiConfig = {
      calendar:{
        height: 450,
        editable: true,
        droppable: true,
        drop: function (event, delta, revertFunc, jsEvent, ui, view) {
        },
        header:{
          right: 'month basicWeek basicDay',
          center: 'title',
          left: 'prev,next, today'
        },
        eventClick: $scope.alertOnEventClick,
        eventDrop: $scope.alertOnDrop,
        eventResize: $scope.alertOnResize,
        eventRender: $scope.eventRender
      }
    };
  
    $scope.addEvent = function(index) {
      //console.log('INDEX', index);
      //console.log('EVENTS', $scope.eventSources);
a49ef5361   Kuldeep Arora   dashboard & Sched...
228
      // $scope.events.push($scope.eventList[index]);
4728ddfdd   Swarn Singh   schedule module f...
229
    }
a49ef5361   Kuldeep Arora   dashboard & Sched...
230
231
232
233
234
   
    /*$scope.showEventsList = function(){
      console.log('testing', $scope.eventsF);
      
    };*/
961a97a2f   Kuldeep Arora   Enhancement in de...
235
236
  
    // $scope.eventSources = [$scope.events, $scope.eventSource, $scope.eventsF];
a49ef5361   Kuldeep Arora   dashboard & Sched...
237
      
961a97a2f   Kuldeep Arora   Enhancement in de...
238
      //$scope.eventSources2 = [$scope.calEventsExt, $scope.eventsF, $scope.events];
4728ddfdd   Swarn Singh   schedule module f...
239
  }]);
feacde5ff   Rishav   setup acuefuel in...
240