Skip to content

Commit 562f0d5

Browse files
authored
Merge pull request #1198 from microting/copilot/migrate-components-to-inject-pattern
Migrate all components from constructor-based DI to inject() pattern
2 parents 88902b2 + f70d4a3 commit 562f0d5

File tree

24 files changed

+233
-201
lines changed

24 files changed

+233
-201
lines changed

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/assigned-site/assigned-site-dialog.component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, DoCheck, Inject, OnInit} from '@angular/core';
1+
import {Component, DoCheck, OnInit,
2+
inject
3+
} from '@angular/core';
24
import {
35
MAT_DIALOG_DATA
46
} from '@angular/material/dialog';
@@ -24,22 +26,19 @@ import {
2426
standalone: false
2527
})
2628
export class AssignedSiteDialogComponent implements DoCheck, OnInit {
29+
private fb = inject(FormBuilder);
30+
public data = inject<AssignedSiteModel>(MAT_DIALOG_DATA);
31+
private timePlanningPnSettingsService = inject(TimePlanningPnSettingsService);
32+
private store = inject(Store);
33+
2734
assignedSiteForm!: FormGroup;
2835

2936
public selectCurrentUserIsAdmin$ = this.store.select(selectCurrentUserIsAdmin);
3037
public selectCurrentUserIsFirstUser$ = this.store.select(selectCurrentUserIsFirstUser);
3138
private previousData: AssignedSiteModel;
3239
private globalAutoBreakSettings: GlobalAutoBreakSettingsModel;
3340

34-
constructor(
35-
private fb: FormBuilder,
36-
@Inject(MAT_DIALOG_DATA) public data: AssignedSiteModel,
37-
private timePlanningPnSettingsService: TimePlanningPnSettingsService,
38-
private store: Store
39-
) {
40-
this.previousData = {...data};
41-
// this.calculateHours();
42-
}
41+
4342

4443
ngDoCheck(): void {
4544
if (this.hasDataChanged()) {
@@ -49,6 +48,8 @@ export class AssignedSiteDialogComponent implements DoCheck, OnInit {
4948
}
5049

5150
ngOnInit(): void {
51+
this.previousData = {...this.data};
52+
// this.calculateHours();
5253
this.timePlanningPnSettingsService.getGlobalAutoBreakCalculationSettings().subscribe(result => {
5354
if (result && result.success) {
5455
this.globalAutoBreakSettings = result.model;

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/download-excel/download-excel-dialog.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, Inject, Input, OnDestroy, OnInit} from '@angular/core';
1+
import {Component, OnDestroy, OnInit,
2+
inject
3+
} from '@angular/core';
24
import {EMPTY, Subscription} from 'rxjs';
35
import {MatDatepickerInputEvent} from '@angular/material/datepicker';
46
import {SiteDto} from 'src/app/common/models';
@@ -21,18 +23,17 @@ import {MAT_DIALOG_DATA} from '@angular/material/dialog';
2123
standalone: false,
2224
})
2325
export class DownloadExcelDialogComponent implements OnInit, OnDestroy {
26+
public availableSites = inject<SiteDto[]>(MAT_DIALOG_DATA);
27+
private toastrService = inject(ToastrService);
28+
private workingHoursService = inject(TimePlanningPnWorkingHoursService);
29+
2430
siteId: number;
2531

2632
dateFrom: Date = null;
2733
dateTo: Date = null;
2834
downloadReportSub$: Subscription;
2935

30-
constructor(
31-
@Inject(MAT_DIALOG_DATA) public availableSites: SiteDto[] = [],
32-
private toastrService: ToastrService,
33-
private workingHoursService: TimePlanningPnWorkingHoursService,
34-
) {
35-
}
36+
3637

3738
ngOnInit(): void {
3839
// this.getAvailableSites();

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/workday-entity/workday-entity-dialog.component.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, Inject, OnInit, TemplateRef, ViewChild} from '@angular/core';
1+
import {Component, OnInit, TemplateRef, ViewChild,
2+
inject
3+
} from '@angular/core';
24
import {MAT_DIALOG_DATA} from '@angular/material/dialog';
35
import {TranslateService} from '@ngx-translate/core';
46
import {DatePipe} from '@angular/common';
@@ -26,6 +28,15 @@ import {
2628
standalone: false
2729
})
2830
export class WorkdayEntityDialogComponent implements OnInit {
31+
private fb = inject(FormBuilder);
32+
private planningsService = inject(TimePlanningPnPlanningsService);
33+
public data = inject<{
34+
planningPrDayModels: PlanningPrDayModel,
35+
assignedSiteModel: AssignedSiteModel
36+
}>(MAT_DIALOG_DATA);
37+
protected datePipe = inject(DatePipe);
38+
private translateService = inject(TranslateService);
39+
2940
TimePlanningMessagesEnum = TimePlanningMessagesEnum;
3041
enumKeys: string[] = [];
3142
tableHeaders: MtxGridColumn[] = [];
@@ -54,17 +65,7 @@ export class WorkdayEntityDialogComponent implements OnInit {
5465
private readonly timeRegex = /^([01]\d|2[0-3]):([0-5]\d)$/;
5566
inputErrorMessages: Record<string, Record<string, string>> = {};
5667

57-
constructor(
58-
private fb: FormBuilder,
59-
private planningsService: TimePlanningPnPlanningsService,
60-
@Inject(MAT_DIALOG_DATA) public data: {
61-
planningPrDayModels: PlanningPrDayModel,
62-
assignedSiteModel: AssignedSiteModel
63-
},
64-
protected datePipe: DatePipe,
65-
private translateService: TranslateService,
66-
) {
67-
}
68+
6869

6970
ngOnInit(): void {
7071
// Enum-opsætning

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-container/time-plannings-container.component.ts

Lines changed: 9 additions & 7 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 {Subscription, take} from 'rxjs';
46
import { SiteDto } from 'src/app/common/models';
@@ -23,6 +25,11 @@ import {MatDatepickerInputEvent} from '@angular/material/datepicker';
2325
standalone: false
2426
})
2527
export class TimePlanningsContainerComponent implements OnInit, OnDestroy {
28+
private store = inject(Store);
29+
private planningsService = inject(TimePlanningPnPlanningsService);
30+
private settingsService = inject(TimePlanningPnSettingsService);
31+
private dialog = inject(MatDialog);
32+
2633
timePlanningsRequest: TimePlanningsRequestModel;
2734
availableSites: SiteDto[] = [];
2835
showResignedSites: boolean = false;
@@ -38,12 +45,7 @@ export class TimePlanningsContainerComponent implements OnInit, OnDestroy {
3845
public selectCurrentUserLocale$ = this.store.select(selectCurrentUserLocale);
3946
locale: string;
4047

41-
constructor(
42-
private store: Store,
43-
private planningsService: TimePlanningPnPlanningsService,
44-
private settingsService: TimePlanningPnSettingsService,
45-
private dialog: MatDialog,
46-
) {}
48+
4749

4850
ngOnInit(): void {
4951

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-table/time-plannings-table.component.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output,
3-
SimpleChanges, TemplateRef, ViewChild, ViewEncapsulation
3+
SimpleChanges, TemplateRef, ViewChild, ViewEncapsulation,
4+
inject
45
} from '@angular/core';
56
import {AssignedSiteModel, TimePlanningModel} from '../../../models';
67
import {MtxGridColumn} from '@ng-matero/extensions/grid';
@@ -23,6 +24,14 @@ import {selectAuthIsAdmin, selectCurrentUserIsFirstUser} from "src/app/state";
2324

2425
})
2526
export class TimePlanningsTableComponent implements OnInit, OnChanges {
27+
private store = inject(Store);
28+
private planningsService = inject(TimePlanningPnPlanningsService);
29+
private timePlanningPnSettingsService = inject(TimePlanningPnSettingsService);
30+
private dialog = inject(MatDialog);
31+
private translateService = inject(TranslateService);
32+
protected datePipe = inject(DatePipe);
33+
private cdr = inject(ChangeDetectorRef);
34+
2635
@Input() timePlannings: TimePlanningModel[] = [];
2736
@Input() dateFrom!: Date;
2837
@Input() dateTo!: Date;
@@ -38,16 +47,7 @@ export class TimePlanningsTableComponent implements OnInit, OnChanges {
3847
protected selectAuthIsAdmin$ = this.store.select(selectAuthIsAdmin);
3948
public selectCurrentUserIsFirstUser$ = this.store.select(selectCurrentUserIsFirstUser);
4049

41-
constructor(
42-
private store: Store,
43-
private planningsService: TimePlanningPnPlanningsService,
44-
private timePlanningPnSettingsService: TimePlanningPnSettingsService,
45-
private dialog: MatDialog,
46-
private translateService: TranslateService,
47-
protected datePipe: DatePipe,
48-
private cdr: ChangeDetectorRef
49-
) {
50-
}
50+
5151

5252
ngOnInit(): void {
5353
this.enumKeys = Object.keys(TimePlanningMessagesEnum).filter(key => isNaN(Number(key)));

eform-client/src/app/plugins/modules/time-planning-pn/components/settings/time-planning-settings/time-planning-settings.component.ts

Lines changed: 9 additions & 7 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 {Subscription} from 'rxjs';
35
import {TimePlanningPnSettingsService} from '../../../services';
46
import {TimePlanningSettingsModel} from '../../../models';
@@ -12,18 +14,18 @@ import {Store} from '@ngrx/store';
1214
standalone: false
1315
})
1416
export class TimePlanningSettingsComponent implements OnInit, OnDestroy {
17+
private timePlanningPnSettingsService = inject(TimePlanningPnSettingsService);
18+
private store = inject(Store);
19+
1520
getSettings$: Subscription;
1621
settingsModel: TimePlanningSettingsModel = new TimePlanningSettingsModel();
1722
previousData: TimePlanningSettingsModel = new TimePlanningSettingsModel();
1823
public selectCurrentUserIsFirstUser$ = this.store.select(selectCurrentUserIsFirstUser);
1924

20-
constructor(
21-
private timePlanningPnSettingsService: TimePlanningPnSettingsService,
22-
private store: Store
23-
) {
24-
this.previousData = {...this.settingsModel};
25-
}
25+
26+
2627
ngOnInit() {
28+
this.previousData = {...this.settingsModel};
2729
this.getSettings();
2830
}
2931

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {AfterContentInit, Component, OnInit} from '@angular/core';
1+
import {AfterContentInit, Component, OnInit,
2+
inject
3+
} from '@angular/core';
24
import {TranslateService} from '@ngx-translate/core';
35
import {translates} from './../i18n/translates';
46
import {Store} from '@ngrx/store';
@@ -12,13 +14,15 @@ import {take} from 'rxjs';
1214
standalone: false
1315
})
1416
export class TimePlanningPnLayoutComponent implements AfterContentInit, OnInit {
17+
private translateService = inject(TranslateService);
18+
private store = inject(Store);
19+
1520
private pluginName = 'time-planning';
1621

17-
constructor(
18-
private translateService: TranslateService,
19-
store: Store
20-
) {
21-
store.select(selectPluginsVisitedPlugins)
22+
23+
24+
ngOnInit() {
25+
this.store.select(selectPluginsVisitedPlugins)
2226
.pipe(take(1))
2327
.subscribe(x => {
2428
// check current plugin in activated plugin
@@ -28,14 +32,11 @@ export class TimePlanningPnLayoutComponent implements AfterContentInit, OnInit {
2832
this.translateService.setTranslation(locale, translates[locale], true);
2933
});
3034
// add plugin to visited plugins
31-
store.dispatch(addPluginToVisited(this.pluginName));
35+
this.store.dispatch(addPluginToVisited(this.pluginName));
3236
}
3337
});
3438
}
3539

36-
ngOnInit() {
37-
}
38-
3940
ngAfterContentInit() {
4041
}
4142
}

eform-client/src/app/plugins/modules/time-planning-pn/modules/flexes/components/time-flexes-actions/comment-office-all-update-modal/time-flexes-comment-office-all-update-modal.component.ts

Lines changed: 8 additions & 8 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 {AutoUnsubscribe} from 'ngx-auto-unsubscribe';
88
import {TimeFlexesModel} from '../../../../../models';
@@ -12,21 +12,21 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
1212
@Component({
1313
selector: 'app-time-flexes-comment-office-all-update-modal',
1414
templateUrl: './time-flexes-comment-office-all-update-modal.component.html',
15-
styleUrls: ['./time-flexes-comment-office-all-update-modal.component.scss'],
15+
styleUrls: ['./time-flexes-comment-office-all-update-modal.component.scss',
16+
],
1617
standalone: false
1718
})
1819
export class TimeFlexesCommentOfficeAllUpdateModalComponent
1920
implements OnInit, OnDestroy {
21+
public dialogRef = inject(MatDialogRef<TimeFlexesCommentOfficeAllUpdateModalComponent>);
22+
private injectedTimeFlexes = inject<TimeFlexesModel>(MAT_DIALOG_DATA);
23+
2024
timeFlexes: TimeFlexesModel = new TimeFlexesModel();
2125

22-
constructor(
23-
public dialogRef: MatDialogRef<TimeFlexesCommentOfficeAllUpdateModalComponent>,
24-
@Inject(MAT_DIALOG_DATA) timeFlexes: TimeFlexesModel,
25-
) {
26-
this.timeFlexes = {...timeFlexes};
27-
}
26+
2827

2928
ngOnInit() {
29+
this.timeFlexes = {...this.injectedTimeFlexes};
3030
}
3131

3232
onUpdateFlexPlanning() {

eform-client/src/app/plugins/modules/time-planning-pn/modules/flexes/components/time-flexes-actions/comment-office-update-modal/time-flexes-comment-office-update-modal.component.ts

Lines changed: 6 additions & 7 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 {AutoUnsubscribe} from 'ngx-auto-unsubscribe';
88
import {TimeFlexesModel} from '../../../../../models';
@@ -16,16 +16,15 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
1616
standalone: false
1717
})
1818
export class TimeFlexesCommentOfficeUpdateModalComponent implements OnInit, OnDestroy {
19+
public dialogRef = inject(MatDialogRef<TimeFlexesCommentOfficeUpdateModalComponent>);
20+
private injectedTimeFlexes = inject<TimeFlexesModel>(MAT_DIALOG_DATA);
21+
1922
timeFlexes: TimeFlexesModel = new TimeFlexesModel();
2023

21-
constructor(
22-
public dialogRef: MatDialogRef<TimeFlexesCommentOfficeUpdateModalComponent>,
23-
@Inject(MAT_DIALOG_DATA) timeFlexes: TimeFlexesModel,
24-
) {
25-
this.timeFlexes = {...timeFlexes};
26-
}
24+
2725

2826
ngOnInit() {
27+
this.timeFlexes = {...this.injectedTimeFlexes};
2928
}
3029

3130
onUpdateFlexPlanning() {

eform-client/src/app/plugins/modules/time-planning-pn/modules/flexes/components/time-flexes-container/time-flexes-container.component.ts

Lines changed: 6 additions & 2 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 { Subscription } from 'rxjs';
46
import { SiteDto } from 'src/app/common/models';
@@ -17,6 +19,8 @@ import { TimePlanningPnFlexesService } from '../../../../services';
1719
standalone: false
1820
})
1921
export class TimeFlexesContainerComponent implements OnInit, OnDestroy {
22+
private planningsService = inject(TimePlanningPnFlexesService);
23+
2024
timePlanningsRequest: TimePlanningsRequestModel;
2125
availableSites: SiteDto[] = [];
2226
timePlannings: TimeFlexesModel[] = [];
@@ -25,7 +29,7 @@ export class TimeFlexesContainerComponent implements OnInit, OnDestroy {
2529
getTimePlannings$: Subscription;
2630
updateTimePlanning$: Subscription;
2731

28-
constructor(private planningsService: TimePlanningPnFlexesService) {}
32+
2933

3034
ngOnInit(): void {
3135
this.getPlannings();

0 commit comments

Comments
 (0)