build: Use prettier for typescript

Stop ignoring .ts files in prettier and fix existing issues.
This commit is contained in:
Ralph Hopman
2025-01-15 11:59:30 +00:00
committed by Adam Saghy
parent 9d6cf1514a
commit cac1d11ad7
1812 changed files with 22516 additions and 16862 deletions
@@ -3,44 +3,41 @@ import { Injectable } from '@angular/core';
import { OfficeItemNode } from './office-item.class';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class ChecklistDatabase {
// rxjs functionality to update DOM via subscribe
dataChange = new BehaviorSubject<OfficeItemNode[]>([]);
get data(): OfficeItemNode[] {
return this.dataChange.value;
}
TREE_DATA = {};
constructor() {}
// rxjs functionality to update DOM via subscribe
dataChange = new BehaviorSubject<OfficeItemNode[]>([]);
get data(): OfficeItemNode[] {
return this.dataChange.value;
}
TREE_DATA = {};
// called every time the data in route changes
initialize(trie: any) {
this.TREE_DATA = trie;
const data = this.buildFileTree(this.TREE_DATA, 0);
this.dataChange.next(data);
}
constructor() {
}
// builds hierarchical tree of officeItemNodes
buildFileTree(obj: { [key: string]: any }, level: number): OfficeItemNode[] {
return Object.keys(obj).reduce<OfficeItemNode[]>((accumulator, key) => {
const value = obj[key];
const node = new OfficeItemNode();
node.item = key;
// called every time the data in route changes
initialize(trie: any) {
this.TREE_DATA = trie;
const data = this.buildFileTree(this.TREE_DATA, 0);
this.dataChange.next(data);
}
if (value != null) {
if (typeof value === 'object') {
node.children = this.buildFileTree(value, level + 1);
} else {
node.item = value;
}
}
// builds hierarchical tree of officeItemNodes
buildFileTree(obj: { [key: string]: any }, level: number): OfficeItemNode[] {
return Object.keys(obj).reduce<OfficeItemNode[]>((accumulator, key) => {
const value = obj[key];
const node = new OfficeItemNode();
node.item = key;
if (value != null) {
if (typeof value === 'object') {
node.children = this.buildFileTree(value, level + 1);
} else {
node.item = value;
}
}
return accumulator.concat(node);
}, []);
}
return accumulator.concat(node);
}, []);
}
}
@@ -8,9 +8,8 @@ describe('CreateHolidayComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateHolidayComponent ]
})
.compileComponents();
declarations: [CreateHolidayComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -24,7 +24,6 @@ import { CreateHoliday } from './create-holiday.service';
styleUrls: ['./create-holiday.component.scss']
})
export class CreateHolidayComponent implements OnInit {
/** Create Holiday form. */
holidayForm: UntypedFormGroup;
/** Repayment Scheduling data. */
@@ -73,15 +72,17 @@ export class CreateHolidayComponent implements OnInit {
* @param {OrganizationService} organizationService Organization Service.
* @param {Router} router Router.
*/
constructor(private formBuilder: UntypedFormBuilder,
private route: ActivatedRoute,
private dateUtils: Dates,
private organizationService: OrganizationService,
private settings: SettingsService,
private router: Router,
private _database: ChecklistDatabase,
private createHoliday: CreateHoliday ) {
this.route.data.subscribe((data: { offices: any, holidayTemplate: any }) => {
constructor(
private formBuilder: UntypedFormBuilder,
private route: ActivatedRoute,
private dateUtils: Dates,
private organizationService: OrganizationService,
private settings: SettingsService,
private router: Router,
private _database: ChecklistDatabase,
private createHoliday: CreateHoliday
) {
this.route.data.subscribe((data: { offices: any; holidayTemplate: any }) => {
this.officesData = data.offices;
this.repaymentSchedulingTypes = data.holidayTemplate;
// Constructs trie everytime data changes
@@ -121,7 +122,7 @@ export class CreateHolidayComponent implements OnInit {
// Sets root as the first object
root = trie[Object.keys(trie)[0]];
// Construction of hierarchy via Depth First Search
hierarchy.forEach((stage: string) => {
hierarchy.forEach((stage: string) => {
if (!(stage in root)) {
root[stage] = {};
}
@@ -160,7 +161,7 @@ export class CreateHolidayComponent implements OnInit {
this.flatNodeMap.set(flatNode, node);
this.nestedNodeMap.set(node, flatNode);
return flatNode;
}
};
/** Whether all the descendants of the node are selected. */
descendantsAllSelected(node: OfficeItemFlatNode): boolean {
@@ -176,7 +177,7 @@ export class CreateHolidayComponent implements OnInit {
setSelectedOffices() {
this.holidayForm.patchValue({
offices: this.checklistSelection.selected.map((item) => item.item),
offices: this.checklistSelection.selected.map((item) => item.item)
});
}
@@ -256,12 +257,27 @@ export class CreateHolidayComponent implements OnInit {
*/
setHolidayForm() {
this.holidayForm = this.formBuilder.group({
'name': ['', Validators.required],
'fromDate': ['', Validators.required],
'toDate': ['', Validators.required],
'reschedulingType': ['', Validators.required],
'description': [''],
'offices': ['', Validators.required]
name: [
'',
Validators.required
],
fromDate: [
'',
Validators.required
],
toDate: [
'',
Validators.required
],
reschedulingType: [
'',
Validators.required
],
description: [''],
offices: [
'',
Validators.required
]
});
}
@@ -294,7 +310,7 @@ export class CreateHolidayComponent implements OnInit {
holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDate(prevRepaymentsRescheduledTo, dateFormat);
}
const offices = this.holidayForm.value.offices.map((office: string) => {
return {'officeId': Number.parseInt(office, 10)};
return { officeId: Number.parseInt(office, 10) };
});
const data = {
...holidayFormData,
@@ -303,8 +319,13 @@ export class CreateHolidayComponent implements OnInit {
offices
};
this.organizationService.createHoliday(data).subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
this.router.navigate(
[
'../',
response.resourceId
],
{ relativeTo: this.route }
);
});
}
}
@@ -1,17 +1,16 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class CreateHoliday {
setEmptyObjectsToNull(root: any) {
Object.keys(root).forEach((key) => {
if (Object.keys(root[key]).length === 0) {
root[key] = null;
} else {
this.setEmptyObjectsToNull(root[key]);
}
});
}
setEmptyObjectsToNull(root: any) {
Object.keys(root).forEach((key) => {
if (Object.keys(root[key]).length === 0) {
root[key] = null;
} else {
this.setEmptyObjectsToNull(root[key]);
}
});
}
}
@@ -1,10 +1,10 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class OfficeItemFlatNode {
item: string;
level: number;
expandable: boolean;
}
item: string;
level: number;
expandable: boolean;
}
@@ -1,9 +1,9 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class OfficeItemNode {
children: OfficeItemNode[];
item: string;
children: OfficeItemNode[];
item: string;
}
@@ -8,9 +8,8 @@ describe('EditHolidayComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditHolidayComponent ]
})
.compileComponents();
declarations: [EditHolidayComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -17,7 +17,6 @@ import { SettingsService } from 'app/settings/settings.service';
styleUrls: ['./edit-holiday.component.scss']
})
export class EditHolidayComponent implements OnInit {
/** Edit Holiday form. */
holidayForm: UntypedFormGroup;
/** Holiday data. */
@@ -39,17 +38,19 @@ export class EditHolidayComponent implements OnInit {
* @param {OrganizationService} organizatioService Organization Service.
* @param {Router} router Router.
*/
constructor(private formBuilder: UntypedFormBuilder,
private route: ActivatedRoute,
private dateUtils: Dates,
private organizatioService: OrganizationService,
private settingsService: SettingsService,
private router: Router ) {
this.route.data.subscribe((data: { holiday: any, holidayTemplate: any }) => {
constructor(
private formBuilder: UntypedFormBuilder,
private route: ActivatedRoute,
private dateUtils: Dates,
private organizatioService: OrganizationService,
private settingsService: SettingsService,
private router: Router
) {
this.route.data.subscribe((data: { holiday: any; holidayTemplate: any }) => {
this.holidayData = data.holiday;
this.holidayData.repaymentSchedulingTypes = data.holidayTemplate;
this.reSchedulingType = this.holidayData.reschedulingType;
if ( this.holidayData.status.value === 'Active' ) {
if (this.holidayData.status.value === 'Active') {
this.isActiveHoliday = true;
} else {
this.isActiveHoliday = false;
@@ -70,15 +71,33 @@ export class EditHolidayComponent implements OnInit {
*/
setEditForm() {
this.holidayForm = this.formBuilder.group({
'name': [this.holidayData.name, Validators.required],
'description': [this.holidayData.description]
name: [
this.holidayData.name,
Validators.required
],
description: [this.holidayData.description]
});
if (!this.isActiveHoliday) {
this.holidayForm.addControl('fromDate', new UntypedFormControl(this.holidayData.fromDate && new Date(this.holidayData.fromDate), Validators.required));
this.holidayForm.addControl('toDate', new UntypedFormControl(this.holidayData.toDate && new Date(this.holidayData.toDate), Validators.required));
this.holidayForm.addControl('reschedulingType', new UntypedFormControl(this.holidayData.reschedulingType, Validators.required));
this.holidayForm.addControl(
'fromDate',
new UntypedFormControl(this.holidayData.fromDate && new Date(this.holidayData.fromDate), Validators.required)
);
this.holidayForm.addControl(
'toDate',
new UntypedFormControl(this.holidayData.toDate && new Date(this.holidayData.toDate), Validators.required)
);
this.holidayForm.addControl(
'reschedulingType',
new UntypedFormControl(this.holidayData.reschedulingType, Validators.required)
);
if (this.reSchedulingType === 2) {
this.holidayForm.addControl('repaymentsRescheduledTo', new UntypedFormControl(this.holidayData.repaymentsRescheduledTo && new Date(this.holidayData.repaymentsRescheduledTo), Validators.required));
this.holidayForm.addControl(
'repaymentsRescheduledTo',
new UntypedFormControl(
this.holidayData.repaymentsRescheduledTo && new Date(this.holidayData.repaymentsRescheduledTo),
Validators.required
)
);
}
}
}
@@ -87,7 +106,7 @@ export class EditHolidayComponent implements OnInit {
* Get Rescheduling Type.
*/
getReschedulingType() {
this.holidayForm.get('reschedulingType').valueChanges.subscribe( (option: any) => {
this.holidayForm.get('reschedulingType').valueChanges.subscribe((option: any) => {
this.reSchedulingType = option;
if (option === 2) {
this.holidayForm.addControl('repaymentsRescheduledTo', new UntypedFormControl(new Date(), Validators.required));
@@ -105,7 +124,7 @@ export class EditHolidayComponent implements OnInit {
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
if (!this.isActiveHoliday) {
if (this.reSchedulingType === 2 ) {
if (this.reSchedulingType === 2) {
const repaymentScheduledTo: Date = this.holidayForm.value.repaymentsRescheduledTo;
holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDate(repaymentScheduledTo, dateFormat);
}
@@ -123,10 +142,9 @@ export class EditHolidayComponent implements OnInit {
dateFormat,
locale
};
this.organizatioService.updateHoliday(this.holidayData.id, data).subscribe(response => {
this.organizatioService.updateHoliday(this.holidayData.id, data).subscribe((response) => {
/** TODO Add Redirects to ViewMakerCheckerTask page. */
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}
@@ -13,7 +13,6 @@ import { OrganizationService } from 'app/organization/organization.service';
*/
@Injectable()
export class HolidayTemplateResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
@@ -26,5 +25,4 @@ export class HolidayTemplateResolver implements Resolve<Object> {
resolve(): Observable<any> {
return this.organizationService.getHolidayTemplate();
}
}
@@ -13,7 +13,6 @@ import { OrganizationService } from 'app/organization/organization.service';
*/
@Injectable()
export class HolidayResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
@@ -24,8 +23,7 @@ export class HolidayResolver implements Resolve<Object> {
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const holidayId = route.paramMap.get('id');
const holidayId = route.paramMap.get('id');
return this.organizationService.getHoliday(holidayId);
}
}
@@ -8,9 +8,8 @@ describe('HolidaysComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HolidaysComponent ]
})
.compileComponents();
declarations: [HolidaysComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -23,7 +23,6 @@ import { ConfigurationWizardService } from '../../configuration-wizard/configura
styleUrls: ['./holidays.component.scss']
})
export class HolidaysComponent implements OnInit, AfterViewInit {
/** Office selector. */
officeSelector = new UntypedFormControl();
/** Holidays data. */
@@ -31,7 +30,13 @@ export class HolidaysComponent implements OnInit, AfterViewInit {
/** Offices data. */
officeData: any;
/** Columns to be displayed in holidays table. */
displayedColumns: string[] = ['name', 'fromDate', 'toDate', 'repaymentsRescheduledTo', 'status'];
displayedColumns: string[] = [
'name',
'fromDate',
'toDate',
'repaymentsRescheduledTo',
'status'
];
/** Data source for holidays table. */
dataSource: MatTableDataSource<any>;
@@ -58,12 +63,14 @@ export class HolidaysComponent implements OnInit, AfterViewInit {
* @param {ConfigurationWizardService} configurationWizardService ConfigurationWizard Service.
* @param {PopoverService} popoverService PopoverService.
*/
constructor(private organizationService: OrganizationService,
private route: ActivatedRoute,
private router: Router,
private configurationWizardService: ConfigurationWizardService,
private popoverService: PopoverService) {
this.route.data.subscribe(( data: { offices: any }) => {
constructor(
private organizationService: OrganizationService,
private route: ActivatedRoute,
private router: Router,
private configurationWizardService: ConfigurationWizardService,
private popoverService: PopoverService
) {
this.route.data.subscribe((data: { offices: any }) => {
this.officeData = data.offices;
});
}
@@ -112,7 +119,12 @@ export class HolidaysComponent implements OnInit, AfterViewInit {
* @param position String.
* @param backdrop Boolean.
*/
showPopover(template: TemplateRef<any>, target: HTMLElement | ElementRef<any>, position: string, backdrop: boolean): void {
showPopover(
template: TemplateRef<any>,
target: HTMLElement | ElementRef<any>,
position: string,
backdrop: boolean
): void {
setTimeout(() => this.popoverService.open(template, target, position, backdrop, {}), 200);
}
@@ -122,13 +134,13 @@ export class HolidaysComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
if (this.configurationWizardService.showHolidayPage === true) {
setTimeout(() => {
this.showPopover(this.templateButtonCreateHoliday, this.buttonCreateHoliday.nativeElement, 'bottom', true);
this.showPopover(this.templateButtonCreateHoliday, this.buttonCreateHoliday.nativeElement, 'bottom', true);
});
}
if (this.configurationWizardService.showHolidayFilter === true) {
setTimeout(() => {
this.showPopover(this.templateFilterRef, this.filterRef.nativeElement, 'bottom', true);
this.showPopover(this.templateFilterRef, this.filterRef.nativeElement, 'bottom', true);
});
}
}
@@ -8,9 +8,8 @@ describe('ViewHolidaysComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ViewHolidaysComponent ]
})
.compileComponents();
declarations: [ViewHolidaysComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -20,7 +20,6 @@ import { TranslateService } from '@ngx-translate/core';
styleUrls: ['./view-holidays.component.scss']
})
export class ViewHolidaysComponent {
/** Holiday data. */
holidayData: any;
@@ -28,11 +27,13 @@ export class ViewHolidaysComponent {
* Retrieves hioliday data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute,
constructor(
private route: ActivatedRoute,
private router: Router,
private dialog: MatDialog,
private translateService: TranslateService,
private organizationService: OrganizationService) {
private organizationService: OrganizationService
) {
this.route.data.subscribe((data: { holidays: any }) => {
this.holidayData = data.holidays;
});
@@ -47,10 +48,9 @@ export class ViewHolidaysComponent {
});
deleteHolidayDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.organizationService.deleteHoliday(this.holidayData.id)
.subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
this.organizationService.deleteHoliday(this.holidayData.id).subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
});
}
@@ -60,16 +60,20 @@ export class ViewHolidaysComponent {
*/
activateHoliday() {
const unAssignStaffDialogRef = this.dialog.open(ConfirmationDialogComponent, {
data: { heading: this.translateService.instant('labels.heading.Holiday'), dialogContext: this.translateService.instant('labels.dialogContext.Are you sure you want to activate') + ` ${this.holidayData.name} ` + this.translateService.instant('labels.dialogContext.holiday') }
data: {
heading: this.translateService.instant('labels.heading.Holiday'),
dialogContext:
this.translateService.instant('labels.dialogContext.Are you sure you want to activate') +
` ${this.holidayData.name} ` +
this.translateService.instant('labels.dialogContext.holiday')
}
});
unAssignStaffDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
if (response.confirm) {
this.organizationService.activateHoliday(this.holidayData.id)
.subscribe(() => {
this.router.navigate(['/organization/holidays']);
});
this.organizationService.activateHoliday(this.holidayData.id).subscribe(() => {
this.router.navigate(['/organization/holidays']);
});
}
});
}
}