Skip to content
Snippets Groups Projects
FeatureDetail.vue 8.92 KiB
Newer Older
Florent Lavelle's avatar
Florent Lavelle committed
  <div
    id="feature-detail"
    class="page"
  >
Florent Lavelle's avatar
Florent Lavelle committed
      v-if="currentFeature"
      class="ui grid"
Florent Lavelle's avatar
Florent Lavelle committed
        <div class="sixteen wide column">
          <FeatureHeader />
Florent Lavelle's avatar
Florent Lavelle committed
        <div class="eight wide column">
          <FeatureTable
            @pushNGo="pushNgo"
          />
Florent Lavelle's avatar
Florent Lavelle committed
        <div class="eight wide column">
          <div
            id="map"
            ref="map"
          />
Florent Lavelle's avatar
Florent Lavelle committed
        <div class="eight wide column">
          <FeatureAttachements
            :attachments="attachments"
          />
Florent Lavelle's avatar
Florent Lavelle committed
        <div class="eight wide column">
          <FeatureComments
            :events="events"
          />
        v-if="isCanceling"
        class="ui dimmer modals page transition visible active"
        style="display: flex !important"
        <div
          :class="[
            'ui mini modal subscription',
            { 'active visible': isCanceling },
          ]"
        >
Florent Lavelle's avatar
Florent Lavelle committed
          <em
            class="close icon"
            @click="isCanceling = false"
          />
Florent Lavelle's avatar
Florent Lavelle committed
            <em class="trash alternate icon" />
            Supprimer le signalement
          </div>
          <div class="actions">
Timothee P's avatar
Timothee P committed
            <button
              type="button"
              class="ui red compact fluid button"
              @click="deleteFeature"
Timothee P's avatar
Timothee P committed
              Confirmer la suppression
            </button>
Florent Lavelle's avatar
Florent Lavelle committed
    <div v-else>
      Pas de signalement correspondant trouvé
    </div>
Florent Lavelle's avatar
Florent Lavelle committed
import { mapState, mapActions, mapMutations } from 'vuex';
import { mapUtil } from '@/assets/js/map-util.js';
Florent Lavelle's avatar
Florent Lavelle committed

import axios from '@/axios-client.js';
Florent Lavelle's avatar
Florent Lavelle committed
import featureAPI from '@/services/feature-api';

import FeatureHeader from '@/components/Feature/Detail/FeatureHeader';
import FeatureTable from '@/components/Feature/Detail/FeatureTable';
import FeatureAttachements from '@/components/Feature/Detail/FeatureAttachements';
import FeatureComments from '@/components/Feature/Detail/FeatureComments';
  name: 'FeatureDetail',
Florent Lavelle's avatar
Florent Lavelle committed
  components: {
    FeatureHeader,
    FeatureTable,
    FeatureAttachements,
    FeatureComments
Timothee P's avatar
Timothee P committed
  },

      attachments: [],
          title: '',
          file: null,
          id_for_label: 'add-comment',
          html_name: 'add-comment',
          errors: '',
      events: [],
      isCanceling: false,
      projectSlug: this.$route.params.slug,
Timothee P's avatar
Timothee P committed
    ...mapState('projects', [
      'project'
    ]),
