Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DGT board Play Menu shortcut configurable #15044

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions app/controllers/DgtCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ final class DgtCtrl(env: Env) extends LilaController(env):
findToken.map(views.dgt.config)
}

def menuShortcut = Auth { ctx ?=> me ?=>
ctx.req
.getQueryString("include")
.map(_ match
case "true" => true
case "false" => false
) match
case Some(bool) => env.pref.api.saveTag(me, _.dgt, bool) >> Ok
case None => BadRequest
}

def generateToken = Auth { _ ?=> me ?=>
findToken.flatMap: t =>
t.isEmpty
.so {
env.oAuth.tokenApi.create(
lila.oauth.OAuthTokenForm.Data(
description = "DGT board automatic token",
scopes = dgtScopes.value.map(_.key)
),
isStudent = false
) >>
env.pref.api.saveTag(me, _.dgt, true)
env.oAuth.tokenApi
.create(
lila.oauth.OAuthTokenForm.Data(
description = "DGT board automatic token",
scopes = dgtScopes.value.map(_.key)
),
isStudent = false
)
.void
}
.inject(Redirect(routes.DgtCtrl.config))
}
Expand All @@ -34,7 +46,6 @@ final class DgtCtrl(env: Env) extends LilaController(env):
findToken.flatMap:
case None => Redirect(routes.DgtCtrl.config)
case Some(t) =>
if !ctx.pref.hasDgt then env.pref.api.saveTag(me, _.dgt, true)
Ok.page(views.dgt.play(t))
}

Expand Down
22 changes: 12 additions & 10 deletions app/views/dgt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ def config(token: Option[lila.oauth.AccessToken])(using PageContext) =
h2(lichessConnectivity()),
if token.isDefined then
p(cls := "text", dataIcon := Icon.Checkmark)(
validDgtOauthToken(),
br,
br,
dgtPlayMenuEntryAdded(
strong(dgtBoard())
)
validDgtOauthToken()
)
else
frag(
Expand Down Expand Up @@ -167,7 +162,7 @@ def config(token: Option[lila.oauth.AccessToken])(using PageContext) =
}
),
st.section(
h2(debug()),
h2(misc()),
div(cls := "form-group")(
st.label(cls := "form-label")(verboseLogging()),
radios(
Expand All @@ -177,9 +172,16 @@ def config(token: Option[lila.oauth.AccessToken])(using PageContext) =
st.small(cls := "form-help")(
toSeeConsoleMessage()
)
)
),
form3.submit(trans.site.save())
),
div(cls := "form-group")(
st.label(cls := "form-label")(menuShortcut()),
radios(
"dgt-menu-shortcut",
List((false, trans.site.no.txt()), (true, trans.site.yes.txt()))
)
),
form3.submit(trans.site.save())
)
)
)

Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ GET /dgt controllers.DgtCtrl.index
GET /dgt/play controllers.DgtCtrl.play
GET /dgt/config controllers.DgtCtrl.config
POST /dgt/config/token controllers.DgtCtrl.generateToken
POST /dgt/config/menu-shortcut controllers.DgtCtrl.menuShortcut

POST /jslog/$id<\w{12}> controllers.Main.jslog(id)

