mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-08 04:47:22 +08:00
Merge branch 'zd_SCI_44' of https://github.com/ZmagoD/scinote-web into ZmagoD-zd_SCI_44
This commit is contained in:
commit
9c5c4f0a3a
8 changed files with 138 additions and 25 deletions
|
@ -1,7 +1,7 @@
|
||||||
class ExperimentsController < ApplicationController
|
class ExperimentsController < ApplicationController
|
||||||
include PermissionHelper
|
include PermissionHelper
|
||||||
before_action :set_experiment, except: [:new, :create]
|
before_action :set_experiment, except: [:new, :create]
|
||||||
before_action :set_project, only: [:new, :create]
|
before_action :set_project, only: [:new, :create, :samples_index, :samples]
|
||||||
before_action :check_view_permissions, only: [:canvas]
|
before_action :check_view_permissions, only: [:canvas]
|
||||||
|
|
||||||
# except parameter could be used but it is not working.
|
# except parameter could be used but it is not working.
|
||||||
|
@ -57,6 +57,7 @@ class ExperimentsController < ApplicationController
|
||||||
if @experiment.save
|
if @experiment.save
|
||||||
flash[:success] = t('experiments.update.success_flash',
|
flash[:success] = t('experiments.update.success_flash',
|
||||||
experiment: @experiment.name)
|
experiment: @experiment.name)
|
||||||
|
|
||||||
redirect_to canvas_experiment_path(@experiment)
|
redirect_to canvas_experiment_path(@experiment)
|
||||||
else
|
else
|
||||||
flash[:alert] = t('experiments.update.error_flash')
|
flash[:alert] = t('experiments.update.error_flash')
|
||||||
|
@ -71,6 +72,7 @@ class ExperimentsController < ApplicationController
|
||||||
if @experiment.save
|
if @experiment.save
|
||||||
flash[:success] = t('experiments.archive.success_flash',
|
flash[:success] = t('experiments.archive.success_flash',
|
||||||
experiment: @experiment.name)
|
experiment: @experiment.name)
|
||||||
|
|
||||||
redirect_to project_path(@experiment.project)
|
redirect_to project_path(@experiment.project)
|
||||||
else
|
else
|
||||||
flash[:alert] = t('experiments.archive.error_flash')
|
flash[:alert] = t('experiments.archive.error_flash')
|
||||||
|
@ -78,6 +80,27 @@ class ExperimentsController < ApplicationController
|
||||||
end
|
end
|
||||||
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 do
|
||||||
|
render json: ::SampleDatatable.new(view_context,
|
||||||
|
@organization,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
@experiment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_experiment
|
def set_experiment
|
||||||
|
@ -86,7 +109,7 @@ class ExperimentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_project
|
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
|
render_404 unless @project
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,16 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
||||||
|
|
||||||
ASSIGNED_SORT_COL = "assigned"
|
ASSIGNED_SORT_COL = "assigned"
|
||||||
|
|
||||||
def initialize(view, organization, project = nil, my_module = nil)
|
def initialize(view,
|
||||||
|
organization,
|
||||||
|
project = nil,
|
||||||
|
my_module = nil,
|
||||||
|
experiment = nil)
|
||||||
super(view)
|
super(view)
|
||||||
@organization = organization
|
@organization = organization
|
||||||
@project = project
|
@project = project
|
||||||
@my_module = my_module
|
@my_module = my_module
|
||||||
|
@experiment = experiment
|
||||||
end
|
end
|
||||||
|
|
||||||
# Define sortable columns, so 1st column will be sorted by attribute in sortable_columns[0]
|
# Define sortable columns, so 1st column will be sorted by attribute in sortable_columns[0]
|
||||||
|
@ -119,24 +124,29 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
||||||
|
|
||||||
if @my_module
|
if @my_module
|
||||||
@assigned_samples = @my_module.samples
|
@assigned_samples = @my_module.samples
|
||||||
samples = samples
|
|
||||||
.joins(
|
samples = samples.joins("LEFT OUTER JOIN sample_my_modules ON
|
||||||
"LEFT OUTER JOIN sample_my_modules ON
|
|
||||||
(samples.id = sample_my_modules.sample_id AND
|
(samples.id = sample_my_modules.sample_id AND
|
||||||
(sample_my_modules.my_module_id = #{@my_module.id.to_s} OR
|
(sample_my_modules.my_module_id = #{@my_module.id.to_s} OR
|
||||||
sample_my_modules.id IS NULL))"
|
sample_my_modules.id IS NULL))")
|
||||||
)
|
|
||||||
.references(:sample_my_modules)
|
.references(:sample_my_modules)
|
||||||
elsif @project
|
elsif @project
|
||||||
@assigned_samples = @project.assigned_samples
|
@assigned_samples = @project.assigned_samples
|
||||||
ids = @project.my_modules.select(:id)
|
ids = @project.my_modules_ids
|
||||||
samples = samples
|
|
||||||
.joins(
|
samples = samples.joins("LEFT OUTER JOIN sample_my_modules ON
|
||||||
"LEFT OUTER JOIN sample_my_modules ON
|
(samples.id = sample_my_modules.sample_id AND
|
||||||
|
(sample_my_modules.my_module_id IN (#{ids}) OR
|
||||||
|
sample_my_modules.id IS NULL))")
|
||||||
|
.references(:sample_my_modules)
|
||||||
|
elsif @experiment
|
||||||
|
@assigned_samples = @experiment.assigned_samples
|
||||||
|
ids = @experiment.my_modules.select(:id)
|
||||||
|
|
||||||
|
samples = samples.joins("LEFT OUTER JOIN sample_my_modules ON
|
||||||
(samples.id = sample_my_modules.sample_id AND
|
(samples.id = sample_my_modules.sample_id AND
|
||||||
(sample_my_modules.my_module_id IN (#{ids.to_sql}) OR
|
(sample_my_modules.my_module_id IN (#{ids.to_sql}) OR
|
||||||
sample_my_modules.id IS NULL))"
|
sample_my_modules.id IS NULL))")
|
||||||
)
|
|
||||||
.references(:sample_my_modules)
|
.references(:sample_my_modules)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -172,6 +182,39 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
||||||
# Depending on the sort, order nulls first or
|
# Depending on the sort, order nulls first or
|
||||||
# nulls last on sample_my_modules association
|
# nulls last on sample_my_modules association
|
||||||
records.order("sample_my_modules.id NULLS #{sort_null_direction(params[:order].values[0])}")
|
records.order("sample_my_modules.id NULLS #{sort_null_direction(params[:order].values[0])}")
|
||||||
|
elsif @experiment
|
||||||
|
# A very elegant solution to sort assigned samples at a experiment level
|
||||||
|
|
||||||
|
# grabs the ids of samples which has a modules that belongs to this project
|
||||||
|
assigned = Sample
|
||||||
|
.joins('LEFT OUTER JOIN "sample_my_modules" ON "sample_my_modules"."sample_id" = "samples"."id"')
|
||||||
|
.joins('LEFT OUTER JOIN "my_modules" ON "my_modules"."id" = "sample_my_modules"."my_module_id"')
|
||||||
|
.where('"my_modules"."experiment_id" = ?', @experiment.id)
|
||||||
|
.where('"my_modules"."nr_of_assigned_samples" > 0')
|
||||||
|
.select('"samples"."id"')
|
||||||
|
.distinct
|
||||||
|
|
||||||
|
# grabs the ids that are not the previous one but are still of the same organization
|
||||||
|
unassigned = Sample
|
||||||
|
.where('"samples"."organization_id" = ?', @organization.id)
|
||||||
|
.where('"samples"."id" NOT IN (?)', assigned)
|
||||||
|
.select('"samples"."id"')
|
||||||
|
.distinct
|
||||||
|
|
||||||
|
# check the input param and merge the two arrays of ids
|
||||||
|
if params[:order].values[0]['dir'] == 'asc'
|
||||||
|
ids = assigned + unassigned
|
||||||
|
elsif params[:order].values[0]['dir'] == 'desc'
|
||||||
|
ids = unassigned + assigned
|
||||||
|
end
|
||||||
|
ids = ids.collect(&:id)
|
||||||
|
|
||||||
|
# order the records by input ids
|
||||||
|
order_by_index = ActiveRecord::Base.send(
|
||||||
|
:sanitize_sql_array,
|
||||||
|
["position((',' || samples.id || ',') in ?)",
|
||||||
|
ids.join(',') + ','] )
|
||||||
|
records.where(id: ids).order(order_by_index)
|
||||||
elsif @project
|
elsif @project
|
||||||
# A very elegant solution to sort assigned samples at a project level
|
# A very elegant solution to sort assigned samples at a project level
|
||||||
|
|
||||||
|
@ -179,7 +222,8 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
||||||
assigned = Sample
|
assigned = Sample
|
||||||
.joins('LEFT OUTER JOIN "sample_my_modules" ON "sample_my_modules"."sample_id" = "samples"."id"')
|
.joins('LEFT OUTER JOIN "sample_my_modules" ON "sample_my_modules"."sample_id" = "samples"."id"')
|
||||||
.joins('LEFT OUTER JOIN "my_modules" ON "my_modules"."id" = "sample_my_modules"."my_module_id"')
|
.joins('LEFT OUTER JOIN "my_modules" ON "my_modules"."id" = "sample_my_modules"."my_module_id"')
|
||||||
.where('"my_modules"."project_id" = ?', @project.id)
|
.joins('LEFT OUTER JOIN "experiments" ON "experiments"."id" = "my_modules"."experiment_id"')
|
||||||
|
.where('"experiments"."project_id" = ?', @project.id)
|
||||||
.where('"my_modules"."nr_of_assigned_samples" > 0')
|
.where('"my_modules"."nr_of_assigned_samples" > 0')
|
||||||
.select('"samples"."id"')
|
.select('"samples"."id"')
|
||||||
.distinct
|
.distinct
|
||||||
|
|
|
@ -140,7 +140,8 @@ module PermissionHelper
|
||||||
:can_view_experiment,
|
:can_view_experiment,
|
||||||
:can_view_experiment_archive,
|
:can_view_experiment_archive,
|
||||||
:can_archive_experiment,
|
:can_archive_experiment,
|
||||||
:can_restore_experiment
|
:can_restore_experiment,
|
||||||
|
:can_view_experiment_samples
|
||||||
] do |proxy, *args, &block|
|
] do |proxy, *args, &block|
|
||||||
if args[0]
|
if args[0]
|
||||||
experiment = args[0]
|
experiment = args[0]
|
||||||
|
@ -346,6 +347,9 @@ module PermissionHelper
|
||||||
experiment.archived? && is_user_or_higher_of_project(experiment.project)
|
experiment.archived? && is_user_or_higher_of_project(experiment.project)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_view_experiment_samples(experiment)
|
||||||
|
can_view_samples(experiment.project.organization)
|
||||||
|
end
|
||||||
# ---- WORKFLOW PERMISSIONS ----
|
# ---- WORKFLOW PERMISSIONS ----
|
||||||
|
|
||||||
def can_edit_canvas(experiment)
|
def can_edit_canvas(experiment)
|
||||||
|
|
|
@ -28,6 +28,10 @@ module SecondaryNavigationHelper
|
||||||
action_name == 'module_archive'
|
action_name == 'module_archive'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_experiment_samples?
|
||||||
|
action_name == 'samples'
|
||||||
|
end
|
||||||
|
|
||||||
def is_module_info?
|
def is_module_info?
|
||||||
action_name == 'show'
|
action_name == 'show'
|
||||||
end
|
end
|
||||||
|
|
|
@ -126,4 +126,17 @@ class Project < ActiveRecord::Base
|
||||||
organization.log(final)
|
organization.log(final)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assigned_samples
|
||||||
|
Sample.joins(:my_modules).where(my_modules: {
|
||||||
|
id: my_modules_ids.split(',')
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
def my_modules_ids
|
||||||
|
ids = active_experiments.map do |exp|
|
||||||
|
exp.my_modules.pluck(:id) if exp.my_modules
|
||||||
|
end
|
||||||
|
ids.delete_if { |i| i.flatten.empty? }
|
||||||
|
ids.join(', ')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
7
app/views/experiments/samples.html.erb
Normal file
7
app/views/experiments/samples.html.erb
Normal file
|
@ -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" %>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
<%= render partial: "shared/samples" %>
|
||||||
|
</div>
|
|
@ -99,6 +99,14 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% elsif experiment_page? %>
|
<% elsif experiment_page? %>
|
||||||
|
<% if can_view_experiment_samples(@experiment) then %>
|
||||||
|
<li id="experiment-samples-nav-tab" class="<%= "active" if is_experiment_samples? %>">
|
||||||
|
<a href="<%= samples_experiment_url(@experiment) %>" title="<%=t "nav2.projects.samples" %>">
|
||||||
|
<span class="hidden-sm hidden-md"><%=t "nav2.projects.samples" %></span>
|
||||||
|
<span class="hidden-xs hidden-lg glyphicon glyphicon-tint"></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
<% if can_view_experiment(@experiment) then %>
|
<% if can_view_experiment(@experiment) then %>
|
||||||
<li id="canvas-nav-tab" class="<%= "active" if is_experiment_canvas? %>">
|
<li id="canvas-nav-tab" class="<%= "active" if is_experiment_canvas? %>">
|
||||||
<a href="<%= project_url(@project) %>" title="<%=t "nav2.experiments.canvas" %>">
|
<a href="<%= project_url(@project) %>" title="<%=t "nav2.experiments.canvas" %>">
|
||||||
|
|
|
@ -103,16 +103,26 @@ Rails.application.routes.draw do
|
||||||
get 'users/edit', to: 'user_projects#index_edit'
|
get 'users/edit', to: 'user_projects#index_edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :experiments do
|
resources :experiments, only: :show do
|
||||||
member do
|
member do
|
||||||
get 'canvas' # Overview/structure for single experiment
|
get 'canvas' # Overview/structure for single experiment
|
||||||
get 'canvas/edit', to: 'canvas#edit' # AJAX-loaded canvas edit mode (from canvas)
|
# AJAX-loaded canvas edit mode (from canvas)
|
||||||
|
get 'canvas/edit', to: 'canvas#edit'
|
||||||
get 'canvas/full_zoom', to: 'canvas#full_zoom' # AJAX-loaded canvas zoom
|
get 'canvas/full_zoom', to: 'canvas#full_zoom' # AJAX-loaded canvas zoom
|
||||||
get 'canvas/medium_zoom', to: 'canvas#medium_zoom' # AJAX-loaded canvas zoom
|
# AJAX-loaded canvas zoom
|
||||||
|
get 'canvas/medium_zoom', to: 'canvas#medium_zoom'
|
||||||
get 'canvas/small_zoom', to: 'canvas#small_zoom' # AJAX-loaded canvas zoom
|
get 'canvas/small_zoom', to: 'canvas#small_zoom' # AJAX-loaded canvas zoom
|
||||||
post 'canvas', to: 'canvas#update' # Save updated canvas action
|
post 'canvas', to: 'canvas#update' # Save updated canvas action
|
||||||
get 'module_archive' # Module archive for single experiment
|
get 'module_archive' # Module archive for single experiment
|
||||||
get 'archive' # archive experiment
|
get 'archive' # archive experiment
|
||||||
|
get 'samples' # Samples for single project
|
||||||
|
# Renders sample datatable for single project (ajax action)
|
||||||
|
post 'samples_index'
|
||||||
|
post :delete_samples,
|
||||||
|
constraints: CommitParamRouting.new(
|
||||||
|
MyModulesController::DELETE_SAMPLES
|
||||||
|
),
|
||||||
|
action: :delete_samples
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue