Blacked and isorted the python files
Prettied and eslinted the typescript/html files
This commit is contained in:
@ -1,18 +1,17 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {GuestBookService} from './guest-book.service';
|
||||
import {GuestBook} from './guest-book';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { GuestBook } from './guest-book';
|
||||
import { GuestBookService } from './guest-book.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class GuestBookDetailResolver implements Resolve<GuestBook> {
|
||||
constructor(private ser: GuestBookService) {}
|
||||
|
||||
constructor(private ser: GuestBookService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<GuestBook> {
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<GuestBook> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
|
||||
@ -5,39 +5,64 @@
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput #name placeholder="Name" formControlName="name">
|
||||
<input matInput #name placeholder="Name" formControlName="name" />
|
||||
<mat-error *ngIf="form.controls['name'].hasError('required')">
|
||||
Name is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Phone</mat-label>
|
||||
<input matInput #phone placeholder="Phone" type="text" formControlName="phone">
|
||||
<input matInput #phone placeholder="Phone" type="text" formControlName="phone" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Pax</mat-label>
|
||||
<input matInput placeholder="Pax" type="number" formControlName="pax">
|
||||
<input matInput placeholder="Pax" type="number" formControlName="pax" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Company</mat-label>
|
||||
<input matInput placeholder="Company" formControlName="company">
|
||||
<input matInput placeholder="Company" formControlName="company" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Address</mat-label>
|
||||
<textarea matInput placeholder="Address" formControlName="address"></textarea>
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { GuestBookService } from '../guest-book.service';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { GuestBook } from '../guest-book';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { GuestBookService } from '../guest-book.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-guest-book-detail',
|
||||
templateUrl: './guest-book-detail.component.html',
|
||||
styleUrls: ['./guest-book-detail.component.css']
|
||||
styleUrls: ['./guest-book-detail.component.css'],
|
||||
})
|
||||
export class GuestBookDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('name', { static: true }) nameElement: ElementRef;
|
||||
@ -20,7 +21,7 @@ export class GuestBookDetailComponent implements OnInit, AfterViewInit {
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private toaster: ToasterService,
|
||||
private ser: GuestBookService
|
||||
private ser: GuestBookService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
@ -31,15 +32,14 @@ export class GuestBookDetailComponent implements OnInit, AfterViewInit {
|
||||
name: [null, Validators.required],
|
||||
phone: [null, Validators.required],
|
||||
pax: ['0', Validators.required],
|
||||
address: null
|
||||
address: null,
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: GuestBook }) => {
|
||||
this.showItem(data.item);
|
||||
});
|
||||
this.route.data.subscribe((data: { item: GuestBook }) => {
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
@ -50,26 +50,25 @@ export class GuestBookDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
showItem(item: GuestBook) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
company: item.company,
|
||||
name: item.name,
|
||||
phone: item.phone,
|
||||
pax: '' + item.pax,
|
||||
address: item.address
|
||||
this.form.setValue({
|
||||
company: item.company,
|
||||
name: item.name,
|
||||
phone: item.phone,
|
||||
pax: `${item.pax}`,
|
||||
address: item.address,
|
||||
});
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/guest-book');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/guest-book');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
getItem(): GuestBook {
|
||||
|
||||
@ -1,18 +1,17 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
|
||||
import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { GuestBookList } from './guest-book';
|
||||
|
||||
import { GuestBookList } from './guest-book-list';
|
||||
import { GuestBookService } from './guest-book.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class GuestBookListResolver implements Resolve<GuestBookList> {
|
||||
constructor(private ser: GuestBookService) {}
|
||||
|
||||
constructor(private ser: GuestBookService) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<GuestBookList> {
|
||||
resolve(): Observable<GuestBookList> {
|
||||
return this.ser.list(null);
|
||||
}
|
||||
}
|
||||
|
||||
6
bookie/src/app/guest-book/guest-book-list.ts
Normal file
6
bookie/src/app/guest-book/guest-book-list.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { GuestBook } from './guest-book';
|
||||
|
||||
export class GuestBookList {
|
||||
date: string;
|
||||
list: GuestBook[];
|
||||
}
|
||||
@ -1,11 +1,10 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { GuestBook } from '../guest-book';
|
||||
|
||||
export class GuestBookListDataSource extends DataSource<GuestBook> {
|
||||
|
||||
constructor(private readonly dataObs: Observable<GuestBook[]>
|
||||
) {
|
||||
constructor(private readonly dataObs: Observable<GuestBook[]>) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -17,6 +16,5 @@ export class GuestBookListDataSource extends DataSource<GuestBook> {
|
||||
* Called when the table is being destroyed. Use this function, to clean up
|
||||
* any open connections or free any held resources that were set up during connect.
|
||||
*/
|
||||
disconnect() {
|
||||
}
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
@ -8,52 +8,63 @@
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-form-field fxFlex>
|
||||
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date"
|
||||
autocomplete="off">
|
||||
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
|
||||
<mat-datepicker #date></mat-datepicker>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<input
|
||||
matInput
|
||||
[matDatepicker]="date"
|
||||
(focus)="date.open()"
|
||||
placeholder="Date"
|
||||
formControlName="date"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
|
||||
<mat-datepicker #date></mat-datepicker>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
<mat-table [dataSource]="dataSource" aria-label="Elements">
|
||||
<!-- SNo Column -->
|
||||
<ng-container matColumnDef="sno">
|
||||
<mat-header-cell *matHeaderCellDef>S. No</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.serial}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.serial }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.name}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.name }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Phone Column -->
|
||||
<ng-container matColumnDef="phone">
|
||||
<mat-header-cell *matHeaderCellDef>Phone</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.phone}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.phone }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Pax Column -->
|
||||
<ng-container matColumnDef="pax">
|
||||
<mat-header-cell *matHeaderCellDef>Pax</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.pax}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.pax }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Time Column -->
|
||||
<ng-container matColumnDef="date">
|
||||
<mat-header-cell *matHeaderCellDef>Time</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.date | localTime}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.date | localTime }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Action Column -->
|
||||
<ng-container matColumnDef="action">
|
||||
<mat-header-cell *matHeaderCellDef class="center">Action</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="center">
|
||||
<button mat-icon-button [routerLink]="['/sales']" [queryParams]="{guest: row.id}">
|
||||
<button mat-icon-button [routerLink]="['/sales']" [queryParams]="{ guest: row.id }">
|
||||
Seat
|
||||
</button>
|
||||
<button mat-icon-button [routerLink]="['/guest-book/', row.id]">
|
||||
@ -66,7 +77,7 @@
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
</mat-table>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@ -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 {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
import { GuestBookListComponent } from './guest-book-list/guest-book-list.component';
|
||||
import { GuestBookDetailComponent } from './guest-book-detail/guest-book-detail.component';
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
import { GuestBookListResolver } from './guest-book-list-resolver.service';
|
||||
|
||||
import { GuestBookDetailResolver } from './guest-book-detail-resolver.service';
|
||||
import { GuestBookDetailComponent } from './guest-book-detail/guest-book-detail.component';
|
||||
import { GuestBookListResolver } from './guest-book-list-resolver.service';
|
||||
import { GuestBookListComponent } from './guest-book-list/guest-book-list.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
@ -12,44 +14,41 @@ const routes: Routes = [
|
||||
component: GuestBookListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Guest Book'
|
||||
permission: 'Guest Book',
|
||||
},
|
||||
resolve: {
|
||||
list: GuestBookListResolver
|
||||
list: GuestBookListResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always'
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: GuestBookDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Guest Book'
|
||||
permission: 'Guest Book',
|
||||
},
|
||||
resolve: {
|
||||
item: GuestBookDetailResolver
|
||||
}
|
||||
item: GuestBookDetailResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: GuestBookDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Guest Book'
|
||||
permission: 'Guest Book',
|
||||
},
|
||||
resolve: {
|
||||
item: GuestBookDetailResolver
|
||||
}
|
||||
}
|
||||
item: GuestBookDetailResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
providers: [
|
||||
GuestBookListResolver,
|
||||
GuestBookDetailResolver
|
||||
]
|
||||
providers: [GuestBookListResolver, GuestBookDetailResolver],
|
||||
})
|
||||
export class GuestBookRoutingModule { }
|
||||
export class GuestBookRoutingModule {}
|
||||
|
||||
@ -1,21 +1,28 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { MomentDateAdapter } from '@angular/material-moment-adapter';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatNativeDateModule, MAT_DATE_FORMATS, MAT_DATE_LOCALE, DateAdapter } from '@angular/material/core';
|
||||
import {
|
||||
MatNativeDateModule,
|
||||
MAT_DATE_FORMATS,
|
||||
MAT_DATE_LOCALE,
|
||||
DateAdapter,
|
||||
} from '@angular/material/core';
|
||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MomentDateAdapter } from '@angular/material-moment-adapter';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
|
||||
import { GuestBookDetailComponent } from './guest-book-detail/guest-book-detail.component';
|
||||
import { GuestBookListComponent } from './guest-book-list/guest-book-list.component';
|
||||
import { GuestBookRoutingModule } from './guest-book-routing.module';
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
|
||||
export const MY_FORMATS = {
|
||||
parse: {
|
||||
@ -45,11 +52,11 @@ export const MY_FORMATS = {
|
||||
ReactiveFormsModule,
|
||||
FlexLayoutModule,
|
||||
GuestBookRoutingModule,
|
||||
SharedModule
|
||||
SharedModule,
|
||||
],
|
||||
providers: [
|
||||
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
|
||||
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
|
||||
],
|
||||
providers: [
|
||||
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
|
||||
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
|
||||
]
|
||||
})
|
||||
export class GuestBookModule { }
|
||||
export class GuestBookModule {}
|
||||
|
||||
@ -1,65 +1,70 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { GuestBook, GuestBookList } from './guest-book';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
import { GuestBook } from './guest-book';
|
||||
import { GuestBookList } from './guest-book-list';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
|
||||
const url = '/api/guest-book';
|
||||
const serviceName = 'GuestBookService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class GuestBookService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<GuestBook> {
|
||||
const getUrl: string = (id === null) ? url : `${url}/${id}`;
|
||||
return <Observable<GuestBook>>this.http.get<GuestBook>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return <Observable<GuestBook>>(
|
||||
this.http
|
||||
.get<GuestBook>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
);
|
||||
}
|
||||
|
||||
list(date: string): Observable<GuestBookList> {
|
||||
const options = {params: new HttpParams().set('q', (date === null) ? '' : date)};
|
||||
return <Observable<GuestBookList>>this.http.get<GuestBookList>(`${url}/list`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
const options = { params: new HttpParams().set('q', date === null ? '' : date) };
|
||||
return <Observable<GuestBookList>>(
|
||||
this.http
|
||||
.get<GuestBookList>(`${url}/list`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
}
|
||||
|
||||
save(guestBook: GuestBook): Observable<GuestBook> {
|
||||
return <Observable<GuestBook>>this.http.post<GuestBook>(url, guestBook, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
return <Observable<GuestBook>>(
|
||||
this.http
|
||||
.post<GuestBook>(url, guestBook, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
|
||||
update(guestBook: GuestBook): Observable<GuestBook> {
|
||||
return <Observable<GuestBook>>this.http.put<GuestBook>(`${url}/${guestBook.id}`, guestBook, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
return <Observable<GuestBook>>(
|
||||
this.http
|
||||
.put<GuestBook>(`${url}/${guestBook.id}`, guestBook, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update')))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(guestBook: GuestBook): Observable<GuestBook> {
|
||||
if (!guestBook.id) {
|
||||
return this.save(guestBook);
|
||||
} else {
|
||||
return this.update(guestBook);
|
||||
}
|
||||
return this.update(guestBook);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<GuestBook> {
|
||||
return <Observable<GuestBook>>this.http.delete<GuestBook>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
return <Observable<GuestBook>>(
|
||||
this.http
|
||||
.delete<GuestBook>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,8 +12,3 @@ export class GuestBook {
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
export class GuestBookList {
|
||||
date: string;
|
||||
list: GuestBook[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user