Browse Source

Merge pull request #5048 from abpframework/feat/5047

Added action callback property to EntityProp for extensible table
pull/5058/head
Levent Arman Özak 6 years ago
committed by GitHub
parent
commit
380a263dad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      npm/ng-packs/.vscode/settings.json
  2. 2
      npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-table/extensible-table.component.html
  3. 5
      npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-table/extensible-table.component.ts
  4. 4
      npm/ng-packs/packages/theme-shared/extensions/src/lib/models/entity-props.ts

4
npm/ng-packs/.vscode/settings.json

@ -18,9 +18,7 @@
"titleBar.inactiveForeground": "#e7e7e799", "titleBar.inactiveForeground": "#e7e7e799",
"statusBar.background": "#1d70a2", "statusBar.background": "#1d70a2",
"statusBarItem.hoverBackground": "#258ecd", "statusBarItem.hoverBackground": "#258ecd",
"statusBar.foreground": "#e7e7e7", "statusBar.foreground": "#e7e7e7"
"statusBar.border": "#1d70a2",
"titleBar.border": "#1d70a2"
}, },
"peacock.color": "#1D70A2" "peacock.color": "#1D70A2"
} }

2
npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-table/extensible-table.component.html

@ -1,5 +1,6 @@
<ngx-datatable default [rows]="data" [count]="recordsTotal" [list]="list"> <ngx-datatable default [rows]="data" [count]="recordsTotal" [list]="list">
<ngx-datatable-column <ngx-datatable-column
*ngIf="actionsTemplate || actionList.length"
[name]="actionsText | abpLocalization" [name]="actionsText | abpLocalization"
[maxWidth]="columnWidths[0]" [maxWidth]="columnWidths[0]"
[width]="columnWidths[0]" [width]="columnWidths[0]"
@ -31,6 +32,7 @@
<div <div
*ngIf="row['_' + prop.name].visible" *ngIf="row['_' + prop.name].visible"
[innerHTML]="row['_' + prop.name].value | async" [innerHTML]="row['_' + prop.name].value | async"
(click)="prop.action({ getInjected: getInjected, record: row, index: i })"
></div> ></div>
</ng-container> </ng-container>
</ng-template> </ng-template>

5
npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-table/extensible-table.component.ts

@ -22,6 +22,7 @@ import { EntityProp, EntityPropList } from '../../models/entity-props';
import { PropData } from '../../models/props'; import { PropData } from '../../models/props';
import { ExtensionsService } from '../../services/extensions.service'; import { ExtensionsService } from '../../services/extensions.service';
import { EXTENSIONS_IDENTIFIER } from '../../tokens/extensions.token'; import { EXTENSIONS_IDENTIFIER } from '../../tokens/extensions.token';
import { EntityActionList } from '../../models/entity-actions';
const DEFAULT_ACTIONS_COLUMN_WIDTH = 150; const DEFAULT_ACTIONS_COLUMN_WIDTH = 150;
@Component({ @Component({
@ -46,6 +47,8 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
readonly propList: EntityPropList<R>; readonly propList: EntityPropList<R>;
readonly actionList: EntityActionList<R>;
readonly trackByFn: TrackByFunction<EntityProp<R>> = (_, item) => item.name; readonly trackByFn: TrackByFunction<EntityProp<R>> = (_, item) => item.name;
constructor(@Inject(LOCALE_ID) private locale: string, injector: Injector) { constructor(@Inject(LOCALE_ID) private locale: string, injector: Injector) {
@ -54,6 +57,8 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
const extensions = injector.get(ExtensionsService); const extensions = injector.get(ExtensionsService);
const name = injector.get(EXTENSIONS_IDENTIFIER); const name = injector.get(EXTENSIONS_IDENTIFIER);
this.propList = extensions.entityProps.get(name).props; this.propList = extensions.entityProps.get(name).props;
this.actionList = (extensions['entityActions'].get(name)
.actions as unknown) as EntityActionList<R>;
this.setColumnWidths(DEFAULT_ACTIONS_COLUMN_WIDTH); this.setColumnWidths(DEFAULT_ACTIONS_COLUMN_WIDTH);
} }

4
npm/ng-packs/packages/theme-shared/extensions/src/lib/models/entity-props.ts

@ -11,6 +11,7 @@ import {
Props, Props,
PropsFactory, PropsFactory,
} from './props'; } from './props';
import { ActionCallback } from './actions';
export class EntityPropList<R = any> extends PropList<R, EntityProp<R>> {} export class EntityPropList<R = any> extends PropList<R, EntityProp<R>> {}
@ -26,6 +27,7 @@ export class EntityProp<R = any> extends Prop<R> {
readonly columnWidth: number | undefined; readonly columnWidth: number | undefined;
readonly sortable: boolean; readonly sortable: boolean;
readonly valueResolver: PropCallback<R, Observable<any>>; readonly valueResolver: PropCallback<R, Observable<any>>;
readonly action: ActionCallback<R>;
constructor(options: EntityPropOptions<R>) { constructor(options: EntityPropOptions<R>) {
super( super(
@ -40,6 +42,7 @@ export class EntityProp<R = any> extends Prop<R> {
this.columnWidth = options.columnWidth; this.columnWidth = options.columnWidth;
this.sortable = options.sortable || false; this.sortable = options.sortable || false;
this.valueResolver = options.valueResolver || (data => of(data.record[this.name])); this.valueResolver = options.valueResolver || (data => of(data.record[this.name]));
this.action = options.action || (_ => {});
} }
static create<R = any>(options: EntityPropOptions<R>) { static create<R = any>(options: EntityPropOptions<R>) {
@ -60,6 +63,7 @@ export type EntityPropOptions<R = any> = O.Optional<
| 'columnWidth' | 'columnWidth'
| 'sortable' | 'sortable'
| 'valueResolver' | 'valueResolver'
| 'action'
>; >;
export type EntityPropDefaults<R = any> = Record<string, EntityProp<R>[]>; export type EntityPropDefaults<R = any> = Record<string, EntityProp<R>[]>;

Loading…
Cancel
Save