Expand Down
4 changes: 2 additions & 2 deletions modules/coreI18n/src/main/key.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,6 @@ object I18nKey:
val `dgtConfigure`: I18nKey = "dgt:dgtConfigure"
val `lichessConnectivity`: I18nKey = "dgt:lichessConnectivity"
val `validDgtOauthToken`: I18nKey = "dgt:validDgtOauthToken"
val `dgtPlayMenuEntryAdded`: I18nKey = "dgt:dgtPlayMenuEntryAdded"
val `noSuitableOauthToken`: I18nKey = "dgt:noSuitableOauthToken"
val `dgtBoardConnectivity`: I18nKey = "dgt:dgtBoardConnectivity"
val `clickToGenerateOne`: I18nKey = "dgt:clickToGenerateOne"
Expand All @@ -2680,9 +2679,10 @@ object I18nKey:
val `moveFormatDescription`: I18nKey = "dgt:moveFormatDescription"
val `keywords`: I18nKey = "dgt:keywords"
val `keywordFormatDescription`: I18nKey = "dgt:keywordFormatDescription"
val `debug`: I18nKey = "dgt:debug"
val `misc`: I18nKey = "dgt:misc"
val `verboseLogging`: I18nKey = "dgt:verboseLogging"
val `toSeeConsoleMessage`: I18nKey = "dgt:toSeeConsoleMessage"
val `menuShortcut`: I18nKey = "dgt:menuShortcut"
val `playWithDgtBoard`: I18nKey = "dgt:playWithDgtBoard"
val `configure`: I18nKey = "dgt:configure"

Expand Down
4 changes: 2 additions & 2 deletions translation/source/dgt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<string name="dgtConfigure">DGT - Configure</string>
<string name="lichessConnectivity">Lichess connectivity</string>
<string name="validDgtOauthToken">You have an OAuth token suitable for DGT play.</string>
<string name="dgtPlayMenuEntryAdded">A %s entry was added to your PLAY menu at the top.</string>
<string name="noSuitableOauthToken">No suitable OAuth token has been created.</string>
<string name="dgtBoardConnectivity">DGT board connectivity</string>
<string name="clickToGenerateOne">Click to generate one</string>
Expand All @@ -39,9 +38,10 @@
<string name="moveFormatDescription">SAN is the standard on Lichess like "Nf6". UCI is common on engines like "g8f6".</string>
<string name="keywords">Keywords</string>
<string name="keywordFormatDescription">Keywords are in JSON format. They are used to translate moves and results into your language. Default is English, but feel free to change it.</string>
<string name="debug">Debug</string>
<string name="misc">Miscellaneous</string>
<string name="verboseLogging">Verbose logging</string>
<string name="toSeeConsoleMessage">To see console message press Command + Option + C (Mac) or Control + Shift + C (Windows, Linux, Chrome OS)</string>
<string name="menuShortcut">Include Play Menu shortcut</string>
<string name="playWithDgtBoard">Play with a DGT board</string>
<string name="configure">Configure</string>
</resources>
11 changes: 10 additions & 1 deletion ui/dgt/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function () {
['dgt-speech-announce-all-moves', 'true'],
['dgt-speech-announce-move-format', 'san'],
['dgt-verbose', 'false'],
['dgt-menu-shortcut', 'false'],
].forEach(([k, v]) => {
if (!localStorage.getItem(k)) localStorage.setItem(k, v);
});
Expand All @@ -54,7 +55,7 @@ export default function () {
['dgt-livechess-url', 'dgt-speech-keywords'].forEach(k => {
form[k].value = localStorage.getItem(k);
});
['dgt-speech-synthesis', 'dgt-speech-announce-all-moves', 'dgt-verbose'].forEach(k =>
['dgt-speech-synthesis', 'dgt-speech-announce-all-moves', 'dgt-verbose', 'dgt-menu-shortcut'].forEach(k =>
[true, false].forEach(v => {
const input = document.getElementById(`${k}_${v}`) as HTMLInputElement;
input.checked = localStorage.getItem(k) == '' + v;
Expand All @@ -73,6 +74,14 @@ export default function () {

form.addEventListener('submit', (e: Event) => {
e.preventDefault();
const menuStorage: string = '' + localStorage.getItem('dgt-menu-shortcut');
const menuForm: string = form['dgt-menu-shortcut'].value;
if (menuStorage != menuForm) {
const req = new XMLHttpRequest();
req.addEventListener('load', () => window.location.reload());
req.open('POST', '/dgt/config/menu-shortcut?include=' + menuForm);
req.send();
}
Array.from(new FormData(form).entries()).forEach(([k, v]) => localStorage.setItem(k, v.toString()));
});
}
Expand Down
Loading