From 90ce07881a11a28697d7fc5b35dd39376b2ebf0f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 5 Feb 2018 19:34:04 +0100 Subject: [PATCH 1/8] Gulpfile refactor, SQL scripts --- gulpfile.js | 11 +++--- services/db/00-trucateAll.sql | 38 +++++++++++++++++++ services/db/changes/1.0.0/01-agencyMode.sql | 25 ++++++++++++ services/db/changes/1.0.0/02-agencyHour.sql | 18 +++++++++ services/db/changes/1.0.0/03-address.sql | 24 ++++++++++++ services/db/changes/1.0.0/04-userRole.sql | 36 ++++++++++++++++++ .../db/changes/1.0.0/05-userHasRoleId.sql | 31 +++++++++++++++ 7 files changed, 178 insertions(+), 5 deletions(-) create mode 100644 services/db/00-trucateAll.sql create mode 100644 services/db/changes/1.0.0/01-agencyMode.sql create mode 100644 services/db/changes/1.0.0/02-agencyHour.sql create mode 100644 services/db/changes/1.0.0/03-address.sql create mode 100644 services/db/changes/1.0.0/04-userRole.sql create mode 100644 services/db/changes/1.0.0/05-userHasRoleId.sql diff --git a/gulpfile.js b/gulpfile.js index 5fa20ad2c..6ef3b3b49 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,9 +1,6 @@ require('require-yaml'); const gulp = require('gulp'); const gutil = require('gulp-util'); -const wrap = require('gulp-wrap'); -const concat = require('gulp-concat'); -const merge = require('merge-stream'); const print = require('gulp-print'); const runSequence = require('run-sequence'); const fs = require('fs-extra'); @@ -108,9 +105,8 @@ gulp.task('build', ['clean'], () => { }); gulp.task('docker-compose', async () => { - let compose = await fs.readFile('./docker-compose.tpl.yml', 'utf8'); - const yaml = require('js-yaml'); + let compose = await fs.readFile('./docker-compose.tpl.yml', 'utf8'); let composeYml = yaml.safeLoad(compose); let services = await getServices(); @@ -253,6 +249,8 @@ let localeFiles = `${srcDir}/**/locale/*.json`; gulp.task('locales', function() { const extend = require('gulp-extend'); const yaml = require('gulp-yaml'); + const merge = require('merge-stream'); + let streams = []; for (let mod in modules) @@ -272,6 +270,9 @@ gulp.task('locales', function() { let routeFiles = `${srcDir}/**/routes.json`; gulp.task('routes', function() { + const concat = require('gulp-concat'); + const wrap = require('gulp-wrap'); + return gulp.src(routeFiles) .pipe(concat('routes.js', {newLine: ','})) .pipe(wrap('var routes = [<%=contents%>\n];')) diff --git a/services/db/00-trucateAll.sql b/services/db/00-trucateAll.sql new file mode 100644 index 000000000..f7d98056c --- /dev/null +++ b/services/db/00-trucateAll.sql @@ -0,0 +1,38 @@ +DROP PROCEDURE IF EXISTS mysql.truncateAll; +DELIMITER $$ +CREATE PROCEDURE mysql.truncateAll() +BEGIN + DECLARE vSchema VARCHAR(255); + DECLARE vTable VARCHAR(255); + DECLARE vDone BOOL; + + DECLARE cTables CURSOR FOR + SELECT `TABLE_SCHEMA`, `TABLE_NAME` + FROM `information_schema`.`TABLES` + WHERE `TABLE_TYPE` = 'BASE TABLE' + AND `TABLE_ROWS` > 0 + AND `TABLE_SCHEMA` NOT IN ('information_schema', 'mysql', 'performance_schema'); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SET FOREIGN_KEY_CHECKS = FALSE; + OPEN cTables; + + l: LOOP + SET vDone = FALSE; + FETCH cTables INTO vSchema, vTable; + + IF vDone THEN + LEAVE l; + END IF; + + SET @stmt = CONCAT('TRUNCATE TABLE `', vSchema, '`.`', vTable, '`'); + PREPARE stmt FROM @stmt; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + END LOOP; + + CLOSE cTables; + SET FOREIGN_KEY_CHECKS = TRUE; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/services/db/changes/1.0.0/01-agencyMode.sql b/services/db/changes/1.0.0/01-agencyMode.sql new file mode 100644 index 000000000..5190821c5 --- /dev/null +++ b/services/db/changes/1.0.0/01-agencyMode.sql @@ -0,0 +1,25 @@ +CREATE OR REPLACE + ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `vn`.`agencyMode` AS + SELECT + `a`.`Id_Agencia` AS `id`, + `a`.`Agencia` AS `name`, + `a`.`description` AS `description`, + `a`.`Vista` AS `deliveryMethodFk`, + `a`.`Vista` AS `__deliveryMethod`, + `a`.`Vista` AS `__view`, + `a`.`m3` AS `m3`, + `a`.`cod71` AS `cod71`, + `a`.`web` AS `web`, + `a`.`agency_id` AS `agencyFk`, + `a`.`agency_id` AS `__agency`, + `a`.`agency_service_id` AS `agencyServiceFk`, + `a`.`agency_service_id` AS `__agencyService`, + `a`.`inflacion` AS `inflation`, + `a`.`inflacion` AS `__inflacion`, + `a`.`is_volumetric` AS `isVolumetric`, + `a`.`send_mail` AS `reportMail` + FROM + `vn2008`.`Agencias` `a` \ No newline at end of file diff --git a/services/db/changes/1.0.0/02-agencyHour.sql b/services/db/changes/1.0.0/02-agencyHour.sql new file mode 100644 index 000000000..1c3a743f6 --- /dev/null +++ b/services/db/changes/1.0.0/02-agencyHour.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE + ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `vn`.`agencyHour` AS + SELECT + `h`.`agency_hour_id` AS `id`, + `h`.`agency_id` AS `agencyFk`, + `h`.`agency_id` AS `__agency`, + `h`.`week_day` AS `weekDay`, + `h`.`warehouse_id` AS `warehouseFk`, + `h`.`warehouse_id` AS `__warehouse`, + `h`.`province_id` AS `provinceFk`, + `h`.`province_id` AS `__province`, + `h`.`subtract_day` AS `substractDay`, + `h`.`max_hour` AS `maxHour` + FROM + `vn2008`.`agency_hour` `h` \ No newline at end of file diff --git a/services/db/changes/1.0.0/03-address.sql b/services/db/changes/1.0.0/03-address.sql new file mode 100644 index 000000000..bdd27136c --- /dev/null +++ b/services/db/changes/1.0.0/03-address.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE + ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `vn`.`address` AS + SELECT + `t`.`id_consigna` AS `id`, + `t`.`Id_cliente` AS `clientFk`, + `t`.`domicilio` AS `street`, + `t`.`poblacion` AS `city`, + `t`.`codPostal` AS `postalCode`, + `t`.`province_id` AS `provinceFk`, + `t`.`telefono` AS `phone`, + `t`.`movil` AS `mobile`, + `t`.`consignatario` AS `nickname`, + `t`.`predeterminada` AS `isDefaultAddress`, + `t`.`longitude` AS `longitude`, + `t`.`latitude` AS `latitude`, + `t`.`warehouse_id` AS `warehouseFk`, + `t`.`Id_Agencia` AS `agencyFk`, + `t`.`isEqualizated` AS `isEqualizated`, + `t`.`active` AS `isActive` + FROM + `vn2008`.`Consignatarios` `t` \ No newline at end of file diff --git a/services/db/changes/1.0.0/04-userRole.sql b/services/db/changes/1.0.0/04-userRole.sql new file mode 100644 index 000000000..b896589bc --- /dev/null +++ b/services/db/changes/1.0.0/04-userRole.sql @@ -0,0 +1,36 @@ +USE `account`; +CREATE + OR REPLACE ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `account`.`__userRole` AS + SELECT + `r`.`inheritsFrom` AS `id` + FROM + (`account`.`roleRole` `r` + JOIN `account`.`user` `u` ON ((`u`.`role` = `r`.`role`))) + WHERE + (`u`.`id` = USERGETID()); + +DROP VIEW `account`.`userRole`; + +CREATE TABLE `account`.`userRole` ( + `userFk` INT(10) UNSIGNED NOT NULL, + `roleFk` INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (`userFk`, `roleFk`)); + +ALTER TABLE `account`.`userRole` + ADD INDEX `user` (`userFk` ASC), + ADD INDEX `role` (`roleFk` ASC); + +ALTER TABLE `account`.`userRole` + ADD CONSTRAINT `user` + FOREIGN KEY (`userFk`) + REFERENCES `account`.`user` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + ADD CONSTRAINT `role` + FOREIGN KEY (`roleFk`) + REFERENCES `account`.`role` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; diff --git a/services/db/changes/1.0.0/05-userHasRoleId.sql b/services/db/changes/1.0.0/05-userHasRoleId.sql new file mode 100644 index 000000000..9d96ff775 --- /dev/null +++ b/services/db/changes/1.0.0/05-userHasRoleId.sql @@ -0,0 +1,31 @@ +DROP function IF EXISTS `userHasRoleId`; +DELIMITER $$ +CREATE DEFINER=`root`@`%` FUNCTION `account`.`userHasRoleId`(vRoleId INT) RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** + * Comprueba si el usuario actual tiene asociado un rol. + * + * @param vRoleId Identificador del rol a comprobar + * @return %TRUE si tiene el rol, %FALSE en caso contrario + */ + DECLARE vHasRole BOOL DEFAULT FALSE; + + SELECT COUNT(*) > 0 INTO vHasRole + FROM user u + JOIN roleRole r ON r.role = u.role + WHERE u.id = userGetId() + AND r.inheritsFrom = vRoleId; + + IF NOT vHasRole + THEN + SELECT COUNT(*) > 0 INTO vHasRole + FROM userRole + WHERE userFk = userGetId() + AND roleFk = vRoleId; + END IF; + + RETURN vHasRole; +END$$ +DELIMITER ; + From c099d3f021293711987760c15bc835e7ec80e82f Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 09:51:51 +0100 Subject: [PATCH 2/8] auto create nginx temp folder --- gulpfile.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 327a51579..4c529708e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -191,6 +191,11 @@ gulp.task('nginx-stop', ['nginx-conf'], async () => { gulp.task('nginx-conf', async () => { const mustache = require('mustache'); + // crear carpeta nginx &{nginxTemp} si no existe + if (!fs.existsSync(nginxTemp)) { + fs.mkdirSync(nginxTemp); + } + let params = { services: await getServices(), defaultService: defaultService, @@ -208,12 +213,12 @@ gulp.task('nginx-conf', async () => { let template = await fs.readFile(confFile, 'utf8'); let nginxConf = mustache.render(template, params); - await fs.writeFile(`${nginxDir}/temp/nginx.conf`, nginxConf); + await fs.writeFile(`${nginxTemp}/nginx.conf`, nginxConf); }); gulp.task('nginx-clean', () => { const del = require('del'); - return del([`${nginxDir}/temp/*`], {force: true}); + return del([`${nginxTemp}/*`], {force: true}); }); let services; From 810db634d34647a5352981370448932ece365b5b Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 09:53:45 +0100 Subject: [PATCH 3/8] auto create nginx tmp folder --- gulpfile.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index 327a51579..af4bda1fd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -191,6 +191,10 @@ gulp.task('nginx-stop', ['nginx-conf'], async () => { gulp.task('nginx-conf', async () => { const mustache = require('mustache'); + if (!fs.existsSync(nginxTemp)) { + fs.mkdirSync(nginxTemp); + } + let params = { services: await getServices(), defaultService: defaultService, From 0fc1dc0faa66a07a8b6c9b408a881c5954a2008d Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 7 Feb 2018 10:29:23 +0100 Subject: [PATCH 4/8] Address id fixtures, gulpfile clean, eslint no-empty --- .eslintrc.yml | 2 +- gulpfile.js | 1 - package-lock.json | 16 ++++++++-------- services/db/02-fixtures.sql | 20 ++++++++++---------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index fc8c9fb1c..022c3d6fa 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -19,4 +19,4 @@ rules: no-eq-null: 0 no-console: 0 no-warning-comments: 0 - no-empty: 0 + no-empty: [error, allowEmptyCatch: true] diff --git a/gulpfile.js b/gulpfile.js index ab87d7d2d..baa0c0639 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,7 +7,6 @@ const fs = require('fs-extra'); const webpack = require('webpack'); const WebpackDevServer = require('webpack-dev-server'); const exec = require('child_process').exec; -const path = require('path'); // Configuration diff --git a/package-lock.json b/package-lock.json index e10725348..dec836866 100644 --- a/package-lock.json +++ b/package-lock.json @@ -113,7 +113,7 @@ "angular": { "version": "1.6.8", "resolved": "https://registry.npmjs.org/angular/-/angular-1.6.8.tgz", - "integrity": "sha1-W+N4pYvpGlSJ54tZxFGM2f0nP/s=" + "integrity": "sha512-9WErZIOw1Cu1V5Yxdvxz/6YpND8ntdP71fdPpufPFJvZodZXqCjQBYrHqEoMZreO5i84O3D/Jw/vepoFt68Azw==" }, "angular-cookies": { "version": "1.6.4", @@ -1119,7 +1119,7 @@ "bluebird": { "version": "3.5.1", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", - "integrity": "sha1-2VUfnemPH82h5oPRfukaBgLuLrk=", + "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==", "dev": true }, "bn.js": { @@ -9909,7 +9909,7 @@ "jasmine-spec-reporter": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/jasmine-spec-reporter/-/jasmine-spec-reporter-4.2.1.tgz", - "integrity": "sha1-HWMq7ANBZwrTJPkrqEtLMrNeniI=", + "integrity": "sha512-FZBoZu7VE5nR7Nilzy+Np8KuVIOxF4oXDPDknehCYBDE080EnlPu0afdZNmpGDBRCUBv3mj5qgqCRmk6W/K8vg==", "dev": true, "requires": { "colors": "1.1.2" @@ -10051,7 +10051,7 @@ "karma": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/karma/-/karma-1.7.1.tgz", - "integrity": "sha1-hcwI6eCiLXzpzKN8ShvoJPaisa4=", + "integrity": "sha512-k5pBjHDhmkdaUccnC7gE3mBzZjcxyxYsYVaqiL2G5AqlfLyBO5nw2VdNK+O16cveEPd/gIOWULH7gkiYYwVNHg==", "dev": true, "requires": { "bluebird": "3.5.1", @@ -10103,7 +10103,7 @@ "karma-chrome-launcher": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-2.2.0.tgz", - "integrity": "sha1-zxudBxNswY/iOTJ9JGVMPbw2is8=", + "integrity": "sha512-uf/ZVpAabDBPvdPdveyk1EPgbnloPvFFGgmRhYLTDH7gEB4nZdSBk8yTU47w1g/drLSx5uMOkjKk7IWKfWg/+w==", "dev": true, "requires": { "fs-access": "1.0.1", @@ -10113,7 +10113,7 @@ "karma-firefox-launcher": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/karma-firefox-launcher/-/karma-firefox-launcher-1.1.0.tgz", - "integrity": "sha1-LEcDBFLwRTHrfRPU/HZpYwu5Mzk=", + "integrity": "sha512-LbZ5/XlIXLeQ3cqnCbYLn+rOVhuMIK9aZwlP6eOLGzWdo1UVp7t6CN3DP4SafiRLjexKwHeKHDm0c38Mtd3VxA==", "dev": true }, "karma-jasmine": { @@ -10134,7 +10134,7 @@ "karma-webpack": { "version": "2.0.9", "resolved": "https://registry.npmjs.org/karma-webpack/-/karma-webpack-2.0.9.tgz", - "integrity": "sha1-YciAkffdkQY1E0wDKyZqRlr/tX8=", + "integrity": "sha512-F1j3IG/XhiMzcunAXbWXH95uizjzr3WdTzmVWlta8xqxcCtAu9FByCb4sccIMxaVFAefpgnUW9KlCo0oLvIX6A==", "dev": true, "requires": { "async": "0.9.2", @@ -14654,7 +14654,7 @@ "useragent": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/useragent/-/useragent-2.3.0.tgz", - "integrity": "sha1-IX+UOtVAyyEoZYqyP8lg9qiMmXI=", + "integrity": "sha512-4AoH4pxuSvHCjqLO04sU6U/uE65BYza8l/KKBS0b0hnUPWi+cQ2BpeTEwejCSx9SPV5/U03nniDTrWx5NrmKdw==", "dev": true, "requires": { "lru-cache": "4.1.1", diff --git a/services/db/02-fixtures.sql b/services/db/02-fixtures.sql index ad22fa67b..a9da268d6 100644 --- a/services/db/02-fixtures.sql +++ b/services/db/02-fixtures.sql @@ -390,16 +390,16 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city INSERT INTO `salix`.`Address`(`id`, `consignee`, `street`, `city`, `postcode`, `provinceFk`, `phone`, `mobile`, `isEnabled`, `isDefaultAddress`, `clientFk`, `defaultAgencyFk`, `longitude`, `latitude`, `isEqualizated`) VALUES - (1, 'Bruce Wayne', 'The Bat cave', 'Silla', 46460, 1, NULL, NULL, 1, 1, 1, 2, NULL, NULL, 0), - (2, 'Petter Parker', 'NY roofs', 'Silla', 46460, 1, NULL, NULL, 1, 1, 2, 2, NULL, NULL, 0), - (3, 'Clark Kenn', 'The phone box', 'Silla', 46460, 1, NULL, NULL, 1, 1, 3, 2, NULL, NULL, 0), - (4, 'Tony Stark', 'Stark tower', 'Silla', 46460, 1, NULL, NULL, 1, 1, 4, 2, NULL, NULL, 0), - (5, 'Max Eisenhardt', 'The plastic cell', 'Silla', 46460, 1, NULL, NULL, 1, 1, 5, 2, NULL, NULL, 0), - (6, 'David Charles Haller', 'Many places', 'Silla', 46460, 1, NULL, NULL, 1, 1, 6, 2, NULL, NULL, 0), - (7, 'Hank Pym', 'Your pocket', 'Silla', 46460, 1, NULL, NULL, 1, 1, 7, 2, NULL, NULL, 0), - (8, 'Charles Xavier', 'Cerebro', 'Silla', 46460, 1, NULL, NULL, 1, 1, 8, 2, NULL, NULL, 0), - (9, 'Bruce Banner', 'Somewhere in Thailand', 'Silla', 46460, 1, NULL, NULL, 1, 1, 9, 2, NULL, NULL, 0), - (10,'Jessica Jones', 'Luke Cages Bar', 'Silla', 46460, 1, NULL, NULL, 1, 1, 10, 2, NULL, NULL, 0); + (101, 'Bruce Wayne', 'The Bat cave', 'Silla', 46460, 1, NULL, NULL, 1, 1, 1, 2, NULL, NULL, 0), + (102, 'Petter Parker', 'NY roofs', 'Silla', 46460, 1, NULL, NULL, 1, 1, 2, 2, NULL, NULL, 0), + (103, 'Clark Kenn', 'The phone box', 'Silla', 46460, 1, NULL, NULL, 1, 1, 3, 2, NULL, NULL, 0), + (104, 'Tony Stark', 'Stark tower', 'Silla', 46460, 1, NULL, NULL, 1, 1, 4, 2, NULL, NULL, 0), + (105, 'Max Eisenhardt', 'The plastic cell', 'Silla', 46460, 1, NULL, NULL, 1, 1, 5, 2, NULL, NULL, 0), + (106, 'David Charles Haller', 'Many places', 'Silla', 46460, 1, NULL, NULL, 1, 1, 6, 2, NULL, NULL, 0), + (107, 'Hank Pym', 'Your pocket', 'Silla', 46460, 1, NULL, NULL, 1, 1, 7, 2, NULL, NULL, 0), + (108, 'Charles Xavier', 'Cerebro', 'Silla', 46460, 1, NULL, NULL, 1, 1, 8, 2, NULL, NULL, 0), + (109, 'Bruce Banner', 'Somewhere in Thailand', 'Silla', 46460, 1, NULL, NULL, 1, 1, 9, 2, NULL, NULL, 0), + (1010,'Jessica Jones', 'Luke Cages Bar', 'Silla', 46460, 1, NULL, NULL, 1, 1, 10, 2, NULL, NULL, 0); INSERT INTO `salix`.`ClientCredit`(`id`, `clientFk`, `employeeFk`, `amount`, `created`) VALUES From 7aa977e0719a823df42178938f0077bdd1ce8987 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 7 Feb 2018 12:14:41 +0100 Subject: [PATCH 5/8] bug en gulpfile si se cierra inesperadamente nging --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 6789bc3c3..15941c78d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -181,7 +181,7 @@ gulp.task('nginx-stop', ['nginx-conf'], async () => { return new Promise((resolve, reject) => { exec(command, err => { - if (err) return reject(err); + if (err && err.code != 1) return reject(err); resolve(); }); }); From fb9ba713bd6656d6f796392392f606c3e5c16b08 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 13:10:22 +0100 Subject: [PATCH 6/8] addresses observations finish --- .../client/src/address-edit/address-edit.html | 2 +- .../client/src/address-edit/address-edit.js | 29 ++++++++++--------- client/client/src/address-edit/locale/es.yml | 5 +++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/client/client/src/address-edit/address-edit.html b/client/client/src/address-edit/address-edit.html index f703c3803..e846eadfe 100644 --- a/client/client/src/address-edit/address-edit.html +++ b/client/client/src/address-edit/address-edit.html @@ -77,7 +77,7 @@ margin-medium-left orange icon="add_circle" - ng-if = "observation.showAddIcon" + ng-if = "observation.showAddIcon && observationsTypes.model.length > $ctrl.observations.length" ng-click="$ctrl.addObservation()" > diff --git a/client/client/src/address-edit/address-edit.js b/client/client/src/address-edit/address-edit.js index 8d7a56994..90009cbe8 100644 --- a/client/client/src/address-edit/address-edit.js +++ b/client/client/src/address-edit/address-edit.js @@ -13,7 +13,7 @@ export default class Controller { id: parseInt($state.params.addressId) }; this.observations = []; - this.observationsDictionary = {}; + this.observationsOld = {}; this.observationsRemoved = []; } @@ -60,11 +60,16 @@ export default class Controller { return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, objectObservations); } + _observationsEquals(ob1, ob2) { + return ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description; + } + submit() { this._unsetDirtyForm(); let submitWatcher = this.$scope.watcher.dataChanged(); let submitObservations; let repeatedTypes = false; + let types = []; let observationsObj = { delete: this.observationsRemoved, create: [], @@ -73,31 +78,27 @@ export default class Controller { for (let i = 0; i < this.observations.length; i++) { let observation = this.observations[i]; - // only one observation is allowed for each of its types - if (this.observationsDictionary[observation.observationTypeFk] !== undefined && // IF the dictionary contains the type - ( - // AND (is a new Observation OR is old but with distinct Id) --> repeated - !observation.id || (observation.id && this.observationsDictionary[observation.observationTypeFk].id !== observation.id) - ) - ) { + let isNewObservation = observation.id === undefined; + + if (types.indexOf(observation.observationTypeFk) !== -1) { repeatedTypes = true; break; } - if (!observation.id && observation.observationTypeFk && observation.description) { + types.push(observation.observationTypeFk); + + if (isNewObservation && observation.observationTypeFk && observation.description) { observationsObj.create.push(observation); - } else if (observation.id && this.observationsDictionary[observation.observationTypeFk].description !== observation.description) { + } else if (!isNewObservation && !this._observationsEquals(this.observationsOld[observation.id], observation)) { observationsObj.update.push(observation); } - - this.observationsDictionary[observation.observationTypeFk] = observation; } submitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0; if (repeatedTypes) { this.vnApp.showMessage( - this.$translate.instant('you can not repeat the types of observations') + this.$translate.instant('The observation type must be unique') ); } else if (submitWatcher && !submitObservations) { this.$scope.watcher.submit().then(() => { @@ -126,7 +127,7 @@ export default class Controller { this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => { this.observations = res.data; res.data.forEach(item => { - this.observationsDictionary[item.observationTypeFk] = Object.assign({}, item); + this.observationsOld[item.id] = Object.assign({}, item); }); }); } diff --git a/client/client/src/address-edit/locale/es.yml b/client/client/src/address-edit/locale/es.yml index aad6a3c87..78f236039 100644 --- a/client/client/src/address-edit/locale/es.yml +++ b/client/client/src/address-edit/locale/es.yml @@ -1,2 +1,5 @@ Enabled: Activo -Is equalizated: Recargo de equivalencia \ No newline at end of file +Is equalizated: Recargo de equivalencia +Observation type: Tipo de observación +Description: Descripción +The observation type must be unique: El tipo de observación ha de ser único \ No newline at end of file From ca0731714a1f7edc40ca2a5a625ed61fc8da211d Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 7 Feb 2018 13:24:46 +0100 Subject: [PATCH 7/8] Gulp bugs --- gulpfile.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 4d0accd05..71be26d3d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -77,9 +77,17 @@ gulp.task('e2e-run', () => { gulp.task('clean', () => { const del = require('del'); - return del([`${buildDir}/*`, `!${buildDir}/templates`, `!${buildDir}/images`], {force: true}); + const files = [ + `${buildDir}/*`, + `!${buildDir}/templates`, + `!${buildDir}/images`, + `docker-compose.yml` + ]; + return del(files, {force: true}); }); +gulp.task('i', ['install']); + gulp.task('install', () => { const install = require('gulp-install'); let jsonFile = []; @@ -97,9 +105,6 @@ gulp.task('install', () => { })); }); -// Gulp install alias -gulp.task('i', ['install']); - // Deployment gulp.task('build', ['clean'], () => { @@ -186,9 +191,8 @@ gulp.task('nginx-stop', ['nginx-conf'], async () => { gulp.task('nginx-conf', async () => { const mustache = require('mustache'); - if (!fs.existsSync(nginxTemp)) { - fs.mkdirSync(nginxTemp); - } + if (!await fs.exists(nginxTemp)) + await fs.mkdir(nginxTemp); let params = { services: await getServices(), @@ -215,11 +219,8 @@ gulp.task('nginx-clean', () => { return del([`${nginxTemp}/*`], {force: true}); }); -let services; - async function getServices() { - if (services) return services; - + let services; let startPort = defaultPort + 1; services = []; @@ -285,7 +286,7 @@ gulp.task('webpack-dev-server', function() { // Locale -let localeFiles = `${srcDir}/**/locale/*.json`; +let localeFiles = `${srcDir}/**/locale/*.yml`; gulp.task('locales', function() { const extend = require('gulp-extend'); From de9f7a5545151b15875360b655165c130f9b9e34 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 7 Feb 2018 13:48:55 +0100 Subject: [PATCH 8/8] item history --- client/item/src/history/item-history.html | 5 +-- services/item/common/methods/item/getLog.js | 34 ++++++-------------- services/item/common/models/itemLog.js | 3 ++ services/item/common/models/itemLog.json | 35 +++++++++++++++++++++ services/item/server/model-config.json | 3 ++ services_tests.js | 1 - 6 files changed, 52 insertions(+), 29 deletions(-) create mode 100644 services/item/common/models/itemLog.js create mode 100644 services/item/common/models/itemLog.json diff --git a/client/item/src/history/item-history.html b/client/item/src/history/item-history.html index 1a5a65483..fe1c1faf7 100644 --- a/client/item/src/history/item-history.html +++ b/client/item/src/history/item-history.html @@ -1,5 +1,4 @@ - - + Item history @@ -22,12 +21,10 @@ {{::itemLog.description}} - No results - diff --git a/services/item/common/methods/item/getLog.js b/services/item/common/methods/item/getLog.js index 50d563c08..3b214e5c8 100644 --- a/services/item/common/methods/item/getLog.js +++ b/services/item/common/methods/item/getLog.js @@ -1,27 +1,13 @@ module.exports = Self => { - Self.remoteMethod('itemLog', { - description: 'Returns the item changes log', - accessType: 'READ', - accepts: [{ - arg: 'id', - type: 'number', - required: true, - description: 'The item id', - http: {source: 'path'} - }], - returns: { - arg: 'data', - type: ['Object'], - root: true - }, - http: { - path: `/:id/itemLog`, - verb: 'get' - } - }); + Self.installMethod('getLog', filterParams); - Self.itemLog = itemFk => { - let query = `SELECT * FROM vn.itemLog WHERE itemFk = ?`; - return Self.rawSql(query, [itemFk]); - }; + function filterParams(params) { + return { + where: { + itemFk: params.itemFk + }, + skip: (params.page - 1) * params.size, + limit: params.size + }; + } }; diff --git a/services/item/common/models/itemLog.js b/services/item/common/models/itemLog.js new file mode 100644 index 000000000..248cc6abd --- /dev/null +++ b/services/item/common/models/itemLog.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + require('../methods/item/getLog.js')(Self); +}; diff --git a/services/item/common/models/itemLog.json b/services/item/common/models/itemLog.json new file mode 100644 index 000000000..63777113f --- /dev/null +++ b/services/item/common/models/itemLog.json @@ -0,0 +1,35 @@ +{ + "name": "ItemLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemLog", + "database": "vn" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "creationDate": { + "type": "Date" + }, + "description": { + "type": "String" + } + }, + "relations": { + "originFk": { + "type": "belongsTo", + "model": "Origin", + "foreignKey": "originFk" + }, + "userFk": { + "type": "belongsTo", + "model": "User", + "foreignKey": "userFk" + } + } + } diff --git a/services/item/server/model-config.json b/services/item/server/model-config.json index f001fcba1..09eed1735 100644 --- a/services/item/server/model-config.json +++ b/services/item/server/model-config.json @@ -34,5 +34,8 @@ }, "Tag": { "dataSource": "vn" + }, + "ItemLog": { + "dataSource": "vn" } } diff --git a/services_tests.js b/services_tests.js index 0ce869843..068f8c8f2 100644 --- a/services_tests.js +++ b/services_tests.js @@ -36,4 +36,3 @@ jasmine.addReporter(new SpecReporter({ })); jasmine.execute(); -