Skip to content

Commit 9c22eb3

Browse files
lroggenroshangautam
authored andcommitted
[feature] refresh task list on manual execute
- refresh task list to reflect any changes when a task is executed manually from dashboard
1 parent 18b6d7e commit 9c22eb3

File tree

6 files changed

+92
-31
lines changed

6 files changed

+92
-31
lines changed

resources/assets/js/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import moment from 'moment';
44
import UIkit from 'uikit';
55
import Icons from 'uikit/dist/js/uikit-icons';
66
import UIKitAlert from './components/UiKitAlert.vue';
7+
import TaskRow from './tasks/components/TaskRow.vue';
78
import TaskType from './tasks/components/TaskType.vue';
89
import TaskOutput from './tasks/components/TaskOutput.vue';
910
import StatusButton from './tasks/components/StatusButton.vue';
@@ -53,6 +54,7 @@ new Vue({
5354
'import-button': ImportButton,
5455
'task-type' : TaskType,
5556
'task-output' : TaskOutput,
57+
'task-row': TaskRow,
5658
'click-to-close' : ClickToClose,
5759
'command-list' : CommandList
5860
},

resources/assets/js/tasks/components/ExecuteButton.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
.then(response => {
4848
this.task = response.data;
4949
this.running = false;
50+
this.$emit('taskExecuted', this.task);
5051
})
5152
}
5253
},
5354
mounted() {
5455
}
5556
}
56-
</script>
57+
</script>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<template>
2+
<tr :class="task.is_active ? '' : 'uk-text-danger'">
3+
<td>
4+
<a :href="showHref">
5+
{{ description }}
6+
</a>
7+
<span class="uk-float-right uk-hidden@s uk-text-muted">Command</span>
8+
</td>
9+
<td>
10+
{{ task.average_runtime ? averageDurationInSeconds : 0 }} seconds
11+
<span class="uk-float-right uk-hidden@s uk-text-muted">Avg. Runtime</span>
12+
</td>
13+
<td>
14+
{{ task.last_result ? lastRunDate : 'N/A' }}
15+
<span class="uk-float-right uk-hidden@s uk-text-muted">Last Run</span>
16+
</td>
17+
<td>
18+
{{task.upcoming}}
19+
<span class="uk-float-right uk-hidden@s uk-text-muted">Next Run</span>
20+
</td>
21+
<td class="uk-text-center@m">
22+
<execute-button
23+
:data-task="task"
24+
:url="executeHref"
25+
v-on:taskExecuted="refreshTask"
26+
icon-name="play"
27+
button-class="uk-button-link"
28+
/>
29+
</td>
30+
</tr>
31+
</template>
32+
33+
<script>
34+
import moment from 'moment'
35+
import ExecuteButton from './ExecuteButton'
36+
37+
export default {
38+
components: {
39+
ExecuteButton
40+
},
41+
42+
props: {
43+
dataTask: {},
44+
},
45+
46+
data() {
47+
return {
48+
task: this.dataTask
49+
}
50+
},
51+
52+
computed: {
53+
description() {
54+
return this.task.description.substring(0,29);
55+
},
56+
57+
averageDurationInSeconds() {
58+
return this.task.average_runtime > 0 ? (this.task.average_runtime / 1000).toFixed(2) : 0;
59+
},
60+
61+
lastRunDate() {
62+
return moment(this.task.last_result.ran_at).format('YYYY-MM-DD hh:mm:ss');
63+
},
64+
65+
showHref() {
66+
return this.$attrs.showhref;
67+
},
68+
69+
executeHref() {
70+
return this.$attrs.executehref;
71+
}
72+
},
73+
74+
methods: {
75+
refreshTask(task) {
76+
this.task = task;
77+
}
78+
}
79+
}
80+
</script>

resources/views/tasks/index.blade.php

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,10 @@
3030
</thead>
3131
<tbody>
3232
@forelse($tasks as $task)
33-
<tr class="{{$task->is_active ?: 'uk-text-danger'}}">
34-
<td>
35-
<a href="{{route('totem.task.view', $task)}}">
36-
{{str_limit($task->description, 30)}}
37-
</a>
38-
<span class="uk-float-right uk-hidden@s uk-text-muted">Command</span>
39-
</td>
40-
<td>
41-
{{ number_format( $task->averageRuntime / 1000 , 2 ) }} seconds
42-
<span class="uk-float-right uk-hidden@s uk-text-muted">Avg. Runtime</span>
43-
</td>
44-
@if($last = $task->lastResult)
45-
<td>
46-
{{$last->ran_at->toDateTimeString()}}
47-
<span class="uk-float-right uk-hidden@s uk-text-muted">Last Run</span>
48-
</td>
49-
@else
50-
<td>
51-
N/A
52-
<span class="uk-float-right uk-hidden@s uk-text-muted">Last Run</span>
53-
</td>
54-
@endif
55-
<td>
56-
{{$task->upcoming}}
57-
<span class="uk-float-right uk-hidden@s uk-text-muted">Next Run</span>
58-
</td>
59-
<td class="uk-text-center@m">
60-
<execute-button :data-task="{{$task}}" url="{{route('totem.task.execute', $task)}}" icon-name="play" button-class="uk-button-link"></execute-button>
61-
</td>
33+
<tr is="task-row"
34+
:data-task="{{$task}}"
35+
showHref="{{route('totem.task.view', $task)}}"
36+
executeHref="{{route('totem.task.execute', $task)}}">
6237
</tr>
6338
@empty
6439
<tr>

src/Http/Controllers/ExecuteTasksController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Studio\Totem\Http\Controllers;
44

5+
use Studio\Totem\Task;
56
use Studio\Totem\Contracts\TaskInterface;
67

78
class ExecuteTasksController extends Controller
@@ -29,6 +30,6 @@ public function index($task)
2930
{
3031
$this->tasks->execute($task);
3132

32-
return redirect()->back();
33+
return Task::find($task->id);
3334
}
3435
}

src/Task.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Task extends TotemModel
4343
protected $appends = [
4444
'activated',
4545
'upcoming',
46+
'last_result',
47+
'average_runtime',
4648
];
4749

4850
/**

0 commit comments

Comments
 (0)