diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index 0d10957e7..539d2e8ef 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -206,9 +206,9 @@ describe('claim', () => { return resolve({id: freightPickUpPrice}); })); controller.onUpdateGreugeResponse('accept').then(res => { - console.log('asdas'); + }).catch(error => { - console.log('errorrrr!!'); + }); $httpBackend.flush(); diff --git a/modules/travel/back/methods/travel-thermograph/allowedContentTypes.js b/modules/travel/back/methods/travel-thermograph/allowedContentTypes.js new file mode 100644 index 000000000..2f5183f92 --- /dev/null +++ b/modules/travel/back/methods/travel-thermograph/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/travel/back/models/travel-thermograph.js b/modules/travel/back/models/travel-thermograph.js new file mode 100644 index 000000000..0d70edd7e --- /dev/null +++ b/modules/travel/back/models/travel-thermograph.js @@ -0,0 +1,4 @@ +module.exports = Self => { + require('../methods/travel-thermograph/allowedContentTypes')(Self); +}; + diff --git a/modules/travel/front/thermograph/create/index.html b/modules/travel/front/thermograph/create/index.html index 327c6e629..02ef54264 100644 --- a/modules/travel/front/thermograph/create/index.html +++ b/modules/travel/front/thermograph/create/index.html @@ -59,7 +59,6 @@ vn-one label="File" ng-model="$ctrl.dms.files" - on-change="$ctrl.onFileChange($files)" accept="{{$ctrl.allowedContentTypes}}" multiple="true"> diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index 40a0fafd0..8e10aca0f 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -8,10 +8,7 @@ class Controller { this.$translate = $translate; this.vnApp = vnApp; this.vnConfig = vnConfig; - this.dms = { - hasFileAttached: false, - files: [] - }; + this.dms = {files: []}; } get travel() { @@ -28,8 +25,7 @@ class Controller { } getAllowedContentTypes() { - // Replace with TravelThermographs - this.$http.get('ticketDms/allowedContentTypes').then(res => { + this.$http.get('TravelThermographs/allowedContentTypes').then(res => { const contentTypes = res.data.join(', '); this.allowedContentTypes = contentTypes; }); @@ -83,21 +79,9 @@ class Controller { 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('travel.card.thermograph.index'); - } - }); - } - - onFileChange(files) { - let hasFileAttached = false; - if (files.length > 0) - hasFileAttached = true; - - this.$.$applyAsync(() => { - this.dms.hasFileAttached = hasFileAttached; + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.watcher.updateOriginalData(); + this.$state.go('travel.card.thermograph.index'); }); } } diff --git a/modules/travel/front/thermograph/create/index.spec.js b/modules/travel/front/thermograph/create/index.spec.js index c8b63358f..bf5b8bec5 100644 --- a/modules/travel/front/thermograph/create/index.spec.js +++ b/modules/travel/front/thermograph/create/index.spec.js @@ -1,37 +1,35 @@ import './index'; describe('Ticket', () => { - describe('Component vnTicketDmsCreate', () => { + describe('Component vnTravelThermographCreate', () => { let controller; let $scope; let $httpBackend; let $httpParamSerializer; + const travelId = 3; + const dmsTypeId = 5; - beforeEach(ngModule('ticket')); + beforeEach(ngModule('travel')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTicketDmsCreate', {$scope}); - controller._ticket = { - id: 15, - client: {id: 101, name: 'Bruce wayne'}, - warehouseFk: 1, - companyFk: 1 + controller = $componentController('vnTravelThermographCreate', {$scope}); + controller._travel = { + id: travelId }; })); - describe('client() setter', () => { - it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => { + describe('travel() setter', () => { + it('should set the travel data and then call setDefaultParams() and getAllowedContentTypes()', () => { spyOn(controller, 'setDefaultParams'); spyOn(controller, 'getAllowedContentTypes'); - controller.ticket = { - id: 15, - name: 'Bruce wayne' + controller.travel = { + id: travelId }; - expect(controller.ticket).toBeDefined(); + expect(controller.travel).toBeDefined(); expect(controller.setDefaultParams).toHaveBeenCalledWith(); expect(controller.getAllowedContentTypes).toHaveBeenCalledWith(); }); @@ -40,40 +38,30 @@ describe('Ticket', () => { describe('setDefaultParams()', () => { it('should perform a GET query and define the dms property on controller', () => { const params = {filter: { - where: {code: 'ticket'} + where: {code: 'miscellaneous'} }}; let serializedParams = $httpParamSerializer(params); - $httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 14, code: 'ticket'}); + $httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: dmsTypeId, code: 'miscellaneous'}); $httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`); controller.setDefaultParams(); $httpBackend.flush(); expect(controller.dms).toBeDefined(); - expect(controller.dms.reference).toEqual(15); - 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.onFileChange(files); - $scope.$apply(); - - expect(controller.dms.hasFileAttached).toBeTruthy(); + expect(controller.dms.reference).toEqual(travelId); + expect(controller.dms.dmsTypeId).toEqual(dmsTypeId); }); }); describe('getAllowedContentTypes()', () => { it('should make an HTTP GET request to get the allowed content types', () => { - const expectedResponse = ['image/png', 'image/jpg']; - $httpBackend.when('GET', `ticketDms/allowedContentTypes`).respond(expectedResponse); - $httpBackend.expect('GET', `ticketDms/allowedContentTypes`); + const expectedResponse = ['application/pdf', 'image/png', 'image/jpg']; + $httpBackend.when('GET', `TravelThermographs/allowedContentTypes`).respond(expectedResponse); + $httpBackend.expect('GET', `TravelThermographs/allowedContentTypes`); controller.getAllowedContentTypes(); $httpBackend.flush(); expect(controller.allowedContentTypes).toBeDefined(); - expect(controller.allowedContentTypes).toEqual('image/png, image/jpg'); + expect(controller.allowedContentTypes).toEqual('application/pdf, image/png, image/jpg'); }); }); });