Updated to angular 11

Now compiling with strict mode in typescript
Need to error checking now
This commit is contained in:
2020-11-22 10:13:37 +05:30
parent cabd6f2ea1
commit 6567f560ab
187 changed files with 1709 additions and 1184 deletions

View File

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, throwError } from 'rxjs';
import { Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { AuthService } from '../../auth/auth.service';
@ -17,6 +17,7 @@ import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component'
import { Bill } from './bill';
import { BillsDataSource } from './bills-datasource';
import { Kot } from './kot';
import { VoucherType } from './voucher-type';
@Component({
selector: 'app-bills',
@ -24,7 +25,7 @@ import { Kot } from './kot';
styleUrls: ['./bills.component.css'],
})
export class BillsComponent implements OnInit {
dataSource: BillsDataSource;
dataSource: BillsDataSource = new BillsDataSource(this.bs.dataObs);
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns: string[] = ['select', 'info', 'quantity'];
@ -39,7 +40,8 @@ export class BillsComponent implements OnInit {
) {}
ngOnInit() {
this.route.data.subscribe((data: { item: Bill }) => {
this.route.data.subscribe((value) => {
const data = value as { item: Bill };
this.bs.loadData(data.item);
});
this.getPax();
@ -122,7 +124,7 @@ export class BillsComponent implements OnInit {
}
subtractOne(item: any): void {
const canEdit = this.auth.user.perms.indexOf('edit-printed-product') !== -1;
const canEdit = this.auth.allowed('edit-printed-product');
this.bs.subtractOne(item, canEdit);
}
@ -134,14 +136,21 @@ export class BillsComponent implements OnInit {
this.bs.modifier(item);
}
confirmMoveKotDialog(table: Table): Observable<Table | Observable<never>> {
confirmMoveKotDialog(table: Table): Observable<Table> {
return this.dialog
.open(ConfirmDialogComponent, {
width: '250px',
data: { title: 'Move KOT?', content: 'Are you sure?' },
})
.afterClosed()
.pipe(map((x: boolean) => (x ? table : throwError('Please confirm move'))));
.pipe(
map((x: boolean) => {
if (!x) {
throw new Error('Please confirm move');
}
return table;
}),
);
}
chooseTable(allowMerge: boolean): Observable<Table> {
@ -154,11 +163,18 @@ export class BillsComponent implements OnInit {
},
})
.afterClosed()
.pipe(map((x) => x || throwError('Please choose a table')));
.pipe(
map((x: Table) => {
if (!x) {
throw new Error('Please choose a table');
}
return x;
}),
);
}
moveKot(kot: Kot) {
const canMergeTables = this.auth.user.perms.indexOf('merge-tables') !== -1;
const canMergeTables = this.auth.allowed('merge-tables');
this.chooseTable(canMergeTables)
.pipe(
switchMap((table: Table) => this.confirmMoveKotDialog(table)),
@ -170,9 +186,9 @@ export class BillsComponent implements OnInit {
return this.bs.moveTable(table);
}
if (table.status) {
return this.bs.mergeKot(kot.id, table);
return this.bs.mergeKot(kot.id as string, table);
}
return this.bs.moveKot(kot.id, table);
return this.bs.moveKot(kot.id as string, table);
}),
)
.subscribe(
@ -190,10 +206,10 @@ export class BillsComponent implements OnInit {
if (!row.isPrinted) {
return false;
}
if (this.bs.bill.isVoid) {
if (this.bs.bill.voucherType === VoucherType.Void) {
return true;
}
if (this.auth.user.perms.indexOf('edit-printed-product') === -1) {
if (!this.auth.allowed('edit-printed-product')) {
return true;
}
return false;