From 0a08365b55dbe0c7ddac83b6ac7c25558c290ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20KILI=C3=87?= Date: Thu, 9 Jun 2022 10:29:56 +0300 Subject: [PATCH 1/8] Added PipeFunction for NgModel Error when using NgModel with select option. Also changed toolbarActions file to use together toolbarAction and toolbar component . --- npm/ng-packs/packages/core/src/lib/core.module.ts | 7 +++++-- npm/ng-packs/packages/core/src/lib/pipes/index.ts | 1 + .../core/src/lib/pipes/pipe-function.pipe.ts | 14 ++++++++++++++ .../page-toolbar/page-toolbar.component.html | 2 +- .../extensions/src/lib/models/toolbar-actions.ts | 4 +++- 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 npm/ng-packs/packages/core/src/lib/pipes/pipe-function.pipe.ts diff --git a/npm/ng-packs/packages/core/src/lib/core.module.ts b/npm/ng-packs/packages/core/src/lib/core.module.ts index 238ed9bb02..81c96fdb0d 100644 --- a/npm/ng-packs/packages/core/src/lib/core.module.ts +++ b/npm/ng-packs/packages/core/src/lib/core.module.ts @@ -37,6 +37,7 @@ import { getInitialData, localeInitializer } from './utils/initial-utils'; import { ShortDateTimePipe } from './pipes/short-date-time.pipe'; import { ShortTimePipe } from './pipes/short-time.pipe'; import { ShortDatePipe } from './pipes/short-date.pipe'; +import {PipeFunction} from "./pipes"; export function storageFactory(): OAuthStorage { return oAuthStorage; @@ -72,7 +73,8 @@ export function storageFactory(): OAuthStorage { ToInjectorPipe, ShortDateTimePipe, ShortTimePipe, - ShortDatePipe + ShortDatePipe, + PipeFunction ], imports: [ OAuthModule, @@ -100,7 +102,8 @@ export function storageFactory(): OAuthStorage { ToInjectorPipe, ShortDateTimePipe, ShortTimePipe, - ShortDatePipe + ShortDatePipe, + PipeFunction ], providers: [LocalizationPipe] diff --git a/npm/ng-packs/packages/core/src/lib/pipes/index.ts b/npm/ng-packs/packages/core/src/lib/pipes/index.ts index 71ce383cd3..7ac9f76a33 100644 --- a/npm/ng-packs/packages/core/src/lib/pipes/index.ts +++ b/npm/ng-packs/packages/core/src/lib/pipes/index.ts @@ -4,3 +4,4 @@ export * from './to-injector.pipe'; export * from './short-date.pipe'; export * from './short-time.pipe'; export * from './short-date-time.pipe'; +export * from './pipe-function.pipe'; diff --git a/npm/ng-packs/packages/core/src/lib/pipes/pipe-function.pipe.ts b/npm/ng-packs/packages/core/src/lib/pipes/pipe-function.pipe.ts new file mode 100644 index 0000000000..efb0f8acaa --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/pipes/pipe-function.pipe.ts @@ -0,0 +1,14 @@ +import {Pipe, PipeTransform} from "@angular/core"; + +@Pipe({ + name: 'pipeFunction' +}) +export class PipeFunction implements PipeTransform { + public transform(value: any, handler: (value: any) => any, context?: any): any { + if (context) { + return handler.call(context, value); + } + + return handler(value); + } +} diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html index c231f3b82c..32b4c9ba42 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html @@ -8,7 +8,7 @@ diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts index 9a688cc20f..1a311d7a5d 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts @@ -68,7 +68,9 @@ export type ToolbarComponentOptions = O.Optional< 'permission' | 'visible' | 'action' >; -export type ToolbarActionDefaults = Record[]>; +export type ToolbarActionDefault = ToolbarAction | ToolbarComponent; + +export type ToolbarActionDefaults = Record>>; export type ToolbarActionContributorCallback = ActionContributorCallback< ToolbarActionList >; From 1adda0eaeefa84941c4e6d16359e337c0e821d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20KILI=C3=87?= Date: Thu, 9 Jun 2022 10:58:48 +0300 Subject: [PATCH 2/8] =?UTF-8?q?Formatted=20=C4=B0mports.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- npm/ng-packs/packages/core/src/lib/core.module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/core/src/lib/core.module.ts b/npm/ng-packs/packages/core/src/lib/core.module.ts index 81c96fdb0d..5dc907ff6a 100644 --- a/npm/ng-packs/packages/core/src/lib/core.module.ts +++ b/npm/ng-packs/packages/core/src/lib/core.module.ts @@ -37,7 +37,7 @@ import { getInitialData, localeInitializer } from './utils/initial-utils'; import { ShortDateTimePipe } from './pipes/short-date-time.pipe'; import { ShortTimePipe } from './pipes/short-time.pipe'; import { ShortDatePipe } from './pipes/short-date.pipe'; -import {PipeFunction} from "./pipes"; +import { PipeFunction } from "./pipes"; export function storageFactory(): OAuthStorage { return oAuthStorage; From 8b8dced2b96c2eda662b9edc572f4ece56de3579 Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Thu, 9 Jun 2022 23:18:05 +0300 Subject: [PATCH 3/8] add createInjector pipe --- .../packages/core/src/lib/core.module.ts | 116 +++++++++--------- .../packages/core/src/lib/pipes/index.ts | 1 - .../core/src/lib/pipes/pipe-function.pipe.ts | 14 --- .../abstract-actions.component.ts | 4 +- .../page-toolbar/page-toolbar.component.html | 5 +- .../page-toolbar/page-toolbar.component.ts | 28 +---- .../src/lib/models/toolbar-actions.ts | 8 +- .../src/lib/pipes/create-injector.pipe.ts | 29 +++++ .../src/lib/ui-extensions.module.ts | 3 + .../theme-shared/extensions/src/public-api.ts | 1 + 10 files changed, 101 insertions(+), 108 deletions(-) delete mode 100644 npm/ng-packs/packages/core/src/lib/pipes/pipe-function.pipe.ts create mode 100644 npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts diff --git a/npm/ng-packs/packages/core/src/lib/core.module.ts b/npm/ng-packs/packages/core/src/lib/core.module.ts index 5dc907ff6a..22cd68f314 100644 --- a/npm/ng-packs/packages/core/src/lib/core.module.ts +++ b/npm/ng-packs/packages/core/src/lib/core.module.ts @@ -1,5 +1,5 @@ import { CommonModule } from '@angular/common'; -import { HttpClientModule, HttpClientXsrfModule, HTTP_INTERCEPTORS } from '@angular/common/http'; +import { HTTP_INTERCEPTORS, HttpClientModule, HttpClientXsrfModule } from '@angular/common/http'; import { APP_INITIALIZER, Injector, ModuleWithProviders, NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; @@ -29,7 +29,7 @@ import { LocaleProvider } from './providers/locale.provider'; import { LocalizationService } from './services/localization.service'; import { oAuthStorage } from './strategies/auth-flow.strategy'; import { localizationContributor, LOCALIZATIONS } from './tokens/localization.token'; -import { coreOptionsFactory, CORE_OPTIONS } from './tokens/options.token'; +import { CORE_OPTIONS, coreOptionsFactory } from './tokens/options.token'; import { TENANT_KEY } from './tokens/tenant-key.token'; import { noop } from './utils/common-utils'; import './utils/date-extensions'; @@ -37,7 +37,6 @@ import { getInitialData, localeInitializer } from './utils/initial-utils'; import { ShortDateTimePipe } from './pipes/short-date-time.pipe'; import { ShortTimePipe } from './pipes/short-time.pipe'; import { ShortDatePipe } from './pipes/short-date.pipe'; -import { PipeFunction } from "./pipes"; export function storageFactory(): OAuthStorage { return oAuthStorage; @@ -50,63 +49,60 @@ export function storageFactory(): OAuthStorage { * This module will be imported and exported by all others. */ @NgModule({ - exports: [ - CommonModule, - HttpClientModule, - FormsModule, - ReactiveFormsModule, - RouterModule, - LocalizationModule, - AbstractNgModelComponent, - AutofocusDirective, - DynamicLayoutComponent, - ForDirective, - FormSubmitDirective, - InitDirective, - InputEventDebounceDirective, - PermissionDirective, - ReplaceableRouteContainerComponent, - ReplaceableTemplateDirective, - RouterOutletComponent, - SortPipe, - StopPropagationDirective, - ToInjectorPipe, - ShortDateTimePipe, - ShortTimePipe, - ShortDatePipe, - PipeFunction - ], - imports: [ - OAuthModule, - CommonModule, - HttpClientModule, - FormsModule, - ReactiveFormsModule, - RouterModule, - LocalizationModule, - ], - declarations: [ - AbstractNgModelComponent, - AutofocusDirective, - DynamicLayoutComponent, - ForDirective, - FormSubmitDirective, - InitDirective, - InputEventDebounceDirective, - PermissionDirective, - ReplaceableRouteContainerComponent, - ReplaceableTemplateDirective, - RouterOutletComponent, - SortPipe, - StopPropagationDirective, - ToInjectorPipe, - ShortDateTimePipe, - ShortTimePipe, - ShortDatePipe, - PipeFunction - - ], - providers: [LocalizationPipe] + exports: [ + CommonModule, + HttpClientModule, + FormsModule, + ReactiveFormsModule, + RouterModule, + LocalizationModule, + AbstractNgModelComponent, + AutofocusDirective, + DynamicLayoutComponent, + ForDirective, + FormSubmitDirective, + InitDirective, + InputEventDebounceDirective, + PermissionDirective, + ReplaceableRouteContainerComponent, + ReplaceableTemplateDirective, + RouterOutletComponent, + SortPipe, + StopPropagationDirective, + ToInjectorPipe, + ShortDateTimePipe, + ShortTimePipe, + ShortDatePipe, + ], + imports: [ + OAuthModule, + CommonModule, + HttpClientModule, + FormsModule, + ReactiveFormsModule, + RouterModule, + LocalizationModule, + ], + declarations: [ + AbstractNgModelComponent, + AutofocusDirective, + DynamicLayoutComponent, + ForDirective, + FormSubmitDirective, + InitDirective, + InputEventDebounceDirective, + PermissionDirective, + ReplaceableRouteContainerComponent, + ReplaceableTemplateDirective, + RouterOutletComponent, + SortPipe, + StopPropagationDirective, + ToInjectorPipe, + ShortDateTimePipe, + ShortTimePipe, + ShortDatePipe, + ], + providers: [LocalizationPipe], }) export class BaseCoreModule {} diff --git a/npm/ng-packs/packages/core/src/lib/pipes/index.ts b/npm/ng-packs/packages/core/src/lib/pipes/index.ts index 7ac9f76a33..71ce383cd3 100644 --- a/npm/ng-packs/packages/core/src/lib/pipes/index.ts +++ b/npm/ng-packs/packages/core/src/lib/pipes/index.ts @@ -4,4 +4,3 @@ export * from './to-injector.pipe'; export * from './short-date.pipe'; export * from './short-time.pipe'; export * from './short-date-time.pipe'; -export * from './pipe-function.pipe'; diff --git a/npm/ng-packs/packages/core/src/lib/pipes/pipe-function.pipe.ts b/npm/ng-packs/packages/core/src/lib/pipes/pipe-function.pipe.ts deleted file mode 100644 index efb0f8acaa..0000000000 --- a/npm/ng-packs/packages/core/src/lib/pipes/pipe-function.pipe.ts +++ /dev/null @@ -1,14 +0,0 @@ -import {Pipe, PipeTransform} from "@angular/core"; - -@Pipe({ - name: 'pipeFunction' -}) -export class PipeFunction implements PipeTransform { - public transform(value: any, handler: (value: any) => any, context?: any): any { - if (context) { - return handler.call(context, value); - } - - return handler(value); - } -} diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/abstract-actions/abstract-actions.component.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/abstract-actions/abstract-actions.component.ts index 6f24273812..285e3fd00a 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/abstract-actions/abstract-actions.component.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/abstract-actions/abstract-actions.component.ts @@ -2,6 +2,7 @@ import { Directive, Injector, Input } from '@angular/core'; import { ActionData, ActionList } from '../../models/actions'; import { ExtensionsService } from '../../services/extensions.service'; import { EXTENSIONS_ACTION_TYPE, EXTENSIONS_IDENTIFIER } from '../../tokens/extensions.token'; +import { InferredData, InferredRecord } from '../../models/toolbar-actions'; // Fix for https://github.com/angular/angular/issues/23904 // @dynamic @@ -25,6 +26,3 @@ export abstract class AbstractActionsComponent> extend this.actionList = extensions[type].get(name).actions as unknown as L; } } - -type InferredData = ActionData>; -type InferredRecord = L extends ActionList ? R : never; diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html index 32b4c9ba42..4cf968e6de 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html @@ -8,7 +8,10 @@ diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts index dfd7c0105d..db5c9cd167 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts @@ -1,18 +1,6 @@ -import { - ChangeDetectionStrategy, - Component, - InjectFlags, - InjectionToken, - Injector, - TrackByFunction, - Type, -} from '@angular/core'; +import { ChangeDetectionStrategy, Component, Injector, TrackByFunction } from '@angular/core'; import { ToolbarActionList, ToolbarComponent } from '../../models/toolbar-actions'; -import { - EXTENSIONS_ACTION_CALLBACK, - EXTENSIONS_ACTION_DATA, - EXTENSIONS_ACTION_TYPE, -} from '../../tokens/extensions.token'; +import { EXTENSIONS_ACTION_TYPE } from '../../tokens/extensions.token'; import { AbstractActionsComponent } from '../abstract-actions/abstract-actions.component'; @Component({ @@ -34,16 +22,4 @@ export class PageToolbarComponent extends AbstractActionsComponent): Injector { - const get = (token: Type | InjectionToken, notFoundValue?: T, flags?: InjectFlags) => { - return token === EXTENSIONS_ACTION_DATA - ? this.data - : token === EXTENSIONS_ACTION_CALLBACK - ? (data = this.data) => action.action(data) - : this.getInjected.call(this.injector, token, notFoundValue, flags); - }; - - return { get }; - } } diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts index 1a311d7a5d..0ed857d235 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts @@ -3,11 +3,11 @@ import { O } from 'ts-toolbelt'; import { Action, ActionContributorCallback, - ActionContributorCallbacks, + ActionContributorCallbacks, ActionData, ActionList, Actions, - ActionsFactory, -} from './actions'; + ActionsFactory +} from "./actions"; export class ToolbarActionList extends ActionList< R, @@ -77,3 +77,5 @@ export type ToolbarActionContributorCallback = ActionContributorCallbac export type ToolbarActionContributorCallbacks = ActionContributorCallbacks< ToolbarActionList >; +export type InferredData = ActionData>; +export type InferredRecord = L extends ActionList ? R : never; diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts new file mode 100644 index 0000000000..6569447198 --- /dev/null +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts @@ -0,0 +1,29 @@ +import { InjectFlags, InjectionToken, Injector, Pipe, PipeTransform, Type } from '@angular/core'; +import { InferredData, ToolbarComponent } from '../models/toolbar-actions'; +import { + EXTENSIONS_ACTION_CALLBACK, + EXTENSIONS_ACTION_DATA, +} from '@abp/ng.theme.shared/extensions'; +import { ReadonlyActionData } from '../models/actions'; + +@Pipe({ + name: 'createInjector', +}) +export class CreateInjectorPipe implements PipeTransform { + constructor(private injector: Injector) {} + + public transform( + action: ToolbarComponent, + componentData: ReadonlyActionData, + getInjectedFn: InferredData['getInjected'], + ): Injector { + const get = (token: Type | InjectionToken, notFoundValue?: T, flags?: InjectFlags) => { + return token === EXTENSIONS_ACTION_DATA + ? componentData + : token === EXTENSIONS_ACTION_CALLBACK + ? (data = componentData) => action.action(data) + : getInjectedFn.call(this.injector, token, notFoundValue, flags); + }; + return { get }; + } +} diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/ui-extensions.module.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/ui-extensions.module.ts index 28456e0324..398b1b2488 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/ui-extensions.module.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/ui-extensions.module.ts @@ -16,6 +16,7 @@ import { GridActionsComponent } from './components/grid-actions/grid-actions.com import { PageToolbarComponent } from './components/page-toolbar/page-toolbar.component'; import { DisabledDirective } from './directives/disabled.directive'; import { PropDataDirective } from './directives/prop-data.directive'; +import { CreateInjectorPipe } from './pipes'; @NgModule({ exports: [ @@ -26,6 +27,7 @@ import { PropDataDirective } from './directives/prop-data.directive'; ExtensibleTableComponent, PropDataDirective, DisabledDirective, + CreateInjectorPipe, ], declarations: [ DateTimePickerComponent, @@ -36,6 +38,7 @@ import { PropDataDirective } from './directives/prop-data.directive'; ExtensibleTableComponent, PropDataDirective, DisabledDirective, + CreateInjectorPipe, ], imports: [ CoreModule, diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/public-api.ts b/npm/ng-packs/packages/theme-shared/extensions/src/public-api.ts index a3afbe7efd..b19f8eb0d9 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/public-api.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/public-api.ts @@ -61,6 +61,7 @@ export { ToolbarComponent, ToolbarComponentOptions, } from './lib/models/toolbar-actions'; +export * from './lib/pipes/create-injector.pipe'; export * from './lib/services/extensions.service'; export * from './lib/tokens/extensions.token'; export * from './lib/ui-extensions.module'; From 8b104856c53b4552ab6f6f7bc3bcf03e9f447ae0 Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Thu, 9 Jun 2022 23:38:22 +0300 Subject: [PATCH 4/8] change import path --- .../theme-shared/extensions/src/lib/ui-extensions.module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/ui-extensions.module.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/ui-extensions.module.ts index 398b1b2488..aebaa16036 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/ui-extensions.module.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/ui-extensions.module.ts @@ -16,7 +16,7 @@ import { GridActionsComponent } from './components/grid-actions/grid-actions.com import { PageToolbarComponent } from './components/page-toolbar/page-toolbar.component'; import { DisabledDirective } from './directives/disabled.directive'; import { PropDataDirective } from './directives/prop-data.directive'; -import { CreateInjectorPipe } from './pipes'; +import { CreateInjectorPipe } from './pipes/create-injector.pipe'; @NgModule({ exports: [ From fc4e75c30f180c7cf2a95590a2821778f3c0fa80 Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Fri, 10 Jun 2022 14:50:42 +0300 Subject: [PATCH 5/8] update injector value on record input change --- .../page-toolbar/page-toolbar.component.html | 5 +--- .../page-toolbar/page-toolbar.component.ts | 5 ++-- .../src/lib/pipes/create-injector.pipe.ts | 23 +++++++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html index 4cf968e6de..30a58c7772 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.html @@ -8,10 +8,7 @@ diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts index db5c9cd167..a358924461 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts @@ -16,10 +16,11 @@ import { AbstractActionsComponent } from '../abstract-actions/abstract-actions.c changeDetection: ChangeDetectionStrategy.OnPush, }) export class PageToolbarComponent extends AbstractActionsComponent> { + getData = () => this.data; + readonly trackByFn: TrackByFunction> = (_, item) => item.action || item.component; - - constructor(private readonly injector: Injector) { + constructor(public readonly injector: Injector) { super(injector); } } diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts index 6569447198..0268f6b539 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts @@ -1,28 +1,27 @@ import { InjectFlags, InjectionToken, Injector, Pipe, PipeTransform, Type } from '@angular/core'; -import { InferredData, ToolbarComponent } from '../models/toolbar-actions'; -import { - EXTENSIONS_ACTION_CALLBACK, - EXTENSIONS_ACTION_DATA, -} from '@abp/ng.theme.shared/extensions'; -import { ReadonlyActionData } from '../models/actions'; +import { ToolbarComponent } from '../models/toolbar-actions'; +import { EXTENSIONS_ACTION_CALLBACK, EXTENSIONS_ACTION_DATA } from '../tokens/extensions.token'; +import { PageToolbarComponent } from '../components/page-toolbar/page-toolbar.component'; @Pipe({ name: 'createInjector', }) export class CreateInjectorPipe implements PipeTransform { - constructor(private injector: Injector) {} - public transform( + _: any, action: ToolbarComponent, - componentData: ReadonlyActionData, - getInjectedFn: InferredData['getInjected'], + context: PageToolbarComponent, ): Injector { const get = (token: Type | InjectionToken, notFoundValue?: T, flags?: InjectFlags) => { + const componentData = context.getData(); return token === EXTENSIONS_ACTION_DATA ? componentData : token === EXTENSIONS_ACTION_CALLBACK - ? (data = componentData) => action.action(data) - : getInjectedFn.call(this.injector, token, notFoundValue, flags); + ? data => { + data = data ?? context.getData(); + return action.action(data); + } + : context.getInjected.call(context.injector, token, notFoundValue, flags); }; return { get }; } From 96099f0bbcb3baa0432bbca879adf3e7a472accc Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Mon, 13 Jun 2022 11:17:33 +0300 Subject: [PATCH 6/8] reformat --- .../extensions/src/lib/models/toolbar-actions.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts index a82d9b9daa..93f634c28b 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts @@ -3,11 +3,12 @@ import { O } from 'ts-toolbelt'; import { Action, ActionContributorCallback, - ActionContributorCallbacks, ActionData, + ActionContributorCallbacks, + ActionData, ActionList, Actions, - ActionsFactory -} from "./actions"; + ActionsFactory, +} from './actions'; export class ToolbarActionList extends ActionList< R, @@ -31,9 +32,9 @@ export class ToolbarAction extends Action { super(options.permission || '', options.visible, options.action); this.text = options.text; this.icon = options.icon || ''; - if(options.btnClass){ - this.btnClass = options.btnClass; - }; + if (options.btnClass) { + this.btnClass = options.btnClass; + } } static create(options: ToolbarActionOptions) { From f75cfa9a6b58ed9a33b631b4972f8cd8faad033f Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Mon, 13 Jun 2022 11:46:34 +0300 Subject: [PATCH 7/8] add an interface for cycle dependency problem --- .../components/page-toolbar/page-toolbar.component.ts | 11 +++++++++-- .../extensions/src/lib/models/toolbar-actions.ts | 9 ++++++++- .../extensions/src/lib/pipes/create-injector.pipe.ts | 5 ++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts index 0ed3559d33..8015aaa84f 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/page-toolbar/page-toolbar.component.ts @@ -1,5 +1,9 @@ import { ChangeDetectionStrategy, Component, Injector, TrackByFunction } from '@angular/core'; -import { ToolbarActionList, ToolbarComponent } from '../../models/toolbar-actions'; +import { + HasCreateInjectorPipe, + ToolbarActionList, + ToolbarComponent, +} from '../../models/toolbar-actions'; import { EXTENSIONS_ACTION_TYPE } from '../../tokens/extensions.token'; import { AbstractActionsComponent } from '../abstract-actions/abstract-actions.component'; @@ -15,7 +19,10 @@ import { AbstractActionsComponent } from '../abstract-actions/abstract-actions.c ], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class PageToolbarComponent extends AbstractActionsComponent> { +export class PageToolbarComponent + extends AbstractActionsComponent> + implements HasCreateInjectorPipe +{ defaultBtnClass = 'btn btn-sm btn-primary'; getData = () => this.data; diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts index 93f634c28b..048ce486c8 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/models/toolbar-actions.ts @@ -1,4 +1,4 @@ -import { Type } from '@angular/core'; +import { Injector, Type } from '@angular/core'; import { O } from 'ts-toolbelt'; import { Action, @@ -8,6 +8,7 @@ import { ActionList, Actions, ActionsFactory, + ReadonlyActionData, } from './actions'; export class ToolbarActionList extends ActionList< @@ -84,3 +85,9 @@ export type ToolbarActionContributorCallbacks = ActionContributorCallba >; export type InferredData = ActionData>; export type InferredRecord = L extends ActionList ? R : never; + +export interface HasCreateInjectorPipe { + getData: () => ReadonlyActionData; + injector: Injector; + getInjected: InferredData>['getInjected']; +} diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts index 0268f6b539..8223c07d22 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts @@ -1,7 +1,6 @@ import { InjectFlags, InjectionToken, Injector, Pipe, PipeTransform, Type } from '@angular/core'; -import { ToolbarComponent } from '../models/toolbar-actions'; +import { HasCreateInjectorPipe, ToolbarComponent } from '../models/toolbar-actions'; import { EXTENSIONS_ACTION_CALLBACK, EXTENSIONS_ACTION_DATA } from '../tokens/extensions.token'; -import { PageToolbarComponent } from '../components/page-toolbar/page-toolbar.component'; @Pipe({ name: 'createInjector', @@ -10,7 +9,7 @@ export class CreateInjectorPipe implements PipeTransform { public transform( _: any, action: ToolbarComponent, - context: PageToolbarComponent, + context: HasCreateInjectorPipe, ): Injector { const get = (token: Type | InjectionToken, notFoundValue?: T, flags?: InjectFlags) => { const componentData = context.getData(); From 998181255ed50a9322b29c56e715e203585bd172 Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Mon, 13 Jun 2022 14:25:43 +0300 Subject: [PATCH 8/8] change inline if to switch case --- .../src/lib/pipes/create-injector.pipe.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts index 8223c07d22..7941a2fe56 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/pipes/create-injector.pipe.ts @@ -13,14 +13,22 @@ export class CreateInjectorPipe implements PipeTransform { ): Injector { const get = (token: Type | InjectionToken, notFoundValue?: T, flags?: InjectFlags) => { const componentData = context.getData(); - return token === EXTENSIONS_ACTION_DATA - ? componentData - : token === EXTENSIONS_ACTION_CALLBACK - ? data => { - data = data ?? context.getData(); - return action.action(data); - } - : context.getInjected.call(context.injector, token, notFoundValue, flags); + const componentDataCallback = data => { + data = data ?? context.getData(); + return action.action(data); + }; + let extensionData; + switch (token) { + case EXTENSIONS_ACTION_DATA: + extensionData = componentData; + break; + case EXTENSIONS_ACTION_CALLBACK: + extensionData = componentDataCallback; + break; + default: + extensionData = context.getInjected.call(context.injector, token, notFoundValue, flags); + } + return extensionData; }; return { get }; }