@cdmx/wappler_ag_grid 0.4.3 → 0.4.5

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.
@@ -503,7 +503,7 @@
503
503
  "variables": [
504
504
  {
505
505
  "name": "cstyles",
506
- "title": "Configure Colors",
506
+ "title": "Configure Colors and Fonts",
507
507
  "attributeStartsWith": "dmx-bind",
508
508
  "attribute": "cstyles",
509
509
  "type": "boolean",
@@ -551,14 +551,39 @@
551
551
  "type": "text"
552
552
  },
553
553
  help: "Example: '#FF0000' or 'red'"
554
+ },
555
+ {
556
+ "field": "area",
557
+ "caption": "Area",
558
+ "size": "20%",
559
+ "editable": {
560
+ "type": "list",
561
+ "items": [
562
+ {id: 'text', text: 'text'},
563
+ {id: 'cell', text: 'cell'}
564
+ ]
565
+ }
566
+ },
567
+ {
568
+ "field": "font",
569
+ "caption": "Font",
570
+ "size": "20%",
571
+ "editable": {
572
+ "type": "list",
573
+ "items": [
574
+ {id: 'normal', text: 'normal'},
575
+ {id: 'italic', text: 'italic'},
576
+ {id: 'bold', text: 'bold'}
577
+ ]
578
+ }
554
579
  }
555
580
  ],
556
581
  "newRecord": {
557
- "name": "",
558
- "value": "",
559
582
  "field": "",
560
583
  "condition": "",
561
- "customColor": ""
584
+ "customColor": "",
585
+ "area": "text",
586
+ "font": "normal"
562
587
  }
563
588
  }
564
589
  ]
@@ -625,13 +650,26 @@
625
650
  "editable": {
626
651
  "type": "text"
627
652
  }
653
+ },
654
+ {
655
+ "field": "area",
656
+ "caption": "Area",
657
+ "size": "5%",
658
+ "editable": {
659
+ "type": "list",
660
+ "items": [
661
+ {id: 'cell', text: 'cell'},
662
+ {id: 'tooltip', text: 'tooltip'}
663
+ ]
664
+ }
628
665
  }
629
666
  ],
630
667
  "newRecord": {
631
668
  "field": "",
632
669
  "data_source": "",
633
670
  "property": "",
634
- "output": ""
671
+ "output": "",
672
+ "area": "cell"
635
673
  }
636
674
  }
637
675
  ]
@@ -687,13 +725,25 @@
687
725
  editable: {
688
726
  type: "text"
689
727
  }
728
+ },
729
+ {
730
+ "field": "area",
731
+ "caption": "Area",
732
+ "size": "5%",
733
+ "editable": {
734
+ "type": "list",
735
+ "items": [
736
+ {id: 'cell', text: 'cell'},
737
+ {id: 'tooltip', text: 'tooltip'}
738
+ ]
739
+ }
690
740
  }
691
741
  ],
692
742
  "newRecord": {
693
- "name": "",
694
- "value": "",
695
743
  "field": "",
696
- "new_value": ""
744
+ "value": "",
745
+ "new_value": "",
746
+ "area": "cell"
697
747
  }
698
748
  }
699
749
  ]
