You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
4.5 KiB
153 lines
4.5 KiB
<app-tasks>
|
|
<div class="tasks">
|
|
<table class="table table--stripped">
|
|
<thead>
|
|
<tr>
|
|
<td class="table__th">
|
|
state
|
|
</td>
|
|
<th class="table__th">
|
|
name
|
|
</th>
|
|
<th class="table__th">
|
|
url
|
|
</th>
|
|
<th class="table__th">
|
|
requestHandler
|
|
</th>
|
|
<th class="table__th">
|
|
actions
|
|
</th>
|
|
<th class="table__th">
|
|
cron
|
|
</th>
|
|
<th class="table__th"></th>
|
|
<tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr if={ state.tasks.length > 0 } each={ task in state.tasks }>
|
|
<td class="table__td">
|
|
|
|
</td>
|
|
<td class="table__td">
|
|
{ task.name }
|
|
</td>
|
|
<td class="table__td">
|
|
{ task.url }
|
|
</td>
|
|
<td class="table__td">
|
|
{ task.requestHandler }
|
|
</td>
|
|
<td class="table__td">
|
|
<virtual each={ action in task.actions }>
|
|
<span>
|
|
{ action.className }
|
|
</span>
|
|
<span if={ actions.options }>
|
|
{ JSON.stringify(action.options) }
|
|
</span>
|
|
</virtual>
|
|
</td>
|
|
<td class="table__td">
|
|
{ task.cron }
|
|
</td>
|
|
<td class="table__td">
|
|
<button class="button">
|
|
Pause
|
|
</button>
|
|
<button class="button" onclick={ (event) => { handleEdit(event, task) } }>
|
|
Edit
|
|
</button>
|
|
<button class="button" onclick={ (event) => { handleDelete(event, task) } }>
|
|
Delete
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
<tr if={ state.tasks.length === 0 }>
|
|
<td class="table__td center" colspan="6">
|
|
Nothing found
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
// stores
|
|
import taskFormStore from './../stores/taskForm.js'
|
|
import notificationStore from './../stores/notification'
|
|
|
|
/**
|
|
* show all tasks
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
export default
|
|
{
|
|
state: {
|
|
tasks: []
|
|
},
|
|
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
onMounted()
|
|
{
|
|
this.getTasks()
|
|
},
|
|
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
getTasks()
|
|
{
|
|
fetch('/api/v1/task')
|
|
.then((response) => response.json())
|
|
.then((response) => {
|
|
this.state.tasks = response.data
|
|
this.update()
|
|
})
|
|
},
|
|
|
|
/**
|
|
* delete
|
|
*
|
|
* @param {object} event
|
|
* @param {object} task
|
|
*
|
|
*/
|
|
handleDelete(event, task)
|
|
{
|
|
fetch('/api/v1/task/' + task._id, {
|
|
'method': 'DELETE'
|
|
})
|
|
.then((response) => response.json())
|
|
.then((response) => {
|
|
notificationStore.success('Deleted ' + response.data.name + '!')
|
|
this.getTasks()
|
|
})
|
|
.catch((errors) => {
|
|
notificationStore.success('Error! ' + response.data.name + ' could not deleted!')
|
|
})
|
|
},
|
|
|
|
/**
|
|
* edit task, trigger form taskForm
|
|
*
|
|
* @param {object} event
|
|
* @param {object} task
|
|
*
|
|
*/
|
|
handleEdit(event, task)
|
|
{
|
|
taskFormStore.open(task)
|
|
}
|
|
}
|
|
|
|
</script>
|
|
</app-tasks> |