Blacked and isorted the python files
Prettied and eslinted the typescript/html files
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user