create-report-item.component.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Component } from '@angular/core';
  2. import { MatDialogRef } from '@angular/material';
  3. import { ReportItemService } from './services/reportItem.service';
  4. import { ReportItem, ReportItemType } from './types';
  5. @Component({
  6. selector: 'ps-create-report-item',
  7. templateUrl: './create-report-item.component.html',
  8. styleUrls: ['./create-report-item.component.css']
  9. })
  10. export class CreateReportItemDialogComponent {
  11. item: ReportItem = {
  12. description: '',
  13. amount: 0,
  14. hasReceipt: false,
  15. type: ReportItemType.unselected,
  16. date: new Date(),
  17. };
  18. itemTypeOptions: ReportItemType[] = [
  19. ReportItemType.unselected,
  20. ReportItemType.food,
  21. ReportItemType.officeSupplies,
  22. ReportItemType.training,
  23. ReportItemType.transport,
  24. ReportItemType.travel
  25. ];
  26. errorMessage = '';
  27. constructor(private dialogRef: MatDialogRef<CreateReportItemDialogComponent>,
  28. private reportItemService: ReportItemService) { }
  29. addItem(item: ReportItem) {
  30. this.errorMessage = this.reportItemService.isValid(item);
  31. if (!this.errorMessage) {
  32. this.dialogRef.close(item);
  33. }
  34. }
  35. }