diff --git a/resources/css/_contentManager.css b/resources/css/_contentManager.css index 6715505..5471111 100644 --- a/resources/css/_contentManager.css +++ b/resources/css/_contentManager.css @@ -58,6 +58,34 @@ html, body { .tablecell{ flex-basis:20%; } + +.sortable:hover { + cursor: pointer; +} + +.sortableBold { + font-weight: bold; +} + +i { + border: solid black; + border-width: 0 3px 3px 0; + display: inline-block; + padding: 3px; + transform: rotate(-45deg); + -webkit-transform: rotate(-45deg); +} + +.arrowUp { + transform: rotate(-135deg); + -webkit-transform: rotate(-135deg); +} + +.arrowDown { + transform: rotate(45deg); + -webkit-transform: rotate(45deg); +} + .cell0 { flex-basis: 60px; flex-grow: 0; diff --git a/resources/js/_contentManager.js b/resources/js/_contentManager.js index 183a00b..809ebbc 100644 --- a/resources/js/_contentManager.js +++ b/resources/js/_contentManager.js @@ -99,7 +99,9 @@ function init() { contentManager: contentManager, displayedBooksNb: 20, books: [], - downloads: {} + downloads: {}, + activeSortType:"", + sortOrderAsc:true }, methods: { openBook : function(book) { @@ -161,6 +163,26 @@ function init() { } return book; }, + sortBookBy : function(sortBy) { + if (this.activeSortType == sortBy && this.sortOrderAsc) + this.sortOrderAsc = false; + else { + this.activeSortType = sortBy; + this.sortOrderAsc = true; + } + contentManager.setSortBy(this.activeSortType, this.sortOrderAsc); + }, + isActive: function (sortType) { + return (this.activeSortType == sortType) + }, + isUpOrDown: function (sortType, sortOrderAsc) { + return (sortType == this.activeSortType && this.sortOrderAsc == sortOrderAsc); + }, + resetSort: function () { + this.sortOrderAsc = true; + this.activeSortType = ""; + contentManager.setSortBy("unsorted", this.sortOrderAsc); + }, niceBytes : niceBytes } }); diff --git a/resources/texts/_contentManager.html b/resources/texts/_contentManager.html index b8a4b9e..6529f06 100644 --- a/resources/texts/_contentManager.html +++ b/resources/texts/_contentManager.html @@ -16,11 +16,13 @@
- File name - Size - Date + File name + Size + Date Content type - + + +
diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index d79d4b7..c5a3eec 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -331,14 +331,15 @@ QStringList ContentManager::getBookIds() filter.rejectTags(tags); } filter.query(m_searchQuery.toStdString()); - + if (m_local) { filter.local(true); filter.valid(true); - return mp_library->listBookIds(filter); + return mp_library->listBookIds(filter, m_sortBy, m_sortOrderAsc); } else { filter.remote(true); auto bookIds = m_remoteLibrary.filter(filter); + m_remoteLibrary.sort(bookIds, m_sortBy, m_sortOrderAsc); QStringList list; for(auto& bookId:bookIds) { list.append(QString::fromStdString(bookId)); @@ -346,3 +347,18 @@ QStringList ContentManager::getBookIds() return list; } } + +void ContentManager::setSortBy(const QString& sortBy, const bool sortOrderAsc) +{ + if (sortBy == "unsorted") { + m_sortBy = kiwix::UNSORTED; + } else if (sortBy == "title") { + m_sortBy = kiwix::TITLE; + } else if (sortBy == "size") { + m_sortBy = kiwix::SIZE; + } else if (sortBy == "date") { + m_sortBy = kiwix::DATE; + } + m_sortOrderAsc = sortOrderAsc; + emit(booksChanged()); +} \ No newline at end of file diff --git a/src/contentmanager.h b/src/contentmanager.h index b20b3db..b86935f 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -36,7 +36,8 @@ private: QString m_currentLanguage; QString m_searchQuery; QString m_categoryFilter = "all"; - + kiwix::supportedListSortBy m_sortBy = kiwix::UNSORTED; + bool m_sortOrderAsc = true; QStringList getBookIds(); void eraseBookFilesFromComputer(const QString fileSelection); @@ -57,6 +58,7 @@ public slots: QString downloadBook(const QString& id); void updateLibrary(); void setSearch(const QString& search); + void setSortBy(const QString& sortBy, const bool sortOrderAsc); void eraseBook(const QString& id); void updateRemoteLibrary(const QString& content); void pauseBook(const QString& id); diff --git a/src/library.cpp b/src/library.cpp index 5ac4fe5..7899ebc 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -91,10 +91,11 @@ QStringList Library::getBookIds() return list; } -QStringList Library::listBookIds(const kiwix::Filter& filter) +QStringList Library::listBookIds(const kiwix::Filter& filter, kiwix::supportedListSortBy sortBy, bool ascending) { QStringList list; auto bookIds = m_library.filter(filter); + m_library.sort(bookIds, sortBy, ascending); for(auto& id: bookIds) { list.append(QString::fromStdString(id)); } diff --git a/src/library.h b/src/library.h index 4910240..316df57 100644 --- a/src/library.h +++ b/src/library.h @@ -29,7 +29,7 @@ public: QString openBookFromPath(const QString& zimPath); std::shared_ptr getReader(const QString& zimId); QStringList getBookIds(); - QStringList listBookIds(const kiwix::Filter& filter); + QStringList listBookIds(const kiwix::Filter& filter, kiwix::supportedListSortBy sortBy, bool ascending); const std::vector& getBookmarks() { return m_library.getBookmarks(); } void addBookToLibrary(kiwix::Book& book); void removeBookFromLibraryById(const QString& id);