|
|
@ -2,9 +2,10 @@ |
|
|
|
import './reset.css'; // Generic reset
|
|
|
|
import './reset.css'; // Generic reset
|
|
|
|
import './style.css'; // The new new
|
|
|
|
import './style.css'; // The new new
|
|
|
|
import React, {useState,useEffect,useRef,useReducer} from 'react'; |
|
|
|
import React, {useState,useEffect,useRef,useReducer} from 'react'; |
|
|
|
|
|
|
|
import useGlobalKeyDown from 'react-global-key-down-hook' |
|
|
|
import Modal from 'react-modal' |
|
|
|
import Modal from 'react-modal' |
|
|
|
|
|
|
|
|
|
|
|
import {XSquare, XSquareFill} from 'react-bootstrap-icons' |
|
|
|
import {XSquare, XSquareFill, PlusCircle} from 'react-bootstrap-icons' |
|
|
|
|
|
|
|
|
|
|
|
import { |
|
|
|
import { |
|
|
|
HashRouter, |
|
|
|
HashRouter, |
|
|
@ -375,18 +376,32 @@ function InputBox(p) { |
|
|
|
const [failed,setFailed] = useState(false) |
|
|
|
const [failed,setFailed] = useState(false) |
|
|
|
const [sending,setSending] = useState(false) |
|
|
|
const [sending,setSending] = useState(false) |
|
|
|
|
|
|
|
|
|
|
|
function changeFunc(f){setValue(f.currentTarget.value)} |
|
|
|
function changeFunc(f){setValue(f.currentTarget.value) |
|
|
|
|
|
|
|
if (p.callback4) { |
|
|
|
|
|
|
|
p.callback4(f.currentTarget.value) |
|
|
|
|
|
|
|
}} |
|
|
|
function blurFunc(f){ |
|
|
|
function blurFunc(f){ |
|
|
|
setSending(true) |
|
|
|
if (p.callback) { |
|
|
|
setFailed(false) |
|
|
|
setSending(true) |
|
|
|
p.callback(f.currentTarget.value) |
|
|
|
setFailed(false) |
|
|
|
.then(()=>{setFailed(false)}) |
|
|
|
p.callback(f.currentTarget.value) |
|
|
|
.catch(()=>{setFailed(true)}) |
|
|
|
.then(()=>{setFailed(false)}) |
|
|
|
.then(()=>{setSending(false)})} |
|
|
|
.catch(()=>{setFailed(true)}) |
|
|
|
|
|
|
|
.then(()=>{setSending(false)})} |
|
|
|
return p.data?<select className={failed?"failedInput":sending?"submitting":""} value={value} onChange={(f)=>{changeFunc(f)}} onBlur={(f)=>{blurFunc(f)}}> |
|
|
|
else
|
|
|
|
|
|
|
|
if (p.callback3) { |
|
|
|
|
|
|
|
p.callback3(f.currentTarget.value) |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
function keydownFunc(f){ |
|
|
|
|
|
|
|
if (p.callback2) { |
|
|
|
|
|
|
|
p.callback2(f,value) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p.data?<select className={failed?"failedInput":sending?"submitting":""} value={value} onKeyDown={(f)=>{keydownFunc(f)}} onChange={(f)=>{changeFunc(f)}} onBlur={(f)=>{blurFunc(f)}}> |
|
|
|
|
|
|
|
{p.includeBlankValue&&<option/>} |
|
|
|
{p.data.map((item)=><option value={item.id}>{item.id} - {item.name||item.username}</option>)} |
|
|
|
{p.data.map((item)=><option value={item.id}>{item.id} - {item.name||item.username}</option>)} |
|
|
|
</select>:<input className={failed?"failedInput":sending?"submitting":""} value={value} onChange={(f)=>{changeFunc(f)}} onBlur={(f)=>{blurFunc(f)}}/> |
|
|
|
</select>:<input className={failed?"failedInput":sending?"submitting":""} value={value} onKeyDown={(f)=>{keydownFunc(f)}} onChange={(f)=>{changeFunc(f)}} onBlur={(f)=>{blurFunc(f)}}/> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function TableEditor(p) { |
|
|
|
function TableEditor(p) { |
|
|
@ -411,6 +426,7 @@ function TableEditor(p) { |
|
|
|
function SubmitBoxes() { |
|
|
|
function SubmitBoxes() { |
|
|
|
axios.post(BACKEND_URL+p.path,submitVals) |
|
|
|
axios.post(BACKEND_URL+p.path,submitVals) |
|
|
|
.then(()=>{ |
|
|
|
.then(()=>{ |
|
|
|
|
|
|
|
setSubmitVal("Clear") |
|
|
|
setUpdate(true) |
|
|
|
setUpdate(true) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((err)=>{ |
|
|
|
.catch((err)=>{ |
|
|
@ -418,6 +434,10 @@ function TableEditor(p) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useGlobalKeyDown(()=>{ |
|
|
|
|
|
|
|
SubmitBoxes() |
|
|
|
|
|
|
|
},['Enter']) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
useEffect(()=>{ |
|
|
|
setUpdate(true) |
|
|
|
setUpdate(true) |
|
|
|
},[p.path]) |
|
|
|
},[p.path]) |
|
|
@ -456,7 +476,6 @@ function TableEditor(p) { |
|
|
|
{!loading? |
|
|
|
{!loading? |
|
|
|
<div className="table-responsive"> |
|
|
|
<div className="table-responsive"> |
|
|
|
<table cellPadding="10" className="table text-light table-padding"> |
|
|
|
<table cellPadding="10" className="table text-light table-padding"> |
|
|
|
<caption>{JSON.stringify(dependencies)}</caption> |
|
|
|
|
|
|
|
<thead> |
|
|
|
<thead> |
|
|
|
<tr> |
|
|
|
<tr> |
|
|
|
<th className="table-padding"></th> |
|
|
|
<th className="table-padding"></th> |
|
|
@ -464,6 +483,8 @@ function TableEditor(p) { |
|
|
|
</tr> |
|
|
|
</tr> |
|
|
|
</thead> |
|
|
|
</thead> |
|
|
|
<tbody> |
|
|
|
<tbody> |
|
|
|
|
|
|
|
{<tr><td></td>{fields.map((col,i)=><td key={i}>{<InputBox includeBlankValue={true} data={dependencies[col.name]} callback4={ |
|
|
|
|
|
|
|
(f)=>{setSubmitVal({field:col.name,value:f});}}/>}</td>)}<input style={{position:'absolute',top:"-1000px"}}/><PlusCircle onClick={()=>{SubmitBoxes()}} className="submitbutton"/></tr>} |
|
|
|
{data.map((dat)=><tr key={dat.id}> |
|
|
|
{data.map((dat)=><tr key={dat.id}> |
|
|
|
<td><XSquareFill className="webicon" onClick={()=>{axios.delete(BACKEND_URL+p.path,{data:{id:dat.id}}).then(()=>{setUpdate(true)}).catch((err)=>{alert(err.response.data)})}}/></td>{fields.map((col,i)=><td key={dat.id+"_"+i} className="table-padding table"> |
|
|
|
<td><XSquareFill className="webicon" onClick={()=>{axios.delete(BACKEND_URL+p.path,{data:{id:dat.id}}).then(()=>{setUpdate(true)}).catch((err)=>{alert(err.response.data)})}}/></td>{fields.map((col,i)=><td key={dat.id+"_"+i} className="table-padding table"> |
|
|
|
<InputBox data={dependencies[col.name]} callback={(value)=>{ |
|
|
|
<InputBox data={dependencies[col.name]} callback={(value)=>{ |
|
|
@ -472,7 +493,6 @@ function TableEditor(p) { |
|
|
|
id:dat.id |
|
|
|
id:dat.id |
|
|
|
}) |
|
|
|
}) |
|
|
|
}} value={String(dat[col.name])}/></td>)}</tr>)} |
|
|
|
}} value={String(dat[col.name])}/></td>)}</tr>)} |
|
|
|
{<tr><td></td>{fields.map((col,i)=><td key={i}>{<input id={"submitField"+i} onBlur={(i===fields.length-1)?(f)=>{setSubmitVal({field:col.name,value:f.currentTarget.value});SubmitBoxes();document.getElementById("submitField0").focus()}:(f)=>{setSubmitVal({field:col.name,value:f.currentTarget.value})}}/>}</td>)}</tr>} |
|
|
|
|
|
|
|
</tbody> |
|
|
|
</tbody> |
|
|
|
</table> |
|
|
|
</table> |
|
|
|
</div>:<img src={process.env.PUBLIC_URL+"/spinner.gif"} alt=""/>} |
|
|
|
</div>:<img src={process.env.PUBLIC_URL+"/spinner.gif"} alt=""/>} |
|
|
|