Browse Source

refactor : migrate theme-basic package to inject() DI

pull/23262/head
Fahri Gedik 1 year ago
parent
commit
0dfd7c0d5c
  1. 6
      npm/ng-packs/packages/theme-basic/src/lib/components/account-layout/account-layout.component.ts
  2. 28
      npm/ng-packs/packages/theme-basic/src/lib/components/account-layout/auth-wrapper/auth-wrapper.component.ts
  3. 44
      npm/ng-packs/packages/theme-basic/src/lib/components/account-layout/tenant-box/tenant-box.component.ts
  4. 6
      npm/ng-packs/packages/theme-basic/src/lib/components/logo/logo.component.ts
  5. 16
      npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/current-user.component.ts
  6. 10
      npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/languages.component.ts
  7. 6
      npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/nav-items.component.ts
  8. 26
      npm/ng-packs/packages/theme-basic/src/lib/components/page-alert-container/page-alert-container.component.ts
  9. 6
      npm/ng-packs/packages/theme-basic/src/lib/handlers/lazy-style.handler.ts
  10. 12
      npm/ng-packs/packages/theme-basic/src/lib/services/layout.service.ts

6
npm/ng-packs/packages/theme-basic/src/lib/components/account-layout/account-layout.component.ts

@ -1,4 +1,4 @@
import { AfterViewInit, Component } from '@angular/core'; import { AfterViewInit, Component, inject } from '@angular/core';
import { eLayoutType, ReplaceableTemplateDirective, SubscriptionService } from '@abp/ng.core'; import { eLayoutType, ReplaceableTemplateDirective, SubscriptionService } from '@abp/ng.core';
import { LayoutService } from '../../services/layout.service'; import { LayoutService } from '../../services/layout.service';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
@ -25,13 +25,13 @@ import { RouterModule } from '@angular/router';
], ],
}) })
export class AccountLayoutComponent implements AfterViewInit { export class AccountLayoutComponent implements AfterViewInit {
service = inject(LayoutService);
// required for dynamic component // required for dynamic component
static type = eLayoutType.account; static type = eLayoutType.account;
authWrapperKey = 'Account.AuthWrapperComponent'; authWrapperKey = 'Account.AuthWrapperComponent';
constructor(public service: LayoutService) {}
ngAfterViewInit() { ngAfterViewInit() {
this.service.subscribeWindowSize(); this.service.subscribeWindowSize();
} }

28
npm/ng-packs/packages/theme-basic/src/lib/components/account-layout/auth-wrapper/auth-wrapper.component.ts

@ -1,15 +1,15 @@
import { AuthWrapperService } from '@abp/ng.account.core'; import { AuthWrapperService } from '@abp/ng.account.core';
import { Component } from '@angular/core'; import { Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { LocalizationPipe, ReplaceableTemplateDirective } from '@abp/ng.core'; import { LocalizationPipe, ReplaceableTemplateDirective } from '@abp/ng.core';
import { TenantBoxComponent } from '../tenant-box/tenant-box.component'; import { TenantBoxComponent } from '../tenant-box/tenant-box.component';
@Component({
selector: 'abp-auth-wrapper',
templateUrl: './auth-wrapper.component.html',
providers: [AuthWrapperService],
imports: [CommonModule, TenantBoxComponent, ReplaceableTemplateDirective, LocalizationPipe],
})
export class AuthWrapperComponent { service = inject(AuthWrapperService);
@Component({ }
selector: 'abp-auth-wrapper',
templateUrl: './auth-wrapper.component.html',
providers: [AuthWrapperService],
imports: [CommonModule, TenantBoxComponent, ReplaceableTemplateDirective, LocalizationPipe],
})
export class AuthWrapperComponent {
constructor(public service: AuthWrapperService) {}
}

44
npm/ng-packs/packages/theme-basic/src/lib/components/account-layout/tenant-box/tenant-box.component.ts

@ -1,23 +1,23 @@
import { TenantBoxService } from '@abp/ng.account.core'; import { TenantBoxService } from '@abp/ng.account.core';
import { Component } from '@angular/core'; import { Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { LocalizationPipe } from '@abp/ng.core'; import { LocalizationPipe } from '@abp/ng.core';
import { ButtonComponent, ModalCloseDirective, ModalComponent } from '@abp/ng.theme.shared'; import { ButtonComponent, ModalCloseDirective, ModalComponent } from '@abp/ng.theme.shared';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
@Component({
selector: 'abp-tenant-box',
templateUrl: './tenant-box.component.html',
providers: [TenantBoxService],
imports: [
CommonModule,
FormsModule,
ModalComponent,
LocalizationPipe,
ButtonComponent,
ModalCloseDirective,
],
})
export class TenantBoxComponent { service = inject(TenantBoxService);
@Component({ }
selector: 'abp-tenant-box',
templateUrl: './tenant-box.component.html',
providers: [TenantBoxService],
imports: [
CommonModule,
FormsModule,
ModalComponent,
LocalizationPipe,
ButtonComponent,
ModalCloseDirective,
],
})
export class TenantBoxComponent {
constructor(public service: TenantBoxService) {}
}

6
npm/ng-packs/packages/theme-basic/src/lib/components/logo/logo.component.ts

@ -1,5 +1,5 @@
import { ApplicationInfo, EnvironmentService } from '@abp/ng.core'; import { ApplicationInfo, EnvironmentService } from '@abp/ng.core';
import { Component } from '@angular/core'; import { Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
@Component({ @Component({
@ -16,9 +16,9 @@ import { CommonModule } from '@angular/common';
imports: [CommonModule], imports: [CommonModule],
}) })
export class LogoComponent { export class LogoComponent {
private environment = inject(EnvironmentService);
get appInfo(): ApplicationInfo { get appInfo(): ApplicationInfo {
return this.environment.getEnvironment().application; return this.environment.getEnvironment().application;
} }
constructor(private environment: EnvironmentService) {}
} }

16
npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/current-user.component.ts

@ -9,7 +9,7 @@ import {
ToInjectorPipe, ToInjectorPipe,
} from '@abp/ng.core'; } from '@abp/ng.core';
import { AbpVisibleDirective, UserMenu, UserMenuService } from '@abp/ng.theme.shared'; import { AbpVisibleDirective, UserMenu, UserMenuService } from '@abp/ng.theme.shared';
import { Component, Inject, TrackByFunction } from '@angular/core'; import { Component, TrackByFunction, inject } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
@ -27,6 +27,12 @@ import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
], ],
}) })
export class CurrentUserComponent { export class CurrentUserComponent {
readonly navigateToManageProfile = inject(NAVIGATE_TO_MANAGE_PROFILE);
readonly userMenu = inject(UserMenuService);
private authService = inject(AuthService);
private configState = inject(ConfigStateService);
private sessionState = inject(SessionStateService);
currentUser$: Observable<CurrentUserDto> = this.configState.getOne$('currentUser'); currentUser$: Observable<CurrentUserDto> = this.configState.getOne$('currentUser');
selectedTenant$ = this.sessionState.getTenant$(); selectedTenant$ = this.sessionState.getTenant$();
@ -36,14 +42,6 @@ export class CurrentUserComponent {
return window.innerWidth < 992; return window.innerWidth < 992;
} }
constructor(
@Inject(NAVIGATE_TO_MANAGE_PROFILE) public readonly navigateToManageProfile: () => void,
public readonly userMenu: UserMenuService,
private authService: AuthService,
private configState: ConfigStateService,
private sessionState: SessionStateService,
) {}
navigateToLogin() { navigateToLogin() {
this.authService.navigateToLogin(); this.authService.navigateToLogin();
} }

10
npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/languages.component.ts

@ -1,5 +1,5 @@
import { ConfigStateService, LanguageInfo, SessionStateService } from '@abp/ng.core'; import { ConfigStateService, LanguageInfo, SessionStateService } from '@abp/ng.core';
import { Component } from '@angular/core'; import { Component, inject } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
@ -42,6 +42,9 @@ import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
imports: [CommonModule, NgbDropdownModule], imports: [CommonModule, NgbDropdownModule],
}) })
export class LanguagesComponent { export class LanguagesComponent {
private sessionState = inject(SessionStateService);
private configState = inject(ConfigStateService);
get smallScreen(): boolean { get smallScreen(): boolean {
return window.innerWidth < 992; return window.innerWidth < 992;
} }
@ -69,11 +72,6 @@ export class LanguagesComponent {
return this.sessionState.getLanguage(); return this.sessionState.getLanguage();
} }
constructor(
private sessionState: SessionStateService,
private configState: ConfigStateService,
) {}
onChangeLang(cultureName: string) { onChangeLang(cultureName: string) {
this.sessionState.setLanguage(cultureName); this.sessionState.setLanguage(cultureName);
} }

6
npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/nav-items.component.ts

@ -1,5 +1,5 @@
import { AbpVisibleDirective, NavItem, NavItemsService } from '@abp/ng.theme.shared'; import { AbpVisibleDirective, NavItem, NavItemsService } from '@abp/ng.theme.shared';
import { Component, TrackByFunction } from '@angular/core'; import { Component, TrackByFunction, inject } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { PermissionDirective, ToInjectorPipe } from '@abp/ng.core'; import { PermissionDirective, ToInjectorPipe } from '@abp/ng.core';
@ -9,7 +9,7 @@ import { PermissionDirective, ToInjectorPipe } from '@abp/ng.core';
imports: [CommonModule, AbpVisibleDirective, PermissionDirective, ToInjectorPipe], imports: [CommonModule, AbpVisibleDirective, PermissionDirective, ToInjectorPipe],
}) })
export class NavItemsComponent { export class NavItemsComponent {
trackByFn: TrackByFunction<NavItem> = (_, element) => element.id; readonly navItems = inject(NavItemsService);
constructor(public readonly navItems: NavItemsService) {} trackByFn: TrackByFunction<NavItem> = (_, element) => element.id;
} }

26
npm/ng-packs/packages/theme-basic/src/lib/components/page-alert-container/page-alert-container.component.ts

@ -1,14 +1,14 @@
import { Component, ViewEncapsulation } from '@angular/core'; import { Component, ViewEncapsulation, inject } from '@angular/core';
import { PageAlertService } from '@abp/ng.theme.shared'; import { PageAlertService } from '@abp/ng.theme.shared';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { LocalizationPipe, SafeHtmlPipe } from '@abp/ng.core'; import { LocalizationPipe, SafeHtmlPipe } from '@abp/ng.core';
@Component({
selector: 'abp-page-alert-container',
templateUrl: './page-alert-container.component.html',
encapsulation: ViewEncapsulation.None,
imports: [CommonModule, LocalizationPipe, SafeHtmlPipe],
})
export class PageAlertContainerComponent { service = inject(PageAlertService);
@Component({ }
selector: 'abp-page-alert-container',
templateUrl: './page-alert-container.component.html',
encapsulation: ViewEncapsulation.None,
imports: [CommonModule, LocalizationPipe, SafeHtmlPipe],
})
export class PageAlertContainerComponent {
constructor(public service: PageAlertService) {}
}

6
npm/ng-packs/packages/theme-basic/src/lib/handlers/lazy-style.handler.ts

@ -1,6 +1,6 @@
import { LazyLoadService, LOADING_STRATEGY } from '@abp/ng.core'; import { LazyLoadService, LOADING_STRATEGY } from '@abp/ng.core';
import { DocumentDirHandlerService, LocaleDirection } from '@abp/ng.theme.shared'; import { DocumentDirHandlerService, LocaleDirection } from '@abp/ng.theme.shared';
import { Injectable, Injector } from '@angular/core'; import { Injectable, Injector, inject } from '@angular/core';
import { LAZY_STYLES } from '../tokens/lazy-styles.token'; import { LAZY_STYLES } from '../tokens/lazy-styles.token';
export const BOOTSTRAP = 'bootstrap-{{dir}}.min.css'; export const BOOTSTRAP = 'bootstrap-{{dir}}.min.css';
@ -23,7 +23,9 @@ export class LazyStyleHandler {
return this._dir; return this._dir;
} }
constructor(injector: Injector) { constructor() {
const injector = inject(Injector);
this.setStyles(injector); this.setStyles(injector);
this.setLazyLoad(injector); this.setLazyLoad(injector);
this.listenToDirectionChanges(injector); this.listenToDirectionChanges(injector);

12
npm/ng-packs/packages/theme-basic/src/lib/services/layout.service.ts

@ -1,11 +1,14 @@
import {RouterEvents, SubscriptionService} from '@abp/ng.core'; import {RouterEvents, SubscriptionService} from '@abp/ng.core';
import { ChangeDetectorRef, Injectable } from '@angular/core'; import { ChangeDetectorRef, Injectable, inject } from '@angular/core';
import { fromEvent } from 'rxjs'; import { fromEvent } from 'rxjs';
import { debounceTime } from 'rxjs/operators'; import { debounceTime } from 'rxjs/operators';
import { eThemeBasicComponents } from '../enums'; import { eThemeBasicComponents } from '../enums';
@Injectable() @Injectable()
export class LayoutService { export class LayoutService {
private subscription = inject(SubscriptionService);
private cdRef = inject(ChangeDetectorRef);
isCollapsed = true; isCollapsed = true;
smallScreen!: boolean; // do not set true or false smallScreen!: boolean; // do not set true or false
@ -16,9 +19,10 @@ export class LayoutService {
navItemsComponentKey = eThemeBasicComponents.NavItems; navItemsComponentKey = eThemeBasicComponents.NavItems;
constructor(private subscription: SubscriptionService, constructor() {
private cdRef: ChangeDetectorRef, const subscription = this.subscription;
routerEvents:RouterEvents) { const routerEvents = inject(RouterEvents);
subscription.addOne(routerEvents.getNavigationEvents("End"),() => { subscription.addOne(routerEvents.getNavigationEvents("End"),() => {
this.isCollapsed = true; this.isCollapsed = true;
}) })

Loading…
Cancel
Save