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> <body>
<div class="configui container"> <div class="configui container">
<h1>Build your own ESP32-NMEA2000</h1> <h1>Build your own ESP32-NMEA2000</h1>
<h3>New Build</h3>
<div class="row"> <div class="row">
<span class="label">Board type</span> <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>
<div class="row"> <div class="row">
<span class="label">Build Flags</span> <span class="label">Build Flags</span>
@ -20,6 +22,7 @@
<div class="row"> <div class="row">
<button id="start">Start</button> <button id="start">Start</button>
</div> </div>
<h3>Last Build</h3>
<div class="row"> <div class="row">
<span class="label">Job Id</span> <span class="label">Job Id</span>
<div id="pipeline">---</div> <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(){ (function(){
const STATUS_INTERVAL=2000; const STATUS_INTERVAL=2000;
const CURRENT_PIPELINE='pipeline'; const CURRENT_PIPELINE='pipeline';
@ -6,6 +6,8 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
let currentPipeline=undefined; let currentPipeline=undefined;
let downloadUrl=undefined; let downloadUrl=undefined;
let timer=undefined; let timer=undefined;
let branch=getParam('branch');
if (! branch) branch='master';
const showError=(text)=>{ const showError=(text)=>{
if (text === undefined){ if (text === undefined){
setVisible('buildError',false,true); setVisible('buildError',false,true);
@ -14,12 +16,21 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
setValue('buildError',text); setValue('buildError',text);
setVisible('buildError',true,true); 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)=>{ const setRunning=(active)=>{
if (active){ if (active){
downloadUrl=undefined;
showError(); showError();
setVisible('download',false,true); downloadUrl=undefined;
setVisible('status_url',false,true); setVisible('download', false, true);
setVisible('status_url', false, true);
} }
enableEl('start',!active); enableEl('start',!active);
} }
@ -68,12 +79,13 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
window.localStorage.setItem(CURRENT_PIPELINE,pipeline); window.localStorage.setItem(CURRENT_PIPELINE,pipeline);
}; };
const startBuild=()=>{ const startBuild=()=>{
let param={}; let param={'branch':branch};
currentPipeline=undefined; currentPipeline=undefined;
if (timer) window.clearTimeout(timer); if (timer) window.clearTimeout(timer);
timer=undefined; timer=undefined;
fillValues(param,['environment','buildflags']); fillValues(param,['environment','buildflags']);
setValue('status','requested'); setValue('status','requested');
setValue('pipeline','');
setRunning(true); setRunning(true);
fetchJson(API,Object.assign({ fetchJson(API,Object.assign({
api:'start'},param)) api:'start'},param))
@ -111,13 +123,21 @@ import { setButtons,fillValues, setValue, buildUrl, fetchJson, setVisible, enabl
download:runDownload, download:runDownload,
webinstall:webInstall webinstall:webInstall
}; };
const environments=[
'm5stack-atom-generic',
'm5stack-atoms3-generic',
'nodemcu-generic'
];
window.onload=()=>{ window.onload=()=>{
setButtons(btConfig); 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); currentPipeline=window.localStorage.getItem(CURRENT_PIPELINE);
if (currentPipeline){ if (currentPipeline){
setValue('pipeline',currentPipeline); setValue('pipeline',currentPipeline);
setRunning(true);
fetchStatus(true); fetchStatus(true);
setRunning(true);
} }
} }
})(); })();

View File

@ -108,5 +108,16 @@ const enableEl=(id,en)=>{
if (en) el.disabled=false; if (en) el.disabled=false;
else el.disabled=true; 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 NAMEOFFSET = 48;
const CHIPOFFSET=NAMEOFFSET+64; const CHIPOFFSET=NAMEOFFSET+64;
const MINSIZE = HDROFFSET + CHIPOFFSET + 32; const MINSIZE = HDROFFSET + CHIPOFFSET + 32;
const imageMagic=0xe9; //at byte 0
const imageCheckBytes = { const imageCheckBytes = {
0: 0xe9, //image magic
288: 0x32, //app header magic 288: 0x32, //app header magic
289: 0x54, 289: 0x54,
290: 0xcd, 290: 0xcd,
@ -25,7 +25,6 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
length--; length--;
} }
if (length <= 0) return ""; if (length <= 0) return "";
let decoder = new TextDecoder();
return buffer.substr(start,length); 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)) { if (content.length < (MINSIZE+startOffset)) {
throw new Error(prfx+"image to small, only " + content.length + " expected " + (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) { for (let idx in imageCheckBytes) {
let cb=content.charCodeAt(parseInt(idx)+startOffset); let cb=content.charCodeAt(parseInt(idx)+startOffset);
if (cb != imageCheckBytes[idx]) { if (cb != imageCheckBytes[idx]) {