From a5486ec69481c5b192a3eb07461d2f3e5d334c44 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 8 Aug 2019 08:37:03 +0200 Subject: [PATCH] Get allowed content-types from model #1598 --- db/changes/10071-coffee/00-dmsType.sql | 1 - db/dump/fixtures.sql | 3 +- front/core/components/input-file/index.html | 5 +- front/core/components/input-file/index.js | 1 + .../core/components/textfield/textfield.html | 2 +- .../methods/claim-dms/allowedContentTypes.js | 23 +++++++ modules/claim/back/models/claim-dms.js | 1 + modules/claim/back/models/claim-dms.json | 5 ++ modules/claim/front/dms/create/index.html | 9 ++- modules/claim/front/dms/create/index.js | 17 ++++- modules/claim/front/dms/create/index.spec.js | 17 ++++- modules/claim/front/dms/create/locale/en.yml | 1 - modules/claim/front/dms/edit/index.html | 10 ++- modules/claim/front/dms/edit/index.js | 17 ++++- modules/claim/front/dms/edit/index.spec.js | 21 +++++- modules/claim/front/dms/edit/locale/es.yml | 3 - modules/claim/front/dms/index/locale/es.yml | 2 - modules/claim/front/dms/locale/en.yml | 2 + .../front/dms/{create => }/locale/es.yml | 5 +- .../methods/client-dms/allowedContentTypes.js | 23 +++++++ modules/client/back/models/client-dms.js | 1 + modules/client/back/models/client-dms.json | 2 +- modules/client/front/dms/create/index.html | 11 +++- modules/client/front/dms/create/index.js | 17 ++++- modules/client/front/dms/create/index.spec.js | 17 ++++- modules/client/front/dms/create/locale/en.yml | 1 - modules/client/front/dms/create/locale/es.yml | 5 -- modules/client/front/dms/edit/index.js | 17 ++++- modules/client/front/dms/edit/index.spec.js | 55 +++++++++++----- modules/client/front/dms/edit/locale/es.yml | 3 - modules/client/front/dms/locale/en.yml | 2 + modules/client/front/dms/locale/es.yml | 14 ++++ modules/order/front/filter/index.spec.js | 2 +- .../methods/ticket-dms/allowedContentTypes.js | 23 +++++++ modules/ticket/back/models/ticket-dms.js | 1 + modules/ticket/front/dms/create/index.html | 10 ++- modules/ticket/front/dms/create/index.js | 17 ++++- modules/ticket/front/dms/create/index.spec.js | 17 ++++- modules/ticket/front/dms/create/locale/en.yml | 1 - modules/ticket/front/dms/create/locale/es.yml | 5 -- modules/ticket/front/dms/edit/index.html | 10 ++- modules/ticket/front/dms/edit/index.js | 17 ++++- modules/ticket/front/dms/edit/index.spec.js | 65 +++++++++++++------ modules/ticket/front/dms/edit/locale/es.yml | 3 - modules/ticket/front/dms/index/locale/es.yml | 3 - modules/ticket/front/dms/locale/en.yml | 2 + modules/ticket/front/dms/locale/es.yml | 9 +++ 47 files changed, 410 insertions(+), 88 deletions(-) delete mode 100644 db/changes/10071-coffee/00-dmsType.sql create mode 100644 modules/claim/back/methods/claim-dms/allowedContentTypes.js delete mode 100644 modules/claim/front/dms/create/locale/en.yml delete mode 100644 modules/claim/front/dms/edit/locale/es.yml delete mode 100644 modules/claim/front/dms/index/locale/es.yml create mode 100644 modules/claim/front/dms/locale/en.yml rename modules/claim/front/dms/{create => }/locale/es.yml (53%) create mode 100644 modules/client/back/methods/client-dms/allowedContentTypes.js delete mode 100644 modules/client/front/dms/create/locale/en.yml delete mode 100644 modules/client/front/dms/create/locale/es.yml delete mode 100644 modules/client/front/dms/edit/locale/es.yml create mode 100644 modules/client/front/dms/locale/en.yml create mode 100644 modules/client/front/dms/locale/es.yml create mode 100644 modules/ticket/back/methods/ticket-dms/allowedContentTypes.js delete mode 100644 modules/ticket/front/dms/create/locale/en.yml delete mode 100644 modules/ticket/front/dms/create/locale/es.yml delete mode 100644 modules/ticket/front/dms/edit/locale/es.yml delete mode 100644 modules/ticket/front/dms/index/locale/es.yml create mode 100644 modules/ticket/front/dms/locale/en.yml create mode 100644 modules/ticket/front/dms/locale/es.yml diff --git a/db/changes/10071-coffee/00-dmsType.sql b/db/changes/10071-coffee/00-dmsType.sql deleted file mode 100644 index b8fc3b37b..000000000 --- a/db/changes/10071-coffee/00-dmsType.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO `vn2008`.`gesttip` (`tipo`, `path`, `writeRoleFk`, `readRoleFk`, `code`) VALUES ('Reclamación', '', '18', '1', 'claim'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index be383e735..cddff8123 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1837,7 +1837,8 @@ INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `c (16, 'Logistica', 'logistica', NULL, NULL, 'logistics'), (17, 'cmr', 'cmr', NULL, NULL, 'cmr'), (18, 'dua', 'dua', NULL, NULL, 'dua'), - (19, 'inmovilizado', 'inmovilizado', NULL, NULL, 'fixedAssets'); + (19, 'inmovilizado', 'inmovilizado', NULL, NULL, 'fixedAssets'), + (20, 'Reclamación', 'reclamacion', NULL, NULL, 'claim'); INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) VALUES diff --git a/front/core/components/input-file/index.html b/front/core/components/input-file/index.html index 59cfcff7d..4e9c48631 100644 --- a/front/core/components/input-file/index.html +++ b/front/core/components/input-file/index.html @@ -18,7 +18,10 @@ ng-blur="$ctrl.hasFocus = false" tabindex="{{$ctrl.input.tabindex}}" accept="{{$ctrl.accept}}"/> - +
diff --git a/front/core/components/input-file/index.js b/front/core/components/input-file/index.js index b54d5af2c..24c0cb44a 100644 --- a/front/core/components/input-file/index.js +++ b/front/core/components/input-file/index.js @@ -122,6 +122,7 @@ ngModule.component('vnInputFile', { name: '@?', disabled: '
diff --git a/modules/claim/back/methods/claim-dms/allowedContentTypes.js b/modules/claim/back/methods/claim-dms/allowedContentTypes.js new file mode 100644 index 000000000..2f5183f92 --- /dev/null +++ b/modules/claim/back/methods/claim-dms/allowedContentTypes.js @@ -0,0 +1,23 @@ +module.exports = Self => { + Self.remoteMethodCtx('allowedContentTypes', { + description: 'Returns a list of allowed contentTypes', + accessType: 'READ', + returns: { + type: ['Object'], + root: true + }, + http: { + path: `/allowedContentTypes`, + verb: 'GET' + } + }); + + Self.allowedContentTypes = async() => { + const storageConnector = Self.app.dataSources.storage.connector; + const allowedContentTypes = storageConnector.allowedContentTypes; + const modelAllowedContentTypes = Self.definition.settings.allowedContentTypes; + + return modelAllowedContentTypes || allowedContentTypes; + }; +}; + diff --git a/modules/claim/back/models/claim-dms.js b/modules/claim/back/models/claim-dms.js index 58cb1c883..ab7beaaf5 100644 --- a/modules/claim/back/models/claim-dms.js +++ b/modules/claim/back/models/claim-dms.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/claim-dms/removeFile')(Self); + require('../methods/claim-dms/allowedContentTypes')(Self); }; diff --git a/modules/claim/back/models/claim-dms.json b/modules/claim/back/models/claim-dms.json index 76e9e7997..9ef964886 100644 --- a/modules/claim/back/models/claim-dms.json +++ b/modules/claim/back/models/claim-dms.json @@ -10,6 +10,11 @@ "table": "claimDms" } }, + "allowedContentTypes": [ + "image/png", + "image/jpeg", + "image/jpg" + ], "properties": { "dmsFk": { "type": "Number", diff --git a/modules/claim/front/dms/create/index.html b/modules/claim/front/dms/create/index.html index 58617c780..0aba5a46a 100644 --- a/modules/claim/front/dms/create/index.html +++ b/modules/claim/front/dms/create/index.html @@ -45,8 +45,15 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".png, .jpg, .jpeg" + accept="{{$ctrl.allowedContentTypes}}" multiple="true"> + + + + diff --git a/modules/claim/front/dms/create/index.js b/modules/claim/front/dms/create/index.js index 15a0dbcbc..2560d6c24 100644 --- a/modules/claim/front/dms/create/index.js +++ b/modules/claim/front/dms/create/index.js @@ -22,8 +22,23 @@ class Controller { set claim(value) { this._claim = value; - if (value) + if (value) { this.setDefaultParams(); + this.getAllowedContentTypes(); + } + } + + getAllowedContentTypes() { + this.$http.get('/api/claimDms/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + + get contentTypesInfo() { + return this.$translate.instant('ContentTypesInfo', { + allowedContentTypes: this.allowedContentTypes + }); } setDefaultParams() { diff --git a/modules/claim/front/dms/create/index.spec.js b/modules/claim/front/dms/create/index.spec.js index 0031b0d38..335f691b9 100644 --- a/modules/claim/front/dms/create/index.spec.js +++ b/modules/claim/front/dms/create/index.spec.js @@ -22,8 +22,9 @@ describe('Claim', () => { })); describe('claim() setter', () => { - it('should set the claim data and then call setDefaultParams()', () => { + it('should set the claim data and then call setDefaultParams() and getAllowedContentTypes()', () => { spyOn(controller, 'setDefaultParams'); + spyOn(controller, 'getAllowedContentTypes'); controller._claim = undefined; controller.claim = { id: 15, @@ -33,6 +34,7 @@ describe('Claim', () => { expect(controller.claim).toBeDefined(); expect(controller.setDefaultParams).toHaveBeenCalledWith(); + expect(controller.getAllowedContentTypes).toHaveBeenCalledWith(); }); }); @@ -62,5 +64,18 @@ describe('Claim', () => { expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); + + describe('getAllowedContentTypes()', () => { + it('should make an HTTP GET request to get the allowed content types', () => { + const expectedResponse = ['image/png', 'image/jpg']; + $httpBackend.when('GET', `/api/claimDms/allowedContentTypes`).respond(expectedResponse); + $httpBackend.expect('GET', `/api/claimDms/allowedContentTypes`); + controller.getAllowedContentTypes(); + $httpBackend.flush(); + + expect(controller.allowedContentTypes).toBeDefined(); + expect(controller.allowedContentTypes).toEqual('image/png, image/jpg'); + }); + }); }); }); diff --git a/modules/claim/front/dms/create/locale/en.yml b/modules/claim/front/dms/create/locale/en.yml deleted file mode 100644 index 9f4c026a4..000000000 --- a/modules/claim/front/dms/create/locale/en.yml +++ /dev/null @@ -1 +0,0 @@ -FileDescription: Ticket id {{ticketId}} from client {{clientName}} id {{clientId}} \ No newline at end of file diff --git a/modules/claim/front/dms/edit/index.html b/modules/claim/front/dms/edit/index.html index 66df4658e..9a74807bc 100644 --- a/modules/claim/front/dms/edit/index.html +++ b/modules/claim/front/dms/edit/index.html @@ -45,7 +45,15 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> + accept="{{$ctrl.allowedContentTypes}}" + multiple="true"> + + + + diff --git a/modules/claim/front/dms/edit/index.js b/modules/claim/front/dms/edit/index.js index 2ad609bb5..02b1fd54b 100644 --- a/modules/claim/front/dms/edit/index.js +++ b/modules/claim/front/dms/edit/index.js @@ -18,8 +18,23 @@ class Controller { set claim(value) { this._claim = value; - if (value) + if (value) { this.setDefaultParams(); + this.getAllowedContentTypes(); + } + } + + getAllowedContentTypes() { + this.$http.get('/api/claimDms/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + + get contentTypesInfo() { + return this.$translate.instant('ContentTypesInfo', { + allowedContentTypes: this.allowedContentTypes + }); } setDefaultParams() { diff --git a/modules/claim/front/dms/edit/index.spec.js b/modules/claim/front/dms/edit/index.spec.js index 51940090b..03add5ab1 100644 --- a/modules/claim/front/dms/edit/index.spec.js +++ b/modules/claim/front/dms/edit/index.spec.js @@ -18,8 +18,9 @@ describe('Claim', () => { })); describe('claim() setter', () => { - it('should set the claim data and then call setDefaultParams()', () => { + it('should set the claim data and then call setDefaultParams() and getAllowedContentTypes()', () => { spyOn(controller, 'setDefaultParams'); + spyOn(controller, 'getAllowedContentTypes'); controller._claim = undefined; controller.claim = { id: 15, @@ -28,6 +29,7 @@ describe('Claim', () => { expect(controller.setDefaultParams).toHaveBeenCalledWith(); expect(controller.claim).toBeDefined(); + expect(controller.getAllowedContentTypes).toHaveBeenCalledWith(); }); }); @@ -38,7 +40,7 @@ describe('Claim', () => { reference: 101, warehouseFk: 1, companyFk: 442, - dmsTypeFk: 12, + dmsTypeFk: 20, description: 'Test', hasFile: false, hasFileAttached: false @@ -51,7 +53,7 @@ describe('Claim', () => { expect(controller.dms).toBeDefined(); expect(controller.dms.reference).toEqual(101); - expect(controller.dms.dmsTypeId).toEqual(12); + expect(controller.dms.dmsTypeId).toEqual(20); }); }); @@ -65,5 +67,18 @@ describe('Claim', () => { expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); + + describe('getAllowedContentTypes()', () => { + it('should make an HTTP GET request to get the allowed content types', () => { + const expectedResponse = ['image/png', 'image/jpg']; + $httpBackend.when('GET', `/api/claimDms/allowedContentTypes`).respond(expectedResponse); + $httpBackend.expect('GET', `/api/claimDms/allowedContentTypes`); + controller.getAllowedContentTypes(); + $httpBackend.flush(); + + expect(controller.allowedContentTypes).toBeDefined(); + expect(controller.allowedContentTypes).toEqual('image/png, image/jpg'); + }); + }); }); }); diff --git a/modules/claim/front/dms/edit/locale/es.yml b/modules/claim/front/dms/edit/locale/es.yml deleted file mode 100644 index 9d97564ba..000000000 --- a/modules/claim/front/dms/edit/locale/es.yml +++ /dev/null @@ -1,3 +0,0 @@ -Edit file: Editar fichero -File: Fichero -Generate identifier for original file: Generar identificador para archivo original \ No newline at end of file diff --git a/modules/claim/front/dms/index/locale/es.yml b/modules/claim/front/dms/index/locale/es.yml deleted file mode 100644 index f355af665..000000000 --- a/modules/claim/front/dms/index/locale/es.yml +++ /dev/null @@ -1,2 +0,0 @@ -Type: Tipo -Are you sure you want to continue?: ¿Seguro que quieres continuar? \ No newline at end of file diff --git a/modules/claim/front/dms/locale/en.yml b/modules/claim/front/dms/locale/en.yml new file mode 100644 index 000000000..a202e8bf2 --- /dev/null +++ b/modules/claim/front/dms/locale/en.yml @@ -0,0 +1,2 @@ +FileDescription: Ticket id {{ticketId}} from client {{clientName}} id {{clientId}} +ContentTypesInfo: Allowed file types {{allowedContentTypes}} \ No newline at end of file diff --git a/modules/claim/front/dms/create/locale/es.yml b/modules/claim/front/dms/locale/es.yml similarity index 53% rename from modules/claim/front/dms/create/locale/es.yml rename to modules/claim/front/dms/locale/es.yml index d63487f04..8a8674c5a 100644 --- a/modules/claim/front/dms/create/locale/es.yml +++ b/modules/claim/front/dms/locale/es.yml @@ -1,5 +1,8 @@ Upload file: Subir fichero +Edit file: Editar fichero Upload: Subir File: Fichero FileDescription: Reclamación id {{claimId}} del cliente "{{clientName}}" id {{clientId}} -Generate identifier for original file: Generar identificador para archivo original \ No newline at end of file +Generate identifier for original file: Generar identificador para archivo original +ContentTypesInfo: "Tipos de archivo permitidos: {{allowedContentTypes}}" +Are you sure you want to continue?: ¿Seguro que quieres continuar? \ No newline at end of file diff --git a/modules/client/back/methods/client-dms/allowedContentTypes.js b/modules/client/back/methods/client-dms/allowedContentTypes.js new file mode 100644 index 000000000..2f5183f92 --- /dev/null +++ b/modules/client/back/methods/client-dms/allowedContentTypes.js @@ -0,0 +1,23 @@ +module.exports = Self => { + Self.remoteMethodCtx('allowedContentTypes', { + description: 'Returns a list of allowed contentTypes', + accessType: 'READ', + returns: { + type: ['Object'], + root: true + }, + http: { + path: `/allowedContentTypes`, + verb: 'GET' + } + }); + + Self.allowedContentTypes = async() => { + const storageConnector = Self.app.dataSources.storage.connector; + const allowedContentTypes = storageConnector.allowedContentTypes; + const modelAllowedContentTypes = Self.definition.settings.allowedContentTypes; + + return modelAllowedContentTypes || allowedContentTypes; + }; +}; + diff --git a/modules/client/back/models/client-dms.js b/modules/client/back/models/client-dms.js index 9e5da9132..0cffb042c 100644 --- a/modules/client/back/models/client-dms.js +++ b/modules/client/back/models/client-dms.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/client-dms/removeFile')(Self); + require('../methods/client-dms/allowedContentTypes')(Self); }; diff --git a/modules/client/back/models/client-dms.json b/modules/client/back/models/client-dms.json index c919c2223..28ad21917 100644 --- a/modules/client/back/models/client-dms.json +++ b/modules/client/back/models/client-dms.json @@ -5,7 +5,7 @@ "model":"ClientLog", "relation": "client", "showField": "dmsFk" - }, + }, "options": { "mysql": { "table": "clientDms" diff --git a/modules/client/front/dms/create/index.html b/modules/client/front/dms/create/index.html index 6010fb4a9..409626578 100644 --- a/modules/client/front/dms/create/index.html +++ b/modules/client/front/dms/create/index.html @@ -46,7 +46,16 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> + accept="{{$ctrl.allowedContentTypes}}" + required="true" + multiple="true"> + + + + diff --git a/modules/client/front/dms/create/index.js b/modules/client/front/dms/create/index.js index 924e5fb26..7f14ca187 100644 --- a/modules/client/front/dms/create/index.js +++ b/modules/client/front/dms/create/index.js @@ -22,8 +22,23 @@ class Controller { set client(value) { this._client = value; - if (value) + if (value) { this.setDefaultParams(); + this.getAllowedContentTypes(); + } + } + + getAllowedContentTypes() { + this.$http.get('/api/clientDms/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + + get contentTypesInfo() { + return this.$translate.instant('ContentTypesInfo', { + allowedContentTypes: this.allowedContentTypes + }); } setDefaultParams() { diff --git a/modules/client/front/dms/create/index.spec.js b/modules/client/front/dms/create/index.spec.js index 5ef4d28f3..3cba70a00 100644 --- a/modules/client/front/dms/create/index.spec.js +++ b/modules/client/front/dms/create/index.spec.js @@ -18,8 +18,9 @@ describe('Client', () => { })); describe('client() setter', () => { - it('should set the client data and then call setDefaultParams()', () => { + it('should set the client data and then call setDefaultParams() and getAllowedContentTypes()', () => { spyOn(controller, 'setDefaultParams'); + spyOn(controller, 'getAllowedContentTypes'); controller.client = { id: 15, name: 'Bruce wayne' @@ -27,6 +28,7 @@ describe('Client', () => { expect(controller.client).toBeDefined(); expect(controller.setDefaultParams).toHaveBeenCalledWith(); + expect(controller.getAllowedContentTypes).toHaveBeenCalledWith(); }); }); @@ -56,5 +58,18 @@ describe('Client', () => { expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); + + describe('getAllowedContentTypes()', () => { + it('should make an HTTP GET request to get the allowed content types', () => { + const expectedResponse = ['image/png', 'image/jpg']; + $httpBackend.when('GET', `/api/clientDms/allowedContentTypes`).respond(expectedResponse); + $httpBackend.expect('GET', `/api/clientDms/allowedContentTypes`); + controller.getAllowedContentTypes(); + $httpBackend.flush(); + + expect(controller.allowedContentTypes).toBeDefined(); + expect(controller.allowedContentTypes).toEqual('image/png, image/jpg'); + }); + }); }); }); diff --git a/modules/client/front/dms/create/locale/en.yml b/modules/client/front/dms/create/locale/en.yml deleted file mode 100644 index 56f6a658b..000000000 --- a/modules/client/front/dms/create/locale/en.yml +++ /dev/null @@ -1 +0,0 @@ -ClientFileDescription: "{{dmsTypeName}} from client {{clientName}} id {{clientId}}" \ No newline at end of file diff --git a/modules/client/front/dms/create/locale/es.yml b/modules/client/front/dms/create/locale/es.yml deleted file mode 100644 index 2ea3b31d8..000000000 --- a/modules/client/front/dms/create/locale/es.yml +++ /dev/null @@ -1,5 +0,0 @@ -Upload file: Subir fichero -Upload: Subir -File: Fichero -ClientFileDescription: "{{dmsTypeName}} del cliente {{clientName}} id {{clientId}}" -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.js b/modules/client/front/dms/edit/index.js index be8396467..45490263b 100644 --- a/modules/client/front/dms/edit/index.js +++ b/modules/client/front/dms/edit/index.js @@ -18,8 +18,23 @@ class Controller { set client(value) { this._client = value; - if (value) + if (value) { this.setDefaultParams(); + this.getAllowedContentTypes(); + } + } + + getAllowedContentTypes() { + this.$http.get('/api/clientDms/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + + get contentTypesInfo() { + return this.$translate.instant('ContentTypesInfo', { + allowedContentTypes: this.allowedContentTypes + }); } setDefaultParams() { diff --git a/modules/client/front/dms/edit/index.spec.js b/modules/client/front/dms/edit/index.spec.js index 5ef4d28f3..7faf629af 100644 --- a/modules/client/front/dms/edit/index.spec.js +++ b/modules/client/front/dms/edit/index.spec.js @@ -1,43 +1,52 @@ import './index'; describe('Client', () => { - describe('Component vnClientDmsCreate', () => { + describe('Component vnClientDmsEdit', () => { let controller; let $scope; let $httpBackend; - let $httpParamSerializer; + let $state; beforeEach(ngModule('client')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnClientDmsCreate', {$scope}); - controller._client = {id: 101, name: 'Bruce wayne'}; + $state = {params: {dmsId: 1}}; + controller = $componentController('vnClientDmsEdit', {$scope, $state}); + controller._client = {id: 1}; })); describe('client() setter', () => { - it('should set the client data and then call setDefaultParams()', () => { + it('should set the client data and then call setDefaultParams() and getAllowedContentTypes()', () => { spyOn(controller, 'setDefaultParams'); + spyOn(controller, 'getAllowedContentTypes'); + controller._client = undefined; controller.client = { - id: 15, - name: 'Bruce wayne' + id: 15 }; - expect(controller.client).toBeDefined(); expect(controller.setDefaultParams).toHaveBeenCalledWith(); + expect(controller.client).toBeDefined(); + expect(controller.getAllowedContentTypes).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}`); + const dmsId = 1; + const expectedResponse = { + reference: 101, + warehouseFk: 1, + companyFk: 442, + dmsTypeFk: 12, + description: 'Test', + hasFile: false, + hasFileAttached: false + }; + + $httpBackend.when('GET', `/api/Dms/${dmsId}`).respond(expectedResponse); + $httpBackend.expect('GET', `/api/Dms/${dmsId}`).respond(expectedResponse); controller.setDefaultParams(); $httpBackend.flush(); @@ -50,11 +59,25 @@ describe('Client', () => { describe('onFileChange()', () => { it('should set dms hasFileAttached property to true if has any files', () => { const files = [{id: 1, name: 'MyFile'}]; + controller.dms = {hasFileAttached: false}; controller.onFileChange(files); $scope.$apply(); expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); + + describe('getAllowedContentTypes()', () => { + it('should make an HTTP GET request to get the allowed content types', () => { + const expectedResponse = ['image/png', 'image/jpg']; + $httpBackend.when('GET', `/api/clientDms/allowedContentTypes`).respond(expectedResponse); + $httpBackend.expect('GET', `/api/clientDms/allowedContentTypes`); + controller.getAllowedContentTypes(); + $httpBackend.flush(); + + expect(controller.allowedContentTypes).toBeDefined(); + expect(controller.allowedContentTypes).toEqual('image/png, image/jpg'); + }); + }); }); }); diff --git a/modules/client/front/dms/edit/locale/es.yml b/modules/client/front/dms/edit/locale/es.yml deleted file mode 100644 index 9d97564ba..000000000 --- a/modules/client/front/dms/edit/locale/es.yml +++ /dev/null @@ -1,3 +0,0 @@ -Edit file: Editar fichero -File: Fichero -Generate identifier for original file: Generar identificador para archivo original \ No newline at end of file diff --git a/modules/client/front/dms/locale/en.yml b/modules/client/front/dms/locale/en.yml new file mode 100644 index 000000000..766853fca --- /dev/null +++ b/modules/client/front/dms/locale/en.yml @@ -0,0 +1,2 @@ +ClientFileDescription: "{{dmsTypeName}} from client {{clientName}} id {{clientId}}" +ContentTypesInfo: Allowed file types {{allowedContentTypes}} \ No newline at end of file diff --git a/modules/client/front/dms/locale/es.yml b/modules/client/front/dms/locale/es.yml new file mode 100644 index 000000000..4185098f3 --- /dev/null +++ b/modules/client/front/dms/locale/es.yml @@ -0,0 +1,14 @@ +Upload file: Subir fichero +Edit file: Editar fichero +Upload: Subir +File: Fichero +ClientFileDescription: "{{dmsTypeName}} del cliente {{clientName}} id {{clientId}}" +ContentTypesInfo: "Tipos de archivo permitidos: {{allowedContentTypes}}" +Generate identifier for original file: Generar identificador para archivo original +File management: Gestión documental +Hard copy: Copia +This file will be deleted: Este fichero va a ser borrado +Are you sure?: Estas seguro? +File deleted: Fichero eliminado +Remove file: Eliminar fichero +Download file: Descargar fichero \ No newline at end of file diff --git a/modules/order/front/filter/index.spec.js b/modules/order/front/filter/index.spec.js index fe7f3e9ed..89a2c68b7 100644 --- a/modules/order/front/filter/index.spec.js +++ b/modules/order/front/filter/index.spec.js @@ -1,7 +1,7 @@ import './index.js'; import crudModel from 'core/mocks/crud-model'; -fdescribe('Order', () => { +describe('Order', () => { describe('Component vnCatalogFilter', () => { let $scope; let $state; diff --git a/modules/ticket/back/methods/ticket-dms/allowedContentTypes.js b/modules/ticket/back/methods/ticket-dms/allowedContentTypes.js new file mode 100644 index 000000000..2f5183f92 --- /dev/null +++ b/modules/ticket/back/methods/ticket-dms/allowedContentTypes.js @@ -0,0 +1,23 @@ +module.exports = Self => { + Self.remoteMethodCtx('allowedContentTypes', { + description: 'Returns a list of allowed contentTypes', + accessType: 'READ', + returns: { + type: ['Object'], + root: true + }, + http: { + path: `/allowedContentTypes`, + verb: 'GET' + } + }); + + Self.allowedContentTypes = async() => { + const storageConnector = Self.app.dataSources.storage.connector; + const allowedContentTypes = storageConnector.allowedContentTypes; + const modelAllowedContentTypes = Self.definition.settings.allowedContentTypes; + + return modelAllowedContentTypes || allowedContentTypes; + }; +}; + diff --git a/modules/ticket/back/models/ticket-dms.js b/modules/ticket/back/models/ticket-dms.js index ddb338632..8a6d03434 100644 --- a/modules/ticket/back/models/ticket-dms.js +++ b/modules/ticket/back/models/ticket-dms.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/ticket-dms/removeFile')(Self); + require('../methods/ticket-dms/allowedContentTypes')(Self); }; diff --git a/modules/ticket/front/dms/create/index.html b/modules/ticket/front/dms/create/index.html index 7c8ae6ad2..2ab817c75 100644 --- a/modules/ticket/front/dms/create/index.html +++ b/modules/ticket/front/dms/create/index.html @@ -45,7 +45,15 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> + accept="{{$ctrl.allowedContentTypes}}" + multiple="true"> + + + + diff --git a/modules/ticket/front/dms/create/index.js b/modules/ticket/front/dms/create/index.js index 630c1149f..2869c831a 100644 --- a/modules/ticket/front/dms/create/index.js +++ b/modules/ticket/front/dms/create/index.js @@ -22,8 +22,23 @@ class Controller { set ticket(value) { this._ticket = value; - if (value) + if (value) { this.setDefaultParams(); + this.getAllowedContentTypes(); + } + } + + getAllowedContentTypes() { + this.$http.get('/api/ticketDms/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + + get contentTypesInfo() { + return this.$translate.instant('ContentTypesInfo', { + allowedContentTypes: this.allowedContentTypes + }); } setDefaultParams() { diff --git a/modules/ticket/front/dms/create/index.spec.js b/modules/ticket/front/dms/create/index.spec.js index 0014c010d..d4f6ad63b 100644 --- a/modules/ticket/front/dms/create/index.spec.js +++ b/modules/ticket/front/dms/create/index.spec.js @@ -23,8 +23,9 @@ describe('Ticket', () => { })); describe('client() setter', () => { - it('should set the ticket data and then call setDefaultParams()', () => { + it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => { spyOn(controller, 'setDefaultParams'); + spyOn(controller, 'getAllowedContentTypes'); controller.ticket = { id: 15, name: 'Bruce wayne' @@ -32,6 +33,7 @@ describe('Ticket', () => { expect(controller.ticket).toBeDefined(); expect(controller.setDefaultParams).toHaveBeenCalledWith(); + expect(controller.getAllowedContentTypes).toHaveBeenCalledWith(); }); }); @@ -61,5 +63,18 @@ describe('Ticket', () => { expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); + + describe('getAllowedContentTypes()', () => { + it('should make an HTTP GET request to get the allowed content types', () => { + const expectedResponse = ['image/png', 'image/jpg']; + $httpBackend.when('GET', `/api/ticketDms/allowedContentTypes`).respond(expectedResponse); + $httpBackend.expect('GET', `/api/ticketDms/allowedContentTypes`); + controller.getAllowedContentTypes(); + $httpBackend.flush(); + + expect(controller.allowedContentTypes).toBeDefined(); + expect(controller.allowedContentTypes).toEqual('image/png, image/jpg'); + }); + }); }); }); diff --git a/modules/ticket/front/dms/create/locale/en.yml b/modules/ticket/front/dms/create/locale/en.yml deleted file mode 100644 index 9f4c026a4..000000000 --- a/modules/ticket/front/dms/create/locale/en.yml +++ /dev/null @@ -1 +0,0 @@ -FileDescription: Ticket id {{ticketId}} from client {{clientName}} id {{clientId}} \ No newline at end of file diff --git a/modules/ticket/front/dms/create/locale/es.yml b/modules/ticket/front/dms/create/locale/es.yml deleted file mode 100644 index 999826352..000000000 --- a/modules/ticket/front/dms/create/locale/es.yml +++ /dev/null @@ -1,5 +0,0 @@ -Upload file: Subir fichero -Upload: Subir -File: Fichero -FileDescription: Ticket id {{ticketId}} del cliente {{clientName}} id {{clientId}} -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 7614a7783..44075615d 100644 --- a/modules/ticket/front/dms/edit/index.html +++ b/modules/ticket/front/dms/edit/index.html @@ -45,7 +45,15 @@ label="File" model="$ctrl.dms.files" on-change="$ctrl.onFileChange(files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> + accept="{{$ctrl.allowedContentTypes}}" + multiple="true"> + + + + diff --git a/modules/ticket/front/dms/edit/index.js b/modules/ticket/front/dms/edit/index.js index 486d37791..800e78b97 100644 --- a/modules/ticket/front/dms/edit/index.js +++ b/modules/ticket/front/dms/edit/index.js @@ -18,8 +18,23 @@ class Controller { set ticket(value) { this._ticket = value; - if (value) + if (value) { this.setDefaultParams(); + this.getAllowedContentTypes(); + } + } + + getAllowedContentTypes() { + this.$http.get('/api/ticketDms/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + + get contentTypesInfo() { + return this.$translate.instant('ContentTypesInfo', { + allowedContentTypes: this.allowedContentTypes + }); } setDefaultParams() { diff --git a/modules/ticket/front/dms/edit/index.spec.js b/modules/ticket/front/dms/edit/index.spec.js index 5ef4d28f3..7639a4ae9 100644 --- a/modules/ticket/front/dms/edit/index.spec.js +++ b/modules/ticket/front/dms/edit/index.spec.js @@ -1,60 +1,83 @@ import './index'; -describe('Client', () => { - describe('Component vnClientDmsCreate', () => { +describe('Ticket', () => { + describe('Component vnTicketDmsEdit', () => { let controller; let $scope; let $httpBackend; - let $httpParamSerializer; + let $state; - beforeEach(ngModule('client')); + beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnClientDmsCreate', {$scope}); - controller._client = {id: 101, name: 'Bruce wayne'}; + $state = {params: {dmsId: 1}}; + controller = $componentController('vnTicketDmsEdit', {$scope, $state}); + controller._ticket = {id: 1, ticketFk: 16}; })); - describe('client() setter', () => { - it('should set the client data and then call setDefaultParams()', () => { + describe('ticket() setter', () => { + it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => { spyOn(controller, 'setDefaultParams'); - controller.client = { - id: 15, - name: 'Bruce wayne' + spyOn(controller, 'getAllowedContentTypes'); + controller._ticket = undefined; + controller.ticket = { + id: 15 }; - expect(controller.client).toBeDefined(); expect(controller.setDefaultParams).toHaveBeenCalledWith(); + expect(controller.ticket).toBeDefined(); + expect(controller.getAllowedContentTypes).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}`); + const dmsId = 1; + const expectedResponse = { + reference: 101, + warehouseFk: 1, + companyFk: 442, + dmsTypeFk: 14, + description: 'Test', + hasFile: false, + hasFileAttached: false + }; + + $httpBackend.when('GET', `/api/Dms/${dmsId}`).respond(expectedResponse); + $httpBackend.expect('GET', `/api/Dms/${dmsId}`).respond(expectedResponse); controller.setDefaultParams(); $httpBackend.flush(); expect(controller.dms).toBeDefined(); expect(controller.dms.reference).toEqual(101); - expect(controller.dms.dmsTypeId).toEqual(12); + expect(controller.dms.dmsTypeId).toEqual(14); }); }); describe('onFileChange()', () => { it('should set dms hasFileAttached property to true if has any files', () => { const files = [{id: 1, name: 'MyFile'}]; + controller.dms = {hasFileAttached: false}; controller.onFileChange(files); $scope.$apply(); expect(controller.dms.hasFileAttached).toBeTruthy(); }); }); + + describe('getAllowedContentTypes()', () => { + it('should make an HTTP GET request to get the allowed content types', () => { + const expectedResponse = ['image/png', 'image/jpg']; + $httpBackend.when('GET', `/api/ticketDms/allowedContentTypes`).respond(expectedResponse); + $httpBackend.expect('GET', `/api/ticketDms/allowedContentTypes`); + controller.getAllowedContentTypes(); + $httpBackend.flush(); + + expect(controller.allowedContentTypes).toBeDefined(); + expect(controller.allowedContentTypes).toEqual('image/png, image/jpg'); + }); + }); }); }); diff --git a/modules/ticket/front/dms/edit/locale/es.yml b/modules/ticket/front/dms/edit/locale/es.yml deleted file mode 100644 index 9d97564ba..000000000 --- a/modules/ticket/front/dms/edit/locale/es.yml +++ /dev/null @@ -1,3 +0,0 @@ -Edit file: Editar fichero -File: Fichero -Generate identifier for original file: Generar identificador para archivo original \ No newline at end of file diff --git a/modules/ticket/front/dms/index/locale/es.yml b/modules/ticket/front/dms/index/locale/es.yml deleted file mode 100644 index c6742ef3c..000000000 --- a/modules/ticket/front/dms/index/locale/es.yml +++ /dev/null @@ -1,3 +0,0 @@ -Type: Tipo -File management: Gestión documental -Are you sure you want to continue?: ¿Seguro que quieres continuar? \ No newline at end of file diff --git a/modules/ticket/front/dms/locale/en.yml b/modules/ticket/front/dms/locale/en.yml new file mode 100644 index 000000000..a202e8bf2 --- /dev/null +++ b/modules/ticket/front/dms/locale/en.yml @@ -0,0 +1,2 @@ +FileDescription: Ticket id {{ticketId}} from client {{clientName}} id {{clientId}} +ContentTypesInfo: Allowed file types {{allowedContentTypes}} \ No newline at end of file diff --git a/modules/ticket/front/dms/locale/es.yml b/modules/ticket/front/dms/locale/es.yml new file mode 100644 index 000000000..998960a8e --- /dev/null +++ b/modules/ticket/front/dms/locale/es.yml @@ -0,0 +1,9 @@ +Upload file: Subir fichero +Edit file: Editar fichero +Upload: Subir +File: Fichero +FileDescription: Ticket id {{ticketId}} del cliente {{clientName}} id {{clientId}} +Generate identifier for original file: Generar identificador para archivo original +ContentTypesInfo: 'Tipos de archivo permitidos: {{allowedContentTypes}}' +Are you sure you want to continue?: ¿Seguro que quieres continuar? +File management: Gestión documental \ No newline at end of file