Prettied, Linted and updated angular.json according to the latest schematic of Angular CLI.
Now all that is needed is to make it ready for strict compiling. Removed eslint-plugin-prettier as it is not recommended and causes errors for both eslint and prettier Bumped to v8.0.0
This commit is contained in:
@ -3,25 +3,29 @@ import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BehaviorSubject, fromEvent, Observable, of, of as observableOf, zip } from 'rxjs';
|
||||
import { PurchaseDataSource } from './purchase-datasource';
|
||||
import { Account } from '../core/account';
|
||||
import { VoucherService } from '../core/voucher.service';
|
||||
import { AccountService } from '../core/account.service';
|
||||
import { DbFile, Inventory, Voucher } from '../core/voucher';
|
||||
import * as moment from 'moment';
|
||||
import { round } from 'mathjs';
|
||||
import { MathService } from '../shared/math.service';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
|
||||
import { PurchaseDialogComponent } from './purchase-dialog.component';
|
||||
import { ImageDialogComponent } from '../shared/image-dialog/image-dialog.component';
|
||||
import { ProductService } from '../product/product.service';
|
||||
import { Product } from '../core/product';
|
||||
import { Hotkey, HotkeysService } from 'angular2-hotkeys';
|
||||
import { conditionallyCreateMapObjectLiteral } from '@angular/compiler/src/render3/view/util';
|
||||
import { round } from 'mathjs';
|
||||
import * as moment from 'moment';
|
||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { Account } from '../core/account';
|
||||
import { AccountService } from '../core/account.service';
|
||||
import { DbFile } from '../core/db-file';
|
||||
import { Inventory } from '../core/inventory';
|
||||
import { Product } from '../core/product';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { Voucher } from '../core/voucher';
|
||||
import { VoucherService } from '../core/voucher.service';
|
||||
import { ProductService } from '../product/product.service';
|
||||
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { ImageDialogComponent } from '../shared/image-dialog/image-dialog.component';
|
||||
import { ImageService } from '../shared/image.service';
|
||||
import { MathService } from '../shared/math.service';
|
||||
|
||||
import { PurchaseDataSource } from './purchase-datasource';
|
||||
import { PurchaseDialogComponent } from './purchase-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-purchase',
|
||||
@ -51,8 +55,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
private dialog: MatDialog,
|
||||
private hotkeys: HotkeysService,
|
||||
private toaster: ToasterService,
|
||||
private auth: AuthService,
|
||||
public auth: AuthService,
|
||||
private math: MathService,
|
||||
public image: ImageService,
|
||||
private ser: VoucherService,
|
||||
private productSer: ProductService,
|
||||
private accountSer: AccountService,
|
||||
@ -69,7 +74,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.hotkeys.add(
|
||||
new Hotkey(
|
||||
'f2',
|
||||
(event: KeyboardEvent): boolean => {
|
||||
(): boolean => {
|
||||
setTimeout(() => {
|
||||
this.dateElement.nativeElement.focus();
|
||||
}, 0);
|
||||
@ -81,7 +86,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.hotkeys.add(
|
||||
new Hotkey(
|
||||
'ctrl+s',
|
||||
(event: KeyboardEvent): boolean => {
|
||||
(): boolean => {
|
||||
if (this.canSave()) {
|
||||
this.save();
|
||||
}
|
||||
@ -93,7 +98,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.hotkeys.add(
|
||||
new Hotkey(
|
||||
'ctrl+p',
|
||||
(event: KeyboardEvent): boolean => {
|
||||
(): boolean => {
|
||||
if (
|
||||
this.voucher.id &&
|
||||
!this.voucher.posted &&
|
||||
@ -157,10 +162,10 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
this.voucher.inventories.push({
|
||||
id: null,
|
||||
quantity: quantity,
|
||||
quantity,
|
||||
rate: price,
|
||||
tax: tax,
|
||||
discount: discount,
|
||||
tax,
|
||||
discount,
|
||||
amount: round(quantity * price * (1 + tax) * (1 - discount), 2),
|
||||
product: this.product,
|
||||
batch: null,
|
||||
@ -196,7 +201,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
editRow(row: Inventory) {
|
||||
const dialogRef = this.dialog.open(PurchaseDialogComponent, {
|
||||
width: '750px',
|
||||
data: { inventory: Object.assign({}, row) },
|
||||
data: { inventory: { ...row } },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean | Inventory) => {
|
||||
@ -240,14 +245,14 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
canSave() {
|
||||
if (!this.voucher.id) {
|
||||
return true;
|
||||
} else if (this.voucher.posted && this.auth.user.perms.indexOf('edit-posted-vouchers') !== -1) {
|
||||
return true;
|
||||
} else {
|
||||
return (
|
||||
this.voucher.user.id === this.auth.user.id ||
|
||||
this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1
|
||||
);
|
||||
}
|
||||
if (this.voucher.posted && this.auth.user.perms.indexOf('edit-posted-vouchers') !== -1) {
|
||||
return true;
|
||||
}
|
||||
return (
|
||||
this.voucher.user.id === this.auth.user.id ||
|
||||
this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1
|
||||
);
|
||||
}
|
||||
|
||||
post() {
|
||||
@ -289,7 +294,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.voucher.id).subscribe(
|
||||
(result) => {
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/purchase'], { replaceUrl: true });
|
||||
},
|
||||
@ -334,18 +339,14 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
);
|
||||
}
|
||||
|
||||
displayAccount(account?: Account): string | undefined {
|
||||
return account ? account.name : undefined;
|
||||
displayFn(item?: Account | Product): string | undefined {
|
||||
return item ? item.name : undefined;
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
this.form.get('account').setValue(event.option.value);
|
||||
}
|
||||
|
||||
displayProductName(product?: Product): string | undefined {
|
||||
return product ? product.name : undefined;
|
||||
}
|
||||
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
this.product = event.option.value;
|
||||
this.form.get('addRow').get('price').setValue(this.product.price);
|
||||
@ -362,50 +363,4 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
const index = this.voucher.files.indexOf(file);
|
||||
this.voucher.files.splice(index, 1);
|
||||
}
|
||||
|
||||
detectFiles(event) {
|
||||
const files = event.target.files;
|
||||
if (files) {
|
||||
for (const file of files) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e: any) => {
|
||||
zip(
|
||||
of(e.target.result),
|
||||
this.resizeImage(e.target.result, 100, 150),
|
||||
this.resizeImage(e.target.result, 825, 1170),
|
||||
).subscribe((val) =>
|
||||
this.voucher.files.push({ id: null, thumbnail: val[1], resized: val[2] }),
|
||||
);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resizeImage(image, MAX_WIDTH, MAX_HEIGHT) {
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const img = new Image();
|
||||
const ex = fromEvent(img, 'load').pipe(
|
||||
map((e) => {
|
||||
let width = img.naturalWidth,
|
||||
height = img.naturalHeight;
|
||||
const ratio = Math.min(1, MAX_WIDTH / width, MAX_HEIGHT / height);
|
||||
|
||||
if (ratio === 1) {
|
||||
return image;
|
||||
}
|
||||
|
||||
width *= ratio;
|
||||
height *= ratio;
|
||||
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
ctx.drawImage(img, 0, 0, width, height);
|
||||
return canvas.toDataURL('image/jpeg', 0.95);
|
||||
}),
|
||||
);
|
||||
img.src = image;
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user