Skip to content

Commit 490b2b4

Browse files
Specifying settings via URL parameters feature, reset button styling
1 parent c27def6 commit 490b2b4

File tree

8 files changed

+57
-7
lines changed

8 files changed

+57
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iknow-entity-browser",
3-
"version": "0.7.10",
3+
"version": "0.7.11",
44
"description": "Visualizer for iKnow entities",
55
"main": "gulpfile.babel.js",
66
"scripts": {

src/static/js/settings/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export function init () {
2626
.data([model.uiState])
2727
.on("click", toggleSettings);
2828

29-
sourceSettings.init();
3029
tabularViewSettings.init();
3130
initValues();
31+
sourceSettings.init();
3232

3333
// make inputs auto-sizable
3434
[].slice.call(document.querySelectorAll(`input[autosize]`)).forEach((i) => makeAutosizable(i));

src/static/js/settings/sourceSettings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ export function init () {
4343
return;
4444
apply();
4545
});
46-
46+
document.getElementById("settings.seed").addEventListener(`keydown`, (e) => {
47+
if (e.keyCode !== 13)
48+
return;
49+
document.getElementById("settings.seed").blur();
50+
});
4751
}

src/static/js/settings/values.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import * as storage from "../storage";
22
import { getObjProp } from "../utils";
3+
import * as url from "../url";
34

45
const STORAGE_KEY = "settings";
56

6-
let settings = { // assign defaults here
7+
const settingsTypes = {
8+
host: String,
9+
port: Number,
10+
webAppName: String,
11+
domain: String,
12+
queryType: new Set(["similar", "related"]),
13+
seed: String,
14+
keepSeedInView: Boolean
15+
};
16+
17+
const settings = { // assign defaults here
718
host: "http://localhost",
8-
port: "57772",
19+
port: 57772,
920
webAppName: "EntityBrowser",
1021
domain: "1",
1122
queryType: "related",
@@ -111,5 +122,18 @@ export function setInputValue (e = {}) {
111122
}
112123

113124
export function init () {
125+
let params = url.getSearchString();
126+
for (let param in params) {
127+
let type = getObjProp(settingsTypes, param.split(".")),
128+
v = params[param];
129+
if (typeof type === "undefined")
130+
continue;
131+
settings[param] =
132+
type === String ? v :
133+
type === Number ? parseFloat(v) :
134+
type === Boolean ? (v === "false" ? false : v === "" ? true : !!v) :
135+
type instanceof Set ? (type.has(v) ? v : settings[param]) :
136+
settings[param];
137+
}
114138
applyFixedClass();
115139
}

src/static/js/url.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const getParams = query => {
2+
if (!query) {
3+
return {};
4+
}
5+
return (/^[?#]/.test(query) ? query.slice(1) : query)
6+
.split('&')
7+
.reduce((params, param) => {
8+
let [ key, value ] = param.split('=');
9+
params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : '';
10+
return params;
11+
}, {});
12+
};
13+
14+
let params = getParams(location.search);
15+
16+
export function getSearchString () {
17+
return params;
18+
}

src/static/js/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export function httpGet (theUrl, callback) {
9292
try {
9393
data = JSON.parse(xmlHttp.responseText);
9494
} catch (e) {
95-
console.error(e, xmlHttp.responseText);
9695
callback({ error: e });
9796
return;
9897
}

src/static/scss/const.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ $defaultShadow: 0 0 2px gray;
55
$colorA: #02ad8b;
66
$colorB: #e08f00;
77
$colorC: #4c79c1;
8+
$colorD: #ff554b;
89

910
$highlightColor: rgb(255, 245, 161);
1011
$relatedColor: #ffb840;
1112
$similarColor: #7ca1ff;
12-
$otherColor: red;
13+
$otherColor: $colorD;
1314

1415
$zIndexInterface: 100;
1516
$zIndexOnTop: 200;

src/static/scss/settings.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555

5656
}
5757

58+
#settings\.resetSettings {
59+
background-color: $colorD;
60+
}
61+
5862
#closeSettingsToggle {
5963

6064
position: absolute;

0 commit comments

Comments
 (0)