Run scheduled scripts
This commit is contained in:
parent
6d05152ab2
commit
ef0a20ffe0
7 changed files with 294 additions and 28 deletions
|
|
@ -245,6 +245,8 @@ select:focus {
|
|||
grid-template-columns: 24px 1fr;
|
||||
grid-gap: 8px;
|
||||
align-items: center;
|
||||
background-color: #f0f0f0;
|
||||
padding: 16px;
|
||||
}
|
||||
#connected-nodes .connected-nodes .type-group .type-name {
|
||||
font-weight: bold;
|
||||
|
|
@ -259,10 +261,10 @@ select:focus {
|
|||
height: 24px;
|
||||
}
|
||||
#script-hooks .scripts-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, min-content);
|
||||
align-items: center;
|
||||
grid-gap: 2px 0px;
|
||||
display: flex;
|
||||
align-items: start;
|
||||
flex-flow: row wrap;
|
||||
gap: 32px;
|
||||
}
|
||||
#script-hooks .scripts-grid .header {
|
||||
font-weight: bold;
|
||||
|
|
@ -272,12 +274,19 @@ select:focus {
|
|||
white-space: nowrap;
|
||||
}
|
||||
#script-hooks .scripts-grid .script-group {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, min-content);
|
||||
align-items: center;
|
||||
grid-gap: 2px 0px;
|
||||
padding: 16px;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
#script-hooks .scripts-grid .script-group-title {
|
||||
grid-column: 1 / -1;
|
||||
font-weight: bold;
|
||||
margin-top: 8px;
|
||||
}
|
||||
#script-hooks .scripts-grid .script-unhook img,
|
||||
#script-hooks .scripts-grid .script-run img {
|
||||
#script-hooks .scripts-grid .script-schedule img {
|
||||
display: block;
|
||||
height: 24px;
|
||||
cursor: pointer;
|
||||
|
|
@ -288,6 +297,10 @@ select:focus {
|
|||
}
|
||||
#script-hooks .scripts-grid .script-ssh {
|
||||
cursor: pointer;
|
||||
color: #555;
|
||||
}
|
||||
#script-hooks .scripts-grid .script-schedule.disabled {
|
||||
filter: invert(50%);
|
||||
}
|
||||
#script-hooks > .label {
|
||||
display: grid;
|
||||
|
|
|
|||
|
|
@ -1048,19 +1048,29 @@ class ScriptHooks extends Component {
|
|||
renderHooks() {// {{{
|
||||
this.scriptGrid.innerHTML = ''
|
||||
|
||||
let prevGroup = null
|
||||
let curGroupName = null
|
||||
let group = document.createElement('div')
|
||||
group.classList.add('script-group')
|
||||
|
||||
for (const hook of this.hooks) {
|
||||
if (hook.Script.Group !== prevGroup) {
|
||||
if (hook.Script.Group !== curGroupName) {
|
||||
const g = document.createElement('div')
|
||||
g.classList.add('script-group')
|
||||
g.classList.add('script-group-title')
|
||||
g.innerText = hook.Script.Group
|
||||
this.scriptGrid.append(g)
|
||||
prevGroup = hook.Script.Group
|
||||
|
||||
group = document.createElement('div')
|
||||
group.classList.add('script-group')
|
||||
group.append(g)
|
||||
this.scriptGrid.append(group)
|
||||
curGroupName = hook.Script.Group
|
||||
}
|
||||
|
||||
const h = new ScriptHook(hook, this)
|
||||
this.scriptGrid.append(h.render())
|
||||
group.append(h.render())
|
||||
}
|
||||
|
||||
if (group.children.length > 1)
|
||||
this.scriptGrid.append(group)
|
||||
}// }}}
|
||||
hookScript(script) {// {{{
|
||||
_app.query(`/nodes/hook`, {
|
||||
|
|
@ -1077,7 +1087,9 @@ class ScriptHook extends Component {
|
|||
super()
|
||||
this.hook = hook
|
||||
this.parentList = parentList
|
||||
this.element_ssh = null
|
||||
this.elementSSH = null
|
||||
this.elementSchedule = null
|
||||
this.scheduleDisable = false
|
||||
}// }}}
|
||||
renderComponent() {// {{{
|
||||
const tmpl = document.createElement('template')
|
||||
|
|
@ -1085,14 +1097,15 @@ class ScriptHook extends Component {
|
|||
<div class="script-name">${this.hook.Script.Name}</div>
|
||||
<div class="script-ssh"></div>
|
||||
<div class="script-unhook"><img src="/images/${_VERSION}/node_modules/@mdi/svg/svg/trash-can.svg" /></div>
|
||||
<div class="script-run"><img src="/images/${_VERSION}/node_modules/@mdi/svg/svg/play-box.svg" /></div>
|
||||
<div class="script-schedule"><img src="/images/${_VERSION}/node_modules/@mdi/svg/svg/play-box.svg" /></div>
|
||||
`
|
||||
this.element_ssh = tmpl.content.querySelector('.script-ssh')
|
||||
this.element_ssh.innerText = this.hook.SSH
|
||||
this.elementSchedule = tmpl.content.querySelector('.script-schedule')
|
||||
this.elementSSH = tmpl.content.querySelector('.script-ssh')
|
||||
this.elementSSH.innerText = `[ ${this.hook.SSH} ]`
|
||||
|
||||
tmpl.content.querySelector('.script-ssh').addEventListener('click', () => this.update())
|
||||
tmpl.content.querySelector('.script-unhook').addEventListener('click', () => this.delete())
|
||||
tmpl.content.querySelector('.script-run').addEventListener('click', () => this.run())
|
||||
tmpl.content.querySelector('.script-schedule').addEventListener('click', () => this.run())
|
||||
|
||||
return tmpl.content
|
||||
}// }}}
|
||||
|
|
@ -1121,7 +1134,7 @@ class ScriptHook extends Component {
|
|||
return
|
||||
}
|
||||
this.hook.SSH = ssh
|
||||
this.element_ssh.innerText = this.hook.SSH
|
||||
this.elementSSH.innerText = this.hook.SSH
|
||||
})
|
||||
.catch(err => showError(err))
|
||||
}// }}}
|
||||
|
|
@ -1141,8 +1154,22 @@ class ScriptHook extends Component {
|
|||
.catch(err => showError(err))
|
||||
}// }}}
|
||||
run() {// {{{
|
||||
if (this.scheduleDisable)
|
||||
return
|
||||
|
||||
this.scheduleDisable = true
|
||||
this.elementSchedule.classList.add('disabled')
|
||||
const start = Date.now()
|
||||
|
||||
_app.query(`/hooks/schedule/${this.hook.ID}`)
|
||||
.catch(err => showError(err))
|
||||
.finally(() => {
|
||||
const duration = Date.now() - start
|
||||
setTimeout(() => {
|
||||
this.scheduleDisable = false
|
||||
this.elementSchedule.classList.remove('disabled')
|
||||
}, 250 - duration)
|
||||
})
|
||||
}// }}}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -324,6 +324,8 @@ select:focus {
|
|||
grid-template-columns: 24px 1fr;
|
||||
grid-gap: 8px;
|
||||
align-items: center;
|
||||
background-color: #f0f0f0;
|
||||
padding: 16px;
|
||||
|
||||
.type-name {
|
||||
font-weight: bold;
|
||||
|
|
@ -346,27 +348,35 @@ select:focus {
|
|||
|
||||
#script-hooks {
|
||||
.scripts-grid {
|
||||
display: flex;
|
||||
align-items: start;
|
||||
flex-flow: row wrap;
|
||||
gap: 32px;
|
||||
|
||||
.header {
|
||||
font-weight: bold;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, min-content);
|
||||
align-items: center;
|
||||
grid-gap: 2px 0px;
|
||||
|
||||
div {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.script-group {
|
||||
grid-column: 1 / -1;
|
||||
font-weight: bold;
|
||||
margin-top: 8px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, min-content);
|
||||
align-items: center;
|
||||
grid-gap: 2px 0px;
|
||||
padding: 16px;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.script-unhook, .script-run {
|
||||
.script-group-title {
|
||||
grid-column: 1 / -1;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.script-unhook, .script-schedule {
|
||||
img {
|
||||
display: block;
|
||||
height: 24px;
|
||||
|
|
@ -380,6 +390,11 @@ select:focus {
|
|||
|
||||
.script-ssh {
|
||||
cursor: pointer;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.script-schedule.disabled {
|
||||
filter: invert(50%);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue