From 3fac9ee37b6e01b0771f7d45a3a398d80a083f76 Mon Sep 17 00:00:00 2001 From: Florent <florent@MacBook-Air-de-neogeo.local> Date: Mon, 6 Dec 2021 12:29:03 +0100 Subject: [PATCH] get only last 5 features on project view --- src/store/modules/feature.js | 9 +++++++-- src/views/project/Project_detail.vue | 12 +++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/store/modules/feature.js b/src/store/modules/feature.js index d4aad9d8..30735fef 100644 --- a/src/store/modules/feature.js +++ b/src/store/modules/feature.js @@ -42,7 +42,9 @@ const feature = { }, mutations: { SET_FEATURES(state, features) { - state.features = features; + state.features = features.sort((a, b) => { + return new Date(b.created_on) - new Date(a.created_on); // sort features chronologically + }); }, SET_FEATURES_COUNT(state, features_count) { state.features_count = features_count; @@ -110,7 +112,7 @@ const feature = { getters: { }, actions: { - GET_PROJECT_FEATURES({ commit, rootState }, { project_slug, feature_type__slug, search, limit }) { + GET_PROJECT_FEATURES({ commit, rootState }, { project_slug, feature_type__slug, ordering, search, limit }) { if (rootState.cancellableSearchRequest.length > 0) { const currentRequestCancelToken = rootState.cancellableSearchRequest[rootState.cancellableSearchRequest.length - 1]; @@ -125,6 +127,9 @@ const feature = { if (feature_type__slug) { url = url.concat('', `${url.includes('?') ? '&' : '?'}feature_type__slug=${feature_type__slug}`); } + if (ordering) { + url = url.concat('', `${url.includes('?') ? '&' : '?'}ordering=${ordering}`); + } if (search) { url = url.concat('', `${url.includes('?') ? '&' : '?'}title__contains=${search}`); } diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue index a521510d..cf87d50e 100644 --- a/src/views/project/Project_detail.vue +++ b/src/views/project/Project_detail.vue @@ -358,7 +358,7 @@ </div> <div class="ui relaxed list"> <div - v-for="(item, index) in last_features" + v-for="(item, index) in features" :key="item.title + index" class="item" > @@ -387,7 +387,7 @@ </div> </div> </div> - <i v-if="last_features.length === 0" + <i v-if="features.length === 0" >Aucun signalement pour le moment.</i > </div> @@ -602,11 +602,7 @@ export default { }, API_BASE_URL() { return this.$store.state.configuration.VUE_APP_DJANGO_API_BASE; - }, - last_features() { - // * limit to last five element of array (looks sorted chronologically, but not sure...) - return this.features.slice(-5); - }, + } }, methods: { @@ -797,6 +793,8 @@ export default { this.$store .dispatch("feature/GET_PROJECT_FEATURES", { project_slug: this.slug, + ordering: '-created_on', + limit: 5 }) .then(() => { this.featuresLoading = false; -- GitLab