Blacked and isorted the python files
Prettied and eslinted the typescript/html files
This commit is contained in:
@ -5,26 +5,46 @@
|
||||
</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-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-checkbox formControlName="showInBill">Show In Bill?</mat-checkbox>
|
||||
</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>Price</mat-label>
|
||||
<input matInput type="number" placeholder="Price" formControlName="price">
|
||||
<input matInput type="number" placeholder="Price" formControlName="price" />
|
||||
</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>Category</mat-label>
|
||||
<mat-select placeholder="Category" formControlName="modifierCategory">
|
||||
@ -34,15 +54,22 @@
|
||||
</mat-select>
|
||||
</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-checkbox formControlName="isActive">Is Active?</mat-checkbox>
|
||||
</div>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
<button mat-raised-button color="warn" (click)="confirmDelete()" *ngIf="!!item.id">Delete</button>
|
||||
<button mat-raised-button color="warn" (click)="confirmDelete()" *ngIf="!!item.id">
|
||||
Delete
|
||||
</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ModifierDetailComponent} from './modifier-detail.component';
|
||||
import { ModifierDetailComponent } from './modifier-detail.component';
|
||||
|
||||
describe('ModifierDetailComponent', () => {
|
||||
let component: ModifierDetailComponent;
|
||||
@ -8,9 +8,8 @@ describe('ModifierDetailComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ModifierDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [ModifierDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ModifierService } from '../modifier.service';
|
||||
import { Modifier } from '../../core/modifier';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { Modifier } from '../../core/modifier';
|
||||
import { ModifierCategory } from '../../core/modifier-category';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { ModifierService } from '../modifier.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-modifier-detail',
|
||||
templateUrl: './modifier-detail.component.html',
|
||||
styleUrls: ['./modifier-detail.component.css']
|
||||
styleUrls: ['./modifier-detail.component.css'],
|
||||
})
|
||||
export class ModifierDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('name', { static: true }) nameElement: ElementRef;
|
||||
@ -25,7 +26,7 @@ export class ModifierDetailComponent implements OnInit, AfterViewInit {
|
||||
private dialog: MatDialog,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: ModifierService
|
||||
private ser: ModifierService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
@ -36,16 +37,17 @@ export class ModifierDetailComponent implements OnInit, AfterViewInit {
|
||||
showInBill: '',
|
||||
price: '',
|
||||
modifierCategory: '',
|
||||
isActive: ''
|
||||
isActive: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Modifier, modifierCategories: ModifierCategory[] }) => {
|
||||
this.route.data.subscribe(
|
||||
(data: { item: Modifier; modifierCategories: ModifierCategory[] }) => {
|
||||
this.modifierCategories = data.modifierCategories;
|
||||
this.showItem(data.item);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
showItem(item: Modifier) {
|
||||
@ -55,7 +57,7 @@ export class ModifierDetailComponent implements OnInit, AfterViewInit {
|
||||
showInBill: this.item.showInBill,
|
||||
price: this.item.price || '',
|
||||
isActive: this.item.isActive,
|
||||
modifierCategory: this.item.modifierCategory.id ? this.item.modifierCategory.id : ''
|
||||
modifierCategory: this.item.modifierCategory.id ? this.item.modifierCategory.id : '',
|
||||
});
|
||||
}
|
||||
|
||||
@ -66,35 +68,33 @@ export class ModifierDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/modifiers');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/modifiers');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/modifiers');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
this.ser.delete(this.item.id).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/modifiers');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Modifier?', content: 'Are you sure? This cannot be undone.'}
|
||||
data: { title: 'Delete Modifier?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ModifierListResolver} from './modifier-list-resolver.service';
|
||||
import { ModifierListResolver } from './modifier-list-resolver.service';
|
||||
|
||||
describe('ModifierListResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ModifierListResolver]
|
||||
providers: [ModifierListResolver],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
|
||||
import {Modifier} from '../core/modifier';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {ModifierService} from './modifier.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { Modifier } from '../core/modifier';
|
||||
|
||||
import { ModifierService } from './modifier.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ModifierListResolver implements Resolve<Modifier[]> {
|
||||
constructor(private ser: ModifierService) {}
|
||||
|
||||
constructor(private ser: ModifierService) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Modifier[]> {
|
||||
resolve(): Observable<Modifier[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,48 +1,50 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { merge, Observable } from 'rxjs';
|
||||
import { Modifier } from '../../core/modifier';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
|
||||
import { Modifier } from '../../core/modifier';
|
||||
|
||||
export class ModifierListDataSource extends DataSource<Modifier> {
|
||||
public data: Modifier[];
|
||||
public viewData: Modifier[];
|
||||
private filterValue: string;
|
||||
|
||||
constructor(private readonly filter: Observable<string>, private readonly dataObs: Observable<Modifier[]>) {
|
||||
constructor(
|
||||
private readonly filter: Observable<string>,
|
||||
private readonly dataObs: Observable<Modifier[]>,
|
||||
) {
|
||||
super();
|
||||
this.data = [];
|
||||
this.viewData = [];
|
||||
this.filter = filter.pipe(
|
||||
tap(x => this.filterValue = x)
|
||||
tap((x) => {
|
||||
this.filterValue = x;
|
||||
}),
|
||||
);
|
||||
this.dataObs = dataObs.pipe(
|
||||
tap(x => this.data = x)
|
||||
tap((x) => {
|
||||
this.data = x;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
connect(): Observable<Modifier[]> {
|
||||
const dataMutations = [
|
||||
this.dataObs,
|
||||
this.filter
|
||||
];
|
||||
const dataMutations = [this.dataObs, this.filter];
|
||||
|
||||
return merge(...dataMutations).pipe(
|
||||
map((x: any) => {
|
||||
map(() => {
|
||||
this.viewData = this.getFilteredData([...this.data]);
|
||||
return this.viewData;
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
disconnect() {}
|
||||
|
||||
private getFilteredData(data: Modifier[]): Modifier[] {
|
||||
const filter = (this.filterValue === undefined) ? '' : this.filterValue;
|
||||
return data.filter(x => {
|
||||
return x.modifierCategory.id === filter || filter === '';
|
||||
}
|
||||
);
|
||||
const filter = this.filterValue === undefined ? '' : this.filterValue;
|
||||
return data.filter((x) => {
|
||||
return x.modifierCategory.id === filter || filter === '';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,25 +8,35 @@
|
||||
</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>
|
||||
<mat-label>Modifier Category</mat-label>
|
||||
<mat-select placeholder="Modifier Category" formControlName="modifierCategory" (selectionChange)="filterOn($event)">
|
||||
<mat-option>-- All Categories --</mat-option>
|
||||
<mat-option *ngFor="let mc of modifierCategories" [value]="mc.id">
|
||||
{{ mc.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</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>Modifier Category</mat-label>
|
||||
<mat-select
|
||||
placeholder="Modifier Category"
|
||||
formControlName="modifierCategory"
|
||||
(selectionChange)="filterOn($event)"
|
||||
>
|
||||
<mat-option>-- All Categories --</mat-option>
|
||||
<mat-option *ngFor="let mc of modifierCategories" [value]="mc.id">
|
||||
{{ mc.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/modifiers', row.id]">{{row.name}}</a></mat-cell>
|
||||
<mat-cell *matCellDef="let row"
|
||||
><a [routerLink]="['/modifiers', row.id]">{{ row.name }}</a></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<!-- Show In Bill Column -->
|
||||
@ -36,9 +46,9 @@
|
||||
<div layout="row">
|
||||
<div flex>
|
||||
<mat-icon>
|
||||
{{ row.showInBill ? "visibility" : "visibility_off" }}
|
||||
{{ row.showInBill ? 'visibility' : 'visibility_off' }}
|
||||
</mat-icon>
|
||||
<b> {{ row.showInBill ? "Show" : "Hide" }}</b>
|
||||
<b> {{ row.showInBill ? 'Show' : 'Hide' }}</b>
|
||||
</div>
|
||||
</div>
|
||||
</mat-cell>
|
||||
@ -47,28 +57,28 @@
|
||||
<!-- Price Column -->
|
||||
<ng-container matColumnDef="price">
|
||||
<mat-header-cell *matHeaderCellDef>Price</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.price | currency:'INR'}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.price | currency: 'INR' }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Modifier Category Column -->
|
||||
<ng-container matColumnDef="modifierCategory">
|
||||
<mat-header-cell *matHeaderCellDef>Category</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.modifierCategory.name}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.modifierCategory.name }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Is Active Column -->
|
||||
<ng-container matColumnDef="isActive">
|
||||
<mat-header-cell *matHeaderCellDef>Is Active</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">
|
||||
<mat-icon>
|
||||
{{ row.isActive ? "visibility" : "visibility_off" }}
|
||||
</mat-icon>
|
||||
<b> {{ row.isActive ? "Active" : "Not Active" }}</b>
|
||||
<mat-icon>
|
||||
{{ row.isActive ? 'visibility' : 'visibility_off' }}
|
||||
</mat-icon>
|
||||
<b> {{ row.isActive ? 'Active' : 'Not Active' }}</b>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
</mat-table>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ModifierListComponent} from './modifier-list.component';
|
||||
import { ModifierListComponent } from './modifier-list.component';
|
||||
|
||||
describe('ModifierListComponent', () => {
|
||||
let component: ModifierListComponent;
|
||||
@ -8,9 +8,8 @@ describe('ModifierListComponent', () => {
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ModifierListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [ModifierListComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ModifierListComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
@ -1,16 +1,18 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { ModifierListDataSource } from './modifier-list-datasource';
|
||||
import { MatTable } from '@angular/material/table';
|
||||
import { Modifier } from '../../core/modifier';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import {ModifierCategory} from '../../core/modifier-category';
|
||||
|
||||
import { Modifier } from '../../core/modifier';
|
||||
import { ModifierCategory } from '../../core/modifier-category';
|
||||
|
||||
import { ModifierListDataSource } from './modifier-list-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-modifier-list',
|
||||
templateUrl: './modifier-list.component.html',
|
||||
styleUrls: ['./modifier-list.component.css']
|
||||
styleUrls: ['./modifier-list.component.css'],
|
||||
})
|
||||
export class ModifierListComponent implements OnInit {
|
||||
@ViewChild('table', { static: true }) table: MatTable<Modifier>;
|
||||
@ -23,13 +25,9 @@ export class ModifierListComponent implements OnInit {
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns: string[] = ['name', 'showInBill', 'price', 'isActive', 'modifierCategory'];
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private fb: FormBuilder,
|
||||
private router: Router
|
||||
) {
|
||||
constructor(private route: ActivatedRoute, private fb: FormBuilder, private router: Router) {
|
||||
this.form = this.fb.group({
|
||||
modifierCategory: ''
|
||||
modifierCategory: '',
|
||||
});
|
||||
this.filter = new BehaviorSubject('');
|
||||
this.data = new BehaviorSubject([]);
|
||||
@ -43,11 +41,12 @@ export class ModifierListComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: Modifier[], modifierCategories: ModifierCategory[] }) => {
|
||||
this.route.data.subscribe(
|
||||
(data: { list: Modifier[]; modifierCategories: ModifierCategory[] }) => {
|
||||
this.data.next(data.list);
|
||||
this.modifierCategories = data.modifierCategories;
|
||||
});
|
||||
},
|
||||
);
|
||||
this.dataSource = new ModifierListDataSource(this.filter, this.data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ModifierResolver} from './modifier-resolver.service';
|
||||
import { ModifierResolver } from './modifier-resolver.service';
|
||||
|
||||
describe('ModifierResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ModifierResolver]
|
||||
providers: [ModifierResolver],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {ModifierService} from './modifier.service';
|
||||
import {Modifier} from '../core/modifier';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { Modifier } from '../core/modifier';
|
||||
|
||||
import { ModifierService } from './modifier.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ModifierResolver implements Resolve<Modifier> {
|
||||
constructor(private ser: ModifierService) {}
|
||||
|
||||
constructor(private ser: ModifierService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Modifier> {
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<Modifier> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ModifierService} from './modifier.service';
|
||||
import { ModifierService } from './modifier.service';
|
||||
|
||||
describe('ModifierService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ModifierService]
|
||||
providers: [ModifierService],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,64 +1,67 @@
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Modifier } from '../core/modifier';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
import { Modifier } from '../core/modifier';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
|
||||
const url = '/api/modifiers';
|
||||
const serviceName = 'ModifierService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ModifierService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<Modifier> {
|
||||
const getUrl: string = (id === null) ? url : `${url}/${id}`;
|
||||
return <Observable<Modifier>>this.http.get<Modifier>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return <Observable<Modifier>>(
|
||||
this.http
|
||||
.get<Modifier>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Modifier[]> {
|
||||
return <Observable<Modifier[]>>this.http.get<Modifier[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'getList'))
|
||||
);
|
||||
return <Observable<Modifier[]>>(
|
||||
this.http
|
||||
.get<Modifier[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'getList')))
|
||||
);
|
||||
}
|
||||
|
||||
save(modifier: Modifier): Observable<Modifier> {
|
||||
return <Observable<Modifier>>this.http.post<Modifier>(url, modifier, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
return <Observable<Modifier>>(
|
||||
this.http
|
||||
.post<Modifier>(url, modifier, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
|
||||
update(modifier: Modifier): Observable<Modifier> {
|
||||
return <Observable<Modifier>>this.http.put<Modifier>(`${url}/${modifier.id}`, modifier, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
return <Observable<Modifier>>(
|
||||
this.http
|
||||
.put<Modifier>(`${url}/${modifier.id}`, modifier, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update')))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(modifier: Modifier): Observable<Modifier> {
|
||||
if (!modifier.id) {
|
||||
return this.save(modifier);
|
||||
} else {
|
||||
return this.update(modifier);
|
||||
}
|
||||
return this.update(modifier);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Modifier> {
|
||||
return <Observable<Modifier>>this.http.delete<Modifier>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
return <Observable<Modifier>>(
|
||||
this.http
|
||||
.delete<Modifier>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {ModifiersRoutingModule} from './modifiers-routing.module';
|
||||
import { ModifiersRoutingModule } from './modifiers-routing.module';
|
||||
|
||||
describe('ModifiersRoutingModule', () => {
|
||||
let modifiersRoutingModule: ModifiersRoutingModule;
|
||||
|
||||
@ -1,67 +1,57 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { ModifierListResolver } from './modifier-list-resolver.service';
|
||||
import { ModifierResolver } from './modifier-resolver.service';
|
||||
import { ModifierDetailComponent } from './modifier-detail/modifier-detail.component';
|
||||
import { ModifierListComponent } from './modifier-list/modifier-list.component';
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
import { ModifierCategoryListResolver } from '../modifier-categories/modifier-category-list-resolver.service';
|
||||
|
||||
import { ModifierDetailComponent } from './modifier-detail/modifier-detail.component';
|
||||
import { ModifierListResolver } from './modifier-list-resolver.service';
|
||||
import { ModifierListComponent } from './modifier-list/modifier-list.component';
|
||||
import { ModifierResolver } from './modifier-resolver.service';
|
||||
|
||||
const modifiersRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: ModifierListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Modifiers'
|
||||
permission: 'Modifiers',
|
||||
},
|
||||
resolve: {
|
||||
list: ModifierListResolver,
|
||||
modifierCategories: ModifierCategoryListResolver
|
||||
}
|
||||
modifierCategories: ModifierCategoryListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: ModifierDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Modifiers'
|
||||
permission: 'Modifiers',
|
||||
},
|
||||
resolve: {
|
||||
item: ModifierResolver,
|
||||
modifierCategories: ModifierCategoryListResolver
|
||||
}
|
||||
modifierCategories: ModifierCategoryListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: ModifierDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Modifiers'
|
||||
permission: 'Modifiers',
|
||||
},
|
||||
resolve: {
|
||||
item: ModifierResolver,
|
||||
modifierCategories: ModifierCategoryListResolver
|
||||
}
|
||||
}
|
||||
modifierCategories: ModifierCategoryListResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(modifiersRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
ModifierListResolver,
|
||||
ModifierResolver
|
||||
]
|
||||
imports: [CommonModule, RouterModule.forChild(modifiersRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [ModifierListResolver, ModifierResolver],
|
||||
})
|
||||
export class ModifiersRoutingModule {
|
||||
}
|
||||
export class ModifiersRoutingModule {}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {ModifiersModule} from './modifiers.module';
|
||||
import { ModifiersModule } from './modifiers.module';
|
||||
|
||||
describe('ModifiersModule', () => {
|
||||
let modifiersModule: ModifiersModule;
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { ModifierListComponent } from './modifier-list/modifier-list.component';
|
||||
import { ModifierDetailComponent } from './modifier-detail/modifier-detail.component';
|
||||
import { ModifiersRoutingModule } from './modifiers-routing.module';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
@ -13,8 +11,10 @@ import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
|
||||
import { ModifierDetailComponent } from './modifier-detail/modifier-detail.component';
|
||||
import { ModifierListComponent } from './modifier-list/modifier-list.component';
|
||||
import { ModifiersRoutingModule } from './modifiers-routing.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@ -30,12 +30,8 @@ import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
MatSelectModule,
|
||||
MatCheckboxModule,
|
||||
ReactiveFormsModule,
|
||||
ModifiersRoutingModule
|
||||
ModifiersRoutingModule,
|
||||
],
|
||||
declarations: [
|
||||
ModifierListComponent,
|
||||
ModifierDetailComponent
|
||||
]
|
||||
declarations: [ModifierListComponent, ModifierDetailComponent],
|
||||
})
|
||||
export class ModifiersModule {
|
||||
}
|
||||
export class ModifiersModule {}
|
||||
|
||||
Reference in New Issue
Block a user