Get allowed content-types from model #1598
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-08-08 08:37:03 +02:00
parent 2f1472b9ee
commit a5486ec694
47 changed files with 410 additions and 88 deletions

View File

@ -1 +0,0 @@
INSERT INTO `vn2008`.`gesttip` (`tipo`, `path`, `writeRoleFk`, `readRoleFk`, `code`) VALUES ('Reclamación', '', '18', '1', 'claim');

View File

@ -1837,7 +1837,8 @@ INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `c
(16, 'Logistica', 'logistica', NULL, NULL, 'logistics'), (16, 'Logistica', 'logistica', NULL, NULL, 'logistics'),
(17, 'cmr', 'cmr', NULL, NULL, 'cmr'), (17, 'cmr', 'cmr', NULL, NULL, 'cmr'),
(18, 'dua', 'dua', NULL, NULL, 'dua'), (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`) INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`)
VALUES VALUES

View File

@ -18,7 +18,10 @@
ng-blur="$ctrl.hasFocus = false" ng-blur="$ctrl.hasFocus = false"
tabindex="{{$ctrl.input.tabindex}}" tabindex="{{$ctrl.input.tabindex}}"
accept="{{$ctrl.accept}}"/> accept="{{$ctrl.accept}}"/>
<label class="label" translate>{{$ctrl.label}}</label> <label class="label">
<span translate>{{::$ctrl.label}}</span>
<span translate ng-show="::$ctrl.required">*</span>
</label>
</div> </div>
<div class="underline"></div> <div class="underline"></div>
<div class="selected underline"></div> <div class="selected underline"></div>

View File

@ -122,6 +122,7 @@ ngModule.component('vnInputFile', {
name: '@?', name: '@?',
disabled: '<?', disabled: '<?',
multiple: '<?', multiple: '<?',
required: '@?',
accept: '@?', accept: '@?',
rule: '@?', rule: '@?',
files: '=model', files: '=model',

View File

@ -16,7 +16,7 @@
tabindex="{{$ctrl.input.tabindex}}"/> tabindex="{{$ctrl.input.tabindex}}"/>
<label class="label"> <label class="label">
<span translate>{{::$ctrl.label}}</span> <span translate>{{::$ctrl.label}}</span>
<span translate vn-tooltip="Required" ng-show="::$ctrl.required">*</span> <span translate ng-show="::$ctrl.required">*</span>
</label> </label>
</div> </div>
<div class="underline"></div> <div class="underline"></div>

View File

@ -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;
};
};

View File

@ -1,3 +1,4 @@
module.exports = Self => { module.exports = Self => {
require('../methods/claim-dms/removeFile')(Self); require('../methods/claim-dms/removeFile')(Self);
require('../methods/claim-dms/allowedContentTypes')(Self);
}; };

View File

@ -10,6 +10,11 @@
"table": "claimDms" "table": "claimDms"
} }
}, },
"allowedContentTypes": [
"image/png",
"image/jpeg",
"image/jpg"
],
"properties": { "properties": {
"dmsFk": { "dmsFk": {
"type": "Number", "type": "Number",

View File

@ -45,8 +45,15 @@
label="File" label="File"
model="$ctrl.dms.files" model="$ctrl.dms.files"
on-change="$ctrl.onFileChange(files)" on-change="$ctrl.onFileChange(files)"
accept=".png, .jpg, .jpeg" accept="{{$ctrl.allowedContentTypes}}"
multiple="true"> multiple="true">
<t-right-icons>
<vn-icon vn-none
color-secondary
title="{{$ctrl.contentTypesInfo}}"
icon="info">
</vn-icon>
</t-right-icons>
</vn-input-file> </vn-input-file>
</vn-horizontal> </vn-horizontal>
<vn-vertical> <vn-vertical>

View File

@ -22,8 +22,23 @@ class Controller {
set claim(value) { set claim(value) {
this._claim = value; this._claim = value;
if (value) if (value) {
this.setDefaultParams(); 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() { setDefaultParams() {

View File

@ -22,8 +22,9 @@ describe('Claim', () => {
})); }));
describe('claim() setter', () => { 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, 'setDefaultParams');
spyOn(controller, 'getAllowedContentTypes');
controller._claim = undefined; controller._claim = undefined;
controller.claim = { controller.claim = {
id: 15, id: 15,
@ -33,6 +34,7 @@ describe('Claim', () => {
expect(controller.claim).toBeDefined(); expect(controller.claim).toBeDefined();
expect(controller.setDefaultParams).toHaveBeenCalledWith(); expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
}); });
}); });
@ -62,5 +64,18 @@ describe('Claim', () => {
expect(controller.dms.hasFileAttached).toBeTruthy(); 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');
});
});
}); });
}); });

View File

@ -1 +0,0 @@
FileDescription: Ticket id {{ticketId}} from client {{clientName}} id {{clientId}}

View File

@ -45,7 +45,15 @@
label="File" label="File"
model="$ctrl.dms.files" model="$ctrl.dms.files"
on-change="$ctrl.onFileChange(files)" on-change="$ctrl.onFileChange(files)"
accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> accept="{{$ctrl.allowedContentTypes}}"
multiple="true">
<t-right-icons>
<vn-icon vn-none
color-secondary
title="{{$ctrl.contentTypesInfo}}"
icon="info">
</vn-icon>
</t-right-icons>
</vn-input-file> </vn-input-file>
</vn-horizontal> </vn-horizontal>
<vn-vertical> <vn-vertical>

View File

@ -18,8 +18,23 @@ class Controller {
set claim(value) { set claim(value) {
this._claim = value; this._claim = value;
if (value) if (value) {
this.setDefaultParams(); 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() { setDefaultParams() {

View File

@ -18,8 +18,9 @@ describe('Claim', () => {
})); }));
describe('claim() setter', () => { 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, 'setDefaultParams');
spyOn(controller, 'getAllowedContentTypes');
controller._claim = undefined; controller._claim = undefined;
controller.claim = { controller.claim = {
id: 15, id: 15,
@ -28,6 +29,7 @@ describe('Claim', () => {
expect(controller.setDefaultParams).toHaveBeenCalledWith(); expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.claim).toBeDefined(); expect(controller.claim).toBeDefined();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
}); });
}); });
@ -38,7 +40,7 @@ describe('Claim', () => {
reference: 101, reference: 101,
warehouseFk: 1, warehouseFk: 1,
companyFk: 442, companyFk: 442,
dmsTypeFk: 12, dmsTypeFk: 20,
description: 'Test', description: 'Test',
hasFile: false, hasFile: false,
hasFileAttached: false hasFileAttached: false
@ -51,7 +53,7 @@ describe('Claim', () => {
expect(controller.dms).toBeDefined(); expect(controller.dms).toBeDefined();
expect(controller.dms.reference).toEqual(101); 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(); 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');
});
});
}); });
}); });

View File

@ -1,3 +0,0 @@
Edit file: Editar fichero
File: Fichero
Generate identifier for original file: Generar identificador para archivo original

View File

@ -1,2 +0,0 @@
Type: Tipo
Are you sure you want to continue?: ¿Seguro que quieres continuar?

View File

@ -0,0 +1,2 @@
FileDescription: Ticket id {{ticketId}} from client {{clientName}} id {{clientId}}
ContentTypesInfo: Allowed file types {{allowedContentTypes}}

View File

@ -1,5 +1,8 @@
Upload file: Subir fichero Upload file: Subir fichero
Edit file: Editar fichero
Upload: Subir Upload: Subir
File: Fichero File: Fichero
FileDescription: Reclamación id {{claimId}} del cliente "{{clientName}}" id {{clientId}} FileDescription: Reclamación id {{claimId}} del cliente "{{clientName}}" id {{clientId}}
Generate identifier for original file: Generar identificador para archivo original 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?

View File

@ -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;
};
};

View File

@ -1,3 +1,4 @@
module.exports = Self => { module.exports = Self => {
require('../methods/client-dms/removeFile')(Self); require('../methods/client-dms/removeFile')(Self);
require('../methods/client-dms/allowedContentTypes')(Self);
}; };

View File

@ -46,7 +46,16 @@
label="File" label="File"
model="$ctrl.dms.files" model="$ctrl.dms.files"
on-change="$ctrl.onFileChange(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">
<t-right-icons>
<vn-icon vn-none
color-secondary
title="{{$ctrl.contentTypesInfo}}"
icon="info">
</vn-icon>
</t-right-icons>
</vn-input-file> </vn-input-file>
</vn-horizontal> </vn-horizontal>
<vn-vertical> <vn-vertical>

View File

@ -22,8 +22,23 @@ class Controller {
set client(value) { set client(value) {
this._client = value; this._client = value;
if (value) if (value) {
this.setDefaultParams(); 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() { setDefaultParams() {

View File

@ -18,8 +18,9 @@ describe('Client', () => {
})); }));
describe('client() setter', () => { 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, 'setDefaultParams');
spyOn(controller, 'getAllowedContentTypes');
controller.client = { controller.client = {
id: 15, id: 15,
name: 'Bruce wayne' name: 'Bruce wayne'
@ -27,6 +28,7 @@ describe('Client', () => {
expect(controller.client).toBeDefined(); expect(controller.client).toBeDefined();
expect(controller.setDefaultParams).toHaveBeenCalledWith(); expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
}); });
}); });
@ -56,5 +58,18 @@ describe('Client', () => {
expect(controller.dms.hasFileAttached).toBeTruthy(); 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');
});
});
}); });
}); });

View File

@ -1 +0,0 @@
ClientFileDescription: "{{dmsTypeName}} from client {{clientName}} id {{clientId}}"

View File

@ -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

View File

@ -18,8 +18,23 @@ class Controller {
set client(value) { set client(value) {
this._client = value; this._client = value;
if (value) if (value) {
this.setDefaultParams(); 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() { setDefaultParams() {

View File

@ -1,43 +1,52 @@
import './index'; import './index';
describe('Client', () => { describe('Client', () => {
describe('Component vnClientDmsCreate', () => { describe('Component vnClientDmsEdit', () => {
let controller; let controller;
let $scope; let $scope;
let $httpBackend; let $httpBackend;
let $httpParamSerializer; let $state;
beforeEach(ngModule('client')); beforeEach(ngModule('client'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_; $state = {params: {dmsId: 1}};
controller = $componentController('vnClientDmsCreate', {$scope}); controller = $componentController('vnClientDmsEdit', {$scope, $state});
controller._client = {id: 101, name: 'Bruce wayne'}; controller._client = {id: 1};
})); }));
describe('client() setter', () => { 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, 'setDefaultParams');
spyOn(controller, 'getAllowedContentTypes');
controller._client = undefined;
controller.client = { controller.client = {
id: 15, id: 15
name: 'Bruce wayne'
}; };
expect(controller.client).toBeDefined();
expect(controller.setDefaultParams).toHaveBeenCalledWith(); expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.client).toBeDefined();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
}); });
}); });
describe('setDefaultParams()', () => { describe('setDefaultParams()', () => {
it('should perform a GET query and define the dms property on controller', () => { it('should perform a GET query and define the dms property on controller', () => {
const params = {filter: { const dmsId = 1;
where: {code: 'paymentsLaw'} const expectedResponse = {
}}; reference: 101,
let serializedParams = $httpParamSerializer(params); warehouseFk: 1,
$httpBackend.when('GET', `/api/DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'paymentsLaw'}); companyFk: 442,
$httpBackend.expect('GET', `/api/DmsTypes/findOne?${serializedParams}`); 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(); controller.setDefaultParams();
$httpBackend.flush(); $httpBackend.flush();
@ -50,11 +59,25 @@ describe('Client', () => {
describe('onFileChange()', () => { describe('onFileChange()', () => {
it('should set dms hasFileAttached 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'}]; const files = [{id: 1, name: 'MyFile'}];
controller.dms = {hasFileAttached: false};
controller.onFileChange(files); controller.onFileChange(files);
$scope.$apply(); $scope.$apply();
expect(controller.dms.hasFileAttached).toBeTruthy(); 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');
});
});
}); });
}); });

