File: resources/assets/js/components/WatchActive.vue

Recommend this page to a friend!
  Classes of Insolita  >  Laravel Interactive Jobs  >  resources/assets/js/components/WatchActive.vue  >  Download  
File: resources/assets/js/components/WatchActive.vue
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Laravel Interactive Jobs
Run background jobs and monitor progress on a page
Author: By
Last change:
Date: 8 months ago
Size: 1,264 bytes
 

Contents

Download
<template>
    <div>
        <active-job v-for="job in jobs" :key="job.id" :job="job" :single="0" @removeItem="remove"/>
    </div>
</template>

<script>
    import ActiveJob from './ActiveJob';
    export default {
        components:{ActiveJob},
        props:['list'],
        data(){
            return {
                jobs:[]
            }
        },
        mounted(){
            this.jobs = JSON.parse(this.list);
            this.$nextTick(function () {
                if(this.$user){
                    this.monitorSubscribe();
                }
            });
        },
        methods:{
            addJob(job){
                this.jobs.unshift(job);
            },
            remove(jobid){
                let index = this.jobs.findIndex(el => el.id == jobid);
                if(index >=0){
                    this.jobs.splice(index, 1);
                }
            },
            monitorSubscribe() {
                console.log('start watch!');
                this.$echo.private(`JobsMonitor.${this.$user.id}`).notification((notification) => {
                    if(notification.job){
                        this.addJob(JSON.parse(notification.job))
                    }
                });
            }
        }
    }
</script>


For more information send a message to info at phpclasses dot org.