From 0a107ba0bc29ff3f73570d3745cca468fa32545b Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 09:57:51 +0100 Subject: [PATCH 1/5] docker --- services/auth/Dockerfile | 6 ++++-- services/client/Dockerfile | 6 ++++-- services/production/Dockerfile | 6 ++++-- services/route/Dockerfile | 6 ++++-- services/salix/Dockerfile | 6 ++++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/services/auth/Dockerfile b/services/auth/Dockerfile index 43ea06188..d3bfe4338 100644 --- a/services/auth/Dockerfile +++ b/services/auth/Dockerfile @@ -1,8 +1,10 @@ FROM node:6.9.1 -COPY ./auth /app +COPY auth /app -COPY ./loopback /loopback +COPY loopback /loopback + +RUN npm install /loopback WORKDIR /app diff --git a/services/client/Dockerfile b/services/client/Dockerfile index 093176521..71f255c9d 100644 --- a/services/client/Dockerfile +++ b/services/client/Dockerfile @@ -1,8 +1,10 @@ FROM node:6.9.1 -COPY ./client /app +COPY client /app -COPY ./loopback /loopback +COPY loopback /loopback + +RUN npm install /loopback WORKDIR /app diff --git a/services/production/Dockerfile b/services/production/Dockerfile index ef90aeb04..7241505bf 100644 --- a/services/production/Dockerfile +++ b/services/production/Dockerfile @@ -1,8 +1,10 @@ FROM node:6.9.1 -COPY ./production /app +COPY production /app -COPY ./loopback /loopback +COPY loopback /loopback + +RUN npm install /loopback WORKDIR /app diff --git a/services/route/Dockerfile b/services/route/Dockerfile index cbda24b7e..fc2de4e7f 100644 --- a/services/route/Dockerfile +++ b/services/route/Dockerfile @@ -1,8 +1,10 @@ FROM node:6.9.1 -COPY ./route /app +COPY route /app -COPY ./loopback /loopback +COPY loopback /loopback + +RUN npm install /loopback WORKDIR /app diff --git a/services/salix/Dockerfile b/services/salix/Dockerfile index ed51d5ce4..61f687e33 100644 --- a/services/salix/Dockerfile +++ b/services/salix/Dockerfile @@ -1,8 +1,10 @@ FROM node:6.9.1 -COPY ./salix /app +COPY salix /app -COPY ./loopback /loopback +COPY loopback /loopback + +RUN npm install /loopback WORKDIR /app From a82de780409bbef8e2a79e9b893c52f766823ecc Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 10:54:59 +0100 Subject: [PATCH 2/5] docker compose --- docker-compose.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 4387b322c..4b4de282a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -64,6 +64,19 @@ services: ports: - "3004:3004" + route: + environment: + - NODE_ENV=${NODE_ENV} + container_name: "${BRANCH_NAME}-route" + image: "route:${TAG}" + build: + context: ./services + dockerfile: /route/Dockerfile + expose: + - "3005" + ports: + - "3005:3005" + nginx: container_name: "${BRANCH_NAME}-nginx" image: "nginx:${TAG}" From 061ae64c503883ebb0f4bd5e4b16b71abfb0fcc3 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 8 Nov 2017 13:42:33 +0100 Subject: [PATCH 3/5] production filtering in temporary table --- client/production/src/index/index.js | 14 ++- client/salix/src/styles/misc.scss | 2 +- services/loopback/common/models/vn-model.js | 8 +- .../common/methods/fake-production/list.js | 101 ++++++++++-------- 4 files changed, 77 insertions(+), 48 deletions(-) diff --git a/client/production/src/index/index.js b/client/production/src/index/index.js index 1c8072eb5..409c3f0fe 100644 --- a/client/production/src/index/index.js +++ b/client/production/src/index/index.js @@ -83,7 +83,15 @@ export default class ProductionIndex { event.preventDefault(); } onChildSubmit(filter) { - this.searchTickets(filter); + let newFilter = {}; + Object.keys(filter).forEach( + field => { + if (filter[field] !== null) { + newFilter[field] = filter[field]; + } + } + ); + this.searchTickets(newFilter); this.onChildCancel(); } onChildCancel() { @@ -111,7 +119,7 @@ export default class ProductionIndex { } refreshTickets() { this.filter = {}; - this.filter.warehouseFk = this.userProfile.warehouseId; + this.filter.warehouseFk = this.$.displayValue = this.userProfile.warehouseId; this.search = null; } onChangeWareHouse(warehouse) { @@ -130,7 +138,7 @@ export default class ProductionIndex { this.hourItems.push({id: i, name: hour}); } this.filter.warehouseFk = this.$.displayValue = this.userProfile.warehouseId; - this.searchTickets(this.filter); + // this.searchTickets(this.filter); } } diff --git a/client/salix/src/styles/misc.scss b/client/salix/src/styles/misc.scss index da372d72d..8168b6781 100644 --- a/client/salix/src/styles/misc.scss +++ b/client/salix/src/styles/misc.scss @@ -52,7 +52,7 @@ html [vn-center], .vn-center{ } .list-element{ - padding: 4px 0px; + padding: 8px 0 0 0; border-bottom: 1px solid $color-medium-grey; i { color: $color-orange; diff --git a/services/loopback/common/models/vn-model.js b/services/loopback/common/models/vn-model.js index 740e41a36..72605a808 100644 --- a/services/loopback/common/models/vn-model.js +++ b/services/loopback/common/models/vn-model.js @@ -2,7 +2,7 @@ module.exports = function(Self) { Self.setup = function() { Self.super_.setup.call(this); - let disableMethods = { + /* let disableMethods = { create: true, replaceOrCreate: true, patchOrCreate: true, @@ -22,7 +22,7 @@ module.exports = function(Self) { }; for (let method in disableMethods) { // this.disableRemoteMethod(method, disableMethods[method]); - } + } */ }; Self.defineScope = function(serverFilter) { @@ -108,6 +108,10 @@ module.exports = function(Self) { this.remoteMethod(methodName, args); }; + Self.getConnection = function(cb) { + this.dataSource.connector.client.getConnection(cb); + }; + Self.connectToService = function(ctx, dataSource) { this.app.dataSources[dataSource].connector.remotes.auth = { bearer: new Buffer(ctx.req.accessToken.id).toString('base64'), diff --git a/services/production/common/methods/fake-production/list.js b/services/production/common/methods/fake-production/list.js index 88f777e18..3282348cd 100644 --- a/services/production/common/methods/fake-production/list.js +++ b/services/production/common/methods/fake-production/list.js @@ -1,62 +1,79 @@ -module.exports = function(FakeProduction) { - FakeProduction.defineScope(); +module.exports = function(Self) { + Self.defineScope(); - FakeProduction.list = function(ctx, filter, cb) { + Self.list = function(ctx, filter, callback) { var page = filter.page - 1; var limit = filter.limit * page; var offset = (page + 1) * filter.limit; let daysTickets = 0; + let warehouseFk = filter.where.warehouseFk; delete filter.limit; delete filter.page; + delete filter.where.warehouseFk; - let query = `call salix.production_control_source( ? , ?)`; - var params = [filter.where.warehouseFk, daysTickets]; - FakeProduction.rawSql(query, params) - .then(function(response) { - getValue(); - }) - .catch(function(response) { - cb(response, null); - }); - let getValue = () => { + let call = `call salix.production_control_source(? , ?)`; + var params = [warehouseFk, daysTickets]; + let conn; + + Self.getConnection((err, connection) => { + if (err) { + onFinish(err); + } + conn = connection; + conn.query(call, params, getValue); + }); + + function getValue(err) { + if (err) { + onFinish(err); + } if (filter.where && filter.where.q) { - var newFilter = { - and: [ - { - or: [ - {agency: {regexp: filter.where.q}}, - {state: {regexp: filter.where.q}} - ] - } - ] - }; + let regexQ = new RegExp(filter.where.q); + delete filter.where.q; + let newFilter = { + and: [ + { + or: [ + {agency: {regexp: regexQ}}, + {state: {regexp: regexQ}} + ] + } + ] + }; - delete filter.where.q; - - if (Object.keys(filter.where).length) { - Object.keys(filter.where).forEach( - key => { - let field = {}; - field[key] = filter.where[key]; - newFilter.and.push(field); - } - ); - } + if (Object.keys(filter.where).length) { + Object.keys(filter.where).forEach( + key => { + let field = {}; + field[key] = filter.where[key]; + newFilter.and.push(field); + } + ); + } filter.where = newFilter; } - FakeProduction.connectToService(ctx, "client"); - this.find(filter, function(err, tickets) { - FakeProduction.disconnectFromService("client"); - (err) ? cb(err, null) : cb(null, (sum(tickets))); - }); - }; - function sum(tickets){ + let where = Self.dataSource.connector.buildWhere(Self.modelName, filter.where); + let query = `SELECT * FROM FakeProduction_tmp ${where.sql} GROUP BY RouteFk ORDER BY routeFk`; + conn.query(query, where.params, onFinish); + } + + function onFinish(err, results) { + conn.query('DROP TEMPORARY TABLE IF EXISTS FakeProduction_tmp'); + conn.release(); + if (err) + callback(err); + callback(null, sum(results)); + } + + function sum(tickets) { var obj = {lines: 0, m3: 0}; - tickets.forEach(function(t) { + tickets.forEach(function(t, i) { obj.lines += t.lines; obj.m3 += t.m3; + if (tickets[i].problem) + tickets[i].problem = tickets[i].problem.trim(); }, this); obj.m3 = obj.m3.toFixed(2); obj.total = tickets.length; From 1d109f237196e0c043542908ff17d91d27a3d6cd Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 14:11:33 +0100 Subject: [PATCH 4/5] docker --- Jenkinsfile | 2 +- docker-compose.yml | 1 + services/auth/Dockerfile | 2 +- services/client/Dockerfile | 2 +- services/production/Dockerfile | 2 +- services/route/Dockerfile | 2 +- services/salix/Dockerfile | 2 +- 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ae8b0e27d..82748e93d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,7 @@ if (branchName == branchProduction) node { stage ('Print environment variables'){ - echo "Branch ${branchName}, Build ${env.TAG} en docker Host ${dockerHost}" + echo "Branch ${branchName}, Build ${env.TAG}, NODE_ENV ${env.NODE_ENV} en docker Host ${dockerHost}" } stage ('Checkout') { checkout scm diff --git a/docker-compose.yml b/docker-compose.yml index 4b4de282a..c7a491d49 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -93,3 +93,4 @@ services: - "client:${BRANCH_NAME}-client" - "mailer:${BRANCH_NAME}-mailer" - "production:${BRANCH_NAME}-production" + - "route:${BRANCH_NAME}-route" diff --git a/services/auth/Dockerfile b/services/auth/Dockerfile index d3bfe4338..f0390d9e9 100644 --- a/services/auth/Dockerfile +++ b/services/auth/Dockerfile @@ -4,7 +4,7 @@ COPY auth /app COPY loopback /loopback -RUN npm install /loopback +RUN npm install loopback WORKDIR /app diff --git a/services/client/Dockerfile b/services/client/Dockerfile index 71f255c9d..01cc147f1 100644 --- a/services/client/Dockerfile +++ b/services/client/Dockerfile @@ -4,7 +4,7 @@ COPY client /app COPY loopback /loopback -RUN npm install /loopback +RUN npm install loopback WORKDIR /app diff --git a/services/production/Dockerfile b/services/production/Dockerfile index 7241505bf..41e52e736 100644 --- a/services/production/Dockerfile +++ b/services/production/Dockerfile @@ -4,7 +4,7 @@ COPY production /app COPY loopback /loopback -RUN npm install /loopback +RUN npm install loopback WORKDIR /app diff --git a/services/route/Dockerfile b/services/route/Dockerfile index fc2de4e7f..6491d6e4f 100644 --- a/services/route/Dockerfile +++ b/services/route/Dockerfile @@ -4,7 +4,7 @@ COPY route /app COPY loopback /loopback -RUN npm install /loopback +RUN npm install loopback WORKDIR /app diff --git a/services/salix/Dockerfile b/services/salix/Dockerfile index 61f687e33..8af14e460 100644 --- a/services/salix/Dockerfile +++ b/services/salix/Dockerfile @@ -4,7 +4,7 @@ COPY salix /app COPY loopback /loopback -RUN npm install /loopback +RUN npm install loopback WORKDIR /app From f71dfa53ef827c8233b887d28acde4d41d773993 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 8 Nov 2017 14:59:46 +0100 Subject: [PATCH 5/5] refact list production --- client/core/src/paging/paging.html | 3 ++- client/production/src/index/index.js | 1 - .../src/production-table/production-table.js | 2 +- .../common/methods/fake-production/list.js | 13 ++++++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/core/src/paging/paging.html b/client/core/src/paging/paging.html index 6e2f56fd3..6e71f321d 100644 --- a/client/core/src/paging/paging.html +++ b/client/core/src/paging/paging.html @@ -1,6 +1,7 @@