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('CreateSurveyComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateSurveyComponent ]
})
.compileComponents();
declarations: [CreateSurveyComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -20,7 +20,6 @@ import { CancelDialogComponent } from '../../../shared/cancel-dialog/cancel-dial
styleUrls: ['./create-survey.component.scss']
})
export class CreateSurveyComponent implements OnInit {
/** Survey form. */
surveyForm: UntypedFormGroup;
@@ -31,11 +30,13 @@ export class CreateSurveyComponent implements OnInit {
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
*/
constructor(private formBuilder: UntypedFormBuilder,
private systemService: SystemService,
private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog) { }
constructor(
private formBuilder: UntypedFormBuilder,
private systemService: SystemService,
private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog
) {}
/**
* Creates the survey form.
@@ -49,11 +50,22 @@ export class CreateSurveyComponent implements OnInit {
*/
createSurveyForm() {
this.surveyForm = this.formBuilder.group({
'key': ['', Validators.required],
'name': ['', Validators.required],
'countryCode': ['', [Validators.required, Validators.pattern('^\\s*([A-Za-z]{2})?\\s*$')]],
'description': [''],
'questionDatas': this.formBuilder.array([])
key: [
'',
Validators.required
],
name: [
'',
Validators.required
],
countryCode: [
'',
[
Validators.required,
Validators.pattern('^\\s*([A-Za-z]{2})?\\s*$')]
],
description: [''],
questionDatas: this.formBuilder.array([])
});
}
@@ -71,7 +83,11 @@ export class CreateSurveyComponent implements OnInit {
* @returns {FormArray} Responses form array.
*/
getResponseDatas(questionIndex: number): UntypedFormArray {
return this.surveyForm.get(['questionDatas', questionIndex, 'responseDatas']) as UntypedFormArray;
return this.surveyForm.get([
'questionDatas',
questionIndex,
'responseDatas'
]) as UntypedFormArray;
}
/**
@@ -80,11 +96,17 @@ export class CreateSurveyComponent implements OnInit {
*/
createQuestionForm(): UntypedFormGroup {
return this.formBuilder.group({
'key': ['', Validators.required],
'text': ['', Validators.required],
'description': [''],
'responseDatas': this.formBuilder.array([this.createResponseForm()]),
'sequenceNo': ['']
key: [
'',
Validators.required
],
text: [
'',
Validators.required
],
description: [''],
responseDatas: this.formBuilder.array([this.createResponseForm()]),
sequenceNo: ['']
});
}
@@ -111,9 +133,17 @@ export class CreateSurveyComponent implements OnInit {
*/
createResponseForm(): UntypedFormGroup {
return this.formBuilder.group({
'text': ['', Validators.required],
'value': ['', [Validators.required, Validators.pattern('^\\s*[-]?\\d{0,4}\\s*$')]],
'sequenceNo': ['']
text: [
'',
Validators.required
],
value: [
'',
[
Validators.required,
Validators.pattern('^\\s*[-]?\\d{0,4}\\s*$')]
],
sequenceNo: ['']
});
}
@@ -141,9 +171,15 @@ export class CreateSurveyComponent implements OnInit {
*/
updateSequenceNumber() {
for (let questionIndex = 0; questionIndex < this.questionDatas.length; questionIndex++) {
this.questionDatas.at(questionIndex).get('sequenceNo').setValue(questionIndex + 1);
this.questionDatas
.at(questionIndex)
.get('sequenceNo')
.setValue(questionIndex + 1);
for (let responseIndex = 0; responseIndex < this.getResponseDatas(questionIndex).length; responseIndex++) {
this.getResponseDatas(questionIndex).at(responseIndex).get('sequenceNo').setValue(responseIndex + 1);
this.getResponseDatas(questionIndex)
.at(responseIndex)
.get('sequenceNo')
.setValue(responseIndex + 1);
}
}
}
@@ -188,5 +224,4 @@ export class CreateSurveyComponent implements OnInit {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}
@@ -8,9 +8,8 @@ describe('EditSurveyComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ EditSurveyComponent ]
})
.compileComponents();
declarations: [EditSurveyComponent]
}).compileComponents();
});
beforeEach(() => {
@@ -23,7 +23,6 @@ import { Survey, QuestionData, ResponseData } from './../survey.model';
styleUrls: ['./edit-survey.component.scss']
})
export class EditSurveyComponent {
/** Survey form. */
surveyForm: UntypedFormGroup;
@@ -34,27 +33,29 @@ export class EditSurveyComponent {
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
*/
constructor(private formBuilder: UntypedFormBuilder,
private systemService: SystemService,
private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog) {
this.createSurveyForm();
this.route.data.subscribe((data: { survey: any }) => {
this.prepareSurveyForm(data.survey);
});
}
constructor(
private formBuilder: UntypedFormBuilder,
private systemService: SystemService,
private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog
) {
this.createSurveyForm();
this.route.data.subscribe((data: { survey: any }) => {
this.prepareSurveyForm(data.survey);
});
}
/**
* Takes an object of type Survey
* and prepares the survey form.
*/
prepareSurveyForm(survey: Survey) {
this.surveyForm.get('key').setValue(survey.key);
this.surveyForm.get('name').setValue(survey.name);
this.surveyForm.get('countryCode').setValue(survey.countryCode);
this.surveyForm.get('description').setValue(survey.description);
this.prepareQuestionDatas(this.questionDatas, survey.questionDatas);
this.surveyForm.get('key').setValue(survey.key);
this.surveyForm.get('name').setValue(survey.name);
this.surveyForm.get('countryCode').setValue(survey.countryCode);
this.surveyForm.get('description').setValue(survey.description);
this.prepareQuestionDatas(this.questionDatas, survey.questionDatas);
}
/**
@@ -68,7 +69,7 @@ export class EditSurveyComponent {
questionForm.get('text').setValue(questionData.text);
questionForm.get('description').setValue(questionData.description);
// questionForm.get('responseDatas').setValue([]);
this.prepareResponseDatas((<UntypedFormArray>questionForm.get('responseDatas')), questionData.responseDatas, idx);
this.prepareResponseDatas(<UntypedFormArray>questionForm.get('responseDatas'), questionData.responseDatas, idx);
});
}
@@ -92,11 +93,22 @@ export class EditSurveyComponent {
*/
createSurveyForm() {
this.surveyForm = this.formBuilder.group({
'key': ['', Validators.required],
'name': ['', Validators.required],
'countryCode': ['', [Validators.required, Validators.pattern('^\\s*([A-Za-z]{2})?\\s*$')]],
'description': [''],
'questionDatas': this.formBuilder.array([])
key: [
'',
Validators.required
],
name: [
'',
Validators.required
],
countryCode: [
'',
[
Validators.required,
Validators.pattern('^\\s*([A-Za-z]{2})?\\s*$')]
],
description: [''],
questionDatas: this.formBuilder.array([])
});
}
@@ -114,7 +126,11 @@ export class EditSurveyComponent {
* @returns {FormArray} Responses form array.
*/
getResponseDatas(questionIndex: number): UntypedFormArray {
return this.surveyForm.get(['questionDatas', questionIndex, 'responseDatas']) as UntypedFormArray;
return this.surveyForm.get([
'questionDatas',
questionIndex,
'responseDatas'
]) as UntypedFormArray;
}
/**
@@ -123,11 +139,17 @@ export class EditSurveyComponent {
*/
createQuestionForm(): UntypedFormGroup {
return this.formBuilder.group({
'key': ['', Validators.required],
'text': ['', Validators.required],
'description': [''],
'responseDatas': this.formBuilder.array([this.createResponseForm()]),
'sequenceNo': ['']
key: [
'',
Validators.required
],
text: [
'',
Validators.required
],
description: [''],
responseDatas: this.formBuilder.array([this.createResponseForm()]),
sequenceNo: ['']
});
}
@@ -154,9 +176,17 @@ export class EditSurveyComponent {
*/
createResponseForm(): UntypedFormGroup {
return this.formBuilder.group({
'text': ['', Validators.required],
'value': ['', [Validators.required, Validators.pattern('^\\s*[-]?\\d{0,4}\\s*$')]],
'sequenceNo': ['']
text: [
'',
Validators.required
],
value: [
'',
[
Validators.required,
Validators.pattern('^\\s*[-]?\\d{0,4}\\s*$')]
],
sequenceNo: ['']
});
}
@@ -184,9 +214,15 @@ export class EditSurveyComponent {
*/
updateSequenceNumber() {
for (let questionIndex = 0; questionIndex < this.questionDatas.length; questionIndex++) {
this.questionDatas.at(questionIndex).get('sequenceNo').setValue(questionIndex + 1);
this.questionDatas
.at(questionIndex)
.get('sequenceNo')
.setValue(questionIndex + 1);
for (let responseIndex = 0; responseIndex < this.getResponseDatas(questionIndex).length; responseIndex++) {
this.getResponseDatas(questionIndex).at(responseIndex).get('sequenceNo').setValue(responseIndex + 1);
this.getResponseDatas(questionIndex)
.at(responseIndex)
.get('sequenceNo')
.setValue(responseIndex + 1);
}
}
}
@@ -227,9 +263,10 @@ export class EditSurveyComponent {
this.surveyForm.patchValue({
countryCode: this.surveyForm.value.countryCode.toUpperCase()
});
this.systemService.editSurvey(this.route.snapshot.paramMap.get('id'), this.surveyForm.value).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
this.systemService
.editSurvey(this.route.snapshot.paramMap.get('id'), this.surveyForm.value)
.subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}
@@ -8,9 +8,8 @@ describe('SurveysComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ManageSurveysComponent ]
})
.compileComponents();
declarations: [ManageSurveysComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -14,14 +14,20 @@ import { SystemService } from '../system.service';
@Component({
selector: 'mifosx-manage-surveys',
templateUrl: './manage-surveys.component.html',
styleUrls: ['./manage-surveys.component.scss'],
styleUrls: ['./manage-surveys.component.scss']
})
export class ManageSurveysComponent implements OnInit {
/* Surveys data */
surveysData: any;
/* Columns to be displayed in manage surveys data table */
displayedColumns: string[] = ['key', 'name', 'description', 'countryCode', 'status', 'action'];
displayedColumns: string[] = [
'key',
'name',
'description',
'countryCode',
'status',
'action'
];
/* Data source for manage surveys data table */
dataSource: MatTableDataSource<any>;
@@ -36,9 +42,9 @@ export class ManageSurveysComponent implements OnInit {
*/
constructor(
private route: ActivatedRoute,
private systemService: SystemService,
private systemService: SystemService
) {
this.route.data.subscribe(( data: { surveys: any }) => {
this.route.data.subscribe((data: { surveys: any }) => {
this.surveysData = data.surveys;
});
}
@@ -50,7 +56,7 @@ export class ManageSurveysComponent implements OnInit {
*/
isActive(validFrom: string, validTo: string) {
const curdate = new Date().toISOString().split('T')[0];
return (curdate >= validFrom && curdate <= validTo);
return curdate >= validFrom && curdate <= validTo;
}
/**
@@ -60,9 +66,12 @@ export class ManageSurveysComponent implements OnInit {
this.setSurveys();
this.dataSource.sortingDataAccessor = (item, property) => {
switch (property) {
case 'status': return this.isActive(item.validFrom, item.validTo);
case 'action': return this.isActive(item.validFrom, item.validTo);
default: return item[property];
case 'status':
return this.isActive(item.validFrom, item.validTo);
case 'action':
return this.isActive(item.validFrom, item.validTo);
default:
return item[property];
}
};
}
@@ -110,5 +119,4 @@ export class ManageSurveysComponent implements OnInit {
survey.validTo = yesterday;
});
}
}
@@ -13,7 +13,6 @@ import { SystemService } from '../system.service';
*/
@Injectable()
export class ManageSurveysResolver implements Resolve<Object> {
/**
* @param {SystemService} systemService System service.
*/
@@ -26,5 +25,4 @@ export class ManageSurveysResolver implements Resolve<Object> {
resolve(): Observable<any> {
return this.systemService.getSurveys();
}
}
+16 -16
View File
@@ -1,24 +1,24 @@
export class Survey {
id: number;
key: string;
name: string;
countryCode: string;
description: string;
questionDatas: Array<QuestionData>;
id: number;
key: string;
name: string;
countryCode: string;
description: string;
questionDatas: Array<QuestionData>;
}
export class QuestionData {
id: number;
key: string;
sequenceNo: number;
text: string;
description: string;
responseDatas: Array<ResponseData>;
id: number;
key: string;
sequenceNo: number;
text: string;
description: string;
responseDatas: Array<ResponseData>;
}
export class ResponseData {
id: number;
sequenceNo: number;
text: string;
value: number;
id: number;
sequenceNo: number;
text: string;
value: number;
}
@@ -13,7 +13,6 @@ import { SystemService } from '../system.service';
*/
@Injectable()
export class SurveyResolver implements Resolve<Object> {
/**
* @param {SystemService} systemService System service.
*/
@@ -27,5 +26,4 @@ export class SurveyResolver implements Resolve<Object> {
const surveyId = route.paramMap.get('id');
return this.systemService.getSurvey(surveyId);
}
}
@@ -8,9 +8,8 @@ describe('ViewSurveyComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ViewSurveyComponent ]
})
.compileComponents();
declarations: [ViewSurveyComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -15,12 +15,14 @@ import { SystemService } from 'app/system/system.service';
styleUrls: ['./view-survey.component.scss']
})
export class ViewSurveyComponent {
/** Survey Data */
surveyData: any;
/** Columns shown in individual survey table */
displayedColumns: string[] = [ 'text', 'value'];
displayedColumns: string[] = [
'text',
'value'
];
/**
* Retrieves the survey data from `resolve`.
@@ -29,10 +31,12 @@ export class ViewSurveyComponent {
* @param {MatDialog} dialog Dialog Reference.
* @param {Router} router Router for navigation.
*/
constructor(private route: ActivatedRoute,
private systemService: SystemService,
private dialog: MatDialog,
private router: Router) {
constructor(
private route: ActivatedRoute,
private systemService: SystemService,
private dialog: MatDialog,
private router: Router
) {
this.route.data.subscribe((data: { survey: any }) => {
this.surveyData = data.survey;
});