ui: partial multi msd support

This commit is contained in:
Devaev Maxim 2019-11-08 01:28:42 +03:00
parent 8abe4b1ac9
commit b261c2695c
7 changed files with 104 additions and 35 deletions

View File

@ -188,7 +188,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
del vd["image"]["path"] del vd["image"]["path"]
return { return {
"enabled": False, # FIXME "enabled": True,
"online": bool(self.__state.vd), "online": bool(self.__state.vd),
"busy": self.__state.is_busy(), "busy": self.__state.is_busy(),
"storage": storage, "storage": storage,

View File

@ -104,7 +104,7 @@
</div> </div>
<hr> <hr>
<div class="menu-item-content-text"> <div class="menu-item-content-text">
<table id="stream-auto-resize-box"><tr> <table class="one-line-switch"><tr>
<td>Auto-resize stream:</td> <td>Auto-resize stream:</td>
<td align="right"> <td align="right">
<div class="switch-box"> <div class="switch-box">
@ -203,13 +203,40 @@
<td>Image size:</td> <td>Image size:</td>
<td id="msd-drive-image-size" class="msd-info-value"></td> <td id="msd-drive-image-size" class="msd-info-value"></td>
</tr> </tr>
<tr> <tr class="msd-single-storage msd-feature-disabled">
<td>Storage size:</td> <td>Storage size:</td>
<td id="msd-storage-size" class="msd-info-value"></td> <td id="msd-storage-size" class="msd-info-value"></td>
</tr> </tr>
</table> </table>
<hr> <hr>
<div class="msd-multi-storage msd-feature-disabled">
<div class="menu-item-content-text">
<table class="one-line-switch"><tr>
<td>Emulate CD-ROM drive: <sup><i>otherwise the flash drive</i></sup></td>
<td align="right">
<div class="switch-box msd-cdrom-switch-box">
<input type="checkbox" id="msd-emulate-cdrom-checkbox" class="switch-checkbox" checked />
<label class="switch-label" for="msd-emulate-cdrom-checkbox">
<span class="switch-inner"></span>
<span class="switch"></span>
</label>
</div>
</td>
</tr></table>
</div>
<hr>
</div>
<div class="msd-multi-storage msd-feature-disabled">
<div class="menu-item-content-text">
<div id="msd-storage-progress" class="progress">
<span id="msd-storage-progress-value" class="progress-value"></span>
</div>
</div>
<hr>
</div>
<input type="file" id="msd-select-new-image-file" class="msd-message" /> <input type="file" id="msd-select-new-image-file" class="msd-message" />
<div class="menu-item-content-buttons buttons-row"> <div class="menu-item-content-buttons buttons-row">
<button disabled id="msd-select-new-image-button" class="row50">Upload new image</button> <button disabled id="msd-select-new-image-button" class="row50">Upload new image</button>
@ -231,8 +258,8 @@
</table> </table>
<hr> <hr>
<div class="menu-item-content-text"> <div class="menu-item-content-text">
<div id="msd-progress" class="progress"> <div id="msd-uploading-progress" class="progress">
<span id="msd-progress-value" class="progress-value"></span> <span id="msd-uploading-progress-value" class="progress-value"></span>
</div> </div>
</div> </div>
<hr> <hr>

View File

@ -24,7 +24,7 @@ div#msd-menu {
width: 450px; width: 450px;
} }
div#msd-menu div.msd-message, input.msd-message { div#msd-menu .msd-feature-disabled, div.msd-message, input.msd-message {
display: none; display: none;
} }

View File

@ -66,18 +66,6 @@ div.stream-slider-box {
display: flex; display: flex;
} }
table#stream-auto-resize-box {
width: 100%;
border-collapse: collapse;
}
@media only screen and (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
@supports (-webkit-appearance: none) {
table#stream-auto-resize-box {
margin: 20px 0 20px 0 !important;
}
}
}
div#stream-mouse-buttons { div#stream-mouse-buttons {
display: none; display: none;
} }

View File

@ -119,6 +119,18 @@ ul#menu li div.menu-item-content-text {
font-size: 14px; font-size: 14px;
} }
ul#menu li div.menu-item-content-text table.one-line-switch {
width: 100%;
border-collapse: collapse;
}
@media only screen and (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
@supports (-webkit-appearance: none) {
ul#menu li div.menu-item-content-text table.one-line-switch {
margin: 20px 0 20px 0 !important;
}
}
}
ul#menu li div.menu-item-content button, select { ul#menu li div.menu-item-content button, select {
box-shadow: none; box-shadow: none;
border: none; border: none;

View File

