<template>
  <div class="external-storage-settings">
    <button-input type="primary"
                  :disabled="fileIndexQueued"
                  @click="executeFileIndexer">
      find media files
      <loading-icon v-if="fileIndexQueued"/>
    </button-input>
  </div>
</template>

<script>
import ButtonInput from "@/components/base/button-input";
import LoadingIcon from "@/components/base/loading-icon";

export default {
  name: "external-storage-settings",
  components: {LoadingIcon, ButtonInput},
  props: ['jobs'],
  computed: {
    fileIndexQueued: function () {
      return this.jobs
          .filter(j => !j.finished && j.type === 'Find Media Files')
          .length > 0;
    }
  },
  methods: {
    executeFileIndexer: function () {
      // TODO then / error
      this.$root.socket.post(`/projects/${this.$root.project.identifier}/external_storage`, {'execute': true});
    }
  }
}
</script>

<style scoped>
.loading-icon {
  float: right;
  width: 1.3rem;
  height: 1.3rem;
  margin: -0.15rem -0.4rem -0.15rem 0.5rem;
}
</style>