Merge pull request 'hotfix_workCenter2' (!1669) from hotfix_workCenter2 into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1669
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Vicent Llopis 2023-07-14 11:34:49 +00:00
commit 06690ca71e
10 changed files with 85 additions and 88 deletions

View File

@ -0,0 +1,4 @@
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
VALUES
('WorkerDisableExcluded', '*', 'READ', 'ALLOW', 'ROLE', 'itManagement'),
('WorkerDisableExcluded', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');

View File

@ -3,7 +3,7 @@
data="absenceTypes" data="absenceTypes"
auto-load="true"> auto-load="true">
</vn-crud-model> </vn-crud-model>
<div ng-if="$ctrl.worker.hasWorkCenter"> <div ng-if="$ctrl.card.hasWorkCenter">
<div class="vn-w-lg"> <div class="vn-w-lg">
<vn-card class="vn-pa-sm calendars"> <vn-card class="vn-pa-sm calendars">
<vn-icon ng-if="::$ctrl.isSubordinate" icon="info" color-marginal <vn-icon ng-if="::$ctrl.isSubordinate" icon="info" color-marginal
@ -23,7 +23,7 @@
</div> </div>
</div> </div>
<div <div
ng-if="!$ctrl.worker.hasWorkCenter" ng-if="!$ctrl.card.hasWorkCenter"
class="bg-title" class="bg-title"
translate> translate>
Autonomous worker Autonomous worker
@ -82,10 +82,8 @@
</vn-autocomplete> </vn-autocomplete>
</div> </div>
<div name="absenceTypes" class="input vn-py-md" style="overflow: hidden;"> <div name="absenceTypes" class="input vn-py-md" style="overflow: hidden;">
<vn-chip ng-repeat="absenceType in absenceTypes" ng-class="::{'selectable': $ctrl.isSubordinate}" <vn-chip ng-repeat="absenceType in absenceTypes" ng-class="::{'selectable': $ctrl.isSubordinate}" ng-click="$ctrl.pick(absenceType)">
ng-click="$ctrl.pick(absenceType)"> <vn-avatar ng-style="{backgroundColor: absenceType.rgb}">
<vn-avatar
ng-style="{backgroundColor: absenceType.rgb}">
<vn-icon icon="check" ng-if="absenceType.id == $ctrl.absenceType.id"></vn-icon> <vn-icon icon="check" ng-if="absenceType.id == $ctrl.absenceType.id"></vn-icon>
</vn-avatar> </vn-avatar>
{{absenceType.name}} {{absenceType.name}}
@ -105,9 +103,9 @@
</div> </div>
</div> </div>
</vn-side-menu> </vn-side-menu>
<vn-confirm <vn-confirm
vn-id="confirm" vn-id="confirm"
message="This item will be deleted" message="This item will be deleted"
question="Are you sure you want to continue?"> question="Are you sure you want to continue?">
</vn-confirm> </vn-confirm>

View File

@ -31,6 +31,8 @@ class Controller extends Section {
} }
set businessId(value) { set businessId(value) {
if (!this.card.hasWorkCenter) return;
this._businessId = value; this._businessId = value;
if (value) { if (value) {
this.refresh() this.refresh()
@ -64,7 +66,7 @@ class Controller extends Section {
set worker(value) { set worker(value) {
this._worker = value; this._worker = value;
if (value && value.hasWorkCenter) { if (value) {
this.getIsSubordinate(); this.getIsSubordinate();
this.getActiveContract(); this.getActiveContract();
} }
@ -293,5 +295,8 @@ ngModule.vnComponent('vnWorkerCalendar', {
controller: Controller, controller: Controller,
bindings: { bindings: {
worker: '<' worker: '<'
},
require: {
card: '^vnWorkerCard'
} }
}); });

View File

@ -20,6 +20,9 @@ describe('Worker', () => {
controller.absenceType = {id: 1, name: 'Holiday', code: 'holiday', rgb: 'red'}; controller.absenceType = {id: 1, name: 'Holiday', code: 'holiday', rgb: 'red'};
controller.$params.id = 1106; controller.$params.id = 1106;
controller._worker = {id: 1106}; controller._worker = {id: 1106};
controller.card = {
hasWorkCenter: true
};
})); }));
describe('year() getter', () => { describe('year() getter', () => {
@ -74,7 +77,7 @@ describe('Worker', () => {
let yesterday = new Date(today.getTime()); let yesterday = new Date(today.getTime());
yesterday.setDate(yesterday.getDate() - 1); yesterday.setDate(yesterday.getDate() - 1);
controller.worker = {id: 1107, hasWorkCenter: true}; controller.worker = {id: 1107};
expect(controller.getIsSubordinate).toHaveBeenCalledWith(); expect(controller.getIsSubordinate).toHaveBeenCalledWith();
expect(controller.getActiveContract).toHaveBeenCalledWith(); expect(controller.getActiveContract).toHaveBeenCalledWith();

View File

@ -3,7 +3,7 @@ import ModuleCard from 'salix/components/module-card';
class Controller extends ModuleCard { class Controller extends ModuleCard {
reload() { reload() {
let filter = { const filter = {
include: [ include: [
{ {
relation: 'user', relation: 'user',
@ -32,13 +32,12 @@ class Controller extends ModuleCard {
] ]
}; };
return Promise.all([
this.$http.get(`Workers/${this.$params.id}`, {filter}) this.$http.get(`Workers/${this.$params.id}`, {filter})
.then(res => this.worker = res.data) .then(res => this.worker = res.data),
.then(() =>
this.$http.get(`Workers/${this.$params.id}/activeContract`) this.$http.get(`Workers/${this.$params.id}/activeContract`)
.then(res => { .then(res => this.hasWorkCenter = res.data.workCenterFk)
if (res.data) this.worker.hasWorkCenter = res.data.workCenterFk; ]);
}));
} }
} }

View File

@ -15,17 +15,10 @@
</div> </div>
</slot-before> </slot-before>
<slot-menu> <slot-menu>
<vn-item <vn-item ng-click="$ctrl.handleExcluded()" translate>
ng-click="$ctrl.handleExcluded()" {{$ctrl.workerExcluded
translate ? 'Click to allow the user to be disabled'
ng-if="!$ctrl.excluded"> : 'Click to exclude the user from getting disabled'}}
Click to exclude the user from getting disabled
</vn-item>
<vn-item
ng-click="$ctrl.handleExcluded()"
translate
ng-if="$ctrl.excluded">
Click to allow the user to be disabled
</vn-item> </vn-item>
</slot-menu> </slot-menu>
<slot-body> <slot-body>

View File

@ -18,28 +18,19 @@ class Controller extends Descriptor {
this.getIsExcluded(); this.getIsExcluded();
} }
get excluded() {
return this.entity.excluded;
}
set excluded(value) {
this.entity.excluded = value;
}
getIsExcluded() { getIsExcluded() {
this.$http.get(`workerDisableExcludeds/${this.entity.id}/exists`).then(data => { this.$http.get(`WorkerDisableExcludeds/${this.entity.id}/exists`).then(data => {
this.excluded = data.data.exists; this.workerExcluded = data.data.exists;
}); });
} }
handleExcluded() { handleExcluded() {
if (this.excluded) { if (this.workerExcluded)
this.$http.delete(`workerDisableExcludeds/${this.entity.id}`); this.$http.delete(`WorkerDisableExcludeds/${this.entity.id}`);
this.excluded = false; else
} else { this.$http.post(`WorkerDisableExcludeds`, {workerFk: this.entity.id, dated: new Date});
this.$http.post(`workerDisableExcludeds`, {workerFk: this.entity.id, dated: new Date});
this.excluded = true; this.workerExcluded = !this.workerExcluded;
}
} }
loadData() { loadData() {

View File

@ -4,7 +4,7 @@
filter="::$ctrl.filter" filter="::$ctrl.filter"
data="$ctrl.hours"> data="$ctrl.hours">
</vn-crud-model> </vn-crud-model>
<div ng-if="$ctrl.worker.hasWorkCenter"> <div ng-if="$ctrl.card.hasWorkCenter">
<vn-card class="vn-pa-lg vn-w-lg"> <vn-card class="vn-pa-lg vn-w-lg">
<vn-table model="model" auto-load="false"> <vn-table model="model" auto-load="false">
<vn-thead> <vn-thead>
@ -107,7 +107,7 @@
</vn-button-bar> </vn-button-bar>
</div> </div>
<div <div
ng-if="!$ctrl.worker.hasWorkCenter" ng-if="!$ctrl.card.hasWorkCenter"
class="bg-title" class="bg-title"
translate> translate>
Autonomous worker Autonomous worker
@ -136,6 +136,7 @@
</vn-calendar> </vn-calendar>
</div> </div>
</vn-side-menu> </vn-side-menu>
<vn-dialog <vn-dialog
vn-id="addTimeDialog" vn-id="addTimeDialog"
on-accept="$ctrl.addTime()" on-accept="$ctrl.addTime()"

View File

@ -141,6 +141,8 @@ class Controller extends Section {
]} ]}
}; };
this.$.model.applyFilter(filter, params).then(() => { this.$.model.applyFilter(filter, params).then(() => {
if (!this.card.hasWorkCenter) return;
this.getWorkedHours(this.started, this.ended); this.getWorkedHours(this.started, this.ended);
this.getAbsences(); this.getAbsences();
}); });
@ -151,7 +153,6 @@ class Controller extends Section {
} }
getAbsences() { getAbsences() {
if (!this.worker.hasWorkerCenter) return;
const fullYear = this.started.getFullYear(); const fullYear = this.started.getFullYear();
let params = { let params = {
workerFk: this.$params.id, workerFk: this.$params.id,
@ -486,5 +487,8 @@ ngModule.vnComponent('vnWorkerTimeControl', {
controller: Controller, controller: Controller,
bindings: { bindings: {
worker: '<' worker: '<'
},
require: {
card: '^vnWorkerCard'
} }
}); });

View File

@ -16,9 +16,8 @@ describe('Component vnWorkerTimeControl', () => {
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$element = angular.element('<vn-worker-time-control></vn-worker-time-control>'); $element = angular.element('<vn-worker-time-control></vn-worker-time-control>');
controller = $componentController('vnWorkerTimeControl', {$element, $scope}); controller = $componentController('vnWorkerTimeControl', {$element, $scope});
controller.worker = { controller.card = {
hasWorkerCenter: true hasWorkCenter: true
}; };
})); }));