allow replacement values in target strings, allow frames without keys, correct status handling
This commit is contained in:
parent
4a93dd8fa4
commit
8e40fa5e9d
|
@ -126,16 +126,13 @@ types:
|
||||||
- 1
|
- 1
|
||||||
- 2
|
- 2
|
||||||
|
|
||||||
- &serial1
|
|
||||||
type: checkbox
|
- &serialValues
|
||||||
label: 'Serial 1'
|
|
||||||
key: serial1
|
|
||||||
values:
|
|
||||||
- key: true
|
- key: true
|
||||||
children:
|
children:
|
||||||
- type: select
|
- type: select
|
||||||
key: type
|
key: type
|
||||||
target: "define:GWSERIAL_TYPE"
|
target: "define:#serial#TYPE"
|
||||||
label: "Serial Type"
|
label: "Serial Type"
|
||||||
values:
|
values:
|
||||||
- key: uni
|
- key: uni
|
||||||
|
@ -145,11 +142,11 @@ types:
|
||||||
children:
|
children:
|
||||||
- <<: *gpiopin
|
- <<: *gpiopin
|
||||||
key: RX
|
key: RX
|
||||||
target: "define:GWSERIAL_RX"
|
target: "define:#serial#RX"
|
||||||
mandatory: true
|
mandatory: true
|
||||||
- <<: *gpiopin
|
- <<: *gpiopin
|
||||||
key: TX
|
key: TX
|
||||||
target: "define:GWSERIAL_TX"
|
target: "define:#serial#TX"
|
||||||
mandatory: true
|
mandatory: true
|
||||||
- key: bi
|
- key: bi
|
||||||
value: 2
|
value: 2
|
||||||
|
@ -158,11 +155,11 @@ types:
|
||||||
children:
|
children:
|
||||||
- <<: *gpiopin
|
- <<: *gpiopin
|
||||||
key: RX
|
key: RX
|
||||||
target: "define:GWSERIAL_RX"
|
target: "define:#serial#RX"
|
||||||
mandatory: true
|
mandatory: true
|
||||||
- <<: *gpiopin
|
- <<: *gpiopin
|
||||||
key: TX
|
key: TX
|
||||||
target: "define:GWSERIAL_TX"
|
target: "define:#serial#TX"
|
||||||
mandatory: true
|
mandatory: true
|
||||||
- key: rx
|
- key: rx
|
||||||
value: 3
|
value: 3
|
||||||
|
@ -171,7 +168,7 @@ types:
|
||||||
children:
|
children:
|
||||||
- <<: *gpiopin
|
- <<: *gpiopin
|
||||||
key: RX
|
key: RX
|
||||||
target: "define:GWSERIAL_RX"
|
target: "define:#serial#RX"
|
||||||
mandatory: true
|
mandatory: true
|
||||||
- key: tx
|
- key: tx
|
||||||
value: 1
|
value: 1
|
||||||
|
@ -180,8 +177,24 @@ types:
|
||||||
children:
|
children:
|
||||||
- <<: *gpiopin
|
- <<: *gpiopin
|
||||||
key: TX
|
key: TX
|
||||||
target: "define:GWSERIAL_TX"
|
target: "define:#serial#TX"
|
||||||
mandatory: true
|
mandatory: true
|
||||||
|
- &serial1
|
||||||
|
type: checkbox
|
||||||
|
label: 'Serial 1'
|
||||||
|
key: serial1
|
||||||
|
base:
|
||||||
|
serial: GWSERIAL_
|
||||||
|
values: *serialValues
|
||||||
|
|
||||||
|
- &serial2
|
||||||
|
type: checkbox
|
||||||
|
label: 'Serial 2'
|
||||||
|
key: serial2
|
||||||
|
base:
|
||||||
|
serial: GWSERIAL2_
|
||||||
|
values: *serialValues
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
default: &esp32default
|
default: &esp32default
|
||||||
serial: 2
|
serial: 2
|
||||||
|
@ -217,4 +230,5 @@ config:
|
||||||
description: "Node mcu"
|
description: "Node mcu"
|
||||||
resource: *esp32default
|
resource: *esp32default
|
||||||
children:
|
children:
|
||||||
- *serial1
|
- *serial1
|
||||||
|
- *serial2
|
|
@ -5,8 +5,10 @@ class PipelineInfo{
|
||||||
constructor(id){
|
constructor(id){
|
||||||
this.STFIELDS=['status','error','status_url'];
|
this.STFIELDS=['status','error','status_url'];
|
||||||
this.reset(id);
|
this.reset(id);
|
||||||
|
this.lastUpdate=0;
|
||||||
}
|
}
|
||||||
update(state){
|
update(state){
|
||||||
|
this.lastUpdate=(new Date()).getTime();
|
||||||
if (state.pipeline_id !== undefined && state.pipeline_id !== this.id){
|
if (state.pipeline_id !== undefined && state.pipeline_id !== this.id){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +34,7 @@ class PipelineInfo{
|
||||||
isRunning(){
|
isRunning(){
|
||||||
if (! this.valid()) return false;
|
if (! this.valid()) return false;
|
||||||
if (this.status === undefined) return false;
|
if (this.status === undefined) return false;
|
||||||
return ['error','success','canceled'].indexOf(this.status) < 0;
|
return ['error','success','canceled','failed','errored'].indexOf(this.status) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -113,7 +115,8 @@ class PipelineInfo{
|
||||||
fetchJson(API,{api:'status',pipeline:currentPipeline.id})
|
fetchJson(API,{api:'status',pipeline:currentPipeline.id})
|
||||||
.then((st)=>{
|
.then((st)=>{
|
||||||
if (queryPipeline !== currentPipeline.id) return;
|
if (queryPipeline !== currentPipeline.id) return;
|
||||||
if (currentPipeline.id !== st.pipeline_id) return;
|
let stid=st.pipeline_id||st.id;
|
||||||
|
if (currentPipeline.id !== stid) return;
|
||||||
if (st.status === undefined) st.status=st.state;
|
if (st.status === undefined) st.status=st.state;
|
||||||
currentPipeline.update(st);
|
currentPipeline.update(st);
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
@ -214,7 +217,9 @@ class PipelineInfo{
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
let content=await readFile(file,true);
|
let content=await readFile(file,true);
|
||||||
config=JSON.parse(content);
|
let newConfig=JSON.parse(content);
|
||||||
|
removeSelectors(ROOT_PATH,true);
|
||||||
|
config=newConfig;
|
||||||
buildSelectors(ROOT_PATH,structure.config.children,true);
|
buildSelectors(ROOT_PATH,structure.config.children,true);
|
||||||
findPipeline();
|
findPipeline();
|
||||||
} catch (e){
|
} catch (e){
|
||||||
|
@ -300,7 +305,9 @@ class PipelineInfo{
|
||||||
let frame=addEl('div','selector level'+level.length+' t'+config.type,parent);
|
let frame=addEl('div','selector level'+level.length+' t'+config.type,parent);
|
||||||
frame.setAttribute(PATH_ATTR,name);
|
frame.setAttribute(PATH_ATTR,name);
|
||||||
let inputFrame=addEl('div','inputFrame',frame);
|
let inputFrame=addEl('div','inputFrame',frame);
|
||||||
let title=addEl('div','title t'+config.type,inputFrame,config.label);
|
if (config.label !== undefined){
|
||||||
|
addEl('div','title t'+config.type,inputFrame,config.label);
|
||||||
|
}
|
||||||
let initialConfig=undefined
|
let initialConfig=undefined
|
||||||
if (config.type === 'frame' || config.type === undefined){
|
if (config.type === 'frame' || config.type === undefined){
|
||||||
initialConfig=config;
|
initialConfig=config;
|
||||||
|
@ -418,8 +425,7 @@ class PipelineInfo{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const buildSelectors=(prefix,configList,initial,parent)=>{
|
const buildSelectors=(prefix,configList,initial,base,parent)=>{
|
||||||
removeSelectors(prefix,!initial);
|
|
||||||
if (!parent) parent=document.getElementById("selectors");;
|
if (!parent) parent=document.getElementById("selectors");;
|
||||||
if (!configList) return;
|
if (!configList) return;
|
||||||
let frame=addEl('div','selectorFrame',parent);
|
let frame=addEl('div','selectorFrame',parent);
|
||||||
|
@ -427,19 +433,38 @@ class PipelineInfo{
|
||||||
let expandedList=expandList(configList);
|
let expandedList=expandList(configList);
|
||||||
expandedList.forEach((cfg)=>{
|
expandedList.forEach((cfg)=>{
|
||||||
if (cfg.key === undefined){
|
if (cfg.key === undefined){
|
||||||
console.log("config without key",cfg);
|
if (cfg.type !== undefined && cfg.type !== 'frame'){
|
||||||
return;
|
console.log("config without key",cfg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let name=prefix;
|
||||||
|
if (name !== undefined){
|
||||||
|
if (cfg.key !== undefined) {
|
||||||
|
name=prefix+SEPARATOR+cfg.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
name=cfg.key;
|
||||||
}
|
}
|
||||||
let name=prefix?(prefix+SEPARATOR+cfg.key):cfg.key;
|
|
||||||
let current=config[name];
|
let current=config[name];
|
||||||
|
let currentBase=Object.assign({},base,cfg.base);
|
||||||
let childFrame=buildSelector(frame,cfg,name,current,
|
let childFrame=buildSelector(frame,cfg,name,current,
|
||||||
(child,initial,opt_frame)=>{
|
(child,initial,opt_frame)=>{
|
||||||
buildSelectors(name,child.children,initial,opt_frame||childFrame);
|
if(cfg.key !== undefined) removeSelectors(name,!initial);
|
||||||
configStruct[name]=child;
|
buildSelectors(name,child.children,initial,currentBase,opt_frame||childFrame);
|
||||||
|
if (cfg.key !== undefined) configStruct[name]={cfg:child,base:currentBase};
|
||||||
buildValues(initial);
|
buildValues(initial);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const replaceValues=(str,base)=>{
|
||||||
|
for (let k in base){
|
||||||
|
let r=new RegExp("#"+k+"#","g");
|
||||||
|
str=str.replace(r,base[k]);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
const ROOT_PATH='root';
|
const ROOT_PATH='root';
|
||||||
const buildValues=(initial)=>{
|
const buildValues=(initial)=>{
|
||||||
let environment;
|
let environment;
|
||||||
|
@ -454,7 +479,9 @@ class PipelineInfo{
|
||||||
//round1: find allowed resources
|
//round1: find allowed resources
|
||||||
//round2: really collect values
|
//round2: really collect values
|
||||||
for (let k in configStruct) {
|
for (let k in configStruct) {
|
||||||
let struct = configStruct[k];
|
let container = configStruct[k];
|
||||||
|
if (! container.cfg) continue;
|
||||||
|
let struct=container.cfg;
|
||||||
if (round > 0) config[k] = struct.key;
|
if (round > 0) config[k] = struct.key;
|
||||||
if (struct.target !== undefined ) {
|
if (struct.target !== undefined ) {
|
||||||
if (struct.value === undefined){
|
if (struct.value === undefined){
|
||||||
|
@ -463,8 +490,9 @@ class PipelineInfo{
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (struct.target === 'environment' ) {
|
let target=replaceValues(struct.target,container.base);
|
||||||
if (round > 0) environment = struct.value;
|
if (target === 'environment' ) {
|
||||||
|
if (round > 0 && struct.key !== undefined) environment = struct.value;
|
||||||
else allowedResources=struct.resource;
|
else allowedResources=struct.resource;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -477,13 +505,13 @@ class PipelineInfo{
|
||||||
}
|
}
|
||||||
resList.push(struct);
|
resList.push(struct);
|
||||||
}
|
}
|
||||||
if (struct.target === 'define') {
|
if (target === 'define') {
|
||||||
flags += " -D" + struct.value;
|
flags += " -D" + struct.value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const DEFPRFX = "define:";
|
const DEFPRFX = "define:";
|
||||||
if (struct.target.indexOf(DEFPRFX) == 0) {
|
if (target.indexOf(DEFPRFX) == 0) {
|
||||||
let def = struct.target.substring(DEFPRFX.length);
|
let def = target.substring(DEFPRFX.length);
|
||||||
flags += " -D" + def + "=" + struct.value;
|
flags += " -D" + def + "=" + struct.value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -623,7 +651,7 @@ class PipelineInfo{
|
||||||
let now=new Date();
|
let now=new Date();
|
||||||
let m=now.getMonth()+1;
|
let m=now.getMonth()+1;
|
||||||
m=((m<10)?"0":"")+m;
|
m=((m<10)?"0":"")+m;
|
||||||
let d=now.getDay();
|
let d=now.getDate();
|
||||||
d=((d<10)?"0":"")+d;
|
d=((d<10)?"0":"")+d;
|
||||||
val=val+now.getFullYear()+m+d;
|
val=val+now.getFullYear()+m+d;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue