Browse Source

Refactor dependency injection in component constructors

pull/19326/head
Yusuf Çırak 2 years ago
parent
commit
f6a6eae4b2
  1. 27
      npm/ng-packs/packages/account/src/lib/components/personal-settings/personal-settings.component.ts
  2. 14
      npm/ng-packs/packages/feature-management/src/lib/components/feature-management/feature-management.component.ts
  3. 16
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts
  4. 17
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts
  5. 11
      npm/ng-packs/packages/permission-management/src/lib/components/permission-management.component.ts
  6. 18
      npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts
  7. 2
      npm/ng-packs/packages/theme-shared/src/lib/services/create-error-component.service.ts

27
npm/ng-packs/packages/account/src/lib/components/personal-settings/personal-settings.component.ts

@ -1,6 +1,6 @@
import { ProfileDto, ProfileService } from '@abp/ng.account.core/proxy';
import { Confirmation, ConfirmationService, ToasterService } from '@abp/ng.theme.shared';
import { Component, Inject, Injector, OnInit } from '@angular/core';
import { Component, inject, Injector, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { finalize, filter } from 'rxjs/operators';
import { Account } from '../../models/account';
@ -31,25 +31,24 @@ export class PersonalSettingsComponent
Account.PersonalSettingsComponentInputs,
Account.PersonalSettingsComponentOutputs
{
private readonly fb = inject(UntypedFormBuilder);
protected readonly toasterService = inject(ToasterService);
protected readonly profileService = inject(ProfileService);
protected readonly manageProfileState = inject(ManageProfileStateService);
protected readonly authService = inject(AuthService);
protected readonly confirmationService = inject(ConfirmationService);
protected readonly configState = inject(ConfigStateService);
protected readonly isPersonalSettingsChangedConfirmationActive = inject(
RE_LOGIN_CONFIRMATION_TOKEN,
);
private readonly injector = inject(Injector);
selected?: ProfileDto;
form!: UntypedFormGroup;
inProgress?: boolean;
constructor(
private fb: UntypedFormBuilder,
private toasterService: ToasterService,
private profileService: ProfileService,
private manageProfileState: ManageProfileStateService,
private readonly authService: AuthService,
private confirmationService: ConfirmationService,
private configState: ConfigStateService,
@Inject(RE_LOGIN_CONFIRMATION_TOKEN)
private isPersonalSettingsChangedConfirmationActive: boolean,
protected injector: Injector,
) {}
buildForm() {
this.selected = this.manageProfileState.getProfile();
if (!this.selected) {

14
npm/ng-packs/packages/feature-management/src/lib/components/feature-management/feature-management.component.ts

@ -31,6 +31,12 @@ export class FeatureManagementComponent
FeatureManagement.FeatureManagementComponentInputs,
FeatureManagement.FeatureManagementComponentOutputs
{
protected readonly trackByService = inject(TrackByService);
protected readonly toasterService = inject(ToasterService);
protected readonly service = inject(FeaturesService);
protected readonly configState = inject(ConfigStateService);
protected readonly confirmationService = inject(ConfirmationService);
@Input()
providerKey: string;
@ -72,14 +78,6 @@ export class FeatureManagementComponent
modalBusy = false;
constructor(
public readonly track: TrackByService,
private toasterService: ToasterService,
protected service: FeaturesService,
protected configState: ConfigStateService,
protected confirmationService: ConfirmationService,
) {}
openModal() {
if (!this.providerName) {
throw new Error('providerName is required.');

16
npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts

@ -7,7 +7,7 @@ import {
FormPropData,
generateFormFromProps,
} from '@abp/ng.components/extensible';
import { Component, Injector, OnInit } from '@angular/core';
import { Component, inject, Injector, OnInit } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { finalize } from 'rxjs/operators';
import { eIdentityComponents } from '../../enums/components';
@ -24,6 +24,12 @@ import { eIdentityComponents } from '../../enums/components';
],
})
export class RolesComponent implements OnInit {
protected readonly list = inject(ListService<PagedAndSortedResultRequestDto>);
protected readonly confirmationService = inject(ConfirmationService);
protected readonly toasterService = inject(ToasterService);
private readonly injector = inject(Injector);
protected readonly service = inject(IdentityRoleService);
data: PagedResultDto<IdentityRoleDto> = { items: [], totalCount: 0 };
form!: UntypedFormGroup;
@ -44,14 +50,6 @@ export class RolesComponent implements OnInit {
this.visiblePermissions = event;
};
constructor(
public readonly list: ListService<PagedAndSortedResultRequestDto>,
protected confirmationService: ConfirmationService,
private toasterService: ToasterService,
protected injector: Injector,
protected service: IdentityRoleService,
) {}
ngOnInit() {
this.hookToQuery();
}

17
npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

@ -19,6 +19,7 @@ import {
} from '@abp/ng.components/extensible';
import {
Component,
inject,
Injector,
OnInit,
TemplateRef,
@ -46,6 +47,13 @@ import { eIdentityComponents } from '../../enums/components';
],
})
export class UsersComponent implements OnInit {
protected readonly list = inject(ListService<GetIdentityUsersInput>);
protected readonly confirmationService = inject(ConfirmationService);
protected readonly service = inject(IdentityUserService);
protected readonly toasterService = inject(ToasterService);
private readonly fb = inject(UntypedFormBuilder);
private readonly injector = inject(Injector);
data: PagedResultDto<IdentityUserDto> = { items: [], totalCount: 0 };
@ViewChild('modalContent', { static: false })
@ -83,15 +91,6 @@ export class UsersComponent implements OnInit {
return ((this.form.get('roleNames') as UntypedFormArray)?.controls as UntypedFormGroup[]) || [];
}
constructor(
public readonly list: ListService<GetIdentityUsersInput>,
protected confirmationService: ConfirmationService,
protected service: IdentityUserService,
private toasterService: ToasterService,
protected fb: UntypedFormBuilder,
protected injector: Injector,
) {}
ngOnInit() {
this.hookToQuery();
}

11
npm/ng-packs/packages/permission-management/src/lib/components/permission-management.component.ts

@ -12,6 +12,7 @@ import {
Component,
ElementRef,
EventEmitter,
inject,
Input,
Output,
QueryList,
@ -52,6 +53,10 @@ export class PermissionManagementComponent
PermissionManagement.PermissionManagementComponentInputs,
PermissionManagement.PermissionManagementComponentOutputs
{
protected readonly service = inject(PermissionsService);
protected readonly configState = inject(ConfigStateService);
protected readonly toasterService = inject(ToasterService);
@Input()
readonly providerName!: string;
@ -118,12 +123,6 @@ export class PermissionManagementComponent
trackByFn: TrackByFunction<PermissionGroupDto> = (_, item) => item.name;
constructor(
protected service: PermissionsService,
protected configState: ConfigStateService,
private readonly toasterService: ToasterService,
) {}
getChecked(name: string) {
return (this.permissions.find(per => per.name === name) || { isGranted: false }).isGranted;
}

18
npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts

@ -7,7 +7,7 @@ import {
FormPropData,
generateFormFromProps,
} from '@abp/ng.components/extensible';
import { Component, Injector, OnInit } from '@angular/core';
import { Component, inject, Injector, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { finalize } from 'rxjs/operators';
import { eTenantManagementComponents } from '../../enums/components';
@ -24,6 +24,13 @@ import { eTenantManagementComponents } from '../../enums/components';
],
})
export class TenantsComponent implements OnInit {
protected readonly list = inject(ListService<GetTenantsInput>);
protected readonly confirmationService = inject(ConfirmationService);
protected readonly service = inject(TenantService);
protected readonly toasterService = inject(ToasterService);
private readonly fb = inject(UntypedFormBuilder);
private readonly injector = inject(Injector);
data: PagedResultDto<TenantDto> = { items: [], totalCount: 0 };
selected!: TenantDto;
@ -48,15 +55,6 @@ export class TenantsComponent implements OnInit {
this.visibleFeatures = value;
};
constructor(
public readonly list: ListService<GetTenantsInput>,
private injector: Injector,
private confirmationService: ConfirmationService,
private service: TenantService,
private toasterService: ToasterService,
private fb: UntypedFormBuilder,
) {}
ngOnInit() {
this.hookToQuery();
}

2
npm/ng-packs/packages/theme-shared/src/lib/services/create-error-component.service.ts

@ -23,7 +23,7 @@ export class CreateErrorComponentService {
protected readonly rendererFactory = inject(RendererFactory2);
protected readonly cfRes = inject(ComponentFactoryResolver);
protected readonly routerEvents = inject(RouterEvents);
protected readonly injector = inject(Injector);
private readonly injector = inject(Injector);
protected readonly httpErrorConfig = inject(HTTP_ERROR_CONFIG);
componentRef: ComponentRef<HttpErrorWrapperComponent> | null = null;

Loading…
Cancel
Save