@smallpearl/ngx-helper 0.29.23 → 0.29.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -516,24 +516,26 @@ class SPMatEntityCrudComponent extends SPMatEntityListComponent {
516
516
  // entity so that we can run per item's allow item action function to
517
517
  // selectively disable one or more actions based on the item's state.
518
518
  _itemActions = computed(() => {
519
- const actions = this.itemActions() && this.itemActions().length
520
- ? this.itemActions()
521
- : this.defaultItemCrudActions();
522
- let actionsCopy = JSON.parse(JSON.stringify(actions));
523
- actionsCopy.forEach((action, index) => {
524
- const orgDisable = actions[index]?.disable;
525
- action.disable = (entity) => {
526
- if (orgDisable) {
527
- return orgDisable(entity);
528
- }
529
- const allowItemActionFn = this.allowEntityActionFn();
530
- if (allowItemActionFn) {
531
- return !allowItemActionFn(entity, action.role ?? action.label);
532
- }
533
- return false;
534
- };
535
- });
536
- return actionsCopy;
519
+ return this.getItemActions();
520
+ // const actions =
521
+ // this.itemActions() && this.itemActions().length
522
+ // ? this.itemActions()
523
+ // : this.defaultItemCrudActions();
524
+ // let actionsCopy: SPContextMenuItem[] = JSON.parse(JSON.stringify(actions));
525
+ // actionsCopy.forEach((action, index: number) => {
526
+ // const orgDisable = actions[index]?.disable;
527
+ // action.disable = (entity: TEntity) => {
528
+ // if (orgDisable) {
529
+ // return orgDisable(entity);
530
+ // }
531
+ // const allowItemActionFn = this.allowEntityActionFn();
532
+ // if (allowItemActionFn) {
533
+ // return !allowItemActionFn(entity, action.role ?? action.label);
534
+ // }
535
+ // return false;
536
+ // };
537
+ // });
538
+ // return actionsCopy;
537
539
  });
538
540
  // This uses the previewActive signal to compute the visible columns
539
541
  // when preview is activated. For now we just hide the 'action' column when
@@ -615,8 +617,8 @@ class SPMatEntityCrudComponent extends SPMatEntityListComponent {
615
617
  }
616
618
  return true;
617
619
  }
618
- refresh() {
619
- this.spEntitiesList()?.refresh();
620
+ refresh(force = false) {
621
+ this.spEntitiesList()?.refresh(force);
620
622
  }
621
623
  closeCreateEdit(cancelled) {
622
624
  this.createEditViewActive.set(false);
@@ -700,7 +702,7 @@ class SPMatEntityCrudComponent extends SPMatEntityListComponent {
700
702
  }));
701
703
  }
702
704
  else if (refreshAfterEdit === 'all') {
703
- this.spEntitiesList()?.refresh();
705
+ this.refresh(true);
704
706
  return of(null);
705
707
  }
706
708
  return of(entity);
