Still in progress

This commit is contained in:
Amritanshu
2019-06-17 13:23:00 +05:30
parent 32500665b5
commit 63f5f60842
26 changed files with 520 additions and 432 deletions

View File

@ -5,6 +5,10 @@ import {LogoutComponent} from "./auth/logout/logout.component";
import {HomeComponent} from "./home/home.component";
const routes: Routes = [
{
path: 'bills',
loadChildren: () => import('./bills/bills.module').then(mod => mod.BillsModule)
},
{
path: 'guest-book',
loadChildren: () => import('./guest-book/guest-book.module').then(mod => mod.GuestBookModule)

View File

@ -1,6 +1,7 @@
export class Table {
id: string;
name: string;
location: string;
seats: number;
section: string;
isActive: boolean;
}

View File

@ -1,27 +0,0 @@
.full-width {
width: 100%;
}
.shipping-card {
min-width: 120px;
margin: 20px auto;
}
.mat-radio-button {
display: block;
margin: 5px 0;
}
.row {
display: flex;
flex-direction: row;
}
.col {
flex: 1;
margin-right: 20px;
}
.col:last-child {
margin-right: 0;
}

View File

@ -1,51 +1,52 @@
<form [formGroup]="form" novalidate (ngSubmit)="onSubmit()">
<mat-card class="shipping-card">
<mat-card-header>
<mat-card-title>Shipping Information</mat-card-title>
</mat-card-header>
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
<mat-card fxFlex>
<mat-card-title-group>
<mat-card-title>Guest Details</mat-card-title>
</mat-card-title-group>
<mat-card-content>
<div class="row">
<div class="col">
<mat-form-field class="full-width">
<input matInput placeholder="Company" formControlName="company">
</mat-form-field>
</div>
</div>
<div class="row">
<div class="col">
<mat-form-field class="full-width">
<input matInput placeholder="Name" formControlName="name">
<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>
<mat-label>Name</mat-label>
<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>
<div class="row">
<div class="col">
<mat-form-field class="full-width">
<textarea matInput placeholder="Address" formControlName="address"></textarea>
<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">
</mat-form-field>
</div>
</div>
<div class="row">
<div class="col">
<mat-form-field class="full-width">
<input matInput #phone placeholder="Phone" type="number" formControlName="phone">
<mat-hint align="end">{{phone.value.length}} / 10</mat-hint>
</mat-form-field>
</div>
</div>
<div class="row">
<div class="col">
<mat-form-field class="full-width">
<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">
</mat-form-field>
</div>
</div>
<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">
</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>
<mat-label>Address</mat-label>
<textarea matInput placeholder="Address" formControlName="address"></textarea>
</mat-form-field>
</div>
</form>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" type="submit">Submit</button>
<button mat-raised-button color="primary" (click)="save()">Save</button>
</mat-card-actions>
</mat-card>
</form>
</div>

View File

@ -1,19 +1,17 @@
import {Component, OnInit} from '@angular/core';
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
import {RoleService} from "../../role/role.service";
import {GuestBookService} from "../guest-book.service";
import {ToasterService} from "../../core/toaster.service";
import {Role} from "../../role/role";
import {GuestBook} from "../guest-book";
import {ActivatedRoute, Router} from "@angular/router";
import {User} from "../../user/user";
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { GuestBookService } from "../guest-book.service";
import { ToasterService } from "../../core/toaster.service";
import { GuestBook } from "../guest-book";
import { ActivatedRoute, Router } from "@angular/router";
@Component({
selector: 'app-guest-book-detail',
templateUrl: './guest-book-detail.component.html',
styleUrls: ['./guest-book-detail.component.css']
})
export class GuestBookDetailComponent implements OnInit {
export class GuestBookDetailComponent implements OnInit, AfterViewInit {
@ViewChild('name', { static: true }) nameElement: ElementRef;
form: FormGroup;
item: GuestBook;
@ -44,6 +42,12 @@ export class GuestBookDetailComponent implements OnInit {
});
}
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
}, 0);
}
showItem(item: GuestBook) {
this.item = item;
this.form.get('company').setValue(item.company);
@ -53,12 +57,12 @@ export class GuestBookDetailComponent implements OnInit {
this.form.get('address').setValue(item.address);
}
onSubmit() {
save() {
this.ser.saveOrUpdate(this.getItem())
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/guest-book/list');
this.router.navigateByUrl('/guest-book');
},
(error) => {
this.toaster.show('Danger', error.error);

View File

@ -1,18 +1,18 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {GuestBook} from "./guest-book";
import {Observable} from 'rxjs/internal/Observable';
import {GuestBookService} from './guest-book.service';
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs/internal/Observable';
import { GuestBookList } from "./guest-book";
import { GuestBookService } from './guest-book.service';
@Injectable({
providedIn: 'root'
})
export class GuestBookListResolver implements Resolve<GuestBook[]> {
export class GuestBookListResolver implements Resolve<GuestBookList> {
constructor(private ser: GuestBookService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<GuestBook[]> {
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<GuestBookList> {
return this.ser.list(null);
}
}

View File

@ -1,9 +1,6 @@
import {DataSource} from '@angular/cdk/collections';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import {map, tap} from 'rxjs/operators';
import {Observable, of as observableOf, merge} from 'rxjs';
import {GuestBook} from "../guest-book";
import { DataSource } from '@angular/cdk/collections';
import { Observable } from 'rxjs';
import { GuestBook } from "../guest-book";
/**
* Data source for the GuestBookList view. This class should
@ -11,31 +8,14 @@ import {GuestBook} from "../guest-book";
* (including sorting, pagination, and filtering).
*/
export class GuestBookListDataSource extends DataSource<GuestBook> {
private dataObservable: Observable<GuestBook[]>;
constructor(
private paginator: MatPaginator,
private sort: MatSort,
public data: GuestBook[]
constructor(private readonly dataObs: Observable<GuestBook[]>
) {
super();
}
connect(): Observable<GuestBook[]> {
this.dataObservable = observableOf(this.data);
const dataMutations = [
this.dataObservable,
this.paginator.page,
this.sort.sortChange
];
return merge(...dataMutations).pipe(
map((x: any) => {
return this.getPagedData(this.getSortedData([...this.data]));
}),
tap((x: GuestBook[]) => this.paginator.length = x.length)
);
return this.dataObs;
}
/**
@ -44,31 +24,4 @@ export class GuestBookListDataSource extends DataSource<GuestBook> {
*/
disconnect() {
}
private getPagedData(data: GuestBook[]) {
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
return data.splice(startIndex, this.paginator.pageSize);
}
private getSortedData(data: GuestBook[]) {
if (!this.sort.active || this.sort.direction === '') {
return data;
}
return data.sort((a, b) => {
const isAsc = this.sort.direction === 'asc';
switch (this.sort.active) {
case 'name':
return compare(a.name, b.name, isAsc);
case 'id':
return compare(+a.id, +b.id, isAsc);
default:
return 0;
}
});
}
}
function compare(a, b, isAsc) {
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}

View File

@ -1,70 +1,66 @@
<div class="mat-elevation-z8">
<form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px">
<mat-card>
<mat-card-title-group>
<mat-card-title>Guest List</mat-card-title>
<a mat-button [routerLink]="['/guest-book', 'new']">
<mat-icon>add_box</mat-icon>
Add
</a>
</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 fxFlex>
<a mat-button [routerLink]="['/guest-book', 'new']">
<mat-icon>add_box</mat-icon>
Add
</a>
</div>
</div>
</form>
</div>
</form>
<mat-table [dataSource]="dataSource" aria-label="Elements">
<!-- Id Column -->
<ng-container matColumnDef="sno">
<mat-header-cell *matHeaderCellDef>S. No</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.serial}}</mat-cell>
</ng-container>
<table mat-table class="full-width-table" [dataSource]="dataSource" matSort aria-label="Elements">
<!-- Id Column -->
<ng-container matColumnDef="sno">
<th mat-header-cell *matHeaderCellDef mat-sort-header>S. No</th>
<td mat-cell *matCellDef="let row">{{row.serial}}</td>
</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>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th>
<td mat-cell *matCellDef="let row">{{row.name}}</td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="phone">
<mat-header-cell *matHeaderCellDef>Phone</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.phone}}</mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="phone">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Phone</th>
<td mat-cell *matCellDef="let row">{{row.phone}}</td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="pax">
<mat-header-cell *matHeaderCellDef>Pax</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.pax}}</mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="pax">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Pax</th>
<td mat-cell *matCellDef="let row">{{row.pax}}</td>
</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]="['/running-tables']" [queryParams]="{guest: row.id}">
Seat
</button>
<button mat-icon-button [routerLink]="['/guest-book/', row.id]">
<mat-icon>edit</mat-icon>
</button>
<button mat-icon-button color="warn" (click)="deleteRow(row)">
<mat-icon>delete</mat-icon>
</button>
</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 (click)="seat(row)">
Seat
</button>
<button mat-icon-button (click)="editRow(row)">
<mat-icon>edit</mat-icon>
</button>
<button mat-icon-button color="warn" (click)="deleteRow(row)">
<mat-icon>delete</mat-icon>
</button>
</mat-cell>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator #paginator
[length]="dataSource.data.length"
[pageIndex]="0"
[pageSize]="250"
[pageSizeOptions]="[25, 50, 100, 250]">
</mat-paginator>
</div>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</mat-card-content>
</mat-card>

