Blacked and isorted the python files

Prettied and eslinted the typescript/html files
This commit is contained in:
2020-10-11 10:56:29 +05:30
parent b31db593c2
commit d677cfb1ea
505 changed files with 7560 additions and 5650 deletions

View File

@ -1,52 +1,53 @@
import { DataSource } from '@angular/cdk/collections';
import { map, tap } from 'rxjs/operators';
import { merge, Observable } from 'rxjs';
import { Product } from '../../core/product';
import { map, tap } from 'rxjs/operators';
import { Product } from '../../core/product';
export class ProductListDataSource extends DataSource<Product> {
public data: Product[];
public viewData: Product[];
private filterValue: string;
constructor(private readonly filter: Observable<string>, private readonly dataObs: Observable<Product[]>) {
constructor(
private readonly filter: Observable<string>,
private readonly dataObs: Observable<Product[]>,
) {
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<Product[]> {
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: Product[]): Product[] {
const filter = (this.filterValue === undefined) ? '' : this.filterValue;
const filter = this.filterValue === undefined ? '' : this.filterValue;
if (filter === '') {
return data;
} else {
return data.filter(x => {
return x.menuCategory.id === filter;
}
);
}
return data.filter((x) => {
return x.menuCategory.id === filter;
});
}
}

View File

@ -14,43 +14,60 @@
</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>Product Type</mat-label>
<mat-select placeholder="Menu Category" formControlName="menuCategory" (selectionChange)="filterOn($event)">
<mat-option>-- All Products --</mat-option>
<mat-option *ngFor="let mc of menuCategories" [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>Product Type</mat-label>
<mat-select
placeholder="Menu Category"
formControlName="menuCategory"
(selectionChange)="filterOn($event)"
>
<mat-option>-- All Products --</mat-option>
<mat-option *ngFor="let mc of menuCategories" [value]="mc.id">
{{ mc.name }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</form>
<mat-table #table cdkDropList [dataSource]="dataSource" [cdkDropListData]="dataSource" aria-label="Elements" (cdkDropListDropped)="dropTable($event)">
<mat-table
#table
cdkDropList
[dataSource]="dataSource"
[cdkDropListData]="dataSource"
aria-label="Elements"
(cdkDropListDropped)="dropTable($event)"
>
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
<mat-cell *matCellDef="let row"><a [routerLink]="['/products', row.id]">{{row.name}} ({{row.units}})</a></mat-cell>
<mat-cell *matCellDef="let row"
><a [routerLink]="['/products', row.id]">{{ row.name }} ({{ row.units }})</a></mat-cell
>
</ng-container>
<!-- 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>
<!-- 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 }}</mat-cell>
</ng-container>
<!-- Sale Category Column -->
<ng-container matColumnDef="saleCategory">
<mat-header-cell *matHeaderCellDef>Sale Category</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.saleCategory.name}}</mat-cell>
<mat-cell *matCellDef="let row">{{ row.saleCategory.name }}</mat-cell>
</ng-container>
<!-- Info Column -->
@ -60,34 +77,38 @@
<div layout="row">
<div flex>
<mat-icon>
{{ row.hasHappyHour ? "sentiment_satisfied_alt" : "sentiment_dissatisfied" }}
{{ row.hasHappyHour ? 'sentiment_satisfied_alt' : 'sentiment_dissatisfied' }}
</mat-icon>
<b> {{ row.hasHappyHour ? "Happy Hour" : "Regular" }}</b>
<b> {{ row.hasHappyHour ? 'Happy Hour' : 'Regular' }}</b>
</div>
<div flex>
<mat-icon>
{{ row.isNotAvailable ? "pause" : "play_arrow" }}
{{ row.isNotAvailable ? 'pause' : 'play_arrow' }}
</mat-icon>
<b> {{ row.isNotAvailable ? "Not Available" : "Available" }}</b>
<b> {{ row.isNotAvailable ? 'Not Available' : 'Available' }}</b>
</div>
<div flex>
<mat-icon>
{{ row.isActive ? "visibility" : "visibility_off" }}
{{ row.isActive ? 'visibility' : 'visibility_off' }}
</mat-icon>
<b> {{ row.isActive ? "Active" : "Deactivated" }}</b>
<b> {{ row.isActive ? 'Active' : 'Deactivated' }}</b>
</div>
</div>
</mat-cell>
</ng-container>
<!-- Yield Column -->
<!-- Yield Column -->
<ng-container matColumnDef="quantity">
<mat-header-cell *matHeaderCellDef>Quantity</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.quantity | currency:'INR'}}</mat-cell>
<mat-cell *matCellDef="let row">{{ row.quantity | currency: 'INR' }}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" cdkDrag [cdkDragData]="row"></mat-row>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row
*matRowDef="let row; columns: displayedColumns"
cdkDrag
[cdkDragData]="row"
></mat-row>
</mat-table>
</mat-card-content>
</mat-card>

View File

@ -1,6 +1,6 @@
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import {ProductListComponent} from './product-list.component';
import { ProductListComponent } from './product-list.component';
describe('ProductListComponent', () => {
let component: ProductListComponent;
@ -8,9 +8,8 @@ describe('ProductListComponent', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
declarations: [ProductListComponent]
})
.compileComponents();
declarations: [ProductListComponent],
}).compileComponents();
fixture = TestBed.createComponent(ProductListComponent);
component = fixture.componentInstance;

View File

@ -1,19 +1,21 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormBuilder, FormGroup } from '@angular/forms';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { ProductListDataSource } from './product-list-datasource';
import { Product } from '../../core/product';
import { ToCsvService } from '../../shared/to-csv.service';
import { ToasterService } from '../../core/toaster.service';
import { ProductService } from '../product.service';
import { MenuCategory } from '../../core/menu-category';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { BehaviorSubject } from 'rxjs';
import { MenuCategory } from '../../core/menu-category';
import { Product } from '../../core/product';
import { ToasterService } from '../../core/toaster.service';
import { ToCsvService } from '../../shared/to-csv.service';
import { ProductService } from '../product.service';
import { ProductListDataSource } from './product-list-datasource';
@Component({
selector: 'app-product-list',
templateUrl: './product-list.component.html',
styleUrls: ['./product-list.component.css']
styleUrls: ['./product-list.component.css'],
})
export class ProductListComponent implements OnInit {
dataSource: ProductListDataSource;
@ -23,17 +25,24 @@ export class ProductListComponent implements OnInit {
data: BehaviorSubject<Product[]>;
menuCategories: MenuCategory[];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns: string[] = ['name', 'price', 'menuCategory', 'saleCategory', 'info', 'quantity'];
displayedColumns: string[] = [
'name',
'price',
'menuCategory',
'saleCategory',
'info',
'quantity',
];
constructor(
private route: ActivatedRoute,
private fb: FormBuilder,
private toaster: ToasterService,
private toCsv: ToCsvService,
private ser: ProductService
private ser: ProductService,
) {
this.form = this.fb.group({
menuCategory: ''
menuCategory: '',
});
this.filter = new BehaviorSubject('');
this.data = new BehaviorSubject([]);
@ -48,10 +57,9 @@ export class ProductListComponent implements OnInit {
ngOnInit() {
this.dataSource = new ProductListDataSource(this.filter, this.data);
this.route.data
.subscribe((data: { list: Product[], menuCategories: MenuCategory[] }) => {
this.loadData(data.list, data.menuCategories);
});
this.route.data.subscribe((data: { list: Product[]; menuCategories: MenuCategory[] }) => {
this.loadData(data.list, data.menuCategories);
});
}
loadData(list: Product[], menuCategories: MenuCategory[]) {
@ -60,16 +68,15 @@ export class ProductListComponent implements OnInit {
}
updateSortOrder() {
this.ser.updateSortOrder(this.dataSource.viewData)
.subscribe(
(result: Product[]) => {
this.toaster.show('Success', '');
this.loadData(result, this.menuCategories);
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
this.ser.updateSortOrder(this.dataSource.viewData).subscribe(
(result: Product[]) => {
this.toaster.show('Success', '');
this.loadData(result, this.menuCategories);
},
(error) => {
this.toaster.show('Danger', error.error);
},
);
}
dropTable(event: CdkDragDrop<ProductListDataSource>) {
@ -78,17 +85,19 @@ export class ProductListComponent implements OnInit {
this.data.next(this.list);
}
exportCsv() {
exportCsv() {
const headers = {
Code: 'code',
Name: 'name',
Units: 'units',
Price: 'price',
MenuCategory: 'menuCategory',
SaleCategory: 'saleCategory'
SaleCategory: 'saleCategory',
};
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.viewData)], {type: 'text/csv;charset=utf-8;'});
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.viewData)], {
type: 'text/csv;charset=utf-8;',
});
const link = document.createElement('a');
link.href = window.URL.createObjectURL(csvData);
link.setAttribute('download', 'products.csv');