From b83e15a8fa84d9058a7b6098791ef9655b9f9ff4 Mon Sep 17 00:00:00 2001 From: Wieland Lindenthal Date: Tue, 7 Nov 2017 12:51:12 +0100 Subject: [PATCH] Allow for filtering on latest_activity_at, while not yet resolving timezone difficulties. --- app/assets/javascripts/project/filters.js | 4 +- app/helpers/projects_helper.rb | 4 +- .../filters/strategies/date_time_past.rb | 2 +- app/models/queries/projects.rb | 1 + .../filters/latest_activity_at_filter.rb | 57 +++++++++++++++++++ app/views/projects/index.html.erb | 14 ++--- 6 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 app/models/queries/projects/filters/latest_activity_at_filter.rb diff --git a/app/assets/javascripts/project/filters.js b/app/assets/javascripts/project/filters.js index 4f3180d283..50bde53558 100644 --- a/app/assets/javascripts/project/filters.js +++ b/app/assets/javascripts/project/filters.js @@ -110,9 +110,9 @@ jQuery(function($) { filters.push(filterParam); } } else if ($valueBlock.hasClass('between-dates')) { - let fromValue = $('.between-dates #between-dates-from-value', + let fromValue = $('.between-dates input[name="from_value"]', $valueBlock).val(); - let toValue = $('.between-dates #between-dates-to-value', + let toValue = $('.between-dates input[name="to_value"]', $valueBlock).val(); if (value.length > 0) { filterParam[filterName] = { diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 35e3f4a941..538e4a2185 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -133,7 +133,7 @@ module ProjectsHelper end def allowed_filters(query) - filters_static = %i(status name_and_identifier created_on) + filters_static = %i(status name_and_identifier created_on latest_activity_at) filters_dynamic = [] if EnterpriseToken.allows_to?(:custom_fields_in_projects_list) filters_dynamic = ProjectCustomField @@ -159,6 +159,6 @@ module ProjectsHelper end def admin_only_filters - %i(created_on) + %i(created_on latest_activity_at) end end diff --git a/app/models/queries/filters/strategies/date_time_past.rb b/app/models/queries/filters/strategies/date_time_past.rb index 740529280e..537deefb0c 100644 --- a/app/models/queries/filters/strategies/date_time_past.rb +++ b/app/models/queries/filters/strategies/date_time_past.rb @@ -31,7 +31,7 @@ module Queries::Filters::Strategies class DateTimePast < BaseStrategy supported_operator_list ['>t-', 'd'] - default_operator 't-' def validate if operator == Queries::Operators::OnDateTime || diff --git a/app/models/queries/projects.rb b/app/models/queries/projects.rb index 35563cbf1c..2ca85ccde0 100644 --- a/app/models/queries/projects.rb +++ b/app/models/queries/projects.rb @@ -37,4 +37,5 @@ module Queries::Projects register.filter query, filters::NameAndIdentifierFilter register.filter query, filters::CustomFieldFilter register.filter query, filters::CreatedOnFilter + register.filter query, filters::LatestActivityAtFilter end diff --git a/app/models/queries/projects/filters/latest_activity_at_filter.rb b/app/models/queries/projects/filters/latest_activity_at_filter.rb new file mode 100644 index 0000000000..e5c77d2ada --- /dev/null +++ b/app/models/queries/projects/filters/latest_activity_at_filter.rb @@ -0,0 +1,57 @@ +#-- encoding: UTF-8 +#-- copyright +# OpenProject is a project management system. +# Copyright (C) 2012-2017 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-2017 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. +#++ + +class Queries::Projects::Filters::LatestActivityAtFilter < Queries::Projects::Filters::ProjectFilter + + self.model = Project.with_latest_activity + + def type + :datetime_past + end + + def self.key + :latest_activity_at + end + + def name + :latest_activity_at + end + + def human_name + I18n.t('activerecord.attributes.project.latest_activity_at') + end + + def where + operator_strategy.sql_for_field(values, "activity", self.class.key) + end + + def order + 9 + end +end diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index 546495fec9..dccf54ca56 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -56,7 +56,7 @@ See doc/COPYRIGHT.rdoc for more details. <% end %> <%= form_tag({}, method: :get, class: "project-filters #{filter_set? ? '-expanded' : ''}") do %> - <% operators_without_values = ['*', '!*'] %> + <% operators_without_values = ['*', '!*', 't', 'w'] %>
<%= t(:label_filter_plural) %> @@ -153,18 +153,18 @@ See doc/COPYRIGHT.rdoc for more details.
- <%= text_field_tag :value, value_format == 'on-date' ? filter.values.first : '', id: "on-date-value", class: 'advanced-filters--text-field -slim', size: '10' %> - <%= calendar_for('on-date-value') %> + <%= text_field_tag :value, value_format == 'on-date' ? filter.values.first : '', id: "on-date-value-#{filter.name}", class: 'advanced-filters--text-field -slim', size: '10' %> + <%= calendar_for("on-date-value-#{filter.name}") %>
From: - <%= text_field_tag :value, value_format == 'between-dates' ? filter.values.first : '', id: "between-dates-from-value", class: 'advanced-filters--text-field -slim', size: '10' %> - <%= calendar_for('between-dates-from-value') %> + <%= text_field_tag :from_value, value_format == 'between-dates' ? filter.values.first : '', id: "between-dates-from-value-#{filter.name}", class: 'advanced-filters--text-field -slim', size: '10' %> + <%= calendar_for("between-dates-from-value-#{filter.name}") %> To: - <%= text_field_tag :value, value_format == 'between-dates' ? filter.values.second : '', id: "between-dates-to-value", class: 'advanced-filters--text-field -slim', size: '10' %> - <%= calendar_for('between-dates-to-value') %> + <%= text_field_tag :to_value, value_format == 'between-dates' ? filter.values.second : '', id: "between-dates-to-value-#{filter.name}", class: 'advanced-filters--text-field -slim', size: '10' %> + <%= calendar_for("between-dates-to-value-#{filter.name}") %>
<% else %>