edit-report.component.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Component } from "@angular/core";
  2. import { MatDialog } from "@angular/material";
  3. import { Location } from '@angular/common';
  4. import { ActivatedRoute } from "@angular/router";
  5. import { ReportDataService, Report } from "./services/reportData.service";
  6. import { BaseReportComponent } from "./base-report.component";
  7. @Component({
  8. selector: 'ps-report',
  9. templateUrl: './report.component.html',
  10. styleUrls: ['./report.component.css']
  11. })
  12. export class EditReportComponent extends BaseReportComponent {
  13. title = 'Edit expense report';
  14. private report: Report;
  15. constructor(location: Location,
  16. dialog: MatDialog,
  17. reportDataService: ReportDataService,
  18. route: ActivatedRoute) {
  19. super(location, dialog, reportDataService);
  20. route
  21. .paramMap
  22. .switchMap(params => reportDataService.getReport(+params.get('id')))
  23. .subscribe(report => {
  24. this.description = report.description;
  25. this.itemsDataBase.addRange(report.items);
  26. this.report = report;
  27. });
  28. }
  29. save(): void {
  30. const modifiedReport = {
  31. ...this.report,
  32. description: this.description,
  33. items: this.itemsDataBase.data
  34. };
  35. this.reportDataService.save(modifiedReport);
  36. }
  37. }