updated clientSample with new reports uri #1001

This commit is contained in:
Joan Sanchez 2019-01-30 08:09:21 +01:00
parent 8d2f56a547
commit c20a08e99b
3 changed files with 55 additions and 34 deletions

View File

@ -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');

View File

@ -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();

View File

@ -5,8 +5,7 @@ vn-client-sample-create {
}
tpl-body {
min-width: 800px;
max-height: 700px;
min-width: 800px
}
}
}