From c20a08e99b32fcd5a1e9b611bf07f8a4711d9f73 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 30 Jan 2019 08:09:21 +0100 Subject: [PATCH] updated clientSample with new reports uri #1001 --- modules/client/front/sample/create/index.js | 40 ++++++++++------ .../client/front/sample/create/index.spec.js | 46 ++++++++++++------- modules/client/front/sample/create/style.scss | 3 +- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index fe3355a64f..d620164a91 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -14,9 +14,20 @@ class Controller { }; } + jsonToQuery(json) { + let query = ''; + for (let param in json) { + if (query != '') + query += '&'; + query += `${param}=${json[param]}`; + } + + return query; + } + showPreview() { let sampleType = this.$scope.sampleType.selection; - let queryParams; + let params = {clientFk: this.$stateParams.id}; if (!sampleType) return this.vnApp.showError(this.$translate.instant('Choose a sample')); @@ -24,19 +35,20 @@ class Controller { if (sampleType.hasCompany && !this.clientSample.companyFk) return this.vnApp.showError(this.$translate.instant('Choose a company')); - if (sampleType.hasCompany) { - queryParams = `${sampleType.code}/${this.clientSample.companyFk}/${this.$stateParams.id}/preview`; - } else { - queryParams = `${sampleType.code}/${this.$stateParams.id}/preview`; - } + if (sampleType.hasCompany) + params.companyFk = this.clientSample.companyFk; - let query = `/mailer/notification/${queryParams}`; + let query = `/api/email/${sampleType.code}?${this.jsonToQuery(params)}`; this.$http.get(query).then(res => { if (res.data) { let dialog = this.$scope.showPreview.element; let body = dialog.querySelector('tpl-body'); + let scroll = dialog.querySelector('div:first-child'); + body.innerHTML = res.data; this.$scope.showPreview.show(); + + scroll.scrollTop = 0; } }); } @@ -50,16 +62,14 @@ class Controller { sendSample() { let sampleType = this.$scope.sampleType.selection; - let queryParams; + let params = {clientFk: this.$stateParams.id}; - if (sampleType.hasCompany) { - queryParams = `${sampleType.code}/${this.clientSample.companyFk}/${this.$stateParams.id}`; - } else { - queryParams = `${sampleType.code}/${this.$stateParams.id}`; - } + if (sampleType.hasCompany) + params.companyFk = this.clientSample.companyFk; - let query = `/mailer/notification/${queryParams}`; - this.$http.get(query).then(res => { + + let query = `/api/email/${sampleType.code}?${this.jsonToQuery(params)}`; + this.$http.post(query).then(res => { if (res) { this.vnApp.showSuccess(this.$translate.instant('Notification sent!')); this.$state.go('client.card.sample.index'); diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index dfc660f351..adb7b1a45b 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -1,6 +1,6 @@ import './index'; -describe('Client', () => { +fdescribe('Client', () => { describe('Component vnClientSampleCreate', () => { let $scope; let $httpBackend; @@ -38,6 +38,22 @@ describe('Client', () => { controller = $componentController('vnClientSampleCreate', {$scope, $state}); })); + describe('jsonToQuery()', () => { + it(`should convert a JSON object with clientFk property to query params`, () => { + let myObject = {clientFk: 101}; + let result = controller.jsonToQuery(myObject); + + expect(result).toEqual('clientFk=101'); + }); + + it(`should convert a JSON object with clientFk and companyFk properties to query params`, () => { + let myObject = {clientFk: 101, companyFk: 442}; + let result = controller.jsonToQuery(myObject); + + expect(result).toEqual('clientFk=101&companyFk=442'); + }); + }); + describe('showPreview()', () => { it(`should perform a query (GET) and open a sample preview`, () => { spyOn(controller.$scope.showPreview, 'show'); @@ -48,14 +64,13 @@ describe('Client', () => { }; controller.clientSample = { - clientFk: 101, - typeFK: 1 + clientFk: 101 }; let event = {preventDefault: () => {}}; - $httpBackend.whenGET(`/mailer/notification/MyReport/101/preview`).respond(true); - $httpBackend.expectGET(`/mailer/notification/MyReport/101/preview`); + $httpBackend.when('GET', `/api/email/MyReport?clientFk=101`).respond(true); + $httpBackend.expect('GET', `/api/email/MyReport?clientFk=101`); controller.showPreview(event); $httpBackend.flush(); @@ -72,14 +87,13 @@ describe('Client', () => { controller.clientSample = { clientFk: 101, - companyFk: 442, - typeFK: 1 + companyFk: 442 }; let event = {preventDefault: () => {}}; - $httpBackend.whenGET(`/mailer/notification/MyReport/442/101/preview`).respond(true); - $httpBackend.expectGET(`/mailer/notification/MyReport/442/101/preview`); + $httpBackend.when('GET', `/api/email/MyReport?clientFk=101&companyFk=442`).respond(true); + $httpBackend.expect('GET', `/api/email/MyReport?clientFk=101&companyFk=442`); controller.showPreview(event); $httpBackend.flush(); @@ -106,12 +120,11 @@ describe('Client', () => { }; controller.clientSample = { - clientFk: 101, - typeFK: 1 + clientFk: 101 }; - $httpBackend.whenGET(`/mailer/notification/MyReport/101`).respond(true); - $httpBackend.expectGET(`/mailer/notification/MyReport/101`); + $httpBackend.when('POST', `/api/email/MyReport?clientFk=101`).respond(true); + $httpBackend.expect('POST', `/api/email/MyReport?clientFk=101`); controller.sendSample(); $httpBackend.flush(); @@ -128,12 +141,11 @@ describe('Client', () => { controller.clientSample = { clientFk: 101, - companyFk: 442, - typeFK: 1 + companyFk: 442 }; - $httpBackend.whenGET(`/mailer/notification/MyReport/442/101`).respond(true); - $httpBackend.expectGET(`/mailer/notification/MyReport/442/101`); + $httpBackend.when('POST', `/api/email/MyReport?clientFk=101&companyFk=442`).respond(true); + $httpBackend.expect('POST', `/api/email/MyReport?clientFk=101&companyFk=442`); controller.sendSample(); $httpBackend.flush(); diff --git a/modules/client/front/sample/create/style.scss b/modules/client/front/sample/create/style.scss index 72e588db50..eecc8ad096 100644 --- a/modules/client/front/sample/create/style.scss +++ b/modules/client/front/sample/create/style.scss @@ -5,8 +5,7 @@ vn-client-sample-create { } tpl-body { - min-width: 800px; - max-height: 700px; + min-width: 800px } } } \ No newline at end of file