All Masters Done!!

This commit is contained in:
2020-06-15 21:40:12 +05:30
parent fdfd3dcbfb
commit 938bb67e0a
33 changed files with 1082 additions and 765 deletions

View File

@ -1,15 +1,15 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable } from 'rxjs';
import { SectionPrinterItem } from '../core/section-printer';
import { SectionPrinter } from '../core/section-printer';
export class SectionPrinterDataSource extends DataSource<SectionPrinterItem> {
export class SectionPrinterDataSource extends DataSource<SectionPrinter> {
constructor(private data: Observable<SectionPrinterItem[]>) {
constructor(private data: Observable<SectionPrinter[]>) {
super();
}
connect(): Observable<SectionPrinterItem[]> {
connect(): Observable<SectionPrinter[]> {
return this.data;
}

View File

@ -7,12 +7,12 @@ import { SectionPrinterService } from './section-printer.service';
@Injectable({
providedIn: 'root'
})
export class SectionPrinterResolver implements Resolve<SectionPrinter> {
export class SectionPrinterResolver implements Resolve<SectionPrinter[]> {
constructor(private ser: SectionPrinterService, private router: Router) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<SectionPrinter> {
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<SectionPrinter[]> {
const id = route.paramMap.get('id');
return this.ser.get(id);
}

View File

@ -22,7 +22,7 @@
<!-- Menu Category Column -->
<ng-container matColumnDef="menuCategory">
<mat-header-cell *matHeaderCellDef>Menu Category</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.menuCategory.name}}</mat-cell>
<mat-cell *matCellDef="let row">{{row.menuCategory?.name || 'Default'}}</mat-cell>
</ng-container>
<!-- Printer Column -->
@ -59,7 +59,7 @@
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" (click)="save()">Save</button>
<button mat-raised-button color="warn" *ngIf="item.id" (click)="confirmDelete()">Delete</button>
<button mat-raised-button color="warn" *ngIf="sectionId" (click)="confirmDelete()">Delete</button>
</mat-card-actions>
</mat-card>
</div>

View File

@ -1,8 +1,8 @@
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router} from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';
import { SectionPrinter } from '../core/section-printer';
import { ToasterService } from '../core/toaster.service';
@ -21,11 +21,11 @@ export class SectionPrinterComponent implements OnInit {
@ViewChild('section', {static: true}) sectionElement: ElementRef;
form: FormGroup;
dataSource: SectionPrinterDataSource;
public itemObservable = new BehaviorSubject<SectionPrinter>(new SectionPrinter());
item: SectionPrinter;
public listObservable = new BehaviorSubject<SectionPrinter[]>([]);
list: SectionPrinter[];
sections: Section[];
printers: Printer[];
sectionId: string;
displayedColumns = ['menuCategory', 'printer', 'copies'];
constructor(
@ -37,6 +37,7 @@ export class SectionPrinterComponent implements OnInit {
private ser: SectionPrinterService
) {
this.createForm();
route.params.pipe(map(p => p.id)).subscribe(x => this.sectionId = x);
}
createForm() {
@ -48,23 +49,23 @@ export class SectionPrinterComponent implements OnInit {
ngOnInit() {
this.route.data
.subscribe((data: { item: SectionPrinter, sections: Section[], printers: Printer[] }) => {
.subscribe((data: { list: SectionPrinter[], sections: Section[], printers: Printer[] }) => {
this.sections = data.sections;
this.printers = data.printers;
this.showItem(data.item);
this.dataSource = new SectionPrinterDataSource(this.itemObservable.pipe(map(p => p.menuCategories)));
this.itemObservable.next(this.item);
this.showItem(data.list);
this.dataSource = new SectionPrinterDataSource(this.listObservable);
this.listObservable.next(this.list);
});
}
showItem(item: SectionPrinter) {
this.item = item;
this.form.get('section').setValue(this.item.id);
showItem(list: SectionPrinter[]) {
this.list = list;
this.form.get('section').setValue(this.sectionId);
this.form.setControl('menuCategories', this.fb.array(
this.item.menuCategories.map(
this.list.map(
x => this.fb.group({
menuCategory: x.menuCategory.name,
printer: x.printer.id,
menuCategory: (x.menuCategory?.name || 'Default'),
printer: x.printer?.id,
copies: '' + x.copies
})
)
@ -73,10 +74,11 @@ export class SectionPrinterComponent implements OnInit {
save() {
this.ser.save(this.getItem())
this.ser.save(this.sectionId, this.getItem())
.subscribe(
(result) => {
(result: SectionPrinter[]) => {
this.toaster.show('Success', '');
this.showItem(result);
},
(error) => {
this.toaster.show('Danger', error.error);
@ -85,7 +87,7 @@ export class SectionPrinterComponent implements OnInit {
}
delete() {
this.ser.delete(this.item.id)
this.ser.delete(this.sectionId)
.subscribe(
(result) => {
this.toaster.show('Success', '');
@ -109,20 +111,19 @@ export class SectionPrinterComponent implements OnInit {
});
}
getItem(): SectionPrinter {
getItem(): SectionPrinter[] {
const formModel = this.form.value;
this.item.id = formModel.section;
this.sectionId = formModel.section;
const array = this.form.get('menuCategories') as FormArray;
this.item.menuCategories.forEach((item, index) => {
this.list.forEach((item, index) => {
const cont = array.controls[index].value;
item.printer.id = cont.printer;
item.printer = {id: cont.printer};
item.copies = +cont.copies;
});
return this.item;
return this.list;
}
show(val: any) {
this.router.navigate(['/section-printers', val.value]);
}
}

View File

@ -1,14 +1,14 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {ErrorLoggerService} from '../core/error-logger.service';
import {catchError} from 'rxjs/operators';
import {Observable} from 'rxjs/internal/Observable';
import {SectionPrinter, SectionPrinterItem} from '../core/section-printer';
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { ErrorLoggerService } from '../core/error-logger.service';
import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs/internal/Observable';
import { SectionPrinter } from '../core/section-printer';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/v1/section-printers';
const url = '/api/section-printers';
const serviceName = 'SectionPrinterService';
@Injectable({
@ -18,31 +18,31 @@ export class SectionPrinterService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
get(id: string): Observable<SectionPrinter> {
get(id: string): Observable<SectionPrinter[]> {
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
return <Observable<SectionPrinter>>this.http.get<SectionPrinter>(getUrl)
return <Observable<SectionPrinter[]>>this.http.get<SectionPrinter[]>(getUrl)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
}
item(id: string, menuCategoryId: string): Observable<SectionPrinterItem> {
const options = {params: new HttpParams().set('m', menuCategoryId)};
return <Observable<SectionPrinterItem>>this.http.get<SectionPrinterItem>(`${url}/${id}`, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
// item(id: string, menuCategoryId: string): Observable<SectionPrinterItem> {
// const options = {params: new HttpParams().set('m', menuCategoryId)};
// return <Observable<SectionPrinterItem>>this.http.get<SectionPrinterItem>(`${url}/${id}`, options)
// .pipe(
// catchError(this.log.handleError(serviceName, 'list'))
// );
// }
save(item: SectionPrinter): Observable<SectionPrinter> {
return <Observable<SectionPrinter>>this.http.post<SectionPrinter>(`${url}/${item.id}`, item, httpOptions)
save(sectionId: string, list: SectionPrinter[]): Observable<SectionPrinter[]> {
return <Observable<SectionPrinter[]>>this.http.post<SectionPrinter[]>(`${url}/${sectionId}`, list, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
}
delete(id: string): Observable<SectionPrinter> {
return <Observable<SectionPrinter>>this.http.delete<SectionPrinter>(`${url}/${id}`, httpOptions)
delete(id: string): Observable<SectionPrinter[]> {
return <Observable<SectionPrinter[]>>this.http.delete<SectionPrinter[]>(`${url}/${id}`, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'delete'))
);

View File

@ -16,7 +16,7 @@ const sectionPrinterRoutes: Routes = [
permission: 'Section Printers'
},
resolve: {
item: SectionPrinterResolver,
list: SectionPrinterResolver,
sections: SectionListResolver,
printers: PrinterListResolver
}
@ -29,7 +29,7 @@ const sectionPrinterRoutes: Routes = [
permission: 'Section Printers'
},
resolve: {
item: SectionPrinterResolver,
list: SectionPrinterResolver,
sections: SectionListResolver,
printers: PrinterListResolver
}