package/dmx-ag-grid.js CHANGED
@@ -216,8 +216,6 @@ dmx.Component('ag-grid', {
216
216
 
217
217
  return container;
218
218
  }
219
-
220
-
221
219
  function humanize(str) {
222
220
  if (str == null) return str;
223
221
 
@@ -390,11 +388,12 @@ dmx.Component('ag-grid', {
390
388
  const data_source = change.data_source;
391
389
  const property = change.property;
392
390
  const output = change.output;
391
+ const area = change.area;
393
392
  let dataArray;
394
393
  this.$addBinding(data_source, (function (e) {
395
394
  dataArray = e;
396
395
  }));
397
- keyLookup[change.field] = { dataArray, property, output };
396
+ keyLookup[change.field] = { dataArray, property, output, area };
398
397
  }
399
398
  });
400
399
 
@@ -403,17 +402,17 @@ dmx.Component('ag-grid', {
403
402
 
404
403
  // Check if there's a matching change in dataChanges
405
404
  const matchingChange = dataChanges.find(change => change.field === key && change.value === String(value));
406
- if (matchingChange) {
405
+ if (matchingChange && matchingChange.area === 'tooltip' ) {
407
406
  return matchingChange.new_value;
408
407
  }
409
408
 
410
409
  // Check if there's a matching change in dataBindedChanges
411
410
  const matchingKeyData = keyLookup[key];
412
411
  if (matchingKeyData) {
413
- const { dataArray, property, output } = matchingKeyData;
412
+ const { dataArray, property, output, area } = matchingKeyData;
414
413
  const matchingItem = dataArray.find(item => item[property] === value);
415
414
 
416
- if (matchingItem) {
415
+ if (matchingItem && area === 'cell') {
417
416
  return matchingItem[output];
418
417
  }
419
418
  }
@@ -422,6 +421,48 @@ dmx.Component('ag-grid', {
422
421
  return value;
423
422
  };
424
423
  }
424
+ createCombinedTooltipValueGetter = (key, dataChanges, dataBindedChanges) => {
425
+ const keyLookup = {};
426
+
427
+ dataBindedChanges.forEach(change => {
428
+ if (!keyLookup[change.field]) {
429
+ const data_source = change.data_source;
430
+ const property = change.property;
431
+ const output = change.output;
432
+ const area = change.area;
433
+ let dataArray;
434
+ this.$addBinding(data_source, (function (e) {
435
+ dataArray = e;
436
+ }));
437
+ keyLookup[change.field] = { dataArray, property, output, area };
438
+ }
439
+ });
440
+
441
+ return function (params) {
442
+ const value = params.data[key];
443
+
444
+
445
+ // Check if there's a matching change in dataChanges
446
+ const matchingChange = dataChanges.find(change => change.field === key && change.value === String(value));
447
+ if (matchingChange && matchingChange.area === 'tooltip' ) {
448
+ return matchingChange.new_value;
449
+ }
450
+
451
+ // Check if there's a matching change in dataBindedChanges
452
+ const matchingKeyData = keyLookup[key];
453
+ if (matchingKeyData) {
454
+ const { dataArray, property, output, area } = matchingKeyData;
455
+ const matchingItem = dataArray.find(item => item[property] === value);
456
+
457
+
458
+ if (matchingItem && area === 'tooltip') {
459
+ return matchingItem[output];
460
+ }
461
+ }
462
+ // Return the original value if no matching changes were found
463
+ return undefined;
464
+ };
465
+ }
425
466
  createCombinedFilterValueGetter = (key, dataChanges, dataBindedChanges) => {
426
467
  const keyLookup = {};
427
468
 
@@ -518,14 +559,30 @@ dmx.Component('ag-grid', {
518
559
  else {
519
560
  valueGetter = createCombinedValueGetter(key, options.data_changes, options.data_binded_changes);
520
561
  filterValueGetter = createCombinedFilterValueGetter(key, options.data_changes, options.data_binded_changes);
562
+ tooltipValueGetter = createCombinedTooltipValueGetter(key, options.data_changes, options.data_binded_changes);
521
563
  }
522
564
  function extractConditionParts(condition) {
523
- const parts = condition.match(/(.+?)(===|==|!=|>|<|>=|<=)(.+)/);
524
- if (parts) {
525
- const [, left, operator, right] = parts;
526
- return [left.trim(), operator.trim(), right.trim()];
565
+
566
+ const operators = ['===', '==', '!=', '>', '<', '>=', '<='];
567
+ let operator;
568
+ let left;
569
+ let right;
570
+
571
+ for (const op of operators) {
572
+ if (condition.includes(op)) {
573
+ operator = op;
574
+ const parts = condition.split(op).map(part => part.trim());
575
+ left = parts[0];
576
+ right = parts.slice(1).join(op).trim();
577
+ break;
578
+ }
527
579
  }
528
- return [];
580
+
581
+ if (!operator) {
582
+ throw new Error('Invalid operator in the condition.');
583
+ }
584
+
585
+ return [left, operator, right];
529
586
  }
530
587
 
531
588
  function evaluateCondition(left, operator, right) {
@@ -557,17 +614,24 @@ dmx.Component('ag-grid', {
557
614
  for (const style of styles) {
558
615
  const condition = style.condition;
559
616
  const customColor = style.customColor;
617
+ const font = style.font || 'normal';
618
+ const area = style.area || 'text';
560
619
  const [left, operator, right] = extractConditionParts(condition);
620
+
561
621
  if (
562
- params.data.hasOwnProperty(left) &&
563
- evaluateCondition(params.data[left], operator, right)
622
+ params.data.hasOwnProperty(left) &&
623
+ evaluateCondition(params.data[left], operator, right)
564
624
  ) {
565
- return { color: customColor };
625
+ if (area === 'text') {
626
+ return { color: customColor, fontStyle: font };
627
+ } else if (area === 'cell') {
628
+ return { backgroundColor: customColor, fontStyle: font };
629
+ }
566
630
  }
567
631
  }
568
632
 
569
633
  return null;
570
- }
634
+ }
571
635
 
572
636
  if (cnames.hasOwnProperty(key)) {
573
637
  const cname = cnames[key]
@@ -615,6 +679,7 @@ dmx.Component('ag-grid', {
615
679
  sortable: sortable,
616
680
  filterValueGetter: filterValueGetter,
617
681
  filterParams: filterParams,
682
+ tooltipValueGetter: tooltipValueGetter,
618
683
  cellStyle: applyCellStyle,
619
684
  ...(cwidths.hasOwnProperty(key) && {
620
685
  minWidth: parseInt(cwidths[key].min_width),
@@ -654,6 +719,7 @@ dmx.Component('ag-grid', {
654
719
  field: 'action',
655
720
  colId: 'actionsColumn',
656
721
  filter: null,
722
+ sortable: false,
657
723
  cellRenderer: actionsRenderer,
658
724
  pinned: options.pin_actions,
659
725
  cellRendererParams: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "type": "module",
5
5
  "description": "App Connect module for AG Grid Table Generation",
6
6
  "license": "MIT",