From a935f871d36ef24ec88207ca77702f366b649553 Mon Sep 17 00:00:00 2001 From: Sebastien DUMETZ Date: Mon, 25 Sep 2023 16:55:59 +0200 Subject: [PATCH] add UI to rename scenes --- source/ui/screens/SceneHistory.ts | 50 +++++++++++++++++++++++++++++-- source/ui/state/strings.ts | 8 +++++ 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/source/ui/screens/SceneHistory.ts b/source/ui/screens/SceneHistory.ts index c6af4768..238a6741 100644 --- a/source/ui/screens/SceneHistory.ts +++ b/source/ui/screens/SceneHistory.ts @@ -12,6 +12,7 @@ import { nothing } from "lit-html"; import i18n from "../state/translate"; import {getLogin} from "../state/auth"; import { navigate } from "../state/router"; +import Modal from "../composants/Modal"; const AccessTypes = [ @@ -163,7 +164,7 @@ class SceneVersion{

${articles.size} article${(1 < articles.size?"s":"")}

${this.t("ui.editScene")} - ${this.t("ui.viewScene")} + ${this.t("ui.viewScene")} ${this.t("ui.downloadScene")}
@@ -175,8 +176,9 @@ class SceneVersion{
${this.renderHistory()}
- ${getLogin()?.isAdministrator? html`
-
+ ${getLogin()?.isAdministrator? html`
+
+
`:null}
`; } @@ -322,4 +324,46 @@ class SceneVersion{ Notification.show(`Failed to remove ${this.scene} : ${e.message}`); }); } + + onRename = ()=>{ + const onRenameSubmit = (ev)=>{ + ev.preventDefault(); + let name = (Modal.Instance.shadowRoot.getElementById("sceneRenameInput") as HTMLInputElement).value; + Modal.close(); + Modal.show({ + header: this.t("ui.renameScene"), + body: html`
`, + }); + fetch(`/api/v1/scenes/${encodeURIComponent(this.scene)}`, { + method:"PATCH", + headers:{"Content-Type":"application/json"}, + body: JSON.stringify({name}) + }).then((r)=>{ + if(r.ok){ + Notification.show("Renamed "+this.scene+" to "+name, "info", 1600); + navigate(this, `/ui/scenes/${encodeURIComponent(name)}/`); + }else{ + throw new Error(`[${r.status}] ${r.statusText}`); + } + }).catch((e)=>{ + console.error(e); + Notification.show(`Failed to rename ${this.scene} : ${e.message}`); + }).finally(()=>{ + setTimeout(()=>{ + Modal.close(); + }, 500); + }); + } + + Modal.show({ + header: this.t("ui.renameScene"), + body: html`
+
+ +
+
`, + buttons: html``, + }); + + } } \ No newline at end of file diff --git a/source/ui/state/strings.ts b/source/ui/state/strings.ts index 95d5bb45..c368e9a8 100644 --- a/source/ui/state/strings.ts +++ b/source/ui/state/strings.ts @@ -183,6 +183,10 @@ export default { fr: "supprimer", en: "delete" }, + rename:{ + fr: "renommer", + en: "rename" + }, alphabet:{ fr: "ordre alphabethique", en: "alphabetical" @@ -202,6 +206,10 @@ export default { downloadScene:{ fr:"Télécharger la scène", en:"Download this scene" + }, + renameScene:{ + fr: "Renommer la scène", + en: "Rename scene" } }, info:{