#1654 - move download management to content service from core (#1788)

This commit is contained in:
Vito
2017-03-30 01:15:59 -07:00
committed by Mario Romano
parent ca36f02826
commit 0b099eff44
2 changed files with 4 additions and 13 deletions

View File

@@ -530,7 +530,6 @@ describe('AnalyticsReportParametersComponent', () => {
it('Should show a dialog to allowing report export', async(() => {
component.submit(values);
spyOn(component, 'generateDownloadElement').and.stub();
fixture.detectChanges();
let exportButton: HTMLButtonElement = <HTMLButtonElement>element.querySelector('#export-button');
expect(exportButton).toBeDefined();

View File

@@ -29,7 +29,7 @@ import {
} from '@angular/core';
import { FormGroup, FormBuilder, FormControl } from '@angular/forms';
import * as moment from 'moment';
import { AlfrescoTranslationService, LogService } from 'ng2-alfresco-core';
import { AlfrescoTranslationService, LogService, ContentService } from 'ng2-alfresco-core';
import { AnalyticsService } from '../services/analytics.service';
import {
ReportParametersModel,
@@ -106,7 +106,8 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
constructor(private translateService: AlfrescoTranslationService,
private analyticsService: AnalyticsService,
private formBuilder: FormBuilder,
private logService: LogService) {
private logService: LogService,
private contentService: ContentService) {
if (translateService) {
translateService.addTranslationFolder('ng2-activiti-analytics', 'node_modules/ng2-activiti-analytics/src');
}
@@ -357,19 +358,10 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
this.analyticsService.exportReportToCsv(this.reportId, paramQuery).subscribe(
(data: any) => {
let blob: Blob = new Blob([data], { type: 'text/csv' });
let downloadUrl = window.URL.createObjectURL(blob);
this.generateDownloadElement(downloadUrl, paramQuery);
this.contentService.downloadBlob(blob, paramQuery.reportName + '.csv');
});
}
generateDownloadElement(downloadUrl: string, paramQuery: ReportQuery) {
let downloadElement = window.document.createElement('a');
downloadElement.setAttribute('id', 'export-download');
downloadElement.setAttribute('href', downloadUrl);
downloadElement.setAttribute('download', paramQuery.reportName);
downloadElement.click();
}
doSave(paramQuery: ReportQuery) {
this.analyticsService.saveReport(this.reportId, paramQuery).subscribe(() => {
this.saveReportSuccess.emit();