View File

@ -1,3 +0,0 @@
Edit file: Editar fichero
File: Fichero
Generate identifier for original file: Generar identificador para archivo original

View File

@ -0,0 +1,2 @@
ClientFileDescription: "{{dmsTypeName}} from client {{clientName}} id {{clientId}}"
ContentTypesInfo: Allowed file types {{allowedContentTypes}}

View File

@ -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

View File

@ -1,7 +1,7 @@
import './index.js'; import './index.js';
import crudModel from 'core/mocks/crud-model'; import crudModel from 'core/mocks/crud-model';
fdescribe('Order', () => { describe('Order', () => {
describe('Component vnCatalogFilter', () => { describe('Component vnCatalogFilter', () => {
let $scope; let $scope;
let $state; let $state;

View File

@ -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;
};
};

View File

@ -1,3 +1,4 @@
module.exports = Self => { module.exports = Self => {
require('../methods/ticket-dms/removeFile')(Self); require('../methods/ticket-dms/removeFile')(Self);
require('../methods/ticket-dms/allowedContentTypes')(Self);
}; };

View File

@ -45,7 +45,15 @@
label="File" label="File"
model="$ctrl.dms.files" model="$ctrl.dms.files"
on-change="$ctrl.onFileChange(files)" on-change="$ctrl.onFileChange(files)"
accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> accept="{{$ctrl.allowedContentTypes}}"
multiple="true">
<t-right-icons>
<vn-icon vn-none
color-secondary
title="{{$ctrl.contentTypesInfo}}"
icon="info">
</vn-icon>
</t-right-icons>
</vn-input-file> </vn-input-file>
</vn-horizontal> </vn-horizontal>
<vn-vertical> <vn-vertical>

View File

@ -22,8 +22,23 @@ class Controller {
set ticket(value) { set ticket(value) {
this._ticket = value; this._ticket = value;
if (value) if (value) {
this.setDefaultParams(); 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() { setDefaultParams() {

View File

@ -23,8 +23,9 @@ describe('Ticket', () => {
})); }));
describe('client() setter', () => { 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, 'setDefaultParams');
spyOn(controller, 'getAllowedContentTypes');
controller.ticket = { controller.ticket = {
id: 15, id: 15,
name: 'Bruce wayne' name: 'Bruce wayne'
@ -32,6 +33,7 @@ describe('Ticket', () => {
expect(controller.ticket).toBeDefined(); expect(controller.ticket).toBeDefined();
expect(controller.setDefaultParams).toHaveBeenCalledWith(); expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
}); });
}); });
@ -61,5 +63,18 @@ describe('Ticket', () => {
expect(controller.dms.hasFileAttached).toBeTruthy(); 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');
});
});
}); });
}); });

