2018-12-04 12:18:27 +00:00
|
|
|
import ngModule from '../module';
|
2018-09-24 12:51:27 +00:00
|
|
|
|
|
|
|
class Controller {
|
2019-01-21 10:45:53 +00:00
|
|
|
constructor($scope, $stateParams, $http) {
|
|
|
|
this.$stateParams = $stateParams;
|
2018-09-24 12:51:27 +00:00
|
|
|
this.$scope = $scope;
|
2019-01-21 10:45:53 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.stMonthDate = new Date();
|
|
|
|
this.ndMonthDate = new Date();
|
|
|
|
this.ndMonthDate.setMonth(this.ndMonthDate.getMonth() + 1);
|
|
|
|
this.events = [];
|
2018-11-12 10:31:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 10:45:53 +00:00
|
|
|
$postLink() {
|
|
|
|
this.stMonth = this.$scope.stMonth;
|
|
|
|
this.ndMonth = this.$scope.ndMonth;
|
|
|
|
}
|
|
|
|
|
|
|
|
get zone() {
|
|
|
|
return this._zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
set zone(value) {
|
|
|
|
this._zone = value;
|
|
|
|
|
|
|
|
if (!value) return;
|
|
|
|
|
|
|
|
let query = '/agency/api/LabourHolidays/getByWarehouse';
|
|
|
|
this.$http.get(query, {params: {warehouseFk: value.warehouseFk}}).then(res => {
|
|
|
|
if (!res.data) return;
|
|
|
|
const events = [];
|
|
|
|
res.data.forEach(holiday => {
|
|
|
|
events.push({
|
|
|
|
date: holiday.dated,
|
|
|
|
color: 'blue-circle',
|
|
|
|
title: holiday.description || holiday.name,
|
|
|
|
isRemovable: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.events = this.events.concat(events);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
return this._data;
|
|
|
|
}
|
|
|
|
|
|
|
|
set data(value) {
|
|
|
|
this._data = value;
|
|
|
|
|
|
|
|
if (!value) return;
|
|
|
|
|
|
|
|
const events = [];
|
|
|
|
value.forEach(event => {
|
|
|
|
events.push({
|
|
|
|
date: event.delivered,
|
|
|
|
color: 'green-circle',
|
|
|
|
title: 'Has delivery',
|
|
|
|
isRemovable: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.events = this.events.concat(events);
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelection(calendar, values) {
|
|
|
|
let totalEvents = 0;
|
|
|
|
values.forEach(day => {
|
|
|
|
const exists = this.events.findIndex(event => {
|
|
|
|
return event.date >= day.date && event.date <= day.date
|
|
|
|
&& event.isRemovable;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (exists > -1) totalEvents++;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (totalEvents > (values.length / 2))
|
|
|
|
this.removeEvents(values);
|
|
|
|
else
|
|
|
|
this.addEvents(values);
|
|
|
|
}
|
|
|
|
|
|
|
|
addEvents(days) {
|
|
|
|
days.forEach(day => {
|
|
|
|
const event = this.events.find(event => {
|
|
|
|
return event.date >= day.date && event.date <= day.date;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
this.$scope.model.insert({
|
|
|
|
zoneFk: this.zone.id,
|
|
|
|
delivered: day.date
|
|
|
|
});
|
|
|
|
|
|
|
|
this.stMonth.addEvent(day.date, 'green-circle', 'Has delivery', true);
|
|
|
|
this.stMonth.repaint();
|
|
|
|
this.ndMonth.addEvent(day.date, 'green-circle', 'Has delivery', true);
|
|
|
|
this.ndMonth.repaint();
|
|
|
|
});
|
|
|
|
this.$scope.model.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
removeEvents(days) {
|
|
|
|
let dates = [];
|
|
|
|
days.forEach(day => {
|
|
|
|
const event = this.events.find(event => {
|
|
|
|
return event.date >= day.date && event.date <= day.date;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (event && !event.isRemovable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// FIXME - Date offset
|
|
|
|
let date = new Date(day.date);
|
|
|
|
date.setHours(0, 0, 0, 0);
|
|
|
|
dates.push(date);
|
|
|
|
|
|
|
|
this.stMonth.removeEvent(day.date);
|
|
|
|
this.stMonth.repaint();
|
|
|
|
this.ndMonth.removeEvent(day.date);
|
|
|
|
this.ndMonth.repaint();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (dates.length == 0) return;
|
|
|
|
const params = {zoneFk: this.zone.id, dates};
|
|
|
|
this.$http.post('/agency/api/zoneCalendars/removeByDate', params);
|
|
|
|
}
|
|
|
|
|
|
|
|
onMoveNext(calendar) {
|
|
|
|
calendar.moveNext(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
onMovePrevious(calendar) {
|
|
|
|
calendar.movePrevious(2);
|
2018-09-24 12:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 10:45:53 +00:00
|
|
|
Controller.$inject = ['$scope', '$stateParams', '$http'];
|
2018-09-24 12:51:27 +00:00
|
|
|
|
|
|
|
ngModule.component('vnZoneCalendar', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
zone: '<'
|
|
|
|
}
|
|
|
|
});
|