mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 05:04:35 +08:00
Improve sidebar rendering performance [SCI-2478]
This commit is contained in:
parent
c6cf5f1aab
commit
2ddc0fb561
14 changed files with 96 additions and 119 deletions
|
@ -11,7 +11,7 @@ class ExperimentsController < ApplicationController
|
||||||
before_action :set_project,
|
before_action :set_project,
|
||||||
only: %i(new create samples_index samples module_archive
|
only: %i(new create samples_index samples module_archive
|
||||||
clone_modal move_modal delete_samples)
|
clone_modal move_modal delete_samples)
|
||||||
before_action :load_projects_by_teams, only: %i(canvas samples module_archive)
|
before_action :load_projects_tree, only: %i(canvas samples module_archive)
|
||||||
before_action :check_view_permissions,
|
before_action :check_view_permissions,
|
||||||
only: %i(canvas module_archive)
|
only: %i(canvas module_archive)
|
||||||
before_action :check_manage_permissions, only: :edit
|
before_action :check_manage_permissions, only: :edit
|
||||||
|
@ -348,9 +348,8 @@ class ExperimentsController < ApplicationController
|
||||||
params.require(:experiment).permit(:name, :description, :archived)
|
params.require(:experiment).permit(:name, :description, :archived)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_projects_by_teams
|
def load_projects_tree
|
||||||
@projects_by_teams = current_user.projects_by_teams(current_team.id,
|
@projects_tree = current_user.projects_tree(current_team, nil)
|
||||||
nil, false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_view_permissions
|
def check_view_permissions
|
||||||
|
|
|
@ -21,8 +21,8 @@ class MyModulesController < ApplicationController
|
||||||
unassign_repository_records_modal
|
unassign_repository_records_modal
|
||||||
assign_repository_records_modal
|
assign_repository_records_modal
|
||||||
repository_index)
|
repository_index)
|
||||||
before_action :load_projects_by_teams, only: %i(protocols results activities
|
before_action :load_projects_tree, only: %i(protocols results activities
|
||||||
samples repository archive)
|
samples repository archive)
|
||||||
before_action :check_manage_permissions_archive, only: %i(update destroy)
|
before_action :check_manage_permissions_archive, only: %i(update destroy)
|
||||||
before_action :check_manage_permissions, only: %i(description due_date)
|
before_action :check_manage_permissions, only: %i(description due_date)
|
||||||
before_action :check_view_permissions, only:
|
before_action :check_view_permissions, only:
|
||||||
|
@ -659,9 +659,8 @@ class MyModulesController < ApplicationController
|
||||||
render_403 unless can_read_team?(@repository.team)
|
render_403 unless can_read_team?(@repository.team)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_projects_by_teams
|
def load_projects_tree
|
||||||
@projects_by_teams = current_user.projects_by_teams(current_team.id,
|
@projects_tree = current_user.projects_tree(current_team, nil)
|
||||||
nil, false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_manage_permissions
|
def check_manage_permissions
|
||||||
|
|
|
@ -9,7 +9,7 @@ class ProjectsController < ApplicationController
|
||||||
notifications reports
|
notifications reports
|
||||||
samples experiment_archive
|
samples experiment_archive
|
||||||
delete_samples samples_index)
|
delete_samples samples_index)
|
||||||
before_action :load_projects_by_teams, only: %i(index show samples archive
|
before_action :load_projects_tree, only: %i(index show samples archive
|
||||||
experiment_archive)
|
experiment_archive)
|
||||||
before_action :load_archive_vars, only: :archive
|
before_action :load_archive_vars, only: :archive
|
||||||
before_action :check_view_permissions, only: %i(show reports notifications
|
before_action :check_view_permissions, only: %i(show reports notifications
|
||||||
|
@ -313,26 +313,24 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_projects_by_teams
|
def load_projects_tree
|
||||||
if current_user.teams.any?
|
if current_user.teams.any?
|
||||||
@current_team_id = current_team.id if current_team
|
@current_team = current_team if current_team
|
||||||
|
|
||||||
@current_team_id ||= current_user.teams.first.id
|
@current_team ||= current_user.teams.first
|
||||||
@current_sort = params[:sort].to_s
|
@current_sort = params[:sort].to_s
|
||||||
@projects_by_teams = current_user.projects_by_teams(@current_team_id,
|
@projects_tree = current_user.projects_tree(@current_team, @current_sort)
|
||||||
@current_sort,
|
|
||||||
false)
|
|
||||||
else
|
else
|
||||||
@projects_by_teams = []
|
@projects_tree = []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_archive_vars
|
def load_archive_vars
|
||||||
if current_user.teams.any?
|
if current_user.teams.any?
|
||||||
@archived_projects_by_teams =
|
@archived_projects_by_teams =
|
||||||
current_user.projects_by_teams(@current_team_id, @current_sort, true)
|
current_user.projects_by_teams(@current_team.id, @current_sort, true)
|
||||||
else
|
else
|
||||||
@projects_by_teams = []
|
@archived_projects_by_teams = []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ class Experiment < ApplicationRecord
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
has_many :my_modules, inverse_of: :experiment, dependent: :destroy
|
has_many :my_modules, inverse_of: :experiment, dependent: :destroy
|
||||||
|
has_many :active_my_modules, -> { where(archived: false) },
|
||||||
|
class_name: 'MyModule'
|
||||||
has_many :my_module_groups, inverse_of: :experiment, dependent: :destroy
|
has_many :my_module_groups, inverse_of: :experiment, dependent: :destroy
|
||||||
has_many :report_elements, inverse_of: :experiment, dependent: :destroy
|
has_many :report_elements, inverse_of: :experiment, dependent: :destroy
|
||||||
has_many :activities, inverse_of: :experiment
|
has_many :activities, inverse_of: :experiment
|
||||||
|
|
|
@ -32,6 +32,8 @@ class Project < ApplicationRecord
|
||||||
has_many :user_projects, inverse_of: :project
|
has_many :user_projects, inverse_of: :project
|
||||||
has_many :users, through: :user_projects
|
has_many :users, through: :user_projects
|
||||||
has_many :experiments, inverse_of: :project
|
has_many :experiments, inverse_of: :project
|
||||||
|
has_many :active_experiments, -> { where(archived: false) },
|
||||||
|
class_name: 'Experiment'
|
||||||
has_many :project_comments, foreign_key: :associated_id, dependent: :destroy
|
has_many :project_comments, foreign_key: :associated_id, dependent: :destroy
|
||||||
has_many :activities, inverse_of: :project
|
has_many :activities, inverse_of: :project
|
||||||
has_many :tags, inverse_of: :project
|
has_many :tags, inverse_of: :project
|
||||||
|
@ -156,7 +158,7 @@ class Project < ApplicationRecord
|
||||||
return (self.user_projects.select { |up| up.user == user }).first.role
|
return (self.user_projects.select { |up| up.user == user }).first.role
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_experiments(sort_by = :new)
|
def sorted_active_experiments(sort_by = :new)
|
||||||
sort = case sort_by
|
sort = case sort_by
|
||||||
when 'old' then { created_at: :asc }
|
when 'old' then { created_at: :asc }
|
||||||
when 'atoz' then { name: :asc }
|
when 'atoz' then { name: :asc }
|
||||||
|
|
|
@ -338,6 +338,30 @@ class User < ApplicationRecord
|
||||||
result || []
|
result || []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def projects_tree(team, sort_by = nil)
|
||||||
|
result = team.projects.includes(active_experiments: :active_my_modules)
|
||||||
|
unless is_admin_of_team?(team)
|
||||||
|
# Only admins see all projects of the team
|
||||||
|
result = result.includes(:user_projects).where(
|
||||||
|
'visibility = 1 OR user_projects.user_id=:user_id)', user_id: id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
sort =
|
||||||
|
case sort_by
|
||||||
|
when 'old'
|
||||||
|
{ created_at: :asc }
|
||||||
|
when 'atoz'
|
||||||
|
{ name: :asc }
|
||||||
|
when 'ztoa'
|
||||||
|
{ name: :desc }
|
||||||
|
else
|
||||||
|
{ created_at: :desc }
|
||||||
|
end
|
||||||
|
|
||||||
|
result.where(archived: false).order(sort)
|
||||||
|
end
|
||||||
|
|
||||||
# Finds all activities of user that is assigned to project. If user
|
# Finds all activities of user that is assigned to project. If user
|
||||||
# is not an owner of the project, user must be also assigned to
|
# is not an owner of the project, user must be also assigned to
|
||||||
# module.
|
# module.
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<ul class="dropdown-menu" aria-labelledby="sortMenu">
|
<ul class="dropdown-menu" aria-labelledby="sortMenu">
|
||||||
<% ["new", "old", "atoz", "ztoa"].each do |sort| %>
|
<% ["new", "old", "atoz", "ztoa"].each do |sort| %>
|
||||||
<% if @current_sort != sort %>
|
<% if @current_sort != sort %>
|
||||||
<li><a href="?<%= {team: @current_team_id, sort: sort}.reject{|k,v| v.to_s == "0"}.to_query %>"><%= t('projects.index.sort_' + sort) %></a></li>
|
<li><a href="?<%= {team: @current_team.id, sort: sort}.reject{|k,v| v.to_s == "0"}.to_query %>"><%= t('projects.index.sort_' + sort) %></a></li>
|
||||||
<% else %>
|
<% else %>
|
||||||
<li class="disabled"><a href="#"><%= t('projects.index.sort_' + sort) %></a></li>
|
<li class="disabled"><a href="#"><%= t('projects.index.sort_' + sort) %></a></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -96,10 +96,8 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% @projects_by_teams.each do |team, projects| %>
|
<%= render partial: "projects/index/team_projects",
|
||||||
<%= render partial: "projects/index/team_projects",
|
locals: { projects: @projects_tree } %>
|
||||||
locals: {team: team, projects: projects} %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% projects.each_index do |i| project = projects[i] %>
|
<% projects.each_with_index do |project, i| %>
|
||||||
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
|
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
|
||||||
<%= render partial: "projects/index/project", locals: {project: project} %>
|
<%= render partial: "projects/index/project", locals: {project: project} %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% @project.active_experiments(@current_sort).each_with_index do |experiment, index| %>
|
<% @project.sorted_active_experiments(@current_sort).each_with_index do |experiment, index| %>
|
||||||
<%= render partial: 'projects/show/experiment',
|
<%= render partial: 'projects/show/experiment',
|
||||||
locals: { experiment: experiment } %>
|
locals: { experiment: experiment } %>
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<% if project.active_experiments.present? then %>
|
<% if project.active_experiments.present? %>
|
||||||
<ul>
|
<ul>
|
||||||
<% project.active_experiments.each do |experiment| %>
|
<% project.active_experiments.each do |experiment| %>
|
||||||
<% if (experiment_page? ||
|
<% if experiment_page? && experiment == @experiment %>
|
||||||
sample_groups_page_experiment? ||
|
|
||||||
sample_types_page_expermient?) && experiment == @experiment %>
|
|
||||||
<li class="active" data-parent="candidate">
|
<li class="active" data-parent="candidate">
|
||||||
<span class="tree-link line-wrap first-indent">
|
<span class="tree-link line-wrap first-indent">
|
||||||
<i class="no-arrow"></i>
|
<i class="no-arrow"></i>
|
||||||
|
@ -15,15 +13,11 @@
|
||||||
<li data-parent="candidate">
|
<li data-parent="candidate">
|
||||||
<span class="tree-link line-wrap first-indent">
|
<span class="tree-link line-wrap first-indent">
|
||||||
<i class="no-arrow"></i>
|
<i class="no-arrow"></i>
|
||||||
<% if can_read_experiment?(experiment) %>
|
<%= link_to experiment.name,
|
||||||
<%= link_to experiment.name,
|
experiment_action_to_link_to(experiment),
|
||||||
experiment_action_to_link_to(experiment),
|
title: experiment.name,
|
||||||
title: experiment.name,
|
class: 'overview_exp_label'
|
||||||
class: 'overview_exp_label'
|
%>
|
||||||
%>
|
|
||||||
<% else %>
|
|
||||||
<%= experiment.name %>
|
|
||||||
<% end %>
|
|
||||||
</span>
|
</span>
|
||||||
<%= render partial: 'shared/sidebar/my_modules', locals: { experiment: experiment } %>
|
<%= render partial: 'shared/sidebar/my_modules', locals: { experiment: experiment } %>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1,53 +1,18 @@
|
||||||
<% if experiment.active_modules.present? then %>
|
<% if experiment.active_my_modules.present? %>
|
||||||
<ul>
|
<ul>
|
||||||
<% experiment.active_module_groups.each do |my_module_group| %>
|
<% experiment.active_my_modules.each do |my_module| %>
|
||||||
<li data-module-group="<%= my_module_group.id %>">
|
<li class="leaf <%= "active" if currently_active? my_module %>"
|
||||||
<% if my_module_group.my_modules.present? then %>
|
data-module-id="<%= my_module.id %>">
|
||||||
<ul>
|
<span class="tree-link second-indent">
|
||||||
<span class="my-module-group-element">
|
<% if currently_active? my_module %>
|
||||||
<% my_module_group.my_modules.sort_by{|m| m.workflow_order}.each do |my_module| %>
|
<%= my_module.name %>
|
||||||
<li class="leaf <%= "active" if currently_active? my_module %>" data-module-id="<%= my_module.id %>">
|
<% else %>
|
||||||
<span class="tree-link second-indent">
|
<%= link_to my_module.name, module_action_to_link_to(my_module), data: { no_turbolink: true } %>
|
||||||
<% if currently_active? my_module %>
|
|
||||||
<%= my_module.name %>
|
|
||||||
<% else %>
|
|
||||||
<% if can_read_experiment?(my_module.experiment) %>
|
|
||||||
<%= link_to my_module.name, module_action_to_link_to(my_module), class: "module-link", data: { no_turbolink: true } %>
|
|
||||||
<% else %>
|
|
||||||
<%= my_module.name %>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
<% if is_canvas? %>
|
|
||||||
<a href="#" class="canvas-center-on"><span class="glyphicon glyphicon-map-marker"></span></a>
|
|
||||||
<% end %>
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</span>
|
|
||||||
</ul>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<% modules_without_group = experiment.modules_without_group %>
|
|
||||||
<% if modules_without_group.present? then %>
|
|
||||||
<li>
|
|
||||||
<ul>
|
|
||||||
<% modules_without_group.each do |my_module| %>
|
|
||||||
<li class="leaf <%= "active" if currently_active? my_module %>"
|
|
||||||
data-module-id="<%= my_module.id %>">
|
|
||||||
<span class="tree-link second-indent">
|
|
||||||
<% if currently_active? my_module %>
|
|
||||||
<%= my_module.name %>
|
|
||||||
<% else %>
|
|
||||||
<%= link_to my_module.name, module_action_to_link_to(my_module), data: { no_turbolink: true } %>
|
|
||||||
<% end %>
|
|
||||||
<% if is_canvas? %>
|
|
||||||
<a href="" class="canvas-center-on"><span class="glyphicon glyphicon-map-marker"></span></a>
|
|
||||||
<% end %>
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
<% if is_canvas? %>
|
||||||
|
<a href="" class="canvas-center-on"><span class="glyphicon glyphicon-map-marker"></span></a>
|
||||||
|
<% end %>
|
||||||
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -1,35 +1,31 @@
|
||||||
<ul>
|
<ul>
|
||||||
<% if @projects_by_teams.present? then %>
|
<% if @projects_tree.present? then %>
|
||||||
<% @projects_by_teams.each do |team, projects| %>
|
<% @projects_tree.each do |project| %>
|
||||||
<% projects.each do |project| %>
|
<% if (project_page? ||
|
||||||
|
sample_types_page_project? ||
|
||||||
<% if (project_page? ||
|
sample_groups_page_project?) && project == @project %>
|
||||||
sample_types_page_project? ||
|
<li class="active" data-parent="candidate">
|
||||||
sample_groups_page_project?) && project == @project %>
|
<span class="tree-link line-wrap no-indent">
|
||||||
<li class="active" data-parent="candidate">
|
<i class="no-arrow"></i>
|
||||||
<span class="tree-link line-wrap no-indent">
|
<span data-project-id="<%= @project.id %>"
|
||||||
<i class="no-arrow"></i>
|
title="<%= @project.name %>"><%= @project.name %></span>
|
||||||
<span data-project-id="<%= @project.id %>"
|
</span>
|
||||||
title="<%= @project.name %>"><%= @project.name %></span>
|
<%= render partial: 'shared/sidebar/experiments',
|
||||||
</span>
|
locals: { project: project } %>
|
||||||
<%= render partial: 'shared/sidebar/experiments',
|
</li>
|
||||||
locals: { project: project } %>
|
<% else %>
|
||||||
</li>
|
<li data-parent="candidate">
|
||||||
<% else %>
|
<span class="tree-link line-wrap no-indent">
|
||||||
<li data-parent="candidate">
|
<i class="no-arrow"></i>
|
||||||
<span class="tree-link line-wrap no-indent">
|
<%= link_to project.name,
|
||||||
<i class="no-arrow"></i>
|
project_action_to_link_to(project),
|
||||||
<%= link_to project.name,
|
title: project.name,
|
||||||
project_action_to_link_to(project),
|
data: { project_id: project.id } %>
|
||||||
title: project.name,
|
</span>
|
||||||
data: { project_id: project.id } %>
|
<%= render partial: 'shared/sidebar/experiments',
|
||||||
</span>
|
locals: { project: project } %>
|
||||||
<%= render partial: 'shared/sidebar/experiments',
|
</li>
|
||||||
locals: { project: project } %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -75,7 +75,7 @@ Rails.application.configure do
|
||||||
config.assets.raise_runtime_errors = true
|
config.assets.raise_runtime_errors = true
|
||||||
|
|
||||||
# Only log info and higher on development
|
# Only log info and higher on development
|
||||||
config.log_level = :info
|
config.log_level = :debug
|
||||||
|
|
||||||
# Only allow Better Errors to work on trusted ip, use ifconfig to see which
|
# Only allow Better Errors to work on trusted ip, use ifconfig to see which
|
||||||
# one you use and put it into application.yml!
|
# one you use and put it into application.yml!
|
||||||
|
|
Loading…
Add table
Reference in a new issue