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:
@@ -1,22 +1,22 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {FormArray, FormBuilder, FormGroup} from '@angular/forms';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {IncentiveDataSource} from './incentive-datasource';
|
||||
import {Account} from '../core/account';
|
||||
import {VoucherService} from '../core/voucher.service';
|
||||
import {Incentive, Voucher} from '../core/voucher';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { IncentiveDataSource } from './incentive-datasource';
|
||||
import { Account } from '../core/account';
|
||||
import { VoucherService } from '../core/voucher.service';
|
||||
import { Incentive, Voucher } from '../core/voucher';
|
||||
import * as moment from 'moment';
|
||||
import {AuthService} from '../auth/auth.service';
|
||||
import {ConfirmDialogComponent} from '../shared/confirm-dialog/confirm-dialog.component';
|
||||
import {ToasterService} from '../core/toaster.service';
|
||||
import {map} from 'rxjs/operators';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-incentive',
|
||||
templateUrl: './incentive.component.html',
|
||||
styleUrls: ['./incentive.component.css']
|
||||
styleUrls: ['./incentive.component.css'],
|
||||
})
|
||||
export class IncentiveComponent implements OnInit {
|
||||
public incentiveObservable = new BehaviorSubject<Incentive[]>([]);
|
||||
@@ -37,29 +37,31 @@ export class IncentiveComponent implements OnInit {
|
||||
private dialog: MatDialog,
|
||||
private toaster: ToasterService,
|
||||
private auth: AuthService,
|
||||
private ser: VoucherService
|
||||
private ser: VoucherService,
|
||||
) {
|
||||
this.createForm();
|
||||
this.listenToDateChange();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { voucher: Voucher }) => {
|
||||
this.loadVoucher(data.voucher);
|
||||
});
|
||||
this.route.data.subscribe((data: { voucher: Voucher }) => {
|
||||
this.loadVoucher(data.voucher);
|
||||
});
|
||||
}
|
||||
|
||||
loadVoucher(voucher) {
|
||||
this.voucher = voucher;
|
||||
this.form.get('date').setValue(moment(this.voucher.date, 'DD-MMM-YYYY').toDate());
|
||||
this.form.setControl('incentives', this.fb.array(
|
||||
this.voucher.incentives.map(
|
||||
x => this.fb.group({
|
||||
points: x.points
|
||||
})
|
||||
)
|
||||
));
|
||||
this.form.setControl(
|
||||
'incentives',
|
||||
this.fb.array(
|
||||
this.voucher.incentives.map((x) =>
|
||||
this.fb.group({
|
||||
points: x.points,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new IncentiveDataSource(this.incentiveObservable);
|
||||
this.incentiveObservable.next(this.voucher.incentives);
|
||||
}
|
||||
@@ -67,50 +69,64 @@ export class IncentiveComponent implements OnInit {
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
date: '',
|
||||
incentives: this.fb.array([])
|
||||
incentives: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
listenToDateChange(): void {
|
||||
this.form.get('date').valueChanges.pipe(
|
||||
map(x => moment(x).format('DD-MMM-YYYY'))
|
||||
).subscribe(x => {
|
||||
if (x !== this.voucher.date && !this.voucher.id) {
|
||||
return this.ser.getIncentive(x)
|
||||
.subscribe((voucher: Voucher) => {
|
||||
this.form
|
||||
.get('date')
|
||||
.valueChanges.pipe(map((x) => moment(x).format('DD-MMM-YYYY')))
|
||||
.subscribe((x) => {
|
||||
if (x !== this.voucher.date && !this.voucher.id) {
|
||||
return this.ser.getIncentive(x).subscribe((voucher: Voucher) => {
|
||||
this.loadVoucher(voucher);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
totalPoints() {
|
||||
return this.voucher.incentives.map((item) => {
|
||||
return item.daysWorked * item.points;
|
||||
}).reduce((sum, item) => {
|
||||
return sum + item;
|
||||
});
|
||||
return this.voucher.incentives
|
||||
.map((item) => {
|
||||
return item.daysWorked * item.points;
|
||||
})
|
||||
.reduce((sum, item) => {
|
||||
return sum + item;
|
||||
});
|
||||
}
|
||||
|
||||
pointValue() {
|
||||
return Math.round(this.voucher.incentive * 100 / this.totalPoints()) / 100;
|
||||
return Math.round((this.voucher.incentive * 100) / this.totalPoints()) / 100;
|
||||
}
|
||||
|
||||
less(row: Incentive, i: number) {
|
||||
if (row.points >= 1) {
|
||||
row.points -= 1;
|
||||
this.form.get('incentives').get('' + i).setValue({'points': '' + row.points});
|
||||
this.form
|
||||
.get('incentives')
|
||||
.get('' + i)
|
||||
.setValue({ points: '' + row.points });
|
||||
}
|
||||
}
|
||||
|
||||
change(row: Incentive, i: number) {
|
||||
row.points = +(this.form.get('incentives').get('' + i).get('points').value);
|
||||
this.form.get('incentives').get('' + i).setValue({'points': '' + row.points});
|
||||
row.points = +this.form
|
||||
.get('incentives')
|
||||
.get('' + i)
|
||||
.get('points').value;
|
||||
this.form
|
||||
.get('incentives')
|
||||
.get('' + i)
|
||||
.setValue({ points: '' + row.points });
|
||||
}
|
||||
|
||||
more(row: Incentive, i: number) {
|
||||
row.points += 1;
|
||||
this.form.get('incentives').get('' + i).setValue({'points': '' + row.points});
|
||||
this.form
|
||||
.get('incentives')
|
||||
.get('' + i)
|
||||
.setValue({ points: '' + row.points });
|
||||
}
|
||||
|
||||
amount(row) {
|
||||
@@ -123,38 +139,39 @@ export class IncentiveComponent implements OnInit {
|
||||
} 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) => {
|
||||
if (voucher.id === result.id) {
|
||||
this.loadVoucher(result);
|
||||
} else {
|
||||
this.ser.saveOrUpdate(voucher).subscribe(
|
||||
(result) => {
|
||||
if (voucher.id === result.id) {
|
||||
this.loadVoucher(result);
|
||||
} else {
|
||||
this.router.navigate(['/incentive', result.id]);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
getVoucher(): Voucher {
|
||||
@@ -168,22 +185,21 @@ export class IncentiveComponent implements OnInit {
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.voucher.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/incentive'], {replaceUrl: true});
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.delete(this.voucher.id).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/incentive'], { 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) => {
|
||||
|
||||
Reference in New Issue
Block a user