fixed worker descriptor not showing the correct worker
gitea/salix/dev This commit looks good Details

This commit is contained in:
Gerard 2019-02-19 15:09:50 +01:00
parent 2121b87895
commit b7db5f969b
11 changed files with 45 additions and 25 deletions

View File

@ -76,7 +76,7 @@
<vn-client-descriptor-popover vn-id="clientDescriptor"></vn-client-descriptor-popover> <vn-client-descriptor-popover vn-id="clientDescriptor"></vn-client-descriptor-popover>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>
<vn-dialog class="dialog-summary" <vn-dialog class="dialog-summary"
vn-id="dialog-summary-claim"> vn-id="dialog-summary-claim">

View File

@ -149,5 +149,5 @@
</vn-item-descriptor-popover> </vn-item-descriptor-popover>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>

View File

@ -119,5 +119,5 @@
</vn-item-descriptor-popover> </vn-item-descriptor-popover>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>

View File

@ -81,7 +81,7 @@
</vn-client-descriptor-popover> </vn-client-descriptor-popover>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>
<vn-dialog <vn-dialog
vn-id="summary" vn-id="summary"

View File

@ -64,7 +64,7 @@
</vn-item-descriptor-popover> </vn-item-descriptor-popover>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>
<vn-confirm <vn-confirm
vn-id="delete-expedition" vn-id="delete-expedition"

View File

@ -120,5 +120,5 @@
</vn-client-descriptor-popover> </vn-client-descriptor-popover>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>

View File

@ -86,7 +86,7 @@
</vn-item-descriptor-popover> </vn-item-descriptor-popover>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>
<a ui-sref="ticket.card.request.create" <a ui-sref="ticket.card.request.create"
vn-tooltip="New request" vn-tooltip="New request"

View File

@ -61,5 +61,5 @@
</vn-item-descriptor-popover> </vn-item-descriptor-popover>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>

View File

@ -41,5 +41,5 @@
</a> </a>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor" vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker"> user-id="$ctrl.selectedWorker">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>

View File

@ -11,16 +11,16 @@ class Controller extends Component {
this.worker = null; this.worker = null;
} }
set workerFk(id) { set userId(id) {
if (id == this._workerFk) return; if (id == this._userId) return;
this._workerFk = id; this._userId = id;
this.worker = null; this.worker = null;
this.loadData(); this.loadData();
} }
get workerFk() { get userId() {
return this._workerFk; return this._userId;
} }
set quicklinks(value = {}) { set quicklinks(value = {}) {
@ -37,8 +37,11 @@ class Controller extends Component {
} }
loadData() { loadData() {
let query = `api/Workers/${this._workerFk}`; let query = `api/Workers/findOne`;
let filter = { let filter = {
where: {
userFk: this._userId
},
include: [ include: [
{ {
relation: 'user', relation: 'user',
@ -49,6 +52,13 @@ class Controller extends Component {
}, { }, {
relation: 'sip', relation: 'sip',
scope: {fields: ['extension']} scope: {fields: ['extension']}
}, {
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
} }
] ]
}; };
@ -67,7 +77,7 @@ ngModule.component('vnWorkerDescriptorPopover', {
template: require('./index.html'), template: require('./index.html'),
controller: Controller, controller: Controller,
bindings: { bindings: {
workerFk: '<', userId: '<',
quicklinks: '<' quicklinks: '<'
} }
}); });

View File

@ -21,23 +21,23 @@ describe('worker Component vnWorkerDescriptorPopover', () => {
describe('workerFk()', () => { describe('workerFk()', () => {
it(`should not apply any changes if the received id is the same stored in _workerFk`, () => { it(`should not apply any changes if the received id is the same stored in _workerFk`, () => {
controller.worker = 'I exist!'; controller.worker = 'I exist!';
controller._workerFk = 1; controller._userId = 1;
spyOn(controller, 'loadData'); spyOn(controller, 'loadData');
controller.workerFk = 1; controller.userId = 1;
expect(controller.worker).toEqual('I exist!'); expect(controller.worker).toEqual('I exist!');
expect(controller._workerFk).toEqual(1); expect(controller._userId).toEqual(1);
expect(controller.loadData).not.toHaveBeenCalled(); expect(controller.loadData).not.toHaveBeenCalled();
}); });
it(`should set the received id into _workerFk, set the worker to null and then call loadData()`, () => { it(`should set the received id into _workerFk, set the worker to null and then call loadData()`, () => {
controller.worker = `Please don't`; controller.worker = `Please don't`;
controller._workerFk = 1; controller._userId = 1;
spyOn(controller, 'loadData'); spyOn(controller, 'loadData');
controller.workerFk = 999; controller.userId = 999;
expect(controller.worker).toBeNull(); expect(controller.worker).toBeNull();
expect(controller._workerFk).toEqual(999); expect(controller._userId).toEqual(999);
expect(controller.loadData).toHaveBeenCalledWith(); expect(controller.loadData).toHaveBeenCalledWith();
}); });
}); });
@ -53,12 +53,15 @@ describe('worker Component vnWorkerDescriptorPopover', () => {
describe('loadData()', () => { describe('loadData()', () => {
it(`should perform a get query to store the worker data into the controller`, () => { it(`should perform a get query to store the worker data into the controller`, () => {
controller.workerFk = 1; controller.userId = 1;
controller.canceler = null; controller.canceler = null;
let response = {}; let response = {};
let config = { let config = {
filter: { filter: {
where: {
userFk: controller.userId
},
include: [ include: [
{ {
relation: 'user', relation: 'user',
@ -69,6 +72,13 @@ describe('worker Component vnWorkerDescriptorPopover', () => {
}, { }, {
relation: 'sip', relation: 'sip',
scope: {fields: ['extension']} scope: {fields: ['extension']}
}, {
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
} }
] ]
} }
@ -76,8 +86,8 @@ describe('worker Component vnWorkerDescriptorPopover', () => {
let json = $httpParamSerializer(config); let json = $httpParamSerializer(config);
$httpBackend.whenGET(`api/Workers/${controller._workerFk}?${json}`).respond(response); $httpBackend.whenGET(`api/Workers/findOne?${json}`).respond(response);
$httpBackend.expectGET(`api/Workers/${controller._workerFk}?${json}`); $httpBackend.expectGET(`api/Workers/findOne?${json}`);
controller.loadData(); controller.loadData();
$httpBackend.flush(); $httpBackend.flush();