Skip to content
Snippets Groups Projects
ProjectsMenu.vue 6.91 KiB
Newer Older
Florent Lavelle's avatar
dev
Florent Lavelle committed
<template>
  <div id="filters-container">
    <div
      class="ui styled accordion"
      @click="displayFilters = !displayFilters"
    >
      <div
        class="title collapsible-filters"
      >
Timothee P's avatar
Timothee P committed
        FILTRES
Florent Lavelle's avatar
Florent Lavelle committed
        <i
          :class="['ui icon customcaret', { 'collapsed': !displayFilters }]"
Florent Lavelle's avatar
Florent Lavelle committed
          aria-hidden="true"
Timothee P's avatar
Timothee P committed
        />
      </div>
    </div>
    <div :class="['full-width', { 'hidden': displayFilters }]">
      <div class="ui menu filters">
        <div class="item">
          <label>
            Niveau d'autorisation requis
          </label>
          <DropdownMenuItem
            :options="accessLevelOptions"
            v-on="$listeners"
          />
        </div>
        <div class="item">
          <label>
            Mon niveau d'autorisation
          </label>
          <DropdownMenuItem
            :options="userAccessLevelOptions"
            v-on="$listeners"
          />
        </div>
        <div class="item">
          <label>
            Modération
          </label>
          <DropdownMenuItem
            :options="moderationOptions"
            v-on="$listeners"
          />
        </div>
        <div class="item">
          <label>
            Recherche par nom
          </label>
          <search-projects
            :search-function="SEARCH_PROJECTS"
            v-on="$listeners"
          />
        </div>
Timothee P's avatar
Timothee P committed
      </div>
      <div class="ui menu filters">
        <div
          v-for="projectAttribute in displayedProjectAttributes"
          :key="projectAttribute.id"
          class="item"
        >
          <label>
            {{ projectAttribute.label }}
          </label>
          <!-- <FeatureExtraForm
            :options="projectAttribute.options"
            v-on="$listeners"
          /> -->
          <FeatureExtraForm
          :id="`attribute-value-for-${projectAttribute.name}`"
          ref="extraForm"
          name="attribute-value"
          :field="{ ...projectAttribute, value: projectAttribute.default_filter_value }"
          :use-value-only="true"
          @update:value="updateValue($event.toString(), projectAttribute.id)"
Timothee P's avatar
Timothee P committed
        />
Timothee P's avatar
Timothee P committed
      </div>
    </div>
  </div>
Florent Lavelle's avatar
dev
Florent Lavelle committed
</template>

<script>
Florent Lavelle's avatar
Florent Lavelle committed
import { mapState, mapActions } from 'vuex';
Florent Lavelle's avatar
dev
Florent Lavelle committed

Florent Lavelle's avatar
Florent Lavelle committed
import DropdownMenuItem from '@/components/Projects/DropdownMenuItem.vue';
import SearchProjects from '@/components/Projects/SearchProjects.vue';
import FeatureExtraForm from '@/components/Feature/Edit/FeatureExtraForm';
Florent Lavelle's avatar
dev
Florent Lavelle committed

