Skip to content
Snippets Groups Projects
FeatureTable.vue 3.04 KiB
Newer Older
Florent Lavelle's avatar
Florent Lavelle committed
<template>
  <div>
    <table class="ui very basic table">
      <tbody>
        <div
          v-for="(field, index) in currentFeature.feature_data"
          :key="'field' + index"
        >
          <tr v-if="field">
            <td>
              <b>{{ field.label }}</b>
            </td>
            <td>
              <b>
Florent Lavelle's avatar
Florent Lavelle committed
                <em
Florent Lavelle's avatar
Florent Lavelle committed
                  v-if="field.field_type === 'boolean'"
                  :class="[
                    'icon',
                    field.value ? 'olive check' : 'grey times',
                  ]"
                />
                <span v-else>
                  {{ field.value }}
                </span>
              </b>
            </td>
          </tr>
        </div>
        <tr>
          <td>Auteur</td>
          <td>{{ currentFeature.display_creator }}</td>
        </tr>
        <tr>
          <td>Statut</td>
          <td>
Florent Lavelle's avatar
Florent Lavelle committed
            <em
Florent Lavelle's avatar
Florent Lavelle committed
              v-if="currentFeature.status"
              :class="['icon', statusIcon]"
            />
            {{ statusLabel }}
          </td>
        </tr>
        <tr>
          <td>Date de création</td>
          <td v-if="currentFeature.created_on">
            {{ currentFeature.created_on | formatDate }}
          </td>
        </tr>
        <tr>
          <td>Date de dernière modification</td>
          <td v-if="currentFeature.updated_on">
            {{ currentFeature.updated_on | formatDate }}
          </td>
        </tr>
      </tbody>
    </table>

    <h3>Liaison entre signalements</h3>
    <table class="ui very basic table">
      <tbody>
        <tr
          v-for="(link, index) in linked_features"
          :key="link.feature_to.title + index"
        >
          <td v-if="link.feature_to.feature_type_slug">
            {{ link.relation_type_display }}
            <a @click="pushNgo(link)">{{ link.feature_to.title }} </a>
            ({{ link.feature_to.display_creator }} -
            {{ link.feature_to.created_on }})
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>

import { mapState } from 'vuex';

export default {
  
  name: 'FeatureTable',

  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
    },
  },

  computed: {
    ...mapState('feature', [
      'currentFeature',
      'linked_features',
      'statusChoices'
    ]),

    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 = this.statusChoices.find(
        (el) => el.value === this.currentFeature.status
      );
      return status ? status.name : '';
    },
  },

  methods: {
    pushNgo(link) {
      this.$emit('push-n-go', link);
    }
  }

};
</script>