113 lines
3.0 KiB
TypeScript
113 lines
3.0 KiB
TypeScript
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import * as moment from 'moment';
|
|
import { Observable, of } from 'rxjs';
|
|
|
|
import { Case } from '../core/case';
|
|
|
|
import { CauseList } from './cause-list';
|
|
import { CauseListDatasource } from './cause-list-datasource';
|
|
|
|
@Component({
|
|
selector: 'app-cause-list',
|
|
templateUrl: './cause-list.component.html',
|
|
styleUrls: ['./cause-list.component.css'],
|
|
})
|
|
export class CauseListComponent implements OnInit {
|
|
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
|
|
form: FormGroup;
|
|
info: CauseList = new CauseList();
|
|
list: Observable<Case[]> = new Observable<Case[]>();
|
|
dataSource: CauseListDatasource = new CauseListDatasource(this.list);
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns = [
|
|
'officeFileNumber',
|
|
'title',
|
|
'courtCaseNumber',
|
|
'forum',
|
|
'courtAndItemNumber',
|
|
'bench',
|
|
'proceedings',
|
|
'nextHearingDate',
|
|
'appearOnBehalfOf',
|
|
'otherHearingDates',
|
|
'remarks',
|
|
];
|
|
|
|
constructor(private route: ActivatedRoute, private router: Router, private fb: FormBuilder) {
|
|
// Create form
|
|
this.form = this.fb.group({
|
|
startDate: '',
|
|
finishDate: '',
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((value) => {
|
|
const data = value as { info: CauseList };
|
|
|
|
this.info = data.info;
|
|
console.log(this.info.cases);
|
|
this.form.setValue({
|
|
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
|
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate(),
|
|
});
|
|
this.list = of(this.info.cases);
|
|
this.dataSource = new CauseListDatasource(this.list, this.paginator);
|
|
});
|
|
}
|
|
|
|
courtNumber(row: Case): string {
|
|
const [hearing] = row.hearings;
|
|
return hearing.courtNumber;
|
|
}
|
|
|
|
itemNumber(row: Case): string {
|
|
const [hearing] = row.hearings;
|
|
return hearing.itemNumber;
|
|
}
|
|
|
|
bench(row: Case): string {
|
|
const [hearing] = row.hearings;
|
|
return hearing.bench;
|
|
}
|
|
|
|
proceedings(row: Case): string {
|
|
const [hearing] = row.hearings;
|
|
return hearing.proceedings;
|
|
}
|
|
|
|
nextHearingDate(row: Case): string {
|
|
const [hearing] = row.hearings;
|
|
return hearing.nextHearingDate || '';
|
|
}
|
|
|
|
otherHearingDates(row: Case): string {
|
|
return row.hearings
|
|
.map((x) => x.nextHearingDate)
|
|
.filter((x) => !!x)
|
|
.join(', ');
|
|
}
|
|
|
|
show() {
|
|
const info = this.getInfo();
|
|
this.router.navigate(['cause-list'], {
|
|
queryParams: {
|
|
startDate: info.startDate,
|
|
finishDate: info.finishDate,
|
|
},
|
|
});
|
|
}
|
|
|
|
getInfo(): CauseList {
|
|
const formModel = this.form.value;
|
|
|
|
return new CauseList({
|
|
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
|
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
|
|
});
|
|
}
|
|
}
|