From ba7f5c0891d6a1e97571de3148669f7eab62235f Mon Sep 17 00:00:00 2001 From: Henriette Dinger Date: Tue, 11 Aug 2015 14:54:41 +0200 Subject: [PATCH 1/2] Add pagination and column sorting to admin projects table * Adds a last activity column. * Removes tooltips from projects table in according with PM * Refactors sort_helper to correctly initialize default sort criteria * Add a placeholder 'information section' which matches the visual text size and icon. If this is used more often, this should be turned into its own LSG item * Default sort order is lft, but is unavailable in colums, thus a user should be able to reset the user-selected sorting. Currently we work around this by clearing the session sort entry. Users have to click on the projects menu item to return to the default sort. Relevant work package: https://community.openproject.org/work_packages/18800 --- .../content/_information_section.sass | 32 +++++++++ app/assets/stylesheets/content/_tables.sass | 20 +++--- app/assets/stylesheets/default.css.sass | 1 + app/controllers/admin_controller.rb | 11 ++- app/helpers/application_helper.rb | 12 ++++ app/helpers/sort_helper.rb | 38 +++++++--- app/views/admin/projects.html.erb | 71 ++++++++----------- config/locales/en.yml | 3 + 8 files changed, 126 insertions(+), 62 deletions(-) create mode 100644 app/assets/stylesheets/content/_information_section.sass diff --git a/app/assets/stylesheets/content/_information_section.sass b/app/assets/stylesheets/content/_information_section.sass new file mode 100644 index 0000000000..9a6a299247 --- /dev/null +++ b/app/assets/stylesheets/content/_information_section.sass @@ -0,0 +1,32 @@ +//-- copyright +// OpenProject is a project management system. +// Copyright (C) 2012-2015 the OpenProject Foundation (OPF) +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See doc/COPYRIGHT.rdoc for more details. +//++ + +$infosec-font-size-rewrite: .8rem + +.information-section + font-size: $infosec-font-size-rewrite diff --git a/app/assets/stylesheets/content/_tables.sass b/app/assets/stylesheets/content/_tables.sass index 55106fd742..84c5066be8 100644 --- a/app/assets/stylesheets/content/_tables.sass +++ b/app/assets/stylesheets/content/_tables.sass @@ -62,26 +62,26 @@ tr &.project td.name a white-space: nowrap - &.idnt td.name span + &.idnt td.project--hierarchy span background: image-url("bullet_arrow_right.png") no-repeat 0 50% padding-left: 16px - &.idnt-1 td.name + &.idnt-1 td.project--hierarchy padding-left: 0.5em - &.idnt-2 td.name + &.idnt-2 td.project--hierarchy padding-left: 2em - &.idnt-3 td.name + &.idnt-3 td.project--hierarchy padding-left: 3.5em - &.idnt-4 td.name + &.idnt-4 td.project--hierarchy padding-left: 5em - &.idnt-5 td.name + &.idnt-5 td.project--hierarchy padding-left: 6.5em - &.idnt-6 td.name + &.idnt-6 td.project--hierarchy padding-left: 8em - &.idnt-7 td.name + &.idnt-7 td.project--hierarchy padding-left: 9.5em - &.idnt-8 td.name + &.idnt-8 td.project--hierarchy padding-left: 11em - &.idnt-9 td.name + &.idnt-9 td.project--hierarchy padding-left: 12.5em &.issue white-space: nowrap diff --git a/app/assets/stylesheets/default.css.sass b/app/assets/stylesheets/default.css.sass index ccbcaa98a6..368bcb4766 100644 --- a/app/assets/stylesheets/default.css.sass +++ b/app/assets/stylesheets/default.css.sass @@ -68,6 +68,7 @@ @import content/attributes_key_value @import content/attributes_group @import content/attributes_table +@import content/information_section @import content/work_package_details/activities_tab @import content/work_package_details/attachments_tab diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 77de2d44df..5351702c0d 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -33,6 +33,7 @@ class AdminController < ApplicationController before_filter :require_admin include SortHelper + include PaginationHelper menu_item :projects, only: [:projects] menu_item :plugins, only: [:plugins] @@ -43,6 +44,12 @@ class AdminController < ApplicationController end def projects + # We need to either clear the session sort + # or users can't access the default lft order with subprojects + # after once sorting the list + sort_clear + sort_init 'lft' + sort_update %w(lft name is_public created_on updated_on required_disk_space) @status = params[:status] ? params[:status].to_i : 1 c = ARCondition.new(@status == 0 ? 'status <> 0' : ['status = ?', @status]) @@ -52,8 +59,10 @@ class AdminController < ApplicationController end @projects = Project.with_required_storage - .order('lft') + .order(sort_clause) .where(c.conditions) + .page(page_param) + .per_page(per_page_param) render action: 'projects', layout: false if request.xhr? end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4d6617b67e..0aa1406268 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -247,6 +247,18 @@ module ApplicationHelper Project.project_tree(projects, &block) end + # Returns a lft-sorted project hierarchy only when + # the sort helper has deemed a non-default sort option to be selected. + def project_tree_when_sorted(projects, &block) + if default_sort_order? + project_tree(projects, &block) + else + projects.each do |p| + yield p, 0 + end + end + end + def project_nested_ul(projects, &_block) s = '' if projects.any? diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rb index b465f13ea9..173793a21d 100644 --- a/app/helpers/sort_helper.rb +++ b/app/helpers/sort_helper.rb @@ -81,6 +81,8 @@ module SortHelper class SortCriteria + attr_reader :criteria + def initialize @criteria = [] end @@ -179,14 +181,16 @@ module SortHelper # sort_init [['name', 'desc'], ['id', 'desc']] # def sort_init(*args) - case args.size - when 1 - @sort_default = args.first.is_a?(Array) ? args.first : [[args.first]] - when 2 - @sort_default = [[args.first, args.last]] - else - raise ArgumentError - end + criteria = case args.size + when 1 + args.first.is_a?(Array) ? args.first : [[args.first]] + when 2 + [[args.first, args.last]] + else + raise ArgumentError + end + @sort_default = SortCriteria.new + @sort_default.criteria = criteria end # Updates the sort state. Call this in the controller prior to calling @@ -197,7 +201,7 @@ module SortHelper @sort_criteria = SortCriteria.new @sort_criteria.available_criteria = criteria @sort_criteria.from_param(params[:sort] || session[sort_name]) - @sort_criteria.criteria = @sort_default if @sort_criteria.empty? + @sort_criteria.criteria = @sort_default.criteria if @sort_criteria.empty? session[sort_name] = @sort_criteria.to_param end @@ -214,6 +218,12 @@ module SortHelper @sort_criteria.to_sql end + # Determines whether the current selected sort criteria + # is identical to the default + def default_sort_order? + @sort_default.criteria == @sort_criteria.criteria + end + # Returns a link which sorts by the named column. # # - column is the name of an attribute in the sorted record collection. @@ -271,4 +281,14 @@ module SortHelper content_tag('th', sort_link(column, caption, default_order, lang: lang), options) end + + # Returns a table header tag similar to +sort_header_tag+, but + # according to the LSG table component. + def sort_header_tag_with_lsg(column, options = {}) + caption = options.delete(:caption) || column.to_s.humanize + default_order = options.delete(:default_order) || 'asc' + lang = options.delete(:lang) || nil + + sort_link(column, caption, default_order, lang: lang) + end end diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb index 6f7acc784d..21059af8eb 100644 --- a/app/views/admin/projects.html.erb +++ b/app/views/admin/projects.html.erb @@ -36,37 +36,12 @@ See doc/COPYRIGHT.rdoc for more details. <% end %> <% end %> -
-
-
-

