Skip to content
Snippets Groups Projects
FeatureHeader.vue 4.9 KiB
Newer Older
Florent Lavelle's avatar
Florent Lavelle committed
<template>
  <div>
    <h1 class="ui header">
      <div class="content">
        {{ currentFeature.title || currentFeature.feature_id }}
        <div class="ui icon right floated compact buttons">
          <span
            v-if="featuresCount"
            id="feature-count"
            class="ui button tiny-margin basic"
          >
            {{ parseInt($route.query.offset) + 1 }} sur {{ featuresCount }}
          </span>
          <button
            v-if="queryparams"
            id="previous-feature"
            :class="['ui button button-hover-green tiny-margin', { disabled: queryparams.previous < 0 }]"
            data-tooltip="Voir le précédent signalement"
            data-position="bottom center"
            @click="toFeature('previous')"
          >
            <i
              class="angle left fitted icon"  
              aria-hidden="true"
            />
          </button>
          <button
            v-if="queryparams"
            id="next-feature"
            :class="[
              'ui button button-hover-green tiny-margin',
              { disabled: queryparams.next >= featuresCount }
            ]"
            data-tooltip="Voir le prochain signalement"
            data-position="bottom center"
            @click="toFeature('next')"
          >
            <i
              class="angle right fitted icon"
              aria-hidden="true"
            />
          </button>

Florent Lavelle's avatar
Florent Lavelle committed
          <router-link
            v-if="permissions && permissions.can_create_feature"
Florent Lavelle's avatar
Florent Lavelle committed
            :to="{
              name: 'ajouter-signalement',
              params: {
                slug_type_signal: $route.params.slug_type_signal || featureType.slug,
Florent Lavelle's avatar
Florent Lavelle committed
              },
            }"
            class="ui button button-hover-green tiny-margin"
Florent Lavelle's avatar
Florent Lavelle committed
            data-tooltip="Ajouter un signalement"
Florent Lavelle's avatar
Florent Lavelle committed
          >
Florent Lavelle's avatar
Florent Lavelle committed
            <i
Florent Lavelle's avatar
Florent Lavelle committed
              aria-hidden="true"
            />
Florent Lavelle's avatar
Florent Lavelle committed
          </router-link>
Florent Lavelle's avatar
Florent Lavelle committed
          <router-link
            v-if="slugSignal &&
              ((permissions && permissions.can_update_feature) ||
Florent Lavelle's avatar
Florent Lavelle committed
                isFeatureCreator ||
Florent Lavelle's avatar
Florent Lavelle committed
            "
Florent Lavelle's avatar
Florent Lavelle committed
            :to="{
              name: 'editer-signalement',
              params: {
                slug_signal: slugSignal,
                slug_type_signal: $route.params.slug_type_signal || featureType.slug,
Florent Lavelle's avatar
Florent Lavelle committed
              },
              query: $route.query
Florent Lavelle's avatar
Florent Lavelle committed
            }"
            class="ui button button-hover-orange tiny-margin"
            data-tooltip="Éditer le signalement"
            data-position="bottom center"
Florent Lavelle's avatar
Florent Lavelle committed
          >
Florent Lavelle's avatar
Florent Lavelle committed
            <i
              class="inverted grey pencil alternate icon"
              aria-hidden="true"
            />
Florent Lavelle's avatar
Florent Lavelle committed
          </router-link>
Florent Lavelle's avatar
Florent Lavelle committed
          <a
            v-if="((permissions && permissions.can_update_feature) || isFeatureCreator) && isOnline"
            id="currentFeature-delete"
            class="ui button button-hover-red tiny-margin"
            data-tooltip="Supprimer le signalement"
            data-position="bottom right"
            @click="$emit('setIsCancelling')"
Florent Lavelle's avatar
Florent Lavelle committed
          >
Florent Lavelle's avatar
Florent Lavelle committed
            <i
              class="inverted grey trash alternate icon"
              aria-hidden="true"
            />
Florent Lavelle's avatar
Florent Lavelle committed
          </a>
        </div>
        <div class="ui hidden divider" />
        <div class="sub header prewrap">
          {{ currentFeature.description }}
        </div>
      </div>
    </h1>
  </div>
</template>

<script>

import { mapState, mapGetters } from 'vuex';

export default {
Florent Lavelle's avatar
Florent Lavelle committed

Florent Lavelle's avatar
Florent Lavelle committed
  name: 'FeatureHeader',

  props: {
    featuresCount : {
      type: Number,
      default: null,
    },
    slugSignal: {
      type: String,
      default: '',
    },
    featureType: {
      type: Object,
      default: () => {},
    },
  },

Florent Lavelle's avatar
Florent Lavelle committed
  computed: {
    ...mapState([
      'user',
      'USER_LEVEL_PROJECTS',
      'isOnline',
    ]),
    ...mapState('feature', [
      'currentFeature'
    ]),

    ...mapGetters([
      'permissions',
    ]),

    isFeatureCreator() {
      if (this.currentFeature && this.user) {
        return this.currentFeature.creator === this.user.id;
      }
      return false;
    },

    isModerator() {
      return this.USER_LEVEL_PROJECTS && this.USER_LEVEL_PROJECTS[this.$route.params.slug] === 'Modérateur';
Florent Lavelle's avatar
Florent Lavelle committed
    },

    queryparams() {
      return this.$route.query.offset >= 0 ? {
        previous: parseInt(this.$route.query.offset) - 1,
        next: parseInt(this.$route.query.offset) + 1
      } : null;
    },
  },

  methods: {
    toFeature(direction) {
      this.$emit('tofeature', {
        name: 'details-signalement-filtre',
        params: {
          slug_type_signal: this.currentFeature.feature_type.slug,
        },
        query: {
          ...this.$route.query,
          offset: this.queryparams[direction]
        }
      });
    }
  }
Florent Lavelle's avatar
Florent Lavelle committed
};
</script>

<style>
#next-feature {
  margin-right: .5rem !important;
}
</style>