Skip to content
Snippets Groups Projects
FeatureHeader.vue 7.48 KiB
Newer Older
Florent Lavelle's avatar
Florent Lavelle committed
<template>
  <div>
    <h1 class="ui header">
      <div class="content">
Timothee P's avatar
Timothee P committed
        <span
          v-if="fastEditionMode && form"
          class="form ui half-block"
        >
          <input
            id="feature_detail_title_input"
            :value="form.title"
            type="text"
            required
            maxlength="128"
            name="title"
            @blur="updateTitle"
Timothee P's avatar
Timothee P committed
          >
        </span>
        <span v-else>
          {{ currentFeature.title || currentFeature.feature_id }}
        </span>

Florent Lavelle's avatar
Florent Lavelle committed
        <div class="ui icon right floated compact buttons">
          <router-link
            v-if="displayToListButton"
            id="feature-detail-to-features-list"
            :to="{
              name: 'liste-signalements',
              params: { slug: $route.params.slug },
            }"
            custom
          >
            <div class="ui button tiny-margin teal">
              <i class="ui icon arrow right" />
              Retour à la liste des signalements
            </div>
          </router-link>
          <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>

            v-if="fastEditionMode && userCanFastEdit"
            id="previous-feature"
            :class="['ui button button-hover-orange tiny-margin', { disabled: false }]"
            data-tooltip="Enregistrer les modifications"
            data-position="bottom center"
            @click="$store.dispatch('feature/SEND_FEATURE', $route.name)"
          >
            <i
              class="save 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
              },
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">
          <span
            v-if="fastEditionMode && form"
            class="form ui half-block"
          >
            <textarea
              :value="form.description.value"
              name="description"
              rows="5"
              @blur="updateDescription"
            />
          </span>
          <span v-else>
            {{ currentFeature.description }}
          </span>
Florent Lavelle's avatar
Florent Lavelle committed
        </div>
      </div>
    </h1>
  </div>
</template>

<script>

import { mapState, mapGetters } from 'vuex';

Florent Lavelle's avatar
Florent Lavelle committed
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: () => {},
    },
    fastEditionMode: {
      type: Boolean,
      default: false,
Florent Lavelle's avatar
Florent Lavelle committed
  computed: {
    ...mapState([
      'user',
      'USER_LEVEL_PROJECTS',
      'isOnline',
    ]),
    ...mapState('feature', [
Timothee P's avatar
Timothee P committed
      'currentFeature',
      'form',
Florent Lavelle's avatar
Florent Lavelle committed
    ]),
    ...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
    },

    userCanFastEdit() {
      const superiorRoles = ['contributor', 'super_contributor', 'moderator', 'admin'];
      return this.USER_LEVEL_PROJECTS &&
        superiorRoles.includes(this.USER_LEVEL_PROJECTS[this.$route.params.slug]) ||
          this.user.is_superuser;
    },

    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]
        }
      });
    updateTitle(e) {
Timothee P's avatar
Timothee P committed
      this.$store.commit('feature/UPDATE_FORM_FIELD', { name: 'title', value: e.target.value });
    },

    updateDescription(e) {
      this.$store.commit('feature/UPDATE_FORM_FIELD', { name: 'description', value: e.target.value });
Florent Lavelle's avatar
Florent Lavelle committed
};
</script>

<style>
#next-feature {
  margin-right: .5rem !important;
}
#feature-detail-to-features-list {
  line-height: 0;
  margin-right: 5px;
}
Timothee P's avatar
Timothee P committed
.half-block {
  display: inline-block;
  width: 50%;
}
#feature_detail_title_input {
  font-weight: bold;
  font-size: 2em;
  padding: .25em;
}