From 27a123f59bc166ded359b0d103503fb048165880 Mon Sep 17 00:00:00 2001 From: audrey Date: Mon, 29 Oct 2018 10:48:01 -0400 Subject: [PATCH] feat(#204): Loading different reports --- src/app/app-routing.ts | 2 +- .../report-configuration.component.ts | 20 ++++++++++++------- .../select-template.component.ts | 12 +++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/app/app-routing.ts b/src/app/app-routing.ts index 5e4906ed..e354c6c7 100644 --- a/src/app/app-routing.ts +++ b/src/app/app-routing.ts @@ -68,7 +68,7 @@ const appRoutes: Routes = [{ path: 'report-configuration', component: SelectTemplateComponent, }, { - path: 'report-edition', + path: 'report-edition/:idReport', component: ReportConfigurationComponent, }, { path: '**', diff --git a/src/app/report-configuration/report-configuration.component.ts b/src/app/report-configuration/report-configuration.component.ts index 26a8654a..5b030e92 100644 --- a/src/app/report-configuration/report-configuration.component.ts +++ b/src/app/report-configuration/report-configuration.component.ts @@ -20,7 +20,7 @@ export class ReportConfigurationComponent implements OnInit { placeholders: PlaceholderGroup[]; constructor( - private dialog: MatDialog, + private activeRoute: ActivatedRoute, private translateService: TranslateService, private reportConfigurationService: ReportTemplateService, private changeDetectorRef: ChangeDetectorRef, @@ -32,17 +32,23 @@ export class ReportConfigurationComponent implements OnInit { this.placeholders = res; }); this.templateIdentifiers = []; - this.fetchTemplateIdentifiers(); - //this.selectedTemplate = new ConfigurationTemplate(); - this.selectedTemplate = this.reportConfigurationService.currentReport; - } + this.fetchRequiredData(); + + this.selectedTemplate = new ConfigurationTemplate(); + } - fetchTemplateIdentifiers(): void { + fetchRequiredData(): void { this.reportConfigurationService.getTemplateList().subscribe(data => { data.forEach((templateIdentifier) => { this.templateIdentifiers.push(templateIdentifier); }); - //this.openDialog(); + + this.activeRoute.params.subscribe(param => { + this.reportConfigurationService.getTemplate(param.idReport).subscribe(data => { + this.selectedTemplate = data; + this.fetchTemplateData(); + }); + }); }); } diff --git a/src/app/report-configuration/select-template/select-template.component.ts b/src/app/report-configuration/select-template/select-template.component.ts index eb5a4dee..c7466f42 100644 --- a/src/app/report-configuration/select-template/select-template.component.ts +++ b/src/app/report-configuration/select-template/select-template.component.ts @@ -40,7 +40,7 @@ export class SelectTemplateComponent implements OnInit, AfterViewInit { this.form = this.formBuilder.group([]); this.isOpenDisabled = true; - this.translateService.get([ + this.translateService.get(['edit']).subscribe(labels => { 'edit' ]).subscribe(labels => { this.labels = labels; @@ -84,14 +84,8 @@ export class SelectTemplateComponent implements OnInit, AfterViewInit { this.saveTemplate(selectedTemplate); } - editReport(id){ - console.log(id); - let configurationToEdit = this.dataSource.filter(function(item){ - return item.id === id; - }); - console.log(configurationToEdit[0]); - this.reportConfigurationService.currentReport = configurationToEdit[0]; - this.router.navigate(['report-edition']); + editReport(report){ + this.router.navigate(['/report-edition', report.id.toString()]); } saveTemplate(selectedTemplate: ConfigurationTemplate): void {