@gisce/ooui 2.40.0-alpha.7 → 2.40.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/ooui",
3
- "version": "2.40.0-alpha.7",
3
+ "version": "2.40.0-alpha.8",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
package/src/Kanban.ts CHANGED
@@ -5,6 +5,7 @@ import { replaceEntities } from "./helpers/attributeParser";
5
5
  import { parseBoolAttribute, ParsedNode } from "./helpers/nodeParser";
6
6
  import * as txml from "txml";
7
7
  import { parseContext } from "./helpers/contextParser";
8
+ import { parseOnChange } from "./helpers/onChangeParser";
8
9
 
9
10
  export type KanbanField = Widget & {
10
11
  sum?: string; // Aggregation label (e.g., "Total hours")
@@ -106,6 +107,16 @@ class Kanban {
106
107
  return this._colors;
107
108
  }
108
109
 
110
+ /**
111
+ * Custom function to call when a card moves between columns
112
+ * Example: "handle_state_change" or with args "handle_state_change(field, from, to)"
113
+ * If not defined, the frontend should use the default on_change_column method
114
+ */
115
+ _on_change_column: { method: string; args: string[] } | null = null;
116
+ get on_change_column(): { method: string; args: string[] } | null {
117
+ return this._on_change_column;
118
+ }
119
+
109
120
  /**
110
121
  * Context for each field in the kanban
111
122
  */
@@ -165,6 +176,11 @@ class Kanban {
165
176
  this._status = replaceEntities(this._status);
166
177
  }
167
178
 
179
+ // Parse on_change_column attribute
180
+ if (view.attributes.on_change_column) {
181
+ this._on_change_column = parseOnChange(view.attributes.on_change_column);
182
+ }
183
+
168
184
  const widgetFactory = new WidgetFactory();
169
185
 
170
186
  // Parse children (fields and buttons)
@@ -3,7 +3,14 @@ const parseOnChange = (onChangeString: string) => {
3
3
 
4
4
  const method = splitted[0];
5
5
  const argsGross = splitted[1];
6
- const argsSplitted = argsGross.split(",").map((arg) => arg.trim());
6
+
7
+ // Handle case where there are no parentheses (no arguments)
8
+ const argsSplitted = argsGross
9
+ ? argsGross
10
+ .split(",")
11
+ .map((arg) => arg.trim())
12
+ .filter((arg) => arg.length > 0)
13
+ : [];
7
14
 
8
15
  return {
9
16
  method,
@@ -360,4 +360,43 @@ describe("A Kanban", () => {
360
360
  expect(tree.aggregations.planned_hours).toBe("Total Planned");
361
361
  expect(tree.aggregations.priority).toBe("Total Priority");
362
362
  });
363
+
364
+ it("should parse on_change_column attribute with simple method name", () => {
365
+ const xmlWithOnChange = `<?xml version="1.0"?>
366
+ <kanban column_field="state" on_change_column="handle_state_change">
367
+ <field name="name"/>
368
+ </kanban>
369
+ `;
370
+ const tree = new Kanban(FIELDS);
371
+ tree.parse(xmlWithOnChange);
372
+
373
+ expect(tree.on_change_column).toBeDefined();
374
+ expect(tree.on_change_column?.method).toBe("handle_state_change");
375
+ expect(tree.on_change_column?.args).toHaveLength(0);
376
+ });
377
+
378
+ it("should parse on_change_column attribute with method and arguments", () => {
379
+ const xmlWithOnChangeArgs = `<?xml version="1.0"?>
380
+ <kanban column_field="state" on_change_column="handle_column_change(field, from_column, to_column, context)">
381
+ <field name="name"/>
382
+ </kanban>
383
+ `;
384
+ const tree = new Kanban(FIELDS);
385
+ tree.parse(xmlWithOnChangeArgs);
386
+
387
+ expect(tree.on_change_column).toBeDefined();
388
+ expect(tree.on_change_column?.method).toBe("handle_column_change");
389
+ expect(tree.on_change_column?.args).toHaveLength(4);
390
+ expect(tree.on_change_column?.args[0]).toBe("field");
391
+ expect(tree.on_change_column?.args[1]).toBe("from_column");
392
+ expect(tree.on_change_column?.args[2]).toBe("to_column");
393
+ expect(tree.on_change_column?.args[3]).toBe("context");
394
+ });
395
+
396
+ it("should return null for on_change_column when not defined", () => {
397
+ const tree = new Kanban(FIELDS);
398
+ tree.parse(XML_VIEW_KANBAN_MINIMAL);
399
+
400
+ expect(tree.on_change_column).toBeNull();
401
+ });
363
402
  });