Browse Source

Refactor dependency injection in component constructors

pull/19326/head
Yusuf Çırak 3 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 { ProfileDto, ProfileService } from '@abp/ng.account.core/proxy';
import { Confirmation, ConfirmationService, ToasterService } from '@abp/ng.theme.shared'; 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 { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { finalize, filter } from 'rxjs/operators'; import { finalize, filter } from 'rxjs/operators';
import { Account } from '../../models/account'; import { Account } from '../../models/account';
@ -31,25 +31,24 @@ export class PersonalSettingsComponent
Account.PersonalSettingsComponentInputs, Account.PersonalSettingsComponentInputs,
Account.PersonalSettingsComponentOutputs 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; selected?: ProfileDto;
form!: UntypedFormGroup; form!: UntypedFormGroup;
inProgress?: boolean; 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() { buildForm() {
this.selected = this.manageProfileState.getProfile(); this.selected = this.manageProfileState.getProfile();
if (!this.selected) { 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.FeatureManagementComponentInputs,
FeatureManagement.FeatureManagementComponentOutputs 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() @Input()
providerKey: string; providerKey: string;
@ -72,14 +78,6 @@ export class FeatureManagementComponent
modalBusy = false; modalBusy = false;
constructor(
public readonly track: TrackByService,
private toasterService: ToasterService,
protected service: FeaturesService,
protected configState: ConfigStateService,
protected confirmationService: ConfirmationService,
) {}
openModal() { openModal() {
if (!this.providerName) { if (!this.providerName) {
throw new Error('providerName is required.'); 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, FormPropData,
generateFormFromProps, generateFormFromProps,
} from '@abp/ng.components/extensible'; } 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 { UntypedFormGroup } from '@angular/forms';
import { finalize } from 'rxjs/operators'; import { finalize } from 'rxjs/operators';
import { eIdentityComponents } from '../../enums/components'; import { eIdentityComponents } from '../../enums/components';
@ -24,6 +24,12 @@ import { eIdentityComponents } from '../../enums/components';
], ],
}) })
export class RolesComponent implements OnInit { 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 }; data: PagedResultDto<IdentityRoleDto> = { items: [], totalCount: 0 };
form!: UntypedFormGroup; form!: UntypedFormGroup;
@ -44,14 +50,6 @@ export class RolesComponent implements OnInit {
this.visiblePermissions = event; this.visiblePermissions = event;
}; };
constructor(
public readonly list: ListService<PagedAndSortedResultRequestDto>,
protected confirmationService: ConfirmationService,
private toasterService: ToasterService,
protected injector: Injector,
protected service: IdentityRoleService,
) {}
ngOnInit() { ngOnInit() {
this.hookToQuery(); 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'; } from '@abp/ng.components/extensible';
import { import {
Component, Component,
inject,
Injector, Injector,
OnInit, OnInit,
TemplateRef, TemplateRef,
@ -46,6 +47,13 @@ import { eIdentityComponents } from '../../enums/components';
], ],
}) })
export class UsersComponent implements OnInit { 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 }; data: PagedResultDto<IdentityUserDto> = { items: [], totalCount: 0 };
@ViewChild('modalContent', { static: false }) @ViewChild('modalContent', { static: false })
@ -83,15 +91,6 @@ export class UsersComponent implements OnInit {
return ((this.form.get('roleNames') as UntypedFormArray)?.controls as UntypedFormGroup[]) || []; 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() { ngOnInit() {
this.hookToQuery(); this.hookToQuery();
} }

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

@ -12,6 +12,7 @@ import {
Component, Component,
ElementRef, ElementRef,
EventEmitter, EventEmitter,
inject,
Input, Input,
Output, Output,
QueryList, QueryList,
@ -52,6 +53,10 @@ export class PermissionManagementComponent
PermissionManagement.PermissionManagementComponentInputs, PermissionManagement.PermissionManagementComponentInputs,
PermissionManagement.PermissionManagementComponentOutputs PermissionManagement.PermissionManagementComponentOutputs
{ {
protected readonly service = inject(PermissionsService);
protected readonly configState = inject(ConfigStateService);
protected readonly toasterService = inject(ToasterService);
@Input() @Input()
readonly providerName!: string; readonly providerName!: string;
@ -118,12 +123,6 @@ export class PermissionManagementComponent
trackByFn: TrackByFunction<PermissionGroupDto> = (_, item) => item.name; trackByFn: TrackByFunction<PermissionGroupDto> = (_, item) => item.name;
constructor(
protected service: PermissionsService,
protected configState: ConfigStateService,
private readonly toasterService: ToasterService,
) {}
getChecked(name: string) { getChecked(name: string) {
return (this.permissions.find(per => per.name === name) || { isGranted: false }).isGranted; 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, FormPropData,
generateFormFromProps, generateFormFromProps,
} from '@abp/ng.components/extensible'; } 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 { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { finalize } from 'rxjs/operators'; import { finalize } from 'rxjs/operators';
import { eTenantManagementComponents } from '../../enums/components'; import { eTenantManagementComponents } from '../../enums/components';
@ -24,6 +24,13 @@ import { eTenantManagementComponents } from '../../enums/components';
], ],
}) })
export class TenantsComponent implements OnInit { 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 }; data: PagedResultDto<TenantDto> = { items: [], totalCount: 0 };
selected!: TenantDto; selected!: TenantDto;
@ -48,15 +55,6 @@ export class TenantsComponent implements OnInit {
this.visibleFeatures = value; 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() { ngOnInit() {
this.hookToQuery(); 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 rendererFactory = inject(RendererFactory2);
protected readonly cfRes = inject(ComponentFactoryResolver); protected readonly cfRes = inject(ComponentFactoryResolver);
protected readonly routerEvents = inject(RouterEvents); protected readonly routerEvents = inject(RouterEvents);
protected readonly injector = inject(Injector); private readonly injector = inject(Injector);
protected readonly httpErrorConfig = inject(HTTP_ERROR_CONFIG); protected readonly httpErrorConfig = inject(HTTP_ERROR_CONFIG);
componentRef: ComponentRef<HttpErrorWrapperComponent> | null = null; componentRef: ComponentRef<HttpErrorWrapperComponent> | null = null;

Loading…
Cancel
Save