cleanups
This commit is contained in:
74
Software/MainBoard/rust/src_webpack/src/submitView.ts
Normal file
74
Software/MainBoard/rust/src_webpack/src/submitView.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import {Controller} from "./main";
|
||||
import {BackupHeader} from "./api";
|
||||
|
||||
export class SubmitView {
|
||||
json: HTMLDivElement;
|
||||
submitFormBtn: HTMLButtonElement;
|
||||
submit_status: HTMLElement;
|
||||
backupBtn: HTMLButtonElement;
|
||||
restoreBackupBtn: HTMLButtonElement;
|
||||
backuptimestamp: HTMLElement;
|
||||
backupsize: HTMLElement;
|
||||
backupjson: HTMLElement;
|
||||
|
||||
constructor(controller: Controller) {
|
||||
(document.getElementById("submitview") as HTMLElement).innerHTML = require("./submitview.html")
|
||||
|
||||
let showJson = document.getElementById('showJson') as HTMLButtonElement
|
||||
let rawdata = document.getElementById('rawdata') as HTMLElement
|
||||
this.json = document.getElementById('json') as HTMLDivElement
|
||||
this.backupjson = document.getElementById('backupjson') as HTMLDivElement
|
||||
this.submitFormBtn = document.getElementById("submit") as HTMLButtonElement
|
||||
this.backupBtn = document.getElementById("backup") as HTMLButtonElement
|
||||
this.restoreBackupBtn = document.getElementById("restorebackup") as HTMLButtonElement
|
||||
this.backuptimestamp = document.getElementById("backuptimestamp") as HTMLElement
|
||||
this.backupsize = document.getElementById("backupsize") as HTMLElement
|
||||
this.submit_status = document.getElementById("submit_status") as HTMLElement
|
||||
this.submitFormBtn.onclick = () => {
|
||||
controller.uploadConfig(this.json.textContent as string, (status: string) => {
|
||||
if (status != "OK") {
|
||||
// Show error toast (click to dismiss only)
|
||||
const { toast } = require('./toast');
|
||||
toast.error(status);
|
||||
} else {
|
||||
// Show info toast (auto hides after 5s, or click to dismiss sooner)
|
||||
const { toast } = require('./toast');
|
||||
toast.info('Config uploaded successfully');
|
||||
}
|
||||
this.submit_status.innerHTML = status;
|
||||
});
|
||||
}
|
||||
this.backupBtn.onclick = () => {
|
||||
controller.progressview.addIndeterminate("backup", "Backup to EEPROM running")
|
||||
controller.backupConfig(this.json.textContent as string).then(saveStatus => {
|
||||
controller.getBackupInfo().then(r => {
|
||||
controller.progressview.removeProgress("backup")
|
||||
this.submit_status.innerHTML = saveStatus;
|
||||
});
|
||||
});
|
||||
}
|
||||
this.restoreBackupBtn.onclick = () => {
|
||||
controller.getBackupConfig();
|
||||
}
|
||||
showJson.onclick = () => {
|
||||
if (rawdata.style.display == "none") {
|
||||
rawdata.style.display = "flex";
|
||||
} else {
|
||||
rawdata.style.display = "none";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setBackupInfo(header: BackupHeader) {
|
||||
this.backuptimestamp.innerText = header.timestamp
|
||||
this.backupsize.innerText = header.size.toString()
|
||||
}
|
||||
|
||||
setJson(pretty: string) {
|
||||
this.json.textContent = pretty
|
||||
}
|
||||
|
||||
setBackupJson(pretty: string) {
|
||||
this.backupjson.textContent = pretty
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user