@@ -796,7 +798,7 @@ class SPMatEntityCrudComponent extends SPMatEntityListComponent {
796
798
  */
797
799
  showCreateEditView(entity, params) {
798
800
  const tmpl = this.createEditFormTemplate();
799
- if (!this.createEditViewActive() && !this.previewActive() && tmpl) {
801
+ if (!this.createEditViewActive() && tmpl) {
800
802
  // If preview is active deactivate it
801
803
  if (this.previewActive()) {
802
804
  this.closePreviewImpl(true);
@@ -941,6 +943,34 @@ class SPMatEntityCrudComponent extends SPMatEntityListComponent {
941
943
  // ? contextParamToHttpContext(httpReqContext)
942
944
  // : undefined;
943
945
  }
946
+ isItemActionAllowed(action, entity) {
947
+ return false;
948
+ }
949
+ /**
950
+ * Returns the list of item actions. Calls 'allowItemActionFn' for each action
951
+ * to determine if the action is allowed for the given entity.
952
+ * @returns
953
+ */
954
+ getItemActions() {
955
+ const actions = this.itemActions() && this.itemActions().length
956
+ ? this.itemActions()
957
+ : this.defaultItemCrudActions();
958
+ let actionsCopy = JSON.parse(JSON.stringify(actions));
959
+ actionsCopy.forEach((action, index) => {
960
+ const orgDisable = actions[index]?.disable;
961
+ action.disable = (entity) => {
962
+ if (orgDisable) {
963
+ return orgDisable(entity);
964
+ }
965
+ const allowItemActionFn = this.allowEntityActionFn();
966
+ if (allowItemActionFn) {
967
+ return !allowItemActionFn(entity, action.role ?? action.label);
968
+ }
969
+ return false;
970
+ };
971
+ });
972
+ return actionsCopy;
973
+ }
944
974
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.6", ngImport: i0, type: SPMatEntityCrudComponent, deps: [{ token: i1$1.HttpClient }, { token: i2$1.MatSnackBar }, { token: i3.DomSanitizer }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component });
945
975
  /** @nocollapse */ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.6", type: SPMatEntityCrudComponent, isStandalone: true, selector: "sp-mat-entity-crud", inputs: { itemLabel: { classPropertyName: "itemLabel", publicName: "itemLabel", isSignal: true, isRequired: false, transformFunction: null }, itemLabelPlural: { classPropertyName: "itemLabelPlural", publicName: "itemLabelPlural", isSignal: true, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null }, itemActions: { classPropertyName: "itemActions", publicName: "itemActions", isSignal: true, isRequired: false, transformFunction: null }, newItemLink: { classPropertyName: "newItemLink", publicName: "newItemLink", isSignal: true, isRequired: false, transformFunction: null }, newItemLabel: { classPropertyName: "newItemLabel", publicName: "newItemLabel", isSignal: true, isRequired: false, transformFunction: null }, editItemTitle: { classPropertyName: "editItemTitle", publicName: "editItemTitle", isSignal: true, isRequired: false, transformFunction: null }, newItemSubTypes: { classPropertyName: "newItemSubTypes", publicName: "newItemSubTypes", isSignal: true, isRequired: false, transformFunction: null }, crudOpFn: { classPropertyName: "crudOpFn", publicName: "crudOpFn", isSignal: true, isRequired: false, transformFunction: null }, previewTemplate: { classPropertyName: "previewTemplate", publicName: "previewTemplate", isSignal: true, isRequired: false, transformFunction: null }, allowEntityActionFn: { classPropertyName: "allowEntityActionFn", publicName: "allowEntityActionFn", isSignal: true, isRequired: false, transformFunction: null }, headerTemplate: { classPropertyName: "headerTemplate", publicName: "headerTemplate", isSignal: true, isRequired: false, transformFunction: null }, actionsTemplate: { classPropertyName: "actionsTemplate", publicName: "actionsTemplate", isSignal: true, isRequired: false, transformFunction: null }, crudResponseParser: { classPropertyName: "crudResponseParser", publicName: "crudResponseParser", isSignal: true, isRequired: false, transformFunction: null }, createEditFormTemplate: { classPropertyName: "createEditFormTemplate", publicName: "createEditFormTemplate", isSignal: true, isRequired: false, transformFunction: null }, disableItemActions: { classPropertyName: "disableItemActions", publicName: "disableItemActions", isSignal: true, isRequired: false, transformFunction: null }, disableCreate: { classPropertyName: "disableCreate", publicName: "disableCreate", isSignal: true, isRequired: false, transformFunction: null }, refreshAfterEdit: { classPropertyName: "refreshAfterEdit", publicName: "refreshAfterEdit", isSignal: true, isRequired: false, transformFunction: null }, crudHttpReqContext: { classPropertyName: "crudHttpReqContext", publicName: "crudHttpReqContext", isSignal: true, isRequired: false, transformFunction: null }, editPaneWidth: { classPropertyName: "editPaneWidth", publicName: "editPaneWidth", isSignal: true, isRequired: false, transformFunction: null }, previewPaneWidth: { classPropertyName: "previewPaneWidth", publicName: "previewPaneWidth", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { action: "action", entityViewPaneActivated: "entityViewPaneActivated" }, queries: [{ propertyName: "_clientColumnDefs", predicate: MatColumnDef }], viewQueries: [{ propertyName: "componentColumns", predicate: MatColumnDef, descendants: true, isSignal: true }, { propertyName: "spEntitiesList", first: true, predicate: (SPMatEntityListComponent), descendants: true, isSignal: true }, { propertyName: "createEditHostComponent", first: true, predicate: FormViewHostComponent, descendants: true, isSignal: true }, { propertyName: "previewHostComponent", first: true, predicate: PreviewHostComponent, descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: `
946
976
  <as-split direction="horizontal" [gutterSize]="6">
@@ -1264,6 +1294,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.6", ngImpor
1264
1294
  type: Output
1265
1295
  }] } });
