Skip to content

Commit d2de2f2

Browse files
Saving settings to local storage
1 parent 9c6917b commit d2de2f2

File tree

4 files changed

+56
-17
lines changed

4 files changed

+56
-17
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iknow-entity-browser",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"description": "Visualizer for iKnow entities",
55
"main": "gulpfile.babel.js",
66
"scripts": {
@@ -15,15 +15,15 @@
1515
"license": "MIT",
1616
"devDependencies": {
1717
"6to5ify": "^4.1.1",
18-
"babel": "^6.5.2",
19-
"babel-core": "^6.18.2",
20-
"babel-preset-es2015": "^6.18.0",
21-
"browserify": "^13.1.1",
18+
"babel": "^6.23.0",
19+
"babel-core": "^6.23.1",
20+
"babel-preset-es2015": "^6.22.0",
21+
"browserify": "^14.1.0",
2222
"gulp": "^3.9.1",
2323
"gulp-cssmin": "^0.1.7",
2424
"gulp-preprocess": "^2.0.0",
2525
"gulp-rimraf": "^0.2.0",
26-
"gulp-sass": "^2.3.2",
26+
"gulp-sass": "^3.1.0",
2727
"gulp-streamify": "^1.0.2",
2828
"vinyl-source-stream": "^1.1.0"
2929
}

src/static/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
<svg id="graph">
3131
<defs>
3232
<marker id="svgLineArrow-related" markerWidth="10" markerHeight="10" refX="7" refY="3" orient="auto" markerUnits="strokeWidth">
33-
<path d="M0,0 L0,6 L9,3 z" fill="#ffb840"/>
33+
<path d="M0,0 L0,6 L9,3 z" fill="#ffb840"></path>
3434
</marker>
3535
<marker id="svgLineArrow-similar" markerWidth="10" markerHeight="10" refX="7" refY="3" orient="auto" markerUnits="strokeWidth">
36-
<path d="M0,0 L0,6 L9,3 z" fill="#7ca1ff"/>
36+
<path d="M0,0 L0,6 L9,3 z" fill="#7ca1ff"></path>
3737
</marker>
3838
<marker id="svgLineArrow-other" markerWidth="10" markerHeight="10" refX="7" refY="3" orient="auto" markerUnits="strokeWidth">
39-
<path d="M0,0 L0,6 L9,3 z" fill="#f00"/>
39+
<path d="M0,0 L0,6 L9,3 z" fill="#f00"></path>
4040
</marker>
4141
</defs>
4242
</svg>
@@ -116,10 +116,10 @@ <h1>General Settings</h1>
116116
<b>Data source:</b>
117117
<input type="text" value="http://localhost" id="settings.host" autosize placeholder="http://host.name"/>
118118
: <input id="settings.port" autosize type="number" placeholder="port" value="57772"/>
119-
/ <input id="settings.webAppName" autosize type="text" placeholder="domain" value="EntityBrowser"/>
119+
/ <input id="settings.webAppName" autosize type="text" placeholder="app name" value="EntityBrowser"/>
120120
/domain/ <input id="settings.domain" autosize type="text" placeholder="domain" value="1"/>
121121
/
122-
<select id="settings.queryType">
122+
<select id="settings.queryType" title="Query Type">
123123
<option value="related">related</option>
124124
<option value="similar">similar</option>
125125
</select>

src/static/js/source/index.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import { httpGet } from "../utils";
2+
import * as storage from "../storage";
23

3-
let settings = {
4+
const STORAGE_KEY = "settings";
45

6+
let settings = { // assign defaults here
7+
host: "http://localhost",
8+
port: "57772",
9+
webAppName: "EntityBrowser",
10+
domain: "1",
11+
queryType: "related",
12+
seed: "crew"
513
};
614

15+
let initialStorage = storage.load(STORAGE_KEY);
16+
for (let option in initialStorage) {
17+
settings[option] = initialStorage[option];
18+
}
19+
720
export function getOption (opt) {
821
return settings[opt];
922
}
@@ -33,17 +46,28 @@ export function getData (callback) {
3346
}
3447

3548
function bind (elements) {
36-
elements.forEach(e => {
37-
setValue(document.getElementById(e)).addEventListener(`change`, setValue)
38-
});
49+
for (let e of elements) {
50+
setValue(document.getElementById(e)).addEventListener(`change`, setValue);
51+
}
52+
}
53+
54+
function saveSettings () {
55+
storage.save(STORAGE_KEY, settings);
3956
}
4057

4158
function setValue (e = {}) {
42-
let id, el = e instanceof HTMLElement ? e : (e.target || e.srcElement);
59+
let isEvent = !(e instanceof HTMLElement),
60+
id, el = isEvent ? (e.target || e.srcElement) : e;
4361
if (!el)
4462
return e;
4563
if ((id = el.getAttribute(`id`)).indexOf(`settings.`) === 0) {
46-
settings[id.replace(/^settings\./, ``)] = el.value;
64+
let key = id.replace(/^settings\./, ``);
65+
if (isEvent) {
66+
settings[key] = el.value;
67+
saveSettings();
68+
} else {
69+
el.value = settings[key];
70+
}
4771
}
4872
return e;
4973
}

src/static/js/storage.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const STORAGE_NAME = "iKnowEntityBrowser";
2+
const storage = JSON.parse(localStorage.getItem(STORAGE_NAME)) || {};
3+
4+
export function save (key, value) {
5+
storage[key] = value;
6+
updateLocalStorage();
7+
}
8+
9+
export function load (key) {
10+
return storage[key];
11+
}
12+
13+
function updateLocalStorage () {
14+
localStorage.setItem(STORAGE_NAME, JSON.stringify(storage));
15+
}

0 commit comments

Comments
 (0)