diff --git a/client/client/src/address-edit/address-edit.js b/client/client/src/address-edit/address-edit.js index 90009cbe8..3046b2733 100644 --- a/client/client/src/address-edit/address-edit.js +++ b/client/client/src/address-edit/address-edit.js @@ -61,7 +61,7 @@ export default class Controller { } _observationsEquals(ob1, ob2) { - return ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description; + return ob1.id === ob2.id && ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description; } submit() { @@ -80,12 +80,13 @@ export default class Controller { let observation = this.observations[i]; let isNewObservation = observation.id === undefined; - if (types.indexOf(observation.observationTypeFk) !== -1) { + if (observation.observationTypeFk && types.indexOf(observation.observationTypeFk) !== -1) { repeatedTypes = true; break; } - types.push(observation.observationTypeFk); + if (observation.observationTypeFk) + types.push(observation.observationTypeFk); if (isNewObservation && observation.observationTypeFk && observation.description) { observationsObj.create.push(observation); diff --git a/client/client/src/address-edit/address-edit.spec.js b/client/client/src/address-edit/address-edit.spec.js index 18fff508f..5c41d653c 100644 --- a/client/client/src/address-edit/address-edit.spec.js +++ b/client/client/src/address-edit/address-edit.spec.js @@ -20,7 +20,46 @@ describe('Client', () => { })); it('should define and set address property', () => { - expect(controller.address.id).toBe(1); + expect(controller.address.id).toEqual(1); + }); + + describe('removeObservation(index)', () => { + it('should remove an observation that occupies in the index given and restore showAddIcon properties', () => { + let index = 2; + controller.observations = [ + {id: 1, description: 'Spiderman rocks', showAddIcon: false}, + {id: 2, description: 'Batman sucks', showAddIcon: false}, + {id: 3, description: 'Ironman rules', showAddIcon: true} + ]; + + spyOn(controller, '_setIconAdd').and.callThrough(); + + controller.removeObservation(index); + + expect(controller._setIconAdd).toHaveBeenCalledWith(); + expect(controller.observations.length).toEqual(2); + expect(controller.observations[0].showAddIcon).toBeFalsy(); + expect(controller.observations[1].showAddIcon).toBeTruthy(); + expect(controller.observations[index]).toBe(undefined); + }); + }); + + describe('_observationsEquals', () => { + it('should return true if two observations are equals independent of control attributes', () => { + let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true}; + let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: false}; + let equals = controller._observationsEquals(ob2, ob1); + + expect(equals).toBeTruthy(); + }); + + it('should return false if two observations are not equals independent of control attributes', () => { + let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true}; + let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman sucks', showAddIcon: true}; + let equals = controller._observationsEquals(ob2, ob1); + + expect(equals).toBeFalsy(); + }); }); describe('$onInit()', () => { diff --git a/client/item/src/history/item-history.html b/client/item/src/history/item-history.html index 1a5a65483..3409dc04b 100644 --- a/client/item/src/history/item-history.html +++ b/client/item/src/history/item-history.html @@ -1,5 +1,4 @@ - - + Item history @@ -15,19 +14,17 @@ class="list list-element text-center" pad-small-bottom ng-repeat="itemLog in index.model.instances track by itemLog.id"> - {{::itemLog.originFk}} - {{::itemLog.userFk}} + {{::itemLog.origin.name}} + {{::itemLog.user.name}} {{::itemLog.action}} {{::itemLog.creationDate | date:'dd/MM/yyyy HH:mm'}} {{::itemLog.description}} - No results - diff --git a/gulpfile.js b/gulpfile.js index 28f1e37f6..c0e09936e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,6 +11,10 @@ const exec = require('child_process').exec; // Configuration const isWindows = /^win/.test(process.platform); + +if (gutil.env.NODE_ENV) + process.env.NODE_ENV = gutil.env.NODE_ENV; + const env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; const langs = ['es', 'en']; @@ -118,17 +122,17 @@ gulp.task('docker-compose', async () => { let services = await getServices(); for (let service of services) { - let dockerFile = `${__dirname}/Dockerfile`; + let dockerFile = `${__dirname}/${service.name}/Dockerfile`; - if (await fs.exists(`./services/${service.name}/Dockerfile`)) - dockerFile = 'Dockerfile'; + // if (await fs.exists(`./services/${service.name}/Dockerfile`)) + // dockerFile = 'Dockerfile'; composeYml.services[service.name] = { environment: ['NODE_ENV=${NODE_ENV}'], container_name: `\${BRANCH_NAME}-${service.name}`, image: `${service.name}:\${TAG}`, build: { - context: `./services/${service.name}`, + context: `./services`, dockerfile: dockerFile }, ports: [`${defaultPort}:${service.port}`] diff --git a/services/auth/Dockerfile b/services/auth/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/auth/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/client/Dockerfile b/services/client/Dockerfile new file mode 100644 index 000000000..b1197d171 --- /dev/null +++ b/services/client/Dockerfile @@ -0,0 +1,12 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] + diff --git a/services/item/Dockerfile b/services/item/Dockerfile new file mode 100644 index 000000000..b1197d171 --- /dev/null +++ b/services/item/Dockerfile @@ -0,0 +1,12 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] + diff --git a/services/item/common/methods/item/getLog.js b/services/item/common/methods/item/getLog.js index 50d563c08..3c0c1e413 100644 --- a/services/item/common/methods/item/getLog.js +++ b/services/item/common/methods/item/getLog.js @@ -1,27 +1,19 @@ 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, + include: [{ + relation: "origin" + }, + { + relation: "user" + }] + }; + } }; diff --git a/services/item/common/models/item.js b/services/item/common/models/item.js index 3cbc622bd..2c193b587 100644 --- a/services/item/common/models/item.js +++ b/services/item/common/models/item.js @@ -1,6 +1,5 @@ module.exports = function(Self) { require('../methods/item/filter.js')(Self); - require('../methods/item/getLog.js')(Self); Self.validatesPresenceOf('name', {message: 'Cannot be blank'}); Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'}); 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..60a105dff --- /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": { + "origin": { + "type": "belongsTo", + "model": "Origin", + "foreignKey": "originFk" + }, + "user": { + "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/mailer/Dockerfile b/services/mailer/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/mailer/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/print/Dockerfile b/services/print/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/print/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/production/Dockerfile b/services/production/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/production/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/route/Dockerfile b/services/route/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/route/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/salix/Dockerfile b/services/salix/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/salix/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] 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(); -