From 52166ec7e5d2e3ec71a5dd4848be5640b31189c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Wed, 20 Oct 2021 18:46:47 +0200
Subject: [PATCH] add sorting function

---
 src/views/project/Project_members.vue | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/views/project/Project_members.vue b/src/views/project/Project_members.vue
index c956b2c1..b303ab1b 100644
--- a/src/views/project/Project_members.vue
+++ b/src/views/project/Project_members.vue
@@ -123,6 +123,8 @@ export default {
           value: "contributor",
         },
       },
+      isSortedByName: false,
+      isSortedByStatus: false,
     };
   },
 
@@ -147,9 +149,21 @@ export default {
     },
 
     projectMembers() {
-      return this.projectUsers.filter(
-        (el) => el.userLevel.value !== "logged_user"
-      );
+      return this.projectUsers
+        .filter((el) => el.userLevel.value !== "logged_user")
+        .sort((a, b) => {
+          if (this.isSortedByName) {
+            const textA = a.user.username.toUpperCase();
+            const textB = b.user.username.toUpperCase();
+            return textA < textB ? -1 : textA > textB ? 1 : 0;
+          } else if (this.isSortedByStatus) {
+            const textA = a.userLevel.name.toUpperCase();
+            const textB = b.userLevel.name.toUpperCase();
+            return textA < textB ? -1 : textA > textB ? 1 : 0;
+          } else {
+            return 0;
+          }
+        });
     },
   },
 
@@ -195,7 +209,8 @@ export default {
         });
     },
 
-    fetchMembers() { // todo: move function to a service
+    fetchMembers() {
+      // todo: move function to a service
       return axios
         .get(
           `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/utilisateurs`
-- 
GitLab