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
@@ -8,9 +8,8 @@ describe('AmountCollectedPieComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AmountCollectedPieComponent ]
})
.compileComponents();
declarations: [AmountCollectedPieComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -18,7 +18,6 @@ import Chart from 'chart.js';
styleUrls: ['./amount-collected-pie.component.scss']
})
export class AmountCollectedPieComponent implements OnInit {
/** Static Form control for office Id */
officeId = new UntypedFormControl();
/** Office Data */
@@ -35,9 +34,11 @@ export class AmountCollectedPieComponent implements OnInit {
* @param {HomeService} homeService Home Service.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private homeService: HomeService,
private route: ActivatedRoute) {
this.route.data.subscribe( (data: { offices: any }) => {
constructor(
private homeService: HomeService,
private route: ActivatedRoute
) {
this.route.data.subscribe((data: { offices: any }) => {
this.officeData = data.offices;
});
}
@@ -57,7 +58,7 @@ export class AmountCollectedPieComponent implements OnInit {
getChartData() {
this.officeId.valueChanges.subscribe((value: number) => {
this.homeService.getCollectedAmount(value).subscribe((response: any) => {
const data = Object.entries(response[0]).map(entry => entry[1]);
const data = Object.entries(response[0]).map((entry) => entry[1]);
if (!(data[0] === 0 && data[1] === 0)) {
this.setChart(data);
this.hideOutput = false;
@@ -80,11 +81,19 @@ export class AmountCollectedPieComponent implements OnInit {
this.chart = new Chart('collection-pie', {
type: 'doughnut',
data: {
labels: ['Pending', 'Collected'],
datasets: [{
backgroundColor: ['dodgerblue', 'red'],
data: data
}]
labels: [
'Pending',
'Collected'
],
datasets: [
{
backgroundColor: [
'dodgerblue',
'red'
],
data: data
}
]
},
options: {
layout: {
@@ -100,5 +109,4 @@ export class AmountCollectedPieComponent implements OnInit {
this.chart.update();
}
}
}
@@ -8,9 +8,8 @@ describe('AmountDisbursedPieComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AmountDisbursedPieComponent ]
})
.compileComponents();
declarations: [AmountDisbursedPieComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -18,26 +18,27 @@ import Chart from 'chart.js';
styleUrls: ['./amount-disbursed-pie.component.scss']
})
export class AmountDisbursedPieComponent implements OnInit {
/** Static Form control for office Id */
officeId = new UntypedFormControl();
/** Office Data */
officeData: any;
/** Chart.js chart */
chart: any;
/** Substitute for resolver */
hideOutput = true;
/** Shows fallback element */
showFallback = true;
/** Static Form control for office Id */
officeId = new UntypedFormControl();
/** Office Data */
officeData: any;
/** Chart.js chart */
chart: any;
/** Substitute for resolver */
hideOutput = true;
/** Shows fallback element */
showFallback = true;
/**
* Fetches offices data from `resolve`.
* @param {HomeService} homeService Home Service.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private homeService: HomeService,
private route: ActivatedRoute) {
this.route.data.subscribe( (data: { offices: any }) => {
constructor(
private homeService: HomeService,
private route: ActivatedRoute
) {
this.route.data.subscribe((data: { offices: any }) => {
this.officeData = data.offices;
});
}
@@ -57,7 +58,7 @@ export class AmountDisbursedPieComponent implements OnInit {
getChartData() {
this.officeId.valueChanges.subscribe((value: number) => {
this.homeService.getDisbursedAmount(value).subscribe((response: any) => {
const data = Object.entries(response[0]).map(entry => entry[1]);
const data = Object.entries(response[0]).map((entry) => entry[1]);
if (!(data[0] === 0 && data[1] === 0)) {
this.setChart(data);
this.showFallback = false;
@@ -80,11 +81,19 @@ export class AmountDisbursedPieComponent implements OnInit {
this.chart = new Chart('disbursement-pie', {
type: 'doughnut',
data: {
labels: ['Pending', 'Disbursed'],
datasets: [{
backgroundColor: ['dodgerblue', 'red'],
data: data
}]
labels: [
'Pending',
'Disbursed'
],
datasets: [
{
backgroundColor: [
'dodgerblue',
'red'
],
data: data
}
]
},
options: {
layout: {
@@ -100,5 +109,4 @@ export class AmountDisbursedPieComponent implements OnInit {
this.chart.update();
}
}
}
@@ -8,9 +8,8 @@ describe('ClientTrendsBarComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ClientTrendsBarComponent ]
})
.compileComponents();
declarations: [ClientTrendsBarComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -23,7 +23,6 @@ import Chart from 'chart.js';
styleUrls: ['./client-trends-bar.component.scss']
})
export class ClientTrendsBarComponent implements OnInit {
/** Static Form control for office Id */
officeId = new UntypedFormControl();
/** Static Form control for time scale */
@@ -41,10 +40,12 @@ export class ClientTrendsBarComponent implements OnInit {
* @param {ActivatedRoute} route Activated Route
* @param {Dates} dateUtils Date Utils
*/
constructor(private homeService: HomeService,
private route: ActivatedRoute,
private dateUtils: Dates) {
this.route.data.subscribe( (data: { offices: any }) => {
constructor(
private homeService: HomeService,
private route: ActivatedRoute,
private dateUtils: Dates
) {
this.route.data.subscribe((data: { offices: any }) => {
this.officeData = data.offices;
});
}
@@ -67,7 +68,8 @@ export class ClientTrendsBarComponent implements OnInit {
* Fetches data accordingly and sets charts based on fetched data.
*/
getChartData() {
merge(this.officeId.valueChanges, this.timescale.valueChanges).pipe(skip(1))
merge(this.officeId.valueChanges, this.timescale.valueChanges)
.pipe(skip(1))
.subscribe(() => {
const officeId = this.officeId.value;
const timescale = this.timescale.value;
@@ -75,7 +77,10 @@ export class ClientTrendsBarComponent implements OnInit {
case 'Day':
const clientsByDay = this.homeService.getClientTrendsByDay(officeId);
const loansByDay = this.homeService.getLoanTrendsByDay(officeId);
forkJoin([clientsByDay, loansByDay]).subscribe((data: any[]) => {
forkJoin([
clientsByDay,
loansByDay
]).subscribe((data: any[]) => {
const dayLabels = this.getLabels(timescale);
const clientCounts = this.getCounts(data[0], dayLabels, timescale, 'client');
const loanCounts = this.getCounts(data[1], dayLabels, timescale, 'loan');
@@ -86,7 +91,10 @@ export class ClientTrendsBarComponent implements OnInit {
case 'Week':
const clientsByWeek = this.homeService.getClientTrendsByWeek(officeId);
const loansByWeek = this.homeService.getLoanTrendsByWeek(officeId);
forkJoin([clientsByWeek, loansByWeek]).subscribe((data: any[]) => {
forkJoin([
clientsByWeek,
loansByWeek
]).subscribe((data: any[]) => {
const weekLabels = this.getLabels(timescale);
const clientCounts = this.getCounts(data[0], weekLabels, timescale, 'client');
const loanCounts = this.getCounts(data[1], weekLabels, timescale, 'loan');
@@ -97,7 +105,10 @@ export class ClientTrendsBarComponent implements OnInit {
case 'Month':
const clientsByMonth = this.homeService.getClientTrendsByMonth(officeId);
const loansByMonth = this.homeService.getLoanTrendsByMonth(officeId);
forkJoin([clientsByMonth, loansByMonth]).subscribe((data: any[]) => {
forkJoin([
clientsByMonth,
loansByMonth
]).subscribe((data: any[]) => {
const monthLabels = this.getLabels(timescale);
const clientCounts = this.getCounts(data[0], monthLabels, timescale, 'client');
const loanCounts = this.getCounts(data[1], monthLabels, timescale, 'loan');
@@ -106,7 +117,7 @@ export class ClientTrendsBarComponent implements OnInit {
});
break;
}
});
});
}
/**
@@ -130,9 +141,7 @@ export class ClientTrendsBarComponent implements OnInit {
while (labelsArray.length < 12) {
date.setDate(date.getDate() - 7);
/** Gets current week number */
const weekNumber = Math.ceil(
(((date.getTime() - onejan.getTime()) / 86400000) + onejan.getDay() + 1) / 7
);
const weekNumber = Math.ceil(((date.getTime() - onejan.getTime()) / 86400000 + onejan.getDay() + 1) / 7);
labelsArray.push(weekNumber);
}
break;
@@ -155,7 +164,7 @@ export class ClientTrendsBarComponent implements OnInit {
* @param {string} type 'client' or 'loan'.
*/
getCounts(response: any[], labels: any[], timescale: string, type: string) {
let counts: number[] = [];
let counts: number[] = [];
switch (timescale) {
case 'Day':
labels.forEach((label: any) => {
@@ -197,10 +206,10 @@ export class ClientTrendsBarComponent implements OnInit {
switch (type) {
case 'client':
counts.push(span.count);
break;
break;
case 'loan':
counts.push(span.lcount);
break;
break;
}
} else {
counts.push(0);
@@ -236,22 +245,22 @@ export class ClientTrendsBarComponent implements OnInit {
backgroundColor: 'red',
borderColor: 'red',
borderWidth: 2,
fill: false,
fill: false
}
]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true,
scaleLabel: {
display: true,
labelString: 'Values',
fontColor: '#1074B9'
}
},
}
scales: {
y: {
beginAtZero: true,
scaleLabel: {
display: true,
labelString: 'Values',
fontColor: '#1074B9'
}
}
}
}
});
} else {
@@ -261,5 +270,4 @@ export class ClientTrendsBarComponent implements OnInit {
this.chart.update();
}
}
}
@@ -8,9 +8,8 @@ describe('DashboardComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DashboardComponent ]
})
.compileComponents();
declarations: [DashboardComponent]
}).compileComponents();
}));
beforeEach(() => {
+29 -20
View File
@@ -14,7 +14,6 @@ import { activities } from '../activities';
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
/** Array of all user activities */
userActivity: string[];
/** Array of most recent user activities */
@@ -52,10 +51,16 @@ export class DashboardComponent implements OnInit {
uniqueActivities.push(activity);
}
});
const topEightRecentActivities =
uniqueActivities
.filter((activity: string) => !['/', '/login', '/home', '/dashboard'].includes(activity))
.slice(0, 8);
const topEightRecentActivities = uniqueActivities
.filter(
(activity: string) => ![
'/',
'/login',
'/home',
'/dashboard'
].includes(activity)
)
.slice(0, 8);
return topEightRecentActivities;
}
@@ -63,18 +68,24 @@ export class DashboardComponent implements OnInit {
* Returns top eight frequent activities.
*/
getFrequentActivities() {
const frequencyCounts: any = {};
let index = this.userActivity.length;
const frequencyCounts: any = {};
let index = this.userActivity.length;
while (index) {
frequencyCounts[this.userActivity[--index]] = (frequencyCounts[this.userActivity[index]] || 0) + 1;
}
const frequencyCountsArray = Object.entries(frequencyCounts);
const topEigthFrequentActivities =
frequencyCountsArray
.sort((a: any, b: any) => b[1] - a[1])
.map((entry: any[]) => entry[0])
.filter((activity: string) => !['/', '/login', '/home', '/dashboard'].includes(activity))
.slice(0, 8);
const topEigthFrequentActivities = frequencyCountsArray
.sort((a: any, b: any) => b[1] - a[1])
.map((entry: any[]) => entry[0])
.filter(
(activity: string) => ![
'/',
'/login',
'/home',
'/dashboard'
].includes(activity)
)
.slice(0, 8);
return topEigthFrequentActivities;
}
@@ -89,10 +100,10 @@ export class DashboardComponent implements OnInit {
* Sets filtered activities for autocomplete.
*/
setFilteredActivities() {
this.filteredActivities = this.searchText.valueChanges
.pipe(
map((activity: any) => typeof activity === 'string' ? activity : activity.activity),
map((activityName: string) => activityName ? this.filterActivity(activityName) : this.allActivities));
this.filteredActivities = this.searchText.valueChanges.pipe(
map((activity: any) => (typeof activity === 'string' ? activity : activity.activity)),
map((activityName: string) => (activityName ? this.filterActivity(activityName) : this.allActivities))
);
}
/**
@@ -102,8 +113,6 @@ export class DashboardComponent implements OnInit {
*/
private filterActivity(activityName: string): any {
const filterValue = activityName.toLowerCase();
return this.allActivities.filter(activity => activity.activity.toLowerCase().indexOf(filterValue) === 0);
return this.allActivities.filter((activity) => activity.activity.toLowerCase().indexOf(filterValue) === 0);
}
}