Просмотр исходного кода

Merge pull request #3415 from weseek/feat/5154-sort-contributors-section-by-order

feat/5154 sort contributors section by order
Yuki Takei 5 лет назад
Родитель
Сommit
876d23f557
2 измененных файлов с 17 добавлено и 6 удалено
  1. 4 0
      resource/Contributor.js
  2. 13 6
      src/server/routes/apiv3/staffs.js

+ 4 - 0
resource/Contributor.js

@@ -1,5 +1,6 @@
 const contributors = [
 const contributors = [
   {
   {
+    order: 1,
     sectionName: 'GROWI VILLAGE',
     sectionName: 'GROWI VILLAGE',
     additionalClass: '',
     additionalClass: '',
     memberGroups: [
     memberGroups: [
@@ -47,6 +48,7 @@ const contributors = [
     ],
     ],
   },
   },
   {
   {
+    order: 10,
     sectionName: 'CONTRIBUTER',
     sectionName: 'CONTRIBUTER',
     additionalClass: '',
     additionalClass: '',
     memberGroups: [
     memberGroups: [
@@ -92,6 +94,7 @@ const contributors = [
     ],
     ],
   },
   },
   {
   {
+    order: 100,
     sectionName: 'VULNERABILITY HUNTER',
     sectionName: 'VULNERABILITY HUNTER',
     additionalClass: '',
     additionalClass: '',
     memberGroups: [
     memberGroups: [
@@ -111,6 +114,7 @@ const contributors = [
     ],
     ],
   },
   },
   {
   {
+    order: 200,
     sectionName: 'SPECIAL THANKS',
     sectionName: 'SPECIAL THANKS',
     additionalClass: '',
     additionalClass: '',
     memberGroups: [
     memberGroups: [

+ 13 - 6
src/server/routes/apiv3/staffs.js

@@ -12,8 +12,13 @@ const { isAfter, addHours } = require('date-fns');
 const contributors = require('../../../../resource/Contributor');
 const contributors = require('../../../../resource/Contributor');
 
 
 let expiredAt;
 let expiredAt;
-let contributorsCache = contributors;
+const contributorsCache = contributors;
+let gcContributors;
 
 
+// Sorting contributors by this method
+const compareFunction = function(a, b) {
+  return a.order - b.order;
+};
 
 
 module.exports = (crowi) => {
 module.exports = (crowi) => {
 
 
@@ -23,15 +28,17 @@ module.exports = (crowi) => {
 
 
     if (expiredAt == null || isAfter(now, expiredAt) || growiCloudUri != null) {
     if (expiredAt == null || isAfter(now, expiredAt) || growiCloudUri != null) {
       const url = new URL('_api/staffCredit', growiCloudUri);
       const url = new URL('_api/staffCredit', growiCloudUri);
-      const growiContributors = contributors.slice(0, 1);
-      const otherContributors = contributors.slice(1);
       try {
       try {
         const gcContributorsRes = await axios.get(url.toString());
         const gcContributorsRes = await axios.get(url.toString());
-        const gcContributors = gcContributorsRes.data;
+        if (gcContributors == null) {
+          gcContributors = gcContributorsRes.data;
+          // merging contributors
+          contributorsCache.push(gcContributors);
+        }
+        // Change the order of section
+        contributorsCache.sort(compareFunction);
         // caching 'expiredAt' for 1 hour
         // caching 'expiredAt' for 1 hour
         expiredAt = addHours(now, 1);
         expiredAt = addHours(now, 1);
-        // caching merged contributors
-        contributorsCache = growiContributors.concat(gcContributors, otherContributors);
       }
       }
       catch (err) {
       catch (err) {
         logger.warn('Getting GROWI.cloud staffcredit is failed');
         logger.warn('Getting GROWI.cloud staffcredit is failed');