#1778 Refactor worker.phone
This commit is contained in:
parent
7ee03d91f8
commit
7a89ab5335
|
@ -52,6 +52,15 @@
|
||||||
},
|
},
|
||||||
"Postcode": {
|
"Postcode": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"UserPhoneType": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"UserPhone": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"UserLog": {
|
||||||
|
"dataSource": "vn"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
});
|
||||||
|
};
|
|
@ -2,7 +2,8 @@
|
||||||
"name": "UserPhone",
|
"name": "UserPhone",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
"log": {
|
||||||
"model":"UserLog"
|
"model":"UserLog",
|
||||||
|
"relation": "user"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
@ -12,11 +13,15 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "String"
|
"type": "Number"
|
||||||
},
|
},
|
||||||
"phone": {
|
"phone": {
|
||||||
"type": "Number",
|
"type": "Number",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
"typeFk": {
|
||||||
|
"type": "String",
|
||||||
|
"required": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
|
@ -1,6 +1,6 @@
|
||||||
CREATE TABLE `vn`.`userLog` (
|
CREATE TABLE `vn`.`userLog` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`originFk` int(11) NOT NULL,
|
`originFk` int(10) unsigned NOT NULL,
|
||||||
`userFk` int(10) unsigned DEFAULT NULL,
|
`userFk` int(10) unsigned DEFAULT NULL,
|
||||||
`action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
|
`action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
|
||||||
`creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
`creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
@ -13,6 +13,6 @@ CREATE TABLE `vn`.`userLog` (
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `originFk` (`originFk`),
|
KEY `originFk` (`originFk`),
|
||||||
KEY `userFk` (`userFk`),
|
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
|
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;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
|
@ -2,7 +2,7 @@ CREATE TABLE `vn`.`userPhone` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
`id` INT NOT NULL AUTO_INCREMENT,
|
||||||
`userFk` INT(10) UNSIGNED NOT NULL,
|
`userFk` INT(10) UNSIGNED NOT NULL,
|
||||||
`typeFk` VARCHAR(45) NOT NULL,
|
`typeFk` VARCHAR(45) NOT NULL,
|
||||||
`phone` INT(15) NOT NULL,
|
`phone` VARCHAR(15) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE INDEX `UserFK_Phone` (`userFk` ASC, `phone` ASC));
|
UNIQUE INDEX `UserFK_Phone` (`userFk` ASC, `phone` ASC));
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ ADD CONSTRAINT `fgnUserFk`
|
||||||
ON UPDATE CASCADE;
|
ON UPDATE CASCADE;
|
||||||
|
|
||||||
insert into vn.userPhone(userFk,typeFk,phone)
|
insert into vn.userPhone(userFk,typeFk,phone)
|
||||||
select id,'PersonalPhone', phone
|
select id,'personalPhone', phone
|
||||||
from vn.client
|
from vn.client
|
||||||
where phone is not null;
|
where phone is not null;
|
||||||
|
|
||||||
|
|
|
@ -1862,4 +1862,46 @@ INSERT INTO `vn`.`queuePriority`(`id`, `priority`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'Alta'),
|
(1, 'Alta'),
|
||||||
(2, 'Normal'),
|
(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');
|
|
@ -109,5 +109,6 @@
|
||||||
"is invalid": "is invalid",
|
"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 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",
|
"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"
|
||||||
}
|
}
|
|
@ -66,7 +66,7 @@ class Controller {
|
||||||
this.$scope.watcher.check();
|
this.$scope.watcher.check();
|
||||||
this.$scope.model.save().then(() => {
|
this.$scope.model.save().then(() => {
|
||||||
this.$scope.watcher.notifySaved();
|
this.$scope.watcher.notifySaved();
|
||||||
this.$scope.model.refresh();
|
this.$scope.watcher.updateOriginalData();
|
||||||
this.card.reload();
|
this.card.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,14 +49,5 @@
|
||||||
},
|
},
|
||||||
"Device": {
|
"Device": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
|
||||||
"UserPhoneType": {
|
|
||||||
"dataSource": "vn"
|
|
||||||
},
|
|
||||||
"UserPhone": {
|
|
||||||
"dataSource": "vn"
|
|
||||||
},
|
|
||||||
"UserLog": {
|
|
||||||
"dataSource": "vn"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,12 @@
|
||||||
"type": "hasMany",
|
"type": "hasMany",
|
||||||
"model": "WorkerTeamCollegues",
|
"model": "WorkerTeamCollegues",
|
||||||
"foreignKey": "workerFk"
|
"foreignKey": "workerFk"
|
||||||
|
},
|
||||||
|
"phones": {
|
||||||
|
"type": "hasMany",
|
||||||
|
"model": "UserPhone",
|
||||||
|
"foreignKey": "userFk",
|
||||||
|
"primaryKey": "userFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,14 +23,6 @@
|
||||||
rule>
|
rule>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
|
||||||
<vn-textfield
|
|
||||||
vn-one
|
|
||||||
label="Phone"
|
|
||||||
ng-model="$ctrl.worker.phone"
|
|
||||||
rule>
|
|
||||||
</vn-textfield>
|
|
||||||
</vn-horizontal>
|
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-button-bar>
|
<vn-button-bar>
|
||||||
|
|
|
@ -40,6 +40,12 @@ class Controller {
|
||||||
relation: 'department'
|
relation: 'department'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
relation: 'phones',
|
||||||
|
scope: {
|
||||||
|
fields: ['phone'],
|
||||||
|
order: 'typeFk ASC'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,8 +26,9 @@
|
||||||
<vn-label-value label="Department"
|
<vn-label-value label="Department"
|
||||||
value="{{$ctrl.worker.department.department.name}}">
|
value="{{$ctrl.worker.department.department.name}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="Phone"
|
<vn-label-value ng-repeat ="phone in $ctrl.worker.phones"
|
||||||
value="{{$ctrl.worker.phone}}">
|
label="Phone"
|
||||||
|
value="{{phone.phone}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="Extension"
|
<vn-label-value label="Extension"
|
||||||
value="{{$ctrl.worker.sip.extension}}">
|
value="{{$ctrl.worker.sip.extension}}">
|
||||||
|
|
|
@ -12,3 +12,4 @@ import './department';
|
||||||
import './calendar';
|
import './calendar';
|
||||||
import './time-control';
|
import './time-control';
|
||||||
import './log';
|
import './log';
|
||||||
|
import './phones';
|
||||||
|
|
|
@ -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>
|
|
@ -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: '<'
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,4 @@
|
||||||
|
Phones: Teléfonos
|
||||||
|
Type: Tipo
|
||||||
|
Remove phone: Eliminar teléfono
|
||||||
|
Add phone: Añadir teléfono
|
|
@ -7,7 +7,8 @@
|
||||||
{"state": "worker.card.basicData", "icon": "settings"},
|
{"state": "worker.card.basicData", "icon": "settings"},
|
||||||
{"state": "worker.card.pbx", "icon": "icon-pbx"},
|
{"state": "worker.card.pbx", "icon": "icon-pbx"},
|
||||||
{"state": "worker.card.calendar", "icon": "icon-calendar"},
|
{"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": [
|
"routes": [
|
||||||
{
|
{
|
||||||
|
@ -79,6 +80,15 @@
|
||||||
"state": "worker.department",
|
"state": "worker.department",
|
||||||
"component": "vn-worker-department",
|
"component": "vn-worker-department",
|
||||||
"description": "Departments"
|
"description": "Departments"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/phones",
|
||||||
|
"state": "worker.card.phones",
|
||||||
|
"component": "vn-worker-phones",
|
||||||
|
"description": "Phones",
|
||||||
|
"params": {
|
||||||
|
"worker": "$ctrl.worker"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -12,8 +12,9 @@
|
||||||
<vn-label-value label="Department"
|
<vn-label-value label="Department"
|
||||||
value="{{worker.department.department.name}}">
|
value="{{worker.department.department.name}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="Phone"
|
<vn-label-value ng-repeat = "phone in worker.phones"
|
||||||
value="{{worker.phone}}">
|
label="Phone"
|
||||||
|
value="{{phone.phone}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
</vn-one>
|
</vn-one>
|
||||||
<vn-one>
|
<vn-one>
|
||||||
|
|
|
@ -50,6 +50,12 @@ class Controller {
|
||||||
relation: 'department'
|
relation: 'department'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
relation: 'phones',
|
||||||
|
scope: {
|
||||||
|
fields: ['phone'],
|
||||||
|
order: 'typeFk ASC'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue