Merge branch '2010-worker_phone_refactor' of verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-01-20 10:24:51 +00:00 committed by Gitea
commit bca8c23c1d
22 changed files with 22 additions and 494 deletions

View File

@ -59,12 +59,6 @@
"Postcode": {
"dataSource": "vn"
},
"UserPhoneType": {
"dataSource": "vn"
},
"UserPhone": {
"dataSource": "vn"
},
"UserLog": {
"dataSource": "vn"
}

View File

@ -1,26 +0,0 @@
{
"name": "UserPhoneType",
"base": "VnModel",
"options": {
"mysql": {
"table": "userPhoneType"
}
},
"properties": {
"code": {
"id": true,
"type": "String"
},
"description": {
"type": "String"
}
},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -1,9 +0,0 @@
let UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')
return new UserError(`This phone already exists`);
return err;
});
};

View File

@ -1,39 +0,0 @@
{
"name": "UserPhone",
"base": "Loggable",
"log": {
"model":"UserLog",
"relation": "user"
},
"options": {
"mysql": {
"table": "userPhone"
}
},
"properties": {
"id": {
"id": true,
"type": "Number"
},
"phone": {
"type": "Number",
"required": true
},
"typeFk": {
"type": "String",
"required": true
}
},
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"foreignKey": "userFk"
},
"type": {
"type": "belongsTo",
"model": "UserPhoneType",
"foreignKey": "typeFk"
}
}
}

View File

