Skip to content

Commit

Permalink
Merge branch 'feature/auto-refresh-field' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Dec 4, 2024
2 parents cc78e0a + 81ee897 commit e36fe35
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Tree.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import WidgetFactory from "./WidgetFactory";
import Widget from "./Widget";
import { replaceEntities } from "./helpers/attributeParser";
import { ParsedNode } from "./helpers/nodeParser";
import { parseBoolAttribute, ParsedNode } from "./helpers/nodeParser";
import * as txml from "txml";
import { parseContext } from "./helpers/contextParser";

Expand Down Expand Up @@ -67,6 +67,14 @@ class Tree {
this._contextForFields = value;
}

/**
* List of autorefreshable fields
*/
_autorefreshableFields: string[] = [];
get autorefreshableFields(): string[] {
return this._autorefreshableFields;
}

/**
* Is infinite
*/
Expand Down Expand Up @@ -145,6 +153,10 @@ class Tree {
const widget = widgetFactory.createWidget(widgetType, mergedAttrs);
this._columns.push(widget);
}

if (parseBoolAttribute(mergedAttrs.autorefresh)) {
this._autorefreshableFields.push(name);
}
}
});
}
Expand Down
19 changes: 19 additions & 0 deletions src/spec/Tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,23 @@ describe("A Tree", () => {
const nameWidget = tree.findById("name") as Char;
expect(nameWidget.isFunction).toBeTruthy();
});
it("Should parse autorefreshable fields", () => {
const tree = new Tree({
name: {
required: true,
select: true,
size: 128,
string: "Potència contractada (kW)",
type: "char",
views: {},
},
});
tree.parse(
`<tree string="Partners" colors="red:type=='updated'"><field name="name" sum="Pot&#232;ncia contractada (kW)" autorefresh="1"/></tree>`,
);

const nameWidget = tree.findById("name") as Char;
expect(nameWidget.autoRefresh).toBeTruthy();
expect(tree._autorefreshableFields.length).toBe(1);
});
});

0 comments on commit e36fe35

Please sign in to comment.