2019-03-22 07:28:57 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2019-10-23 15:38:35 +00:00
|
|
|
constructor($element, $http) {
|
|
|
|
this.element = $element[0];
|
2019-03-22 07:28:57 +00:00
|
|
|
this.$http = $http;
|
2019-10-23 15:38:35 +00:00
|
|
|
this.date = new Date();
|
|
|
|
this.events = {};
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
get date() {
|
|
|
|
return this._date;
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
set date(value) {
|
|
|
|
this._date = value;
|
|
|
|
value.setHours(0, 0, 0, 0);
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
const started = new Date(value.getTime());
|
|
|
|
started.setMonth(0);
|
|
|
|
started.setDate(1);
|
|
|
|
this.started = started;
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
const ended = new Date(value.getTime());
|
|
|
|
ended.setMonth(12);
|
|
|
|
ended.setDate(0);
|
|
|
|
this.ended = ended;
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
this.months = new Array(12);
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
for (let i = 0; i < this.months.length; i++) {
|
|
|
|
const now = new Date(value.getTime());
|
|
|
|
now.setDate(1);
|
|
|
|
now.setMonth(i);
|
|
|
|
this.months[i] = now;
|
|
|
|
}
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
get worker() {
|
|
|
|
return this._worker;
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
set worker(value) {
|
|
|
|
this._worker = value;
|
|
|
|
if (!value) return;
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
let params = {
|
|
|
|
workerFk: this.worker.id,
|
|
|
|
started: this.started,
|
|
|
|
ended: this.ended
|
|
|
|
};
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.get(`WorkerCalendars/absences`, {params})
|
2019-10-23 15:38:35 +00:00
|
|
|
.then(res => this.onData(res.data));
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
onData(data) {
|
|
|
|
this.events = {};
|
|
|
|
this.calendar = data.calendar;
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
let addEvent = (day, event) => {
|
|
|
|
this.events[new Date(day).getTime()] = event;
|
|
|
|
};
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
if (data.holidays) {
|
|
|
|
data.holidays.forEach(holiday => {
|
|
|
|
const holidayDetail = holiday.detail && holiday.detail.description;
|
|
|
|
const holidayType = holiday.type && holiday.type.name;
|
|
|
|
const holidayName = holidayDetail || holidayType;
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
addEvent(holiday.dated, {
|
|
|
|
name: holidayName,
|
|
|
|
color: '#ff0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (data.absences) {
|
|
|
|
data.absences.forEach(absence => {
|
|
|
|
let type = absence.absenceType;
|
|
|
|
addEvent(absence.dated, {
|
|
|
|
name: type.name,
|
|
|
|
color: type.rgb
|
|
|
|
});
|
|
|
|
});
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
this.repaint();
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
2019-05-10 11:16:37 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
repaint() {
|
|
|
|
let calendars = this.element.querySelectorAll('vn-calendar');
|
|
|
|
for (let calendar of calendars)
|
|
|
|
calendar.$ctrl.repaint();
|
2019-05-10 11:16:37 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
formatDay(day, element) {
|
|
|
|
let event = this.events[day.getTime()];
|
|
|
|
if (!event) return;
|
|
|
|
|
|
|
|
let dayNumber = element.firstElementChild;
|
|
|
|
dayNumber.title = event.name;
|
|
|
|
dayNumber.style.backgroundColor = event.color;
|
2019-11-15 09:03:46 +00:00
|
|
|
dayNumber.style.color = 'rgba(0, 0, 0, 0.7)';
|
2019-05-10 11:16:37 +00:00
|
|
|
}
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
2019-10-23 15:38:35 +00:00
|
|
|
Controller.$inject = ['$element', '$http'];
|
2019-03-22 07:28:57 +00:00
|
|
|
|
|
|
|
ngModule.component('vnWorkerCalendar', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
worker: '<'
|
|
|
|
}
|
|
|
|
});
|