Skip to content

Commit 4f3443e

Browse files
Copilotrenemadsen
andcommitted
Migrate all components and services to inject() pattern
Co-authored-by: renemadsen <[email protected]>
1 parent eaa0ace commit 4f3443e

File tree

11 files changed

+88
-67
lines changed

11 files changed

+88
-67
lines changed

eform-client/src/app/plugins/modules/customers-pn/components/customer-pn-add/customer-pn-add.component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, EventEmitter, Inject, OnInit} from '@angular/core';
1+
import {Component, EventEmitter, OnInit,
2+
inject
3+
} from '@angular/core';
24
import {CustomerPnFieldsEnum, CustomersPnFieldStatusEnum} from '../../enums';
35
import {FieldsPnUpdateModel, CustomerPnFullModel} from '../../models';
46
import {CustomersPnService} from '../../services';
@@ -11,22 +13,21 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
1113
standalone: false
1214
})
1315
export class CustomerPnAddComponent implements OnInit {
16+
private customersService = inject(CustomersPnService);
17+
public dialogRef = inject(MatDialogRef<CustomerPnAddComponent>);
18+
private data = inject<{customerId?: number, fields: FieldsPnUpdateModel}>(MAT_DIALOG_DATA);
19+
1420
customerCreated: EventEmitter<void> = new EventEmitter<void>();
1521
fieldsModel = new FieldsPnUpdateModel();
1622
get fieldsEnum() { return CustomerPnFieldsEnum; }
1723
newCustomerModel: CustomerPnFullModel = new CustomerPnFullModel();
1824

19-
constructor(
20-
private customersService: CustomersPnService,
21-
public dialogRef: MatDialogRef<CustomerPnAddComponent>,
22-
@Inject(MAT_DIALOG_DATA) public data: {customerId?: number, fields: FieldsPnUpdateModel}
23-
) {
24-
if (data && data.fields) {
25-
this.fieldsModel = data.fields;
26-
}
27-
}
25+
2826

2927
ngOnInit() {
28+
if (this.data && this.data.fields) {
29+
this.fieldsModel = this.data.fields;
30+
}
3031
if (this.data && this.data.customerId) {
3132
this.getSingleCustomer(this.data.customerId);
3233
}

eform-client/src/app/plugins/modules/customers-pn/components/customer-pn-delete/customer-pn-delete.component.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, EventEmitter, Inject, OnInit} from '@angular/core';
1+
import {Component, EventEmitter, OnInit,
2+
inject
3+
} from '@angular/core';
24
import {CustomerPnFieldsEnum} from 'src/app/plugins/modules/customers-pn/enums';
35
import {CustomerPnModel} from 'src/app/plugins/modules/customers-pn/models/customer';
46
import {FieldsPnUpdateModel} from 'src/app/plugins/modules/customers-pn/models/field';
@@ -12,25 +14,24 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
1214
standalone: false
1315
})
1416
export class CustomerPnDeleteComponent implements OnInit {
17+
private customersService = inject(CustomersPnService);
18+
public dialogRef = inject(MatDialogRef<CustomerPnDeleteComponent>);
19+
private data = inject<{customer: CustomerPnModel, fields: FieldsPnUpdateModel}>(MAT_DIALOG_DATA);
20+
1521
customerDeleted: EventEmitter<void> = new EventEmitter<void>();
1622
selectedCustomer: CustomerPnModel = new CustomerPnModel();
1723
fields: FieldsPnUpdateModel = new FieldsPnUpdateModel();
1824
get fieldsEnum() { return CustomerPnFieldsEnum; }
1925

20-
constructor(
21-
private customersService: CustomersPnService,
22-
public dialogRef: MatDialogRef<CustomerPnDeleteComponent>,
23-
@Inject(MAT_DIALOG_DATA) public data: {customer: CustomerPnModel, fields: FieldsPnUpdateModel}
24-
) {
25-
if (data) {
26-
this.selectedCustomer = data.customer;
27-
if (data.fields) {
28-
this.fields = data.fields;
29-
}
30-
}
31-
}
26+
3227

3328
ngOnInit() {
29+
if (this.data) {
30+
this.selectedCustomer = this.data.customer;
31+
if (this.data.fields) {
32+
this.fields = this.data.fields;
33+
}
34+
}
3435
}
3536

3637
hide() {

eform-client/src/app/plugins/modules/customers-pn/components/customer-pn-edit/customer-pn-edit.component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, EventEmitter, Inject, OnInit} from '@angular/core';
1+
import {Component, EventEmitter, OnInit,
2+
inject
3+
} from '@angular/core';
24
import {CustomerPnFieldsEnum, CustomersPnFieldStatusEnum} from '../../enums';
35
import {FieldsPnUpdateModel, CustomerPnFullModel} from '../../models';
46
import {CustomersPnService} from '../../services';
@@ -11,24 +13,23 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
1113
standalone: false
1214
})
1315
export class CustomerPnEditComponent implements OnInit {
16+
private customersService = inject(CustomersPnService);
17+
public dialogRef = inject(MatDialogRef<CustomerPnEditComponent>);
18+
private data = inject<{customerId: number, fields: FieldsPnUpdateModel}>(MAT_DIALOG_DATA);
19+
1420
fieldsModel = new FieldsPnUpdateModel();
1521
customerUpdate: EventEmitter<void> = new EventEmitter<void>();
1622

1723
get fieldsEnum() { return CustomerPnFieldsEnum; }
1824

1925
selectedCustomerModel = new CustomerPnFullModel();
2026

21-
constructor(
22-
private customersService: CustomersPnService,
23-
public dialogRef: MatDialogRef<CustomerPnEditComponent>,
24-
@Inject(MAT_DIALOG_DATA) public data: {customerId: number, fields: FieldsPnUpdateModel}
25-
) {
26-
if (data && data.fields) {
27-
this.fieldsModel = data.fields;
28-
}
29-
}
27+
3028

3129
ngOnInit() {
30+
if (this.data && this.data.fields) {
31+
this.fieldsModel = this.data.fields;
32+
}
3233
if (this.data && this.data.customerId) {
3334
this.getSingleCustomer(this.data.customerId);
3435
}

eform-client/src/app/plugins/modules/customers-pn/components/customer-pn-import/customer-pn-import.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit,
2+
inject
3+
} from '@angular/core';
24
import { FileUploader } from 'ng2-file-upload';
35
import { Papa } from 'ngx-papaparse';
46
import { CustomersPnService } from '../../services';
@@ -15,6 +17,8 @@ const URL = '';
1517
standalone: false
1618
})
1719
export class CustomerPnImportComponent implements OnInit {
20+
private customerService = inject(CustomersPnService);
21+
1822
public data: any = [];
1923
uploader: FileUploader;
2024
customerImportModel: CustomersPnImportModel;
@@ -52,7 +56,8 @@ export class CustomerPnImportComponent implements OnInit {
5256
{ value: 18, label: 'FloorsWithLivingSpace' },
5357
{ value: 19, label: 'Ignore' },
5458
];
55-
constructor(private customerService: CustomersPnService) {
59+
60+
constructor() {
5661
this.customerImportModel = new CustomersPnImportModel();
5762
// forEach(Option in this.options) {
5863
// this.customerHeaderModel = new CustomerPnHeadersModel();

eform-client/src/app/plugins/modules/customers-pn/components/customers-pn-fields/customers-pn-fields.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit,
2+
inject
3+
} from '@angular/core';
24
import { Router } from '@angular/router';
35
import { AdvEntitySearchableGroupListRequestModel } from 'src/app/common/models';
46
import { CustomersPnFieldStatusEnum } from '../../enums';
@@ -19,6 +21,10 @@ import {
1921
standalone: false
2022
})
2123
export class CustomersPnFieldsComponent implements OnInit {
24+
private customersFieldsService = inject(CustomersPnFieldsService);
25+
private customersSettingsService = inject(CustomersPnSettingsService);
26+
private router = inject(Router);
27+
2228
isChecked = false;
2329
fieldsUpdateModel: FieldsPnUpdateModel = new FieldsPnUpdateModel();
2430
customersPnSettingsModel: CustomersPnSettingsModel = new CustomersPnSettingsModel();
@@ -27,11 +33,7 @@ export class CustomersPnFieldsComponent implements OnInit {
2733
return CustomersPnFieldStatusEnum;
2834
}
2935

30-
constructor(
31-
private customersFieldsService: CustomersPnFieldsService,
32-
private customersSettingsService: CustomersPnSettingsService,
33-
private router: Router
34-
) {}
36+
3537

3638
ngOnInit() {
3739
this.advEntitySearchableGroupListRequestModel.pageSize = 15;

eform-client/src/app/plugins/modules/customers-pn/components/customers-pn-page/customers-pn-page.component.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
EventEmitter,
44
OnInit,
55
Output,
6+
inject
67
} from '@angular/core';
78
import { MatDialog } from '@angular/material/dialog';
89
import { TableHeaderElementModel } from 'src/app/common/models';
@@ -28,6 +29,12 @@ import { Overlay } from '@angular/cdk/overlay';
2829
standalone: false
2930
})
3031
export class CustomersPnPageComponent implements OnInit {
32+
private customersService = inject(CustomersPnService);
33+
private customersFieldsService = inject(CustomersPnFieldsService);
34+
public customersStateService = inject(CustomersStateService);
35+
private dialog = inject(MatDialog);
36+
private overlay = inject(Overlay);
37+
3138
@Output() onCustomerDuplicated: EventEmitter<void> = new EventEmitter<void>();
3239
get fieldStatusEnum() {
3340
return CustomersPnFieldStatusEnum;
@@ -39,14 +46,6 @@ export class CustomersPnPageComponent implements OnInit {
3946

4047
tableHeaders: TableHeaderElementModel[];
4148

42-
constructor(
43-
private customersService: CustomersPnService,
44-
private customersFieldsService: CustomersPnFieldsService,
45-
public customersStateService: CustomersStateService,
46-
private dialog: MatDialog,
47-
private overlay: Overlay
48-
) {}
49-
5049
checkFieldStatus(numField: number) {
5150
return (
5251
this.fieldsModel.fields[numField].fieldStatus ===

eform-client/src/app/plugins/modules/customers-pn/components/store/customers-state.service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Injectable} from '@angular/core';
1+
import {Injectable,
2+
inject
3+
} from '@angular/core';
24
import {Observable, tap} from 'rxjs';
35
import {
46
CommonPaginationState,
@@ -25,15 +27,16 @@ import {map} from 'rxjs/operators';
2527

2628
@Injectable({providedIn: 'root'})
2729
export class CustomersStateService {
30+
private store = inject(Store);
31+
private service = inject(CustomersPnService);
32+
2833
private selectCustomersFilters$ = this.store.select(selectCustomersFilters);
2934
private selectCustomersPagination$ = this.store.select(selectCustomersPagination);
3035
currentPagination: CommonPaginationState;
3136
currentFilters: CustomersFiltrationModel;
3237

33-
constructor(
34-
private store: Store,
35-
private service: CustomersPnService,
36-
) {
38+
39+
constructor() {
3740
this.selectCustomersPagination$.subscribe(x => this.currentPagination = x);
3841
this.selectCustomersFilters$.subscribe(x => this.currentFilters = x);
3942
}

eform-client/src/app/plugins/modules/customers-pn/layouts/customer-pn-layout.component.ts

Lines changed: 10 additions & 7 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 { Store } from '@ngrx/store';
46
import { addPluginToVisited, selectPluginsVisitedPlugins } from 'src/app/state';
@@ -11,13 +13,14 @@ import { translates } from './../i18n/translates';
1113
standalone: false
1214
})
1315
export class CustomerPnLayoutComponent implements AfterContentInit, OnInit {
16+
private translateService = inject(TranslateService);
17+
private store = inject(Store);
18+
1419
private pluginName = 'customers-pn';
1520

16-
constructor(
17-
private translateService: TranslateService,
18-
store: Store
19-
) {
20-
store.select(selectPluginsVisitedPlugins)
21+
22+
constructor() {
23+
this.store.select(selectPluginsVisitedPlugins)
2124
.pipe(take(1))
2225
.subscribe(x => {
2326
// check current plugin in activated plugin
@@ -27,7 +30,7 @@ export class CustomerPnLayoutComponent implements AfterContentInit, OnInit {
2730
this.translateService.setTranslation(locale, translates[locale], true);
2831
});
2932
// add plugin to visited plugins
30-
store.dispatch(addPluginToVisited(this.pluginName));
33+
this.store.dispatch(addPluginToVisited(this.pluginName));
3134
}
3235
});
3336
}

eform-client/src/app/plugins/modules/customers-pn/services/customers-pn-fields.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable,
2+
inject
3+
} from '@angular/core';
24
import { Observable } from 'rxjs';
35
import {
46
OperationDataResult,
@@ -13,7 +15,7 @@ export let CustomerPnFieldsMethods = {
1315

1416
@Injectable()
1517
export class CustomersPnFieldsService {
16-
constructor(private apiBaseService: ApiBaseService) {}
18+
private apiBaseService = inject(ApiBaseService);
1719

1820
getAllFields(): Observable<OperationDataResult<FieldsPnUpdateModel>> {
1921
return this.apiBaseService.get(CustomerPnFieldsMethods.CustomerPnFields);

eform-client/src/app/plugins/modules/customers-pn/services/customers-pn-settings.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable,
2+
inject
3+
} from '@angular/core';
24
import { Observable } from 'rxjs';
35
import {
46
OperationDataResult,
@@ -13,7 +15,7 @@ export let CustomerPnSettingsMethods = {
1315

1416
@Injectable()
1517
export class CustomersPnSettingsService {
16-
constructor(private apiBaseService: ApiBaseService) {}
18+
private apiBaseService = inject(ApiBaseService);
1719

1820
getAllSettings(): Observable<OperationDataResult<CustomersPnSettingsModel>> {
1921
return this.apiBaseService.get(

0 commit comments

Comments
 (0)