Skip to content
Snippets Groups Projects
AppHeader.vue 11.9 KiB
Newer Older
Florent Lavelle's avatar
dev
Florent Lavelle committed
<template>
Florent Lavelle's avatar
dev
Florent Lavelle committed
    <div class="menu container">
      <div class="ui inverted icon menu">
        <router-link
          :is="isSharedProject ? 'span' : 'router-link'"
          :to="isSharedProject ? '' : '/'"
          :class="['header item', {disable: isSharedProject}]"
        >
          <img
            class="ui right spaced image"
Florent Lavelle's avatar
Florent Lavelle committed
            alt="Logo de l'application"
Florent Lavelle's avatar
dev
Florent Lavelle committed
            :src="logo"
          >
          <span class="desktop">
            {{ APPLICATION_NAME }}
          </span>
        </router-link>
        <div
          v-if="width <= 560 || (width > 560 && project)"
          id="menu-dropdown"
          :class="['ui dropdown item', { 'active visible': menuIsOpen }]"
          @click="menuIsOpen = !menuIsOpen"
        >
          <div
            v-if="!isOnline"
            class="crossed-out mobile"
          >
            <i
              class="wifi icon"
Timothee P's avatar
Timothee P committed
              aria-hidden="true"
            />
          </div>
          <span class="expand-center">
Florent Lavelle's avatar
dev
Florent Lavelle committed
            <span v-if="project"> Projet : {{ project.title }} </span>
          </span>
Florent Lavelle's avatar
Florent Lavelle committed
          <i
            class="dropdown icon"
            aria-hidden="true"
          />
Florent Lavelle's avatar
dev
Florent Lavelle committed
          <div
            :class="[
              'menu dropdown-list transition',
              { 'visible': menuIsOpen },
Florent Lavelle's avatar
dev
Florent Lavelle committed
            ]"
            style="z-index: 401"
          >
            <router-link
              v-if="project"
              :to="{
                name: 'project_detail',
                params: { slug: project.slug },
              }"
              class="item"
            >
Florent Lavelle's avatar
Florent Lavelle committed
              <i
                class="home icon"
                aria-hidden="true"
              />Accueil
Florent Lavelle's avatar
dev
Florent Lavelle committed
            </router-link>
            <router-link
              v-if="project"
              :to="{
                name: 'liste-signalements',
                params: { slug: project.slug },
              }"
              class="item"
            >
Florent Lavelle's avatar
Florent Lavelle committed
              <i
                class="list icon"
                aria-hidden="true"
              />Liste & Carte
Florent Lavelle's avatar
dev
Florent Lavelle committed
            </router-link>
            <router-link
              v-if="
Florent Lavelle's avatar
Florent Lavelle committed
                project && isOnline &&
Florent Lavelle's avatar
dev
Florent Lavelle committed
                  (user.is_administrator || user.is_superuser || isAdmin)
              "
              :to="{
                name: 'project_mapping',
                params: { slug: project.slug },
              }"
              class="item"
            >
Florent Lavelle's avatar
Florent Lavelle committed
              <i
                class="map icon"
                aria-hidden="true"
              />Fonds cartographiques
Florent Lavelle's avatar
dev
Florent Lavelle committed
            </router-link>
            <router-link
              v-if="
Florent Lavelle's avatar
Florent Lavelle committed
                project && isOnline &&
Florent Lavelle's avatar
dev
Florent Lavelle committed
                  (user.is_administrator || user.is_superuser || isAdmin)
              "
              :to="{
                name: 'project_members',
                params: { slug: project.slug },
              }"
              class="item"
            >
Florent Lavelle's avatar
Florent Lavelle committed
              <i
                class="users icon"
                aria-hidden="true"
              />Membres
Florent Lavelle's avatar
dev
Florent Lavelle committed
            </router-link>
            <div class="mobile">
              <router-link
Florent Lavelle's avatar
Florent Lavelle committed
                :is="isOnline ? 'router-link' : 'span'"
Florent Lavelle's avatar
dev
Florent Lavelle committed
                v-if="user"
Florent Lavelle's avatar
Florent Lavelle committed
                :to="{
                  name: 'my_account',
                  params: { slug: isSharedProject && $route.params.slug ? $route.params.slug : null }
                }"
Florent Lavelle's avatar
dev
Florent Lavelle committed
                class="item"
              >
                {{ userFullname || user.username || "Utilisateur inconnu" }}
              </router-link>
              <div
                v-if="USER_LEVEL_PROJECTS && project"
                class="item ui label vertical no-hover"
              >
                <!-- super user rights are higher than others -->
                {{ user.is_superuser ? 'Administrateur' : USER_LEVEL_PROJECTS[project.slug] }}
