Skip to content

Commit 7eb5aef

Browse files
authored
Merge pull request #608 from microting/copilot/update-components-to-inject-pattern
Migrate all components from constructor-based DI to inject() pattern
2 parents d02cb97 + f10025d commit 7eb5aef

File tree

80 files changed

+1019
-873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1019
-873
lines changed

eform-client/src/app/plugins/modules/backend-configuration-pn/components/area-rule-entity-list-modal/area-rule-entity-list-modal.component.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, EventEmitter, Inject, OnDestroy, OnInit,} from '@angular/core';
1+
import {Component, EventEmitter, OnDestroy, OnInit,
2+
inject
3+
} from '@angular/core';
24
import {EntityItemModel} from 'src/app/common/models';
35
import { EntityItemEditNameComponent } from 'src/app/common/modules/eform-shared/components';
46
import {EntitySelectService} from 'src/app/common/services';
@@ -16,21 +18,23 @@ import {Subscription} from 'rxjs';
1618
standalone: false
1719
})
1820
export class AreaRuleEntityListModalComponent implements OnInit, OnDestroy {
21+
private entitySelectService = inject(EntitySelectService);
22+
public dialog = inject(MatDialog);
23+
private overlay = inject(Overlay);
24+
public dialogRef = inject(MatDialogRef<AreaRuleEntityListModalComponent>);
25+
private groupId = inject<number | undefined>(MAT_DIALOG_DATA);
26+
1927
entityListChanged: EventEmitter<Array<EntityItemModel>> = new EventEmitter<Array<EntityItemModel>>();
2028
entityList: Array<EntityItemModel> = [];
2129

2230
entityItemEditNameComponentAfterClosedSub$: Subscription;
2331
getEntitySelectableGroupSub$: Subscription;
2432

25-
constructor(
26-
private entitySelectService: EntitySelectService,
27-
public dialog: MatDialog,
28-
private overlay: Overlay,
29-
public dialogRef: MatDialogRef<AreaRuleEntityListModalComponent>,
30-
@Inject(MAT_DIALOG_DATA) groupId?: number
31-
) {
32-
if (groupId) {
33-
this.getEntitySelectableGroupSub$ = this.entitySelectService.getEntitySelectableGroup(groupId)
33+
34+
35+
ngOnInit() {
36+
if (this.groupId) {
37+
this.getEntitySelectableGroupSub$ = this.entitySelectService.getEntitySelectableGroup(this.groupId)
3438
.subscribe(data => {
3539
if (data && data.success && data.model) {
3640
this.entityList = [...data.model.entityGroupItemLst];
@@ -43,9 +47,7 @@ export class AreaRuleEntityListModalComponent implements OnInit, OnDestroy {
4347
}
4448
})
4549
}
46-
}
47-
48-
ngOnInit() {}
50+
}
4951

5052
hide() {
5153
this.dialogRef.close();

eform-client/src/app/plugins/modules/backend-configuration-pn/components/area-rule-plan-modal/area-rule-plan-modal.component.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
Component,
33
EventEmitter,
4-
Inject,
54
OnInit,
5+
inject
66
} from '@angular/core';
77
import {format} from 'date-fns';
88
import {
@@ -32,6 +32,15 @@ import {generateWeeksList} from '../../helpers';
3232
standalone: false
3333
})
3434
export class AreaRulePlanModalComponent implements OnInit {
35+
private translate = inject(TranslateService);
36+
public dialogRef = inject(MatDialogRef<AreaRulePlanModalComponent>);
37+
private model = inject<{
38+
areaRule: AreaRuleSimpleModel | AreaRuleNameAndTypeSpecificFields,
39+
propertyId: number,
40+
area: AreaModel,
41+
areaRulePlan: AreaRulePlanningModel,
42+
}>(MAT_DIALOG_DATA);
43+
3544
updateAreaRulePlan: EventEmitter<AreaRulePlanningModel> = new EventEmitter<AreaRulePlanningModel>();
3645
selectedArea: AreaModel = new AreaModel();
3746
selectedAreaRulePlanning: AreaRulePlanningModel = new AreaRulePlanningModel();
@@ -104,23 +113,14 @@ export class AreaRulePlanModalComponent implements OnInit {
104113
return this.selectedArea.availableWorkers.filter(x => assignedSites.some(y => y === x.siteId));
105114
}
106115

107-
constructor(
108-
private translate: TranslateService,
109-
public dialogRef: MatDialogRef<AreaRulePlanModalComponent>,
110-
@Inject(MAT_DIALOG_DATA) model: {
111-
areaRule: AreaRuleSimpleModel | AreaRuleNameAndTypeSpecificFields,
112-
propertyId: number,
113-
area: AreaModel,
114-
areaRulePlan: AreaRulePlanningModel,
115-
},
116-
) {
117-
this.setData(model.areaRule, model.propertyId, model.area, model.areaRulePlan);
118-
}
116+
119117

120118
ngOnInit() {
119+
this.setData(this.model.areaRule, this.model.propertyId, this.model.area, this.model.areaRulePlan);
120+
121121
this.repeatTypeDay = R.map(x => {
122122
return {name: x === 1 ? this.translate.instant('Every') : x.toString(), id: x};
123-
}, R.range(1, 31)); // 1, 2, ..., 29, 30.
123+
}, R.range(1, 31)); // 1, 2, ..., 29, 30.
124124
this.repeatTypeWeek = R.map(x => {
125125
return {name: x === 1 ? this.translate.instant('Every') : x.toString(), id: x};
126126
}, R.range(1, 51)); // 1, 2, ..., 49, 50.

eform-client/src/app/plugins/modules/backend-configuration-pn/components/backend-configuration-case/backend-configuration-case-page/backend-configuration-case-page.component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
QueryList,
55
ViewChild,
66
ViewChildren,
7+
inject
78
} from '@angular/core';
89
import {ActivatedRoute, Router} from '@angular/router';
910
import {EFormService, CasesService} from 'src/app/common/services';
@@ -27,6 +28,13 @@ import {Store} from '@ngrx/store';
2728
standalone: false
2829
})
2930
export class BackendConfigurationCasePageComponent implements OnInit {
31+
private activateRoute = inject(ActivatedRoute);
32+
private casesService = inject(CasesService);
33+
private store = inject(Store);
34+
private eFormService = inject(EFormService);
35+
private router = inject(Router);
36+
private backendConfigurationPnCasesService = inject(BackendConfigurationPnCasesService);
37+
3038
@ViewChildren(CaseEditElementComponent)
3139
editElements: QueryList<CaseEditElementComponent>;
3240
@ViewChild('caseConfirmation', { static: false }) caseConfirmation;
@@ -41,14 +49,9 @@ export class BackendConfigurationCasePageComponent implements OnInit {
4149
maxDate: Date;
4250
initialDate: Date;
4351

44-
constructor(
45-
private activateRoute: ActivatedRoute,
46-
private casesService: CasesService,
47-
private store: Store,
48-
private eFormService: EFormService,
49-
private router: Router,
50-
private backendConfigurationPnCasesService: BackendConfigurationPnCasesService
51-
) {
52+
53+
54+
ngOnInit() {
5255
this.activateRoute.params.subscribe((params) => {
5356
this.id = +params['id'];
5457
this.planningId = +params['planningId'];
@@ -57,9 +60,7 @@ export class BackendConfigurationCasePageComponent implements OnInit {
5760
this.activateRoute.queryParams.subscribe((queryParams) => {
5861
this.reverseRoute = queryParams['reverseRoute'];
5962
})
60-
}
6163

62-
ngOnInit() {
6364
this.loadTemplateInfo();
6465
this.maxDate = new Date();
6566
}

eform-client/src/app/plugins/modules/backend-configuration-pn/components/properties/properties-page/properties-container/properties-container.component.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, OnDestroy, OnInit} from '@angular/core';
1+
import {Component, OnDestroy, OnInit,
2+
inject
3+
} from '@angular/core';
24
import {AutoUnsubscribe} from 'ngx-auto-unsubscribe';
35
import {Subject, Subscription} from 'rxjs';
46
import {EntityItemModel, Paged} from 'src/app/common/models';
@@ -33,6 +35,14 @@ import {dialogConfigHelper} from 'src/app/common/helpers';
3335
standalone: false
3436
})
3537
export class PropertiesContainerComponent implements OnInit, OnDestroy {
38+
private propertiesService = inject(BackendConfigurationPnPropertiesService);
39+
public propertiesStateService = inject(PropertiesStateService);
40+
public authStateService = inject(AuthStateService);
41+
private entitySelectService = inject(EntitySelectService);
42+
private translateService = inject(TranslateService);
43+
private dialog = inject(MatDialog);
44+
private overlay = inject(Overlay);
45+
3646
isFarms: boolean = false;
3747
tableHeaders: MtxGridColumn[] = [
3848
{
@@ -127,26 +137,18 @@ export class PropertiesContainerComponent implements OnInit, OnDestroy {
127137
updateEntitySelectableGroupSub$: Subscription;
128138
nameSearchSubjectSub$: Subscription;
129139

130-
constructor(
131-
private propertiesService: BackendConfigurationPnPropertiesService,
132-
public propertiesStateService: PropertiesStateService,
133-
public authStateService: AuthStateService,
134-
private entitySelectService: EntitySelectService,
135-
private translateService: TranslateService,
136-
private dialog: MatDialog,
137-
private overlay: Overlay,
138-
) {
139-
this.nameSearchSubjectSub$ = this.nameSearchSubject.pipe(debounceTime(500)).subscribe((val) => {
140-
this.propertiesStateService.updateNameFilter(val.toString());
141-
this.getProperties();
142-
});
143-
}
140+
144141

145142
// get backendConfigurationPnClaims() {
146143
// return BackendConfigurationPnClaims;
147144
// }
148145

149146
ngOnInit() {
147+
this.nameSearchSubjectSub$ = this.nameSearchSubject.pipe(debounceTime(500)).subscribe((val) => {
148+
this.propertiesStateService.updateNameFilter(val.toString());
149+
this.getProperties();
150+
});
151+
150152
this.getProperties();
151153
}
152154

eform-client/src/app/plugins/modules/backend-configuration-pn/components/properties/properties-page/properties-table/properties-table.component.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output,} from '@angular/core';
1+
import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output,
2+
inject
3+
} from '@angular/core';
24
import {Paged, TableHeaderElementModel} from 'src/app/common/models';
35
import {PropertyModel} from '../../../../models/properties';
46
import {PropertiesStateService} from '../../store';
@@ -28,6 +30,13 @@ import {
2830
standalone: false
2931
})
3032
export class PropertiesTableComponent implements OnInit {
33+
private store = inject(Store);
34+
public propertiesStateService = inject(PropertiesStateService);
35+
private entitySelectService = inject(EntitySelectService);
36+
public authStateService = inject(AuthStateService);
37+
private iconRegistry = inject(MatIconRegistry);
38+
private sanitizer = inject(DomSanitizer);
39+
3140
@Input() nameSearchSubject = new Subject();
3241
@Input() propertiesModel: Paged<PropertyModel> = new Paged<PropertyModel>();
3342

@@ -58,17 +67,12 @@ export class PropertiesTableComponent implements OnInit {
5867
return PropertyCompliancesColorBadgesEnum;
5968
}
6069

61-
constructor(
62-
private store: Store,
63-
public propertiesStateService: PropertiesStateService,
64-
private entitySelectService: EntitySelectService,
65-
public authStateService: AuthStateService,
66-
iconRegistry: MatIconRegistry,
67-
sanitizer: DomSanitizer,
68-
) {
69-
iconRegistry.addSvgIconLiteral('file-word', sanitizer.bypassSecurityTrustHtml(WordIcon));
70+
71+
constructor() {
72+
this.iconRegistry.addSvgIconLiteral('file-word', this.sanitizer.bypassSecurityTrustHtml(WordIcon));
7073
}
7174

75+
7276
ngOnInit(): void {
7377
this.tableHeaders = [
7478
{ header: 'ID', field: 'id', sortable: true },

eform-client/src/app/plugins/modules/backend-configuration-pn/components/properties/property-actions/property-create-modal/property-create-modal.component.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Component, EventEmitter, OnDestroy, OnInit } from '@angular/core';
1+
import { Component, EventEmitter, OnDestroy, OnInit,
2+
inject
3+
} from '@angular/core';
24
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
35
import { applicationLanguages, applicationLanguagesTranslated } from 'src/app/common/const';
46
import { PropertyCreateModel } from '../../../../models';
@@ -16,6 +18,11 @@ import { Subscription } from 'rxjs';
1618
standalone: false
1719
})
1820
export class PropertyCreateModalComponent implements OnInit, OnDestroy {
21+
private fb = inject(FormBuilder);
22+
public authStateService = inject(AuthStateService);
23+
private propertiesService = inject(BackendConfigurationPnPropertiesService);
24+
public dialogRef = inject(MatDialogRef<PropertyCreateModalComponent>);
25+
1926
propertyCreate: EventEmitter<PropertyCreateModel> = new EventEmitter<PropertyCreateModel>();
2027
newPropertyForm: FormGroup;
2128
newProperty: PropertyCreateModel = new PropertyCreateModel();
@@ -29,12 +36,12 @@ export class PropertyCreateModalComponent implements OnInit, OnDestroy {
2936
return applicationLanguages;
3037
}
3138

32-
constructor(
33-
private fb: FormBuilder,
34-
public authStateService: AuthStateService,
35-
private propertiesService: BackendConfigurationPnPropertiesService,
36-
public dialogRef: MatDialogRef<PropertyCreateModalComponent>
37-
) {
39+
40+
41+
ngOnDestroy(): void {
42+
}
43+
44+
ngOnInit() {
3845
this.propertyIsFarm = false;
3946

4047
// Initialize reactive form
@@ -47,12 +54,7 @@ export class PropertyCreateModalComponent implements OnInit, OnDestroy {
4754
workorderEnable: [false],
4855
isFarm: [false]
4956
});
50-
}
5157

52-
ngOnDestroy(): void {
53-
}
54-
55-
ngOnInit() {
5658
}
5759

5860
hide() {

eform-client/src/app/plugins/modules/backend-configuration-pn/components/properties/property-actions/property-delete-modal/property-delete-modal.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
Component,
33
EventEmitter,
4-
Inject,
54
OnInit,
5+
inject
66
} from '@angular/core';
77
import { PropertyModel } from '../../../../models';
88
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
@@ -14,12 +14,12 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
1414
standalone: false
1515
})
1616
export class PropertyDeleteModalComponent implements OnInit {
17+
public dialogRef = inject(MatDialogRef<PropertyDeleteModalComponent>);
18+
public propertyModel = inject<PropertyModel>(MAT_DIALOG_DATA);
19+
1720
propertyDelete: EventEmitter<number> = new EventEmitter<number>();
1821

19-
constructor(
20-
public dialogRef: MatDialogRef<PropertyDeleteModalComponent>,
21-
@Inject(MAT_DIALOG_DATA) public propertyModel: PropertyModel = new PropertyModel()
22-
) {}
22+
2323

2424
ngOnInit() {}
2525

eform-client/src/app/plugins/modules/backend-configuration-pn/components/properties/property-actions/property-docx-report-modal/property-docx-report-modal.component.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
Component,
3-
Inject,
43
OnDestroy,
54
OnInit,
5+
inject
66
} from '@angular/core';
77
import {PropertyAreaModel,} from '../../../../models';
88
import {BackendConfigurationPnPropertiesService, BackendConfigurationPnReportService} from '../../../../services';
@@ -22,6 +22,12 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
2222
standalone: false
2323
})
2424
export class PropertyDocxReportModalComponent implements OnInit, OnDestroy {
25+
private backendConfigurationPnPropertiesService = inject(BackendConfigurationPnPropertiesService);
26+
private reportService = inject(BackendConfigurationPnReportService);
27+
private toasterService = inject(ToastrService);
28+
public dialogRef = inject(MatDialogRef<PropertyDocxReportModalComponent>);
29+
public propertyId = inject<number>(MAT_DIALOG_DATA);
30+
2531
selectedArea: PropertyAreaModel;
2632
selectedYear: number;
2733
areasList: PropertyAreaModel[] = [];
@@ -30,23 +36,17 @@ export class PropertyDocxReportModalComponent implements OnInit, OnDestroy {
3036
downloadReportSub$: Subscription;
3137
getPropertyAreasSub$: Subscription;
3238

33-
constructor(
34-
private backendConfigurationPnPropertiesService: BackendConfigurationPnPropertiesService,
35-
private reportService: BackendConfigurationPnReportService,
36-
private toasterService: ToastrService,
37-
public dialogRef: MatDialogRef<PropertyDocxReportModalComponent>,
38-
@Inject(MAT_DIALOG_DATA) public propertyId: number
39-
) {
39+
40+
41+
ngOnInit() {
4042
this.getPropertyAreasSub$ = this.backendConfigurationPnPropertiesService
41-
.getPropertyAreas(propertyId)
43+
.getPropertyAreas(this.propertyId)
4244
.subscribe((data) => {
4345
if (data && data.success && data.model) {
4446
this.areasList = data.model.filter(x => x.activated && x.name === '24. IE-indberetning');
4547
}
4648
});
47-
}
4849

49-
ngOnInit() {
5050
const currentYear = new Date().getFullYear();
5151
this.years = R.range(currentYear - 1, currentYear + 10);
5252
}

0 commit comments

Comments
 (0)