Skip to content

Commit

Permalink
Merge pull request #93 from gisce/help-inline
Browse files Browse the repository at this point in the history
Allow help to be inline
  • Loading branch information
mguellsegarra authored Nov 15, 2023
2 parents b5d09f2 + 2e7ab05 commit 31d846f
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/ooui",
"version": "0.22.4",
"version": "0.22.5",
"main": "./dist/ooui.umd.js",
"module": "./dist/ooui.es.js",
"types": "./dist/index.d.ts",
Expand Down
18 changes: 17 additions & 1 deletion src/Field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Widget from "./Widget";
import { replaceEntities } from "./helpers/attributeParser";
import { replaceEntities, isTrue } from "./helpers/attributeParser";

class Field extends Widget {
/**
Expand Down Expand Up @@ -64,6 +64,18 @@ class Field extends Widget {
this._tooltip = value;
}

/**
* Tooltip inline
*/
_tooltipInline: boolean = false;
get tooltipInline(): boolean {
return this._tooltipInline;
}
set tooltipInline(value: boolean) {
this._tooltipInline = value;
}


/**
* Activated (default is true)
*/
Expand Down Expand Up @@ -144,6 +156,10 @@ class Field extends Widget {
if (props.selection) {
this._selectionValues = new Map(props.selection);
}

if (props.help_inline) {
this.tooltipInline = isTrue(props.help_inline);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/helpers/attributeParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { decode } from "html-entities";

export const isTrue = (value: string | boolean | number = false) => {
value = JSON.parse(value.toString().toLowerCase())
return (+ value > 0)
}

const evaluateCondition = ({
entry,
values,
Expand Down
67 changes: 46 additions & 21 deletions src/spec/Form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,29 +334,54 @@ describe("A Form", () => {
}
});

it("should be able to parse a field with tooltip", () => {
const fields = {
char1: {
size: 128,
string: "Name",
type: "char",
help: "tooltip string",
},
};
const xmlViewForm = `<?xml version="1.0"?>
<form string="Form1">
<group name="group">
<field colspan="1" name="char1" />
</group>
</form>`;
const form = new Form(fields);
form.parse(xmlViewForm);
describe("If field has a help message", () => {
it("should be able to parse a field with tooltip", () => {
const fields = {
char1: {
size: 128,
string: "Name",
type: "char",
help: "tooltip string",
},
};
const xmlViewForm = `<?xml version="1.0"?>
<form string="Form1">
<group name="group">
<field colspan="1" name="char1" />
</group>
</form>`;
const form = new Form(fields);
form.parse(xmlViewForm);

const field = form.findById("char1") as Char;
expect(field).not.toBeNull();
expect(field.tooltip).toBe("tooltip string");
});
const field = form.findById("char1") as Char;
expect(field).not.toBeNull();
expect(field.tooltip).toBe("tooltip string");
expect(field.tooltipInline).toBeFalsy();
});
it("should be inline if attribute help_inline is set", () => {
const fields = {
char1: {
size: 128,
string: "Name",
type: "char",
help: "tooltip string",
},
};
const xmlViewForm = `<?xml version="1.0"?>
<form string="Form1">
<group name="group">
<field colspan="1" name="char1" help_inline="1"/>
</group>
</form>`;
const form = new Form(fields);
form.parse(xmlViewForm);

const field = form.findById("char1") as Char;
expect(field).not.toBeNull();
expect(field.tooltip).toBe("tooltip string");
expect(field.tooltipInline).toBeTruthy();
});
})
it("should properly parse a password field", () => {
const arch =
'<form><group><field name="password" password="True" readonly="0"/></group></form>';
Expand Down
37 changes: 36 additions & 1 deletion src/spec/attributeParser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { evaluateAttributes } from "../helpers/attributeParser";
import { evaluateAttributes, isTrue } from "../helpers/attributeParser";

const fields = {
force_potencia_adscrita: {
Expand Down Expand Up @@ -211,4 +211,39 @@ describe("An Attribute Parser", () => {
expect(evaluatedAttrs.invisible).toBeTruthy();
});
});
describe("isTrue method", () => {
it("should return true when value is 'True'", () => {
expect(isTrue('True')).toBeTruthy();
})
it("should return true when value is 'true'", () => {
expect(isTrue('true')).toBeTruthy();
})
it("should return true when value is true", () => {
expect(isTrue(true)).toBeTruthy();
})
it("should return true when value is '1'", () => {
expect(isTrue('1')).toBeTruthy();
})
it("should return true when value is 1", () => {
expect(isTrue(1)).toBeTruthy();
})
it("should return false when value is 'False'", () => {
expect(isTrue('False')).toBeFalsy();
})
it("should return false when value is 'false'", () => {
expect(isTrue('false')).toBeFalsy();
})
it("should return false when value is false", () => {
expect(isTrue(false)).toBeFalsy();
})
it("should return false when value is '0'", () => {
expect(isTrue('0')).toBeFalsy();
})
it("should return false when value is 0", () => {
expect(isTrue(0)).toBeFalsy();
})
it("should return false when value is undefined", () => {
expect(isTrue(undefined)).toBeFalsy();
})
});
});

0 comments on commit 31d846f

Please sign in to comment.