Florent Lavelle's avatar
dev
Florent Lavelle committed
                <br>
              </div>
              <div
                v-if="user && user.is_administrator"
                class="item ui label vertical no-hover"
              >
                Gestionnaire métier
              </div>
              <div
                v-if="!DISABLE_LOGIN_BUTTON"
              >
                <a
                  v-if="user"
                  class="item"
                  @click="logout"
Florent Lavelle's avatar
Florent Lavelle committed
                ><i
                  class="ui logout icon"
                  aria-hidden="true"
                />
Florent Lavelle's avatar
dev
Florent Lavelle committed
                </a>
                <router-link
                  v-else-if="!user && !SSO_LOGIN_URL"
                  :to="{ name : 'login' }"
                  class="item"
                >
                  Se connecter
                </router-link>
                <a
                  v-else
                  class="item"
                  :href="SSO_LOGIN_URL"
                  target="_self"
Florent Lavelle's avatar
dev
Florent Lavelle committed
                >Se connecter</a>
              </div>
            </div>
          </div>
        </div>
Florent Lavelle's avatar
Florent Lavelle committed
        <div class="desktop flex push-right-desktop item title abstract">
Florent Lavelle's avatar
dev
Florent Lavelle committed
          <span>
            {{ APPLICATION_ABSTRACT }}
          </span>
        </div>
        <div class="desktop flex push-right-desktop">
            class="item network-icon"
          >
            <span
              data-tooltip="Vous êtes hors-ligne,
                vos changements pourront être envoyés au serveur au retour de la connexion"
              data-position="bottom right"
            >
              <div class="crossed-out">
Timothee P's avatar
Timothee P committed
                <i
                  class="wifi icon"
                  aria-hidden="true"
                />
Florent Lavelle's avatar
dev
Florent Lavelle committed
          <router-link
Florent Lavelle's avatar
Florent Lavelle committed
            :is="isOnline ? 'router-link' : 'span'"
Florent Lavelle's avatar
dev
Florent Lavelle committed
            v-if="user"
Florent Lavelle's avatar
Florent Lavelle committed
            :to="{
              name: 'my_account',
              params: { slug: isSharedProject && $route.params.slug ? $route.params.slug : null }
            }"
Florent Lavelle's avatar
dev
Florent Lavelle committed
            class="item"
          >
            {{ userFullname || user.username || "Utilisateur inconnu" }}
          </router-link>
          <div
            v-if="USER_LEVEL_PROJECTS && project"
            class="item ui label vertical no-hover"
          >
            <!-- super user rights are higher than others -->
            {{ user.is_superuser ? 'Administrateur' : USER_LEVEL_PROJECTS[project.slug] }}
Florent Lavelle's avatar
dev
Florent Lavelle committed
            <br>
          </div>
          <div
            v-if="user && user.is_administrator"
            class="item ui label vertical no-hover"
          >
            Gestionnaire métier
          </div>
          <div
            v-if="!DISABLE_LOGIN_BUTTON"
          >
            <a
              v-if="user"
              class="item log-item"
              @click="logout"
Florent Lavelle's avatar
Florent Lavelle committed
            ><i
              class="ui logout icon"
              aria-hidden="true"
            />
Florent Lavelle's avatar
dev
Florent Lavelle committed
            </a>
            <router-link
              v-else-if="!user && !SSO_LOGIN_URL"
              :to="{ name : 'login' }"
              class="item log-item"
            >
              Se Connecter
            </router-link>
            <a
              v-else
              class="item log-item"
              :href="SSO_LOGIN_URL"
              target="_self"
Florent Lavelle's avatar
dev
Florent Lavelle committed
            >Se connecter</a>
          </div>
        </div>
      </div>
      <MessageInfoList />
Florent Lavelle's avatar
dev
Florent Lavelle committed
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import MessageInfoList from '@/components/MessageInfoList';
Florent Lavelle's avatar
dev
Florent Lavelle committed

