75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
import { debounceTime, distinctUntilChanged, startWith, switchMap, tap } from 'rxjs/operators';
|
|
|
|
import { Case } from '../../core/case';
|
|
import { CaseSource } from '../../core/case-source';
|
|
import { CaseService } from '../case.service';
|
|
|
|
import { CaseListDataSource } from './case-list-datasource';
|
|
|
|
@Component({
|
|
selector: 'app-case-list',
|
|
templateUrl: './case-list.component.html',
|
|
styleUrls: ['./case-list.component.css'],
|
|
})
|
|
export class CaseListComponent implements OnInit {
|
|
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
|
|
form: FormGroup;
|
|
caseSources: CaseSource[] = [];
|
|
list: Observable<Case[]> = new Observable<Case[]>();
|
|
search: Observable<string>;
|
|
dataSource: CaseListDataSource;
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns = [
|
|
'officeFileNumber',
|
|
'title',
|
|
'courtCaseNumber',
|
|
'court',
|
|
'appearOnBehalfOf',
|
|
'nextHearingDate',
|
|
'courtStatus',
|
|
'remarks',
|
|
'receiptDate',
|
|
];
|
|
|
|
constructor(private route: ActivatedRoute, private fb: FormBuilder, private ser: CaseService) {
|
|
// Create form
|
|
this.form = this.fb.group({
|
|
caseSource: '',
|
|
search: '',
|
|
});
|
|
this.search = (this.form.get('search') as FormControl).valueChanges.pipe(
|
|
startWith(''),
|
|
debounceTime(150),
|
|
distinctUntilChanged(),
|
|
);
|
|
this.dataSource = new CaseListDataSource(this.list, this.search);
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((value) => {
|
|
const data = value as { caseSources: CaseSource[] };
|
|
this.caseSources = data.caseSources;
|
|
this.form.setValue({
|
|
caseSource: '08efc7cc-e4a1-4d24-bcba-58ca9bc29994',
|
|
search: '',
|
|
});
|
|
this.list = (this.form.get('caseSource') as FormControl).valueChanges.pipe(
|
|
startWith('08efc7cc-e4a1-4d24-bcba-58ca9bc29994'),
|
|
distinctUntilChanged(),
|
|
switchMap((x) => this.ser.list(x)),
|
|
);
|
|
});
|
|
this.dataSource = new CaseListDataSource(this.list, this.search, this.paginator);
|
|
}
|
|
|
|
nextHearingDate(row: Case): string {
|
|
const date = row.hearings.map((x) => x.nextHearingDate).find((x) => !!x);
|
|
return date ? date : '';
|
|
}
|
|
}
|