42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import ngModule from '../module';
|
|
|
|
class Report {
|
|
constructor($httpParamSerializer, vnToken) {
|
|
this.$httpParamSerializer = $httpParamSerializer;
|
|
this.vnToken = vnToken;
|
|
}
|
|
|
|
/**
|
|
* Shows a report in another window, automatically adds the authorization
|
|
* token to params.
|
|
*
|
|
* @param {String} report The report name
|
|
* @param {Object} params The report parameters
|
|
*/
|
|
show(report, params) {
|
|
params = Object.assign({
|
|
authorization: this.vnToken.token
|
|
}, params);
|
|
const serializedParams = this.$httpParamSerializer(params);
|
|
window.open(`api/report/${report}?${serializedParams}`);
|
|
}
|
|
|
|
/**
|
|
* Shows a report in another window, automatically adds the authorization
|
|
* token to params.
|
|
*
|
|
* @param {String} report The report name
|
|
* @param {Object} params The report parameters
|
|
*/
|
|
showCsv(report, params) {
|
|
params = Object.assign({
|
|
authorization: this.vnToken.token
|
|
}, params);
|
|
const serializedParams = this.$httpParamSerializer(params);
|
|
window.open(`api/csv/${report}/download?${serializedParams}`);
|
|
}
|
|
}
|
|
Report.$inject = ['$httpParamSerializer', 'vnToken'];
|
|
|
|
ngModule.service('vnReport', Report);
|