@cdmx/wappler_ag_grid 1.1.6 → 1.1.8

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.
package/README.md CHANGED
@@ -253,6 +253,7 @@ This will set the minimum width (px) for the Actions Column.(Default: 80)
253
253
  **Actions Column Max Width**
254
254
  This will set the maximum width (px) for the Actions Column.(Default: null)
255
255
 
256
+
256
257
  **Edit Action Button**
257
258
  This will display the "Edit Action Button" options.
258
259
 
@@ -265,9 +266,12 @@ Specify the tooltip text for the Edit Action button.
265
266
  **Edit Action Button Class**
266
267
  Specify the CSS class for styling the Edit Action button.
267
268
 
268
- **Edit Action Icon Class**
269
+ **Edit Action Button Icon Class**
269
270
  Specify the CSS class for styling the icon of the Edit Action button.
270
271
 
272
+ **Edit Action Button Condition**
273
+ Specify the condition to Show the Edit Action button, eg: code==TEST, or status==COMPLETED
274
+
271
275
  **View Action Button**
272
276
  This will display the "View Action Button" options.
273
277
 
@@ -280,10 +284,15 @@ Specify the tooltip text for the View Action button.
280
284
  **View Action Button Class**
281
285
  Specify the CSS class for styling the View Action button.
282
286
 
283
- **View Action Icon Class**
287
+ **View Action Button Icon Class**
284
288
  Specify the CSS class for styling the icon of the View Action button.
285
289
 
290
+ **View Action Button Condition**
291
+ Specify the condition to Show the View Action button, eg: code==TEST, or status==COMPLETED
292
+
286
293
  **Delete Action Button**
294
+ This will display the "Delete Action Button" options.
295
+
287
296
  **Delete Action Button Title**
288
297
  Specify the title for the Delete Action button.
289
298
 
@@ -292,8 +301,13 @@ Specify the tooltip text for the Delete Action button.
292
301
 
293
302
  **Delete Action Button Class**
294
303
  Specify the CSS class for styling the Delete Action button.
304
+
305
+ **Delete Action Button Icon Class**
295
306
  Specify the CSS class for styling the icon of the Delete Action button.
296
307
 
308
+ **Delete Action Button Condition**
309
+ Specify the condition to Show the Delete Action button, eg: code==TEST, or status==COMPLETED
310
+
297
311
  # Custom Action Buttons
298
312
 
299
313
  **Button1 Class**
@@ -1489,6 +1489,12 @@
1489
1489
  "type": "text",
1490
1490
  "defaultValue": 'fas fa-pencil-alt'
1491
1491
  },
1492
+ {
1493
+ "name": "editActionBtnCondition",
1494
+ "attribute": "edit_action_btn_condition",
1495
+ "title": "Edit Action Button Conditon",
1496
+ "type": "text"
1497
+ },
1492
1498
  {
1493
1499
  "name": "viewActionBtn",
1494
1500
  "attribute": "dmx-bind:view_action_btn",
@@ -1524,6 +1530,12 @@
1524
1530
  "type": "text",
1525
1531
  "defaultValue": 'fas fa-eye'
1526
1532
  },
1533
+ {
1534
+ "name": "viewActionBtnCondition",
1535
+ "attribute": "view_action_btn_condition",
1536
+ "title": "View Action Button Conditon",
1537
+ "type": "text"
1538
+ },
1527
1539
  {
1528
1540
  "name": "deleteActionBtn",
1529
1541
  "attribute": "dmx-bind:delete_action_btn",
@@ -1558,6 +1570,12 @@
1558
1570
  "title": "Delete Action Icon Class",
1559
1571
  "type": "text",
1560
1572
  "defaultValue": 'fas fa-trash'
1573
+ },
1574
+ {
1575
+ "name": "deleteActionBtnCondition",
1576
+ "attribute": "delete_action_btn_condition",
1577
+ "title": "Delete Action Button Conditon",
1578
+ "type": "text"
1561
1579
  }
1562
1580
  ]
1563
1581
  },