export default {
Florent Lavelle's avatar
Florent Lavelle committed

Florent Lavelle's avatar
dev
Florent Lavelle committed
  name: 'AppHeader',

    MessageInfoList
Florent Lavelle's avatar
dev
Florent Lavelle committed
  data() {
    return {
      menuIsOpen: false,
      width: window.innerWidth > 0 ? window.innerWidth : screen.width,
    };
  },

  computed: {
    ...mapState([
      'user',
      'USER_LEVEL_PROJECTS',
      'configuration',
      'loader',
Florent Lavelle's avatar
Florent Lavelle committed
      'isOnline'
Florent Lavelle's avatar
dev
Florent Lavelle committed
    ]),
    ...mapState('projects', [
      'projects',
      'project',
    ]),

    APPLICATION_NAME() {
      return this.configuration.VUE_APP_APPLICATION_NAME;
    },
    APPLICATION_ABSTRACT() {
      return this.configuration.VUE_APP_APPLICATION_ABSTRACT;
Florent Lavelle's avatar
dev
Florent Lavelle committed
    },
    DISABLE_LOGIN_BUTTON() {
      return this.configuration.VUE_APP_DISABLE_LOGIN_BUTTON;
    },
    SSO_LOGIN_URL() {
      if (this.configuration.VUE_APP_LOGIN_URL) { 
        // add a next parameter with the pathname as expected by OGS to redirect after login 
        return `${this.configuration.VUE_APP_LOGIN_URL}/?next=${encodeURIComponent(window.location.pathname)}`;
Florent Lavelle's avatar
dev
Florent Lavelle committed
    },

    logo() {
      return this.configuration.VUE_APP_LOGO_PATH;
    },
    userFullname() {
Florent Lavelle's avatar
Florent Lavelle committed
      if (this.user.first_name || this.user.last_name) {
Florent Lavelle's avatar
Florent Lavelle committed
        return `${this.user.first_name} ${this.user.last_name}`;
Florent Lavelle's avatar
Florent Lavelle committed
      }
Florent Lavelle's avatar
dev
Florent Lavelle committed
      return null;
    },
    isAdmin() {
      return this.USER_LEVEL_PROJECTS &&
        this.USER_LEVEL_PROJECTS[this.project.slug] === 'Administrateur projet'
        ? true
        : false;
    },
    isSharedProject() {
      return this.$route.path.includes('projet-partage');
    }
  },

  created() {
    window.addEventListener('mousedown', this.clickOutsideMenu);
  },

  beforeDestroy() {
    window.removeEventListener('mousedown', this.clickOutsideMenu);
  },

Florent Lavelle's avatar
dev
Florent Lavelle committed
  methods: {
    logout() {
      this.$store.dispatch('LOGOUT');
    },

    clickOutsideMenu(e) {
      if (e.target.closest && !e.target.closest('#menu-dropdown')) {
        this.menuIsOpen = false;
      }
    },
Florent Lavelle's avatar
dev
Florent Lavelle committed
  }

};
</script>

<style lang="less" scoped>
.menu.container .header {
  padding-top: 5px !important;
  padding-bottom: 5px !important;
  &> img {
.vertical {
  flex-direction: column;
  justify-content: center;
}

.flex {
  display: flex;
}

/* keep above loader */
#menu-dropdown {
  z-index: 1001;
}

.expand-center {
  width: 100%;
  text-align: center;
}

.network-icon {
  padding: .5rem !important;
}

.crossed-out {
  position: relative;
  padding: .2em;
  &::before {
    content: "";
    position: absolute;
    top: 45%;
    left: -8%;
    width: 100%;
    border-top: 2px solid #ee2e24;
    transform: rotate(45deg);
    box-shadow: 0px 0px 0px 1px #373636;
    border-radius: 3px;
  }
}

@media screen and (max-width: 1110px) {
@media screen and (min-width: 726px) {
  .mobile {
    display: none !important;
  }
  #app-header {
    min-width: 560px;
  }
  .menu.container {
    width: auto !important;
  }
  .push-right-desktop {
    margin-left: auto;
  }
}

@media screen and (max-width: 725px) {
  .desktop {
    display: none !important;
  }
  div.dropdown-list {
    width: 100vw;
  }
  .menu.container .header {
    //width: 70px;
    width: 100%;
  }
    /*  make the logo disappear on scroll */
    position: sticky;
    top: -90px;
    height: 80px;
    .menu.container {
      /*  make the logo disappear on scroll */
      position: sticky;
      top: 0;
    }
  .menu.container .header > img {
    margin: auto;
    max-width: 100%;
  }
  #menu-dropdown > span {
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
}
Florent Lavelle's avatar
dev
Florent Lavelle committed

.menu.container {
  position: relative;
Florent Lavelle's avatar
dev
Florent Lavelle committed
}

.disable:hover {
  cursor: default !important;
  background-color: #373636 !important;
}

/* keep above map controls or buttons */
#app-header {
  z-index: 9999;
  .menu.container .ui.inverted.icon.menu { /* avoid adding space when messages are displayed */
    margin: 0;
    display: flex;
    flex-wrap: wrap;
Florent Lavelle's avatar
dev
Florent Lavelle committed
.ui.menu .ui.dropdown .menu {
  .item.no-hover:hover {
    cursor: auto !important;
    background: white !important;
  }

}

/* copy style to apply inside nested div */
.ui.menu .ui.dropdown .menu .item {
  margin: 0;
  text-align: left;
  font-size: 1em !important;
  padding: 0.78571429em 1.14285714em !important;
  background: 0 0 !important;
  color: #252525 !important;
  text-transform: none !important;
  font-weight: 400 !important;
  box-shadow: none !important;
  transition: none !important;
}

.item.title::before {
  background: none !important;
}

.log-item {
  height: 100% !important;
}