refs #6119 microsip link added #1729
|
@ -52,6 +52,28 @@ class Controller extends Section {
|
||||||
|
|
||||||
set worker(value) {
|
set worker(value) {
|
||||||
this._worker = value;
|
this._worker = value;
|
||||||
|
this.fetchHours();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Worker hours data
|
||||||
|
*/
|
||||||
|
get hours() {
|
||||||
|
return this._hours;
|
||||||
|
}
|
||||||
|
|
||||||
|
set hours(value) {
|
||||||
|
this._hours = value;
|
||||||
|
|
||||||
|
for (const weekDay of this.weekDays) {
|
||||||
|
if (value) {
|
||||||
|
let day = weekDay.dated.getDay();
|
||||||
|
weekDay.hours = value
|
||||||
|
.filter(hour => new Date(hour.timed).getDay() == day)
|
||||||
|
.sort((a, b) => new Date(a.timed) - new Date(b.timed));
|
||||||
|
} else
|
||||||
|
weekDay.hours = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,10 +109,18 @@ class Controller extends Section {
|
||||||
dayIndex.setDate(dayIndex.getDate() + 1);
|
dayIndex.setDate(dayIndex.getDate() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fetchHours();
|
if (!this.weekTotalHours) this.fetchHours();
|
||||||
this.getWeekData();
|
this.getWeekData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set weekTotalHours(totalHours) {
|
||||||
|
this._weekTotalHours = this.formatHours(totalHours);
|
||||||
|
}
|
||||||
|
|
||||||
|
get weekTotalHours() {
|
||||||
|
return this._weekTotalHours;
|
||||||
|
}
|
||||||
|
|
||||||
getWeekData() {
|
getWeekData() {
|
||||||
const filter = {
|
const filter = {
|
||||||
where: {
|
where: {
|
||||||
|
@ -101,38 +131,19 @@ class Controller extends Section {
|
||||||
};
|
};
|
||||||
this.$http.get('WorkerTimeControlMails', {filter})
|
this.$http.get('WorkerTimeControlMails', {filter})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const workerTimeControlMail = res.data;
|
const mail = res.data;
|
||||||
if (!workerTimeControlMail.length) {
|
if (!mail.length) {
|
||||||
this.state = null;
|
this.state = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.state = workerTimeControlMail[0].state;
|
this.state = mail[0].state;
|
||||||
this.reason = workerTimeControlMail[0].reason;
|
this.reason = mail[0].reason;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Worker hours data
|
|
||||||
*/
|
|
||||||
get hours() {
|
|
||||||
return this._hours;
|
|
||||||
}
|
|
||||||
|
|
||||||
set hours(value) {
|
|
||||||
this._hours = value;
|
|
||||||
|
|
||||||
for (const weekDay of this.weekDays) {
|
|
||||||
if (value) {
|
|
||||||
let day = weekDay.dated.getDay();
|
|
||||||
weekDay.hours = value
|
|
||||||
.filter(hour => new Date(hour.timed).getDay() == day)
|
|
||||||
.sort((a, b) => new Date(a.timed) - new Date(b.timed));
|
|
||||||
} else
|
|
||||||
weekDay.hours = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchHours() {
|
fetchHours() {
|
||||||
|
if (!this.worker || !this.date) return;
|
||||||
|
|
||||||
const params = {workerFk: this.$params.id};
|
const params = {workerFk: this.$params.id};
|
||||||
const filter = {
|
const filter = {
|
||||||
where: {and: [
|
where: {and: [
|
||||||
|
@ -148,58 +159,6 @@ class Controller extends Section {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
hasEvents(day) {
|
|
||||||
return day >= this.started && day < this.ended;
|
|
||||||
}
|
|
||||||
|
|
||||||
getAbsences() {
|
|
||||||
const fullYear = this.started.getFullYear();
|
|
||||||
let params = {
|
|
||||||
workerFk: this.$params.id,
|
|
||||||
businessFk: null,
|
|
||||||
year: fullYear
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.$http.get(`Calendars/absences`, {params})
|
|
||||||
.then(res => this.onData(res.data));
|
|
||||||
}
|
|
||||||
|
|
||||||
onData(data) {
|
|
||||||
const events = {};
|
|
||||||
|
|
||||||
const addEvent = (day, event) => {
|
|
||||||
events[new Date(day).getTime()] = event;
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
addEvent(holiday.dated, {
|
|
||||||
name: holidayName,
|
|
||||||
color: '#ff0'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (data.absences) {
|
|
||||||
data.absences.forEach(absence => {
|
|
||||||
const type = absence.absenceType;
|
|
||||||
addEvent(absence.dated, {
|
|
||||||
name: type.name,
|
|
||||||
color: type.rgb
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.weekDays.forEach(day => {
|
|
||||||
const timestamp = day.dated.getTime();
|
|
||||||
if (events[timestamp])
|
|
||||||
day.event = events[timestamp];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getWorkedHours(from, to) {
|
getWorkedHours(from, to) {
|
||||||
this.weekTotalHours = null;
|
this.weekTotalHours = null;
|
||||||
let weekTotalHours = 0;
|
let weekTotalHours = 0;
|
||||||
|
@ -239,6 +198,58 @@ class Controller extends Section {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAbsences() {
|
||||||
|
const fullYear = this.started.getFullYear();
|
||||||
|
let params = {
|
||||||
|
workerFk: this.$params.id,
|
||||||
|
businessFk: null,
|
||||||
|
year: fullYear
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.$http.get(`Calendars/absences`, {params})
|
||||||
|
.then(res => this.onData(res.data));
|
||||||
|
}
|
||||||
|
|
||||||
|
hasEvents(day) {
|
||||||
|
return day >= this.started && day < this.ended;
|
||||||
|
}
|
||||||
|
|
||||||
|
onData(data) {
|
||||||
|
const events = {};
|
||||||
|
|
||||||
|
const addEvent = (day, event) => {
|
||||||
|
events[new Date(day).getTime()] = event;
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
addEvent(holiday.dated, {
|
||||||
|
name: holidayName,
|
||||||
|
color: '#ff0'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data.absences) {
|
||||||
|
data.absences.forEach(absence => {
|
||||||
|
const type = absence.absenceType;
|
||||||
|
addEvent(absence.dated, {
|
||||||
|
name: type.name,
|
||||||
|
color: type.rgb
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.weekDays.forEach(day => {
|
||||||
|
const timestamp = day.dated.getTime();
|
||||||
|
if (events[timestamp])
|
||||||
|
day.event = events[timestamp];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getFinishTime() {
|
getFinishTime() {
|
||||||
if (!this.weekDays) return;
|
if (!this.weekDays) return;
|
||||||
|
|
||||||
|
@ -267,14 +278,6 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set weekTotalHours(totalHours) {
|
|
||||||
this._weekTotalHours = this.formatHours(totalHours);
|
|
||||||
}
|
|
||||||
|
|
||||||
get weekTotalHours() {
|
|
||||||
return this._weekTotalHours;
|
|
||||||
}
|
|
||||||
|
|
||||||
formatHours(timestamp = 0) {
|
formatHours(timestamp = 0) {
|
||||||
let hour = Math.floor(timestamp / 3600);
|
let hour = Math.floor(timestamp / 3600);
|
||||||
let min = Math.floor(timestamp / 60 - 60 * hour);
|
let min = Math.floor(timestamp / 60 - 60 * hour);
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe('Component vnWorkerTimeControl', () => {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('date() setter', () => {
|
describe('date() setter', () => {
|
||||||
it(`should set the weekDays, the date in the controller and call fetchHours`, () => {
|
it(`should set the weekDays and the date in the controller`, () => {
|
||||||
let today = Date.vnNew();
|
let today = Date.vnNew();
|
||||||
jest.spyOn(controller, 'fetchHours').mockReturnThis();
|
jest.spyOn(controller, 'fetchHours').mockReturnThis();
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@ describe('Component vnWorkerTimeControl', () => {
|
||||||
expect(controller.started).toBeDefined();
|
expect(controller.started).toBeDefined();
|
||||||
expect(controller.ended).toBeDefined();
|
expect(controller.ended).toBeDefined();
|
||||||
expect(controller.weekDays.length).toEqual(7);
|
expect(controller.weekDays.length).toEqual(7);
|
||||||
expect(controller.fetchHours).toHaveBeenCalledWith();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue