From 9581e2751f59f0001bbeb96df44d6c57ad3e48d6 Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 2 Aug 2016 08:44:07 +0200 Subject: [PATCH] fixes samples page for experiment level [fixes SCI-44] --- app/controllers/experiments_controller.rb | 22 ++++++++++++++++--- app/helpers/permission_helper.rb | 6 ++++- app/helpers/secondary_navigation_helper.rb | 4 ++++ app/views/experiments/samples.html.erb | 7 ++++++ .../shared/_secondary_navigation.html.erb | 8 +++++++ config/routes.rb | 5 ++++- 6 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 app/views/experiments/samples.html.erb diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index 1ef63c8b6..0da3fbecc 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -1,8 +1,8 @@ class ExperimentsController < ApplicationController include PermissionHelper before_action :set_experiment, except: [:new, :create] - before_action :set_project, only: [:new, :create] - before_action :check_view_permissions, only: [:canvas] + before_action :set_project, only: [:new, :create, :samples_index, :samples ] + # before_action :check_view_permissions, only: [:canvas] # except parameter could be used but it is not working. layout :choose_layout @@ -66,6 +66,22 @@ class ExperimentsController < ApplicationController end end + def samples + @samples_index_link = samples_index_experiment_path(@experiment, format: :json) + @organization = @experiment.project.organization + end + + def samples_index + @organization = @experiment.project.organization + + respond_to do |format| + format.html + format.json { + render json: ::SampleDatatable.new(view_context, @organization, @experiment, nil) + } + end + end + private def set_experiment @@ -74,7 +90,7 @@ class ExperimentsController < ApplicationController end def set_project - @project = Project.find_by_id(params[:project_id]) + @project = Project.find_by_id(params[:project_id]) || @experiment.project render_404 unless @project end diff --git a/app/helpers/permission_helper.rb b/app/helpers/permission_helper.rb index 162d332b3..f061a4ca7 100644 --- a/app/helpers/permission_helper.rb +++ b/app/helpers/permission_helper.rb @@ -140,7 +140,8 @@ module PermissionHelper :can_view_experiment, :can_view_experiment_archive, :can_archive_experiment, - :can_restore_experiment + :can_restore_experiment, + :can_view_experiment_samples ] do |proxy, *args, &block| if args[0] experiment = args[0] @@ -346,6 +347,9 @@ module PermissionHelper experiment.archived? and is_user_or_higher_of_project(experiment.project) end + def can_view_experiment_samples(experiment) + can_view_samples(experiment.project.organization) + end # ---- WORKFLOW PERMISSIONS ---- def can_edit_canvas(experiment) diff --git a/app/helpers/secondary_navigation_helper.rb b/app/helpers/secondary_navigation_helper.rb index a12c48af7..e867d3c4a 100644 --- a/app/helpers/secondary_navigation_helper.rb +++ b/app/helpers/secondary_navigation_helper.rb @@ -28,6 +28,10 @@ module SecondaryNavigationHelper action_name == 'module_archive' end + def is_experiment_samples? + action_name == 'samples' + end + def is_module_info? action_name == 'show' end diff --git a/app/views/experiments/samples.html.erb b/app/views/experiments/samples.html.erb new file mode 100644 index 000000000..4f5692ae9 --- /dev/null +++ b/app/views/experiments/samples.html.erb @@ -0,0 +1,7 @@ +<% provide(:head_title, raw(t("projects.samples.head_title", project: @experiment.name))) %> +<%= render partial: "shared/sidebar" %> +<%= render partial: "shared/secondary_navigation" %> + +
+ <%= render partial: "shared/samples" %> +
diff --git a/app/views/shared/_secondary_navigation.html.erb b/app/views/shared/_secondary_navigation.html.erb index 1b57b912d..6d3516adf 100644 --- a/app/views/shared/_secondary_navigation.html.erb +++ b/app/views/shared/_secondary_navigation.html.erb @@ -99,6 +99,14 @@ <% end %> <% elsif experiment_page? %> + <% if can_view_experiment_samples(@experiment) then %> +
  • "> + "> + + + +
  • + <% end %> <% if can_view_experiment(@experiment) then %>
  • "> "> diff --git a/config/routes.rb b/config/routes.rb index dabf2e151..41ac22cf9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -101,7 +101,7 @@ Rails.application.routes.draw do get 'users/edit', to: 'user_projects#index_edit' end - resources :experiments do + resources :experiments, only: :show do member do get 'canvas' # Overview/structure for single experiment get 'canvas/edit', to: 'canvas#edit' # AJAX-loaded canvas edit mode (from canvas) @@ -110,6 +110,9 @@ Rails.application.routes.draw do get 'canvas/small_zoom', to: 'canvas#small_zoom' # AJAX-loaded canvas zoom post 'canvas', to: 'canvas#update' # Save updated canvas action get 'module_archive' # Module archive for single experiment + get 'samples' # Samples for single project + post 'samples_index' # Renders sample datatable for single project (ajax action) + post :delete_samples, constraints: CommitParamRouting.new(MyModulesController::DELETE_SAMPLES), action: :delete_samples end end