Cases add/edit should be working now. Along with the hearings in it
This commit is contained in:
69
otis/src/app/cases/case-detail/hearing-dialog.component.ts
Normal file
69
otis/src/app/cases/case-detail/hearing-dialog.component.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import * as moment from 'moment';
|
||||
|
||||
import { CourtStatus } from '../../core/court-status';
|
||||
import { Hearing } from '../../core/hearing';
|
||||
|
||||
@Component({
|
||||
selector: 'app-hearing-dialog',
|
||||
templateUrl: './hearing-dialog.component.html',
|
||||
styleUrls: ['./hearing-dialog.component.css'],
|
||||
})
|
||||
export class HearingDialogComponent implements OnInit {
|
||||
form: FormGroup;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<HearingDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: { hearing: Hearing; courtStatuses: CourtStatus[] },
|
||||
private fb: FormBuilder,
|
||||
) {
|
||||
this.form = this.fb.group({
|
||||
courtNumber: '',
|
||||
itemNumber: '',
|
||||
bench: '',
|
||||
latestStatus: '',
|
||||
proceedings: '',
|
||||
nextHearingDate: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.form.setValue({
|
||||
courtNumber: this.data.hearing.courtNumber,
|
||||
itemNumber: this.data.hearing.itemNumber,
|
||||
bench: this.data.hearing.bench,
|
||||
latestStatus: this.data.hearing.courtStatus ? this.data.hearing.courtStatus.id : '',
|
||||
proceedings: this.data.hearing.proceedings,
|
||||
nextHearingDate: this.data.hearing.nextHearingDate
|
||||
? moment(this.data.hearing.nextHearingDate, 'DD-MMM-YYYY').toDate()
|
||||
: '',
|
||||
});
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
const formValue = this.form.value;
|
||||
this.data.hearing.courtNumber = formValue.courtNumber;
|
||||
this.data.hearing.itemNumber = formValue.itemNumber;
|
||||
this.data.hearing.bench = formValue.bench;
|
||||
|
||||
this.data.hearing.courtStatus =
|
||||
formValue.latestStatus === ''
|
||||
? null
|
||||
: new CourtStatus({
|
||||
id: formValue.latestStatus,
|
||||
name: (this.data.courtStatuses.find(
|
||||
(x) => x.id === formValue.latestStatus,
|
||||
) as CourtStatus).name,
|
||||
});
|
||||
this.data.hearing.proceedings = formValue.proceedings;
|
||||
if (formValue.nextHearingDate === '') {
|
||||
this.data.hearing.nextHearingDate = null;
|
||||
} else {
|
||||
this.data.hearing.nextHearingDate = moment(formValue.nextHearingDate).format('DD-MMM-YYYY');
|
||||
}
|
||||
|
||||
this.dialogRef.close(this.data.hearing);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user