@gisce/ooui 0.22.4 → 0.22.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/ooui",
3
- "version": "0.22.4",
3
+ "version": "0.22.5",
4
4
  "main": "./dist/ooui.umd.js",
5
5
  "module": "./dist/ooui.es.js",
6
6
  "types": "./dist/index.d.ts",
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
  /**
@@ -64,6 +64,18 @@ class Field extends Widget {
64
64
  this._tooltip = value;
65
65
  }
66
66
 
67
+ /**
68
+ * Tooltip inline
69
+ */
70
+ _tooltipInline: boolean = false;
71
+ get tooltipInline(): boolean {
72
+ return this._tooltipInline;
73
+ }
74
+ set tooltipInline(value: boolean) {
75
+ this._tooltipInline = value;
76
+ }
77
+
78
+
67
79
  /**
68
80
  * Activated (default is true)
69
81
  */
@@ -144,6 +156,10 @@ class Field extends Widget {
144
156
  if (props.selection) {
145
157
  this._selectionValues = new Map(props.selection);
146
158
  }
159
+
160
+ if (props.help_inline) {
161
+ this.tooltipInline = isTrue(props.help_inline);
162
+ }
147
163
  }
148
164
  }
149
165
 
@@ -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,
@@ -334,29 +334,54 @@ describe("A Form", () => {
334
334
  }
335
335
  });
336
336
 
337
- it("should be able to parse a field with tooltip", () => {
338
- const fields = {
339
- char1: {
340
- size: 128,
341
- string: "Name",
342
- type: "char",
343
- help: "tooltip string",
344
- },
345
- };
346
- const xmlViewForm = `<?xml version="1.0"?>
347
- <form string="Form1">
348
- <group name="group">
349
- <field colspan="1" name="char1" />
350
- </group>
351
- </form>`;
352
- const form = new Form(fields);
353
- form.parse(xmlViewForm);
337
+ describe("If field has a help message", () => {
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);
354
355
 
355
- const field = form.findById("char1") as Char;
356
- expect(field).not.toBeNull();
357
- expect(field.tooltip).toBe("tooltip string");
358
- });
356
+ const field = form.findById("char1") as Char;
357
+ expect(field).not.toBeNull();
358
+ expect(field.tooltip).toBe("tooltip string");
359
+ expect(field.tooltipInline).toBeFalsy();
360
+ });
361
+ it("should be inline if attribute help_inline is set", () => {
362
+ const fields = {
363
+ char1: {
364
+ size: 128,
365
+ string: "Name",
366
+ type: "char",
367
+ help: "tooltip string",
368
+ },
369
+ };
370
+ const xmlViewForm = `<?xml version="1.0"?>
371
+ <form string="Form1">
372
+ <group name="group">
373
+ <field colspan="1" name="char1" help_inline="1"/>
374
+ </group>
375
+ </form>`;
376
+ const form = new Form(fields);
377
+ form.parse(xmlViewForm);
359
378
 
379
+ const field = form.findById("char1") as Char;
380
+ expect(field).not.toBeNull();
381
+ expect(field.tooltip).toBe("tooltip string");
382
+ expect(field.tooltipInline).toBeTruthy();
383
+ });
384
+ })
360
385
  it("should properly parse a password field", () => {
361
386
  const arch =
362
387
  '<form><group><field name="password" password="True" readonly="0"/></group></form>';
@@ -1,4 +1,4 @@
1
- import { evaluateAttributes } from "../helpers/attributeParser";
1
+ import { evaluateAttributes, isTrue } from "../helpers/attributeParser";
2
2
 
3
3
  const fields = {
4
4
  force_potencia_adscrita: {
@@ -211,4 +211,39 @@ describe("An Attribute Parser", () => {
211
211
  expect(evaluatedAttrs.invisible).toBeTruthy();
212
212
  });
213
213
  });
214
+ describe("isTrue method", () => {
215
+ it("should return true when value is 'True'", () => {
216
+ expect(isTrue('True')).toBeTruthy();
217
+ })
218
+ it("should return true when value is 'true'", () => {
219
+ expect(isTrue('true')).toBeTruthy();
220
+ })
221
+ it("should return true when value is true", () => {
222
+ expect(isTrue(true)).toBeTruthy();
223
+ })
224
+ it("should return true when value is '1'", () => {
225
+ expect(isTrue('1')).toBeTruthy();
226
+ })
227
+ it("should return true when value is 1", () => {
228
+ expect(isTrue(1)).toBeTruthy();
229
+ })
230
+ it("should return false when value is 'False'", () => {
231
+ expect(isTrue('False')).toBeFalsy();
232
+ })
233
+ it("should return false when value is 'false'", () => {
234
+ expect(isTrue('false')).toBeFalsy();
235
+ })
236
+ it("should return false when value is false", () => {
237
+ expect(isTrue(false)).toBeFalsy();
238
+ })
239
+ it("should return false when value is '0'", () => {
240
+ expect(isTrue('0')).toBeFalsy();
241
+ })
242
+ it("should return false when value is 0", () => {
243
+ expect(isTrue(0)).toBeFalsy();
244
+ })
245
+ it("should return false when value is undefined", () => {
246
+ expect(isTrue(undefined)).toBeFalsy();
247
+ })
248
+ });
214
249
  });