All files / components/Admin/Articles/ArticleForm ArticleMedia.vue

100% Statements 6/6
100% Branches 2/2
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109                                                              1x   1x 1x   1x 3x                                                                                                   1x                                          
<template>
  <div class="row w-100 m-0 justify-content-center">
    <div class="image-wrap col-5 position-relative m-2">
      <div
        class="
          image-buttons
          position-absolute
          align-items-center
          justify-content-center
        "
      >
        <button
          class="btn btn-primary m-1"
          type="button"
          v-on:click="setImageIndex(0)"
        >
          show
        </button>
        <button
          class="btn btn-danger m-1"
          type="button"
          v-on:click="deleteFromImages(0)"
        >
          delete
        </button>
      </div>
      <PreloaderImage v-if="image" :image="image" rounded />
    </div>
    <ConfirmModal :id="'confirm-delete-image'" v-on:confirm="confirm" />
  </div>
</template>
 
<script>
import { mapMutations, mapActions, mapGetters } from "vuex";
import { getStrapiMedia } from "~/utils/medias";
 
import PreloaderImage from "~/components/common/PreloaderImage.vue";
import ConfirmModal from "~/components/Admin/common/ConfirmModal.vue";
 
export default {
  name: "ArticleMedia",
  components: { PreloaderImage, ConfirmModal },
  data: () => ({
    image: "",
  }),
  computed: {
    ...mapGetters({
      selected: "admin_articles/selected",
    }),
  },
  watch: {
    selected: {
      handler() {
        if (this.selected) {
          this.image = this.getStrapiMedia(this.selected.image.url);
          this.setImages([this.image]);
        }
      },
      deep: true,
    },
  },
  methods: {
    getStrapiMedia,
    ...mapActions({
      updateArticle: "admin_articles/updateArticle",
    }),
    ...mapMutations({
      updateSelectedImages: "admin_products/updateSelectedImages",
      setImages: "cool_light_box/setImages",
      setImageIndex: "cool_light_box/setImageIndex",
    }),
    deleteFromImages: async function (index) {
      this.removeImageIndex = index;
      this.$root.$emit("bv::show::modal", "confirm-delete-image");
    },
 
    confirm: async function () {
      const article = { ...this.selected, image: null };
      await this.updateArticle(article);
    },
  },
  mounted() {
    if (this.selected) {
      this.image = this.getStrapiMedia(this.selected.image.url);
      this.setImages([this.image]);
    }
  },
};
</script>
 
<style scoped>
.image-wrap > .image-buttons {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  display: none;
  border-radius: 10px;
  background-color: rgba(0, 0, 0, 0.663);
}
 
.image-wrap:hover > .image-buttons {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
}
</style>