2019-03-22 07:28:57 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
|
|
|
constructor($scope, $http) {
|
|
|
|
this.$scope = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.months = this.monthsOfYear();
|
|
|
|
this.events = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2019-03-22 11:51:44 +00:00
|
|
|
if (!data.holidays) return;
|
|
|
|
|
2019-03-22 07:28:57 +00:00
|
|
|
const holidays = data.holidays;
|
|
|
|
const events = [];
|
|
|
|
holidays.forEach(holiday => {
|
2019-04-30 09:43:26 +00:00
|
|
|
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
|
|
|
events.push({
|
2019-04-03 09:34:58 +00:00
|
|
|
dated: holiday.dated,
|
2019-03-22 07:28:57 +00:00
|
|
|
className: 'red',
|
2019-04-30 09:43:26 +00:00
|
|
|
title: holidayName,
|
2019-03-22 07:28:57 +00:00
|
|
|
isRemovable: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.events = this.events.concat(events);
|
|
|
|
}
|
|
|
|
|
|
|
|
setWorkerCalendar(data) {
|
2019-03-22 11:51:44 +00:00
|
|
|
if (!data.absences) return;
|
|
|
|
|
2019-03-22 07:28:57 +00:00
|
|
|
const absences = data.absences;
|
|
|
|
const events = [];
|
|
|
|
absences.forEach(absence => {
|
|
|
|
const absenceType = absence.absenceType;
|
|
|
|
events.push({
|
2019-04-03 09:34:58 +00:00
|
|
|
dated: absence.dated,
|
2019-03-22 07:28:57 +00:00
|
|
|
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++) {
|
2019-03-22 11:51:44 +00:00
|
|
|
const now = new Date();
|
|
|
|
now.setHours(0, 0, 0, 0);
|
|
|
|
now.setMonth(i);
|
|
|
|
now.setDate(1);
|
2019-03-22 07:28:57 +00:00
|
|
|
|
2019-03-22 11:51:44 +00:00
|
|
|
months[i] = now;
|
2019-03-22 07:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return months;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$scope', '$http'];
|
|
|
|
|
|
|
|
ngModule.component('vnWorkerCalendar', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
worker: '<'
|
|
|
|
}
|
|
|
|
});
|