@rxap/material-table-system 12.5.1 → 12.5.2

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.
@@ -21,6 +21,7 @@ export class TableRowActionDirective {
21
21
  this.matButton = matButton;
22
22
  this._hasConfirmDirective = false;
23
23
  this._currentStatus = TableRowActionStatus.DONE;
24
+ this._actionDisabled = false;
24
25
  this.actionMethodList = coerceArray(actionMethodList);
25
26
  }
26
27
  set hasConfirmDirective(value) {
@@ -43,6 +44,9 @@ export class TableRowActionDirective {
43
44
  }
44
45
  execute() {
45
46
  return __awaiter(this, void 0, void 0, function* () {
47
+ if (this._actionDisabled) {
48
+ return Promise.resolve();
49
+ }
46
50
  this.setStatus(TableRowActionStatus.EXECUTING);
47
51
  try {
48
52
  yield Promise.all(this.getElementList().map((element) => {
@@ -78,15 +82,26 @@ export class TableRowActionDirective {
78
82
  findTypedActionMethod() {
79
83
  return this.actionMethodList.filter(IsTableRowActionTypeMethod(this.type));
80
84
  }
85
+ /**
86
+ * Disables the action. If the button is pressed the action is NOT executed
87
+ *
88
+ * Hint: the button is set to disabled = true to prevent any conflict with
89
+ * extern button enable features linke : rxapHasEnablePermission
90
+ * @protected
91
+ */
81
92
  setButtonDisabled() {
82
- if (this.matButton) {
83
- this.matButton.disabled = true;
84
- }
93
+ this._actionDisabled = true;
85
94
  }
95
+ /**
96
+ * Enables the action. If the button is pressed the action is executed
97
+ *
98
+ * TODO : find a way to communicate the disabled state between the features
99
+ * Hint: the button is set to disabled = false to prevent any conflict with
100
+ * extern button enable features linke : rxapHasEnablePermission
101
+ * @protected
102
+ */
86
103
  setButtonEnabled() {
87
- if (this.matButton) {
88
- this.matButton.disabled = false;
89
- }
104
+ this._actionDisabled = false;
90
105
  }
91
106
  setStatus(status) {
92
107
  var _a, _b;
@@ -1 +1 @@
1
- {"version":3,"file":"table-row-action.directive.js","sourceRoot":"","sources":["../../../../../../../libs/material/table-system/src/lib/table-row-actions/table-row-action.directive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AAY;uBAAC,OAAO,EAAE,CAAE,QAAQ,CAAE","sourcesContent":["import {\n ChangeDetectorRef,\n ContentChild,\n Directive,\n HostListener,\n Inject,\n Input,\n isDevMode,\n Optional,\n ViewContainerRef\n} from '@angular/core';\nimport { MatButton } from '@angular/material/button';\nimport { MatSnackBar } from '@angular/material/snack-bar';\nimport {\n coerceArray,\n coerceBoolean,\n Required\n} from '@rxap/utilities';\nimport { TableRowActionExecutingDirective } from './table-row-action-executing.directive';\nimport { TableRowActionStatus } from './table-row-action-status';\nimport {\n IsTableRowActionTypeMethod,\n IsTableRowActionTypeSwitchMethod,\n TableRowActionMethod,\n TableRowActionTypeMethod,\n TableRowActionTypeSwitchMethod\n} from './table-row-action.method';\nimport { RXAP_TABLE_ROW_ACTION_METHOD } from './tokens';\nimport { TableDataSourceDirective } from '../table-data-source.directive';\n\n@Directive({\n selector: 'button[rxapTableRowAction]'\n})\nexport class TableRowActionDirective<Data extends Record<string, any>> {\n private _hasConfirmDirective = false;\n\n @Input('rxapConfirm')\n public set hasConfirmDirective(value: any) {\n this._hasConfirmDirective = coerceBoolean(value);\n }\n\n @Input()\n @Required\n public element!: Data;\n @Input('rxapTableRowAction')\n @Required\n public type!: string;\n\n @Input()\n public errorMessage?: string;\n\n @Input()\n public successMessage?: string;\n\n /**\n * true - after the action is executed the table datasource is refreshed\n */\n @Input()\n public refresh?: boolean;\n\n @ContentChild(TableRowActionExecutingDirective)\n private readonly executingDirective?: TableRowActionExecutingDirective;\n private _currentStatus: TableRowActionStatus = TableRowActionStatus.DONE;\n\n private readonly actionMethodList: Array<TableRowActionMethod<Data>>;\n\n constructor(\n @Inject(RXAP_TABLE_ROW_ACTION_METHOD)\n actionMethodList:\n | Array<TableRowActionMethod<Data>>\n | TableRowActionMethod<Data>,\n @Inject(ChangeDetectorRef)\n protected readonly cdr: ChangeDetectorRef,\n @Inject(ViewContainerRef)\n private readonly vcr: ViewContainerRef,\n @Inject(TableDataSourceDirective)\n private readonly tableDataSourceDirective: TableDataSourceDirective,\n @Inject(MatSnackBar)\n private readonly snackBar: MatSnackBar,\n @Optional()\n @Inject(MatButton)\n private readonly matButton: MatButton | null\n ) {\n this.actionMethodList = coerceArray(actionMethodList);\n }\n\n @HostListener('confirmed')\n public onConfirmed() {\n return this.execute();\n }\n\n @HostListener('click', [ '$event' ])\n public onClick($event: Event) {\n $event.stopPropagation();\n if (!this._hasConfirmDirective) {\n return this.execute();\n } else {\n if (isDevMode()) {\n console.debug('skip remote method call. Wait for confirmation.');\n }\n }\n return Promise.resolve();\n }\n\n public async execute(): Promise<void> {\n this.setStatus(TableRowActionStatus.EXECUTING);\n try {\n await Promise.all(\n this.getElementList().map((element) => {\n return Promise.all([\n Promise.all(\n this.findUntypedActionMethod().map((am) =>\n am.call({ element, type: this.type })\n )\n ),\n Promise.all(\n this.findTypedActionMethod().map((am) => am.call(element))\n )\n ]);\n })\n );\n this.setStatus(TableRowActionStatus.SUCCESS);\n } catch (e) {\n console.error(`Failed to execute row action: ${e.message}`);\n this.setStatus(TableRowActionStatus.ERROR);\n }\n }\n\n protected getElementList(): Data[] {\n return [ this.element ];\n }\n\n /**\n * find all method instance in the actionMethodList member that\n * do not have a @TableActionMethod decorators\n * @private\n */\n private findUntypedActionMethod(): Array<TableRowActionTypeSwitchMethod<Data>> {\n return this.actionMethodList.filter(IsTableRowActionTypeSwitchMethod);\n }\n\n /**\n * find all method instance in the actionMethodList member that\n * do have a @TableActionMethod decorators with the current type\n * @private\n */\n private findTypedActionMethod(): Array<TableRowActionTypeMethod<Data>> {\n return this.actionMethodList.filter(IsTableRowActionTypeMethod(this.type));\n }\n\n protected setButtonDisabled() {\n if (this.matButton) {\n this.matButton.disabled = true;\n }\n }\n\n protected setButtonEnabled() {\n if (this.matButton) {\n this.matButton.disabled = false;\n }\n }\n\n private setStatus(status: TableRowActionStatus) {\n if (this._currentStatus === status) {\n return;\n }\n this._currentStatus = status;\n switch (status) {\n case TableRowActionStatus.EXECUTING:\n this.setButtonDisabled();\n this.executingDirective?.show();\n break;\n case TableRowActionStatus.SUCCESS:\n if (this.refresh) {\n this.tableDataSourceDirective.refresh();\n }\n if (this.successMessage) {\n this.snackBar.open(this.successMessage, 'ok', { duration: 2560 });\n }\n this.setStatus(TableRowActionStatus.DONE);\n break;\n case TableRowActionStatus.ERROR:\n this.setStatus(TableRowActionStatus.DONE);\n if (this.errorMessage) {\n this.snackBar.open(this.errorMessage, 'ok', { duration: 5120 });\n }\n break;\n case TableRowActionStatus.DONE:\n this.setButtonEnabled();\n this.executingDirective?.hide();\n break;\n }\n this.cdr.detectChanges();\n }\n}\n"]}
1
+ {"version":3,"file":"table-row-action.directive.js","sourceRoot":"","sources":["../../../../../../../libs/material/table-system/src/lib/table-row-actions/table-row-action.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,MAAM,EACN,KAAK,EACL,SAAS,EACT,QAAQ,EACR,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACL,WAAW,EACX,aAAa,EACb,QAAQ,EACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gCAAgC,EAAE,MAAM,wCAAwC,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAIjC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;;;;;AAK1E,MAAM,OAAO,uBAAuB;IAmClC,YAEI,gBAE4B,EAEX,GAAsB,EAExB,GAAqB,EAErB,wBAAkD,EAElD,QAAqB,EAGrB,SAA2B;QATzB,QAAG,GAAH,GAAG,CA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AAE,4BAA4B;iBACvC;;0BAqCI,MAAM;2BAAC,4BAA4B;;0BAInC,MAAM;2BAAC,iBAAiB;;0BAExB,MAAM;2BAAC,gBAAgB;;0BAEvB,MAAM;2BAAC,wBAAwB;;0BAE/B,MAAM;2BAAC,WAAW;;0BAElB,QAAQ;;0BACR,MAAM;2BAAC,SAAS;4CA7CR,mBAAmB;sBAD7B,KAAK;uBAAC,aAAa;gBAOb,OAAO;sBAFb,KAAK;gBAKC,IAAI;sBAFV,KAAK;uBAAC,oBAAoB;gBAKpB,YAAY;sBADlB,KAAK;gBAIC,cAAc;sBADpB,KAAK;gBAOC,OAAO;sBADb,KAAK;gBAIW,kBAAkB;sBADlC,YAAY;uBAAC,gCAAgC;gBA6BvC,WAAW;sBADjB,YAAY;uBAAC,WAAW;gBAMlB,OAAO;sBADb,YAAY;uBAAC,OAAO,EAAE,CAAE,QAAQ,CAAE","sourcesContent":["import {\n ChangeDetectorRef,\n ContentChild,\n Directive,\n HostListener,\n Inject,\n Input,\n isDevMode,\n Optional,\n ViewContainerRef\n} from '@angular/core';\nimport { MatButton } from '@angular/material/button';\nimport { MatSnackBar } from '@angular/material/snack-bar';\nimport {\n coerceArray,\n coerceBoolean,\n Required\n} from '@rxap/utilities';\nimport { TableRowActionExecutingDirective } from './table-row-action-executing.directive';\nimport { TableRowActionStatus } from './table-row-action-status';\nimport {\n IsTableRowActionTypeMethod,\n IsTableRowActionTypeSwitchMethod,\n TableRowActionMethod,\n TableRowActionTypeMethod,\n TableRowActionTypeSwitchMethod\n} from './table-row-action.method';\nimport { RXAP_TABLE_ROW_ACTION_METHOD } from './tokens';\nimport { TableDataSourceDirective } from '../table-data-source.directive';\n\n@Directive({\n selector: 'button[rxapTableRowAction]'\n})\nexport class TableRowActionDirective<Data extends Record<string, any>> {\n private _hasConfirmDirective = false;\n\n @Input('rxapConfirm')\n public set hasConfirmDirective(value: any) {\n this._hasConfirmDirective = coerceBoolean(value);\n }\n\n @Input()\n @Required\n public element!: Data;\n @Input('rxapTableRowAction')\n @Required\n public type!: string;\n\n @Input()\n public errorMessage?: string;\n\n @Input()\n public successMessage?: string;\n\n /**\n * true - after the action is executed the table datasource is refreshed\n */\n @Input()\n public refresh?: boolean;\n\n @ContentChild(TableRowActionExecutingDirective)\n private readonly executingDirective?: TableRowActionExecutingDirective;\n private _currentStatus: TableRowActionStatus = TableRowActionStatus.DONE;\n\n private readonly actionMethodList: Array<TableRowActionMethod<Data>>;\n\n private _actionDisabled = false;\n\n constructor(\n @Inject(RXAP_TABLE_ROW_ACTION_METHOD)\n actionMethodList:\n | Array<TableRowActionMethod<Data>>\n | TableRowActionMethod<Data>,\n @Inject(ChangeDetectorRef)\n protected readonly cdr: ChangeDetectorRef,\n @Inject(ViewContainerRef)\n private readonly vcr: ViewContainerRef,\n @Inject(TableDataSourceDirective)\n private readonly tableDataSourceDirective: TableDataSourceDirective,\n @Inject(MatSnackBar)\n private readonly snackBar: MatSnackBar,\n @Optional()\n @Inject(MatButton)\n private readonly matButton: MatButton | null\n ) {\n this.actionMethodList = coerceArray(actionMethodList);\n }\n\n @HostListener('confirmed')\n public onConfirmed() {\n return this.execute();\n }\n\n @HostListener('click', [ '$event' ])\n public onClick($event: Event) {\n $event.stopPropagation();\n if (!this._hasConfirmDirective) {\n return this.execute();\n } else {\n if (isDevMode()) {\n console.debug('skip remote method call. Wait for confirmation.');\n }\n }\n return Promise.resolve();\n }\n\n public async execute(): Promise<void> {\n if (this._actionDisabled) {\n return Promise.resolve();\n }\n this.setStatus(TableRowActionStatus.EXECUTING);\n try {\n await Promise.all(\n this.getElementList().map((element) => {\n return Promise.all([\n Promise.all(\n this.findUntypedActionMethod().map((am) =>\n am.call({ element, type: this.type })\n )\n ),\n Promise.all(\n this.findTypedActionMethod().map((am) => am.call(element))\n )\n ]);\n })\n );\n this.setStatus(TableRowActionStatus.SUCCESS);\n } catch (e) {\n console.error(`Failed to execute row action: ${e.message}`);\n this.setStatus(TableRowActionStatus.ERROR);\n }\n }\n\n protected getElementList(): Data[] {\n return [ this.element ];\n }\n\n /**\n * find all method instance in the actionMethodList member that\n * do not have a @TableActionMethod decorators\n * @private\n */\n private findUntypedActionMethod(): Array<TableRowActionTypeSwitchMethod<Data>> {\n return this.actionMethodList.filter(IsTableRowActionTypeSwitchMethod);\n }\n\n /**\n * find all method instance in the actionMethodList member that\n * do have a @TableActionMethod decorators with the current type\n * @private\n */\n private findTypedActionMethod(): Array<TableRowActionTypeMethod<Data>> {\n return this.actionMethodList.filter(IsTableRowActionTypeMethod(this.type));\n }\n\n /**\n * Disables the action. If the button is pressed the action is NOT executed\n *\n * Hint: the button is set to disabled = true to prevent any conflict with\n * extern button enable features linke : rxapHasEnablePermission\n * @protected\n */\n protected setButtonDisabled() {\n this._actionDisabled = true;\n }\n\n /**\n * Enables the action. If the button is pressed the action is executed\n *\n * TODO : find a way to communicate the disabled state between the features\n * Hint: the button is set to disabled = false to prevent any conflict with\n * extern button enable features linke : rxapHasEnablePermission\n * @protected\n */\n protected setButtonEnabled() {\n this._actionDisabled = false;\n }\n\n private setStatus(status: TableRowActionStatus) {\n if (this._currentStatus === status) {\n return;\n }\n this._currentStatus = status;\n switch (status) {\n case TableRowActionStatus.EXECUTING:\n this.setButtonDisabled();\n this.executingDirective?.show();\n break;\n case TableRowActionStatus.SUCCESS:\n if (this.refresh) {\n this.tableDataSourceDirective.refresh();\n }\n if (this.successMessage) {\n this.snackBar.open(this.successMessage, 'ok', { duration: 2560 });\n }\n this.setStatus(TableRowActionStatus.DONE);\n break;\n case TableRowActionStatus.ERROR:\n this.setStatus(TableRowActionStatus.DONE);\n if (this.errorMessage) {\n this.snackBar.open(this.errorMessage, 'ok', { duration: 5120 });\n }\n break;\n case TableRowActionStatus.DONE:\n this.setButtonEnabled();\n this.executingDirective?.hide();\n break;\n }\n this.cdr.detectChanges();\n }\n}\n"]}
@@ -1866,6 +1866,7 @@ class TableRowActionDirective {
1866
1866
  this.matButton = matButton;
1867
1867
  this._hasConfirmDirective = false;
1868
1868
  this._currentStatus = TableRowActionStatus.DONE;
1869
+ this._actionDisabled = false;
1869
1870
  this.actionMethodList = coerceArray(actionMethodList);
1870
1871
  }
1871
1872
  set hasConfirmDirective(value) {
@@ -1888,6 +1889,9 @@ class TableRowActionDirective {
1888
1889
  }
1889
1890
  execute() {
1890
1891
  return __awaiter(this, void 0, void 0, function* () {
1892
+ if (this._actionDisabled) {
1893
+ return Promise.resolve();
1894
+ }
1891
1895
  this.setStatus(TableRowActionStatus.EXECUTING);
1892
1896
  try {
1893
1897
  yield Promise.all(this.getElementList().map((element) => {
@@ -1923,15 +1927,26 @@ class TableRowActionDirective {
1923
1927
  findTypedActionMethod() {
1924
1928
  return this.actionMethodList.filter(IsTableRowActionTypeMethod(this.type));
1925
1929
  }
1930
+ /**
1931
+ * Disables the action. If the button is pressed the action is NOT executed
1932
+ *
1933
+ * Hint: the button is set to disabled = true to prevent any conflict with
1934
+ * extern button enable features linke : rxapHasEnablePermission
1935
+ * @protected
1936
+ */
1926
1937
  setButtonDisabled() {
1927
- if (this.matButton) {
1928
- this.matButton.disabled = true;
1929
- }
1938
+ this._actionDisabled = true;
1930
1939
  }
1940
+ /**
1941
+ * Enables the action. If the button is pressed the action is executed
1942
+ *
1943
+ * TODO : find a way to communicate the disabled state between the features
1944
+ * Hint: the button is set to disabled = false to prevent any conflict with
1945
+ * extern button enable features linke : rxapHasEnablePermission
1946
+ * @protected
1947
+ */
1931
1948
  setButtonEnabled() {
1932
- if (this.matButton) {
1933
- this.matButton.disabled = false;
1934
- }
1949
+ this._actionDisabled = false;
1935
1950
  }
1936
1951
  setStatus(status) {
1937
1952
  var _a, _b;