updated clientSample with new reports uri #1001
This commit is contained in:
parent
8d2f56a547
commit
c20a08e99b
|
@ -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() {
|
showPreview() {
|
||||||
let sampleType = this.$scope.sampleType.selection;
|
let sampleType = this.$scope.sampleType.selection;
|
||||||
let queryParams;
|
let params = {clientFk: this.$stateParams.id};
|
||||||
|
|
||||||
if (!sampleType)
|
if (!sampleType)
|
||||||
return this.vnApp.showError(this.$translate.instant('Choose a sample'));
|
return this.vnApp.showError(this.$translate.instant('Choose a sample'));
|
||||||
|
@ -24,19 +35,20 @@ class Controller {
|
||||||
if (sampleType.hasCompany && !this.clientSample.companyFk)
|
if (sampleType.hasCompany && !this.clientSample.companyFk)
|
||||||
return this.vnApp.showError(this.$translate.instant('Choose a company'));
|
return this.vnApp.showError(this.$translate.instant('Choose a company'));
|
||||||
|
|
||||||
if (sampleType.hasCompany) {
|
if (sampleType.hasCompany)
|
||||||
queryParams = `${sampleType.code}/${this.clientSample.companyFk}/${this.$stateParams.id}/preview`;
|
params.companyFk = this.clientSample.companyFk;
|
||||||
} else {
|
|
||||||
queryParams = `${sampleType.code}/${this.$stateParams.id}/preview`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let query = `/mailer/notification/${queryParams}`;
|
let query = `/api/email/${sampleType.code}?${this.jsonToQuery(params)}`;
|
||||||
this.$http.get(query).then(res => {
|
this.$http.get(query).then(res => {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
let dialog = this.$scope.showPreview.element;
|
let dialog = this.$scope.showPreview.element;
|
||||||
let body = dialog.querySelector('tpl-body');
|
let body = dialog.querySelector('tpl-body');
|
||||||
|
let scroll = dialog.querySelector('div:first-child');
|
||||||
|
|
||||||
body.innerHTML = res.data;
|
body.innerHTML = res.data;
|
||||||
this.$scope.showPreview.show();
|
this.$scope.showPreview.show();
|
||||||
|
|
||||||
|
scroll.scrollTop = 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -50,16 +62,14 @@ class Controller {
|
||||||
|
|
||||||
sendSample() {
|
sendSample() {
|
||||||
let sampleType = this.$scope.sampleType.selection;
|
let sampleType = this.$scope.sampleType.selection;
|
||||||
let queryParams;
|
let params = {clientFk: this.$stateParams.id};
|
||||||
|
|
||||||
if (sampleType.hasCompany) {
|
if (sampleType.hasCompany)
|
||||||
queryParams = `${sampleType.code}/${this.clientSample.companyFk}/${this.$stateParams.id}`;
|
params.companyFk = this.clientSample.companyFk;
|
||||||
} else {
|
|
||||||
queryParams = `${sampleType.code}/${this.$stateParams.id}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
if (res) {
|
||||||
this.vnApp.showSuccess(this.$translate.instant('Notification sent!'));
|
this.vnApp.showSuccess(this.$translate.instant('Notification sent!'));
|
||||||
this.$state.go('client.card.sample.index');
|
this.$state.go('client.card.sample.index');
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import './index';
|
import './index';
|
||||||
|
|
||||||
describe('Client', () => {
|
fdescribe('Client', () => {
|
||||||
describe('Component vnClientSampleCreate', () => {
|
describe('Component vnClientSampleCreate', () => {
|
||||||
let $scope;
|
let $scope;
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
|
@ -38,6 +38,22 @@ describe('Client', () => {
|
||||||
controller = $componentController('vnClientSampleCreate', {$scope, $state});
|
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()', () => {
|
describe('showPreview()', () => {
|
||||||
it(`should perform a query (GET) and open a sample preview`, () => {
|
it(`should perform a query (GET) and open a sample preview`, () => {
|
||||||
spyOn(controller.$scope.showPreview, 'show');
|
spyOn(controller.$scope.showPreview, 'show');
|
||||||
|
@ -48,14 +64,13 @@ describe('Client', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
controller.clientSample = {
|
controller.clientSample = {
|
||||||
clientFk: 101,
|
clientFk: 101
|
||||||
typeFK: 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = {preventDefault: () => {}};
|
let event = {preventDefault: () => {}};
|
||||||
|
|
||||||
$httpBackend.whenGET(`/mailer/notification/MyReport/101/preview`).respond(true);
|
$httpBackend.when('GET', `/api/email/MyReport?clientFk=101`).respond(true);
|
||||||
$httpBackend.expectGET(`/mailer/notification/MyReport/101/preview`);
|
$httpBackend.expect('GET', `/api/email/MyReport?clientFk=101`);
|
||||||
controller.showPreview(event);
|
controller.showPreview(event);
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
@ -72,14 +87,13 @@ describe('Client', () => {
|
||||||
|
|
||||||
controller.clientSample = {
|
controller.clientSample = {
|
||||||
clientFk: 101,
|
clientFk: 101,
|
||||||
companyFk: 442,
|
companyFk: 442
|
||||||
typeFK: 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = {preventDefault: () => {}};
|
let event = {preventDefault: () => {}};
|
||||||
|
|
||||||
$httpBackend.whenGET(`/mailer/notification/MyReport/442/101/preview`).respond(true);
|
$httpBackend.when('GET', `/api/email/MyReport?clientFk=101&companyFk=442`).respond(true);
|
||||||
$httpBackend.expectGET(`/mailer/notification/MyReport/442/101/preview`);
|
$httpBackend.expect('GET', `/api/email/MyReport?clientFk=101&companyFk=442`);
|
||||||
controller.showPreview(event);
|
controller.showPreview(event);
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
@ -106,12 +120,11 @@ describe('Client', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
controller.clientSample = {
|
controller.clientSample = {
|
||||||
clientFk: 101,
|
clientFk: 101
|
||||||
typeFK: 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$httpBackend.whenGET(`/mailer/notification/MyReport/101`).respond(true);
|
$httpBackend.when('POST', `/api/email/MyReport?clientFk=101`).respond(true);
|
||||||
$httpBackend.expectGET(`/mailer/notification/MyReport/101`);
|
$httpBackend.expect('POST', `/api/email/MyReport?clientFk=101`);
|
||||||
controller.sendSample();
|
controller.sendSample();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
@ -128,12 +141,11 @@ describe('Client', () => {
|
||||||
|
|
||||||
controller.clientSample = {
|
controller.clientSample = {
|
||||||
clientFk: 101,
|
clientFk: 101,
|
||||||
companyFk: 442,
|
companyFk: 442
|
||||||
typeFK: 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$httpBackend.whenGET(`/mailer/notification/MyReport/442/101`).respond(true);
|
$httpBackend.when('POST', `/api/email/MyReport?clientFk=101&companyFk=442`).respond(true);
|
||||||
$httpBackend.expectGET(`/mailer/notification/MyReport/442/101`);
|
$httpBackend.expect('POST', `/api/email/MyReport?clientFk=101&companyFk=442`);
|
||||||
controller.sendSample();
|
controller.sendSample();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@ vn-client-sample-create {
|
||||||
}
|
}
|
||||||
|
|
||||||
tpl-body {
|
tpl-body {
|
||||||
min-width: 800px;
|
min-width: 800px
|
||||||
max-height: 700px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue