<template>
  <div>
    <v-container justify="center">
      <v-banner>
        <h4>Gestion des demandes d'impression</h4>
      </v-banner>
      <v-container align="center">
        <v-layout row>
          <v-flex v-for="item of requests" :key="item.request_id">
            <ImpressionRequest
              :id="item.request_id"
              :admin="true"
              @stopReload="stop_reload"
              @startReload="start_reload"
            />
          </v-flex>
        </v-layout>
      </v-container>
    </v-container>
  </div>
</template>

<script>
// 'id', 'stl', 'admin', 'title', 'description', 'status', 'project', 'fullname', 'gcode', 'queue', 'recup_id'
import ImpressionRequest from "@/components/ImpressionRequestCard";
export default {
  mounted() {
    // executed when the user requests this page
    this.start_reload();
  },
  beforeDestroy() {
    this.stop_reload();
  },
  computed: {
    requests() {
      return this.$store.state.admin_requests;
    }
  },
  methods: {
    load() {
      if (this.no_load) return;
      this.$store.dispatch("update_requests", this.filters);
      setTimeout(this.load, 9000);
    },
    stop_reload() {
      this.no_load = true;
    },
    start_reload() {
      this.no_load = false;
      this.load();
    }
  },
  data() {
    return {
      filters: {
        status: [],
        no_load: false
      }
    };
  },
  components: {
    ImpressionRequest
  }
};
</script>