Florent Lavelle's avatar
Florent Lavelle committed
    ...mapState('feature-type', [
      'feature_types'
    ]),
    ...mapState('feature', [
Florent Lavelle's avatar
Florent Lavelle committed
      'currentFeature'
Timothee P's avatar
Timothee P committed

  created() {
Florent Lavelle's avatar
Florent Lavelle committed
    this.SET_CURRENT_FEATURE_TYPE_SLUG(this.$route.params.slug_type_signal);
Timothee P's avatar
Timothee P committed
    this.getFeatureEvents();
    this.getFeatureAttachments();
    this.getLinkedFeatures();
  },

  mounted() {
Florent Lavelle's avatar
Florent Lavelle committed
    this.DISPLAY_LOADER('Recherche du signalement');
Timothee P's avatar
Timothee P committed
    if (!this.project) {
      // Chargements des features et infos projet en cas d'arrivée directe sur la page ou de refresh
      axios.all([
Florent Lavelle's avatar
Florent Lavelle committed
        this.GET_PROJECT(this.$route.params.slug),
        this.GET_PROJECT_INFO(this.$route.params.slug),
        this.GET_PROJECT_FEATURE({
Timothee P's avatar
Timothee P committed
          project_slug: this.$route.params.slug,
          feature_id: this.$route.params.slug_signal
        })])
        .then(() => {
Florent Lavelle's avatar
Florent Lavelle committed
          this.DISCARD_LOADER();
Timothee P's avatar
Timothee P committed
          this.initMap();
        });
Florent Lavelle's avatar
Florent Lavelle committed
    } if (!this.currentFeature || this.currentFeature.feature_id !== this.$route.params.slug_signal) {
      this.GET_PROJECT_FEATURE({
Timothee P's avatar
Timothee P committed
        project_slug: this.$route.params.slug,
        feature_id: this.$route.params.slug_signal
      })
        .then(() => {
Florent Lavelle's avatar
Florent Lavelle committed
          this.DISCARD_LOADER();
Timothee P's avatar
Timothee P committed
          this.initMap();
        });
    } else {
Florent Lavelle's avatar
Florent Lavelle committed
      this.DISCARD_LOADER();
Timothee P's avatar
Timothee P committed
      this.initMap();
    }
  },

  beforeDestroy() {
    this.$store.commit('CLEAR_MESSAGES');
Timothee P's avatar
Timothee P committed
  },

Florent Lavelle's avatar
Florent Lavelle committed
    ...mapMutations([
      'DISPLAY_LOADER',
      'DISCARD_LOADER'
    ]),
    ...mapMutations('feature-type', [
      'SET_CURRENT_FEATURE_TYPE_SLUG'
    ]),
    ...mapActions('projects', [
      'GET_PROJECT',
      'GET_PROJECT_INFO'
    ]),
    ...mapActions('feature', [
Florent Lavelle's avatar
Florent Lavelle committed
      'GET_PROJECT_FEATURE',
      'GET_PROJECT_FEATURES'
    ]),
    pushNgo(link) {
      this.$router.push({
        name: 'details-signalement',
        params: {
          slug_type_signal: link.feature_to.feature_type_slug,
          slug_signal: link.feature_to.feature_id,
        },
      });
      this.getFeatureEvents();
      this.getFeatureAttachments();
      this.getLinkedFeatures();
      this.addFeatureToMap();
    },

leandro's avatar
leandro committed
    goBackToProject(message) {
      this.$router.push({
        name: 'project_detail',
leandro's avatar
leandro committed
        params: {
leandro's avatar
leandro committed
          message,
        },
      });
    },
Florent Lavelle's avatar
Florent Lavelle committed
        .dispatch('feature/DELETE_FEATURE', { feature_id: this.currentFeature.feature_id })
        .then((response) => {
          if (response.status === 204) {
            this.GET_PROJECT_FEATURES({
              project_slug: this.$route.params.slug
            });
    initMap() {
      var mapDefaultViewCenter =
        this.$store.state.configuration.DEFAULT_MAP_VIEW.center;
      var mapDefaultViewZoom =
        this.$store.state.configuration.DEFAULT_MAP_VIEW.zoom;
      this.map = mapUtil.createMap(this.$refs.map, {
        mapDefaultViewCenter,
        mapDefaultViewZoom,
      });

      // Update link to feature list with map zoom and center
      mapUtil.addMapEventListener('moveend', function () {
        // update link to feature list with map zoom and center
        /*var $featureListLink = $("#feature-list-link")
        var baseUrl = $featureListLink.attr("href").split("?")[0]

        $featureListLink.attr("href", baseUrl +`?zoom=${this.map.getZoom()}&lat=${this.map.getCenter().lat}&lng=${this.map.getCenter().lng}`)*/
      });

      // Load the layers.
      // - if one basemap exists, we load the layers of the first one
      // - if not, load the default map and service options
      let layersToLoad = null;
      var baseMaps = this.$store.state.map.basemaps;
      var layers = this.$store.state.map.availableLayers;
DESPRES Damien's avatar
DESPRES Damien committed
        const basemapIndex = 0;
        layersToLoad = baseMaps[basemapIndex].layers;
        layersToLoad.forEach((layerToLoad) => {
          layers.forEach((layer) => {
            if (layer.id === layerToLoad.id) {
              layerToLoad = Object.assign(layerToLoad, layer);
            }
          });
        });
        layersToLoad.reverse();
      }
      mapUtil.addLayers(
        layersToLoad,
        this.$store.state.configuration.DEFAULT_BASE_MAP_SERVICE,
        this.$store.state.configuration.DEFAULT_BASE_MAP_OPTIONS,
        this.$store.state.configuration.DEFAULT_BASE_MAP_SCHEMA_TYPE,
      mapUtil.getMap().dragging.disable();
      mapUtil.getMap().doubleClickZoom.disable();
      mapUtil.getMap().scrollWheelZoom.disable();

      this.addFeatureToMap();
    },

    addFeatureToMap() {
leandro's avatar
leandro committed
      const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature/` +
                  `?feature_id=${this.$route.params.slug_signal}&output=geojson`;
          if (response.data.features.length > 0) {
            const featureGroup = mapUtil.addFeatures(
Florent Lavelle's avatar
Florent Lavelle committed
              this.feature_types
            mapUtil
              .getMap()
              .fitBounds(featureGroup.getBounds(), { padding: [25, 25] });
    getFeatureEvents() {
      featureAPI
        .getFeatureEvents(this.$route.params.slug_signal)
        .then((data) => (this.events = data));
    },

    getFeatureAttachments() {
      featureAPI
        .getFeatureAttachments(this.$route.params.slug_signal)
        .then((data) => (this.attachments = data));
    },

    getLinkedFeatures() {
      featureAPI
        .getFeatureLinks(this.$route.params.slug_signal)
        .then((data) =>
          this.$store.commit('feature/SET_LINKED_FEATURES', data)
Timothee P's avatar
Timothee P committed
<style scoped>
#map {
  width: 100%;
  height: 100%;
  min-height: 250px;
  max-height: 70vh;
}
#feed-event .event {
  margin-bottom: 1em;
}
#feed-event .event .date {
  margin-right: 1em !important;
}
#feed-event .event .extra.text {
  margin-left: 107px;
  margin-top: 0;
}