@ -96,3 +96,8 @@ div.switch-box input[type=checkbox].switch-checkbox:checked + label.switch-label
div.switch-box input[type=checkbox].switch-checkbox:checked + label.switch-label span.switch { div.switch-box input[type=checkbox].switch-checkbox:checked + label.switch-label span.switch {
right: 0px; right: 0px;
} }
div.switch-box input[type=checkbox].switch-checkbox:disabled + label.switch-label span.switch {
background: var(--cs-thumb-disabled-bg);
border: var(--border-default-2px);
}

View File

@ -23,7 +23,7 @@
"use strict"; "use strict";
import {tools, $} from "../tools.js"; import {tools, $, $$$} from "../tools.js";
import {wm} from "../wm.js"; import {wm} from "../wm.js";
@ -39,6 +39,8 @@ export function Msd() {
var __init__ = function() { var __init__ = function() {
$("msd-led").title = "Unknown state"; $("msd-led").title = "Unknown state";
tools.setOnClick($("msd-emulate-cdrom-checkbox"), __clickCdromSwitch);
$("msd-select-new-image-file").onchange = __selectNewImageFile; $("msd-select-new-image-file").onchange = __selectNewImageFile;
tools.setOnClick($("msd-select-new-image-button"), () => $("msd-select-new-image-file").click()); tools.setOnClick($("msd-select-new-image-button"), () => $("msd-select-new-image-file").click());
@ -58,6 +60,10 @@ export function Msd() {
__applyState(); __applyState();
}; };
var __clickCdromSwitch = function() {
__sendParam("cdrom", ($("msd-emulate-cdrom-checkbox").checked ? "1" : "0"));
};
var __clickUploadNewImageButton = function() { var __clickUploadNewImageButton = function() {
let form_data = new FormData(); let form_data = new FormData();
form_data.append("image", __image_file.name); form_data.append("image", __image_file.name);
@ -76,8 +82,8 @@ export function Msd() {
__upload_http.upload.onprogress = null; __upload_http.upload.onprogress = null;
__upload_http.abort(); __upload_http.abort();
__upload_http = null; __upload_http = null;
$("msd-progress").setAttribute("data-label", "Aborted"); $("msd-uploading-progress").setAttribute("data-label", "Aborted");
$("msd-progress-value").style.width = "0%"; $("msd-uploading-progress-value").style.width = "0%";
}; };
var __clickConnectButton = function(connect) { var __clickConnectButton = function(connect) {
@ -124,13 +130,15 @@ export function Msd() {
var __applyState = function() { var __applyState = function() {
if (__state) { if (__state) {
if (__state.enabled) { for (let el of $$$(".msd-single-storage")) {
$("msd-dropdown").classList.remove("feature-disabled"); el.classList.toggle("msd-feature-disabled", __state.features.multi);
$("msd-reset-button").classList.remove("feature-disabled");
} else {
$("msd-dropdown").classList.add("feature-disabled");
$("msd-reset-button").classList.add("feature-disabled");
} }
for (let el of $$$(".msd-multi-storage")) {
el.classList.toggle("msd-feature-disabled", !__state.features.multi);
}
$("msd-dropdown").classList.toggle("feature-disabled", !__state.enabled);
$("msd-reset-button").classList.toggle("feature-disabled", !__state.enabled);
if (__state.online && __state.drive.connected) { if (__state.online && __state.drive.connected) {
$("msd-another-another-user-uploads").style.display = "none"; $("msd-another-another-user-uploads").style.display = "none";
@ -160,18 +168,35 @@ export function Msd() {
$("msd-drive-image-name").innerHTML = (__state.online && __state.drive.image ? __state.drive.image.name : "None"); $("msd-drive-image-name").innerHTML = (__state.online && __state.drive.image ? __state.drive.image.name : "None");
$("msd-drive-image-size").innerHTML = (__state.online && __state.drive.image ? __formatSize(__state.drive.image.size) : "None"); $("msd-drive-image-size").innerHTML = (__state.online && __state.drive.image ? __formatSize(__state.drive.image.size) : "None");
$("msd-storage-size").innerHTML = (__state.online ? __formatSize(__state.storage.size) : "Unavailable");
wm.switchDisabled($("msd-connect-button"), (!__state.online || __state.drive.connected || __state.busy)); if (__state.online) {
let size = __state.storage.size;
let used = __state.storage.size - __state.storage.free;
$("msd-storage-size").innerHTML = __formatSize(size);
$("msd-storage-progress").setAttribute("data-label", `Storage: ${__formatSize(used)} of ${__formatSize(size)} used`);
$("msd-storage-progress-value").style.width = `${used / size * 100}%`;
} else {
$("msd-storage-size").innerHTML = "Unavailable";
$("msd-storage-progress").setAttribute("data-label", "Storage: unavailable");
$("msd-storage-progress-value").style.width = "0%";
}
wm.switchDisabled($("msd-emulate-cdrom-checkbox"), (!__state.online || !__state.features.cdrom, __state.drive.connected || __state.busy));
if (__state.features.multi) {
wm.switchDisabled($("msd-connect-button"), (!__state.online || !__state.drive.image || __state.drive.connected || __state.busy));
} else {
wm.switchDisabled($("msd-connect-button"), (!__state.online || __state.drive.connected || __state.busy));
}
wm.switchDisabled($("msd-disconnect-button"), (!__state.online || !__state.drive.connected || __state.busy)); wm.switchDisabled($("msd-disconnect-button"), (!__state.online || !__state.drive.connected || __state.busy));
wm.switchDisabled($("msd-select-new-image-button"), (!__state.online || __state.drive.connected || __state.busy || __upload_http)); wm.switchDisabled($("msd-select-new-image-button"), (!__state.online || __state.drive.connected || __state.busy || __upload_http));
wm.switchDisabled($("msd-upload-new-image-button"), (!__state.online || __state.drive.connected || __state.busy || !__image_file)); wm.switchDisabled($("msd-upload-new-image-button"), (!__state.online || __state.drive.connected || __state.busy || !__image_file));
wm.switchDisabled($("msd-abort-uploading-button"), (!__state.online || !__upload_http)); wm.switchDisabled($("msd-abort-uploading-button"), (!__state.online || !__upload_http));
wm.switchDisabled($("msd-reset-button"), (!__state.enabled || __state.busy)); wm.switchDisabled($("msd-reset-button"), (!__state.enabled || __state.busy));
$("msd-emulate-cdrom-checkbox").checked = (__state.online && __state.features.cdrom && __state.drive.cdrom);
$("msd-new-image").style.display = (__image_file ? "block" : "none"); $("msd-new-image").style.display = (__image_file ? "block" : "none");
$("msd-progress").setAttribute("data-label", "Waiting for upload ..."); $("msd-uploading-progress").setAttribute("data-label", "Waiting for upload ...");
$("msd-progress-value").style.width = "0%"; $("msd-uploading-progress-value").style.width = "0%";
$("msd-new-image-name").innerHTML = (__image_file ? __image_file.name : ""); $("msd-new-image-name").innerHTML = (__image_file ? __image_file.name : "");
$("msd-new-image-size").innerHTML = (__image_file ? __formatSize(__image_file.size) : ""); $("msd-new-image-size").innerHTML = (__image_file ? __formatSize(__image_file.size) : "");
@ -186,6 +211,7 @@ export function Msd() {
$("msd-drive-image-size").innerHTML = ""; $("msd-drive-image-size").innerHTML = "";
$("msd-storage-size").innerHTML = ""; $("msd-storage-size").innerHTML = "";
wm.switchDisabled($("msd-emulate-cdrom-checkbox"), true);
wm.switchDisabled($("msd-connect-button"), true); wm.switchDisabled($("msd-connect-button"), true);
wm.switchDisabled($("msd-disconnect-button"), true); wm.switchDisabled($("msd-disconnect-button"), true);
wm.switchDisabled($("msd-select-new-image-button"), true); wm.switchDisabled($("msd-select-new-image-button"), true);
@ -193,10 +219,11 @@ export function Msd() {
wm.switchDisabled($("msd-abort-uploading-button"), true); wm.switchDisabled($("msd-abort-uploading-button"), true);
wm.switchDisabled($("msd-reset-button"), true); wm.switchDisabled($("msd-reset-button"), true);
$("msd-emulate-cdrom-checkbox").checked = false;
$("msd-select-new-image-file").value = ""; $("msd-select-new-image-file").value = "";
$("msd-new-image").style.display = "none"; $("msd-new-image").style.display = "none";
$("msd-progress").setAttribute("data-label", ""); $("msd-uploading-progress").setAttribute("data-label", "");
$("msd-progress-value").style.width = "0%"; $("msd-uploading-progress-value").style.width = "0%";
$("msd-new-image-name").innerHTML = ""; $("msd-new-image-name").innerHTML = "";
$("msd-new-image-size").innerHTML = ""; $("msd-new-image-size").innerHTML = "";
} }
@ -226,10 +253,20 @@ export function Msd() {
var __uploadProgress = function(event) { var __uploadProgress = function(event) {
if(event.lengthComputable) { if(event.lengthComputable) {
let percent = Math.round((event.loaded * 100) / event.total); let percent = Math.round((event.loaded * 100) / event.total);
$("msd-progress").setAttribute("data-label", percent + "%"); $("msd-uploading-progress").setAttribute("data-label", percent + "%");
$("msd-progress-value").style.width = percent + "%"; $("msd-uploading-progress-value").style.width = percent + "%";
} }
}; };
var __sendParam = function(name, value) {
let http = tools.makeRequest("POST", `/api/msd/set_params?${name}=${value}`, function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("Can't configure MSD:<br>", http.responseText);
}
}
});
};
__init__(); __init__();
} }