<%= l(:label_information) %>

-
-
-
-
<%= l(:label_project_count) %>
-
-
- - <%= l(:label_x_projects, :count => Project.count) %> - -
-
-
<%= l(:label_required_disk_storage) %>
-
-
- - <%= number_to_human_size(Project.total_projects_size, precision: 2) %> - -
-
-
-
<%= form_tag({}, :method => :get) do %>
<%= l(:label_filter_plural) %>
<% end %> -  -
+

+ + <%= l(:label_projects_storage_information, + count: Project.count, + storage: number_to_human_size(Project.total_projects_size, precision: 2)) %> +

+
@@ -89,6 +69,7 @@ See doc/COPYRIGHT.rdoc for more details. + @@ -96,26 +77,23 @@ See doc/COPYRIGHT.rdoc for more details. - + @@ -133,12 +118,13 @@ See doc/COPYRIGHT.rdoc for more details. - <% project_tree(@projects) do |project, level| %> + <% project_tree_when_sorted(@projects) do |project, level| %> "> - + +
- - <%= Project.model_name.human %> - + <%= sort_header_tag_with_lsg('name', caption: Project.model_name.human) %>
+
- - <%= Project.human_attribute_name(:is_public) %> - + <%= sort_header_tag_with_lsg('is_public', + caption: Project.human_attribute_name(:is_public)) %>
- - <%= l(:label_required_disk_storage) %> + <%= sort_header_tag_with_lsg('required_disk_space', + caption: I18n.t(:label_required_disk_storage)) %>
@@ -123,9 +101,16 @@ See doc/COPYRIGHT.rdoc for more details.
- - <%= Project.human_attribute_name(:created_on) %> - + <%= sort_header_tag_with_lsg('created_on', + caption: Project.human_attribute_name(:created_on)) %> +
+
+
+
+
+ <%= sort_header_tag_with_lsg('updated_on', + caption: I18n.t(:label_last_activity)) %>
<%= link_to project, settings_project_path(project), :title => project.short_description %><%= link_to project, settings_project_path(project), :title => project.short_description %> <%= checked_image project.is_public? %> <%= number_to_human_size(project.required_disk_space, precision: 2) if project.required_disk_space.to_i > 0 %> <%= format_date(project.created_on) %><%= format_date(project.updated_on) %> <%= link_to(l(:button_archive), archive_project_path(project, :status => params[:status]), @@ -161,5 +147,6 @@ See doc/COPYRIGHT.rdoc for more details.
+ <%= pagination_links_full @projects %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 483124de7c..bf6d354bc6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -814,6 +814,7 @@ en: label_journal_diff: "Description Comparison" label_jump_to_a_project: "Jump to a project..." label_language_based: "Based on user's language" + label_last_activity: "Last activity" label_last_changes: "last %{count} changes" label_last_login: "Last login" label_last_month: "last month" @@ -911,9 +912,11 @@ en: label_project_copy_notifications: "Send email notifications during the project copy" label_project_latest: "Latest projects" label_project_default_type: "Allow empty type" + label_project_hierarchy: "Project hierarchy" label_project_new: "New project" label_project_plural: "Projects" label_project_settings: "Project settings" + label_projects_storage_information: "%{count} projects using %{storage} disk storage" label_project_view_all: "View all projects" label_public_projects: "Public projects" label_query_new: "New query" From 7ee9756c7a58485a06084600fc810986b2cd9644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 19 Aug 2015 15:43:37 +0200 Subject: [PATCH 2/2] Move interactive-table attribute --- app/views/admin/projects.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb index 21059af8eb..efe7913e7b 100644 --- a/app/views/admin/projects.html.erb +++ b/app/views/admin/projects.html.erb @@ -61,9 +61,9 @@ See doc/COPYRIGHT.rdoc for more details. count: Project.count, storage: number_to_human_size(Project.total_projects_size, precision: 2)) %>

-
+
- +