@ -68,13 +68,13 @@ INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,
(111, 'Missing', 'Missing', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'es'),
(112, 'Trash', 'Trash', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'es');
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`)
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`, `phone`)
VALUES
(106, 'LGN', 'David Charles', 'Haller', 106, 19),
(107, 'ANT', 'Hank' , 'Pym' , 107, 19),
(108, 'DCX', 'Charles' , 'Xavier', 108, 19),
(109, 'HLK', 'Bruce' , 'Banner', 109, 19),
(110, 'JJJ', 'Jessica' , 'Jones' , 110, 19);
(106, 'LGN', 'David Charles', 'Haller', 106, 19, 432978106),
(107, 'ANT', 'Hank' , 'Pym' , 107, 19, 432978107),
(108, 'DCX', 'Charles' , 'Xavier', 108, 19, 432978108),
(109, 'HLK', 'Bruce' , 'Banner', 109, 19, 432978109),
(110, 'JJJ', 'Jessica' , 'Jones' , 110, 19, 432978110);
INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`)
VALUES
@ -1940,73 +1940,6 @@ INSERT INTO `vn`.`queuePriority`(`id`, `priority`)
(2, 'Normal'),
(3, 'Baja');
INSERT INTO `vn`.`userPhoneType` (`code`, `description`)
VALUES
('businessPhone', 'Telefono de empresa del usuario'),
('personalPhone', 'Telefono personal del usuario');
INSERT INTO `vn`.`userPhone`(`id`, `userFk`, `typeFk`, `phone`)
VALUES
(1, 101, 'personalPhone', 1111111111),
(2, 102, 'personalPhone', 1111111111),
(3, 103, 'personalPhone', 1111111111),
(4, 104, 'personalPhone', 1111111111),
(5, 105, 'personalPhone', 1111111111),
(6, 106, 'personalPhone', 1111111111),
(7, 107, 'personalPhone', 1111111111),
(8, 108, 'personalPhone', 1111111111),
(9, 109, 'personalPhone', 1111111111),
(10, 110, 'personalPhone', 1111111111),
(11, 111, 'personalPhone', 1111111111),
(12, 112, 'personalPhone', 1111111111),
(13, 1, 'personalPhone', 623111111),
(14, 2, 'personalPhone', 623111111),
(15, 3, 'personalPhone', 623111111),
(16, 5, 'personalPhone', 623111111),
(17, 6, 'personalPhone', 623111111),
(18, 9, 'personalPhone', 623111111),
(19, 13, 'personalPhone', 623111111),
(20, 15, 'personalPhone', 623111111),
(21, 16, 'personalPhone', 623111111),
(22, 17, 'personalPhone', 623111111),
(23, 18, 'personalPhone', 623111111),
(24, 19, 'personalPhone', 623111111),
(26, 21, 'personalPhone', 623111111),
(27, 22, 'personalPhone', 623111111),
(28, 30, 'personalPhone', 623111111),
(29, 31, 'personalPhone', 623111111),
(30, 32, 'personalPhone', 623111111),
(31, 34, 'personalPhone', 623111111),
(32, 35, 'personalPhone', 623111111),
(33, 36, 'personalPhone', 623111111),
(34, 37, 'personalPhone', 623111111),
(35, 38, 'personalPhone', 623111111),
(36, 39, 'personalPhone', 623111111),
(37, 40, 'personalPhone', 623111111),
(38, 41, 'personalPhone', 623111111),
(39, 42, 'personalPhone', 623111111),
(40, 43, 'personalPhone', 623111111),
(41, 44, 'personalPhone', 623111111),
(42, 45, 'personalPhone', 623111111),
(43, 47, 'personalPhone', 623111111),
(44, 48, 'personalPhone', 623111111),
(45, 50, 'personalPhone', 623111111),
(46, 51, 'personalPhone', 623111111),
(47, 52, 'personalPhone', 623111111),
(48, 54, 'personalPhone', 623111111),
(49, 55, 'personalPhone', 623111111),
(50, 56, 'personalPhone', 623111111),
(51, 57, 'personalPhone', 623111111),
(52, 58, 'personalPhone', 623111111),
(53, 59, 'personalPhone', 623111111),
(54, 60, 'personalPhone', 623111111),
(55, 61, 'personalPhone', 623111111),
(56, 65, 'personalPhone', 623111111),
(57, 66, 'personalPhone', 623111111),
(65, 107, 'businessPhone', 700987987),
(67, 106, 'businessPhone', 1111111112),
(68, 106, 'personalPhone', 1111111113);
INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `weekScope`, `dayWorkMax`, `dayStayMax`)
VALUES
(1, 43200, 129600, 734400, 43200, 50400);

View File

@ -1,10 +1,10 @@
const app = require('vn-loopback/server/server');
describe('client sendSms()', () => {
let clientLog;
let createdLog;
afterAll(async done => {
await app.models.ClientLog.destroyById(clientLog.id);
await app.models.ClientLog.destroyById(createdLog.id);
done();
});
@ -19,7 +19,7 @@ describe('client sendSms()', () => {
logId = sms.logId;
let createdLog = await app.models.ClientLog.findById(logId);
createdLog = await app.models.ClientLog.findById(logId);
let json = JSON.parse(JSON.stringify(createdLog.newInstance));
expect(json.message).toEqual(message);

View File

@ -1,54 +0,0 @@
<vn-crud-model
url="UserPhoneTypes"
data="phoneTypes"
auto-load="true">
</vn-crud-model>
<vn-crud-model
vn-id="model"
url="UserPhones"
data="$ctrl.phones">
</vn-crud-model>
<vn-watcher
vn-id="watcher"
data="$ctrl.phones">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-horizontal ng-repeat="clientPhone in $ctrl.phones">
<vn-autocomplete
vn-one
ng-model="clientPhone.typeFk"
initial-data="clientPhone.typeFk"
data ="phoneTypes"
show-field="code"
value-field="code"
label="Type"
vn-focus>
</vn-autocomplete>
<vn-textfield
vn-one
label="Phone"
ng-model="clientPhone.phone">
</vn-textfield>
<vn-none>
<vn-icon-button
vn-tooltip="Remove phone"
icon="delete"
ng-click="model.remove($index)"
tabindex="-1">
</vn-icon-button>
</vn-none>
</vn-horizontal>
<vn-one>
<vn-icon-button
vn-bind="+"
vn-tooltip="Add phone"
icon="add_circle"
ng-click="$ctrl.add()">
</vn-icon-button>
</vn-one>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -1,44 +0,0 @@
import ngModule from '../module';
import Section from 'salix/components/section';
class Controller extends Section {
get client() {
return this._client;
}
set client(value) {
this._client = value;
if (value)
this.setLink(value);
}
setLink(value) {
this.$.$applyAsync(()=> {
this.$.model.link = {userFk: value.id};
this.$.model.refresh();
});
}
onSubmit() {
this.$.watcher.check();
return this.$.model.save().then(() => {
this.$.watcher.updateOriginalData();
this.$.watcher.notifySaved();
this.card.reload();
});
}
add() {
this.$.model.insert();
}
}
ngModule.component('vnClientPhones', {
template: require('./index.html'),
controller: Controller,
require: {card: '^vnClientCard'},
bindings: {
client: '<'
}
});

View File

@ -1,50 +0,0 @@
import './index';
import watcher from 'core/mocks/watcher';
describe('Component vnClientPhones', () => {
let controller;
let $element;
let $scope;
beforeEach(ngModule('client'));
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
$element = angular.element('<div></div>');
$scope.watcher = watcher;
$scope.model = {
link: 1,
save: () => {}
};
controller = $componentController('vnClientPhones', {$element, $scope});
controller.card = {reload: () => {}};
}));
describe('setLink()', () => {
it('set the link in the model and refreshes it', () => {
spyOn(controller.$, '$applyAsync');
let value = {id: 106};
controller.setLink(value);
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
});
});
describe('onSubmit()', () => {
it('should call watcher functions, reload the card and save the model', done => {
spyOn(controller.$.watcher, 'check');
spyOn(controller.$.model, 'save').and.returnValue(Promise.resolve());
spyOn(controller.$.watcher, 'updateOriginalData');
spyOn(controller.$.watcher, 'notifySaved');
spyOn(controller.card, 'reload');
controller.onSubmit();
controller.onSubmit().then(() => {
expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith();
expect(controller.$.watcher.notifySaved).toHaveBeenCalledWith();
expect(controller.card.reload).toHaveBeenCalledWith();
done();
}).catch(done.fail);
});
});
});

View File

@ -285,7 +285,7 @@
"url": "/contact",
"state": "client.card.contact",
"component": "vn-client-contact",
"description": "Client contact",
"description": "Contacts",
"params": {
"client": "$ctrl.client"
}

View File

@ -54,12 +54,6 @@
"type": "hasMany",
"model": "WorkerTeamCollegues",
"foreignKey": "workerFk"
},
"phones": {
"type": "hasMany",
"model": "UserPhone",
"foreignKey": "userFk",
"primaryKey": "userFk"
}
}
}

View File

@ -23,6 +23,14 @@
rule>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="Phone"
ng-model="$ctrl.worker.phone"
rule>
</vn-textfield>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>

View File

@ -28,12 +28,6 @@ class Controller extends ModuleCard {
relation: 'department'
}
}
}, {
relation: 'phones',
scope: {
fields: ['phone'],
order: 'typeFk ASC'
}
}
]
};

View File

@ -26,9 +26,8 @@
<vn-label-value label="Department"
value="{{$ctrl.worker.department.department.name}}">
</vn-label-value>
<vn-label-value ng-repeat ="phone in $ctrl.worker.phones"
label="Phone"
value="{{phone.phone}}">
<vn-label-value label="Phone"
value="{{$ctrl.worker.phone}}">
</vn-label-value>
<vn-label-value label="Extension"
value="{{$ctrl.worker.sip.extension}}">

View File

@ -13,7 +13,6 @@ import './department';
import './calendar';
import './time-control';
import './log';
import './phones';
import './dms/index';
import './dms/create';
import './dms/edit';

View File

@ -1,54 +0,0 @@
<vn-crud-model
url="UserPhoneTypes"
data="phoneTypes"
auto-load="true">
</vn-crud-model>
<vn-crud-model
vn-id="model"
url="UserPhones"
data="$ctrl.phones">
</vn-crud-model>
<vn-watcher
vn-id="watcher"
data="$ctrl.phones">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-horizontal ng-repeat="workerPhone in $ctrl.phones">
<vn-autocomplete
vn-one
ng-model="workerPhone.typeFk"
initial-data="workerPhone.typeFk"
data ="phoneTypes"
show-field="code"
value-field="code"
label="Type"
vn-focus>
</vn-autocomplete>
<vn-textfield
vn-one
label="Phone"
ng-model="workerPhone.phone">
</vn-textfield>
<vn-none>
<vn-icon-button
vn-tooltip="Remove phone"
icon="delete"
ng-click="model.remove($index)"
tabindex="-1">
</vn-icon-button>
</vn-none>
</vn-horizontal>
<vn-one>
<vn-icon-button
vn-bind="+"
vn-tooltip="Add phone"
icon="add_circle"
ng-click="$ctrl.add()">
</vn-icon-button>
</vn-one>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -1,48 +0,0 @@
import ngModule from '../module';
class Controller {
constructor($scope) {
this.$scope = $scope;
}
get worker() {
return this._worker;
}
set worker(value) {
this._worker = value;
if (value)
this.setLink(value);
}
setLink(value) {
this.$scope.$applyAsync(()=> {
this.$scope.model.link = {userFk: value.userFk};
this.$scope.model.refresh();
});
}
onSubmit() {
this.$scope.watcher.check();
return this.$scope.model.save().then(() => {
this.$scope.watcher.updateOriginalData();
this.$scope.watcher.notifySaved();
this.card.reload();
});
}
add() {
this.$scope.model.insert();
}
}
Controller.$inject = ['$scope'];
ngModule.component('vnWorkerPhones', {
template: require('./index.html'),
controller: Controller,
require: {card: '^vnWorkerCard'},
bindings: {
worker: '<'
}
});

View File

@ -1,47 +0,0 @@
import './index';
import watcher from 'core/mocks/watcher';
describe('Component vnWorkerPhones', () => {
let controller;
beforeEach(ngModule('worker'));
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
let $scope = $rootScope.$new();
controller = $componentController('vnWorkerPhones', $scope);
controller.$scope.watcher = watcher;
controller.$scope.model = {
link: 1,
save: () => {}
};
controller.card = {reload: () => {}};
}));
describe('setLink()', () => {
it('set the link in the model and refreshes it', () => {
spyOn(controller.$scope, '$applyAsync');
let value = {userFk: 106};
controller.setLink(value);
expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
});
});
describe('onSubmit()', () => {
it('should call watcher functions, reload the card and save the model', done => {
spyOn(controller.$scope.watcher, 'check');
spyOn(controller.$scope.model, 'save').and.returnValue(Promise.resolve());
spyOn(controller.$scope.watcher, 'updateOriginalData');
spyOn(controller.$scope.watcher, 'notifySaved');
spyOn(controller.card, 'reload');
controller.onSubmit();
controller.onSubmit().then(() => {
expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith();
expect(controller.$scope.watcher.notifySaved).toHaveBeenCalledWith();
expect(controller.card.reload).toHaveBeenCalledWith();
done();
}).catch(done.fail);
});
});
});

View File

@ -1,4 +0,0 @@
Phones: Teléfonos
Type: Tipo
Remove phone: Eliminar teléfono
Add phone: Añadir teléfono

View File

@ -13,7 +13,6 @@
{"state": "worker.card.pbx", "icon": "icon-pbx"},
{"state": "worker.card.calendar", "icon": "icon-calendar"},
{"state": "worker.card.timeControl", "icon": "access_time"},
{"state": "worker.card.phones", "icon": "contact_phone"},
{"state": "worker.card.dms.index", "icon": "cloud_upload"}
]
},
@ -84,16 +83,6 @@
"description": "Departments",
"acl": ["hr"]
}, {
"url": "/phones",
"state": "worker.card.phones",
"component": "vn-worker-phones",
"description": "Phones",
"params": {
"worker": "$ctrl.worker"
},
"acl": ["hr"]
},
{
"url": "/dms",
"state": "worker.card.dms",
"abstract": true,

View File

@ -12,9 +12,8 @@
<vn-label-value label="Department"
value="{{worker.department.department.name}}">
</vn-label-value>
<vn-label-value ng-repeat = "phone in worker.phones"
label="Phone"
value="{{phone.phone}}">
<vn-label-value label="Phone"
value="{{worker.phone}}">
</vn-label-value>
</vn-one>
<vn-one>

View File

@ -50,12 +50,6 @@ class Controller {
relation: 'department'
}
}
}, {
relation: 'phones',
scope: {
fields: ['phone'],
order: 'typeFk ASC'
}
}
]
};