<!--
  This file is part of vospace-ui
  Copyright (C) 2021 Istituto Nazionale di Astrofisica
  SPDX-License-Identifier: GPL-3.0-or-later
-->
<template>
<div>
  <b-button variant="primary" class="float-right" @click="loadJobs">Reload</b-button>
  <h3>Async recall jobs</h3>
  <table class="table b-table table-striped table-hover">
    <thead>
      <tr>
        <th>Creation time</th>
        <th>Id</th>
        <th>Phase</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="job in jobs" :key="job.id">
        <td>{{job.creationTime}}</td>
        <td>{{job.id}}</td>
        <td>{{job.phase}}</td>
      </tr>
    </tbody>
  </table>
  <div id="jobs-loading" v-if="jobsLoading" class="loading">
    <div class="spinner-wrapper">
      <b-spinner variant="primary" style="width: 3rem; height: 3rem;" label="Loading"></b-spinner>
    </div>
  </div>
</div>
</template>

<script>
export default {
  computed: {
    jobs() { return this.$store.state.jobs },
    jobsLoading() { return this.$store.state.jobsLoading }
  },
  mounted() {
    this.loadJobs();
    this.$store.commit('setLoading', false);
  },
  methods: {
    loadJobs() {
      this.$store.dispatch('loadJobs');
    }
  }
}
</script>