@gisce/ooui 1.0.0-alpha.4 → 1.0.0-alpha.6

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": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.6",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
package/src/Field.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Widget from "./Widget";
2
- import { replaceEntities } from "./helpers/attributeParser";
2
+ import { replaceEntities, isTrue } from "./helpers/attributeParser";
3
3
 
4
4
  class Field extends Widget {
5
5
  /**
@@ -69,6 +69,18 @@ class Field extends Widget {
69
69
  this._tooltip = value;
70
70
  }
71
71
 
72
+ /**
73
+ * Tooltip inline
74
+ */
75
+ _tooltipInline: boolean = false;
76
+ get tooltipInline(): boolean {
77
+ return this._tooltipInline;
78
+ }
79
+
80
+ set tooltipInline(value: boolean) {
81
+ this._tooltipInline = value;
82
+ }
83
+
72
84
  /**
73
85
  * Activated (default is true)
74
86
  */
@@ -152,6 +164,10 @@ class Field extends Widget {
152
164
  if (props.selection) {
153
165
  this._selectionValues = new Map(props.selection);
154
166
  }
167
+
168
+ if (props.help_inline) {
169
+ this.tooltipInline = isTrue(props.help_inline);
170
+ }
155
171
  }
156
172
  }
157
173
 
package/src/Widget.ts CHANGED
@@ -12,14 +12,14 @@ abstract class Widget {
12
12
  }
13
13
 
14
14
  /**
15
- * Determines if widget is read only (default is false)
15
+ * Determines if widget is read only (default is undefined)
16
16
  */
17
- _readOnly: boolean;
18
- get readOnly(): boolean {
17
+ _readOnly: boolean | undefined;
18
+ get readOnly(): boolean | undefined {
19
19
  return this._readOnly;
20
20
  }
21
21
 
22
- set readOnly(value: boolean) {
22
+ set readOnly(value: boolean | undefined) {
23
23
  this._readOnly = value;
24
24
  }
25
25
 
@@ -106,20 +106,25 @@ abstract class Widget {
106
106
 
107
107
  constructor(props?: any) {
108
108
  this._colspan = Widget._defaultColspan;
109
- this._readOnly = false;
110
109
  this._invisible = false;
111
110
 
112
111
  if (props) {
113
112
  if (props.colspan) {
114
113
  this._colspan = +props.colspan;
115
114
  }
116
- if (props.readonly) {
115
+ if (props.readonly !== undefined) {
117
116
  if (
118
117
  props.readonly === "1" ||
119
118
  props.readonly === 1 ||
120
119
  props.readonly === true
121
120
  ) {
122
121
  this._readOnly = true;
122
+ } else if (
123
+ props.readonly === "0" ||
124
+ props.readonly === 0 ||
125
+ props.readonly === false
126
+ ) {
127
+ this._readOnly = false;
123
128
  }
124
129
  }
125
130
  if (props.invisible) {
@@ -1,5 +1,10 @@
1
1
  import { decode } from "html-entities";
2
2
 
3
+ export const isTrue = (value: string | boolean | number = false) => {
4
+ value = JSON.parse(value.toString().toLowerCase());
5
+ return +value > 0;
6
+ };
7
+
3
8
  const evaluateCondition = ({
4
9
  entry,
5
10
  values,
@@ -335,29 +335,54 @@ describe("A Form", () => {
335
335
  }
336
336
  });
337
337
 
338
- it("should be able to parse a field with tooltip", () => {
339
- const fields = {
340
- char1: {
341
- size: 128,
342
- string: "Name",
343
- type: "char",
344
- help: "tooltip string",
345
- },
346
- };
347
- const xmlViewForm = `<?xml version="1.0"?>
348
- <form string="Form1">
349
- <group name="group">
350
- <field colspan="1" name="char1" />
351
- </group>
352
- </form>`;
353
- const form = new Form(fields);
354
- form.parse(xmlViewForm);
338
+ describe("If field has a help message", () => {
339
+ it("should be able to parse a field with tooltip", () => {
340
+ const fields = {
341
+ char1: {
342
+ size: 128,
343
+ string: "Name",
344
+ type: "char",
345
+ help: "tooltip string",
346
+ },
347
+ };
348
+ const xmlViewForm = `<?xml version="1.0"?>
349
+ <form string="Form1">
350
+ <group name="group">
351
+ <field colspan="1" name="char1" />
352
+ </group>
353
+ </form>`;
354
+ const form = new Form(fields);
355
+ form.parse(xmlViewForm);
355
356
 
356
- const field = form.findById("char1") as Char;
357
- expect(field).not.toBeNull();
358
- expect(field.tooltip).toBe("tooltip string");
359
- });
357
+ const field = form.findById("char1") as Char;
358
+ expect(field).not.toBeNull();
359
+ expect(field.tooltip).toBe("tooltip string");
360
+ expect(field.tooltipInline).toBeFalsy();
361
+ });
362
+ it("should be inline if attribute help_inline is set", () => {
363
+ const fields = {
364
+ char1: {
365
+ size: 128,
366
+ string: "Name",
367
+ type: "char",
368
+ help: "tooltip string",
369
+ },
370
+ };
371
+ const xmlViewForm = `<?xml version="1.0"?>
372
+ <form string="Form1">
373
+ <group name="group">
374
+ <field colspan="1" name="char1" help_inline="1"/>
375
+ </group>
376
+ </form>`;
377
+ const form = new Form(fields);
378
+ form.parse(xmlViewForm);
360
379
 
380
+ const field = form.findById("char1") as Char;
381
+ expect(field).not.toBeNull();
382
+ expect(field.tooltip).toBe("tooltip string");
383
+ expect(field.tooltipInline).toBeTruthy();
384
+ });
385
+ });
361
386
  it("should properly parse a password field", () => {
362
387
  const arch =
363
388
  '<form><group><field name="password" password="True" readonly="0"/></group></form>';
@@ -21,12 +21,6 @@ describe("A Widget", () => {
21
21
  expect(widget.colspan).toBe(3);
22
22
  });
23
23
 
24
- it("should be readOnly false by default", () => {
25
- const widget = new WidgetImpl();
26
-
27
- expect(widget.readOnly).toBe(false);
28
- });
29
-
30
24
  it("colspan should be of type Number", () => {
31
25
  const widget = new WidgetImpl();
32
26
 
@@ -1,5 +1,5 @@
1
1
  import { it, expect, describe } from "vitest";
2
- import { evaluateAttributes } from "../helpers/attributeParser";
2
+ import { evaluateAttributes, isTrue } from "../helpers/attributeParser";
3
3
 
4
4
  const fields = {
5
5
  force_potencia_adscrita: {
@@ -212,4 +212,39 @@ describe("An Attribute Parser", () => {
212
212
  expect(evaluatedAttrs.invisible).toBeTruthy();
213
213
  });
214
214
  });
215
+ describe("isTrue method", () => {
216
+ it("should return true when value is 'True'", () => {
217
+ expect(isTrue("True")).toBeTruthy();
218
+ });
219
+ it("should return true when value is 'true'", () => {
220
+ expect(isTrue("true")).toBeTruthy();
221
+ });
222
+ it("should return true when value is true", () => {
223
+ expect(isTrue(true)).toBeTruthy();
224
+ });
225
+ it("should return true when value is '1'", () => {
226
+ expect(isTrue("1")).toBeTruthy();
227
+ });
228
+ it("should return true when value is 1", () => {
229
+ expect(isTrue(1)).toBeTruthy();
230
+ });
231
+ it("should return false when value is 'False'", () => {
232
+ expect(isTrue("False")).toBeFalsy();
233
+ });
234
+ it("should return false when value is 'false'", () => {
235
+ expect(isTrue("false")).toBeFalsy();
236
+ });
237
+ it("should return false when value is false", () => {
238
+ expect(isTrue(false)).toBeFalsy();
239
+ });
240
+ it("should return false when value is '0'", () => {
241
+ expect(isTrue("0")).toBeFalsy();
242
+ });
243
+ it("should return false when value is 0", () => {
244
+ expect(isTrue(0)).toBeFalsy();
245
+ });
246
+ it("should return false when value is undefined", () => {
247
+ expect(isTrue(undefined)).toBeFalsy();
248
+ });
249
+ });
215
250
  });