From d2de312a27c910ca839e0156b9a60270ed914836 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 15 Jul 2019 11:40:11 +0200 Subject: [PATCH 01/22] dms update files --- back/methods/dms/specs/updateFile.spec.js | 22 +++ back/methods/dms/updateFile.js | 158 ++++++++++++++++++++ back/methods/dms/uploadFile.js | 14 +- back/models/dms.js | 1 + front/core/components/table/style.scss | 6 + loopback/server/boot/storage.js | 2 +- modules/client/front/dms/edit/index.html | 63 ++++++++ modules/client/front/dms/edit/index.js | 86 +++++++++++ modules/client/front/dms/edit/index.spec.js | 60 ++++++++ modules/client/front/dms/edit/locale/es.yml | 3 + modules/client/front/dms/edit/style.scss | 7 + modules/client/front/dms/index/index.html | 19 ++- modules/client/front/index.js | 1 + modules/client/front/routes.json | 9 ++ modules/ticket/front/dms/edit/index.html | 63 ++++++++ modules/ticket/front/dms/edit/index.js | 86 +++++++++++ modules/ticket/front/dms/edit/index.spec.js | 60 ++++++++ modules/ticket/front/dms/edit/locale/es.yml | 3 + modules/ticket/front/dms/edit/style.scss | 7 + modules/ticket/front/dms/index/index.html | 7 +- modules/ticket/front/index.js | 1 + modules/ticket/front/routes.json | 9 ++ 22 files changed, 670 insertions(+), 17 deletions(-) create mode 100644 back/methods/dms/specs/updateFile.spec.js create mode 100644 back/methods/dms/updateFile.js create mode 100644 modules/client/front/dms/edit/index.html create mode 100644 modules/client/front/dms/edit/index.js create mode 100644 modules/client/front/dms/edit/index.spec.js create mode 100644 modules/client/front/dms/edit/locale/es.yml create mode 100644 modules/client/front/dms/edit/style.scss create mode 100644 modules/ticket/front/dms/edit/index.html create mode 100644 modules/ticket/front/dms/edit/index.js create mode 100644 modules/ticket/front/dms/edit/index.spec.js create mode 100644 modules/ticket/front/dms/edit/locale/es.yml create mode 100644 modules/ticket/front/dms/edit/style.scss diff --git a/back/methods/dms/specs/updateFile.spec.js b/back/methods/dms/specs/updateFile.spec.js new file mode 100644 index 000000000..2945b1ac9 --- /dev/null +++ b/back/methods/dms/specs/updateFile.spec.js @@ -0,0 +1,22 @@ +const app = require('vn-loopback/server/server'); + +describe('dms updateFile()', () => { + it(`should return an error for a user without enough privileges`, async() => { + let clientId = 101; + let companyId = 442; + let warehouseId = 1; + let dmsTypeId = 14; + + let dmsId = 1; + let ctx = {req: {accessToken: {userId: clientId}}, args: {dmsTypeId: dmsTypeId}}; + + let error; + await app.models.Dms.updateFile(ctx, dmsId, warehouseId, companyId, dmsTypeId).catch(e => { + error = e; + }).finally(() => { + expect(error.message).toEqual(`You don't have enough privileges`); + }); + + expect(error).toBeDefined(); + }); +}); diff --git a/back/methods/dms/updateFile.js b/back/methods/dms/updateFile.js new file mode 100644 index 000000000..e502c7b94 --- /dev/null +++ b/back/methods/dms/updateFile.js @@ -0,0 +1,158 @@ +const UserError = require('vn-loopback/util/user-error'); +const fs = require('fs-extra'); + +module.exports = Self => { + Self.remoteMethodCtx('updateFile', { + description: 'updates a file properties or file', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'Number', + description: 'The document id', + http: {source: 'path'} + }, + { + arg: 'warehouseId', + type: 'Number', + description: 'The warehouse id' + }, { + arg: 'companyId', + type: 'Number', + description: 'The company id' + }, { + arg: 'dmsTypeId', + type: 'Number', + description: 'The dms type id' + }, { + arg: 'reference', + type: 'String' + }, { + arg: 'description', + type: 'String' + }, { + arg: 'hasFile', + type: 'Boolean', + description: 'True if has an attached file' + }], + returns: { + type: 'Object', + root: true + }, + http: { + path: `/:id/updateFile`, + verb: 'POST' + } + }); + + Self.updateFile = async(ctx, id, warehouseId, companyId, + dmsTypeId, reference, description, hasFile, options) => { + const storageConnector = Self.app.dataSources.storage.connector; + const models = Self.app.models; + const fileOptions = {}; + + let tx; + let myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const hasWriteRole = await models.DmsType.hasWriteRole(ctx, dmsTypeId); + if (!hasWriteRole) + throw new UserError(`You don't have enough privileges`); + + // Upload file to temporary path + const tempContainer = await getContainer('temp'); + let files = []; + try { + const uploaded = await models.Container.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); + files = Object.values(uploaded.files).map(file => { + return file[0]; + }); + } catch (err) { + if (err.message != 'No file content uploaded') + throw e; + } + + const updatedDmsList = []; + for (const file of files) { + const updatedDms = await updateDms(id, dmsTypeId, companyId, warehouseId, + reference, description, hasFile, file.name, myOptions); + + const pathHash = storageConnector.getPathHash(updatedDms.id); + const container = await getContainer(pathHash); + + const originPath = `${tempContainer.client.root}/${tempContainer.name}/${file.name}`; + const destinationPath = `${container.client.root}/${pathHash}/${updatedDms.file}`; + + fs.rename(originPath, destinationPath); + + updatedDmsList.push(updatedDms); + } + + if (tx) await tx.commit(); + return updatedDmsList; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; + + async function updateDms(id, dmsTypeId, companyId, warehouseId, + reference, description, hasFile, fileName, myOptions) { + const storageConnector = Self.app.dataSources.storage.connector; + const dms = await Self.findById(id, null, myOptions); + const updatedDms = await dms.updateAttributes({ + dmsTypeFk: dmsTypeId, + companyFk: companyId, + warehouseFk: warehouseId, + reference: reference, + description: description, + hasFile: hasFile + }, myOptions); + + const oldExtension = storageConnector.getFileExtension(dms.file); + const newExtension = storageConnector.getFileExtension(fileName); + + try { + if (oldExtension != newExtension) { + const pathHash = storageConnector.getPathHash(updatedDms.id); + + await Self.app.models.Container.removeFile(pathHash, dms.file); + } + } catch (err) {} + + fileName = `${updatedDms.id}.${newExtension}`; + + return updatedDms.updateAttribute('file', fileName, myOptions); + } + + + /** + * Returns a container instance + * If doesn't exists creates a new one + * + * @param {String} name Container name + * @return {Object} Container instance + */ + async function getContainer(name) { + const models = Self.app.models; + let container; + try { + container = await models.Container.getContainer(name); + } catch (err) { + if (err.code === 'ENOENT') { + container = await models.Container.createContainer({ + name: name + }); + } else throw err; + } + + return container; + } +}; diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index 9ef60c005..5d4634aae 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -9,27 +9,25 @@ module.exports = Self => { { arg: 'warehouseId', type: 'Number', - description: '' + description: 'The warehouse id' }, { arg: 'companyId', type: 'Number', - description: '' + description: 'The company id' }, { arg: 'dmsTypeId', type: 'Number', - description: '' + description: 'The dms type id' }, { arg: 'reference', - type: 'String', - description: '' + type: 'String' }, { arg: 'description', - type: 'String', - description: '' + type: 'String' }, { arg: 'hasFile', type: 'Boolean', - description: '' + description: 'True if has an attached file' }], returns: { type: 'Object', diff --git a/back/models/dms.js b/back/models/dms.js index d3471178b..9a06928db 100644 --- a/back/models/dms.js +++ b/back/models/dms.js @@ -2,4 +2,5 @@ module.exports = Self => { require('../methods/dms/downloadFile')(Self); require('../methods/dms/uploadFile')(Self); require('../methods/dms/removeFile')(Self); + require('../methods/dms/updateFile')(Self); }; diff --git a/front/core/components/table/style.scss b/front/core/components/table/style.scss index 87af10834..7d985c437 100644 --- a/front/core/components/table/style.scss +++ b/front/core/components/table/style.scss @@ -141,6 +141,12 @@ vn-table { background-color: $color-alert-medium; } + & > vn-td vn-icon-menu { + display: inline-block; + color: $color-main; + padding: .25em + } + & > [actions] { width: 1px; diff --git a/loopback/server/boot/storage.js b/loopback/server/boot/storage.js index d34804059..12662ab73 100644 --- a/loopback/server/boot/storage.js +++ b/loopback/server/boot/storage.js @@ -9,7 +9,7 @@ module.exports = app => { }; storageConnector.getFileExtension = function(fileName) { - return fileName.split('.').pop(); + return fileName.split('.').pop().toLowerCase(); }; storageConnector.getPathHash = function(id) { diff --git a/modules/client/front/dms/edit/index.html b/modules/client/front/dms/edit/index.html new file mode 100644 index 000000000..65c280c5d --- /dev/null +++ b/modules/client/front/dms/edit/index.html @@ -0,0 +1,63 @@ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/modules/client/front/dms/edit/index.js b/modules/client/front/dms/edit/index.js new file mode 100644 index 000000000..ba0108e6b --- /dev/null +++ b/modules/client/front/dms/edit/index.js @@ -0,0 +1,86 @@ +import ngModule from '../../module'; +import './style.scss'; + +class Controller { + constructor($scope, $http, $state, $translate, vnApp) { + this.$ = $scope; + this.$http = $http; + this.$state = $state; + this.$stateParams = $state.params; + this.$translate = $translate; + this.vnApp = vnApp; + } + + get client() { + return this._client; + } + + set client(value) { + this._client = value; + + if (value) + this.setDefaultParams(); + } + + setDefaultParams() { + const path = `/api/Dms/${this.$stateParams.dmsId}`; + this.$http.get(path).then(res => { + const dms = res.data && res.data; + this.dms = { + reference: dms.reference, + warehouseId: dms.warehouseFk, + companyId: dms.companyFk, + dmsTypeId: dms.dmsTypeFk, + description: dms.description, + hasFile: dms.hasFile, + files: [] + }; + }); + } + + onSubmit() { + const query = `/api/dms/${this.$stateParams.dmsId}/updateFile`; + const options = { + method: 'POST', + url: query, + params: this.dms, + headers: { + 'Content-Type': undefined + }, + transformRequest: files => { + const formData = new FormData(); + + for (let i = 0; i < files.length; i++) + formData.append(files[i].name, files[i]); + + return formData; + }, + data: this.dms.files + }; + this.$http(options).then(res => { + if (res) { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.watcher.updateOriginalData(); + this.$state.go('client.card.dms.index'); + } + }); + } + + onFileChange(files) { + if (files.length > 0) { + this.$.$applyAsync(() => { + this.dms.hasFile = true; + }); + } + } +} + +Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp']; + +ngModule.component('vnClientDmsEdit', { + template: require('./index.html'), + controller: Controller, + bindings: { + client: '<' + } +}); diff --git a/modules/client/front/dms/edit/index.spec.js b/modules/client/front/dms/edit/index.spec.js new file mode 100644 index 000000000..2825d4d25 --- /dev/null +++ b/modules/client/front/dms/edit/index.spec.js @@ -0,0 +1,60 @@ +import './index'; + +describe('Client', () => { + describe('Component vnClientDmsCreate', () => { + let controller; + let $scope; + let $httpBackend; + let $httpParamSerializer; + + beforeEach(ngModule('client')); + + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + $scope = $rootScope.$new(); + $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; + controller = $componentController('vnClientDmsCreate', {$scope}); + controller._client = {id: 101, name: 'Bruce wayne'}; + })); + + describe('client() setter', () => { + it('should set the client data and then call setDefaultParams()', () => { + spyOn(controller, 'setDefaultParams'); + controller.client = { + id: 15, + name: 'Bruce wayne' + }; + + expect(controller.client).toBeDefined(); + expect(controller.setDefaultParams).toHaveBeenCalledWith(); + }); + }); + + describe('setDefaultParams()', () => { + it('should perform a GET query and define the dms property on controller', () => { + const params = {filter: { + where: {code: 'paymentsLaw'} + }}; + let serializedParams = $httpParamSerializer(params); + $httpBackend.when('GET', `/api/DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'paymentsLaw'}); + $httpBackend.expect('GET', `/api/DmsTypes/findOne?${serializedParams}`); + controller.setDefaultParams(); + $httpBackend.flush(); + + expect(controller.dms).toBeDefined(); + expect(controller.dms.reference).toEqual(101); + expect(controller.dms.dmsTypeId).toEqual(12); + }); + }); + + describe('onFileChange()', () => { + it('should set dms hasFile property to true if has any files', () => { + const files = [{id: 1, name: 'MyFile'}]; + controller.onFileChange(files); + $scope.$apply(); + + expect(controller.dms.hasFile).toBeTruthy(); + }); + }); + }); +}); diff --git a/modules/client/front/dms/edit/locale/es.yml b/modules/client/front/dms/edit/locale/es.yml new file mode 100644 index 000000000..7625d5195 --- /dev/null +++ b/modules/client/front/dms/edit/locale/es.yml @@ -0,0 +1,3 @@ +Edit file: Editar fichero +File: Fichero +Attached file: Fichero adjunto \ No newline at end of file diff --git a/modules/client/front/dms/edit/style.scss b/modules/client/front/dms/edit/style.scss new file mode 100644 index 000000000..b47544b12 --- /dev/null +++ b/modules/client/front/dms/edit/style.scss @@ -0,0 +1,7 @@ +vn-ticket-request { + vn-textfield { + margin: 0!important; + max-width: 100px; + } +} + diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index 2cf6cdd4f..b55bc137f 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -16,11 +16,11 @@ Type Reference Description - Attached file + Original File - Employee + Employee Created - + @@ -41,13 +41,13 @@ {{::document.dms.description}} - + {{::document.dms.file}} - + {{::document.dms.worker.user.nickname | dashIfEmpty}} @@ -55,16 +55,21 @@ {{::document.dms.created | dateTime:'dd/MM/yyyy HH:mm'}} - + + ng-show="document.dms.hasFile"> + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/modules/ticket/front/dms/edit/index.js b/modules/ticket/front/dms/edit/index.js new file mode 100644 index 000000000..c35c4140d --- /dev/null +++ b/modules/ticket/front/dms/edit/index.js @@ -0,0 +1,86 @@ +import ngModule from '../../module'; +import './style.scss'; + +class Controller { + constructor($scope, $http, $state, $translate, vnApp) { + this.$ = $scope; + this.$http = $http; + this.$state = $state; + this.$stateParams = $state.params; + this.$translate = $translate; + this.vnApp = vnApp; + } + + get ticket() { + return this._ticket; + } + + set ticket(value) { + this._ticket = value; + + if (value) + this.setDefaultParams(); + } + + setDefaultParams() { + const path = `/api/Dms/${this.$stateParams.dmsId}`; + this.$http.get(path).then(res => { + const dms = res.data && res.data; + this.dms = { + reference: dms.reference, + warehouseId: dms.warehouseFk, + companyId: dms.companyFk, + dmsTypeId: dms.dmsTypeFk, + description: dms.description, + hasFile: dms.hasFile, + files: [] + }; + }); + } + + onSubmit() { + const query = `/api/dms/${this.$stateParams.dmsId}/updateFile`; + const options = { + method: 'POST', + url: query, + params: this.dms, + headers: { + 'Content-Type': undefined + }, + transformRequest: files => { + const formData = new FormData(); + + for (let i = 0; i < files.length; i++) + formData.append(files[i].name, files[i]); + + return formData; + }, + data: this.dms.files + }; + this.$http(options).then(res => { + if (res) { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.watcher.updateOriginalData(); + this.$state.go('ticket.card.dms.index'); + } + }); + } + + onFileChange(files) { + if (files.length > 0) { + this.$.$applyAsync(() => { + this.dms.hasFile = true; + }); + } + } +} + +Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp']; + +ngModule.component('vnTicketDmsEdit', { + template: require('./index.html'), + controller: Controller, + bindings: { + ticket: '<' + } +}); diff --git a/modules/ticket/front/dms/edit/index.spec.js b/modules/ticket/front/dms/edit/index.spec.js new file mode 100644 index 000000000..2825d4d25 --- /dev/null +++ b/modules/ticket/front/dms/edit/index.spec.js @@ -0,0 +1,60 @@ +import './index'; + +describe('Client', () => { + describe('Component vnClientDmsCreate', () => { + let controller; + let $scope; + let $httpBackend; + let $httpParamSerializer; + + beforeEach(ngModule('client')); + + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + $scope = $rootScope.$new(); + $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; + controller = $componentController('vnClientDmsCreate', {$scope}); + controller._client = {id: 101, name: 'Bruce wayne'}; + })); + + describe('client() setter', () => { + it('should set the client data and then call setDefaultParams()', () => { + spyOn(controller, 'setDefaultParams'); + controller.client = { + id: 15, + name: 'Bruce wayne' + }; + + expect(controller.client).toBeDefined(); + expect(controller.setDefaultParams).toHaveBeenCalledWith(); + }); + }); + + describe('setDefaultParams()', () => { + it('should perform a GET query and define the dms property on controller', () => { + const params = {filter: { + where: {code: 'paymentsLaw'} + }}; + let serializedParams = $httpParamSerializer(params); + $httpBackend.when('GET', `/api/DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'paymentsLaw'}); + $httpBackend.expect('GET', `/api/DmsTypes/findOne?${serializedParams}`); + controller.setDefaultParams(); + $httpBackend.flush(); + + expect(controller.dms).toBeDefined(); + expect(controller.dms.reference).toEqual(101); + expect(controller.dms.dmsTypeId).toEqual(12); + }); + }); + + describe('onFileChange()', () => { + it('should set dms hasFile property to true if has any files', () => { + const files = [{id: 1, name: 'MyFile'}]; + controller.onFileChange(files); + $scope.$apply(); + + expect(controller.dms.hasFile).toBeTruthy(); + }); + }); + }); +}); diff --git a/modules/ticket/front/dms/edit/locale/es.yml b/modules/ticket/front/dms/edit/locale/es.yml new file mode 100644 index 000000000..7625d5195 --- /dev/null +++ b/modules/ticket/front/dms/edit/locale/es.yml @@ -0,0 +1,3 @@ +Edit file: Editar fichero +File: Fichero +Attached file: Fichero adjunto \ No newline at end of file diff --git a/modules/ticket/front/dms/edit/style.scss b/modules/ticket/front/dms/edit/style.scss new file mode 100644 index 000000000..b47544b12 --- /dev/null +++ b/modules/ticket/front/dms/edit/style.scss @@ -0,0 +1,7 @@ +vn-ticket-request { + vn-textfield { + margin: 0!important; + max-width: 100px; + } +} + diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index eb51710b6..920035060 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -59,12 +59,17 @@ + ng-show="document.dms.hasFile"> + + Date: Mon, 15 Jul 2019 11:56:17 +0200 Subject: [PATCH 02/22] removed download file conditional --- modules/client/front/dms/index/index.html | 3 +-- modules/ticket/front/dms/index/index.html | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index b55bc137f..155e11c92 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -58,8 +58,7 @@ + href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.accessToken}}"> diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 920035060..e85c1e30a 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -58,8 +58,7 @@ + href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.accessToken}}"> From c658cd3c1f8d1468b3cb30e34c5ad068a852eeb6 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 15 Jul 2019 13:16:02 +0200 Subject: [PATCH 03/22] save file content-type #1597 --- back/methods/dms/downloadFile.js | 4 ++-- back/methods/dms/updateFile.js | 6 ++++-- back/methods/dms/uploadFile.js | 6 ++++-- back/models/dms.json | 3 +++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/back/methods/dms/downloadFile.js b/back/methods/dms/downloadFile.js index 72090f33b..01ba01b84 100644 --- a/back/methods/dms/downloadFile.js +++ b/back/methods/dms/downloadFile.js @@ -46,7 +46,7 @@ module.exports = Self => { if (env && env != 'development') { const pathHash = storageConnector.getPathHash(dms.id); file = { - contentType: 'application/octet-stream', + contentType: dms.contentType, container: pathHash, name: dms.file }; @@ -60,6 +60,6 @@ module.exports = Self => { const stream = await models.Container.downloadStream(file.container, file.name); - return [stream, file.contentType, `filename="${file.name}"`]; + return [stream, file.contentType, `inline; filename="${file.name}"`]; }; }; diff --git a/back/methods/dms/updateFile.js b/back/methods/dms/updateFile.js index e502c7b94..eaafd7f7d 100644 --- a/back/methods/dms/updateFile.js +++ b/back/methods/dms/updateFile.js @@ -82,7 +82,7 @@ module.exports = Self => { const updatedDmsList = []; for (const file of files) { const updatedDms = await updateDms(id, dmsTypeId, companyId, warehouseId, - reference, description, hasFile, file.name, myOptions); + reference, description, hasFile, file, myOptions); const pathHash = storageConnector.getPathHash(updatedDms.id); const container = await getContainer(pathHash); @@ -104,7 +104,7 @@ module.exports = Self => { }; async function updateDms(id, dmsTypeId, companyId, warehouseId, - reference, description, hasFile, fileName, myOptions) { + reference, description, hasFile, file, myOptions) { const storageConnector = Self.app.dataSources.storage.connector; const dms = await Self.findById(id, null, myOptions); const updatedDms = await dms.updateAttributes({ @@ -113,9 +113,11 @@ module.exports = Self => { warehouseFk: warehouseId, reference: reference, description: description, + contentType: file.type, hasFile: hasFile }, myOptions); + let fileName = file.name; const oldExtension = storageConnector.getFileExtension(dms.file); const newExtension = storageConnector.getFileExtension(fileName); diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index 5d4634aae..b50aaf824 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -70,7 +70,7 @@ module.exports = Self => { const addedDms = []; for (const file of files) { - const newDms = await createDms(ctx, file.name, myOptions); + const newDms = await createDms(ctx, file, myOptions); const pathHash = storageConnector.getPathHash(newDms.id); const container = await getContainer(pathHash); @@ -90,7 +90,7 @@ module.exports = Self => { } }; - async function createDms(ctx, fileName, myOptions) { + async function createDms(ctx, file, myOptions) { const models = Self.app.models; const storageConnector = Self.app.dataSources.storage.connector; const myUserId = ctx.req.accessToken.userId; @@ -104,9 +104,11 @@ module.exports = Self => { warehouseFk: args.warehouseId, reference: args.reference, description: args.description, + contentType: file.type, hasFile: args.hasFile }, myOptions); + let fileName = file.name; const extension = storageConnector.getFileExtension(fileName); fileName = `${newDms.id}.${extension}`; diff --git a/back/models/dms.json b/back/models/dms.json index dc421a7a1..bf6e44311 100644 --- a/back/models/dms.json +++ b/back/models/dms.json @@ -17,6 +17,9 @@ "file": { "type": "string" }, + "contentType": { + "type": "string" + }, "reference": { "type": "string" }, From af9eb0c4eac77178843f8c074c8c381419a92f1c Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 15 Jul 2019 13:20:50 +0200 Subject: [PATCH 04/22] fixed icons column size --- modules/client/front/dms/index/index.html | 4 ++-- modules/ticket/front/dms/index/index.html | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index 155e11c92..cc237c157 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -16,7 +16,7 @@ Type Reference Description - Original + Original File Employee Created @@ -41,7 +41,7 @@ {{::document.dms.description}}
- + diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index e85c1e30a..9e4beb58d 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -16,11 +16,11 @@ Type Reference Description - Attached file + Original File - Employee + Employee Created - + @@ -41,13 +41,13 @@ {{::document.dms.description}} - + {{::document.dms.file}} - + {{::document.dms.worker.user.nickname | dashIfEmpty}} @@ -55,7 +55,7 @@ {{::document.dms.created | dateTime:'dd/MM/yyyy HH:mm'}} - + From 527492a8596c85423cef25ac3c8f10ae02155dff Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 15 Jul 2019 14:52:41 +0200 Subject: [PATCH 05/22] download zip files only --- back/methods/dms/downloadFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/dms/downloadFile.js b/back/methods/dms/downloadFile.js index 01ba01b84..bb03dda89 100644 --- a/back/methods/dms/downloadFile.js +++ b/back/methods/dms/downloadFile.js @@ -60,6 +60,6 @@ module.exports = Self => { const stream = await models.Container.downloadStream(file.container, file.name); - return [stream, file.contentType, `inline; filename="${file.name}"`]; + return [stream, file.contentType, `filename="${file.name}"`]; }; }; From 1915960824df5b00ca96d05e23342f26cf1893fc Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 15 Jul 2019 15:05:54 +0200 Subject: [PATCH 06/22] fix --- back/methods/dms/downloadFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/dms/downloadFile.js b/back/methods/dms/downloadFile.js index bb03dda89..47db5c5a2 100644 --- a/back/methods/dms/downloadFile.js +++ b/back/methods/dms/downloadFile.js @@ -8,7 +8,7 @@ module.exports = Self => { { arg: 'id', type: 'Number', - description: 'The document id', + description: 'Document id', http: {source: 'path'} } ], From 9fe32865d6e597e62d578677f76d28eed37ca176 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Jul 2019 07:22:29 +0200 Subject: [PATCH 07/22] 7z mimetype --- modules/client/front/dms/create/index.html | 2 +- modules/client/front/dms/edit/index.html | 2 +- modules/ticket/front/dms/create/index.html | 2 +- modules/ticket/front/dms/edit/index.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/client/front/dms/create/index.html b/modules/client/front/dms/create/index.html index 3fa96a9da..879210907 100644 --- a/modules/client/front/dms/create/index.html +++ b/modules/client/front/dms/create/index.html @@ -46,7 +46,7 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar"> + accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> diff --git a/modules/client/front/dms/edit/index.html b/modules/client/front/dms/edit/index.html index 65c280c5d..6f6392d66 100644 --- a/modules/client/front/dms/edit/index.html +++ b/modules/client/front/dms/edit/index.html @@ -45,7 +45,7 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar"> + accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> diff --git a/modules/ticket/front/dms/create/index.html b/modules/ticket/front/dms/create/index.html index 527c6030d..d6ebb0130 100644 --- a/modules/ticket/front/dms/create/index.html +++ b/modules/ticket/front/dms/create/index.html @@ -45,7 +45,7 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar"> + accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> diff --git a/modules/ticket/front/dms/edit/index.html b/modules/ticket/front/dms/edit/index.html index 275d330bb..c740d5103 100644 --- a/modules/ticket/front/dms/edit/index.html +++ b/modules/ticket/front/dms/edit/index.html @@ -45,7 +45,7 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar"> + accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> From 17087c8d14548e9b6e469ce36e5f97d7b8c90440 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Jul 2019 08:26:57 +0200 Subject: [PATCH 08/22] address.edit fixed location autocompletion --- modules/client/front/address/edit/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/front/address/edit/index.html b/modules/client/front/address/edit/index.html index b7361b71b..cb769617b 100644 --- a/modules/client/front/address/edit/index.html +++ b/modules/client/front/address/edit/index.html @@ -42,7 +42,7 @@ Date: Tue, 16 Jul 2019 13:37:25 +0200 Subject: [PATCH 09/22] dms fixes --- back/methods/dms/downloadFile.js | 29 +++-- back/methods/dms/updateFile.js | 105 +++++++++--------- loopback/locale/es.json | 3 +- modules/client/front/dms/create/index.html | 2 +- modules/client/front/dms/create/index.js | 15 ++- modules/client/front/dms/create/locale/es.yml | 2 +- modules/client/front/dms/edit/index.html | 2 +- modules/client/front/dms/edit/index.js | 13 ++- modules/client/front/dms/edit/locale/es.yml | 2 +- modules/client/front/dms/index/index.html | 9 +- modules/ticket/front/dms/create/index.html | 2 +- modules/ticket/front/dms/create/index.js | 15 ++- modules/ticket/front/dms/create/locale/es.yml | 2 +- modules/ticket/front/dms/edit/index.html | 2 +- modules/ticket/front/dms/edit/index.js | 13 ++- modules/ticket/front/dms/edit/locale/es.yml | 2 +- modules/ticket/front/dms/index/index.html | 10 +- 17 files changed, 122 insertions(+), 106 deletions(-) diff --git a/back/methods/dms/downloadFile.js b/back/methods/dms/downloadFile.js index 47db5c5a2..3174a19fd 100644 --- a/back/methods/dms/downloadFile.js +++ b/back/methods/dms/downloadFile.js @@ -34,7 +34,6 @@ module.exports = Self => { }); Self.downloadFile = async function(ctx, id) { - const env = process.env.NODE_ENV; const storageConnector = Self.app.dataSources.storage.connector; const models = Self.app.models; const dms = await Self.findById(id); @@ -43,23 +42,21 @@ module.exports = Self => { if (!hasReadRole) throw new UserError(`You don't have enough privileges`); - if (env && env != 'development') { - const pathHash = storageConnector.getPathHash(dms.id); - file = { - contentType: dms.contentType, - container: pathHash, - name: dms.file - }; - } else { - file = { - contentType: 'text/plain', - container: 'temp', - name: `file.txt` - }; + const pathHash = storageConnector.getPathHash(dms.id); + try { + await models.Container.getFile(pathHash, dms.file); + } catch (e) { + if (e.code != 'ENOENT') + throw e; + + const error = new UserError(`File doesn't exists`); + error.statusCode = 404; + + throw error; } - const stream = await models.Container.downloadStream(file.container, file.name); + const stream = models.Container.downloadStream(pathHash, dms.file); - return [stream, file.contentType, `filename="${file.name}"`]; + return [stream, dms.contentType, `filename="${dms.file}"`]; }; }; diff --git a/back/methods/dms/updateFile.js b/back/methods/dms/updateFile.js index eaafd7f7d..ff3c0806f 100644 --- a/back/methods/dms/updateFile.js +++ b/back/methods/dms/updateFile.js @@ -32,6 +32,10 @@ module.exports = Self => { }, { arg: 'hasFile', type: 'Boolean', + description: 'True if has original file' + }, { + arg: 'hasAttachedFile', + type: 'Boolean', description: 'True if has an attached file' }], returns: { @@ -45,10 +49,8 @@ module.exports = Self => { }); Self.updateFile = async(ctx, id, warehouseId, companyId, - dmsTypeId, reference, description, hasFile, options) => { - const storageConnector = Self.app.dataSources.storage.connector; + dmsTypeId, reference, description, hasFile, hasAttachedFile, options) => { const models = Self.app.models; - const fileOptions = {}; let tx; let myOptions = {}; @@ -66,75 +68,68 @@ module.exports = Self => { if (!hasWriteRole) throw new UserError(`You don't have enough privileges`); - // Upload file to temporary path - const tempContainer = await getContainer('temp'); - let files = []; - try { - const uploaded = await models.Container.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); - files = Object.values(uploaded.files).map(file => { - return file[0]; - }); - } catch (err) { - if (err.message != 'No file content uploaded') - throw e; - } + const dms = await Self.findById(id, null, myOptions); + await dms.updateAttributes({ + dmsTypeFk: dmsTypeId, + companyFk: companyId, + warehouseFk: warehouseId, + reference: reference, + description: description, + hasFile: hasFile + }, myOptions); - const updatedDmsList = []; - for (const file of files) { - const updatedDms = await updateDms(id, dmsTypeId, companyId, warehouseId, - reference, description, hasFile, file, myOptions); - - const pathHash = storageConnector.getPathHash(updatedDms.id); - const container = await getContainer(pathHash); - - const originPath = `${tempContainer.client.root}/${tempContainer.name}/${file.name}`; - const destinationPath = `${container.client.root}/${pathHash}/${updatedDms.file}`; - - fs.rename(originPath, destinationPath); - - updatedDmsList.push(updatedDms); - } + if (hasAttachedFile) + updatedDms = await uploadNewFile(ctx, dms, myOptions); if (tx) await tx.commit(); - return updatedDmsList; + return updatedDms; } catch (e) { if (tx) await tx.rollback(); throw e; } }; - async function updateDms(id, dmsTypeId, companyId, warehouseId, - reference, description, hasFile, file, myOptions) { + async function uploadNewFile(ctx, dms, myOptions) { const storageConnector = Self.app.dataSources.storage.connector; - const dms = await Self.findById(id, null, myOptions); - const updatedDms = await dms.updateAttributes({ - dmsTypeFk: dmsTypeId, - companyFk: companyId, - warehouseFk: warehouseId, - reference: reference, - description: description, - contentType: file.type, - hasFile: hasFile - }, myOptions); + const models = Self.app.models; + const fileOptions = {}; - let fileName = file.name; - const oldExtension = storageConnector.getFileExtension(dms.file); - const newExtension = storageConnector.getFileExtension(fileName); + const tempContainer = await getContainer('temp'); + const makeUpload = await models.Container.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); + const keys = Object.values(makeUpload.files); + const files = keys.map(file => file[0]); + const file = files[0]; - try { - if (oldExtension != newExtension) { - const pathHash = storageConnector.getPathHash(updatedDms.id); + if (file) { + const oldExtension = storageConnector.getFileExtension(dms.file); + const newExtension = storageConnector.getFileExtension(file.name); + const fileName = `${dms.id}.${newExtension}`; - await Self.app.models.Container.removeFile(pathHash, dms.file); - } - } catch (err) {} + try { + if (oldExtension != newExtension) { + const pathHash = storageConnector.getPathHash(dms.id); - fileName = `${updatedDms.id}.${newExtension}`; + await models.Container.removeFile(pathHash, dms.file); + } + } catch (err) {} - return updatedDms.updateAttribute('file', fileName, myOptions); + const updatedDms = await dms.updateAttributes({ + contentType: file.type, + file: fileName + }, myOptions); + + const pathHash = storageConnector.getPathHash(updatedDms.id); + const container = await getContainer(pathHash); + + const originPath = `${tempContainer.client.root}/${tempContainer.name}/${file.name}`; + const destinationPath = `${container.client.root}/${pathHash}/${updatedDms.file}`; + + fs.rename(originPath, destinationPath); + + return updatedDms; + } } - /** * Returns a container instance * If doesn't exists creates a new one diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 256b51205..94c425279 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -94,5 +94,6 @@ "Invalid parameters to create a new ticket": "Parámetros inválidos para crear un nuevo ticket", "This item is not available": "Este artículo no está disponible", "This postcode already exists": "Este código postal ya existe", - "Concept cannot be blank": "Concept cannot be blank" + "Concept cannot be blank": "El concepto no puede quedar en blanco", + "File doesn't exists": "El archivo no existe" } \ No newline at end of file diff --git a/modules/client/front/dms/create/index.html b/modules/client/front/dms/create/index.html index 879210907..6010fb4a9 100644 --- a/modules/client/front/dms/create/index.html +++ b/modules/client/front/dms/create/index.html @@ -51,7 +51,7 @@ diff --git a/modules/client/front/dms/create/index.js b/modules/client/front/dms/create/index.js index a3b32228f..f3738fc2b 100644 --- a/modules/client/front/dms/create/index.js +++ b/modules/client/front/dms/create/index.js @@ -10,7 +10,8 @@ class Controller { this.vnApp = vnApp; this.dms = { files: [], - hasFile: false + hasFile: false, + hasAttachedFile: false }; } @@ -78,11 +79,13 @@ class Controller { } onFileChange(files) { - if (files.length > 0) { - this.$.$applyAsync(() => { - this.dms.hasFile = true; - }); - } + let hasAttachedFile = false; + if (files.length > 0) + hasAttachedFile = true; + + this.$.$applyAsync(() => { + this.dms.hasAttachedFile = hasAttachedFile; + }); } } diff --git a/modules/client/front/dms/create/locale/es.yml b/modules/client/front/dms/create/locale/es.yml index 2de9e68d3..2ea3b31d8 100644 --- a/modules/client/front/dms/create/locale/es.yml +++ b/modules/client/front/dms/create/locale/es.yml @@ -2,4 +2,4 @@ Upload file: Subir fichero Upload: Subir File: Fichero ClientFileDescription: "{{dmsTypeName}} del cliente {{clientName}} id {{clientId}}" -Attached file: Fichero adjunto \ No newline at end of file +Generate identifier for original file: Generar identificador para archivo original \ No newline at end of file diff --git a/modules/client/front/dms/edit/index.html b/modules/client/front/dms/edit/index.html index 6f6392d66..e3dccf1c0 100644 --- a/modules/client/front/dms/edit/index.html +++ b/modules/client/front/dms/edit/index.html @@ -50,7 +50,7 @@ diff --git a/modules/client/front/dms/edit/index.js b/modules/client/front/dms/edit/index.js index ba0108e6b..00e3e4d28 100644 --- a/modules/client/front/dms/edit/index.js +++ b/modules/client/front/dms/edit/index.js @@ -33,6 +33,7 @@ class Controller { dmsTypeId: dms.dmsTypeFk, description: dms.description, hasFile: dms.hasFile, + hasAttachedFile: false, files: [] }; }); @@ -67,11 +68,13 @@ class Controller { } onFileChange(files) { - if (files.length > 0) { - this.$.$applyAsync(() => { - this.dms.hasFile = true; - }); - } + let hasAttachedFile = false; + if (files.length > 0) + hasAttachedFile = true; + + this.$.$applyAsync(() => { + this.dms.hasAttachedFile = hasAttachedFile; + }); } } diff --git a/modules/client/front/dms/edit/locale/es.yml b/modules/client/front/dms/edit/locale/es.yml index 7625d5195..9d97564ba 100644 --- a/modules/client/front/dms/edit/locale/es.yml +++ b/modules/client/front/dms/edit/locale/es.yml @@ -1,3 +1,3 @@ Edit file: Editar fichero File: Fichero -Attached file: Fichero adjunto \ No newline at end of file +Generate identifier for original file: Generar identificador para archivo original \ No newline at end of file diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index cc237c157..26a36d086 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -17,7 +17,7 @@ Reference Description Original - File + File Employee Created @@ -46,7 +46,12 @@ field="document.dms.hasFile">
- {{::document.dms.file}} + + {{::document.dms.file}} + +
diff --git a/modules/ticket/front/dms/create/index.html b/modules/ticket/front/dms/create/index.html index d6ebb0130..7c8ae6ad2 100644 --- a/modules/ticket/front/dms/create/index.html +++ b/modules/ticket/front/dms/create/index.html @@ -50,7 +50,7 @@ diff --git a/modules/ticket/front/dms/create/index.js b/modules/ticket/front/dms/create/index.js index 1b28b2417..8f6f7e322 100644 --- a/modules/ticket/front/dms/create/index.js +++ b/modules/ticket/front/dms/create/index.js @@ -10,7 +10,8 @@ class Controller { this.vnApp = vnApp; this.dms = { files: [], - hasFile: false + hasFile: false, + hasAttachedFile: false }; } @@ -76,11 +77,13 @@ class Controller { } onFileChange(files) { - if (files.length > 0) { - this.$.$applyAsync(() => { - this.dms.hasFile = true; - }); - } + let hasAttachedFile = false; + if (files.length > 0) + hasAttachedFile = true; + + this.$.$applyAsync(() => { + this.dms.hasAttachedFile = hasAttachedFile; + }); } } diff --git a/modules/ticket/front/dms/create/locale/es.yml b/modules/ticket/front/dms/create/locale/es.yml index e074da48b..999826352 100644 --- a/modules/ticket/front/dms/create/locale/es.yml +++ b/modules/ticket/front/dms/create/locale/es.yml @@ -2,4 +2,4 @@ Upload file: Subir fichero Upload: Subir File: Fichero FileDescription: Ticket id {{ticketId}} del cliente {{clientName}} id {{clientId}} -Attached file: Fichero adjunto \ No newline at end of file +Generate identifier for original file: Generar identificador para archivo original \ No newline at end of file diff --git a/modules/ticket/front/dms/edit/index.html b/modules/ticket/front/dms/edit/index.html index c740d5103..ac12e4984 100644 --- a/modules/ticket/front/dms/edit/index.html +++ b/modules/ticket/front/dms/edit/index.html @@ -50,7 +50,7 @@ diff --git a/modules/ticket/front/dms/edit/index.js b/modules/ticket/front/dms/edit/index.js index c35c4140d..df25cea94 100644 --- a/modules/ticket/front/dms/edit/index.js +++ b/modules/ticket/front/dms/edit/index.js @@ -33,6 +33,7 @@ class Controller { dmsTypeId: dms.dmsTypeFk, description: dms.description, hasFile: dms.hasFile, + hasAttachedFile: false, files: [] }; }); @@ -67,11 +68,13 @@ class Controller { } onFileChange(files) { - if (files.length > 0) { - this.$.$applyAsync(() => { - this.dms.hasFile = true; - }); - } + let hasAttachedFile = false; + if (files.length > 0) + hasAttachedFile = true; + + this.$.$applyAsync(() => { + this.dms.hasAttachedFile = hasAttachedFile; + }); } } diff --git a/modules/ticket/front/dms/edit/locale/es.yml b/modules/ticket/front/dms/edit/locale/es.yml index 7625d5195..9d97564ba 100644 --- a/modules/ticket/front/dms/edit/locale/es.yml +++ b/modules/ticket/front/dms/edit/locale/es.yml @@ -1,3 +1,3 @@ Edit file: Editar fichero File: Fichero -Attached file: Fichero adjunto \ No newline at end of file +Generate identifier for original file: Generar identificador para archivo original \ No newline at end of file diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 9e4beb58d..222a14b04 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -17,7 +17,7 @@ Reference Description Original - File + File Employee Created @@ -46,7 +46,13 @@ field="document.dms.hasFile"> - {{::document.dms.file}} + + + {{::document.dms.file}} + + From 5e40b384ffccf546021c550aa716169173155524 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Jul 2019 13:55:24 +0200 Subject: [PATCH 10/22] fixed updateFile transaction --- back/methods/dms/updateFile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/back/methods/dms/updateFile.js b/back/methods/dms/updateFile.js index ff3c0806f..32aae891b 100644 --- a/back/methods/dms/updateFile.js +++ b/back/methods/dms/updateFile.js @@ -79,10 +79,10 @@ module.exports = Self => { }, myOptions); if (hasAttachedFile) - updatedDms = await uploadNewFile(ctx, dms, myOptions); + await uploadNewFile(ctx, dms, myOptions); if (tx) await tx.commit(); - return updatedDms; + return dms; } catch (e) { if (tx) await tx.rollback(); throw e; From 87e0a914ade3844736ffe385740587d466e7918c Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Jul 2019 14:12:58 +0200 Subject: [PATCH 11/22] fixed dms unit tests --- back/methods/dms/updateFile.js | 6 +++--- modules/client/front/dms/create/index.js | 8 ++++---- modules/client/front/dms/create/index.spec.js | 4 ++-- modules/client/front/dms/edit/index.js | 8 ++++---- modules/client/front/dms/edit/index.spec.js | 4 ++-- modules/ticket/front/dms/create/index.js | 8 ++++---- modules/ticket/front/dms/create/index.spec.js | 4 ++-- modules/ticket/front/dms/edit/index.js | 8 ++++---- modules/ticket/front/dms/edit/index.spec.js | 4 ++-- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/back/methods/dms/updateFile.js b/back/methods/dms/updateFile.js index 32aae891b..8e21a6203 100644 --- a/back/methods/dms/updateFile.js +++ b/back/methods/dms/updateFile.js @@ -34,7 +34,7 @@ module.exports = Self => { type: 'Boolean', description: 'True if has original file' }, { - arg: 'hasAttachedFile', + arg: 'hasFileAttached', type: 'Boolean', description: 'True if has an attached file' }], @@ -49,7 +49,7 @@ module.exports = Self => { }); Self.updateFile = async(ctx, id, warehouseId, companyId, - dmsTypeId, reference, description, hasFile, hasAttachedFile, options) => { + dmsTypeId, reference, description, hasFile, hasFileAttached, options) => { const models = Self.app.models; let tx; @@ -78,7 +78,7 @@ module.exports = Self => { hasFile: hasFile }, myOptions); - if (hasAttachedFile) + if (hasFileAttached) await uploadNewFile(ctx, dms, myOptions); if (tx) await tx.commit(); diff --git a/modules/client/front/dms/create/index.js b/modules/client/front/dms/create/index.js index f3738fc2b..924e5fb26 100644 --- a/modules/client/front/dms/create/index.js +++ b/modules/client/front/dms/create/index.js @@ -11,7 +11,7 @@ class Controller { this.dms = { files: [], hasFile: false, - hasAttachedFile: false + hasFileAttached: false }; } @@ -79,12 +79,12 @@ class Controller { } onFileChange(files) { - let hasAttachedFile = false; + let hasFileAttached = false; if (files.length > 0) - hasAttachedFile = true; + hasFileAttached = true; this.$.$applyAsync(() => { - this.dms.hasAttachedFile = hasAttachedFile; + this.dms.hasFileAttached = hasFileAttached; }); } } diff --git a/modules/client/front/dms/create/index.spec.js b/modules/client/front/dms/create/index.spec.js index 2825d4d25..5ef4d28f3 100644 --- a/modules/client/front/dms/create/index.spec.js +++ b/modules/client/front/dms/create/index.spec.js @@ -48,12 +48,12 @@ describe('Client', () => { }); describe('onFileChange()', () => { - it('should set dms hasFile property to true if has any files', () => { + it('should set dms hasFileAttached property to true if has any files', () => { const files = [{id: 1, name: 'MyFile'}]; controller.onFileChange(files); $scope.$apply(); - expect(controller.dms.hasFile).toBeTruthy(); + expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); }); diff --git a/modules/client/front/dms/edit/index.js b/modules/client/front/dms/edit/index.js index 00e3e4d28..be8396467 100644 --- a/modules/client/front/dms/edit/index.js +++ b/modules/client/front/dms/edit/index.js @@ -33,7 +33,7 @@ class Controller { dmsTypeId: dms.dmsTypeFk, description: dms.description, hasFile: dms.hasFile, - hasAttachedFile: false, + hasFileAttached: false, files: [] }; }); @@ -68,12 +68,12 @@ class Controller { } onFileChange(files) { - let hasAttachedFile = false; + let hasFileAttached = false; if (files.length > 0) - hasAttachedFile = true; + hasFileAttached = true; this.$.$applyAsync(() => { - this.dms.hasAttachedFile = hasAttachedFile; + this.dms.hasFileAttached = hasFileAttached; }); } } diff --git a/modules/client/front/dms/edit/index.spec.js b/modules/client/front/dms/edit/index.spec.js index 2825d4d25..5ef4d28f3 100644 --- a/modules/client/front/dms/edit/index.spec.js +++ b/modules/client/front/dms/edit/index.spec.js @@ -48,12 +48,12 @@ describe('Client', () => { }); describe('onFileChange()', () => { - it('should set dms hasFile property to true if has any files', () => { + it('should set dms hasFileAttached property to true if has any files', () => { const files = [{id: 1, name: 'MyFile'}]; controller.onFileChange(files); $scope.$apply(); - expect(controller.dms.hasFile).toBeTruthy(); + expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); }); diff --git a/modules/ticket/front/dms/create/index.js b/modules/ticket/front/dms/create/index.js index 8f6f7e322..4e22a8ba5 100644 --- a/modules/ticket/front/dms/create/index.js +++ b/modules/ticket/front/dms/create/index.js @@ -11,7 +11,7 @@ class Controller { this.dms = { files: [], hasFile: false, - hasAttachedFile: false + hasFileAttached: false }; } @@ -77,12 +77,12 @@ class Controller { } onFileChange(files) { - let hasAttachedFile = false; + let hasFileAttached = false; if (files.length > 0) - hasAttachedFile = true; + hasFileAttached = true; this.$.$applyAsync(() => { - this.dms.hasAttachedFile = hasAttachedFile; + this.dms.hasFileAttached = hasFileAttached; }); } } diff --git a/modules/ticket/front/dms/create/index.spec.js b/modules/ticket/front/dms/create/index.spec.js index 1b8cdadfa..0014c010d 100644 --- a/modules/ticket/front/dms/create/index.spec.js +++ b/modules/ticket/front/dms/create/index.spec.js @@ -53,12 +53,12 @@ describe('Ticket', () => { }); describe('onFileChange()', () => { - it('should set dms hasFile property to true if has any files', () => { + it('should set dms hasFileAttached property to true if has any files', () => { const files = [{id: 1, name: 'MyFile'}]; controller.onFileChange(files); $scope.$apply(); - expect(controller.dms.hasFile).toBeTruthy(); + expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); }); diff --git a/modules/ticket/front/dms/edit/index.js b/modules/ticket/front/dms/edit/index.js index df25cea94..486d37791 100644 --- a/modules/ticket/front/dms/edit/index.js +++ b/modules/ticket/front/dms/edit/index.js @@ -33,7 +33,7 @@ class Controller { dmsTypeId: dms.dmsTypeFk, description: dms.description, hasFile: dms.hasFile, - hasAttachedFile: false, + hasFileAttached: false, files: [] }; }); @@ -68,12 +68,12 @@ class Controller { } onFileChange(files) { - let hasAttachedFile = false; + let hasFileAttached = false; if (files.length > 0) - hasAttachedFile = true; + hasFileAttached = true; this.$.$applyAsync(() => { - this.dms.hasAttachedFile = hasAttachedFile; + this.dms.hasFileAttached = hasFileAttached; }); } } diff --git a/modules/ticket/front/dms/edit/index.spec.js b/modules/ticket/front/dms/edit/index.spec.js index 2825d4d25..5ef4d28f3 100644 --- a/modules/ticket/front/dms/edit/index.spec.js +++ b/modules/ticket/front/dms/edit/index.spec.js @@ -48,12 +48,12 @@ describe('Client', () => { }); describe('onFileChange()', () => { - it('should set dms hasFile property to true if has any files', () => { + it('should set dms hasFileAttached property to true if has any files', () => { const files = [{id: 1, name: 'MyFile'}]; controller.onFileChange(files); $scope.$apply(); - expect(controller.dms.hasFile).toBeTruthy(); + expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); }); From 2c39103e934448271734dda8418d5d3c3e60361c Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Jul 2019 14:48:48 +0200 Subject: [PATCH 12/22] fixed dms back unit tests --- db/changes/10060-summer/00-dms.sql | 23 +++++++++++++++++++++++ db/dump/fixtures.sql | 8 ++++---- e2e/dms/temp/file.txt | 1 - 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 db/changes/10060-summer/00-dms.sql delete mode 100644 e2e/dms/temp/file.txt diff --git a/db/changes/10060-summer/00-dms.sql b/db/changes/10060-summer/00-dms.sql new file mode 100644 index 000000000..c06ba22fd --- /dev/null +++ b/db/changes/10060-summer/00-dms.sql @@ -0,0 +1,23 @@ +ALTER TABLE `vn2008`.`gestdoc` +ADD COLUMN `contentType` VARCHAR(100) NULL AFTER `file`; + +CREATE + OR REPLACE ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `vn`.`dms` AS + SELECT + `g`.`id` AS `id`, + `g`.`gesttip_id` AS `dmsTypeFk`, + `g`.`file` AS `file`, + `g`.`contentType` AS `contentType`, + `g`.`trabajador_id` AS `workerFk`, + `g`.`warehouse_id` AS `warehouseFk`, + `g`.`emp_id` AS `companyFk`, + `g`.`orden` AS `hardCopyNumber`, + `g`.`original` AS `hasFile`, + `g`.`sref` AS `reference`, + `g`.`brief` AS `description`, + `g`.`odbc_date` AS `created` + FROM + `vn2008`.`gestdoc` `g`; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 5af72a24a..f97148a8e 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1820,11 +1820,11 @@ INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `c (18, 'dua', 'dua', NULL, NULL, 'dua'), (19, 'inmovilizado', 'inmovilizado', NULL, NULL, 'fixedAssets'); -INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) +INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) VALUES - (1, 14, '1.pdf', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()), - (2, 5, '2.pdf', 5, 1, 442, 1, TRUE, 'Client:101', 'Client:101 dms for the client', CURDATE()), - (3, 5, '3.pdf', 5, 1, 442, NULL, TRUE, 'Client: 101', 'Client:101 readme', CURDATE()); + (1, 14, '1.txt', 'text/plain', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()), + (2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:101', 'Client:101 dms for the client', CURDATE()), + (3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 101', 'Client:101 readme', CURDATE()); INSERT INTO `vn`.`ticketDms`(`ticketFk`, `dmsFk`) VALUES diff --git a/e2e/dms/temp/file.txt b/e2e/dms/temp/file.txt deleted file mode 100644 index 5ef648a88..000000000 --- a/e2e/dms/temp/file.txt +++ /dev/null @@ -1 +0,0 @@ -It works! \ No newline at end of file From 573868c4ad57ee10f77b5bd643d9afab4e0bb254 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 17 Jul 2019 07:33:46 +0200 Subject: [PATCH 13/22] fixed e2e tests --- .gitignore | 4 +++- e2e/dms/c4c/1.txt | 1 + e2e/dms/c81/2.txt | 1 + e2e/dms/ecc/3.txt | 1 + modules/client/front/address/edit/index.js | 3 ++- 5 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 e2e/dms/c4c/1.txt create mode 100644 e2e/dms/c81/2.txt create mode 100644 e2e/dms/ecc/3.txt diff --git a/.gitignore b/.gitignore index 7f9805f39..b8da20c68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ node_modules dist/* e2e/dms/*/ -!e2e/dms/temp/ +!e2e/dms/c4c +!e2e/dms/c81 +!e2e/dms/ecc npm-debug.log .eslintcache datasources.*.json diff --git a/e2e/dms/c4c/1.txt b/e2e/dms/c4c/1.txt new file mode 100644 index 000000000..5ef648a88 --- /dev/null +++ b/e2e/dms/c4c/1.txt @@ -0,0 +1 @@ +It works! \ No newline at end of file diff --git a/e2e/dms/c81/2.txt b/e2e/dms/c81/2.txt new file mode 100644 index 000000000..5ef648a88 --- /dev/null +++ b/e2e/dms/c81/2.txt @@ -0,0 +1 @@ +It works! \ No newline at end of file diff --git a/e2e/dms/ecc/3.txt b/e2e/dms/ecc/3.txt new file mode 100644 index 000000000..5ef648a88 --- /dev/null +++ b/e2e/dms/ecc/3.txt @@ -0,0 +1 @@ +It works! \ No newline at end of file diff --git a/modules/client/front/address/edit/index.js b/modules/client/front/address/edit/index.js index 14c5880bc..76bde9e0f 100644 --- a/modules/client/front/address/edit/index.js +++ b/modules/client/front/address/edit/index.js @@ -25,9 +25,10 @@ export default class Controller { } set postcodeSelection(selection) { + const hasValue = this._postcodeSelection; this._postcodeSelection = selection; - if (!selection) return; + if (!selection || !hasValue) return; const town = selection.town; const province = town.province; From 32f9aadaebaa4b096f27eafafdedc86d8101a58f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 17 Jul 2019 07:39:08 +0200 Subject: [PATCH 14/22] fixed unit tests --- modules/client/front/address/edit/index.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/client/front/address/edit/index.spec.js b/modules/client/front/address/edit/index.spec.js index ea0da9559..9ce61bfe2 100644 --- a/modules/client/front/address/edit/index.spec.js +++ b/modules/client/front/address/edit/index.spec.js @@ -59,6 +59,7 @@ describe('Client', () => { describe('postcodeSelection() setter', () => { it(`should set the town, province and contry properties`, () => { controller.address = {}; + controller._postcodeSelection = {townFk: 2}; controller.postcodeSelection = { townFk: 1, code: 46001, From 7a4ed5c3d0c8dac776f8e7fe348e7a4be20b778a Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 17 Jul 2019 15:01:38 +0200 Subject: [PATCH 15/22] ticket dms local warehouse and company --- .../components/user-configuration-popover/locale/es.yml | 4 ++-- modules/ticket/front/dms/create/index.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/front/salix/components/user-configuration-popover/locale/es.yml b/front/salix/components/user-configuration-popover/locale/es.yml index 3961f69ad..19584a1a5 100644 --- a/front/salix/components/user-configuration-popover/locale/es.yml +++ b/front/salix/components/user-configuration-popover/locale/es.yml @@ -1,5 +1,5 @@ Local warehouse: Almacén local Local bank: Banco local -Local company: Compañia local +Local company: Empresa local User warehouse: Almacén del usuario -User company: Compañia del usuario \ No newline at end of file +User company: Empresa del usuario \ No newline at end of file diff --git a/modules/ticket/front/dms/create/index.js b/modules/ticket/front/dms/create/index.js index 4e22a8ba5..630c1149f 100644 --- a/modules/ticket/front/dms/create/index.js +++ b/modules/ticket/front/dms/create/index.js @@ -32,10 +32,12 @@ class Controller { }}; this.$http.get('/api/DmsTypes/findOne', {params}).then(res => { const dmsTypeId = res.data && res.data.id; + const companyId = window.localStorage.defaultCompanyFk; + const warehouseId = window.localStorage.defaultWarehouseFk; const defaultParams = { reference: this.ticket.id, - warehouseId: this.ticket.warehouseFk, - companyId: this.ticket.companyFk, + warehouseId: warehouseId, + companyId: companyId, dmsTypeId: dmsTypeId, description: this.$translate.instant('FileDescription', { ticketId: this.ticket.id, From e6b97ba6e15c13fe63957e530e75aa5f610a5cec Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 19 Jul 2019 08:13:52 +0200 Subject: [PATCH 16/22] show dms order number #1601 --- modules/client/front/dms/index/index.html | 10 ++++++++-- modules/client/front/dms/index/index.js | 3 ++- modules/ticket/front/dms/index/index.html | 10 ++++++++-- modules/ticket/front/dms/index/index.js | 1 + 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index 26a36d086..c1d3444c2 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -14,7 +14,8 @@ Id Type - Reference + Order + Reference Description Original File @@ -31,7 +32,12 @@ {{::document.dms.dmsType.name}} - + + + {{::document.dms.hardCopyNumber}} + + + {{::document.dms.reference}} diff --git a/modules/client/front/dms/index/index.js b/modules/client/front/dms/index/index.js index 2a5da4072..ffaf1ee61 100644 --- a/modules/client/front/dms/index/index.js +++ b/modules/client/front/dms/index/index.js @@ -15,8 +15,9 @@ class Controller { scope: { fields: [ 'dmsTypeFk', - 'workerFk', 'reference', + 'hardCopyNumber', + 'workerFk', 'description', 'hasFile', 'file', diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 222a14b04..36c091828 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -14,7 +14,8 @@ Id Type - Reference + Order + Reference Description Original File @@ -31,7 +32,12 @@ {{::document.dms.dmsType.name}} - + + + {{::document.dms.hardCopyNumber}} + + + {{::document.dms.reference}} diff --git a/modules/ticket/front/dms/index/index.js b/modules/ticket/front/dms/index/index.js index f2c65be26..d0ee3cc45 100644 --- a/modules/ticket/front/dms/index/index.js +++ b/modules/ticket/front/dms/index/index.js @@ -16,6 +16,7 @@ class Controller { fields: [ 'dmsTypeFk', 'workerFk', + 'hardCopyNumber', 'reference', 'description', 'hasFile', From 2ca78d5916bcdec8557fe5dcc3f82a836a9609d2 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 19 Jul 2019 09:25:30 +0200 Subject: [PATCH 17/22] catalogFilter show items without color --- modules/order/back/methods/order/catalogFilter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js index 1c845efdc..33ad91ff5 100644 --- a/modules/order/back/methods/order/catalogFilter.js +++ b/modules/order/back/methods/order/catalogFilter.js @@ -111,7 +111,7 @@ module.exports = Self => { FROM tmp.ticketCalculateItem tci JOIN vn.item i ON i.id = tci.itemFk JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.ink ON ink.id = i.inkFk + LEFT JOIN vn.ink ON ink.id = i.inkFk JOIN vn.worker w on w.id = it.workerFk`); // Apply order by tag From e94dbfe1897dc67467707b2e3e2fce01002dd11e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 23 Jul 2019 13:41:28 +0200 Subject: [PATCH 18/22] updated delivery-note dms path --- print/config/print.json | 3 +++ print/report/rpt-delivery-note/index.js | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/print/config/print.json b/print/config/print.json index e5bc72021..cb98421fc 100755 --- a/print/config/print.json +++ b/print/config/print.json @@ -24,5 +24,8 @@ "rejectUnauthorized": false }, "pool": true + }, + "storage": { + "root": "./e2e/dms" } } \ No newline at end of file diff --git a/print/report/rpt-delivery-note/index.js b/print/report/rpt-delivery-note/index.js index b282898a5..1a18bb180 100755 --- a/print/report/rpt-delivery-note/index.js +++ b/print/report/rpt-delivery-note/index.js @@ -1,6 +1,8 @@ const strftime = require('strftime'); const database = require(`${appPath}/lib/database`); +const config = require(`${appPath}/lib/config.js`); const UserException = require(`${appPath}/lib/exceptions/userException`); +const md5 = require('md5'); module.exports = { name: 'rpt-delivery-note', @@ -30,7 +32,9 @@ module.exports = { }, computed: { dmsPath() { - const hostPath = 'http://windows.verdnatura.es/signatures/tickets'; + const pathHash = md5(this.signature.id.toString()).substring(0, 3); + const hostPath = `file:///${config.storage.root}/${pathHash}`; + if (this.signature && this.signature.id) return `${hostPath}/${this.signature.id}.png`; }, From a165fcd07fba905add541d594f2d831b9b6a0f3b Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 26 Jul 2019 13:05:22 +0200 Subject: [PATCH 19/22] client.create not showing all postcodes, changed autocomplete #1619 --- .../client/front/address/create/index.html | 38 +++++----- modules/client/front/address/edit/index.html | 37 ++++----- modules/client/front/create/index.html | 75 ++++++++++--------- modules/route/front/locale/es.yml | 3 +- 4 files changed, 82 insertions(+), 71 deletions(-) diff --git a/modules/client/front/address/create/index.html b/modules/client/front/address/create/index.html index 9b3dc2ac2..432d4ebbe 100644 --- a/modules/client/front/address/create/index.html +++ b/modules/client/front/address/create/index.html @@ -24,12 +24,30 @@ + + + + @@ -43,21 +61,7 @@ vn-tooltip="New postcode" ng-click="postcode.open()"> - - - - + + + + + @@ -59,21 +77,6 @@ vn-tooltip="New postcode" ng-click="postcode.open()"> - - - - - - - {{code}}, {{town.name}} - {{town.province.name}} - ({{town.province.country.country}}) - + + + + + + + - - - - - - + url="/api/Postcodes/location" + fields="['code', 'townFk']" + field="$ctrl.client.postcode" + selection="$ctrl.postcodeSelection" + search-function="{code: $search}" + where="{townFk: town.selection.id}" + order="code, townFk" + show-field="code" + value-field="code" + label="Postcode"> + + {{code}}, {{town.name}} - {{town.province.name}} + ({{town.province.country.country}}) + diff --git a/modules/route/front/locale/es.yml b/modules/route/front/locale/es.yml index 0b6c1f2b3..421d40923 100644 --- a/modules/route/front/locale/es.yml +++ b/modules/route/front/locale/es.yml @@ -1,2 +1,3 @@ Routes: Rutas -Search routes by id: Buscar rutas por identificador \ No newline at end of file +Search routes by id: Buscar rutas por identificador +New route: Nueva ruta \ No newline at end of file From e3c4536183da553b7229b4107a10bf0660b8459d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 1 Aug 2019 09:58:59 +0200 Subject: [PATCH 20/22] timeControl calendar fixed #1623 --- front/core/components/calendar/index.js | 8 ++++++-- modules/worker/front/time-control/index.js | 16 ++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/front/core/components/calendar/index.js b/front/core/components/calendar/index.js index 372ed280d..e7c925e60 100644 --- a/front/core/components/calendar/index.js +++ b/front/core/components/calendar/index.js @@ -260,8 +260,9 @@ export default class Calendar extends Component { */ moveNext(skip = 1) { let next = this.defaultDate.getMonth() + skip; - this.defaultDate.setDate(1); this.defaultDate.setMonth(next); + this.defaultDate.setHours(0, 0, 0, 0); + this.defaultDate.setDate(1); this.repaint(); this.emit('moveNext'); @@ -274,8 +275,11 @@ export default class Calendar extends Component { */ movePrevious(skip = 1) { let previous = this.defaultDate.getMonth() - skip; - this.defaultDate.setDate(1); this.defaultDate.setMonth(previous); + this.defaultDate.setHours(0, 0, 0, 0); + + const lastDate = this.lastDay(this.defaultDate); + this.defaultDate.setDate(lastDate.getDate()); this.repaint(); this.emit('movePrevious'); diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 2d23d378c..b013df44b 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -84,7 +84,7 @@ class Controller { for (let i = 0; i < weekdays.length; i++) { const dated = new Date(); - dated.setHours(0, 0, 0, 0); + dated.setHours(23, 59, 0, 0); dated.setMonth(this.started.getMonth()); dated.setDate(this.started.getDate() + i); @@ -113,10 +113,10 @@ class Controller { } get weekOffset() { - const currentDate = this.defaultDate; - const weekDay = currentDate.getDay() + 1; + const timed = this.defaultDate; + const weekDay = timed.getDay() == 0 ? 7 : timed.getDay(); - return weekDay - 2; + return weekDay - 1; } /** @@ -125,8 +125,10 @@ class Controller { */ get started() { const started = new Date(); + const offset = this.weekOffset; + started.setMonth(this.defaultDate.getMonth()); - started.setDate(this.defaultDate.getDate() - this.weekOffset); + started.setDate(this.defaultDate.getDate() - offset); started.setHours(0, 0, 0, 0); return started; @@ -202,8 +204,10 @@ class Controller { onSelection(value) { const selected = value[0].dated; + this.defaultDate.setMonth(selected.getMonth()); - this.defaultDate.setDate(selected.getDate() - 1); + this.defaultDate.setDate(selected.getDate()); + this.refresh(); } From e7511aefdc4491c655805f3b958fe13a4ed1c4af Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 1 Aug 2019 11:52:53 +0200 Subject: [PATCH 21/22] back errors fixed --- modules/client/front/address/create/index.js | 2 -- modules/client/front/address/edit/index.js | 2 -- modules/ticket/back/methods/ticket/new.js | 4 ++-- modules/ticket/back/methods/ticket/priceDifference.js | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/client/front/address/create/index.js b/modules/client/front/address/create/index.js index bcccc0730..3cd8af614 100644 --- a/modules/client/front/address/create/index.js +++ b/modules/client/front/address/create/index.js @@ -25,11 +25,9 @@ export default class Controller { const town = selection.town; const province = town.province; - const country = province.country; this.address.city = town.name; this.address.provinceFk = province.id; - this.address.countryFk = country.id; } onResponse(response) { diff --git a/modules/client/front/address/edit/index.js b/modules/client/front/address/edit/index.js index 76bde9e0f..02fe19658 100644 --- a/modules/client/front/address/edit/index.js +++ b/modules/client/front/address/edit/index.js @@ -32,11 +32,9 @@ export default class Controller { const town = selection.town; const province = town.province; - const country = province.country; this.address.city = town.name; this.address.provinceFk = province.id; - this.address.countryFk = country.id; } onResponse(response) { diff --git a/modules/ticket/back/methods/ticket/new.js b/modules/ticket/back/methods/ticket/new.js index 5bfb1996e..25e5a08c5 100644 --- a/modules/ticket/back/methods/ticket/new.js +++ b/modules/ticket/back/methods/ticket/new.js @@ -63,13 +63,13 @@ module.exports = Self => { if (!params.shipped && params.landed) { const shippedResult = await models.Agency.getShipped(params.landed, address.id, params.agencyModeFk, params.warehouseFk); - params.shipped = shippedResult.shipped; + params.shipped = shippedResult && shippedResult.shipped; } if (params.shipped && !params.landed) { const landedResult = await models.Agency.getLanded(params.shipped, address.id, params.agencyModeFk, params.warehouseFk); - params.landed = landedResult.landed; + params.landed = landedResult && landedResult.landed; } if (!params.userId && ctx.req && ctx.req.accessToken.userId) diff --git a/modules/ticket/back/methods/ticket/priceDifference.js b/modules/ticket/back/methods/ticket/priceDifference.js index 96c34d252..552c2b991 100644 --- a/modules/ticket/back/methods/ticket/priceDifference.js +++ b/modules/ticket/back/methods/ticket/priceDifference.js @@ -63,7 +63,7 @@ module.exports = Self => { if (!isProductionBoss) { const zone = await models.Agency.getShipped(landed, addressId, agencyModeId, warehouseId); - if (zone.id != zoneId) + if (!zone || zone.id != zoneId) throw new UserError(`You don't have privileges to change the zone`); } From 2ff374e7ba0fbca178612b8952372d6a21f39974 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 2 Aug 2019 08:27:55 +0200 Subject: [PATCH 22/22] postcode autocompletion fixes --- .../components/autocomplete/autocomplete.js | 17 +++++- .../client/front/address/create/index.spec.js | 1 - modules/client/front/address/edit/index.html | 3 +- .../client/front/address/edit/index.spec.js | 1 - modules/client/front/fiscal-data/index.html | 58 ++++++++++--------- modules/client/front/fiscal-data/index.js | 23 +++++--- 6 files changed, 62 insertions(+), 41 deletions(-) diff --git a/front/core/components/autocomplete/autocomplete.js b/front/core/components/autocomplete/autocomplete.js index 45e28350b..91a88704a 100755 --- a/front/core/components/autocomplete/autocomplete.js +++ b/front/core/components/autocomplete/autocomplete.js @@ -1,6 +1,7 @@ import ngModule from '../../module'; import Input from '../../lib/input'; import assignProps from '../../lib/assign-props'; +import {mergeWhere} from 'vn-loopback/util/filter'; import './style.scss'; /** @@ -163,6 +164,8 @@ export default class Autocomplete extends Input { else where[this.valueField] = this._field; + where = mergeWhere(where, this.fetchFunction); + let filter = { fields: this.$.dropDown.getFields(), where: where @@ -292,6 +295,17 @@ export default class Autocomplete extends Input { this.assignDropdownProps(); this.$.dropDown.show(this.input, search); } + + get fetchFunction() { + return this._fetchFunction; + } + + set fetchFunction(value) { + this._fetchFunction = value; + + if (value) + this.refreshSelection(); + } } Autocomplete.$inject = ['$element', '$scope', '$http', '$transclude', '$translate', '$interpolate']; @@ -317,7 +331,8 @@ ngModule.component('vnAutocomplete', { order: '@?', limit: ' { expect(controller.address.city).toEqual('New York'); expect(controller.address.provinceFk).toEqual(1); - expect(controller.address.countryFk).toEqual(2); }); }); }); diff --git a/modules/client/front/address/edit/index.html b/modules/client/front/address/edit/index.html index b54e98901..c2dce8f37 100644 --- a/modules/client/front/address/edit/index.html +++ b/modules/client/front/address/edit/index.html @@ -60,9 +60,10 @@ url="/api/Postcodes/location" fields="['code', 'townFk']" field="$ctrl.address.postalCode" + where="{townFk: town.selection.id}" selection="$ctrl.postcodeSelection" search-function="{code: $search}" - where="{townFk: town.selection.id}" + fetch-function="{townFk: town.selection.id}" order="code, townFk" show-field="code" value-field="code" diff --git a/modules/client/front/address/edit/index.spec.js b/modules/client/front/address/edit/index.spec.js index 9ce61bfe2..33aacb672 100644 --- a/modules/client/front/address/edit/index.spec.js +++ b/modules/client/front/address/edit/index.spec.js @@ -79,7 +79,6 @@ describe('Client', () => { expect(controller.address.city).toEqual('New York'); expect(controller.address.provinceFk).toEqual(1); - expect(controller.address.countryFk).toEqual(2); }); }); }); diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 04bd1815f..67d7705ce 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -28,12 +28,39 @@ + + + + + + + + @@ -42,31 +69,6 @@ ({{town.province.country.country}}) - - - - - - - -