1266
1296
 
1297
+ const ITEM_ACTION_UPDATE = '_update_';
1298
+ const ITEM_ACTION_DELETE = '_delete_';
1299
+
1267
1300
  /**
1268
1301
  * A preview pane container to provide a consistent UX for all preview panes.
1269
1302
  * It consits of a toolbar on the top and a container div below that takes up
@@ -1278,10 +1311,26 @@ class SPMatEntityCrudPreviewPaneComponent {
1278
1311
  disableDelete = input(false);
1279
1312
  hideDelete = input(false);
1280
1313
  config;
1314
+ itemActions;
1315
+ _disableActionFactory = (role, signal) => {
1316
+ return computed(() => {
1317
+ if (signal && signal()) {
1318
+ return true;
1319
+ }
1320
+ const actionFn = this.itemActions.find((a) => a.role === role)?.disable;
1321
+ if (actionFn && actionFn(this.entity())) {
1322
+ return true;
1323
+ }
1324
+ return false;
1325
+ });
1326
+ };
1327
+ _disableUpdate = this._disableActionFactory(ITEM_ACTION_UPDATE, this.disableUpdate);
1328
+ _disableDelete = this._disableActionFactory(ITEM_ACTION_DELETE, this.disableDelete);
1281
1329
  constructor() {
1282
1330
  this.config = getEntityCrudConfig();
1283
1331
  }
1284
1332
  ngOnInit() {
1333
+ this.itemActions = this.entityCrudComponent().getItemActions();
1285
1334
  }
1286
1335
  ngOnDestroy() {
1287
1336
  }
@@ -1303,12 +1352,12 @@ class SPMatEntityCrudPreviewPaneComponent {
1303
1352
  <h2>{{ title() }}</h2>&nbsp;
1304
1353
  }
1305
1354
  @if (!hideUpdate()) {
1306
- <button mat-icon-button aria-label="Edit" (click)="onEdit()" [disabled]="disableUpdate()">
1355
+ <button mat-icon-button aria-label="Edit" (click)="onEdit()" [disabled]="_disableUpdate()">
1307
1356
  <mat-icon>edit</mat-icon>
1308
1357
  </button>
1309
1358
  }
1310
1359
  @if (!hideDelete()) {
1311
- <button mat-icon-button aria-label="Delete" (click)="onDelete()" [disabled]="disableDelete()">
1360
+ <button mat-icon-button aria-label="Delete" (click)="onDelete()" [disabled]="_disableDelete()">
1312
1361
  <mat-icon>delete</mat-icon>
1313
1362
  </button>
1314
1363
  }
@@ -1335,12 +1384,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.6", ngImpor
1335
1384
  <h2>{{ title() }}</h2>&nbsp;
1336
1385
  }
1337
1386
  @if (!hideUpdate()) {
1338
- <button mat-icon-button aria-label="Edit" (click)="onEdit()" [disabled]="disableUpdate()">
1387
+ <button mat-icon-button aria-label="Edit" (click)="onEdit()" [disabled]="_disableUpdate()">
1339
1388
  <mat-icon>edit</mat-icon>
1340
1389
  </button>
1341
1390
  }
1342
1391
  @if (!hideDelete()) {
1343
- <button mat-icon-button aria-label="Delete" (click)="onDelete()" [disabled]="disableDelete()">
1392
+ <button mat-icon-button aria-label="Delete" (click)="onDelete()" [disabled]="_disableDelete()">
1344
1393
  <mat-icon>delete</mat-icon>
1345
1394
  </button>
1346
1395
  }