From 2c3802444c0874f15bdcad1e09332a129cc4d5bd Mon Sep 17 00:00:00 2001 From: Freist Li Date: Mon, 29 Apr 2024 13:42:56 +0800 Subject: [PATCH] config service url --- src/taskpane/taskpane.css | 11 +++++++++- src/taskpane/taskpane.html | 15 +++++++------ src/taskpane/taskpane.js | 44 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/taskpane/taskpane.css b/src/taskpane/taskpane.css index 7dc6892..fb42e89 100644 --- a/src/taskpane/taskpane.css +++ b/src/taskpane/taskpane.css @@ -85,4 +85,13 @@ b { flex: 1 0 0; width: 90%; height: 230px; - } \ No newline at end of file + } + +#iframe-src{ + margin-bottom: 8px; + margin-left: 8px; + width: 80%; +} +#update-iframe-src { + margin-left: 8px; +} \ No newline at end of file diff --git a/src/taskpane/taskpane.html b/src/taskpane/taskpane.html index 626466f..bf0a980 100644 --- a/src/taskpane/taskpane.html +++ b/src/taskpane/taskpane.html @@ -9,10 +9,7 @@ Contoso Task Pane Add-in - + @@ -55,9 +52,15 @@

Please

- - + +
+
+ +
+ \ No newline at end of file diff --git a/src/taskpane/taskpane.js b/src/taskpane/taskpane.js index f2d3584..378a0dd 100644 --- a/src/taskpane/taskpane.js +++ b/src/taskpane/taskpane.js @@ -7,12 +7,56 @@ import { client } from "@gradio/client"; +function setInLocalStorage(key, value) { + const myPartitionKey = Office.context.partitionKey; + + // Check if local storage is partitioned. + // If so, use the partition to ensure the data is only accessible by your add-in. + if (myPartitionKey) { + localStorage.setItem(myPartitionKey + key, value); + } else { + localStorage.setItem(key, value); + } +} + +function getFromLocalStorage(key) { + const myPartitionKey = Office.context.partitionKey; + + // Check if local storage is partitioned. + if (myPartitionKey) { + return localStorage.getItem(myPartitionKey + key); + } else { + return localStorage.getItem(key); + } +} + + +export async function updateIframeSrc() { + const iframeSrcInput = document.getElementById('iframe-src'); + const iframe = document.getElementById('proofreading-iframe'); + iframe.src = iframeSrcInput.value+"/proofreadaddin/"; + setInLocalStorage("serviceUrl",iframeSrcInput.value); + console.log("Save Service URL:" + iframeSrcInput.value); +} + + Office.onReady((info) => { if (info.host === Office.HostType.Word) { + document.getElementById("sideload-msg").style.display = "none"; document.getElementById("app-body").style.display = "flex"; document.getElementById("run").onclick = run; document.getElementById("Proofreading").onclick = proofreading; + document.getElementById("update-iframe-src").onclick = updateIframeSrc; + + const serviceUrl = getFromLocalStorage("serviceUrl"); + + console.log("Get Stored Service URL:" + serviceUrl); + + if (serviceUrl) { + document.getElementById("iframe-src").value = serviceUrl; + updateIframeSrc(); + } window.addEventListener('message', event => { console.log("gradio posted message arrived");