package/dmx-ag-grid.js CHANGED
@@ -83,16 +83,19 @@ dmx.Component('ag-grid', {
83
83
  edit_action_tooltip: {type: String, default: 'Edit' },
84
84
  edit_action_icon_class: {type: String, default: 'fas fa-pencil-alt' },
85
85
  edit_action_btn_class: {type: String, default: 'btn-primary btn-xs m-1' },
86
+ edit_action_btn_condition: {type: String, default: null },
86
87
  view_action_btn: { type: Boolean, default: false },
87
88
  view_action_title: {type: String, default: '' },
88
89
  view_action_tooltip: {type: String, default: 'View' },
89
90
  view_action_icon_class: {type: String, default: 'fas fa-eye' },
90
91
  view_action_btn_class: {type: String, default: 'btn-info btn-xs m-1' },
92
+ view_action_btn_condition: {type: String, default: null },
91
93
  delete_action_btn: { type: Boolean, default: false },
92
94
  delete_action_title: {type: String, default: '' },
93
95
  delete_action_tooltip: {type: String, default: 'Delete' },
94
96
  delete_action_icon_class: {type: String, default: 'fas fa-trash' },
95
97
  delete_action_btn_class: {type: String, default: 'btn-danger btn-xs m-1' },
98
+ delete_action_btn_condition: {type: String, default: null },
96
99
  enable_custom_action_btns: { type: Boolean, default: false },
97
100
  button1_action_btn: { type: "Boolean", default: false },
98
101
  button1_action_title: { type: "String", default: "" },
@@ -445,6 +448,15 @@ dmx.Component('ag-grid', {
445
448
  button.setAttribute('title', buttonConfig.tooltip);
446
449
  button.innerHTML = `<i class="${buttonConfig.icon}"></i> ${buttonConfig.action}`;
447
450
  container.appendChild(button);
451
+ // Check if the button should be hidden based on the condition string and row data
452
+ if (buttonConfig.condition) {
453
+ const [left, operator, right] = extractConditionParts(buttonConfig.condition);
454
+
455
+ const isConditionMet = params.data.hasOwnProperty(left) && evaluateCondition(params.data[left], operator, right);
456
+ if (!isConditionMet) {
457
+ button.style.setProperty('display', 'none', 'important');
458
+ }
459
+ }
448
460
  button.addEventListener('click', function () {
449
461
  if (typeof buttonConfig.onClick === 'function') {
450
462
  buttonConfig.onClick(params.data);
@@ -493,6 +505,52 @@ dmx.Component('ag-grid', {
493
505
  }
494
506
  return params.value;
495
507
  }
508
+
509
+ function extractConditionParts(condition) {
510
+
511
+ const operators = ['===', '==', '!=', '>', '<', '>=', '<='];
512
+ let operator;
513
+ let left;
514
+ let right;
515
+
516
+ for (const op of operators) {
517
+ if (condition.includes(op)) {
518
+ operator = op;
519
+ const parts = condition.split(op).map(part => part.trim());
520
+ left = parts[0];
521
+ right = parts.slice(1).join(op).trim();
522
+ break;
523
+ }
524
+ }
525
+
526
+ if (!operator) {
527
+ throw new Error('Invalid operator in the condition.');
528
+ }
529
+
530
+ return [left, operator, right];
531
+ }
532
+
533
+ function evaluateCondition(left, operator, right) {
534
+ switch (operator) {
535
+ case '===':
536
+ return left.toString() === right.toString();
537
+ case '==':
538
+ return left.toString() == right.toString();
539
+ case '!=':
540
+ return left.toString() != right.toString();
541
+ case '>':
542
+ return left.toString() > parseFloat(right);
543
+ case '<':
544
+ return left.toString() < parseFloat(right);
545
+ case '>=':
546
+ return left.toString() >= parseFloat(right);
547
+ case '<=':
548
+ return left.toString() <= parseFloat(right);
549
+ default:
550
+ return false;
551
+ }
552
+ }
553
+
496
554
  function formatDate(timestamp) {
497
555
  const format = options.date_format
498
556
  const localDate = new Date(timestamp);
@@ -849,50 +907,7 @@ dmx.Component('ag-grid', {
849
907
  tooltipValueGetter = createCombinedTooltipValueGetter(key, options.data_changes, options.data_binded_changes);
850
908
 
851
909
  }
852
- function extractConditionParts(condition) {
853
-
854
- const operators = ['===', '==', '!=', '>', '<', '>=', '<='];
855
- let operator;
856
- let left;
857
- let right;
858
910
 
859
- for (const op of operators) {
860
- if (condition.includes(op)) {
861
- operator = op;
862
- const parts = condition.split(op).map(part => part.trim());
863
- left = parts[0];
864
- right = parts.slice(1).join(op).trim();
865
- break;
866
- }
867
- }
868
-
869
- if (!operator) {
870
- throw new Error('Invalid operator in the condition.');
871
- }
872
-
873
- return [left, operator, right];
874
- }
875
-
876
- function evaluateCondition(left, operator, right) {
877
- switch (operator) {
878
- case '===':
879
- return left.toString() === right.toString();
880
- case '==':
881
- return left.toString() == right.toString();
882
- case '!=':
883
- return left.toString() != right.toString();
884
- case '>':
885
- return left.toNumber() > right.toNumber();
886
- case '<':
887
- return left.toNumber() < right.toNumber();
888
- case '>=':
889
- return left.toNumber() >= right.toNumber();
890
- case '<=':
891
- return left.toNumber() <= right.toNumber();
892
- default:
893
- return false;
894
- }
895
- }
896
911
  const cstyles = this.props.cstyles
897
912
  // Check if custom color exists for the current field and condition
898
913
  function applyCellStyle(params) {
@@ -905,7 +920,6 @@ dmx.Component('ag-grid', {
905
920
  const font = style.font || 'normal';
906
921
  const area = style.area || 'text';
907
922
  const [left, operator, right] = extractConditionParts(condition);
908
-
909
923
  if (
910
924
  params.data.hasOwnProperty(left) &&
911
925
  evaluateCondition(params.data[left], operator, right)
@@ -1060,6 +1074,7 @@ dmx.Component('ag-grid', {
1060
1074
  this.set('id', rowData.id);
1061
1075
  this.dispatchEvent('row_action_edit');
1062
1076
  },
1077
+ condition: options.edit_action_btn_condition
1063
1078
  });
1064
1079
  }
1065
1080
 
@@ -1074,6 +1089,7 @@ dmx.Component('ag-grid', {
1074
1089
  this.set('id', rowData.id);
1075
1090
  this.dispatchEvent('row_action_view');
1076
1091
  },
1092
+ condition: options.view_action_btn_condition
1077
1093
  });
1078
1094
  }
1079
1095
 
@@ -1088,6 +1104,7 @@ dmx.Component('ag-grid', {
1088
1104
  this.set('id', rowData.id);
1089
1105
  this.dispatchEvent('row_action_delete');
1090
1106
  },
1107
+ condition: options.delete_action_btn_condition
1091
1108
  });
1092
1109
  }
1093
1110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "type": "module",
5
5
  "description": "App Connect module for AG Grid Table Generation.",
6
6
  "license": "MIT",