View File

@ -1,14 +1,12 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import {GuestBookListDataSource} from './guest-book-list-datasource';
import {ActivatedRoute} from "@angular/router";
import {FormBuilder, FormGroup} from "@angular/forms";
import {debounceTime, distinctUntilChanged, map} from "rxjs/operators";
import {GuestBook} from "../guest-book";
import {Observable} from "rxjs";
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from "@angular/router";
import { FormBuilder, FormGroup } from "@angular/forms";
import { BehaviorSubject } from "rxjs";
import { map } from "rxjs/operators";
import * as moment from 'moment';
import {GuestBookService} from "../guest-book.service";
import {GuestBook, GuestBookList} from "../guest-book";
import { GuestBookService } from "../guest-book.service";
import { GuestBookListDataSource } from './guest-book-list-datasource';
@Component({
selector: 'app-guest-book-list',
@ -16,17 +14,15 @@ import {GuestBookService} from "../guest-book.service";
styleUrls: ['./guest-book-list.component.css']
})
export class GuestBookListComponent implements OnInit {
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;
dataSource: GuestBookListDataSource;
filter: Observable<string>;
form: FormGroup;
list: GuestBook[];
data: BehaviorSubject<GuestBook[]>;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['sno', 'name', 'phone', 'pax', 'action'];
constructor(private route: ActivatedRoute, private fb: FormBuilder, private ser: GuestBookService) {
this.createForm();
this.data = new BehaviorSubject([]);
this.listenToDateChange();
}
@ -41,18 +37,19 @@ export class GuestBookListComponent implements OnInit {
map(x => moment(x).format('DD-MMM-YYYY'))
).subscribe(x => {
return this.ser.list(x)
.subscribe((list: GuestBook[]) => {
this.list = list;
this.dataSource = new GuestBookListDataSource(this.paginator, this.sort, this.list);
.subscribe((list: GuestBookList) => {
console.log("date changed");
this.data.next(list.list);
});
});
}
ngOnInit() {
this.route.data
.subscribe((data: { list: GuestBook[] }) => {
this.list = data.list;
.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.paginator, this.sort, this.list);
this.dataSource = new GuestBookListDataSource(this.data);
}
}

View File

@ -11,9 +11,10 @@ import { MatRadioModule } from '@angular/material/radio';
import { MatSelectModule } from '@angular/material/select';
import { MatSortModule } from '@angular/material/sort';
import { MatTableModule } from '@angular/material/table';
import {MomentDateAdapter} from '@angular/material-moment-adapter';
import { GuestBookDetailComponent } from './guest-book-detail/guest-book-detail.component';
import { MomentDateAdapter } from '@angular/material-moment-adapter';
import { ReactiveFormsModule } from '@angular/forms';
import { FlexLayoutModule } from '@angular/flex-layout';
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';
@ -45,6 +46,7 @@ export const MY_FORMATS = {
MatDatepickerModule,
MatNativeDateModule,
ReactiveFormsModule,
FlexLayoutModule,
GuestBookRoutingModule
],
providers: [

View File

@ -1,9 +1,9 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/internal/Observable';
import {catchError} from 'rxjs/operators';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {GuestBook} from './guest-book';
import {ErrorLoggerService} from '../core/error-logger.service';
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { GuestBook, GuestBookList } from './guest-book';
import { ErrorLoggerService } from '../core/error-logger.service';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
@ -26,10 +26,10 @@ export class GuestBookService {
);
}
list(date: string): Observable<GuestBook[]> {
list(date: string): Observable<GuestBookList> {
const options = {params: new HttpParams().set('q', (date === null) ? '' : date)};
const listUrl: string = `${url}/list`;
return <Observable<GuestBook[]>>this.http.get<GuestBook[]>(listUrl, options)
return <Observable<GuestBookList>>this.http.get<GuestBookList>(listUrl, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);

View File

@ -11,3 +11,8 @@ export class GuestBook {
Object.assign(this, init);
}
}
export class GuestBookList {
date: string;
list: GuestBook[];
}

View File

@ -1,7 +1,7 @@
<a mat-raised-button routerLink="/login" *ngIf="!(nameObject | async)">
<mat-icon>account_box</mat-icon>
Login</a>
<a mat-raised-button routerLink="/guest-book/list">
<a mat-raised-button routerLink="/guest-book">
Guest Book
</a>
<a mat-raised-button routerLink="/running-tables">

View File

@ -15,7 +15,7 @@ import { Tax } from "../../core/tax";
styleUrls: ['./product-detail.component.css']
})
export class ProductDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
@ViewChild('name', { static: true }) nameElement: ElementRef;
form: FormGroup;
productGroups: ProductGroup[];
taxes: Tax[];

View File

@ -4,6 +4,6 @@
</mat-card-title-group>
<mat-card-content fxLayout="row wrap" fxLayoutGap="grid 20px">
<button mat-raised-button class="square-button"
*ngFor="let table of list" [routerLink]="[table.id]">{{table.name}}</button>
*ngFor="let table of list" [routerLink]="['/bills', 'new']" [queryParams]="{table: table.id}">{{table.name}}</button>
</mat-card-content>
</mat-card>

View File

@ -15,8 +15,15 @@
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex>
<mat-label>Location</mat-label>
<input matInput placeholder="Location" formControlName="location">
<mat-label>Seats</mat-label>
<input matInput type="number" placeholder="Seats" formControlName="seats">
</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>
<mat-label>Section</mat-label>
<input matInput placeholder="Section" formControlName="section">
</mat-form-field>
</div>
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"

View File

@ -32,7 +32,8 @@ export class TableDetailComponent implements OnInit, AfterViewInit {
createForm() {
this.form = this.fb.group({
name: '',
location: '',
seats: '',
section: '',
isActive: ''
});
}
@ -48,7 +49,8 @@ export class TableDetailComponent implements OnInit, AfterViewInit {
this.item = item;
this.form.setValue({
name: this.item.name,
location: this.item.location,
seats: this.item.seats,
section: this.item.section,
isActive: this.item.isActive
});
}
@ -101,7 +103,8 @@ export class TableDetailComponent implements OnInit, AfterViewInit {
getItem(): Table {
const formModel = this.form.value;
this.item.name = formModel.name;
this.item.location = formModel.location;
this.item.seats = +formModel.seats;
this.item.section = formModel.section;
this.item.isActive = formModel.isActive;
return this.item;
}

View File

@ -18,10 +18,16 @@
<mat-cell *matCellDef="let row"><a [routerLink]="['/tables', row.id]">{{row.name}}</a></mat-cell>
</ng-container>
<!-- Location Column -->
<ng-container matColumnDef="location">
<mat-header-cell *matHeaderCellDef>Location</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.location}}</mat-cell>
<!-- Seats Column -->
<ng-container matColumnDef="seats">
<mat-header-cell *matHeaderCellDef>Seats</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.seats}}</mat-cell>
</ng-container>
<!-- Section Column -->
<ng-container matColumnDef="section">
<mat-header-cell *matHeaderCellDef>Section</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.section}}</mat-cell>
</ng-container>
<!-- Is Active Column -->

View File

@ -20,7 +20,7 @@ export class TableListComponent implements OnInit {
list: Table[];
data: BehaviorSubject<Table[]>;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'location', 'isActive'];
displayedColumns = ['name', 'seats', 'section', 'isActive'];
constructor(
private route: ActivatedRoute,