Skip to content

Commit

Permalink
delete works without confirmation prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
jessewashburn committed Jan 16, 2025
1 parent 1524337 commit 18c106b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/app/health/health-event-dialog.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h4 class="primary-text-color" *ngIf="hasConditionAndTreatment" i18n>Other Notes
<p *ngIf="event.referrals"><strong class="mat-body-strong" i18n>Referrals: </strong><td-markdown [content]="event.referrals"></td-markdown>
</mat-dialog-content>
<mat-dialog-actions>
<button type="button" mat-raised-button mat-dialog-delete (click)="openDeleteDialog(event)" i18n>Delete</button>
<button type="button" mat-raised-button mat-dialog-delete (click)="deleteExam(event)" i18n>Delete</button>
<button type="button" mat-raised-button mat-dialog-close i18n>Close</button>
<button type="button" color="primary" mat-dialog-close (click)="editExam(event)" *ngIf="canUpdate" mat-raised-button>
<span i18n>Edit</span> <ng-container *ngIf="minutes">({{ minutes }}:{{ seconds }})</ng-container>
Expand Down
40 changes: 5 additions & 35 deletions src/app/health/health-event-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { UsersService } from '../users/users.service';
import { CouchService } from '../shared/couchdb.service';
import { HealthService } from './health.service';
import { UserService } from '../shared/user.service';
import { DialogsPromptComponent } from '../shared/dialogs/dialogs-prompt.component';
import { MatDialog } from '@angular/material/dialog';
import { PlanetMessageService } from '../shared/planet-message.service';

Expand All @@ -19,7 +18,7 @@ export class HealthEventDialogComponent implements OnInit, OnDestroy {

event: any;
hasConditionAndTreatment = false;
@Output() examinationDeleted = new EventEmitter<string>();
@Output() examDeleted = new EventEmitter<void>();
conditionAndTreatmentFields = conditionAndTreatmentFields;
conditions: string;
hasVital = false;
Expand All @@ -29,7 +28,6 @@ export class HealthEventDialogComponent implements OnInit, OnDestroy {
seconds: string;
timeLimit = 300000;
isDestroyed = false;
deleteDialog: any;

constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
Expand Down Expand Up @@ -69,39 +67,11 @@ export class HealthEventDialogComponent implements OnInit, OnDestroy {
this.router.navigate([ 'event', { id: this.data.user, eventId: event._id } ], { relativeTo: this.data.route });
}

openDeleteDialog(event) {
const formattedDate = new Date(event.date).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
second: '2-digit',
hour12: true
deleteExam(event) {
this.healthService.deleteExamination(event._id, event._rev).subscribe(() => {
this.examDeleted.emit(event._id);
this.dialog.closeAll();
});
this.deleteDialog = this.dialog.open(DialogsPromptComponent, {
data: {
okClick: this.deleteExamination(event),
request: 'none',
changeType: 'Cancel',
type: `examination`,
displayName: formattedDate
}
});
}

deleteExamination(event) {
const {_id: eventId, _rev: eventRev} = event;
return {
request: this.healthService.deleteExamination(eventId, eventRev),
onNext: () => {
this.deleteDialog.close();
this.dialog.closeAll();
this.examinationDeleted.emit(eventId);
this.planetMessageService.showMessage($localize`You have deleted this examination`);
},
onError: () => this.planetMessageService.showAlert($localize`There was a problem deleting this resource.`)
};
}

editButtonCountdown() {
Expand Down
24 changes: 19 additions & 5 deletions src/app/health/health.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,29 @@ export class HealthComponent implements OnInit, AfterViewChecked, OnDestroy {
this.healthService.getHealthData(this.userDetail._id, { docId: event._id })
: of([ event ])
).subscribe(([ eventDoc ]) => {
this.dialog.open(HealthEventDialogComponent, {
data: { event: eventDoc, user: this.userDetail._id, route: this.route },
width: '50vw',
maxHeight: '90vh'
});
this.openExamDialog(eventDoc);
});
}
}

openExamDialog(event) {
const dialogRef = this.dialog.open(HealthEventDialogComponent, {
data: { event }
});

dialogRef.componentInstance.examDeleted.subscribe((deletedExamId: string) => {
this.events = this.events.filter(e => e._id !== deletedExamId);
this.setEventData();
});
}

refreshExaminations() {
this.healthService.getExaminations(this.userDetail._id).subscribe(events => {
this.events = events;
this.setEventData();
});
}

setEventData() {
this.eventTable.data = this.events
.sort((a, b) => a.date - b.date)
Expand Down

0 comments on commit 18c106b

Please sign in to comment.