Skip to content
Snippets Groups Projects
My_account.vue 13.7 KiB
Newer Older
<template>
  <div v-frag>
    <div class="fourteen wide column">
      <h1>Mon compte</h1>
    </div>

    <div class="row">
      <div class="five wide column">
        <h4 class="ui horizontal divider header">
          PROFIL
        </h4>
        <div class="ui divided list">
          <div class="item">
            <div class="right floated content">
              <div class="description">
                <span v-if="user.username">{{ user.username }} </span>
              </div>
            </div>
            <div class="content">
              Nom d'utilisateur
            </div>
          </div>
          <div class="item">
            <div class="right floated content">
              <div class="description">
                {{ userFullname }}
              </div>
            </div>
            <div class="content">
              Nom complet
            </div>
          </div>
          <div class="item">
            <div class="right floated content">
              <div class="description">
                {{ user.email }}
              </div>
            </div>
            <div class="content">
              Adresse e-mail
            </div>
          </div>
          <div class="item">
            <div class="right floated content">
              <div class="description">
                {{ user.is_superuser ? "Oui" : "Non" }}
              </div>
            </div>
            <div class="content">
              Administrateur
            </div>
        <h4 class="ui horizontal divider header">
          MES PROJETS
        </h4>
Timothee P's avatar
Timothee P committed
          <div
            v-for="project in projectsArray"
            :key="project.slug"
            class="item"
          >
            <div
              v-if="user_permissions[project.slug].can_view_project"
              v-frag
            >
Timothee P's avatar
Timothee P committed
              <div class="ui tiny image">
                <img
                  v-if="project.thumbnail"
                  class="ui small image"
                  :src="
                    project.thumbnail.includes('default')
                      ? require('@/assets/img/default.png')
                      : DJANGO_BASE_URL + project.thumbnail + refreshId()
                  "
                  height="200"
Timothee P's avatar
Timothee P committed
              <div class="middle aligned content">
                <router-link
                  :to="{
                    name: 'project_detail',
                    params: { slug: project.slug },
                  }"
                  class="header"
                  {{ project.title }}
                </router-link>
Timothee P's avatar
Timothee P committed
                <div class="description">
                  <p>{{ project.description }}</p>
                </div>
                <div class="meta">
                  <span
                    class="right floated"
                  >Projet {{ project.moderation ? "" : "non" }} modéré</span>
                  <span>Niveau d'autorisation requis :
                    {{ project.access_level_pub_feature }}</span><br>
Timothee P's avatar
Timothee P committed
                  <span>
                    Mon niveau d'autorisation :
                    <span v-if="USER_LEVEL_PROJECTS && project">{{
                      USER_LEVEL_PROJECTS[project.slug]
                    }}</span>
                    <span v-if="user && user.is_administrator">{{
                      "+ Gestionnaire métier"
                    }}</span>
                  </span>
                </div>
                <div class="meta">
                  <span
                    class="right floated"
                    :data-tooltip="`Projet créé le ${project.created_on}`"
                  >
                    <i class="calendar icon" />&nbsp;{{ project.created_on }}
Timothee P's avatar
Timothee P committed
                  </span>
                  <span data-tooltip="Membres">
                    {{ project.nb_contributors }}&nbsp;<i class="user icon" />
Timothee P's avatar
Timothee P committed
                  </span>
                  <span data-tooltip="Signalements publiés">
Timothee P's avatar
Timothee P committed
                    {{ project.nb_published_features }}&nbsp;<i
                      class="map marker icon"
Timothee P's avatar
Timothee P committed
                  </span>
                  <span data-tooltip="Commentaires">
                    {{ project.nb_published_features_comments }}&nbsp;<i
                      class="comment icon"
Timothee P's avatar
Timothee P committed
                  </span>
                </div>

          <div
            :class="['ui inverted dimmer', { active: projectsLoading }]"
          >
            <div class="ui text loader">
              Récupération des projets en cours...
            </div>
          </div>
Timothee P's avatar
Timothee P committed
          <!-- PAGINATION -->
          <Pagination
            v-if="count"
            :nb-pages="Math.ceil(count/10)"
            :on-page-change="SET_CURRENT_PAGE"
            @change-page="changePage"
          />
    <div class="row">
      <div class="fourteen wide column">
        <div class="ui three stackable cards">
          <div class="red card">
            <div class="content">
              <div class="center aligned header">
                Mes dernières notifications reçues
              </div>
              <div class="center aligned description">
                <div class="ui relaxed list">
                  <div
                    v-for="item in events"
                    :key="item.id"
                    class="item"
                  >
                      <span v-if="item.event_type === 'create'">
                          :href="modifyUrl(item.related_feature.feature_url)"
                          :href="modifyUrl(item.related_feature.feature_url)"
                        >
                          Commentaire créé
                        </a>
                        <a
                          v-else-if="item.object_type === 'attachment'"
                          :href="modifyUrl(item.related_feature.feature_url)"
                        >
                          Pièce jointe ajoutée
                        </a>
                        <a
                          v-else-if="item.object_type === 'project'"
                          :href="modifyUrl(item.project_url)"
                      </span>
                      <span v-else-if="item.event_type === 'update'">
                          :href="modifyUrl(item.related_feature.feature_url || item.project_url)"
                        >
                          Signalement mis à jour
                        </a>
                        <a
                          v-else-if="item.object_type === 'project'"
                          :href="modifyUrl(item.project_url)"
                        >à Projet mis à jour
                      </span>
                      <span v-else-if="item.event_type === 'delete'">
                        <span v-if="item.object_type === 'feature'">
                          Signalement supprimé({{ item.data.feature_title }})
                        </span>
                        <i v-else>Événement inconnu</i>
                      </span>

                      <span
                        v-if="item.object_type !== 'project'"
                      >
                        ({{ item.related_feature.title ?
                          item.related_feature.title :
                          'signalement supprimé'
                        }})
                      </span>

                        <i>[ {{ item.created_on }}
                          <span v-if="user.is_authenticated">
                            , par {{ item.display_user }}
                          </span>
                  <i
                    v-if="!events || events.length === 0"
                  >Aucune notification pour le moment.</i>
                </div>
              </div>
            </div>
          </div>
          <div class="orange card">
            <div class="content">
              <div class="center aligned header">
                Mes derniers signalements
              </div>
              <div class="center aligned description">
                <div class="ui relaxed list">
                  <div
                    v-for="item in features"
                    :key="item.id"
                    class="item"
                  >
                          v-if="item.related_feature && item.related_feature.feature_url"
                          :href="modifyUrl(item.related_feature.feature_url)"
                        >{{ item.related_feature.title }}</a>
                        <span
                          v-else
                          class="meta"
                        ><del>{{ item.data.feature_title }}</del>&nbsp;(supprimé)</span>
                        <i>[ {{ item.created_on }}
                          <span v-if="user.is_authenticated">
                            , par {{ item.display_user }}
                          </span>
                  <i
                    v-if="!features || features.length === 0"
                  >Aucun signalement pour le moment.</i>
                </div>
              </div>
            </div>
          </div>
          <div class="yellow card">
            <div class="content">
              <div class="center aligned header">
                Mes derniers commentaires
              </div>
              <div class="center aligned description">
                <div class="ui relaxed list">
                  <div
                    v-for="item in comments"
                    :key="item.id"
                    class="item"
                  >
                          :href="modifyUrl(item.related_feature.feature_url)"
                        >"{{ item.related_comment.comment }}"</a>
                        <i>[ {{ item.created_on }}
                          <span v-if="user.is_authenticated">
                            , par {{ item.display_user }}
                          </span>
                  <i
                    v-if="!comments || comments.length === 0"
                  >Aucun commentaire pour le moment.</i>
import frag from 'vue-frag';
Timothee P's avatar
Timothee P committed
import { mapActions, mapMutations, mapState } from 'vuex';
import miscAPI from '@/services/misc-api';
Timothee P's avatar
Timothee P committed
import Pagination from '@/components/Pagination.vue';

  name: 'MyAccount',
Timothee P's avatar
Timothee P committed
  components: {
    Pagination,
  },

Timothee P's avatar
Timothee P committed
      projectsLoading: true,
Timothee P's avatar
Timothee P committed
    ...mapState([
Timothee P's avatar
Timothee P committed
      'user',
      'USER_LEVEL_PROJECTS',
      'user_permissions',
Timothee P's avatar
Timothee P committed
    ]),
Florent Lavelle's avatar
Florent Lavelle committed
    ...mapState('projects', [
Timothee P's avatar
Timothee P committed
      'projects',
      'count',
Timothee P's avatar
Timothee P committed
    ]),
      return this.$store.state.configuration.VUE_APP_DJANGO_BASE;
    },
      if (this.user.first_name || this.user.last_name)
        return this.user.first_name + ' ' + this.user.last_name;
    isSharedProject() {
      return this.$route.path.includes('projet-partage');
    },

Timothee P's avatar
Timothee P committed
    projectsArray() { //* if only one project, only project object is returned
      return Array.isArray(this.projects) ? this.projects : [this.projects];
  created(){
    this.RESET_PROJECTS_FILTER(); //* empty remaining filters in store
Timothee P's avatar
Timothee P committed
    this.SET_PROJECTS([]); //* empty previous project to avoid undefined user_permissions[project.slug]
    this.getData();
    this.getEvents();
  },
Timothee P's avatar
Timothee P committed
    ...mapActions('projects', [
      'GET_PROJECTS',
    ]),
    ...mapMutations('projects', [
      'SET_PROJECTS',
Timothee P's avatar
Timothee P committed
    ]),
    ...mapMutations('projects', [
      'SET_CURRENT_PAGE',
    ]),

      return '?ver=' + Math.random();
leandro's avatar
leandro committed
    getEvents(){
      miscAPI.getUserEvents(this.$route.params.slug)
leandro's avatar
leandro committed
        .then((data)=>{
          this.events = data.events;
          this.features = data.features;
          this.comments = data.comments;
      if (url && this.isSharedProject) {
        return url.replace('projet', 'projet-partage');
      }
      return url;
Timothee P's avatar
Timothee P committed
    },

    getData(page) {
      this.GET_PROJECTS({ myaccount: true, projectSlug: this.$route.params.slug, page })
Timothee P's avatar
Timothee P committed
        .then(() => this.projectsLoading = false)
        .catch(() => this.projectsLoading = false);
    },

    changePage(e) {
      this.getData(e);
    },
leandro's avatar
leandro committed
  }