4856-worker.time-control #1375

Merged
joan merged 32 commits from 4856-worker.time-control into dev 2023-03-16 06:39:02 +00:00
5 changed files with 77 additions and 30 deletions
Showing only changes of commit 0396d3707c - Show all commits

View File

@ -160,7 +160,7 @@ export default class Calendar extends FormInput {
this.repaint();
this.emit('move', {$date: date});
this.getStates({$day: date});
this.getMailStates({$day: date});
vicent marked this conversation as resolved Outdated
Outdated
Review

Esta funció pareix específica de la secció que estás modificant. Calendar es un component genéric i deu de ser agnóstic al funcionament de la secció WorkerTimeControl

Esta funció pareix específica de la secció que estás modificant. Calendar es un component genéric i deu de ser agnóstic al funcionament de la secció WorkerTimeControl
}
/*
@ -237,7 +237,7 @@ ngModule.vnComponent('vnCalendar', {
bindings: {
defaultDate: '=?',
hasEvents: '&?',
getStates: '&?',
getMailStates: '&?',
getClass: '&?',
formatDay: '&?',
formatWeek: '&?',

View File

@ -0,0 +1,61 @@
module.exports = Self => {
Self.remoteMethodCtx('getMailStates', {
description: 'Get the states of a month about time control mail',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
description: 'The worker id',
http: {source: 'path'}
},
{
arg: 'month',
type: 'number',
description: 'The number of the month'
},
{
arg: 'year',
type: 'number',
description: 'The number of the year'
}],
returns: [{
type: ['object'],
root: true
}],
http: {
path: `/:id/getMailStates`,
verb: 'GET'
}
});
Self.getMailStates = async(ctx, workerId, options) => {
const models = Self.app.models;
const args = ctx.args;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const times = await models.Time.find({
fields: ['week'],
where: {
month: args.month,
year: args.year
}
}, myOptions);
const weeks = times.map(time => time.week);
const weekNumbersSet = new Set(weeks);
const weekNumbers = Array.from(weekNumbersSet);
const workerTimeControlMails = await models.WorkerTimeControlMail.find({
where: {
workerFk: workerId,
year: args.year,
week: {inq: weekNumbers}
}
}, myOptions);
return workerTimeControlMails;
};
};

View File

@ -8,6 +8,7 @@ module.exports = Self => {
require('../methods/worker-time-control/sendMail')(Self);
require('../methods/worker-time-control/updateWorkerTimeControlMail')(Self);
require('../methods/worker-time-control/weeklyHourRecordEmail')(Self);
require('../methods/worker-time-control/getMailStates')(Self);
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')

View File

@ -123,7 +123,7 @@
class="vn-pt-md"
ng-model="$ctrl.date"
format-week="$ctrl.formatWeek($element)"
get-states="$ctrl.getStates($day)"
get-mail-states="$ctrl.getMailStates($day)"
has-events="$ctrl.hasEvents($day)">
</vn-calendar>
</div>

View File

@ -26,7 +26,7 @@ class Controller extends Section {
this.date = initialDate;
this.getStates(this.date);
this.getMailStates(this.date);
}
get isHr() {
@ -355,7 +355,7 @@ class Controller extends Section {
};
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
this.$http.post(query, params).then(() => {
this.getStates(this.date);
this.getMailStates(this.date);
this.getWeekData();
this.vnApp.showSuccess(this.$t('Data saved!'));
});
@ -373,7 +373,7 @@ class Controller extends Section {
};
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
this.$http.post(query, params).then(() => {
this.getStates(this.date);
this.getMailStates(this.date);
this.getWeekData();
this.vnApp.showSuccess(this.$t('Data saved!'));
});
@ -421,32 +421,17 @@ class Controller extends Section {
return [parseInt(hours), parseInt(minutes), parseInt(seconds)];
}
getStates(day) {
const filterTime = {
fields: ['week'],
where: {
month: day.getMonth() + 1,
year: day.getFullYear()
}
getMailStates(day) {
const params = {
month: day.getMonth() + 1,
year: day.getFullYear()
};
this.$http.get('Times', {filter: filterTime})
const query = `WorkerTimeControls/${this.$params.id}/getMailStates`;
this.$http.get(query, {params})
.then(res => {
const weeks = res.data.map(time => time.week);
const weekNumbersSet = new Set(weeks);
const weekNumbers = Array.from(weekNumbersSet);
const filter = {
where: {
workerFk: this.$params.id,
year: day.getFullYear(),
week: {inq: weekNumbers}
}
};
this.$http.get('WorkerTimeControlMails', {filter})
.then(res => {
this.workerTimeControlMails = res.data;
this.repaint();
});
console.log(res.data);
this.workerTimeControlMails = res.data;
this.repaint();
});
}