Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor <idrozdov@gitlab.com>2019-04-04 19:28:56 +0300
committerDouwe Maan <douwe@gitlab.com>2019-04-04 19:28:56 +0300
commit866b58a54e95415ad74b8f004db40abb4343c753 (patch)
treeed7436c916e4d3db48c255267255e9bbc4fbaa22 /app/models/project_wiki.rb
parent8647230fa509cbba8e1853aae500315bf1116005 (diff)
Allow to sort wiki pages by date and title
- Add controls for sorting by title and date - Execute Gitaly call which now accepts sorting params for wikis
Diffstat (limited to 'app/models/project_wiki.rb')
-rw-r--r--app/models/project_wiki.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index 268706a6aea..23ddd708396 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -13,6 +13,11 @@ class ProjectWiki
CouldNotCreateWikiError = Class.new(StandardError)
SIDEBAR = '_sidebar'
+ TITLE_ORDER = 'title'
+ CREATED_AT_ORDER = 'created_at'
+ DIRECTION_DESC = 'desc'
+ DIRECTION_ASC = 'asc'
+
# Returns a string describing what went wrong after
# an operation fails.
attr_reader :error_message
@@ -82,8 +87,15 @@ class ProjectWiki
# Returns an Array of GitLab WikiPage instances or an
# empty Array if this Wiki has no pages.
- def pages(limit: 0)
- wiki.pages(limit: limit).map { |page| WikiPage.new(self, page, true) }
+ def pages(limit: 0, sort: nil, direction: DIRECTION_ASC)
+ sort ||= TITLE_ORDER
+ direction_desc = direction == DIRECTION_DESC
+
+ wiki.pages(
+ limit: limit, sort: sort, direction_desc: direction_desc
+ ).map do |page|
+ WikiPage.new(self, page, true)
+ end
end
# Finds a page within the repository based on a tile