From 1aa9b765f62134426ad52b7d6dfd627a8ddc848a Mon Sep 17 00:00:00 2001 From: Kylart Date: Tue, 7 Mar 2017 00:33:38 +0100 Subject: [PATCH] Added a method in localPage to sort animes by name and by episode number (ascending or not will be chosen via config file later). --- src/localPage/functions.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/localPage/functions.js b/src/localPage/functions.js index dde33e3..9c6b864 100644 --- a/src/localPage/functions.js +++ b/src/localPage/functions.js @@ -10,6 +10,7 @@ const self = this // This will later be set with the config file const downloadRep = 'Downloads' +const ascending = false const fs = require('fs') const path = require('path') @@ -35,16 +36,6 @@ exports.filterFiles = (files, filters) => { return filteredFiles } -exports.byProperty = (prop) => { - return function (a, b) { - if (typeof a[prop] == "number") - { - return (a[prop] - b[prop]) - } - return ((a[prop] < b[prop]) ? -1 : ((a[prop] > b[prop]) ? 1 : 0)) - } -} - // This function works only if the file is named this way: // [FANSUB] <-> exports.searchAnime = (filename, object) => { @@ -74,7 +65,15 @@ exports.searchAnime = (filename, object) => { result.mark = anime.statistics.score.value object.files.push(result) - object.files.sort(self.byProperty('title')) + + if (ascending) + object.files.sort((a, b) => a.title === b.title ? + - b.episode.toString().localeCompare(a.episode) : + a.title.toString().localeCompare(b.title)) + else + object.files.sort((a, b) => a.title === b.title ? + b.episode.toString().localeCompare(a.episode) : + a.title.toString().localeCompare(b.title)) }) }