mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Remove the 'Archived tasks' tab and refactor sidebar to include archived [SCI-5273]
This commit is contained in:
parent
691072f519
commit
94b6c96e48
|
@ -204,7 +204,7 @@ class CanvasController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
@my_modules = @experiment.active_modules
|
||||
@my_modules = @experiment.my_modules.active
|
||||
end
|
||||
|
||||
def check_edit_canvas
|
||||
|
|
|
@ -58,8 +58,7 @@ class ExperimentsController < ApplicationController
|
|||
|
||||
def canvas
|
||||
@project = @experiment.project
|
||||
@active_modules = @experiment.active_modules
|
||||
.includes(:tags, :inputs, :outputs)
|
||||
@active_modules = @experiment.my_modules.active.includes(:tags, :inputs, :outputs)
|
||||
current_team_switch(@project.team)
|
||||
end
|
||||
|
||||
|
@ -207,6 +206,7 @@ class ExperimentsController < ApplicationController
|
|||
end
|
||||
|
||||
def module_archive
|
||||
@my_modules = @experiment.archived_branch? ? @experiment.my_modules : @experiment.my_modules.archived
|
||||
end
|
||||
|
||||
def updated_img
|
||||
|
|
|
@ -40,7 +40,7 @@ class MyModuleTagsController < ApplicationController
|
|||
experiment = Experiment.find(params[:id])
|
||||
render_403 unless can_read_experiment?(experiment)
|
||||
res = []
|
||||
experiment.active_my_modules.each do |my_module|
|
||||
experiment.my_modules.active.each do |my_module|
|
||||
res << {
|
||||
id: my_module.id,
|
||||
tags_html: render_to_string(
|
||||
|
|
|
@ -5,11 +5,14 @@ module ArchivableModel
|
|||
validates :archived, inclusion: { in: [true, false] }
|
||||
before_save :set_archive_timestamp
|
||||
before_save :set_restore_timestamp
|
||||
|
||||
scope :active, -> { where(archived: false) }
|
||||
scope :archived, -> { where(archived: true) }
|
||||
end
|
||||
|
||||
# Not archived
|
||||
def active?
|
||||
not archived?
|
||||
!archived?
|
||||
end
|
||||
|
||||
# Helper for archiving project. Timestamp of archiving is handler by
|
||||
|
|
|
@ -18,9 +18,6 @@ class Experiment < ApplicationRecord
|
|||
optional: true
|
||||
|
||||
has_many :my_modules, inverse_of: :experiment, dependent: :destroy
|
||||
has_many :active_my_modules,
|
||||
-> { where(archived: false).order(:name) },
|
||||
class_name: 'MyModule'
|
||||
has_many :my_module_groups, inverse_of: :experiment, dependent: :destroy
|
||||
has_many :report_elements, inverse_of: :experiment, dependent: :destroy
|
||||
# Associations for old activity type
|
||||
|
@ -44,8 +41,6 @@ class Experiment < ApplicationRecord
|
|||
experiment.validates :archived_on, presence: true
|
||||
end
|
||||
|
||||
scope :is_archived, ->(is_archived) { where("archived = ?", is_archived) }
|
||||
|
||||
def self.search(
|
||||
user,
|
||||
include_archived,
|
||||
|
@ -73,7 +68,7 @@ class Experiment < ApplicationRecord
|
|||
Experiment
|
||||
.where('experiments.project_id IN (?)', projects_ids)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
return include_archived ? new_query : new_query.is_archived(false)
|
||||
return include_archived ? new_query : new_query.active
|
||||
elsif include_archived
|
||||
new_query =
|
||||
Experiment
|
||||
|
@ -82,7 +77,7 @@ class Experiment < ApplicationRecord
|
|||
else
|
||||
new_query =
|
||||
Experiment
|
||||
.is_archived(false)
|
||||
.active
|
||||
.where(project: project_ids)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
end
|
||||
|
@ -101,18 +96,14 @@ class Experiment < ApplicationRecord
|
|||
where(project: Project.viewable_by_user(user, teams))
|
||||
end
|
||||
|
||||
def archived_branch?
|
||||
archived? || project.archived?
|
||||
end
|
||||
|
||||
def navigable?
|
||||
!project.archived?
|
||||
end
|
||||
|
||||
def active_modules
|
||||
my_modules.where(archived: false)
|
||||
end
|
||||
|
||||
def archived_modules
|
||||
my_modules.where(archived: true)
|
||||
end
|
||||
|
||||
def update_canvas(
|
||||
to_archive,
|
||||
to_add,
|
||||
|
@ -368,12 +359,13 @@ class Experiment < ApplicationRecord
|
|||
|
||||
# Find the lowest point for current modules(max_y) and the leftmost
|
||||
# module(min_x)
|
||||
if experiment.active_modules.empty?
|
||||
active_modules = experiment.my_modules.active
|
||||
if active_modules.blank?
|
||||
max_y = 0
|
||||
min_x = 0
|
||||
else
|
||||
max_y = experiment.active_modules.maximum(:y) + MyModule::HEIGHT
|
||||
min_x = experiment.active_modules.minimum(:x)
|
||||
max_y = active_modules.maximum(:y) + MyModule::HEIGHT
|
||||
min_x = active_modules.minimum(:x)
|
||||
end
|
||||
|
||||
# Set new positions
|
||||
|
@ -511,7 +503,7 @@ class Experiment < ApplicationRecord
|
|||
|
||||
dg = RGL::DirectedAdjacencyGraph[]
|
||||
group_ids = Set.new
|
||||
active_modules.includes(:my_module_group, outputs: :to).each do |m|
|
||||
my_modules.active.includes(:my_module_group, outputs: :to).each do |m|
|
||||
group_ids << m.my_module_group.id unless m.my_module_group.blank?
|
||||
dg.add_vertex m.id unless dg.has_vertex? m.id
|
||||
m.outputs.each do |o|
|
||||
|
|
|
@ -55,8 +55,6 @@ class MyModule < ApplicationRecord
|
|||
# Associations for old activity type
|
||||
has_many :activities, inverse_of: :my_module
|
||||
|
||||
scope :is_archived, ->(is_archived) { where('archived = ?', is_archived) }
|
||||
scope :active, -> { where(archived: false) }
|
||||
scope :overdue, -> { where('my_modules.due_date < ?', Time.current.utc) }
|
||||
scope :without_group, -> { active.where(my_module_group: nil) }
|
||||
scope :one_day_prior, (lambda do
|
||||
|
@ -129,8 +127,8 @@ class MyModule < ApplicationRecord
|
|||
where(experiment: Experiment.viewable_by_user(user, teams))
|
||||
end
|
||||
|
||||
def navigable?
|
||||
!experiment.archived? && experiment.navigable?
|
||||
def archived_branch?
|
||||
archived? || experiment.archived_branch?
|
||||
end
|
||||
|
||||
# Removes connections with other modules
|
||||
|
@ -426,7 +424,7 @@ class MyModule < ApplicationRecord
|
|||
|
||||
# Get all modules position that overlap with first column, [0, WIDTH) and
|
||||
# sort them by y coordinate.
|
||||
positions = experiment.active_modules.collect { |m| [m.x, m.y] }
|
||||
positions = experiment.my_modules.active.collect { |m| [m.x, m.y] }
|
||||
.select { |x, _| x >= 0 && x < WIDTH }
|
||||
.sort_by { |_, y| y }
|
||||
return { x: 0, y: 0 } if positions.empty? || positions.first[1] >= HEIGHT
|
||||
|
|
|
@ -187,11 +187,7 @@ class Project < ApplicationRecord
|
|||
when 'ztoa' then { name: :desc }
|
||||
else { created_at: :desc }
|
||||
end
|
||||
experiments.is_archived(false).order(sort)
|
||||
end
|
||||
|
||||
def archived_experiments
|
||||
experiments.is_archived(true)
|
||||
experiments.active.order(sort)
|
||||
end
|
||||
|
||||
def project_my_modules
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
Canaid::Permissions.register_for(Experiment) do
|
||||
# Experiment and its project must be active for all the specified permissions
|
||||
%i(read_experiment
|
||||
manage_experiment
|
||||
%i(manage_experiment
|
||||
archive_experiment
|
||||
clone_experiment
|
||||
move_experiment)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
Canaid::Permissions.register_for(Project) do
|
||||
# Project must be active for all the specified permissions
|
||||
%i(read_project
|
||||
manage_project
|
||||
%i(manage_project
|
||||
archive_project
|
||||
create_experiments
|
||||
create_comments_in_project
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<h4 class="modal-title" id="modal-move-module-label"><%=t "experiments.canvas.edit.modal_move_module.title" %></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<% experiments = @experiment.project.experiments.is_archived(false) %>
|
||||
<% experiments = @experiment.project.experiments.active %>
|
||||
<% if experiments.count > 1 %>
|
||||
<%= bootstrap_form_tag do |f| %>
|
||||
<%= f.select :experiment_id, experiments
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<h4 class="modal-title" id="modal-move-module-group-label"><%=t "experiments.canvas.edit.modal_move_module_group.title" %></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<% experiments = @experiment.project.experiments.is_archived(false) %>
|
||||
<% experiments = @experiment.project.experiments.active %>
|
||||
<% if experiments.count > 1 %>
|
||||
<%= bootstrap_form_tag do |f| %>
|
||||
<%= f.select :experiment_id, experiments
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<% provide(:sidebar_url, experiment_sidebar_path(@experiment)) %>
|
||||
|
||||
<%= content_for :sidebar do %>
|
||||
<%= render partial: 'shared/sidebar/my_modules.html.erb', locals: { experiment: @experiment } %>
|
||||
<%= render partial: 'shared/sidebar/my_modules.html.erb', locals: { experiment: @experiment, my_modules: @active_modules } %>
|
||||
<% end %>
|
||||
<%= render partial: "shared/secondary_navigation" %>
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
<% provide(:sidebar_url, experiment_sidebar_path(@experiment)) %>
|
||||
|
||||
<%= content_for :sidebar do %>
|
||||
<%= render partial: 'shared/sidebar/my_modules.html.erb', locals: { experiment: @experiment } %>
|
||||
<%= render partial: 'shared/sidebar/archived_my_modules.html.erb', locals: { experiment: @experiment, my_modules: @my_modules } %>
|
||||
<% end %>
|
||||
<%= render partial: "shared/secondary_navigation" %>
|
||||
|
||||
<div class="content-pane" id="module-archive">
|
||||
<% if @experiment.archived_modules.count > 0 %>
|
||||
<% if @my_modules.present? %>
|
||||
<div class="row" style="margin-top: 10px;">
|
||||
<% @experiment.archived_modules.each_with_index do |my_module, i| %>
|
||||
<% @my_modules.each_with_index do |my_module, i| %>
|
||||
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
|
||||
<%= render partial: "experiments/module_archive/my_module.html.erb", locals: { my_module: my_module} %>
|
||||
</div>
|
||||
|
@ -28,7 +28,7 @@
|
|||
<% else %>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<em><%=t "experiments.module_archive.no_archived_modules" %></em>
|
||||
<em><%= t('experiments.module_archive.no_archived_modules') %></em>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -23,16 +23,18 @@
|
|||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<%=t "experiments.module_archive.archived_on" %>
|
||||
<% if my_module.archived? %>
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<%=t "experiments.module_archive.archived_on" %>
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
<span title="<%=t "experiments.module_archive.archived_on_title", date: l(my_module.archived_on, format: :full_date), time: l(my_module.archived_on, format: :time) %>">
|
||||
<%= l(my_module.archived_on, format: :full_date) %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
<span title="<%=t "experiments.module_archive.archived_on_title", date: l(my_module.archived_on, format: :full_date), time: l(my_module.archived_on, format: :time) %>">
|
||||
<%=l my_module.archived_on, format: :full_date %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
<%= render partial: "shared/secondary_navigation" %>
|
||||
|
||||
<div class="content-pane" id="experiment-archive">
|
||||
<% if @project.archived_experiments.count > 0 %>
|
||||
<% if @project.experiments.archived.present? %>
|
||||
<div class="row" style="margin-top: 10px;">
|
||||
<% @project.archived_experiments.each_with_index do |experiment, i| %>
|
||||
<% @project.experiments.archived.each_with_index do |experiment, i| %>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||
<%= render partial: "projects/experiment_archive/experiment.html.erb", locals: { experiment: experiment} %>
|
||||
</div>
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<% if experiment.active_modules.length > 0 %>
|
||||
<% if experiment.my_modules.active.exists? %>
|
||||
<%= link_to canvas_experiment_path(experiment) do %>
|
||||
<div class="workflowimg-container"
|
||||
data-check-img="<%= updated_img_experiment_url(experiment) %>"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<span class="hidden-xs"><%= t("projects.reports.elements.modals.project_contents.tasks_tab") %></span>
|
||||
</a>
|
||||
</li>
|
||||
<% if project.project_my_modules.is_archived(false).exists? %>
|
||||
<% if project.project_my_modules.active.exists? %>
|
||||
<li role="presentation">
|
||||
<a href="#content-tab" aria-controls="content-tab" role="tab" data-toggle="tab">
|
||||
<span class="fas fa-link visible-xs"></span>
|
||||
|
|
|
@ -4,22 +4,21 @@
|
|||
</em>
|
||||
</div>
|
||||
|
||||
<% if project.project_my_modules.is_archived(false).exists? %>
|
||||
<% if project.project_my_modules.active.exists? %>
|
||||
<div class="checkbox-tree">
|
||||
<ul>
|
||||
<li>
|
||||
<%= form.check_box :project, label: project.name %>
|
||||
<ul>
|
||||
|
||||
<% project.experiments.includes(:my_module_groups).is_archived(false).each do |experiment| %>
|
||||
<% next unless experiment.my_modules.is_archived(false).exists? %>
|
||||
<% project.experiments.includes(:my_module_groups).active.each do |experiment| %>
|
||||
<% next unless experiment.my_modules.active.exists? %>
|
||||
<li>
|
||||
<%= form.check_box "experiment_#{experiment.id}", label: experiment.name %>
|
||||
<ul>
|
||||
|
||||
<% experiment.my_module_groups.each do |my_module_group| %>
|
||||
<% next unless my_module_group.my_modules.is_archived(false).exists? %>
|
||||
<% my_module_group.my_modules.workflow_ordered.is_archived(false).each do |my_module| %>
|
||||
<% my_module_group.my_modules.workflow_ordered.active.each do |my_module| %>
|
||||
<li>
|
||||
<%= form.check_box "modules[#{my_module.id}]", label: my_module.name %>
|
||||
</li>
|
||||
|
|
|
@ -69,24 +69,6 @@
|
|||
</li>
|
||||
<% end %>
|
||||
|
||||
<% elsif experiment_page? %>
|
||||
<% if can_read_experiment?(@experiment) %>
|
||||
<li id="canvas-nav-tab" class="<%= "active" if is_experiment_canvas? %>">
|
||||
<a href="<%= canvas_experiment_url(@experiment) %>" title="<%=t "nav2.experiments.canvas" %>">
|
||||
<span class="hidden-sm hidden-md"><%=t "nav2.experiments.canvas" %></span>
|
||||
<span class="hidden-xs hidden-lg fas fa-folder"></span>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
<% if can_read_project?(@experiment.project) %>
|
||||
<li id="project-archive-nav-tab" class="<%= "active" if is_experiment_archive? %>">
|
||||
<a href="<%= module_archive_experiment_url(@experiment) %>" title="<%=t "nav2.experiments.archive" %>">
|
||||
<span class="hidden-sm hidden-md"><%=t "nav2.experiments.archive" %></span>
|
||||
<span class="hidden-xs hidden-lg fas fa-briefcase"></span>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% elsif module_page? %>
|
||||
<% if can_read_experiment?(@my_module.experiment) %>
|
||||
<li id="steps-nav-tab" class="<%= "active" if is_module_protocols? %>">
|
||||
|
|
19
app/views/shared/sidebar/_archived_my_modules.html.erb
Normal file
19
app/views/shared/sidebar/_archived_my_modules.html.erb
Normal file
|
@ -0,0 +1,19 @@
|
|||
<ul class="sidebar-branch">
|
||||
<% if experiment.archived_branch? %>
|
||||
<li class="sidebar-leaf">
|
||||
<%= link_to t('sidebar.my_modules.back_to_archived_button'), experiment_archive_project_url(experiment.project), class: 'sidebar-link back-button' %>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="sidebar-leaf">
|
||||
<%= link_to t('sidebar.my_modules.back_to_active_button'), canvas_experiment_url(experiment), class: 'sidebar-link back-button' %>
|
||||
</li>
|
||||
<% end %>
|
||||
<% my_modules.each do |my_module| %>
|
||||
<li class="sidebar-leaf">
|
||||
<%= link_to my_module.name,
|
||||
module_action_to_link_to(my_module),
|
||||
class: 'sidebar-link',
|
||||
data: { module_id: my_module.id } %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
|
@ -2,15 +2,19 @@
|
|||
<li class="sidebar-leaf">
|
||||
<%= link_to t('sidebar.my_modules.back_button'), project_url(experiment.project), class: 'sidebar-link back-button' %>
|
||||
</li>
|
||||
<% experiment.active_my_modules.each do |my_module| %>
|
||||
<% my_modules.each do |my_module| %>
|
||||
<li class="sidebar-leaf">
|
||||
<%= link_to my_module.name,
|
||||
module_action_to_link_to(my_module),
|
||||
class: "sidebar-link",
|
||||
class: 'sidebar-link',
|
||||
data: { module_id: my_module.id } %>
|
||||
<% if action_name =='canvas' %>
|
||||
<% if action_name == 'canvas' %>
|
||||
<i class="fas fa-map-marker-alt canvas-center-on" data-module-id="<%= my_module.id %>"></i>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
<li class="sidebar-leaf">
|
||||
<i class="fas fa-archive"></i>
|
||||
<%= link_to t('sidebar.my_modules.archived_button'), module_archive_experiment_url(experiment), class: 'sidebar-link' %>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -214,6 +214,9 @@ en:
|
|||
my_modules:
|
||||
sidebar_title: "TASKS"
|
||||
back_button: "Back to experiments"
|
||||
back_to_archived_button: "Back to archived experiments"
|
||||
archived_button: "Archived tasks"
|
||||
back_to_active_button: "Back to active tasks"
|
||||
my_module:
|
||||
sidebar_title: "TASK"
|
||||
back_button: "Back to all tasks"
|
||||
|
@ -232,9 +235,6 @@ en:
|
|||
activities: "Activity"
|
||||
reports: "Reports"
|
||||
archive: "Archived experiments"
|
||||
experiments:
|
||||
canvas: "Tasks"
|
||||
archive: "Archived tasks"
|
||||
modules:
|
||||
steps: "Protocols"
|
||||
results: "Results"
|
||||
|
|
|
@ -79,7 +79,7 @@ describe TeamImporter do
|
|||
it do
|
||||
expect(@exp.my_modules.where(my_module_group: nil).count).to eq 2
|
||||
end
|
||||
it { expect(@exp.archived_modules.count).to eq 1 }
|
||||
it { expect(@exp.my_modules.archived.count).to eq 1 }
|
||||
end
|
||||
|
||||
describe 'Connections' do
|
||||
|
|
|
@ -38,9 +38,9 @@ describe TemplatesService do
|
|||
expect(tmpl_exp.name).to eq(demo_exp.name)
|
||||
expect(tmpl_exp.uuid).to_not eq(nil)
|
||||
expect(tmpl_exp.my_modules.pluck(:name))
|
||||
.to match_array(demo_exp.active_my_modules.pluck(:name))
|
||||
.to match_array(demo_exp.my_modules.active.pluck(:name))
|
||||
tmpl_tasks = tmpl_exp.my_modules
|
||||
demo_tasks = demo_exp.active_my_modules
|
||||
demo_tasks = demo_exp.my_modules.active
|
||||
demo_tasks.each do |demo_task|
|
||||
tmpl_task = tmpl_tasks.find_by_name(demo_task.name)
|
||||
expect(tmpl_task.name).to eq(demo_task.name)
|
||||
|
|
Loading…
Reference in a new issue