|
| 1 | +import { Component, Inject } from '@angular/core'; |
| 2 | +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
| 3 | +import { EvidenceEntry, EvidenceStore } from '../../model/evidence-store'; |
| 4 | +import { TeamGroups } from '../../model/types'; |
| 5 | + |
| 6 | +export interface AddEvidenceModalData { |
| 7 | + activityUuid: string; |
| 8 | + allTeams: string[]; |
| 9 | + teamGroups: TeamGroups; |
| 10 | +} |
| 11 | + |
| 12 | +@Component({ |
| 13 | + selector: 'app-add-evidence-modal', |
| 14 | + templateUrl: './add-evidence-modal.component.html', |
| 15 | + styleUrls: ['./add-evidence-modal.component.css'], |
| 16 | +}) |
| 17 | +export class AddEvidenceModalComponent { |
| 18 | + activityUuid: string; |
| 19 | + allTeams: string[]; |
| 20 | + teamGroups: TeamGroups; |
| 21 | + |
| 22 | + // Form fields |
| 23 | + selectedTeams: string[] = []; |
| 24 | + title: string = ''; |
| 25 | + description: string = ''; |
| 26 | + progress: string = ''; |
| 27 | + evidenceRecorded: string = EvidenceStore.todayDateString(); |
| 28 | + reviewer: string = ''; |
| 29 | + attachments: { type: string; externalLink: string }[] = []; |
| 30 | + |
| 31 | + // Validation |
| 32 | + teamsError: boolean = false; |
| 33 | + titleError: boolean = false; |
| 34 | + |
| 35 | + attachmentTypes: string[] = ['document', 'image', 'link']; |
| 36 | + |
| 37 | + constructor( |
| 38 | + public dialogRef: MatDialogRef<AddEvidenceModalComponent>, |
| 39 | + @Inject(MAT_DIALOG_DATA) public data: AddEvidenceModalData |
| 40 | + ) { |
| 41 | + this.activityUuid = data.activityUuid; |
| 42 | + this.allTeams = data.allTeams; |
| 43 | + this.teamGroups = data.teamGroups || {}; |
| 44 | + } |
| 45 | + |
| 46 | + onSelectedTeamsChange(teams: string[]): void { |
| 47 | + this.selectedTeams = teams; |
| 48 | + this.teamsError = this.selectedTeams.length === 0; |
| 49 | + } |
| 50 | + |
| 51 | + addAttachment(): void { |
| 52 | + this.attachments.push({ type: 'link', externalLink: '' }); |
| 53 | + } |
| 54 | + |
| 55 | + removeAttachment(index: number): void { |
| 56 | + this.attachments.splice(index, 1); |
| 57 | + } |
| 58 | + |
| 59 | + onSave(): void { |
| 60 | + this.teamsError = this.selectedTeams.length === 0; |
| 61 | + this.titleError = !this.title.trim(); |
| 62 | + |
| 63 | + if (this.teamsError || this.titleError) { |
| 64 | + return; |
| 65 | + } |
| 66 | + |
| 67 | + // Filter out empty attachments |
| 68 | + const validAttachments = this.attachments.filter(a => a.externalLink.trim()); |
| 69 | + |
| 70 | + const entry: EvidenceEntry = { |
| 71 | + id: EvidenceStore.generateId(), |
| 72 | + teams: [...this.selectedTeams], |
| 73 | + title: this.title.trim(), |
| 74 | + description: this.description.trim(), |
| 75 | + evidenceRecorded: this.evidenceRecorded, |
| 76 | + reviewer: this.reviewer.trim() || undefined, |
| 77 | + attachment: validAttachments.length > 0 ? validAttachments : undefined, |
| 78 | + }; |
| 79 | + |
| 80 | + this.dialogRef.close({ activityUuid: this.activityUuid, entry }); |
| 81 | + } |
| 82 | + |
| 83 | + onCancel(): void { |
| 84 | + this.dialogRef.close(null); |
| 85 | + } |
| 86 | +} |
0 commit comments