View File

@ -1 +0,0 @@
FileDescription: Ticket id {{ticketId}} from client {{clientName}} id {{clientId}}

View File

@ -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

View File

@ -45,7 +45,15 @@
label="File" label="File"
model="$ctrl.dms.files" model="$ctrl.dms.files"
on-change="$ctrl.onFileChange(files)" on-change="$ctrl.onFileChange(files)"
accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> accept="{{$ctrl.allowedContentTypes}}"
multiple="true">
<t-right-icons>
<vn-icon vn-none
color-secondary
title="{{$ctrl.contentTypesInfo}}"
icon="info">
</vn-icon>
</t-right-icons>
</vn-input-file> </vn-input-file>
</vn-horizontal> </vn-horizontal>
<vn-vertical> <vn-vertical>

View File

@ -18,8 +18,23 @@ class Controller {
set ticket(value) { set ticket(value) {
this._ticket = value; this._ticket = value;
if (value) if (value) {
this.setDefaultParams(); 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() { setDefaultParams() {

View File

@ -1,60 +1,83 @@
import './index'; import './index';
describe('Client', () => { describe('Ticket', () => {
describe('Component vnClientDmsCreate', () => { describe('Component vnTicketDmsEdit', () => {
let controller; let controller;
let $scope; let $scope;
let $httpBackend; 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(); $scope = $rootScope.$new();
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_; $state = {params: {dmsId: 1}};
controller = $componentController('vnClientDmsCreate', {$scope}); controller = $componentController('vnTicketDmsEdit', {$scope, $state});
controller._client = {id: 101, name: 'Bruce wayne'}; controller._ticket = {id: 1, ticketFk: 16};
})); }));
describe('client() setter', () => { describe('ticket() setter', () => {
it('should set the client data and then call setDefaultParams()', () => { it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => {
spyOn(controller, 'setDefaultParams'); spyOn(controller, 'setDefaultParams');
controller.client = { spyOn(controller, 'getAllowedContentTypes');
id: 15, controller._ticket = undefined;
name: 'Bruce wayne' controller.ticket = {
id: 15
}; };
expect(controller.client).toBeDefined();
expect(controller.setDefaultParams).toHaveBeenCalledWith(); expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.ticket).toBeDefined();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
}); });
}); });
describe('setDefaultParams()', () => { describe('setDefaultParams()', () => {
it('should perform a GET query and define the dms property on controller', () => { it('should perform a GET query and define the dms property on controller', () => {
const params = {filter: { const dmsId = 1;
where: {code: 'paymentsLaw'} const expectedResponse = {
}}; reference: 101,
let serializedParams = $httpParamSerializer(params); warehouseFk: 1,
$httpBackend.when('GET', `/api/DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'paymentsLaw'}); companyFk: 442,
$httpBackend.expect('GET', `/api/DmsTypes/findOne?${serializedParams}`); 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(); controller.setDefaultParams();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.dms).toBeDefined(); expect(controller.dms).toBeDefined();
expect(controller.dms.reference).toEqual(101); expect(controller.dms.reference).toEqual(101);
expect(controller.dms.dmsTypeId).toEqual(12); expect(controller.dms.dmsTypeId).toEqual(14);
}); });
}); });
describe('onFileChange()', () => { describe('onFileChange()', () => {
it('should set dms hasFileAttached 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'}]; const files = [{id: 1, name: 'MyFile'}];
controller.dms = {hasFileAttached: false};
controller.onFileChange(files); controller.onFileChange(files);
$scope.$apply(); $scope.$apply();
expect(controller.dms.hasFileAttached).toBeTruthy(); 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');
});
});
}); });
}); });

View File

@ -1,3 +0,0 @@
Edit file: Editar fichero
File: Fichero
Generate identifier for original file: Generar identificador para archivo original

View File

@ -1,3 +0,0 @@
Type: Tipo
File management: Gestión documental
Are you sure you want to continue?: ¿Seguro que quieres continuar?

View File

@ -0,0 +1,2 @@
FileDescription: Ticket id {{ticketId}} from client {{clientName}} id {{clientId}}
ContentTypesInfo: Allowed file types {{allowedContentTypes}}

View File

@ -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