Blacked and isorted the python files
Prettied and eslinted the typescript/html files
This commit is contained in:
@ -1,20 +1,23 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import * as moment from 'moment';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { GuestBook, GuestBookList } from '../guest-book';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
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.css']
|
||||
styleUrls: ['./guest-book-list.component.css'],
|
||||
})
|
||||
export class GuestBookListComponent implements OnInit {
|
||||
dataSource: GuestBookListDataSource;
|
||||
@ -29,7 +32,7 @@ export class GuestBookListComponent implements OnInit {
|
||||
private fb: FormBuilder,
|
||||
private dialog: MatDialog,
|
||||
private toaster: ToasterService,
|
||||
private ser: GuestBookService
|
||||
private ser: GuestBookService,
|
||||
) {
|
||||
this.createForm();
|
||||
this.data = new BehaviorSubject([]);
|
||||
@ -38,47 +41,45 @@ export class GuestBookListComponent implements OnInit {
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
date: ''
|
||||
date: '',
|
||||
});
|
||||
}
|
||||
|
||||
listenToDateChange(): void {
|
||||
this.form.get('date').valueChanges.pipe(
|
||||
map(x => moment(x).format('DD-MMM-YYYY'))
|
||||
).subscribe(x => {
|
||||
return this.ser.list(x)
|
||||
.subscribe((list: GuestBookList) => {
|
||||
this.form
|
||||
.get('date')
|
||||
.valueChanges.pipe(map((x) => moment(x).format('DD-MMM-YYYY')))
|
||||
.subscribe((x) => {
|
||||
return this.ser.list(x).subscribe((list: GuestBookList) => {
|
||||
this.data.next(list.list);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: GuestBookList }) => {
|
||||
this.data.next(data.list.list);
|
||||
this.form.setValue({'date': moment(data.list.date, 'DD-MMM-YYYY').toDate()});
|
||||
});
|
||||
this.route.data.subscribe((data: { 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);
|
||||
}
|
||||
|
||||
delete(id: string) {
|
||||
this.ser.delete(id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/guest-book');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.delete(id).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/guest-book');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(id: string): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Guest Book Entry?', content: 'Are you sure? This cannot be undone.'}
|
||||
data: { title: 'Delete Guest Book Entry?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
@ -87,6 +88,4 @@ export class GuestBookListComponent implements OnInit {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user