diff --git a/app/assets/javascripts/sidebar.js b/app/assets/javascripts/sidebar.js index d06ab9afb..b31678f80 100644 --- a/app/assets/javascripts/sidebar.js +++ b/app/assets/javascripts/sidebar.js @@ -114,6 +114,33 @@ } } + // Make active current project/experiment/task + function activateCurrent() { + var sidebar = $('#slide-panel'); + var projectId = sidebar.data('current-project'); + var experimentId = sidebar.data('current-experiment'); + var taskId = sidebar.data('current-task'); + var currentPage = sidebar.data('page'); + var li; + + if (currentPage === 'project') { + li = sidebar.find('li[data-project-id="' + projectId + '"]'); + } else if (currentPage === 'experiment') { + li = sidebar.find('[data-experiment-id="' + experimentId + '"]'); + } else if (currentPage === 'canvas') { + li = sidebar.find('[data-experiment-id="' + experimentId + '"]'); + li.find('.task-tree-link') + .append('' + + ''); + } else if (currentPage === 'task') { + li = sidebar.find('[data-module-id="' + taskId + '"]'); + } + li.find('a:first').addClass('disabled'); + li.addClass('active'); + } + + activateCurrent(); + // Add triangle icons and titles to every parent node $('.tree li:has(ul)') .addClass('parent_li') diff --git a/app/assets/stylesheets/partials/_sidebar.scss b/app/assets/stylesheets/partials/_sidebar.scss index e726e143b..f3eed2ba0 100644 --- a/app/assets/stylesheets/partials/_sidebar.scss +++ b/app/assets/stylesheets/partials/_sidebar.scss @@ -68,6 +68,14 @@ $toggle-btn-size: 50px; #slide-panel { height: 100%; + .disabled { + opacity: 1; + } + + .fa-caret-right { + padding: 3px 5px; + } + .tree { margin-bottom: 0; opacity: 1; diff --git a/app/helpers/sidebar_helper.rb b/app/helpers/sidebar_helper.rb index 47952732d..eafb8f930 100644 --- a/app/helpers/sidebar_helper.rb +++ b/app/helpers/sidebar_helper.rb @@ -1,13 +1,4 @@ module SidebarHelper - - def currently_active?(my_module) - @my_module.present? and @my_module.id == my_module.id - end - - def is_canvas? - action_name == "canvas" - end - def project_action_to_link_to(project) case action_name when 'samples' diff --git a/app/models/experiment.rb b/app/models/experiment.rb index fec46ca43..6bd1ce1e1 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -19,7 +19,8 @@ class Experiment < ApplicationRecord optional: true has_many :my_modules, inverse_of: :experiment, dependent: :destroy - has_many :active_my_modules, -> { where(archived: false) }, + has_many :active_my_modules, + -> { where(archived: false).order(:workflow_order) }, class_name: 'MyModule' has_many :my_module_groups, inverse_of: :experiment, dependent: :destroy has_many :report_elements, inverse_of: :experiment, dependent: :destroy diff --git a/app/models/project.rb b/app/models/project.rb index 80a8d5777..5c7e6876a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -27,7 +27,7 @@ class Project < ApplicationRecord foreign_key: 'restored_by_id', class_name: 'User', optional: true - belongs_to :team, inverse_of: :projects, optional: true + belongs_to :team, inverse_of: :projects, touch: true, optional: true has_many :user_projects, inverse_of: :project has_many :users, through: :user_projects has_many :experiments, inverse_of: :project diff --git a/app/views/experiments/canvas.html.erb b/app/views/experiments/canvas.html.erb index 8d2a3bdad..a9c7d008f 100644 --- a/app/views/experiments/canvas.html.erb +++ b/app/views/experiments/canvas.html.erb @@ -1,5 +1,5 @@ <% provide(:head_title, t("experiments.canvas.head_title", project: h(@project.name)).html_safe) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_experiment: @experiment, page: 'canvas' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/experiments/module_archive.html.erb b/app/views/experiments/module_archive.html.erb index ee1f1d8d0..e0f0bc904 100644 --- a/app/views/experiments/module_archive.html.erb +++ b/app/views/experiments/module_archive.html.erb @@ -1,5 +1,5 @@ <% provide(:head_title, t("experiments.module_archive.head_title", experiment: h(@experiment.name)).html_safe) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_experiment: @experiment, page: 'experiment' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/my_modules/activities.html.erb b/app/views/my_modules/activities.html.erb index 5365906b8..027b784b8 100644 --- a/app/views/my_modules/activities.html.erb +++ b/app/views/my_modules/activities.html.erb @@ -1,5 +1,5 @@ <% provide(:head_title, t("my_modules.activities.head_title", project: h(@my_module.experiment.project.name), module: h(@my_module.name)).html_safe) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/my_modules/archive.html.erb b/app/views/my_modules/archive.html.erb index 886d1e0b2..b68cafe65 100644 --- a/app/views/my_modules/archive.html.erb +++ b/app/views/my_modules/archive.html.erb @@ -1,5 +1,5 @@ <% provide(:head_title, t("my_modules.module_archive.head_title", project: h(@my_module.experiment.project.name), module: h(@my_module.name)).html_safe) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/my_modules/protocols.html.erb b/app/views/my_modules/protocols.html.erb index 6ad77a783..f5d3883d8 100644 --- a/app/views/my_modules/protocols.html.erb +++ b/app/views/my_modules/protocols.html.erb @@ -1,7 +1,7 @@ <% provide(:head_title, t("my_modules.protocols.head_title", project: h(@project.name), module: h(@my_module.name)).html_safe) %> <%= render partial: 'shared/drag_n_drop_overlay' %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/my_modules/repository.html.erb b/app/views/my_modules/repository.html.erb index b932c7350..904f0491d 100644 --- a/app/views/my_modules/repository.html.erb +++ b/app/views/my_modules/repository.html.erb @@ -6,7 +6,7 @@ project: h(@project.name), module: h(@my_module.name), repository: @repository.name).html_safe) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/my_modules/results.html.erb b/app/views/my_modules/results.html.erb index d672db880..4777f59d8 100644 --- a/app/views/my_modules/results.html.erb +++ b/app/views/my_modules/results.html.erb @@ -1,5 +1,5 @@ <% provide(:head_title, t("my_modules.results.head_title", project: h(@project.name), module: h(@my_module.name)).html_safe) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %> <%= render partial: "shared/secondary_navigation" %> <%= render partial: 'shared/drag_n_drop_overlay' %> diff --git a/app/views/projects/archive.html.erb b/app/views/projects/archive.html.erb index 90328f23c..03753fd4e 100644 --- a/app/views/projects/archive.html.erb +++ b/app/views/projects/archive.html.erb @@ -1,5 +1,5 @@ <% provide(:head_title, t("projects.archive.head_title")) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { page: 'project' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/projects/experiment_archive.html.erb b/app/views/projects/experiment_archive.html.erb index 1c165c281..fefe9f572 100644 --- a/app/views/projects/experiment_archive.html.erb +++ b/app/views/projects/experiment_archive.html.erb @@ -1,5 +1,5 @@ <% provide(:head_title, t("projects.experiment_archive.head_title", project: h(@project.name)).html_safe) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_project: @project, page: 'project' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index f852217b4..cc798773b 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -1,7 +1,7 @@ <% provide(:head_title, t("projects.index.head_title")) %> <% if current_team %> - <%= render partial: "shared/sidebar" %> + <%= render partial: "shared/sidebar", locals: { page: 'project' } %> <%= render partial: "shared/secondary_navigation" %> <% if can_create_projects?(current_team) %> diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 0df95b3bf..ff4a036f1 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -1,5 +1,5 @@ <% provide(:head_title, t("projects.show.head_title", project: h(@project.name)).html_safe) %> -<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/sidebar", locals: { current_project: @project, page: 'project' } %> <%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/shared/_sidebar.html.erb b/app/views/shared/_sidebar.html.erb index 617f25e22..de8521450 100644 --- a/app/views/shared/_sidebar.html.erb +++ b/app/views/shared/_sidebar.html.erb @@ -1,8 +1,19 @@ <%= content_for :sidebar do %> -
+ <% current_task ||= current_task || nil %> + <% current_experiment ||= current_experiment || current_task&.experiment || nil %> + <% current_project ||= current_experiment&.project || current_task&.experiment&.project || nil %> + +
    - <%= render partial: 'shared/sidebar/projects' %> + <% cache [current_user, current_team] do %> + <%= render partial: 'shared/sidebar/projects' %> + <% end %>
diff --git a/app/views/shared/sidebar/_experiments.html.erb b/app/views/shared/sidebar/_experiments.html.erb index 49c0acc1f..e6090749c 100644 --- a/app/views/shared/sidebar/_experiments.html.erb +++ b/app/views/shared/sidebar/_experiments.html.erb @@ -1,16 +1,8 @@ <% if project.active_experiments.present? %>
    <% project.active_experiments.each do |experiment| %> - <% if experiment_page? && experiment == @experiment %> -
  • - - - <%= @experiment.name %> - - <%= render partial: 'shared/sidebar/my_modules', locals: { experiment: @experiment } %> -
  • - <% else %> -
  • + <% cache [current_user, experiment] do %> +
  • <%= link_to experiment.name, diff --git a/app/views/shared/sidebar/_my_modules.html.erb b/app/views/shared/sidebar/_my_modules.html.erb index ce5ce0625..fb2a6d483 100644 --- a/app/views/shared/sidebar/_my_modules.html.erb +++ b/app/views/shared/sidebar/_my_modules.html.erb @@ -1,21 +1,11 @@ <% if experiment.active_my_modules.present? %>
      - <% experiment.active_my_modules.sort_by{ |m| m.workflow_order }.each do |my_module| %> - -
    • " - data-module-id="<%= my_module.id %>"> - - <% if currently_active? my_module %> - <%= my_module.name %> - <% else %> - <%= link_to my_module.name, module_action_to_link_to(my_module) %> - <% end %> - <% if is_canvas? %> - - <% end %> + <% experiment.active_my_modules.each do |my_module| %> +
    • + + <%= link_to my_module.name, module_action_to_link_to(my_module) %>
    • - <% end %>
    <% end %> diff --git a/app/views/shared/sidebar/_projects.html.erb b/app/views/shared/sidebar/_projects.html.erb index ab32806dc..4bdd17ac8 100644 --- a/app/views/shared/sidebar/_projects.html.erb +++ b/app/views/shared/sidebar/_projects.html.erb @@ -1,29 +1,16 @@
      - <% if @projects_tree.present? then %> - <% @projects_tree.each do |project| %> - <% if project_page? && project == @project %> -
    • - - - <%= @project.name %> - - <%= render partial: 'shared/sidebar/experiments', - locals: { project: project } %> -
    • - <% else %> -
    • - - - <%= link_to project.name, - project_action_to_link_to(project), - title: project.name, - data: { project_id: project.id } %> - - <%= render partial: 'shared/sidebar/experiments', - locals: { project: project } %> -
    • - <% end %> + <% @projects_tree.each do |project| %> + <% cache [current_user, project] do %> +
    • + + + <%= link_to project.name, + project_action_to_link_to(project), + title: project.name, + data: { project_id: project.id } %> + + <%= render partial: 'shared/sidebar/experiments', locals: { project: project } %> +
    • <% end %> <% end %>