Skip to content

Commit

Permalink
#118 clean up field names, fix user settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
cdot committed Jan 31, 2024
1 parent 17d80f7 commit 0af6661
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 71 deletions.
2 changes: 1 addition & 1 deletion bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const DEFAULT_CONFIG = {
// Defaults passed to the UI without processing by the server
user_defaults: {
notification: false, // notification requires https
theme: "default",
layout: "default",
jqTheme: "pepper-grinder",
warnings: true,
cheers: true,
Expand Down
4 changes: 2 additions & 2 deletions html/UserSettingsDialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</div>

<div class="dialog-row">
<label for="xanadoCSS" data-i18n-tooltip="tt-look-feel" data-i18n="label-look-feel"></label>
<select id="xanadoCSS" name="xanadoCSS">
<label for="layout" data-i18n-tooltip="tt-look-feel" data-i18n="label-look-feel"></label>
<select id="layout" name="layout">
</select>
</div>

Expand Down
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"tt-invite": "Send emails to invite people to join the game",
"tt-invite-mess": "Add a message that will be included in the invitation email",
"tt-join": "Join the game and open it in a new window",
"tt-jqTheme": "Choose a display theme",
"tt-jqTheme": "Choose a display theme for dialogs",
"tt-lang-code": "Choose a supported language code (e.g. 'en' is English)",
"tt-leave": "If you leave the game your score will still count towards the leader board.",
"tt-library": "Open games library",
Expand Down
25 changes: 5 additions & 20 deletions src/browser/GameSetupDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,13 @@ class GameSetupDialog extends Dialog {
.then(editions => {
const $eds = this.$dlg.find("[name=edition]");
editions.forEach(e => $eds.append(`<option value="${e}">${e}</option>`));
if (ui.getSetting("edition")) {
$eds.val(ui.getSetting("edition"));
$eds.selectmenu("refresh");
}
}),
ui.promiseDictionaries()
.then(dictionaries => {
const $dics = this.$dlg.find("[name=dictionary]");
dictionaries
.forEach(d => $dics.append($(`<option value="${d}">${d}</option>`)));
$dics.on("selectmenuchange", () => this.showFeedbackFields());
const seldic = ui.getSetting("dictionary");
if (seldic)
$dics.val(seldic).selectmenu("refresh");
this.showFeedbackFields();
})
]);
Expand All @@ -150,21 +143,13 @@ class GameSetupDialog extends Dialog {
$fields.each((i, el) => {
const $el = $(el);
const field = $el.attr("name");
let val = game ? game[field] : (
ui.getSetting(field) || Game.DEFAULTS[field]);
if (el.tagName === "INPUT" && el.type === "checkbox") {
//console.debug("SET", field, "=", val);
const val = (game ? game[field] : undefined) || ui.getSetting(field);
if (el.tagName === "INPUT" && el.type === "checkbox")
$el.prop("checked", val).checkboxradio("refresh");
} else if (el.tagName === "SELECT") {
if (typeof val === "undefined")
val = this.options.ui.getSetting(field);
//console.debug("SELECT", field, "=", val);
$el.val(val || "none");
$el.selectmenu("refresh");
} else if (val) {
//console.debug("SET", field, "=", val);
else if (el.tagName === "SELECT")
$el.val(val).selectmenu("refresh");
else if (val)
$el.val(val);
}
return true;
});
this.showTimerFields();
Expand Down
10 changes: 6 additions & 4 deletions src/browser/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ class UI {
// Initialise jquery theme
const jqTheme = this.getSetting("jqTheme");
if (jqTheme)
// Replace the link for the jQuery theme
$("#jQueryTheme").each(function() {
this.href = this.href.replace(/\/themes\/[^/.]+/, `/themes/${jqTheme}`);
});

const css = this.getSetting("xanadoCSS");
const css = this.getSetting("layout");
if (css)
// Replace the link for the CSS
$("#xanadoCSS").each(function() {
if (this.href)
this.href = this.href.replace(/\/css\/[^/.]+/, `/css/${css}`);
Expand Down Expand Up @@ -260,7 +262,7 @@ class UI {
// Handle special case of a button that opens a dialog.
// When the dialog closes, a focusin event is sent back
// to the tooltip, that we want to ignore.
if (event.originalEvent.type === "focusin")
if (event.originalEvent && event.originalEvent.type === "focusin")
ui.tooltip.hide();
}
/* c8 ignore stop */
Expand Down Expand Up @@ -338,8 +340,8 @@ class UI {
* @return {Promise} promise that resolves to
* a list of css name strings.
*/
promiseCSS() {
assert.fail("UI.promiseCSS");
promiseLayouts() {
assert.fail("UI.promiseLayouts");
}

/**
Expand Down
31 changes: 14 additions & 17 deletions src/browser/UserSettingsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ class UserSettingsDialog extends Dialog {
createDialog() {
return super.createDialog()
.then(() => {
const curlan = $.i18n.locale();
//console.log("Curlan",curlan);

const ui = this.options.ui;
const $css = this.$dlg.find('[name=xanadoCSS]');
const $layout = this.$dlg.find('[name=layout]');
//const $jqt = this.$dlg.find("[name=jqTheme]");
const $locale = this.$dlg.find('[name=language]');

return Promise.all([ ui.promiseCSS(), ui.promiseLocales() ])
.then(all => {
all[0].forEach(css => $css.append(`<option>${css}</option>`));
all[1]
.filter(d => d !== "qqq")
.sort((a, b) => new RegExp(`^${a}`,"i").test(curlan) ? -1 :
new RegExp(`^${b}`,"i").test(curlan) ? 1 : 0)
.forEach(d => $locale.append(`<option>${d}</option>`));
});
return Promise.all([
ui.promiseLayouts()
.then(layouts => layouts
.forEach(css => $layout.append(`<option>${css}</option>`))),
ui.promiseLocales()
.then(locales => locales
.filter(d => d !== "qqq")
.forEach(lan => $locale.append(`<option>${lan}</option>`)))
]);
});
}

Expand All @@ -53,17 +50,17 @@ class UserSettingsDialog extends Dialog {
.val(ui.getSetting("language"))
.selectmenu("refresh");

this.$dlg.find("select[name=xanadoCSS]")
.val(ui.getSetting('theme'))
this.$dlg.find("select[name=layout]")
.val(ui.getSetting("layout"))
.selectmenu("refresh");

this.$dlg.find("select[name=jqTheme]")
.val(ui.getSetting('jqTheme'))
.val(ui.getSetting("jqTheme"))
.selectmenu("refresh");

this.$dlg.find('input[type=checkbox]')
.each(function() {
$(this).prop('checked', ui.getSetting(this.name) === "true")
$(this).prop("checked", ui.getSetting(this.name) === "true")
.checkboxradio("refresh");
});
// Notification requires https
Expand Down
2 changes: 1 addition & 1 deletion src/browser/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ $.i18n.init = (locale, data_url, dbg) => {
* Get the current locale
* @return { string} the current locale string
*/
$.i18n.locale = () => $.banana.locale;
$.i18n.locale = () => $.banana ? $.banana.locale : undefined;

/**
* jQuery plugin to translate all elements in DOM that have
Expand Down
2 changes: 1 addition & 1 deletion src/client/ClientUIMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const ClientUIMixin = superclass => class extends superclass {
* @memberof CientUIMixin
* @override
*/
promiseCSS() {
promiseLayouts() {
return $.get("/css");
}

Expand Down
13 changes: 8 additions & 5 deletions src/standalone/StandaloneUIMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const DEFAULT_USER_SETTINGS = {
// User settings
one_window: true,
notification: false, // requires https
theme: "default",
layout: "default",
language: "en",
jqTheme: "pepper-grinder",
warnings: true,
cheers: true,
Expand Down Expand Up @@ -120,9 +121,11 @@ const StandaloneUIMixin = superclass => class extends superclass {
if (session === null) {
// null means key does not exist
// see https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem
if (typeof Game.DEFAULTS[key] === "undefined")
if (typeof Game.DEFAULTS[key] === "undefined") {
if (key === "language")
return $.i18n.locale() || DEFAULT_USER_SETTINGS.language;
return DEFAULT_USER_SETTINGS[key];
else
} else
return Game.DEFAULTS[key];
} else
return session;
Expand All @@ -142,12 +145,12 @@ const StandaloneUIMixin = superclass => class extends superclass {
}

/**
* @implements UI#promiseCSS
* @implements UI#promiseLayouts
* @memberof standalone/StandaloneUIMixin
* @instance
* @override
*/
promiseCSS() {
promiseLayouts() {
return Platform.readFile(Platform.getFilePath("css/index.json"));
}

Expand Down
8 changes: 4 additions & 4 deletions test/browser/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("browser/UI", () => {
getSetting(t) {
return this.settings[t];
}
promiseCSS() { return Promise.resolve([ "A", "B" ]); }
promiseLayouts() { return Promise.resolve([ "A", "B" ]); }
promiseLocales() { return Promise.resolve([ "en", "fr" ]); }
};
}));
Expand Down Expand Up @@ -67,11 +67,11 @@ describe("browser/UI", () => {
getSetting(t) {
switch (t) {
case "jqTheme": return "le-frog";
case "xanadoCSS": return "exander77";
case "layout": return "exander77";
default: assert.fail(t); return false;
}
}
promiseCSS() { return Promise.resolve([]); }
promiseLayouts() { return Promise.resolve([]); }
}
(new NUI()).initTheme();
let url = $("#xanadoCSS").attr("href");
Expand Down Expand Up @@ -134,7 +134,7 @@ describe("browser/UI", () => {
assert.fail(t); return false;
}
promiseLocales() { return Promise.resolve([ "en", "fr" ]); }
promiseCSS() { return Promise.resolve([]); }
promiseLayouts() { return Promise.resolve([]); }
}
const ui = new NUI();
return ui.initLocale()
Expand Down
4 changes: 2 additions & 2 deletions test/browser/UserSettingsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("browser/UserSettingsDialog", () => {

const user_settings = {
"language": "en",
"xanadoCSS": "default",
"layout": "default",
"jqTheme": "vader",
"turn_alert": false,
"cheers": false,
Expand All @@ -33,7 +33,7 @@ describe("browser/UserSettingsDialog", () => {
it ("dialog", () => {
const ui = {
session: { key : "session key" },
promiseCSS: () => Promise.resolve(["A", "B"]),
promiseLayouts: () => Promise.resolve(["A", "B"]),
promiseLocales: () => Promise.resolve(["C", "D"]),
getSetting: s => user_settings[s]
};
Expand Down
6 changes: 3 additions & 3 deletions test/client/ClientGameUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe("client/ClientGameUI", () => {
};

const USER_DEFAULTS = {
theme: "default",
layout: "default",
jqTheme: "invader"
};

const session = {
name: "Descartes",
settings: {
"language": "en",
"xanadoCSS": "default",
"layout": "default",
"jqTheme": "vader",
"turn_alert": false,
"cheers": false,
Expand All @@ -44,7 +44,7 @@ describe("client/ClientGameUI", () => {
defaults: {
edition: "Test",
dictionary: "Oxford_5000",
theme: "default"
layout: "default"
},
games: "delayed"
};
Expand Down
7 changes: 3 additions & 4 deletions test/client/ClientGamesUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("client/ClientGamesUI", () => {
};

const USER_DEFAULTS = {
theme: "default",
layout: "default",
jqTheme: "invader"
};

Expand All @@ -33,7 +33,7 @@ describe("client/ClientGamesUI", () => {
key: "human",
settings: {
"language": "en",
"xanadoCSS": "default",
"layout": "default",
"jqTheme": "vader",
"turn_alert": false,
"cheers": false,
Expand Down Expand Up @@ -107,14 +107,13 @@ describe("client/ClientGamesUI", () => {
//debug: console.debug
}))
.then(() => {
console.debug("Logged in");
//console.debug("Logged in");
$("#signout-button").trigger("click");
})
.then(() => expectDialog(
"UserSettingsDialog",
() => $("#personaliseButton").trigger("click")))
.then(() => {
console.debug("USD done");
return expectDialog(
"GameSetupDialog",
() => $("#create-game").trigger("click"));
Expand Down
6 changes: 3 additions & 3 deletions test/client/ClientUIMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("client/ClientUIMixin", () => {
name: "Descartes",
settings: {
"language": "en",
"xanadoCSS": "default",
"layout": "default",
"jqTheme": "vader",
"turn_alert": false,
"cheers": false,
Expand Down Expand Up @@ -67,7 +67,7 @@ describe("client/ClientUIMixin", () => {
};
const USER_DEFAULTS = {
notification: false,
theme: "none",
layout: "none",
jqTheme: "grass"
};
const server = new StubServer({
Expand Down Expand Up @@ -114,7 +114,7 @@ describe("client/ClientUIMixin", () => {
ui.promiseDefaults("user")
.then(s => assert.deepEqual(s, USER_DEFAULTS)),

ui.promiseCSS()
ui.promiseLayouts()
.then(e => assert(Array.isArray(e))),

ui.promiseLocales()
Expand Down
2 changes: 1 addition & 1 deletion test/server/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("server/Server.js", () => {
timePenalty: 0
},
user_defaults: {
theme: "default"
layout: "default"
},
games: "delayed",
html_dir: "html"
Expand Down
2 changes: 1 addition & 1 deletion test/server/UserManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("server/UserManager", () => {
timePenalty: 0
},
user_defaults: {
theme: "default"
layout: "default"
},
html_dir: "html"
};
Expand Down
2 changes: 1 addition & 1 deletion test/standalone/StandaloneUIMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("standalone/StandaloneUIMixin", () => {
it("get...", () => {
const ui = new Test();
return Promise.all([
ui.promiseCSS(),
ui.promiseLayouts(),
Platform.readFile(Platform.getFilePath(`css/index.json`))])
.then(data => assert.deepEqual(data[0], data[1]))

Expand Down

0 comments on commit 0af6661

Please sign in to comment.