1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-15 15:03:07 +01:00

intermediate: prepare custom install in webinstaller

This commit is contained in:
andreas
2023-09-06 12:22:33 +02:00
parent 0e0be14415
commit a9396798ce
7 changed files with 283 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enableEl } from "./helper";
import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enableEl, setValues } from "./helper";
(function(){
const STATUS_INTERVAL=2000;
const CURRENT_PIPELINE='pipeline';
@@ -6,37 +6,56 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
let currentPipeline=undefined;
let downloadUrl=undefined;
let timer=undefined;
const fetchStatus=()=>{
const showError=(text)=>{
if (text === undefined){
setVisible('buildError',false,true);
return;
}
setValue('buildError',text);
setVisible('buildError',true,true);
}
const setRunning=(active)=>{
if (active){
downloadUrl=undefined;
showError();
setVisible('download',false,true);
setVisible('status_url',false,true);
}
enableEl('start',!active);
}
const fetchStatus=(initial)=>{
if (currentPipeline === undefined) return;
fetchJson(API,{api:'status',pipeline:currentPipeline})
.then((st)=>{
setValue('status',st.status);
let l=document.getElementById('link');
if (l){
if (st.status_url){
l.setAttribute('href',st.status_url);
setVisible(l.parentElement,true);
}
else{
setVisible(l.parentElement,false);
}
setValues(st);
setVisible('status_url',st.status_url !== undefined,true);
setVisible('error',st.error !== undefined,true);
if (st.status === 'error'){
setRunning(false);
setVisible('download',false,true);
return;
}
if (st.status === 'success'){
enableEl('start',true);
setRunning(false);
fetchJson(API,{api:'artifacts',pipeline:currentPipeline})
.then((ar)=>{
if (! ar.items || ar.items.length < 1){
throw new Error("no download link");
}
downloadUrl=ar.items[0].url;
setVisible(document.getElementById('download'),true,true);
downloadUrl=buildUrl(API,{
download: currentPipeline
});
setVisible('download',true,true);
})
.catch((err)=>alert("Unable to get build result: "+err));
.catch((err)=>{
showError("Unable to get build result: "+err);
setVisible('download',false,true);
});
return;
}
else{
setVisible(document.getElementById('download'),false,true);
setVisible('download',false,true);
}
timer=window.setTimeout(fetchStatus,STATUS_INTERVAL)
})
@@ -55,6 +74,7 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
timer=undefined;
fillValues(param,['environment','buildflags']);
setValue('status','requested');
setRunning(true);
fetchJson(API,Object.assign({
api:'start'},param))
.then((json)=>{
@@ -65,13 +85,12 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
setCurrentPipeline(json.id);
setValue('pipeline',currentPipeline);
setValue('status',json.status);
enableEl('start',false);
timer=window.setTimeout(fetchStatus,STATUS_INTERVAL);
})
.catch((err)=>{
setRunning(false);
setValue('status','error');
enableEl('start',true);
alert(err);
showError(err);
});
}
const runDownload=()=>{
@@ -82,17 +101,23 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
df.setAttribute('src',downloadUrl);
}
}
const webInstall=()=>{
if (! downloadUrl) return;
let url=buildUrl("install.html",{custom:downloadUrl});
window.location.href=url;
}
const btConfig={
start:startBuild,
download:runDownload
download:runDownload,
webinstall:webInstall
};
window.onload=()=>{
setButtons(btConfig);
currentPipeline=window.localStorage.getItem(CURRENT_PIPELINE);
if (currentPipeline){
setValue('pipeline',currentPipeline);
enableEl('start',false);
fetchStatus();
setRunning(true);
fetchStatus(true);
}
}
})();