#1778 Refactor worker.phone

This commit is contained in:
Bernat 2019-10-18 08:36:33 +02:00
parent 7ee03d91f8
commit 7a89ab5335
22 changed files with 215 additions and 31 deletions

View File

@ -52,6 +52,15 @@
},
"Postcode": {
"dataSource": "vn"
},
"UserPhoneType": {
"dataSource": "vn"
},
"UserPhone": {
"dataSource": "vn"
},
"UserLog": {
"dataSource": "vn"
}
}

View File

@ -0,0 +1,9 @@
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

@ -2,7 +2,8 @@
"name": "UserPhone",
"base": "Loggable",
"log": {
"model":"UserLog"
"model":"UserLog",
"relation": "user"
},
"options": {
"mysql": {
@ -12,11 +13,15 @@
"properties": {
"id": {
"id": true,
"type": "String"
"type": "Number"
},
"phone": {
"type": "Number",
"required": true
},
"typeFk": {
"type": "String",
"required": true
}
},
"relations": {

View File

@ -1,6 +1,6 @@
CREATE TABLE `vn`.`userLog` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`originFk` int(11) NOT NULL,
`originFk` int(10) unsigned NOT NULL,
`userFk` int(10) unsigned DEFAULT NULL,
`action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
`creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
@ -13,6 +13,6 @@ CREATE TABLE `vn`.`userLog` (
PRIMARY KEY (`id`),
KEY `originFk` (`originFk`),
KEY `userFk` (`userFk`),
CONSTRAINT `userLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `userLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `userLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

View File

@ -2,7 +2,7 @@ CREATE TABLE `vn`.`userPhone` (
`id` INT NOT NULL AUTO_INCREMENT,
`userFk` INT(10) UNSIGNED NOT NULL,
`typeFk` VARCHAR(45) NOT NULL,
`phone` INT(15) NOT NULL,
`phone` VARCHAR(15) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `UserFK_Phone` (`userFk` ASC, `phone` ASC));
@ -22,7 +22,7 @@ ADD CONSTRAINT `fgnUserFk`
ON UPDATE CASCADE;
insert into vn.userPhone(userFk,typeFk,phone)
select id,'PersonalPhone', phone
select id,'personalPhone', phone
from vn.client
where phone is not null;

View File

@ -1862,4 +1862,46 @@ INSERT INTO `vn`.`queuePriority`(`id`, `priority`)
VALUES
(1, 'Alta'),
(2, 'Normal'),
(3, 'Baja');
(3, 'Baja');
-- Fixtures para userPhone, #1814
insert into vn.userPhone(userFk,typeFk,phone)
select id,'personalPhone', phone
from vn.client
where phone is not null;
insert into vn.userPhone(userFk,typeFk,phone)
select id,'businessPhone', phone
from vn.worker
where phone is not null AND phone > '';
insert into vn.userPhone(userFk,typeFk,phone)
SELECT
`w`.`userFk`,
'businessPhone',
`m`.`value` AS `mediaValue`
FROM
(((((`postgresql`.`person` `p`
JOIN `postgresql`.`profile` `po` ON ((`po`.`person_id` = `p`.`person_id`)))
JOIN `postgresql`.`profile_media` `pom` ON ((`pom`.`profile_id` = `po`.`profile_id`)))
JOIN `postgresql`.`media` `m` ON ((`m`.`media_id` = `pom`.`media_id`)))
JOIN `postgresql`.`media_type` `mt` ON ((`mt`.`media_type_id` = `m`.`media_type_id`)))
JOIN `vn`.`worker` `w` ON ((`w`.`id` = `p`.`id_trabajador`)))
WHERE
(`mt`.`name` = 'movil empresa');
insert into vn.userPhone(userFk,typeFk,phone)
SELECT
`w`.`userFk`,
'personalPhone',
`m`.`value` AS `mediaValue`
FROM
(((((`postgresql`.`person` `p`
JOIN `postgresql`.`profile` `po` ON ((`po`.`person_id` = `p`.`person_id`)))
JOIN `postgresql`.`profile_media` `pom` ON ((`pom`.`profile_id` = `po`.`profile_id`)))
JOIN `postgresql`.`media` `m` ON ((`m`.`media_id` = `pom`.`media_id`)))
JOIN `postgresql`.`media_type` `mt` ON ((`mt`.`media_type_id` = `m`.`media_type_id`)))
JOIN `vn`.`worker` `w` ON ((`w`.`id` = `p`.`id_trabajador`)))
WHERE
(`mt`.`name` = 'movil personal');

View File

@ -109,5 +109,6 @@
"is invalid": "is invalid",
"The postcode doesn't exists. Ensure you put the correct format": "El código postal no existe. Asegúrate de ponerlo con el formato correcto",
"The department name can't be repeated": "El nombre del departamento no puede repetirse",
"You can't create a claim for a removed ticket": "No puedes crear una reclamación para un ticket eliminado"
"You can't create a claim for a removed ticket": "No puedes crear una reclamación para un ticket eliminado",
"This phone already exists": "Este teléfono ya existe"
}

View File

@ -66,7 +66,7 @@ class Controller {
this.$scope.watcher.check();
this.$scope.model.save().then(() => {
this.$scope.watcher.notifySaved();
this.$scope.model.refresh();
this.$scope.watcher.updateOriginalData();
this.card.reload();
});
}

View File

@ -49,14 +49,5 @@
},
"Device": {
"dataSource": "vn"
},
"UserPhoneType": {
"dataSource": "vn"
},
"UserPhone": {
"dataSource": "vn"
},
"UserLog": {
"dataSource": "vn"
}
}

View File

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

View File

@ -23,14 +23,6 @@
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

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

View File

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

View File

@ -12,3 +12,4 @@ import './department';
import './calendar';
import './time-control';
import './log';
import './phones';

View File

@ -0,0 +1,54 @@
<vn-crud-model
url="/api/UserPhoneTypes"
data="phoneTypes"
auto-load="true">
</vn-crud-model>
<vn-crud-model
vn-id="model"
url="/api/UserPhones"
data="$ctrl.phones">
</vn-crud-model>
<vn-watcher
vn-id="watcher"
data="$ctrl.phones">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" compact>
<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

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

View File

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

View File

@ -7,7 +7,8 @@
{"state": "worker.card.basicData", "icon": "settings"},
{"state": "worker.card.pbx", "icon": "icon-pbx"},
{"state": "worker.card.calendar", "icon": "icon-calendar"},
{"state": "worker.card.timeControl", "icon": "access_time"}
{"state": "worker.card.timeControl", "icon": "access_time"},
{"state": "worker.card.phones", "icon": "icon-pbx"}
],
"routes": [
{
@ -79,6 +80,15 @@
"state": "worker.department",
"component": "vn-worker-department",
"description": "Departments"
},
{
"url": "/phones",
"state": "worker.card.phones",
"component": "vn-worker-phones",
"description": "Phones",
"params": {
"worker": "$ctrl.worker"
}
}
]
}

View File

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

View File

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