log webview
This commit is contained in:
parent
9bace8d8c5
commit
67c653fa8b
@ -1,3 +1,21 @@
|
||||
interface LogArray extends Array<LogEntry>{}
|
||||
|
||||
interface LogEntry {
|
||||
timestamp: string,
|
||||
message_id: number,
|
||||
a: number,
|
||||
b: number,
|
||||
txt_short: string,
|
||||
txt_long: string
|
||||
}
|
||||
|
||||
interface LogLocalisation extends Array<LogLocalisationEntry>{}
|
||||
|
||||
interface LogLocalisationEntry {
|
||||
msg_type: string,
|
||||
message: string
|
||||
}
|
||||
|
||||
interface BackupHeader {
|
||||
timestamp: string,
|
||||
size: number
|
||||
|
@ -171,6 +171,10 @@
|
||||
<button id="exit">Exit</button>
|
||||
<button id="reboot">Reboot</button>
|
||||
|
||||
<div class="flexcontainer">
|
||||
<div id="logview" class="subcontainercontainer"></div>
|
||||
</div>
|
||||
|
||||
<script src="bundle.js"></script>
|
||||
</div>
|
||||
|
||||
|
@ -17,10 +17,33 @@ import { ProgressView } from "./progress";
|
||||
import { OTAView } from "./ota";
|
||||
import { BatteryView } from "./batteryview";
|
||||
import { FileView } from './fileview';
|
||||
import { LogView } from './log';
|
||||
|
||||
export class Controller {
|
||||
getBackupInfo() {
|
||||
fetch(PUBLIC_URL + "/backup_info")
|
||||
loadLogLocaleConfig() {
|
||||
return fetch(PUBLIC_URL + "/log_localization")
|
||||
.then(response => response.json())
|
||||
.then(json => json as LogLocalisation)
|
||||
.then(loglocale => {
|
||||
controller.logView.setLogLocalisation(loglocale)
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
loadLog() {
|
||||
return fetch(PUBLIC_URL + "/log")
|
||||
.then(response => response.json())
|
||||
.then(json => json as LogArray)
|
||||
.then(logs => {
|
||||
controller.logView.setLog(logs)
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
getBackupInfo() : Promise<void> {
|
||||
return fetch(PUBLIC_URL + "/backup_info")
|
||||
.then(response => response.json())
|
||||
.then(json => json as BackupHeader)
|
||||
.then(header => {
|
||||
@ -30,8 +53,8 @@ export class Controller {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
updateFileList() {
|
||||
fetch(PUBLIC_URL + "/files")
|
||||
updateFileList() : Promise<void> {
|
||||
return fetch(PUBLIC_URL + "/files")
|
||||
.then(response => response.json())
|
||||
.then(json => json as FileList)
|
||||
.then(filelist => {
|
||||
@ -90,8 +113,8 @@ export class Controller {
|
||||
controller.updateFileList()
|
||||
}
|
||||
|
||||
updateRTCData() {
|
||||
fetch(PUBLIC_URL + "/time")
|
||||
updateRTCData() : Promise<void> {
|
||||
return fetch(PUBLIC_URL + "/time")
|
||||
.then(response => response.json())
|
||||
.then(json => json as GetTime)
|
||||
.then(time => {
|
||||
@ -102,8 +125,8 @@ export class Controller {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
updateBatteryData() {
|
||||
fetch(PUBLIC_URL + "/battery")
|
||||
updateBatteryData(): Promise<void> {
|
||||
return fetch(PUBLIC_URL + "/battery")
|
||||
.then(response => response.json())
|
||||
.then(json => json as BatteryState)
|
||||
.then(battery => {
|
||||
@ -112,7 +135,7 @@ export class Controller {
|
||||
.catch(error => {
|
||||
controller.batteryView.update(null)
|
||||
console.log(error);
|
||||
});
|
||||
})
|
||||
}
|
||||
uploadNewFirmware(file: File) {
|
||||
var current = 0;
|
||||
@ -139,9 +162,9 @@ export class Controller {
|
||||
ajax.open("POST", PUBLIC_URL + "/ota");
|
||||
ajax.send(file);
|
||||
}
|
||||
version() {
|
||||
version() : Promise<void> {
|
||||
controller.progressview.addIndeterminate("version", "Getting buildVersion")
|
||||
fetch(PUBLIC_URL + "/version")
|
||||
return fetch(PUBLIC_URL + "/version")
|
||||
.then(response => response.json())
|
||||
.then(json => json as VersionInfo)
|
||||
.then(versionInfo => {
|
||||
@ -160,9 +183,9 @@ export class Controller {
|
||||
})
|
||||
}
|
||||
|
||||
downloadConfig() {
|
||||
downloadConfig() :Promise<void> {
|
||||
controller.progressview.addIndeterminate("get_config", "Downloading Config")
|
||||
fetch(PUBLIC_URL + "/get_config")
|
||||
return fetch(PUBLIC_URL + "/get_config")
|
||||
.then(response => response.json())
|
||||
.then(loaded => {
|
||||
var currentConfig = loaded as PlantControllerConfig;
|
||||
@ -399,6 +422,7 @@ export class Controller {
|
||||
readonly progressview: ProgressView;
|
||||
readonly batteryView: BatteryView;
|
||||
readonly fileview: FileView;
|
||||
readonly logView: LogView
|
||||
constructor() {
|
||||
this.timeView = new TimeView(this)
|
||||
this.plantViews = new PlantViews(this)
|
||||
@ -410,6 +434,7 @@ export class Controller {
|
||||
this.firmWareView = new OTAView(this)
|
||||
this.progressview = new ProgressView(this)
|
||||
this.fileview = new FileView(this)
|
||||
this.logView = new LogView(this)
|
||||
this.rebootBtn = document.getElementById("reboot") as HTMLButtonElement
|
||||
this.rebootBtn.onclick = () => {
|
||||
controller.reboot();
|
||||
@ -421,12 +446,31 @@ export class Controller {
|
||||
}
|
||||
}
|
||||
const controller = new Controller();
|
||||
controller.updateRTCData();
|
||||
controller.updateBatteryData();
|
||||
controller.downloadConfig();
|
||||
controller.progressview.removeProgress("rebooting");
|
||||
controller.progressview.addProgress("initial", 0, "read rtc");
|
||||
controller.updateRTCData().then(_ => {
|
||||
controller.progressview.addProgress("initial", 20, "read battery");
|
||||
controller.updateBatteryData().then(_ => {
|
||||
controller.progressview.addProgress("initial", 40, "read config");
|
||||
controller.downloadConfig().then(_ => {
|
||||
controller.progressview.addProgress("initial", 50, "read version");
|
||||
controller.version().then(_ => {
|
||||
controller.progressview.addProgress("initial", 70, "read filelist");
|
||||
controller.updateFileList().then(_ => {
|
||||
controller.progressview.addProgress("initial", 90, "read backupinfo");
|
||||
controller.getBackupInfo().then(_ => {
|
||||
controller.progressview.removeProgress("initial");
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
})
|
||||
;
|
||||
|
||||
//controller.measure_moisture();
|
||||
controller.version();
|
||||
controller.updateFileList();
|
||||
controller.getBackupInfo();
|
||||
|
||||
|
||||
|
||||
controller.progressview.removeProgress("rebooting");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user