114 lines
2.6 KiB
JavaScript
114 lines
2.6 KiB
JavaScript
|
import ngModule from '../module';
|
||
|
import './style.scss';
|
||
|
|
||
|
class Controller {
|
||
|
constructor($scope, $http) {
|
||
|
this.$scope = $scope;
|
||
|
this.$http = $http;
|
||
|
this.months = this.monthsOfYear();
|
||
|
this.events = [];
|
||
|
this.eventMap = {};
|
||
|
}
|
||
|
|
||
|
get worker() {
|
||
|
return this._worker;
|
||
|
}
|
||
|
|
||
|
set worker(value) {
|
||
|
this._worker = value;
|
||
|
|
||
|
if (!value) return;
|
||
|
|
||
|
let params = {params: {
|
||
|
workerFk: this.worker.id,
|
||
|
started: this.started,
|
||
|
ended: this.ended
|
||
|
}};
|
||
|
|
||
|
let query = `/worker/api/WorkerCalendars/absences`;
|
||
|
this.$http.get(query, params).then(res => {
|
||
|
if (!res.data) return;
|
||
|
|
||
|
this.setHolidays(res.data);
|
||
|
this.setWorkerCalendar(res.data);
|
||
|
|
||
|
this.calendar = res.data.calendar;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
setHolidays(data) {
|
||
|
const holidays = data.holidays;
|
||
|
const events = [];
|
||
|
|
||
|
holidays.forEach(holiday => {
|
||
|
events.push({
|
||
|
date: holiday.dated,
|
||
|
className: 'red',
|
||
|
title: holiday.detail.description || holiday.type.name,
|
||
|
isRemovable: false
|
||
|
});
|
||
|
});
|
||
|
this.events = this.events.concat(events);
|
||
|
}
|
||
|
|
||
|
setWorkerCalendar(data) {
|
||
|
const absences = data.absences;
|
||
|
const events = [];
|
||
|
absences.forEach(absence => {
|
||
|
const absenceType = absence.absenceType;
|
||
|
events.push({
|
||
|
date: absence.dated,
|
||
|
title: absenceType.name,
|
||
|
style: {
|
||
|
background: absenceType.rgb
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
this.events = this.events.concat(events);
|
||
|
}
|
||
|
|
||
|
get started() {
|
||
|
const started = new Date();
|
||
|
started.setHours(0, 0, 0, 0);
|
||
|
started.setMonth(0);
|
||
|
started.setDate(1);
|
||
|
|
||
|
return started;
|
||
|
}
|
||
|
|
||
|
get ended() {
|
||
|
const monthIndex = 11;
|
||
|
const ended = new Date();
|
||
|
ended.setHours(0, 0, 0, 0);
|
||
|
ended.setMonth(monthIndex + 1);
|
||
|
// Last day of previous month (January)
|
||
|
ended.setDate(0);
|
||
|
|
||
|
return ended;
|
||
|
}
|
||
|
|
||
|
monthsOfYear() {
|
||
|
let months = new Array(12);
|
||
|
|
||
|
for (let i = 0; i < months.length; i++) {
|
||
|
const currentDate = new Date();
|
||
|
currentDate.setMonth(i);
|
||
|
currentDate.setDate(1);
|
||
|
|
||
|
months[i] = currentDate;
|
||
|
}
|
||
|
|
||
|
return months;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Controller.$inject = ['$scope', '$http'];
|
||
|
|
||
|
ngModule.component('vnWorkerCalendar', {
|
||
|
template: require('./index.html'),
|
||
|
controller: Controller,
|
||
|
bindings: {
|
||
|
worker: '<'
|
||
|
}
|
||
|
});
|