diff --git a/back/model-config.json b/back/model-config.json
index b24226507..89f517812 100644
--- a/back/model-config.json
+++ b/back/model-config.json
@@ -52,6 +52,15 @@
},
"Postcode": {
"dataSource": "vn"
+ },
+ "UserPhoneType": {
+ "dataSource": "vn"
+ },
+ "UserPhone": {
+ "dataSource": "vn"
+ },
+ "UserLog": {
+ "dataSource": "vn"
}
}
diff --git a/modules/worker/back/models/user-log.json b/back/models/user-log.json
similarity index 100%
rename from modules/worker/back/models/user-log.json
rename to back/models/user-log.json
diff --git a/modules/worker/back/models/user-phone-type.json b/back/models/user-phone-type.json
similarity index 100%
rename from modules/worker/back/models/user-phone-type.json
rename to back/models/user-phone-type.json
diff --git a/back/models/user-phone.js b/back/models/user-phone.js
new file mode 100644
index 000000000..6f6c20049
--- /dev/null
+++ b/back/models/user-phone.js
@@ -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;
+ });
+};
diff --git a/modules/worker/back/models/user-phone.json b/back/models/user-phone.json
similarity index 75%
rename from modules/worker/back/models/user-phone.json
rename to back/models/user-phone.json
index c869a808d..f264ff28f 100644
--- a/modules/worker/back/models/user-phone.json
+++ b/back/models/user-phone.json
@@ -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": {
diff --git a/db/changes/10100-AllSaints/00-userLog.sql b/db/changes/10100-AllSaints/00-userLog.sql
index 2e541eaf4..f6972796d 100644
--- a/db/changes/10100-AllSaints/00-userLog.sql
+++ b/db/changes/10100-AllSaints/00-userLog.sql
@@ -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;
\ No newline at end of file
diff --git a/db/changes/10100-AllSaints/01-userPhone.sql b/db/changes/10100-AllSaints/01-userPhone.sql
index 488bbb112..e82b48000 100644
--- a/db/changes/10100-AllSaints/01-userPhone.sql
+++ b/db/changes/10100-AllSaints/01-userPhone.sql
@@ -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;
diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql
index 2624f1768..619e5ae2c 100644
--- a/db/dump/fixtures.sql
+++ b/db/dump/fixtures.sql
@@ -1862,4 +1862,46 @@ INSERT INTO `vn`.`queuePriority`(`id`, `priority`)
VALUES
(1, 'Alta'),
(2, 'Normal'),
- (3, 'Baja');
\ No newline at end of file
+ (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');
\ No newline at end of file
diff --git a/loopback/locale/es.json b/loopback/locale/es.json
index a6904074a..587d5e9c4 100644
--- a/loopback/locale/es.json
+++ b/loopback/locale/es.json
@@ -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"
}
\ No newline at end of file
diff --git a/modules/item/front/tags/index.js b/modules/item/front/tags/index.js
index b187e5baf..c5e120d82 100644
--- a/modules/item/front/tags/index.js
+++ b/modules/item/front/tags/index.js
@@ -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();
});
}
diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json
index df2b776fb..35a039d3c 100644
--- a/modules/worker/back/model-config.json
+++ b/modules/worker/back/model-config.json
@@ -49,14 +49,5 @@
},
"Device": {
"dataSource": "vn"
- },
- "UserPhoneType": {
- "dataSource": "vn"
- },
- "UserPhone": {
- "dataSource": "vn"
- },
- "UserLog": {
- "dataSource": "vn"
}
}
diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json
index 7456a3caa..c5c770fcd 100644
--- a/modules/worker/back/models/worker.json
+++ b/modules/worker/back/models/worker.json
@@ -54,6 +54,12 @@
"type": "hasMany",
"model": "WorkerTeamCollegues",
"foreignKey": "workerFk"
+ },
+ "phones": {
+ "type": "hasMany",
+ "model": "UserPhone",
+ "foreignKey": "userFk",
+ "primaryKey": "userFk"
}
}
}
\ No newline at end of file
diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html
index 7303bccc1..0ba32eff9 100644
--- a/modules/worker/front/basic-data/index.html
+++ b/modules/worker/front/basic-data/index.html
@@ -23,14 +23,6 @@
rule>
-
-
-
-
diff --git a/modules/worker/front/card/index.js b/modules/worker/front/card/index.js
index 5e1e33510..eefa6360a 100644
--- a/modules/worker/front/card/index.js
+++ b/modules/worker/front/card/index.js
@@ -40,6 +40,12 @@ class Controller {
relation: 'department'
}
}
+ }, {
+ relation: 'phones',
+ scope: {
+ fields: ['phone'],
+ order: 'typeFk ASC'
+ }
}
]
};
diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html
index 5bb9b22e5..0ff8563c5 100644
--- a/modules/worker/front/descriptor/index.html
+++ b/modules/worker/front/descriptor/index.html
@@ -26,8 +26,9 @@
-
+
diff --git a/modules/worker/front/index.js b/modules/worker/front/index.js
index 71c529ea8..6f4a7fe34 100644
--- a/modules/worker/front/index.js
+++ b/modules/worker/front/index.js
@@ -12,3 +12,4 @@ import './department';
import './calendar';
import './time-control';
import './log';
+import './phones';
diff --git a/modules/worker/front/phones/index.html b/modules/worker/front/phones/index.html
new file mode 100644
index 000000000..2c172bc2f
--- /dev/null
+++ b/modules/worker/front/phones/index.html
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
diff --git a/modules/worker/front/phones/index.js b/modules/worker/front/phones/index.js
new file mode 100644
index 000000000..b4eb8df71
--- /dev/null
+++ b/modules/worker/front/phones/index.js
@@ -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: '<'
+ }
+});
diff --git a/modules/worker/front/phones/locale/es.yml b/modules/worker/front/phones/locale/es.yml
new file mode 100644
index 000000000..8628f38ee
--- /dev/null
+++ b/modules/worker/front/phones/locale/es.yml
@@ -0,0 +1,4 @@
+Phones: Teléfonos
+Type: Tipo
+Remove phone: Eliminar teléfono
+Add phone: Añadir teléfono
\ No newline at end of file
diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json
index 1b4f9ec2a..c92ccc94d 100644
--- a/modules/worker/front/routes.json
+++ b/modules/worker/front/routes.json
@@ -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"
+ }
}
]
}
\ No newline at end of file
diff --git a/modules/worker/front/summary/index.html b/modules/worker/front/summary/index.html
index e2c93ea48..de86c1f84 100644
--- a/modules/worker/front/summary/index.html
+++ b/modules/worker/front/summary/index.html
@@ -12,8 +12,9 @@
-
+
diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js
index 24656d601..f9f4e688b 100644
--- a/modules/worker/front/summary/index.js
+++ b/modules/worker/front/summary/index.js
@@ -50,6 +50,12 @@ class Controller {
relation: 'department'
}
}
+ }, {
+ relation: 'phones',
+ scope: {
+ fields: ['phone'],
+ order: 'typeFk ASC'
+ }
}
]
};