-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Activity filters #1207
base: develop
Are you sure you want to change the base?
Activity filters #1207
Changes from all commits
8bf6daa
0631474
cbd34b9
0a99f32
e3498f6
ee31c64
21d0dd4
752970f
6ac1df3
bd27d00
67c5b4d
41b6096
370d0fd
d0c8a7c
704b8b1
cc678cd
0ed1bfe
826d1cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ class ActivitiesController < AuthenticatedController | |
|
||
def index | ||
@page = params[:page].present? ? params[:page].to_i : 1 | ||
@users_for_select = current_project.activities.map(&:user).union(current_project.authors.enabled) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to include users that have no activities? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the first part of this query we're also including users who have activities in the project even if they're no longer on the project. Do we want to include these? |
||
|
||
activities = current_project.activities | ||
.includes(:trackable) | ||
.order(created_at: :desc) | ||
.page(@page) | ||
activities = current_project.activities.includes(:trackable) | ||
activities = filter_activities(activities) | ||
activities = activities.order(created_at: :desc).page(@page) | ||
|
||
@activities_groups = activities.group_by do |activity| | ||
activity.created_at.strftime(Activity::ACTIVITIES_STRFTIME_FORMAT) | ||
|
@@ -30,4 +30,36 @@ def poll | |
format.js | ||
end | ||
end | ||
|
||
private | ||
|
||
def filtering_params | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're not using this anywhere but probably a good idea |
||
params.permit(:user_id, :trackable_type, :since, :before) | ||
end | ||
|
||
def filter_activities(activities) | ||
if params[:since].present? && valid_date?(params[:since]) | ||
activities = activities.since(DateTime.parse(params[:since]).beginning_of_day) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need |
||
end | ||
|
||
if params[:before].present? && valid_date?(params[:before]) | ||
activities = activities.before(DateTime.parse(params[:before]).end_of_day) | ||
end | ||
|
||
if params[:user_id].present? | ||
activities = activities.where(user_id: params[:user_id]) | ||
end | ||
|
||
if params[:trackable_type].present? | ||
activities = activities.where(trackable_type: params[:trackable_type]) | ||
end | ||
|
||
activities | ||
end | ||
|
||
def valid_date?(date_string) | ||
Date.parse(date_string) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will allow dates in the future. Do we want to prevent this? |
||
rescue ArgumentError | ||
false | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||
<%= form_with url: project_activities_path(current_project), method: :get, remote: true, class: 'd-flex flex-xl-row flex-column gap-3', data: { behavior: 'activity-filters' } do |f| %> | ||||||
<div class="d-flex flex-column flex-sm-row w-100 gap-3"> | ||||||
<div class="w-100"> | ||||||
<%= f.label :user_id, class: 'form-label' %> | ||||||
<%= f.select :user_id, options_from_collection_for_select(@users_for_select, :id, :name, params[:user_id]), { include_blank: 'All users' }, { class: 'form-select' } %> | ||||||
</div> | ||||||
<div class="w-100"> | ||||||
<%= f.label :trackable_type, class: 'form-label' %> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we label this something more user-friendly? |
||||||
<%= f.select :trackable_type, options_from_collection_for_select(current_project.activities.pluck(:trackable_type).uniq, :to_s, :demodulize, params[:trackable_type] ), { include_blank: 'All types', selected: params[:type] }, { class: 'form-select' } %> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get the collection of trackable types in the controller? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we split this across multiple lines? ditto for the other fields |
||||||
</div> | ||||||
</div> | ||||||
|
||||||
<div class="w-100"> | ||||||
<span class="form-label mb-2 d-block">Date range</span> | ||||||
<div class="d-flex flex-column flex-sm-row gap-3 w-100"> | ||||||
<div class="input-group"> | ||||||
<%= f.date_field :since, max: params[:before] || Date.today, min: "01-01-2016", placeholder: 'From date', value: params[:since], class: 'form-control', data: { behavior: 'since' } %> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for the min date choice? |
||||||
<%= f.label :since, class: 'visually-hidden' %> | ||||||
<span class="input-group-text">to</span> | ||||||
<%= f.label :before, class: 'visually-hidden' %> | ||||||
<%= f.date_field :before, max: Date.today, min: params[:since], placeholder: 'To date', value: params[:before] || Date.today, class: 'form-control' %> | ||||||
</div> | ||||||
|
||||||
<%= link_to project_activities_path(current_project.id), class: 'text-error-hover text-nowrap d-flex align-items-center' do %> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<i class="fa-solid fa-xmark me-2"></i> Clear filters | ||||||
<% end %> | ||||||
</div> | ||||||
</div> | ||||||
<% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.