2
2
<%
3
3
var tableColumnsEnumName = classify(name) + 'Column';
4
4
var cmpFileName = dasherize(name);
5
+ var hasCustomRowActions = options.customRowActions.length > 0;
6
+ var customRowActionNames = options.customRowActions.map(action => `'${action.replace(/\.[^/.]+$/, '')}'`);
5
7
%>
6
8
import {
7
9
AfterViewInit,
@@ -96,17 +98,23 @@ export enum <%= tableColumnsEnumName %> {
96
98
<% if (options.addRowCheckboxes) { %>CHECKBOX = 'checkboxes',<% } %>
97
99
<%= enumPropertyDefinitions %>
98
100
<%= enumCustomColumns %>
99
- <% if (options.customRowActions.length > 0 ) { %>CUSTOM_ROW_ACTIONS = 'customRowActions',<% } %>
101
+ <% if (hasCustomRowActions ) { %>CUSTOM_ROW_ACTIONS = 'customRowActions',<% } %>
100
102
COLUMNS_MENU = 'columnsMenu'
101
103
}
102
104
103
105
export const NON_DATA_COLUMNS: <%= tableColumnsEnumName %>[] = [
104
- <% if (options.customRowActions.length > 0 ) { %>
106
+ <% if (hasCustomRowActions ) { %>
105
107
<%= tableColumnsEnumName %>.CUSTOM_ROW_ACTIONS,
106
108
<% } %>
107
109
<%= tableColumnsEnumName %>.COLUMNS_MENU
108
110
];
109
111
112
+ <% if (hasCustomRowActions) { %>
113
+ type RowAction = <%= customRowActionNames.join(' | ') %>;
114
+ export type <%= options.aspectModelTypeName %>ActionsResolvers = Partial<Record<RowAction, (rowData: <%= options.aspectModelTypeName %>) => boolean>> | undefined;
115
+ <% } %>
116
+
117
+
110
118
111
119
@Component({
112
120
selector: '<%= options.selector %>',
@@ -160,6 +168,10 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
160
168
@Input() maxExportRows: number = 0;
161
169
<% } %>
162
170
171
+ <% if (hasCustomRowActions) { %>
172
+ @Input() actionResolvers: <%= options.aspectModelTypeName %>ActionsResolvers = {};
173
+ <% } %>
174
+
163
175
@Output() rowClickEvent = new EventEmitter<any>();
164
176
@Output() rowDblClickEvent = new EventEmitter<any>();
165
177
@Output() rowRightClickEvent = new EventEmitter<any>();
@@ -169,7 +181,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
169
181
@Output() downloadEvent = new EventEmitter<{error: boolean, success: boolean, inProgress: boolean}>();
170
182
@Output() rowSelectionEvent = new EventEmitter<any>();
171
183
172
- <% if (options.customRowActions.length > 0 ) { %>
184
+ <% if (hasCustomRowActions ) { %>
173
185
@Output() customActionEvent = new EventEmitter<any>();
174
186
<% } %>
175
187
<% if (options.customCommandBarActions.length > 0) { %>
@@ -383,9 +395,15 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
383
395
this.rowRightClickEvent.emit({ data: row, mousePosition: mousePositionOnClick });
384
396
}
385
397
386
- if ($event.type === 'click') {
387
- this.rowClickEvent.emit({ data: row })
388
- }
398
+ <% if (hasCustomRowActions) { %>
399
+ if ($event.type === 'click' && this.isAvailableRowAction('forward-right', row)) {
400
+ this.rowClickEvent.emit({ data: row })
401
+ }
402
+ <% } else {%>
403
+ if ($event.type === 'click') {
404
+ this.rowClickEvent.emit({ data: row })
405
+ }
406
+ <% }%>
389
407
390
408
return false;
391
409
}
@@ -438,7 +456,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
438
456
<% } %>
439
457
<% } %>
440
458
441
- <% if (options.customRowActions.length > 0 ) { %>
459
+ <% if (hasCustomRowActions ) { %>
442
460
executeCustomAction($event: MouseEvent, action: string, row:any): void{
443
461
if(this.customRowActionsLength <= this.visibleRowActionsIcons) {
444
462
$event.stopPropagation();
@@ -635,7 +653,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
635
653
636
654
displayedColumnsTmp.push(...columns);
637
655
638
- <% if (options.customRowActions.length > 0 ) { %>
656
+ <% if (hasCustomRowActions ) { %>
639
657
displayedColumnsTmp.push({name: <%= tableColumnsEnumName %>['CUSTOM_ROW_ACTIONS'], selected: true});
640
658
<% } %>
641
659
@@ -657,6 +675,14 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
657
675
}
658
676
<% } %>
659
677
678
+ protected isAvailableRowAction(action: RowAction, rowData: <%= options.aspectModelTypeName %>): boolean {
679
+ if (!this.actionResolvers || !this.actionResolvers[action]) {
680
+ return true;
681
+ }
682
+
683
+ return this.actionResolvers[action](rowData) ?? true;
684
+ }
685
+
660
686
<% if (options.hasSearchBar) { %>
661
687
private initializeHighlightConfig(): void {
662
688
const configStorage = this.storageService.getItem(this.<%= options.localStorageKeyConfig %>);
0 commit comments