Added absence selection
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
778c38df89
commit
dd8e03dd0f
|
@ -0,0 +1,11 @@
|
||||||
|
USE `vn`;
|
||||||
|
CREATE
|
||||||
|
OR REPLACE ALGORITHM = UNDEFINED
|
||||||
|
DEFINER = `root`@`%`
|
||||||
|
SQL SECURITY DEFINER
|
||||||
|
VIEW `workerCalendar2` AS
|
||||||
|
SELECT
|
||||||
|
`ce`.`business_id` AS `businessFk`,
|
||||||
|
`ce`.`calendar_state_id` AS `absenceTypeFk`,
|
||||||
|
`ce`.`date` AS `dated`
|
||||||
|
FROM `postgresql`.`calendar_employee` `ce`;
|
|
@ -0,0 +1,101 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('createAbsences', {
|
||||||
|
description: 'Returns an array of absences from an specified worker',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The worker id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'absenceTypeId',
|
||||||
|
type: 'Number',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'dated',
|
||||||
|
type: 'Date',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'started',
|
||||||
|
type: 'Date',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'ended',
|
||||||
|
type: 'Date',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'type',
|
||||||
|
type: 'String',
|
||||||
|
required: true
|
||||||
|
}],
|
||||||
|
returns: 'Object',
|
||||||
|
http: {
|
||||||
|
path: `/:id/createAbsences`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.createAbsences = async(ctx, id, absenceTypeId, dated, started, ended, type) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const isSubordinate = await models.Worker.isSubordinate(ctx, id);
|
||||||
|
|
||||||
|
if (!isSubordinate)
|
||||||
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
|
const absences = [];
|
||||||
|
|
||||||
|
if (type == 'day') {
|
||||||
|
const contracts = await models.WorkerLabour.find({
|
||||||
|
where: {
|
||||||
|
and: [
|
||||||
|
{workerFk: id},
|
||||||
|
{or: [{
|
||||||
|
ended: {gte: [yearStarted]}
|
||||||
|
}, {ended: null}]}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
absences.push({
|
||||||
|
businessFk: 106,
|
||||||
|
absenceTypeFk: absenceTypeId,
|
||||||
|
dated: dated
|
||||||
|
});
|
||||||
|
} else if (type == 'range')
|
||||||
|
console.log(true);
|
||||||
|
|
||||||
|
return models.WorkerCalendar.create(absences);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/* include: [{
|
||||||
|
relation: 'holidays',
|
||||||
|
scope: {
|
||||||
|
where: {year}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'workCenter',
|
||||||
|
scope: {
|
||||||
|
include: {
|
||||||
|
relation: 'holidays',
|
||||||
|
scope: {
|
||||||
|
include: [{
|
||||||
|
relation: 'detail'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'type'
|
||||||
|
}],
|
||||||
|
where: {
|
||||||
|
dated: {between: [yearStarted, yearEnded]}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}], */
|
|
@ -3,7 +3,7 @@
|
||||||
"base": "VnModel",
|
"base": "VnModel",
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "workerCalendar"
|
"table": "workerCalendar2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -11,21 +11,12 @@
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"type": "Number"
|
"type": "Number"
|
||||||
},
|
},
|
||||||
"workerFk": {
|
|
||||||
"id": 2,
|
|
||||||
"type": "Number"
|
|
||||||
},
|
|
||||||
"dated": {
|
"dated": {
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"type": "Date"
|
"type": "Date"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
"worker": {
|
|
||||||
"type": "belongsTo",
|
|
||||||
"model": "Worker",
|
|
||||||
"foreignKey": "workerFk"
|
|
||||||
},
|
|
||||||
"absenceType": {
|
"absenceType": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "AbsenceType",
|
"model": "AbsenceType",
|
||||||
|
|
|
@ -4,4 +4,5 @@ module.exports = Self => {
|
||||||
require('../methods/worker/isSubordinate')(Self);
|
require('../methods/worker/isSubordinate')(Self);
|
||||||
require('../methods/worker/getWorkedHours')(Self);
|
require('../methods/worker/getWorkedHours')(Self);
|
||||||
require('../methods/worker/uploadFile')(Self);
|
require('../methods/worker/uploadFile')(Self);
|
||||||
|
require('../methods/worker/createAbsences')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
format-day="$ctrl.formatDay($day, $element)"
|
format-day="$ctrl.formatDay($day, $element)"
|
||||||
display-controls="false"
|
display-controls="false"
|
||||||
hide-contiguous="true"
|
hide-contiguous="true"
|
||||||
hide-year="true">
|
hide-year="true"
|
||||||
|
on-selection="$ctrl.onSelection($days, $type, $weekday)">
|
||||||
</vn-calendar>
|
</vn-calendar>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
</div>
|
</div>
|
||||||
|
@ -26,12 +27,74 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="vn-pt-md" style="overflow: hidden;">
|
<div class="vn-pt-md" style="overflow: hidden;">
|
||||||
<vn-chip ng-repeat="absenceType in absenceTypes">
|
<vn-chip ng-repeat="absenceType in absenceTypes" class="selectable"
|
||||||
|
ng-click="$ctrl.pick(absenceType)">
|
||||||
<vn-avatar
|
<vn-avatar
|
||||||
ng-style="{backgroundColor: absenceType.rgb}">
|
ng-style="{backgroundColor: absenceType.rgb}">
|
||||||
|
<vn-icon icon="check" ng-if="absenceType.id == $ctrl.absenceType.id"></vn-icon>
|
||||||
</vn-avatar>
|
</vn-avatar>
|
||||||
{{absenceType.name}}
|
{{absenceType.name}}
|
||||||
</vn-chip>
|
</vn-chip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</vn-side-menu>
|
</vn-side-menu>
|
||||||
|
|
||||||
|
<vn-dialog
|
||||||
|
vn-id="dialog"
|
||||||
|
on-response="$ctrl.onAbsenceResponse($response)"
|
||||||
|
message="{{$ctrl.isNew ? 'Add absence' : 'Edit absence'}}">
|
||||||
|
<tpl-body>
|
||||||
|
<vn-vertical>
|
||||||
|
<vn-vertical class="vn-pb-md">
|
||||||
|
<vn-radio
|
||||||
|
ng-model="$ctrl.selected.type"
|
||||||
|
label="One day"
|
||||||
|
val="day">
|
||||||
|
</vn-radio>
|
||||||
|
<vn-radio
|
||||||
|
ng-model="$ctrl.selected.type"
|
||||||
|
label="Range of dates"
|
||||||
|
val="range">
|
||||||
|
</vn-radio>
|
||||||
|
</vn-vertical>
|
||||||
|
<vn-date-picker
|
||||||
|
ng-if="$ctrl.selected.type == 'day'"
|
||||||
|
label="Day"
|
||||||
|
ng-model="$ctrl.selected.dated">
|
||||||
|
</vn-date-picker>
|
||||||
|
<vn-horizontal
|
||||||
|
ng-if="$ctrl.selected.type == 'range'">
|
||||||
|
<vn-date-picker
|
||||||
|
label="From"
|
||||||
|
ng-model="$ctrl.selected.started">
|
||||||
|
</vn-date-picker>
|
||||||
|
<vn-date-picker
|
||||||
|
label="To"
|
||||||
|
ng-model="$ctrl.selected.ended">
|
||||||
|
</vn-date-picker>
|
||||||
|
</vn-horizontal>
|
||||||
|
</vn-vertical>
|
||||||
|
</tpl-body>
|
||||||
|
<tpl-buttons>
|
||||||
|
<input
|
||||||
|
type="button"
|
||||||
|
response="cancel"
|
||||||
|
translate-attr="{value: 'Cancel'}">
|
||||||
|
</input>
|
||||||
|
<input
|
||||||
|
type="button"
|
||||||
|
ng-if="!$ctrl.isNew"
|
||||||
|
response="delete"
|
||||||
|
translate-attr="{value: 'Delete'}">
|
||||||
|
</input>
|
||||||
|
<button response="accept">
|
||||||
|
<span ng-if="$ctrl.isNew" translate>Add</span>
|
||||||
|
<span ng-if="!$ctrl.isNew" translate>Save</span>
|
||||||
|
</button>
|
||||||
|
</tpl-buttons>
|
||||||
|
</vn-dialog>
|
||||||
|
<vn-confirm
|
||||||
|
vn-id="confirm"
|
||||||
|
message="This item will be deleted"
|
||||||
|
question="Are you sure you want to continue?">
|
||||||
|
</vn-confirm>
|
||||||
|
|
|
@ -43,15 +43,8 @@ class Controller extends Section {
|
||||||
|
|
||||||
set worker(value) {
|
set worker(value) {
|
||||||
this._worker = value;
|
this._worker = value;
|
||||||
if (!value) return;
|
|
||||||
|
|
||||||
let params = {
|
if (value) this.refresh();
|
||||||
workerFk: this.worker.id,
|
|
||||||
started: this.started,
|
|
||||||
ended: this.ended
|
|
||||||
};
|
|
||||||
this.$http.get(`WorkerCalendars/absences`, {params})
|
|
||||||
.then(res => this.onData(res.data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onData(data) {
|
onData(data) {
|
||||||
|
@ -102,6 +95,86 @@ class Controller extends Section {
|
||||||
dayNumber.style.backgroundColor = event.color;
|
dayNumber.style.backgroundColor = event.color;
|
||||||
dayNumber.style.color = 'rgba(0, 0, 0, 0.7)';
|
dayNumber.style.color = 'rgba(0, 0, 0, 0.7)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pick(absenceType) {
|
||||||
|
if (absenceType == this.absenceType)
|
||||||
|
absenceType = null;
|
||||||
|
|
||||||
|
this.absenceType = absenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelection($days, $type, $weekday) {
|
||||||
|
if (!this.absenceType)
|
||||||
|
return this.vnApp.showMessage(this.$t('Choose an absence type'));
|
||||||
|
|
||||||
|
let $events = [];
|
||||||
|
for (let day of $days) {
|
||||||
|
const stamp = day.getTime();
|
||||||
|
$events = $events.concat(this.events[stamp] || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($events.length)
|
||||||
|
this.edit($events[0]);
|
||||||
|
else
|
||||||
|
this.create($type, $days, $weekday);
|
||||||
|
}
|
||||||
|
|
||||||
|
create(type, days, weekday) {
|
||||||
|
this.isNew = true;
|
||||||
|
this.selected = {
|
||||||
|
type: 'day',
|
||||||
|
dated: days[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$.dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
edit() {
|
||||||
|
this.isNew = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
onAbsenceResponse(response) {
|
||||||
|
switch (response) {
|
||||||
|
case 'accept': {
|
||||||
|
const selected = this.selected;
|
||||||
|
const params = Object.assign(selected, {
|
||||||
|
absenceTypeId: this.absenceType.id
|
||||||
|
});
|
||||||
|
|
||||||
|
/* const selected = {
|
||||||
|
businessFk: 106,
|
||||||
|
absenceTypeFk: this.absenceType.id,
|
||||||
|
dated: $days[0]
|
||||||
|
}; */
|
||||||
|
|
||||||
|
let req;
|
||||||
|
if (this.isNew) {
|
||||||
|
const path = `Workers/${this.$params.id}/createAbsences`;
|
||||||
|
req = this.$http.post(path, params);
|
||||||
|
} else
|
||||||
|
req = this.$http.put(`${this.path}/${selected.id}`, selected);
|
||||||
|
|
||||||
|
return req.then(() => {
|
||||||
|
this.selected = null;
|
||||||
|
this.isNew = null;
|
||||||
|
this.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
case 'delete':
|
||||||
|
return this.onDelete(this.selected.id)
|
||||||
|
.then(response => response == 'accept');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh() {
|
||||||
|
const params = {
|
||||||
|
workerFk: this.worker.id,
|
||||||
|
started: this.started,
|
||||||
|
ended: this.ended
|
||||||
|
};
|
||||||
|
this.$http.get(`WorkerCalendars/absences`, {params})
|
||||||
|
.then(res => this.onData(res.data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.component('vnWorkerCalendar', {
|
ngModule.component('vnWorkerCalendar', {
|
||||||
|
|
|
@ -16,4 +16,17 @@ vn-worker-calendar {
|
||||||
max-width: 288px;
|
max-width: 288px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vn-chip.selectable {
|
||||||
|
cursor: pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
vn-chip.selectable:hover {
|
||||||
|
opacity: 0.8
|
||||||
|
}
|
||||||
|
|
||||||
|
vn-chip vn-avatar {
|
||||||
|
text-align: center;
|
||||||
|
color: white
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue