edit-report.component.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. if (report) {
  25. this.description = report.description;
  26. this.itemsDataBase.addRange(report.items);
  27. this.report = report;
  28. } else {
  29. console.log("report is undefined")
  30. }
  31. });
  32. }
  33. save(): void {
  34. const modifiedReport = {
  35. ...this.report,
  36. description: this.description,
  37. items: this.itemsDataBase.data
  38. };
  39. this.reportDataService.save(modifiedReport);
  40. }
  41. }