From b1c91758da455d4c9e1a968b7ff98cdd86ecdbb8 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Tue, 27 Aug 2024 17:27:40 -0700 Subject: [PATCH] Fix sort bug in dev center --- src/dev-center/js/dev-center.js | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/dev-center/js/dev-center.js b/src/dev-center/js/dev-center.js index a603f3d2..759eac23 100644 --- a/src/dev-center/js/dev-center.js +++ b/src/dev-center/js/dev-center.js @@ -519,9 +519,9 @@ function generate_edit_app_section(app) {
- + - +
@@ -1318,11 +1318,31 @@ function sort_apps() { let sorted_apps; // sort - if (sortDirection === 'asc') - sorted_apps = apps.sort((a, b) => a[sortBy] > b[sortBy] ? 1 : -1); - else - sorted_apps = apps.sort((a, b) => a[sortBy] < b[sortBy] ? 1 : -1); - + if (sortDirection === 'asc'){ + sorted_apps = apps.sort((a, b) => { + if(sortBy === 'name'){ + return a[sortBy].localeCompare(b[sortBy]); + }else if(sortBy === 'created_at'){ + return new Date(a[sortBy]) - new Date(b[sortBy]); + } else if(sortBy === 'user_count' || sortBy === 'open_count'){ + return a.stats[sortBy] - b.stats[sortBy]; + }else{ + a[sortBy] > b[sortBy] ? 1 : -1 + } + }); + }else{ + sorted_apps = apps.sort((a, b) => { + if(sortBy === 'name'){ + return b[sortBy].localeCompare(a[sortBy]); + }else if(sortBy === 'created_at'){ + return new Date(b[sortBy]) - new Date(a[sortBy]); + } else if(sortBy === 'user_count' || sortBy === 'open_count'){ + return b.stats[sortBy] - a.stats[sortBy]; + }else{ + b[sortBy] > a[sortBy] ? 1 : -1 + } + }); + } // refresh app list $('.app-card').remove(); sorted_apps.forEach(app => {