export default {
Timothee P's avatar
Timothee P committed
  name: 'ProjectsMenu',
Florent Lavelle's avatar
dev
Florent Lavelle committed

Timothee P's avatar
Timothee P committed
  components: {
    DropdownMenuItem,
    SearchProjects,
Timothee P's avatar
Timothee P committed
  },
Florent Lavelle's avatar
Florent Lavelle committed

Timothee P's avatar
Timothee P committed
  data() {
    return {
Timothee P's avatar
Timothee P committed
      moderationOptions: [
        {
          label: 'Tous',
          filter: 'moderation',
          value: null
        },
        {
          label: 'Projet modéré',
          filter: 'moderation',
          value: 'true'
        },
        {
          label: 'Projet non modéré',
          filter: 'moderation',
          value: 'false'
        },
      ],
      accessLevelOptions: [
        {
          label: 'Tous',
          filter: 'access_level',
          value: null
        },
Florent Lavelle's avatar
Florent Lavelle committed
        {
          label: 'Utilisateur anonyme',
          filter: 'access_level',
          value: 'anonymous'
        },
Timothee P's avatar
Timothee P committed
        {
          label: 'Utilisateur connecté',
          filter: 'access_level',
          value: 'logged_user'
        },
        {
          label: 'Contributeur',
          filter: 'access_level',
          value: 'contributor'
        },
      ],
      userAccessLevelOptions: [
        {
          label: 'Tous',
          filter: 'user_access_level',
          value: null
        },
        {
          label: 'Utilisateur connecté',
          filter: 'user_access_level',
          value: '1'
        },
        {
          label: 'Contributeur',
          filter: 'user_access_level',
          value: '2'
        },
        {
          label: 'Super contributeur',
Timothee P's avatar
Timothee P committed
          filter: 'user_access_level',
          value: '3'
        },
        {
          label: 'Modérateur',
Timothee P's avatar
Timothee P committed
          filter: 'user_access_level',
          value: '4'
        },
        {
          label: 'Administrateur projet',
          filter: 'user_access_level',
          value: '5'
        },
Timothee P's avatar
Timothee P committed
    };
  },
Florent Lavelle's avatar
Florent Lavelle committed
  computed: {
    ...mapState(['user', 'projectAttributes']),

    displayedProjectAttributes() {
      return this.projectAttributes.filter(el => el.display_filter);
    },
Florent Lavelle's avatar
Florent Lavelle committed
  },

  created() {
    if (!this.user) {
      this.userAccessLevelOptions.splice(1, 0, {
        label: 'Utilisateur anonyme',
        filter: 'user_access_level',
        value: '0'
      });
    }
  },

Timothee P's avatar
Timothee P committed
  methods: {
    ...mapActions('projects', [
      'SEARCH_PROJECTS'
    updateValue(value, id) {
      // update the project attributes key/value object
      this.projectAttributesFilter[id] = value;
      // emit the new project attributes object to be set as a project filter in query
      this.$emit('filter', { filter: 'attributes', value: JSON.stringify(this.projectAttributesFilter) });
    }
Timothee P's avatar
Timothee P committed
  }
};
Florent Lavelle's avatar
dev
Florent Lavelle committed
</script>

<style lang="less" scoped>
.transition-properties(...) {
  -webkit-transition: @arguments;
  -moz-transition: @arguments;
  -o-transition: @arguments;
  transition: @arguments;
}
Florent Lavelle's avatar
Florent Lavelle committed

	width: 100%;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	.accordion {
		.collapsible-filters {
			font-size: 1.25em;
			padding-right: 0;
      .customcaret{
        transition: transform .2s ease;
        &.collapsed {
          transform: rotate(180deg);
        }
        &::before{
          position: relative;
          right: 0;
          top: 65%;
          color: #999;
          margin-top: 4px;
          border-color: #999 transparent transparent;
          border-style: solid;
          border-width: 5px 5px 0;
          content: "";
        }
      }
		}
	}
	.filters {
		width: 100%;
		height:auto;
		min-height: 0;
		max-height:75px;
		margin: 0 0 1em 0;
    border: none;
    box-shadow: none;
		.transition-properties(all 0.2s ease-out;);
		.item {
			display: flex;
			flex-direction: column;
			align-items: flex-start !important;
Florent Lavelle's avatar
Florent Lavelle committed

			label {
				margin-bottom: 0.2em;
				font-size: 0.9em;
				font-weight: 600;
			}
		}
		.item {
			width: 25%;
		}
    .item::before {
			width: 0;
		}
Florent Lavelle's avatar
Florent Lavelle committed
	}
	.filters.hidden {
		overflow: hidden;
Florent Lavelle's avatar
Florent Lavelle committed
	}
Florent Lavelle's avatar
dev
Florent Lavelle committed
}
@media screen and (min-width: 701px) {
  .item {
    &:first-child {
      padding-left: 0;
    }
    &:last-child {
      padding-right: 0;
    }
  }
}

@media screen and (max-width: 700px) {

    .filters {
      display: flex;
      flex-direction: column;
      max-height: 275px;
      .transition-properties(all 0.2s ease-out;);

      .item {
        width: 100%;
Florent Lavelle's avatar
dev
Florent Lavelle committed
</style>