@gisce/ooui 2.40.0 → 2.42.0

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",
3
+ "version": "2.42.0",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
@@ -23,6 +23,16 @@ export class GraphIndicator extends Graph {
23
23
  return this._showPercent;
24
24
  }
25
25
 
26
+ _progressbar: boolean = false;
27
+ get progressbar(): boolean {
28
+ return this._progressbar;
29
+ }
30
+
31
+ _showTotal: boolean = true;
32
+ get showTotal(): boolean {
33
+ return this._showTotal;
34
+ }
35
+
26
36
  _suffix: string | null = null;
27
37
  get suffix(): string | null {
28
38
  return this._suffix;
@@ -43,5 +53,10 @@ export class GraphIndicator extends Graph {
43
53
  this._suffix = element.attributes.suffix || null;
44
54
  this._totalDomain = replaceEntities(element.attributes.totalDomain) || null;
45
55
  this._showPercent = parseBoolAttribute(element.attributes.showPercent);
56
+ this._progressbar = parseBoolAttribute(element.attributes.progressbar);
57
+ this._showTotal =
58
+ element.attributes.showTotal !== undefined
59
+ ? parseBoolAttribute(element.attributes.showTotal)
60
+ : !!this._totalDomain;
46
61
  }
47
62
  }
package/src/Icon.ts ADDED
@@ -0,0 +1,59 @@
1
+ import Field from "./Field";
2
+
3
+ class Icon extends Field {
4
+ /**
5
+ * Icon name
6
+ */
7
+ _name: string = "";
8
+ get name(): string {
9
+ return this._name;
10
+ }
11
+
12
+ set name(value: string) {
13
+ this._name = value;
14
+ }
15
+
16
+ /**
17
+ * Icon size
18
+ */
19
+ _size: number = 16;
20
+ get size(): number {
21
+ return this._size;
22
+ }
23
+
24
+ set size(value: number) {
25
+ this._size = value;
26
+ }
27
+
28
+ /**
29
+ * Icon color
30
+ */
31
+ _color: string = "";
32
+ get color(): string {
33
+ return this._color;
34
+ }
35
+
36
+ set color(value: string) {
37
+ this._color = value;
38
+ }
39
+
40
+ constructor(props?: any) {
41
+ super({ ...props, nolabel: true });
42
+
43
+ if (props) {
44
+ if (props.name) {
45
+ this._name = props.name;
46
+ }
47
+
48
+ if (props.size) {
49
+ this._size = props.size;
50
+ }
51
+
52
+ if (props.color) {
53
+ this._color = props.color;
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ export default Icon;
@@ -25,6 +25,7 @@ import Separator from "./Separator";
25
25
  import Reference from "./Reference";
26
26
  import Binary from "./Binary";
27
27
  import Image from "./Image";
28
+ import Icon from "./Icon";
28
29
  import FiberGrid from "./FiberGrid";
29
30
  import Timeline from "./Timeline";
30
31
  import Indicator from "./Indicator";
@@ -141,6 +142,9 @@ class WidgetFactory {
141
142
  case "image":
142
143
  this._widgetClass = Image;
143
144
  break;
145
+ case "icon":
146
+ this._widgetClass = Icon;
147
+ break;
144
148
  case "fiber_grid":
145
149
  this._widgetClass = FiberGrid;
146
150
  break;
package/src/index.ts CHANGED
@@ -31,6 +31,7 @@ import ActionButtons from "./ActionButtons";
31
31
  import Reference from "./Reference";
32
32
  import Binary from "./Binary";
33
33
  import Image from "./Image";
34
+ import Icon from "./Icon";
34
35
  import { parseContext, parseContextFields } from "./helpers/contextParser";
35
36
  import {
36
37
  transformDomainForChildWidget,
@@ -111,6 +112,7 @@ export {
111
112
  Reference,
112
113
  Binary,
113
114
  Image,
115
+ Icon,
114
116
  parseContext,
115
117
  parseContextFields,
116
118
  transformDomainForChildWidget,
@@ -55,6 +55,66 @@ describe("A Graph", () => {
55
55
  expect(graph.field).toBe("potencia");
56
56
  expect(graph.operator).toBe("+");
57
57
  });
58
+ it("should parse progressbar, showPercent and showTotal attributes", () => {
59
+ const xml1 = `<?xml version="1.0"?>
60
+ <graph string="My indicator" type="indicator" progressbar="1" />
61
+ `;
62
+
63
+ const graph1 = parseGraph(xml1) as GraphIndicator;
64
+ expect(graph1.progressbar).toBe(true);
65
+ expect(graph1.showPercent).toBe(false);
66
+ expect(graph1.showTotal).toBe(false); // No totalDomain, should default to false
67
+
68
+ const xml2 = `<?xml version="1.0"?>
69
+ <graph string="My indicator" type="indicator" showPercent="1" />
70
+ `;
71
+
72
+ const graph2 = parseGraph(xml2) as GraphIndicator;
73
+ expect(graph2.showPercent).toBe(true);
74
+ expect(graph2.progressbar).toBe(false);
75
+ expect(graph2.showTotal).toBe(false); // No totalDomain, should default to false
76
+
77
+ const xml3 = `<?xml version="1.0"?>
78
+ <graph string="My indicator" type="indicator" />
79
+ `;
80
+
81
+ const graph3 = parseGraph(xml3) as GraphIndicator;
82
+ expect(graph3.showPercent).toBe(false);
83
+ expect(graph3.progressbar).toBe(false);
84
+ expect(graph3.showTotal).toBe(false); // No totalDomain, should default to false
85
+
86
+ const xml4 = `<?xml version="1.0"?>
87
+ <graph string="My indicator" type="indicator" showTotal="0" />
88
+ `;
89
+
90
+ const graph4 = parseGraph(xml4) as GraphIndicator;
91
+ expect(graph4.showTotal).toBe(false);
92
+ });
93
+ it("should set showTotal to true when totalDomain is defined", () => {
94
+ const xml1 = `<?xml version="1.0"?>
95
+ <graph string="My indicator" type="indicator" totalDomain="[('state','=','open')]" />
96
+ `;
97
+
98
+ const graph1 = parseGraph(xml1) as GraphIndicator;
99
+ expect(graph1.totalDomain).toBe("[('state','=','open')]");
100
+ expect(graph1.showTotal).toBe(true); // totalDomain is defined, should default to true
101
+
102
+ const xml2 = `<?xml version="1.0"?>
103
+ <graph string="My indicator" type="indicator" totalDomain="[('state','=','open')]" showTotal="0" />
104
+ `;
105
+
106
+ const graph2 = parseGraph(xml2) as GraphIndicator;
107
+ expect(graph2.totalDomain).toBe("[('state','=','open')]");
108
+ expect(graph2.showTotal).toBe(false); // Explicitly set to false
109
+
110
+ const xml3 = `<?xml version="1.0"?>
111
+ <graph string="My indicator" type="indicator" totalDomain="[('state','=','open')]" showTotal="1" />
112
+ `;
113
+
114
+ const graph3 = parseGraph(xml3) as GraphIndicator;
115
+ expect(graph3.totalDomain).toBe("[('state','=','open')]");
116
+ expect(graph3.showTotal).toBe(true); // Explicitly set to true
117
+ });
58
118
  it("should parse a graph with timerange parameter", () => {
59
119
  const xml = `<?xml version="1.0"?>
60
120
  <graph type="line" timerange="day">
@@ -0,0 +1,93 @@
1
+ import WidgetFactory from "../WidgetFactory";
2
+ import { it, expect, describe } from "vitest";
3
+
4
+ describe("An Icon", () => {
5
+ it("should have an id corresponding to field name", () => {
6
+ const widgetFactory = new WidgetFactory();
7
+ const props = {
8
+ name: "icon1",
9
+ };
10
+
11
+ const widget = widgetFactory.createWidget("icon", props);
12
+
13
+ expect(widget.id).toBe("icon1");
14
+ });
15
+
16
+ it("should properly have nolabel as true by default", () => {
17
+ const widgetFactory = new WidgetFactory();
18
+ const props = {
19
+ name: "icon1",
20
+ };
21
+ const widget = widgetFactory.createWidget("icon", props);
22
+
23
+ expect(widget.nolabel).toBe(true);
24
+ });
25
+
26
+ it("should properly set name", () => {
27
+ const widgetFactory = new WidgetFactory();
28
+ const props = {
29
+ name: "icon1",
30
+ };
31
+ const widget = widgetFactory.createWidget("icon", props);
32
+
33
+ widget.name = "home";
34
+ expect(widget.name).toBe("home");
35
+ });
36
+
37
+ it("should properly set size", () => {
38
+ const widgetFactory = new WidgetFactory();
39
+ const props = {
40
+ name: "icon1",
41
+ size: 24,
42
+ };
43
+ const widget = widgetFactory.createWidget("icon", props);
44
+
45
+ expect(widget.size).toBe(24);
46
+ });
47
+
48
+ it("should have default size of 16", () => {
49
+ const widgetFactory = new WidgetFactory();
50
+ const props = {
51
+ name: "icon1",
52
+ };
53
+ const widget = widgetFactory.createWidget("icon", props);
54
+
55
+ expect(widget.size).toBe(16);
56
+ });
57
+
58
+ it("should properly set color", () => {
59
+ const widgetFactory = new WidgetFactory();
60
+ const props = {
61
+ name: "icon1",
62
+ color: "#FF0000",
63
+ };
64
+ const widget = widgetFactory.createWidget("icon", props);
65
+
66
+ expect(widget.color).toBe("#FF0000");
67
+ });
68
+
69
+ it("should have empty color by default", () => {
70
+ const widgetFactory = new WidgetFactory();
71
+ const props = {
72
+ name: "icon1",
73
+ };
74
+ const widget = widgetFactory.createWidget("icon", props);
75
+
76
+ expect(widget.color).toBe("");
77
+ });
78
+
79
+ it("should properly parse all props together", () => {
80
+ const widgetFactory = new WidgetFactory();
81
+ const props = {
82
+ name: "icon1",
83
+ size: 32,
84
+ color: "blue",
85
+ };
86
+ const widget = widgetFactory.createWidget("icon", props);
87
+
88
+ widget.name = "star";
89
+ expect(widget.name).toBe("star");
90
+ expect(widget.size).toBe(32);
91
+ expect(widget.color).toBe("blue");
92
+ });
93
+ });