feat(fe): update task statuses on Dashboard in realtime

Issue: https://github.com/ansible-semaphore/semaphore/issues/621
This commit is contained in:
Denis Gukov 2020-11-22 05:13:03 +05:00
parent d417f95273
commit 043b8852aa
2 changed files with 24 additions and 2 deletions

View File

@ -106,7 +106,7 @@ export default {
},
},
async created() {
socket.addListener((data) => this.onDataReceive(data));
socket.addListener((data) => this.onWebsocketDataReceived(data));
await this.loadData();
},
@ -117,7 +117,7 @@ export default {
this.user = {};
},
onDataReceive(data) {
onWebsocketDataReceived(data) {
if (data.project_id !== this.projectId || data.task_id !== this.itemId) {
return;
}

View File

@ -46,6 +46,7 @@
import ItemListPageBase from '@/components/ItemListPageBase';
import EventBus from '@/event-bus';
import TaskStatus from '@/components/TaskStatus.vue';
import socket from '@/socket';
export default {
mixins: [ItemListPageBase],
@ -58,6 +59,10 @@ export default {
},
},
created() {
socket.addListener((data) => this.onWebsocketDataReceived(data));
},
methods: {
showTaskLog(taskId) {
EventBus.$emit('i-show-task', {
@ -65,6 +70,23 @@ export default {
});
},
async onWebsocketDataReceived(data) {
if (data.project_id !== this.projectId || data.type !== 'update') {
return;
}
if (!this.items.some((item) => item.id === data.task_id)) {
await this.loadItems();
}
const task = this.items.find((item) => item.id === data.task_id);
Object.assign(task, {
...data,
type: undefined,
});
},
getHeaders() {
return [
{