111 lines
3.3 KiB
TypeScript
111 lines
3.3 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
import { MatAnchor, MatIconButton, MatButton } from '@angular/material/button';
|
|
import { MatCard, MatCardHeader, MatCardTitleGroup, MatCardTitle, MatCardContent } from '@angular/material/card';
|
|
import { MatDatepickerInput, MatDatepickerToggle, MatDatepicker } from '@angular/material/datepicker';
|
|
import { MatFormField, MatLabel, MatSuffix } from '@angular/material/form-field';
|
|
import { MatIcon } from '@angular/material/icon';
|
|
import { MatInput } from '@angular/material/input';
|
|
import {
|
|
MatTable,
|
|
MatColumnDef,
|
|
MatHeaderCellDef,
|
|
MatHeaderCell,
|
|
MatCellDef,
|
|
MatCell,
|
|
MatHeaderRowDef,
|
|
MatHeaderRow,
|
|
MatRowDef,
|
|
MatRow,
|
|
} from '@angular/material/table';
|
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
|
import moment from 'moment';
|
|
import { BehaviorSubject } from 'rxjs';
|
|
import { map } from 'rxjs/operators';
|
|
|
|
import { ToasterService } from '../../core/toaster.service';
|
|
import { LocalTimePipe } from '../../shared/local-time.pipe';
|
|
import { GuestBook } from '../guest-book';
|
|
import { GuestBookList } from '../guest-book-list';
|
|
import { GuestBookService } from '../guest-book.service';
|
|
|
|
import { GuestBookListDataSource } from './guest-book-list-datasource';
|
|
|
|
@Component({
|
|
selector: 'app-guest-book-list',
|
|
templateUrl: './guest-book-list.component.html',
|
|
styleUrls: ['./guest-book-list.component.sass'],
|
|
standalone: true,
|
|
imports: [
|
|
MatCard,
|
|
MatCardHeader,
|
|
MatCardTitleGroup,
|
|
MatCardTitle,
|
|
MatAnchor,
|
|
RouterLink,
|
|
MatIcon,
|
|
MatCardContent,
|
|
ReactiveFormsModule,
|
|
MatFormField,
|
|
MatLabel,
|
|
MatInput,
|
|
MatDatepickerInput,
|
|
MatDatepickerToggle,
|
|
MatSuffix,
|
|
MatDatepicker,
|
|
MatTable,
|
|
MatColumnDef,
|
|
MatHeaderCellDef,
|
|
MatHeaderCell,
|
|
MatCellDef,
|
|
MatCell,
|
|
MatIconButton,
|
|
MatButton,
|
|
MatHeaderRowDef,
|
|
MatHeaderRow,
|
|
MatRowDef,
|
|
MatRow,
|
|
LocalTimePipe,
|
|
],
|
|
})
|
|
export class GuestBookListComponent implements OnInit {
|
|
data: BehaviorSubject<GuestBook[]> = new BehaviorSubject<GuestBook[]>([]);
|
|
dataSource: GuestBookListDataSource = new GuestBookListDataSource(this.data);
|
|
form: FormGroup<{
|
|
date: FormControl<Date>;
|
|
}>;
|
|
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns = ['sno', 'name', 'phone', 'pax', 'date', 'action'];
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private toaster: ToasterService,
|
|
private ser: GuestBookService,
|
|
) {
|
|
// Create form
|
|
this.form = new FormGroup({
|
|
date: new FormControl(new Date(), { nonNullable: true }),
|
|
});
|
|
this.listenToDateChange();
|
|
}
|
|
|
|
listenToDateChange(): void {
|
|
this.form.controls.date.valueChanges.pipe(map((x) => moment(x).format('DD-MMM-YYYY'))).subscribe((x) =>
|
|
this.ser.list(x).subscribe((list: GuestBookList) => {
|
|
this.data.next(list.list);
|
|
}),
|
|
);
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((value) => {
|
|
const data = value as { list: GuestBookList };
|
|
this.data.next(data.list.list);
|
|
this.form.setValue({ date: moment(data.list.date, 'DD-MMM-YYYY').toDate() });
|
|
});
|
|
this.dataSource = new GuestBookListDataSource(this.data);
|
|
}
|
|
}
|