Skip to content
Snippets Groups Projects
ProjectsList.vue 4.51 KiB
Newer Older
Florent Lavelle's avatar
Florent Lavelle committed
  <div
    id="projects"
    class="page"
  >
Florent Lavelle's avatar
Florent Lavelle committed
    <h2 class="ui horizontal divider header">
      PROJETS
    <div class="flex">
      <router-link
        v-if="user && user.can_create_project && isOnline"
        :to="{ name: 'project_create', params: { action: 'create' } }"
        class="ui green basic button"
      >
Florent Lavelle's avatar
Florent Lavelle committed
        <i
          class="plus icon"
          aria-hidden="true"
        />
        Créer un nouveau projet
      </router-link>
      <router-link
        v-if="user && user.can_create_project && isOnline"
        :to="{
          name: 'project_type_list',
        }"
        class="ui blue basic button"
      >
Florent Lavelle's avatar
Florent Lavelle committed
        <i
          class="copy icon"
          aria-hidden="true"
        />
        Accéder à la liste des modèles de projets
      </router-link>
    </div>

    <!-- FILTRES DES PROJETS -->
      @filter="setProjectsFilters"
Florent Lavelle's avatar
Florent Lavelle committed
      @loading="setLoader"
Florent Lavelle's avatar
Florent Lavelle committed

    <div
      v-if="configuration.DISPLAY_FORBIDDEN_PROJECTS"
      id="forbidden-projects"
      class="ui toggle checkbox"
    >
      <input
        v-model="displayForbiddenProjects"
        type="checkbox"
Timothee P's avatar
Timothee P committed
      >
      <label>
        N'afficher que les projets disponibles à la consultation
      </label>
    </div>

Florent Lavelle's avatar
Florent Lavelle committed
    <!-- LISTE DES PROJETS -->
Timothee P's avatar
Timothee P committed
    <div
      v-if="projects"
      class="ui divided items dimmable dimmed"
    >
      <div
        :class="{ active: loading }"
        class="ui inverted dimmer"
      >
        <div class="ui loader" />
      </div>
Florent Lavelle's avatar
Florent Lavelle committed
      
      <ProjectsListItem
Timothee P's avatar
Timothee P committed
        v-for="project in projects"
        :key="project.slug"
Florent Lavelle's avatar
Florent Lavelle committed
        :project="project"
      />
      <span
        v-if="!projects || projects.length === 0"
Florent Lavelle's avatar
Florent Lavelle committed
        Vous n'avez accès à aucun projet.
      </span>
Florent Lavelle's avatar
Florent Lavelle committed

      <!-- PAGINATION -->
      <Pagination
        v-if="count"
        :nb-pages="Math.ceil(count/10)"
        :on-page-change="SET_CURRENT_PAGE"
        @change-page="changePage"
      />
Florent Lavelle's avatar
Florent Lavelle committed
    </div>
import { mapState, mapMutations, mapActions } from 'vuex';
Florent Lavelle's avatar
Florent Lavelle committed
import ProjectsMenu from '@/components/Projects/ProjectsMenu';
import ProjectsListItem from '@/components/Projects/ProjectsListItem';
import Pagination from '@/components/Pagination';
Florent Lavelle's avatar
Florent Lavelle committed

Florent Lavelle's avatar
Florent Lavelle committed
  name: 'ProjectsList',
Florent Lavelle's avatar
Florent Lavelle committed

  components: {
Florent Lavelle's avatar
Florent Lavelle committed
    ProjectsMenu,
Florent Lavelle's avatar
Florent Lavelle committed
    ProjectsListItem,
Florent Lavelle's avatar
Florent Lavelle committed
    Pagination
Florent Lavelle's avatar
Florent Lavelle committed
  },
      loading: false,
      displayForbiddenProjects: false
Timothee P's avatar
Timothee P committed
    };
Florent Lavelle's avatar
Florent Lavelle committed
    ...mapState([
Florent Lavelle's avatar
Florent Lavelle committed
      'user',
Florent Lavelle's avatar
Florent Lavelle committed
    ]),
    ...mapState('projects', [
Florent Lavelle's avatar
Florent Lavelle committed
    ]),
    DJANGO_BASE_URL() {
      return this.$store.state.configuration.VUE_APP_DJANGO_BASE;
    },
  },

  watch: {
    filters: {
      deep: true,
      handler(newValue) {
        if (newValue) {
          this.getData();
        }
      }
    },
    displayForbiddenProjects(newValue) {
      if (newValue) {
        this.SET_PROJECTS_FILTER({
          filter: 'accessible',
          value: 'true'
        });
      } else {
        this.SET_PROJECTS_FILTER({
          filter: 'accessible',
          value: null
        });
      }
      this.getData();
    }
  },

  created() {
    this.$store.commit('projects/SET_PROJECT', null);
    this.SET_PROJECTS_FILTER({
      filter: 'accessible',
      value: 'true'
    });
    this.displayForbiddenProjects = this.configuration.DISPLAY_FORBIDDEN_PROJECTS_DEFAULT;
Florent Lavelle's avatar
Florent Lavelle committed
    ...mapMutations('projects', [
      'SET_CURRENT_PAGE',
      'SET_PROJECTS_FILTER'
    ]),
    ...mapActions('projects', [
      'GET_PROJECTS'
Florent Lavelle's avatar
Florent Lavelle committed
    ]),

    getData(page) {
      this.loading = true;
Timothee P's avatar
Timothee P committed
      this.GET_PROJECTS({ page })
        .then(() => {
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },

Florent Lavelle's avatar
Florent Lavelle committed
    setLoader(e) {
      this.loading = e;
    },

    changePage(e) {
      this.getData(e);
    },

    setProjectsFilters(e) {
      this.SET_PROJECTS_FILTER(e);
Florent Lavelle's avatar
Florent Lavelle committed
#projects {
  margin: 0 auto;
Florent Lavelle's avatar
Florent Lavelle committed

  .dimmable {

    .dimmer {
      
      .loader {
        top: 25%;
      }
    }
  }
Florent Lavelle's avatar
Florent Lavelle committed
}

.flex {
  display: flex;
  justify-content: space-between;
}
#filters-divider {
  padding-top: 0;
  color: gray !important;
}

#forbidden-projects.checkbox {
  font-size: 1.2em;
  font-weight: 600;
  label {
    color: rgb(94, 94, 94);
  }
  input:checked ~ label::before {
    background-color: teal !important;
  }
  input:checked ~ label {
    color: teal !important;
  }
}