From bd2c961e235b84ddb130bbe19004391d915ff9a1 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Sun, 6 Mar 2016 18:32:46 +0100 Subject: [PATCH] Improve sorting of wiki pages Sorting is completely broken. Also align the sorting UI with other pages. --- .../wiki/app/controllers/pages_controller.rb | 25 ++++++++++--------- .../app/views/pages/_recent_changes.html.haml | 8 ------ .../wiki/app/views/pages/_site_map.html.haml | 2 +- .../app/views/pages/_title_list.html.haml | 4 +-- plugins/wiki/app/views/pages/all.html.haml | 1 - 5 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 plugins/wiki/app/views/pages/_recent_changes.html.haml diff --git a/plugins/wiki/app/controllers/pages_controller.rb b/plugins/wiki/app/controllers/pages_controller.rb index 4abbd265..04ffef60 100644 --- a/plugins/wiki/app/controllers/pages_controller.rb +++ b/plugins/wiki/app/controllers/pages_controller.rb @@ -108,22 +108,23 @@ class PagesController < ApplicationController def all @pages = Page.non_redirected - @partial = params[:view] || 'recent_changes' + @partial = params[:view] || 'title_list' if params[:name] - @pages = @pages.where("title LIKE ?", "%#{params[:name]}%").limit(20).order('updated_at DESC') + @pages = @pages.where("title LIKE ?", "%#{params[:name]}%").limit(20) @partial = 'title_list' - else - order = case @partial - when 'recent_changes' then - 'updated_at DESC' - when 'site_map' then - 'created_at DESC' - when 'title_list' then - 'title DESC' - end - @pages.order(order) end + if params[:sort] + sort = case params[:sort] + when "title" then "title" + when "title_reverse" then "title DESC" + when "last_updated" then "updated_at DESC" + when "last_updated_reverse" then "updated_at" + end + else + sort = "title" + end + @pages = @pages.order(sort) respond_to do |format| format.html format.rss { render :layout => false } diff --git a/plugins/wiki/app/views/pages/_recent_changes.html.haml b/plugins/wiki/app/views/pages/_recent_changes.html.haml deleted file mode 100644 index 50d301dc..00000000 --- a/plugins/wiki/app/views/pages/_recent_changes.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -%table.table.table-striped - %thead - %tr - %th= t 'pages.title' - %th= t 'pages.last_updated' - %tbody - - for page in @pages - = render :partial => "page_list_item", :locals => {:page => page, :level => 0, :siteMap => 0} diff --git a/plugins/wiki/app/views/pages/_site_map.html.haml b/plugins/wiki/app/views/pages/_site_map.html.haml index d3e9681f..e92dd499 100644 --- a/plugins/wiki/app/views/pages/_site_map.html.haml +++ b/plugins/wiki/app/views/pages/_site_map.html.haml @@ -8,5 +8,5 @@ = render :partial => 'page_list_item', :locals => {:page => homepage, :level => 0, :siteMap => 1} %tbody - for page in @pages - - if page.id != homepage.try(:id) + - if page.id != homepage.try(:id) && !page.parent_id? = render :partial => 'page_list_item', :locals => {:page => page, :level => 0, :siteMap => 1} diff --git a/plugins/wiki/app/views/pages/_title_list.html.haml b/plugins/wiki/app/views/pages/_title_list.html.haml index 50d301dc..af7fb565 100644 --- a/plugins/wiki/app/views/pages/_title_list.html.haml +++ b/plugins/wiki/app/views/pages/_title_list.html.haml @@ -1,8 +1,8 @@ %table.table.table-striped %thead %tr - %th= t 'pages.title' - %th= t 'pages.last_updated' + %th= sort_link_helper t('pages.title'), "title", :remote => false + %th= sort_link_helper t('pages.last_updated'), "last_updated", :remote => false %tbody - for page in @pages = render :partial => "page_list_item", :locals => {:page => page, :level => 0, :siteMap => 0} diff --git a/plugins/wiki/app/views/pages/all.html.haml b/plugins/wiki/app/views/pages/all.html.haml index a3a5ea35..734ace3f 100644 --- a/plugins/wiki/app/views/pages/all.html.haml +++ b/plugins/wiki/app/views/pages/all.html.haml @@ -6,7 +6,6 @@ .navbar .navbar-inner %ul.nav - %li= link_to t('.recent_changes'), all_pages_path(:view => 'recent_changes') %li= link_to t('.title_list'), all_pages_path(:view => 'title_list') %li= link_to t('.site_map'), all_pages_path(:view => 'site_map') %li= link_to image_tag('icons/feed-icon-14x14.png', :alt => 'RSS Feed'), all_pages_rss_url