Skip to content

Commit

Permalink
add waiting animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanguage committed Sep 21, 2023
1 parent 05b48b9 commit d8addc0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
74 changes: 66 additions & 8 deletions public/plugins/bioengine-test-run.imjoy.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
class ImJoyPlugin {
async setup() {
console.log("setup")
this.setFileInputDisabled(true)
this.setButtonDisabled("url-load-button", true)
this.setButtonDisabled("submit-button", true)
this.setButtonDisabled("sample-input-button", true)
this.setButtonDisabled("sample-output-button", true)
this.setInfoPanel("Loading model RDF...")
this.setWaiting(true)
this.core_plugin = await api.loadPlugin(await api.getAttachment("bioengine-runner"))
this.setupEvents()
}
Expand All @@ -49,7 +56,7 @@
const viewImageByBytes = this.viewImageByBytes.bind(this)

fileInput.addEventListener("input", async () => {
setInfoPanel("Loading file...")
setInfoPanel("Loading file...", true)
const file = fileInput.files[0]
fileChosen.textContent = file.name
if (!file) {
Expand Down Expand Up @@ -79,7 +86,7 @@
await api.alert("No URL provided")
return
}
setInfoPanel("Loading image...")
setInfoPanel("Loading image...", true)
await viewImageByURL(url)
setInfoPanel("")
})
Expand All @@ -89,7 +96,7 @@
const sampleInputButton = document.getElementById("sample-input-button")
sampleInputButton.addEventListener("click", async () => {
const sampleInput = this.model_rdf.sample_inputs[0]
setInfoPanel("Loading sample input...")
setInfoPanel("Loading sample input...", true)
await this.viewImageByURL(sampleInput)
setInfoPanel("")
})
Expand All @@ -99,7 +106,7 @@
const sampleOutputButton = document.getElementById("sample-output-button")
sampleOutputButton.addEventListener("click", async () => {
const sampleOutput = this.model_rdf.sample_outputs[0]
setInfoPanel("Loading sample output...")
setInfoPanel("Loading sample output...", true)
await this.viewImageByURL(sampleOutput)
setInfoPanel("")
})
Expand All @@ -113,7 +120,7 @@
submitButton.addEventListener("click", async () => {
const input_axes = inputAxes.value || null
console.log("Input axes:", input_axes)
setInfoPanel("Running model...")
setInfoPanel("Running model...", true)
const ret = await core.run_model(
self.model_id, self.model_rdf, input_axes
)
Expand Down Expand Up @@ -146,9 +153,10 @@
urlInput.value = sampleInput
}

setInfoPanel(content) {
setInfoPanel(content, waiting = false) {
const info = document.getElementById("info-panel")
info.textContent = content
this.setWaiting(waiting)
}

async updateImageShapePanel() {
Expand All @@ -157,6 +165,40 @@
imgShapePanel.textContent = `Current image shape: ${shape}`
}

setButtonDisabled(buttonId, disabled) {
const button = document.getElementById(buttonId)
button.disabled = disabled
if (disabled) {
button.classList.add("bg-gray-300")
button.classList.add("hover:bg-gray-300")
} else {
button.classList.remove("bg-gray-300")
button.classList.remove("hover:bg-gray-300")
}
}

setFileInputDisabled(disabled) {
const fileInput = document.getElementById("file-input")
const label = document.getElementById("file-input-label")
fileInput.disabled = disabled
if (disabled) {
label.classList.add("bg-gray-300")
label.classList.add("hover:bg-gray-300")
} else {
label.classList.remove("bg-gray-300")
label.classList.remove("hover:bg-gray-300")
}
}

setWaiting(waiting) {
const waitAnimation = document.getElementById("wait-animation")
if (waiting) {
waitAnimation.style.display = "inline-block"
} else {
waitAnimation.style.display = "none"
}
}

async run(ctx) {
console.log("run", ctx)
const defaultModel = "10.5281/zenodo.5874741"
Expand All @@ -169,6 +211,13 @@
console.log(rdf)
this.model_rdf = rdf
const sampleInput = rdf.sample_inputs[0]
this.setInfoPanel("")
this.setWaiting(false)
this.setFileInputDisabled(false)
this.setButtonDisabled("url-load-button", false)
this.setButtonDisabled("submit-button", false)
this.setButtonDisabled("sample-input-button", false)
this.setButtonDisabled("sample-output-button", false)
this.set_default_url(sampleInput)
}
}
Expand All @@ -181,7 +230,7 @@
<p class="mt-2">Load an PNG, JPG or TIFF file:</p>
<div class="flex">
<span id="file-chosen" class="w-1/2 px-4 py-2 border border-gray-300 rounded-l-md text-gray-500">No file selected.</span>
<label for="file-input" class="py-2 px-3 bg-blue-500 text-white rounded-r-md cursor-pointer w-20 text-center hover:bg-blue-600">
<label id="file-input-label" for="file-input" class="py-2 px-3 bg-blue-500 text-white rounded-r-md cursor-pointer w-20 text-center hover:bg-blue-600">
Browse
</label>
<input type="file" id="file-input" class="hidden" />
Expand All @@ -202,7 +251,16 @@
placeholder="Input axes"
id="input-axes-input" />

<p class="mt-2 text-gray-500 text-sm" id="info-panel"></p>
<div id="info" class="mt-2">
<div id="wait-animation" role="status" style="display: none">
<svg aria-hidden="true" class="w-4 h-4 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
</svg>
<span class="sr-only">Loading...</span>
</div>
<p class="text-gray-500 text-sm" style="display: inline-block" id="info-panel"></p>
</div>
<p class="mt-2 text-gray-500 text-sm" id="img-shape-panel"></p>

<div class="flex flex-row gap-4 mt-2">
Expand Down
2 changes: 1 addition & 1 deletion src/components/ResourceItemInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ api.createWindow({
display: none;
}
#test-run-form {
height: 300px;
height: 340px;
}
#image_output_window:empty {
display: none;
Expand Down

0 comments on commit d8addc0

Please sign in to comment.