correctly handle start button enable/disable for cibuild
This commit is contained in:
parent
0561223327
commit
0574e8b47b
|
@ -14,12 +14,11 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
let structure=undefined;
|
let structure=undefined;
|
||||||
let config={}; //values as read and stored
|
let config={}; //values as read and stored
|
||||||
let configStruct={}; //complete struct merged of config and struct
|
let configStruct={}; //complete struct merged of config and struct
|
||||||
let branch=getParam('branch');
|
|
||||||
let displayMode='last';
|
let displayMode='last';
|
||||||
let delayedSearch=undefined;
|
let delayedSearch=undefined;
|
||||||
let running=false;
|
let running=false;
|
||||||
|
let pipelineState=undefined;
|
||||||
let gitSha=undefined;
|
let gitSha=undefined;
|
||||||
if (! branch) branch='master';
|
|
||||||
const modeStrings={
|
const modeStrings={
|
||||||
last: 'Last Build',
|
last: 'Last Build',
|
||||||
existing: 'Existing Build',
|
existing: 'Existing Build',
|
||||||
|
@ -52,7 +51,27 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
setVisible('download', false, true);
|
setVisible('download', false, true);
|
||||||
setVisible('status_url', false, true);
|
setVisible('status_url', false, true);
|
||||||
}
|
}
|
||||||
const setRunning=(active,opt_noActivate)=>{
|
const updateStart=()=>{
|
||||||
|
if (running) {
|
||||||
|
enableEl('start',false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (displayMode != 'existing'){
|
||||||
|
if (currentPipeline !== undefined){
|
||||||
|
//check pipeline state
|
||||||
|
if (['error','success'].indexOf(pipelineState) >= 0){
|
||||||
|
enableEl('start',true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
enableEl('start',false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
enableEl('start',true);
|
||||||
|
}
|
||||||
|
//display mnode existing
|
||||||
|
enableEl('start',currentPipeline === undefined);
|
||||||
|
}
|
||||||
|
const setRunning=(active)=>{
|
||||||
running=active;
|
running=active;
|
||||||
if (active){
|
if (active){
|
||||||
showError();
|
showError();
|
||||||
|
@ -60,7 +79,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
setVisible('download', false, true);
|
setVisible('download', false, true);
|
||||||
setVisible('status_url', false, true);
|
setVisible('status_url', false, true);
|
||||||
}
|
}
|
||||||
if (active || ! opt_noActivate) enableEl('start',!active);
|
updateStart();
|
||||||
}
|
}
|
||||||
const isRunning=()=>{
|
const isRunning=()=>{
|
||||||
return running;
|
return running;
|
||||||
|
@ -71,6 +90,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
setVisible('error',false);
|
setVisible('error',false);
|
||||||
setVisible('download',false,true);
|
setVisible('download',false,true);
|
||||||
setValue('status','---');
|
setValue('status','---');
|
||||||
|
updateStart();
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let queryPipeline=currentPipeline;
|
let queryPipeline=currentPipeline;
|
||||||
|
@ -78,16 +98,19 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
.then((st)=>{
|
.then((st)=>{
|
||||||
if (queryPipeline !== currentPipeline) return;
|
if (queryPipeline !== currentPipeline) return;
|
||||||
if (st.status === undefined) st.status=st.state;
|
if (st.status === undefined) st.status=st.state;
|
||||||
|
pipelineState=st.status;
|
||||||
setValues(st);
|
setValues(st);
|
||||||
setVisible('status_url',st.status_url !== undefined,true);
|
setVisible('status_url',st.status_url !== undefined,true);
|
||||||
setVisible('error',st.error !== undefined,true);
|
setVisible('error',st.error !== undefined,true);
|
||||||
if (st.status === 'error' || st.status === 'errored'){
|
if (st.status === 'error' || st.status === 'errored'){
|
||||||
setRunning(false);
|
setRunning(false);
|
||||||
setVisible('download',false,true);
|
setVisible('download',false,true);
|
||||||
|
updateStart();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (st.status === 'success'){
|
if (st.status === 'success'){
|
||||||
setRunning(false, displayMode == 'existing');
|
setRunning(false);
|
||||||
|
updateStart();
|
||||||
fetchJson(API,{api:'artifacts',pipeline:currentPipeline})
|
fetchJson(API,{api:'artifacts',pipeline:currentPipeline})
|
||||||
.then((ar)=>{
|
.then((ar)=>{
|
||||||
if (! ar.items || ar.items.length < 1){
|
if (! ar.items || ar.items.length < 1){
|
||||||
|
@ -108,6 +131,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
else{
|
else{
|
||||||
setVisible('download',false,true);
|
setVisible('download',false,true);
|
||||||
}
|
}
|
||||||
|
updateStart();
|
||||||
timer=window.setTimeout(fetchStatus,STATUS_INTERVAL)
|
timer=window.setTimeout(fetchStatus,STATUS_INTERVAL)
|
||||||
})
|
})
|
||||||
.catch((e)=>{
|
.catch((e)=>{
|
||||||
|
@ -120,7 +144,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
if (doStore) window.localStorage.setItem(CURRENT_PIPELINE,pipeline);
|
if (doStore) window.localStorage.setItem(CURRENT_PIPELINE,pipeline);
|
||||||
};
|
};
|
||||||
const startBuild=()=>{
|
const startBuild=()=>{
|
||||||
let param={'branch':branch};
|
let param={};
|
||||||
currentPipeline=undefined;
|
currentPipeline=undefined;
|
||||||
if (timer) window.clearTimeout(timer);
|
if (timer) window.clearTimeout(timer);
|
||||||
timer=undefined;
|
timer=undefined;
|
||||||
|
@ -128,6 +152,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
setValue('status','requested');
|
setValue('status','requested');
|
||||||
setValue('pipeline','');
|
setValue('pipeline','');
|
||||||
setRunning(true);
|
setRunning(true);
|
||||||
|
updateStart();
|
||||||
if (gitSha !== undefined) param.tag=gitSha;
|
if (gitSha !== undefined) param.tag=gitSha;
|
||||||
param.config=JSON.stringify(config);
|
param.config=JSON.stringify(config);
|
||||||
fetchJson(API,Object.assign({
|
fetchJson(API,Object.assign({
|
||||||
|
@ -176,6 +201,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
let content=await readFile(file,true);
|
let content=await readFile(file,true);
|
||||||
config=JSON.parse(content);
|
config=JSON.parse(content);
|
||||||
buildSelectors(ROOT_PATH,structure.config.children,true);
|
buildSelectors(ROOT_PATH,structure.config.children,true);
|
||||||
|
findPipeline();
|
||||||
} catch (e){
|
} catch (e){
|
||||||
alert("upload "+fsel.files[0].name+" failed: "+e);
|
alert("upload "+fsel.files[0].name+" failed: "+e);
|
||||||
}
|
}
|
||||||
|
@ -243,9 +269,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
}
|
}
|
||||||
if (key == current) {
|
if (key == current) {
|
||||||
re.setAttribute('checked','checked');
|
re.setAttribute('checked','checked');
|
||||||
window.setTimeout(() => {
|
callback(v.children,key,val,true);
|
||||||
callback(v.children,key,val,true);
|
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -317,8 +341,9 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
}
|
}
|
||||||
document.getElementById('environment').value=environment;
|
document.getElementById('environment').value=environment;
|
||||||
document.getElementById('buildflags').value=flags;
|
document.getElementById('buildflags').value=flags;
|
||||||
findPipeline();
|
if (! initial) findPipeline();
|
||||||
}
|
}
|
||||||
|
let findIdx=0;
|
||||||
const findPipeline=()=>{
|
const findPipeline=()=>{
|
||||||
if (delayedSearch !== undefined){
|
if (delayedSearch !== undefined){
|
||||||
window.clearTimeout(delayedSearch);
|
window.clearTimeout(delayedSearch);
|
||||||
|
@ -328,15 +353,18 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
delayedSearch=window.setTimeout(findPipeline,500);
|
delayedSearch=window.setTimeout(findPipeline,500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
findIdx++;
|
||||||
|
let queryIdx=findIdx;
|
||||||
let param={find:1};
|
let param={find:1};
|
||||||
fillValues(param,['environment','buildflags']);
|
fillValues(param,['environment','buildflags']);
|
||||||
if (gitSha !== undefined) param.tag=gitSha;
|
if (gitSha !== undefined) param.tag=gitSha;
|
||||||
fetchJson(API,param)
|
fetchJson(API,param)
|
||||||
.then((res)=>{
|
.then((res)=>{
|
||||||
|
if (queryIdx != findIdx) return;
|
||||||
setCurrentPipeline(res.pipeline);
|
setCurrentPipeline(res.pipeline);
|
||||||
fetchStatus(true);
|
updateStart();
|
||||||
setDisplayMode('existing');
|
setDisplayMode('existing');
|
||||||
enableEl('start',res.pipeline === undefined);
|
fetchStatus(true);
|
||||||
})
|
})
|
||||||
.catch((e)=>console.log("findPipeline error ",e));
|
.catch((e)=>console.log("findPipeline error ",e));
|
||||||
|
|
||||||
|
@ -354,6 +382,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
}
|
}
|
||||||
structure=await loadConfig("build.yaml");
|
structure=await loadConfig("build.yaml");
|
||||||
buildSelectors(ROOT_PATH,structure.config.children,true);
|
buildSelectors(ROOT_PATH,structure.config.children,true);
|
||||||
|
if (! running) findPipeline();
|
||||||
let gitParam={user:GITUSER,repo:GITREPO};
|
let gitParam={user:GITUSER,repo:GITREPO};
|
||||||
let branch=getParam('branch');
|
let branch=getParam('branch');
|
||||||
if (branch){
|
if (branch){
|
||||||
|
@ -407,5 +436,6 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
|
||||||
else{
|
else{
|
||||||
setValue('gitSha',gitSha);
|
setValue('gitSha',gitSha);
|
||||||
}
|
}
|
||||||
|
updateStart();
|
||||||
}
|
}
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue