mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Change filtering logic when no filters are selected [SCI-3223]
This commit is contained in:
parent
935e3a65cf
commit
2ff43a3320
3 changed files with 40 additions and 34 deletions
|
@ -34,11 +34,23 @@ function GlobalActivitiesFilterPrepareArray() {
|
|||
if (subjectFilter[splitObject[0]] === undefined) subjectFilter[splitObject[0]] = [];
|
||||
subjectFilter[splitObject[0]].push(parseInt(splitObject[1], 10));
|
||||
});
|
||||
|
||||
// Clear request parameters if all options are selected
|
||||
if (teamFilter.length === $('.ga-side .team-selector option').length) {
|
||||
teamFilter = [];
|
||||
}
|
||||
if (userFilter.length === $('.ga-side .user-selector option').length) {
|
||||
userFilter = [];
|
||||
}
|
||||
if (activityFilter.length === $('.ga-side .activity-selector option').length) {
|
||||
activityFilter = [];
|
||||
}
|
||||
|
||||
return {
|
||||
teams: JSON.stringify(teamFilter),
|
||||
users: JSON.stringify(userFilter),
|
||||
types: JSON.stringify(activityFilter),
|
||||
subjects: JSON.stringify(subjectFilter),
|
||||
teams: teamFilter,
|
||||
users: userFilter,
|
||||
types: activityFilter,
|
||||
subjects: subjectFilter,
|
||||
from_date: GlobalActivitiesFiltersGetDates().from,
|
||||
to_date: GlobalActivitiesFiltersGetDates().to
|
||||
};
|
||||
|
@ -171,6 +183,7 @@ $(function() {
|
|||
$('#calendar-from-date').data('DateTimePicker').clear();
|
||||
$('#calendar-to-date').data('DateTimePicker').clear();
|
||||
updateRunning = false;
|
||||
GlobalActivitiesUpdateTopPaneTags();
|
||||
reloadActivities();
|
||||
});
|
||||
|
||||
|
|
|
@ -2,15 +2,20 @@
|
|||
|
||||
class GlobalActivitiesController < ApplicationController
|
||||
def index
|
||||
teams = activity_filters[:teams]
|
||||
@teams = current_user.teams
|
||||
teams = current_team if teams.blank?
|
||||
selected_teams = if request.format.html?
|
||||
current_team
|
||||
elsif activity_filters[:teams].present?
|
||||
@teams.where(id: activity_filters[:teams])
|
||||
else
|
||||
@teams
|
||||
end
|
||||
@activity_types = Activity.activity_types_list
|
||||
@user_list = User.where(id: UserTeam.where(team: current_user.teams).select(:user_id))
|
||||
.distinct
|
||||
.pluck(:full_name, :id)
|
||||
@grouped_activities, @more_activities =
|
||||
ActivitiesService.load_activities(current_user, teams, activity_filters)
|
||||
ActivitiesService.load_activities(current_user, selected_teams, activity_filters)
|
||||
last_day = @grouped_activities.keys.last
|
||||
@next_date = (Date.parse(last_day) - 1.day).strftime('%Y-%m-%d') if last_day
|
||||
respond_to do |format|
|
||||
|
@ -63,14 +68,6 @@ class GlobalActivitiesController < ApplicationController
|
|||
private
|
||||
|
||||
def activity_filters
|
||||
begin
|
||||
params[:types] = JSON.parse(params[:types])
|
||||
params[:users] = JSON.parse(params[:users])
|
||||
params[:teams] = JSON.parse(params[:teams])
|
||||
params[:subjects] = JSON.parse(params[:subjects])
|
||||
rescue StandardError
|
||||
end
|
||||
|
||||
params.permit(
|
||||
:from_date, :to_date, types: [], subjects: {}, users: [], teams: []
|
||||
)
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
class ActivitiesService
|
||||
def self.load_activities(user, teams, filters = {})
|
||||
# Create condition for view permissions checking first
|
||||
visible_projects = Project.viewable_by_user(user, teams)
|
||||
query = Activity.where('project_id IS NULL AND team_id IN (?)', teams)
|
||||
.or(Activity.where(project: visible_projects))
|
||||
|
||||
visible_teams = user.teams.where(id: teams)
|
||||
visible_projects = Project.viewable_by_user(user, visible_teams)
|
||||
query = Activity.where(project: visible_projects)
|
||||
.or(Activity.where(project: nil, team: visible_teams))
|
||||
if filters[:subjects].present?
|
||||
query = query.where(
|
||||
filters[:subjects]
|
||||
|
@ -18,20 +18,16 @@ class ActivitiesService
|
|||
query = query.where(owner_id: filters[:users]) if filters[:users]
|
||||
query = query.where(type_of: filters[:types]) if filters[:types]
|
||||
|
||||
if filters[:from_date].present? && filters[:to_date].present?
|
||||
activities = query.where(
|
||||
'created_at <= :from AND created_at >= :to',
|
||||
from: Time.zone.parse(filters[:from_date]).beginning_of_day.utc,
|
||||
to: Time.zone.parse(filters[:to_date]).end_of_day.utc
|
||||
)
|
||||
elsif filters[:from_date].present? && filters[:to_date].blank?
|
||||
activities = query.where(
|
||||
'created_at <= :from',
|
||||
from: Time.zone.parse(filters[:from_date]).beginning_of_day.utc
|
||||
)
|
||||
else
|
||||
activities = query
|
||||
end
|
||||
activities =
|
||||
if filters[:from_date].present? && filters[:to_date].present?
|
||||
query.where('created_at <= :from AND created_at >= :to',
|
||||
from: Time.zone.parse(filters[:from_date]).end_of_day.utc,
|
||||
to: Time.zone.parse(filters[:to_date]).beginning_of_day.utc)
|
||||
elsif filters[:from_date].present? && filters[:to_date].blank?
|
||||
query.where('created_at <= :from', from: Time.zone.parse(filters[:from_date]).end_of_day.utc)
|
||||
else
|
||||
query
|
||||
end
|
||||
|
||||
activities = activities.order(created_at: :desc)
|
||||
.limit(Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT)
|
||||
|
@ -51,7 +47,7 @@ class ActivitiesService
|
|||
|
||||
more_left = query.where(
|
||||
'created_at < :from',
|
||||
from: Time.zone.parse(last_date).end_of_day.utc
|
||||
from: Time.zone.parse(last_date).prev_day.end_of_day.utc
|
||||
).exists?
|
||||
|
||||
results[last_date] = activities.to_a
|
||||
|
|
Loading…
Reference in a new issue