better handling of result visibility

This commit is contained in:
andreas 2023-09-07 20:43:55 +02:00
parent 54693e0b27
commit e8c6a72a43
4 changed files with 46 additions and 10 deletions

View File

@ -9,9 +9,11 @@
<body>
<div class="configui container">
<h1>Build your own ESP32-NMEA2000</h1>
<h3>New Build</h3>
<div class="row">
<span class="label">Board type</span>
<input type="text" id="environment" value="m5stack-atom-generic">
<select id="environment" value="m5stack-atom-generic">
</select>
</div>
<div class="row">
<span class="label">Build Flags</span>
@ -20,6 +22,7 @@
<div class="row">
<button id="start">Start</button>
</div>
<h3>Last Build</h3>
<div class="row">
<span class="label">Job Id</span>
<div id="pipeline">---</div>

View File

@ -1,4 +1,4 @@
import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enableEl, setValues } from "./helper";
import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enableEl, setValues, getParam, fillSelect, forEachEl } from "./helper.js";
(function(){
const STATUS_INTERVAL=2000;
const CURRENT_PIPELINE='pipeline';
@ -6,6 +6,8 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
let currentPipeline=undefined;
let downloadUrl=undefined;
let timer=undefined;
let branch=getParam('branch');
if (! branch) branch='master';
const showError=(text)=>{
if (text === undefined){
setVisible('buildError',false,true);
@ -14,12 +16,21 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
setValue('buildError',text);
setVisible('buildError',true,true);
}
const hideResults = () => {
downloadUrl = undefined;
currentPipeline = undefined;
setValue('pipeline', currentPipeline);
setValue('status','');
showError();
setVisible('download', false, true);
setVisible('status_url', false, true);
}
const setRunning=(active)=>{
if (active){
downloadUrl=undefined;
showError();
setVisible('download',false,true);
setVisible('status_url',false,true);
downloadUrl=undefined;
setVisible('download', false, true);
setVisible('status_url', false, true);
}
enableEl('start',!active);
}
@ -68,12 +79,13 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
window.localStorage.setItem(CURRENT_PIPELINE,pipeline);
};
const startBuild=()=>{
let param={};
let param={'branch':branch};
currentPipeline=undefined;
if (timer) window.clearTimeout(timer);
timer=undefined;
fillValues(param,['environment','buildflags']);
setValue('status','requested');
setValue('pipeline','');
setRunning(true);
fetchJson(API,Object.assign({
api:'start'},param))
@ -111,13 +123,21 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
download:runDownload,
webinstall:webInstall
};
const environments=[
'm5stack-atom-generic',
'm5stack-atoms3-generic',
'nodemcu-generic'
];
window.onload=()=>{
setButtons(btConfig);
forEachEl('#environment',(el)=>el.addEventListener('change',hideResults));
forEachEl('#buildflags',(el)=>el.addEventListener('change',hideResults));
fillSelect('environment',environments);
currentPipeline=window.localStorage.getItem(CURRENT_PIPELINE);
if (currentPipeline){
setValue('pipeline',currentPipeline);
setRunning(true);
fetchStatus(true);
setRunning(true);
}
}
})();

View File

@ -108,5 +108,16 @@ const enableEl=(id,en)=>{
if (en) el.disabled=false;
else el.disabled=true;
}
const fillSelect=(el,values)=>{
if (typeof(el) !== 'object') el=document.getElementById(el);
if (! el) return;
el.textContent='';
let kf=(values instanceof Array)?(k)=>values[k]:(k)=>k;
for (let k in values){
let o=addEl('option','',el);
o.setAttribute('value',kf(k));
o.textContent=values[k];
}
}
export { getParam, addEl, forEachEl,setButtons,fillValues, setValue,setValues,buildUrl,fetchJson,setVisible, enableEl }
export { getParam, addEl, forEachEl,setButtons,fillValues, setValue,setValues,buildUrl,fetchJson,setVisible, enableEl,fillSelect }

View File

@ -13,8 +13,8 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
const NAMEOFFSET = 48;
const CHIPOFFSET=NAMEOFFSET+64;
const MINSIZE = HDROFFSET + CHIPOFFSET + 32;
const imageMagic=0xe9; //at byte 0
const imageCheckBytes = {
0: 0xe9, //image magic
288: 0x32, //app header magic
289: 0x54,
290: 0xcd,
@ -25,7 +25,6 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
length--;
}
if (length <= 0) return "";
let decoder = new TextDecoder();
return buffer.substr(start,length);
}
/**
@ -38,6 +37,9 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
if (content.length < (MINSIZE+startOffset)) {
throw new Error(prfx+"image to small, only " + content.length + " expected " + (MINSIZE+startOffset));
}
if (content.charCodeAt(0) != imageMagic){
throw new Error("no image magic "+imageMagic+" at start of "+prfx+"image");
}
for (let idx in imageCheckBytes) {
let cb=content.charCodeAt(parseInt(idx)+startOffset);
if (cb != imageCheckBytes[idx]) {