Moved from tslint to eslint as tslint was depreciated.

Added prettier and also prettied all the typescript files using prettier

ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
2020-10-01 21:28:12 +05:30
parent 40e79ff949
commit 1350870f9e
545 changed files with 8455 additions and 7036 deletions
+116 -91
View File
@@ -22,7 +22,7 @@ import { Hotkey, HotkeysService } from 'angular2-hotkeys';
@Component({
selector: 'app-payment',
templateUrl: './payment.component.html',
styleUrls: ['./payment.component.css']
styleUrls: ['./payment.component.css'],
})
export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('accountElement', { static: true }) accountElement: ElementRef;
@@ -49,7 +49,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
private toaster: ToasterService,
private auth: AuthService,
private ser: VoucherService,
private accountSer: AccountService
private accountSer: AccountService,
) {
this.account = null;
this.createForm();
@@ -58,27 +58,47 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
}
ngOnInit() {
this.route.data
.subscribe((data: { voucher: Voucher, paymentAccounts: Account[] }) => {
this.paymentAccounts = data.paymentAccounts;
this.loadVoucher(data.voucher);
});
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
this.save();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+p', (event: KeyboardEvent): boolean => {
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('post-vouchers') !== -1)
this.post();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.route.data.subscribe((data: { voucher: Voucher; paymentAccounts: Account[] }) => {
this.paymentAccounts = data.paymentAccounts;
this.loadVoucher(data.voucher);
});
this.hotkeys.add(
new Hotkey(
'f2',
(event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
},
['INPUT', 'SELECT', 'TEXTAREA'],
),
);
this.hotkeys.add(
new Hotkey(
'ctrl+s',
(event: KeyboardEvent): boolean => {
if (this.canSave()) this.save();
return false; // Prevent bubbling
},
['INPUT', 'SELECT', 'TEXTAREA'],
),
);
this.hotkeys.add(
new Hotkey(
'ctrl+p',
(event: KeyboardEvent): boolean => {
if (
this.voucher.id &&
!this.voucher.posted &&
this.auth.user.perms.indexOf('post-vouchers') !== -1
)
this.post();
return false; // Prevent bubbling
},
['INPUT', 'SELECT', 'TEXTAREA'],
),
);
}
ngAfterViewInit() {
@@ -91,20 +111,19 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
loadVoucher(voucher: Voucher) {
this.voucher = voucher;
this.paymentJournal = this.voucher.journals.filter(x => x.debit === -1)[0];
this.paymentJournal = this.voucher.journals.filter((x) => x.debit === -1)[0];
this.form.setValue({
date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
paymentAccount: this.paymentJournal.account.id,
paymentAmount: this.paymentJournal.amount,
addRow: {
account: '',
amount: 0
amount: 0,
},
narration: this.voucher.narration
narration: this.voucher.narration,
});
this.dataSource = new PaymentDataSource(this.journalObservable);
this.updateView();
}
focusAccount() {
@@ -132,7 +151,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
debit: debit,
amount: amount,
account: this.account,
costCentre: null
costCentre: null,
});
}
this.resetAddRow();
@@ -141,7 +160,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
rowAmount(amount: string = ''): number {
try {
amount = amount.replace(new RegExp('(₹[\s]*)|(,)|(\s)', 'g'), '');
amount = amount.replace(new RegExp('(₹[s]*)|(,)|(s)', 'g'), '');
return evaluate(amount);
} catch {
return 0;
@@ -151,7 +170,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
resetAddRow() {
this.form.get('addRow').reset({
account: null,
amount: null
amount: null,
});
this.account = null;
this.accBal = null;
@@ -161,7 +180,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
}
updateView() {
const journals = this.voucher.journals.filter(x => x.debit === 1);
const journals = this.voucher.journals.filter((x) => x.debit === 1);
this.journalObservable.next(journals);
this.paymentJournal.amount = Math.abs(journals.map((x) => x.amount).reduce((p, c) => p + c, 0));
this.form.get('paymentAmount').setValue(this.paymentJournal.amount);
@@ -170,7 +189,10 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
editRow(row: Journal) {
const dialogRef = this.dialog.open(PaymentDialogComponent, {
width: '750px',
data: {journal: Object.assign({}, row), date: moment(this.form.get('date').value).format('DD-MMM-YYYY')}
data: {
journal: Object.assign({}, row),
date: moment(this.form.get('date').value).format('DD-MMM-YYYY'),
},
});
dialogRef.afterClosed().subscribe((result: boolean | Journal) => {
@@ -178,7 +200,10 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
return;
}
const j = result as Journal;
if (j.account.id !== row.account.id && this.voucher.journals.filter((x) => x.account.id === j.account.id).length) {
if (
j.account.id !== row.account.id &&
this.voucher.journals.filter((x) => x.account.id === j.account.id).length
) {
return;
}
Object.assign(row, j);
@@ -195,12 +220,12 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
this.form = this.fb.group({
date: '',
paymentAccount: '',
paymentAmount: {value: '', disabled: true},
paymentAmount: { value: '', disabled: true },
addRow: this.fb.group({
account: '',
amount: ''
amount: '',
}),
narration: ''
narration: '',
});
this.accBal = null;
}
@@ -211,39 +236,40 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
} 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;
return (
this.voucher.user.id === this.auth.user.id ||
this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1
);
}
}
post() {
this.ser.post(this.voucher.id)
.subscribe(
(result) => {
this.loadVoucher(result);
this.toaster.show('Success', 'Voucher Posted');
},
(error) => {
this.toaster.show('Danger', error);
}
);
this.ser.post(this.voucher.id).subscribe(
(result) => {
this.loadVoucher(result);
this.toaster.show('Success', 'Voucher Posted');
},
(error) => {
this.toaster.show('Danger', error);
},
);
}
save() {
const voucher: Voucher = this.getVoucher();
this.ser.saveOrUpdate(voucher)
.subscribe(
(result) => {
this.toaster.show('Success', '');
if (voucher.id === result.id) {
this.loadVoucher(result);
} else {
this.ser.saveOrUpdate(voucher).subscribe(
(result) => {
this.toaster.show('Success', '');
if (voucher.id === result.id) {
this.loadVoucher(result);
} else {
this.router.navigate(['/payment', result.id]);
}
},
(error) => {
this.toaster.show('Danger', error);
}
);
},
(error) => {
this.toaster.show('Danger', error);
},
);
}
getVoucher(): Voucher {
@@ -255,22 +281,21 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
}
delete() {
this.ser.delete(this.voucher.id)
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigate(['/payment'], {replaceUrl: true});
},
(error) => {
this.toaster.show('Danger', error);
}
);
this.ser.delete(this.voucher.id).subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigate(['/payment'], { replaceUrl: true });
},
(error) => {
this.toaster.show('Danger', error);
},
);
}
confirmDelete(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.'}
data: { title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.' },
});
dialogRef.afterClosed().subscribe((result: boolean) => {
@@ -282,24 +307,23 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
listenToAccountAutocompleteChange(): void {
const control = this.form.get('addRow').get('account');
this.accounts = control.valueChanges
.pipe(
startWith(null),
map(x => (x !== null && x.length >= 1) ? x : null),
debounceTime(150),
distinctUntilChanged(),
switchMap(x => (x === null) ? observableOf([]) : this.accountSer.autocomplete(x))
);
this.accounts = control.valueChanges.pipe(
startWith(null),
map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150),
distinctUntilChanged(),
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
);
}
listenToPaymentAccountChange(): void {
this.form.get('paymentAccount').valueChanges
.subscribe(x => this.router.navigate([], {
relativeTo: this.route,
queryParams: {a: x},
replaceUrl: true
})
);
this.form.get('paymentAccount').valueChanges.subscribe((x) =>
this.router.navigate([], {
relativeTo: this.route,
queryParams: { a: x },
replaceUrl: true,
}),
);
}
displayAccount(account?: Account): string | undefined {
@@ -317,7 +341,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
zoomImage(file: DbFile) {
this.dialog.open(ImageDialogComponent, {
width: '750px',
data: file.resized
data: file.resized,
});
}
@@ -332,11 +356,12 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
for (const file of files) {
const reader = new FileReader();
reader.onload = (e: any) => {
zip(of(e.target.result),
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]})
this.resizeImage(e.target.result, 825, 1170),
).subscribe((val) =>
this.voucher.files.push({ id: null, thumbnail: val[1], resized: val[2] }),
);
};
reader.readAsDataURL(file);
@@ -365,7 +390,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
canvas.height = height;
ctx.drawImage(img, 0, 0, width, height);
return canvas.toDataURL('image/jpeg', 0.95);
})
}),
);
img.src = image;
return ex;