Skip to content
Snippets Groups Projects
FeatureTable.vue 5.16 KiB
Newer Older
Florent Lavelle's avatar
Florent Lavelle committed
<template>
  <div>
Florent Lavelle's avatar
Florent Lavelle committed
    <table
      class="ui very basic table"
      aria-describedby="Table des données du signalement"
    >
Florent Lavelle's avatar
Florent Lavelle committed
      <tbody>
            <strong> Type de signalement </strong>
            <FeatureTypeLink :feature-type="featureType" />
Florent Lavelle's avatar
Florent Lavelle committed
        <tr
Florent Lavelle's avatar
Florent Lavelle committed
          v-for="(field, index) in currentFeature.feature_data"
          :key="'field' + index"
        >
Florent Lavelle's avatar
Florent Lavelle committed
          <td>
            <strong>{{ field.label }}</strong>
          </td>
          <td>
            <strong class="ui form">
              <span
                v-if="fastEditionMode && extra_forms.length > 0"
Timothee P's avatar
Timothee P committed
                :id="field.label"
              >
                <FeatureExtraForm
                  :field="getExtraForm(field)"
                />
              </span>
Florent Lavelle's avatar
Florent Lavelle committed
              <i
                v-else-if="field.field_type === 'boolean'"
Florent Lavelle's avatar
Florent Lavelle committed
                :class="[
                  'icon',
                  field.value ? 'olive check' : 'grey times',
                ]"
                aria-hidden="true"
              />
              <span v-else>
                {{ field.value }}
              </span>
            </strong>
          </td>
        </tr>
Florent Lavelle's avatar
Florent Lavelle committed
        <tr>
Florent Lavelle's avatar
Florent Lavelle committed
          <td>
Florent Lavelle's avatar
Florent Lavelle committed
            Auteur
Florent Lavelle's avatar
Florent Lavelle committed
          </td>
Florent Lavelle's avatar
Florent Lavelle committed
          <td>{{ currentFeature.display_creator }}</td>
        </tr>
        <tr>
Florent Lavelle's avatar
Florent Lavelle committed
          <td>
Florent Lavelle's avatar
Florent Lavelle committed
            Statut
Florent Lavelle's avatar
Florent Lavelle committed
          </td>
Florent Lavelle's avatar
Florent Lavelle committed
          <td>
Florent Lavelle's avatar
Florent Lavelle committed
            <i
Florent Lavelle's avatar
Florent Lavelle committed
              v-if="currentFeature.status"
              :class="['icon', statusIcon]"
Florent Lavelle's avatar
Florent Lavelle committed
              aria-hidden="true"
Florent Lavelle's avatar
Florent Lavelle committed
            />
            <FeatureEditStatusField
              v-if="fastEditionMode && form"
              :status="form.status.value"
              class="inline"
            />
            <span v-else>
              {{ statusLabel }}
            </span>
Florent Lavelle's avatar
Florent Lavelle committed
          </td>
        </tr>
        <tr>
Florent Lavelle's avatar
Florent Lavelle committed
          <td>
Florent Lavelle's avatar
Florent Lavelle committed
            Date de création
Florent Lavelle's avatar
Florent Lavelle committed
          </td>
Florent Lavelle's avatar
Florent Lavelle committed
          <td v-if="currentFeature.created_on">
            {{ currentFeature.created_on | formatDate }}
          </td>
        </tr>
        <tr>
Florent Lavelle's avatar
Florent Lavelle committed
          <td>
Florent Lavelle's avatar
Florent Lavelle committed
            Date de dernière modification
Florent Lavelle's avatar
Florent Lavelle committed
          </td>
Florent Lavelle's avatar
Florent Lavelle committed
          <td v-if="currentFeature.updated_on">
            {{ currentFeature.updated_on | formatDate }}
          </td>
        </tr>
      </tbody>
    </table>

    <h3>Liaison entre signalements</h3>
Florent Lavelle's avatar
Florent Lavelle committed
    <table
      class="ui very basic table"
      aria-describedby="Table des signalements lié à ce signalement"
    >
Florent Lavelle's avatar
Florent Lavelle committed
      <tbody>
        <tr
          v-for="(link, index) in linked_features"
          :key="link.feature_to.title + index"
        >
Florent Lavelle's avatar
Florent Lavelle committed
          <th
            v-if="link.feature_to.feature_type_slug"
            scope="row"
          >
Florent Lavelle's avatar
Florent Lavelle committed
            {{ link.relation_type_display }}
Florent Lavelle's avatar
Florent Lavelle committed
          </th>
          <td
            v-if="link.feature_to.feature_type_slug"
          >
            <a
              class="pointer"
              @click="toFeature(link)"
            >{{ link.feature_to.title }} </a>
Florent Lavelle's avatar
Florent Lavelle committed
            ({{ link.feature_to.display_creator }} -
            {{ link.feature_to.created_on }})
          </td>
        </tr>
        <tr v-if="linked_features.length === 0">
          <td>
            <em>
              Aucune liaison associée au signalement.
            </em>
          </td>
        </tr>
Florent Lavelle's avatar
Florent Lavelle committed
      </tbody>
    </table>
  </div>
</template>

<script>

import { mapState } from 'vuex';
import FeatureTypeLink from '@/components/FeatureType/FeatureTypeLink';
import FeatureEditStatusField from '@/components/Feature/FeatureEditStatusField';
import FeatureExtraForm from '@/components/Feature/Edit/FeatureExtraForm';
import { statusChoices } from '@/utils';
Florent Lavelle's avatar
Florent Lavelle committed

export default {
Florent Lavelle's avatar
Florent Lavelle committed

Florent Lavelle's avatar
Florent Lavelle committed
  name: 'FeatureTable',
    FeatureTypeLink,
    FeatureEditStatusField,
    FeatureExtraForm,
Florent Lavelle's avatar
Florent Lavelle committed
  filters: {
    formatDate(value) {
      let date = new Date(value);
      date = date.toLocaleString().replace(',', '');
      return date.substr(0, date.length - 3); //* quick & dirty way to remove seconds from date
    },
  },

  props: {
    featureType: {
      type: Object,
      default: () => {},
    },
    fastEditionMode: {
      type: Boolean,
      default: false,
    }
Florent Lavelle's avatar
Florent Lavelle committed
  computed: {
    ...mapState('feature', [
      'currentFeature',
      'linked_features',
Florent Lavelle's avatar
Florent Lavelle committed
    ]),

    statusIcon() {
      switch (this.currentFeature.status) {
      case 'archived':
        return 'grey archive';
      case 'pending':
        return 'teal hourglass outline';
      case 'published':
        return 'olive check';
      case 'draft':
        return 'orange pencil alternate';
      default:
        return '';
      }
    },
    statusLabel() {
      const status = statusChoices.find(
Florent Lavelle's avatar
Florent Lavelle committed
        (el) => el.value === this.currentFeature.status
      );
      return status ? status.name : '';
    },
  },

  methods: {
    toFeature(link) {
      this.$emit('tofeature', {
        name: 'details-signalement',
        params: {
          slug_type_signal: link.feature_to.feature_type_slug,
          slug_signal: link.feature_to.feature_id,
        },
      });
    },

    getExtraForm(field) {
      return this.extra_forms.find(exF => exF.label === field.label);
Florent Lavelle's avatar
Florent Lavelle committed
    }
  }

};
</script>