edit canvas controller to work with experiment

This commit is contained in:
zmagod 2016-07-26 14:02:06 +02:00
parent b13747291e
commit 0a84ecdfc1
5 changed files with 30 additions and 30 deletions

View file

@ -6,25 +6,25 @@ class CanvasController < ApplicationController
def edit def edit
render partial: 'canvas/edit', render partial: 'canvas/edit',
locals: { project: @project, my_modules: @my_modules }, locals: { experiment: @experiment, my_modules: @my_modules },
:content_type => 'text/html' :content_type => 'text/html'
end end
def full_zoom def full_zoom
render partial: 'canvas/full_zoom', render partial: 'canvas/full_zoom',
locals: { project: @project, my_modules: @my_modules }, locals: { experiment: @experiment, my_modules: @my_modules },
:content_type => 'text/html' :content_type => 'text/html'
end end
def medium_zoom def medium_zoom
render partial: 'canvas/medium_zoom', render partial: 'canvas/medium_zoom',
locals: { project: @project, my_modules: @my_modules }, locals: { experiment: @experiment, my_modules: @my_modules },
:content_type => 'text/html' :content_type => 'text/html'
end end
def small_zoom def small_zoom
render partial: 'canvas/small_zoom', render partial: 'canvas/small_zoom',
locals: { project: @project, my_modules: @my_modules }, locals: { experiment: @experiment, my_modules: @my_modules },
:content_type => 'text/html' :content_type => 'text/html'
end end
@ -33,7 +33,7 @@ class CanvasController < ApplicationController
# Make sure that remove parameter is valid # Make sure that remove parameter is valid
to_archive = [] to_archive = []
if can_archive_modules(@project) and if can_archive_modules(@experiment.project) and
update_params[:remove].present? then update_params[:remove].present? then
to_archive = update_params[:remove].split(",") to_archive = update_params[:remove].split(",")
unless to_archive.all? { |id| is_int? id } unless to_archive.all? { |id| is_int? id }
@ -49,7 +49,7 @@ class CanvasController < ApplicationController
# Make sure connections parameter is valid # Make sure connections parameter is valid
connections = [] connections = []
if can_edit_connections(@project) and if can_edit_connections(@experiment.project) and
update_params[:connections].present? then update_params[:connections].present? then
conns = update_params[:connections].split(",") conns = update_params[:connections].split(",")
unless conns.length % 2 == 0 and unless conns.length % 2 == 0 and
@ -68,7 +68,7 @@ class CanvasController < ApplicationController
# Make sure positions parameter is valid # Make sure positions parameter is valid
positions = Hash.new positions = Hash.new
if can_reposition_modules(@project) and if can_reposition_modules(@experiment.project) and
update_params[:positions].present? then update_params[:positions].present? then
poss = update_params[:positions].split(";") poss = update_params[:positions].split(";")
center = "" center = ""
@ -104,7 +104,7 @@ class CanvasController < ApplicationController
# Make sure that to_add is an array of strings, # Make sure that to_add is an array of strings,
# as well as that positions for newly added modules exist # as well as that positions for newly added modules exist
to_add = [] to_add = []
if can_create_modules(@project) and if can_create_modules(@experiment.project) and
update_params[:add].present? and update_params[:add].present? and
update_params["add-names"].present? then update_params["add-names"].present? then
ids = update_params[:add].split(",") ids = update_params[:add].split(",")
@ -131,7 +131,7 @@ class CanvasController < ApplicationController
# Make sure rename parameter is valid # Make sure rename parameter is valid
to_rename = Hash.new to_rename = Hash.new
if can_edit_modules(@project) and if can_edit_modules(@experiment.project) and
update_params[:rename].present? then update_params[:rename].present? then
begin begin
to_rename = JSON.parse(update_params[:rename]) to_rename = JSON.parse(update_params[:rename])
@ -156,7 +156,7 @@ class CanvasController < ApplicationController
# Make sure that to_clone is an array of pairs, # Make sure that to_clone is an array of pairs,
# as well as that all IDs exist # as well as that all IDs exist
to_clone = Hash.new to_clone = Hash.new
if can_clone_modules(@project) and if can_clone_modules(@experiment.project) and
update_params[:cloned].present? then update_params[:cloned].present? then
clones = update_params[:cloned].split(";") clones = update_params[:cloned].split(";")
(clones.collect { |v| v.split(",") }).each do |val| (clones.collect { |v| v.split(",") }).each do |val|
@ -177,7 +177,7 @@ class CanvasController < ApplicationController
end end
module_groups = Hash.new module_groups = Hash.new
if can_edit_module_groups(@project) and if can_edit_module_groups(@experiment.project) and
update_params["module-groups"].present? then update_params["module-groups"].present? then
begin begin
module_groups = JSON.parse(update_params["module-groups"]) module_groups = JSON.parse(update_params["module-groups"])
@ -200,7 +200,7 @@ class CanvasController < ApplicationController
end end
# Call the "master" function to do all the updating for us # Call the "master" function to do all the updating for us
unless @project.update_canvas( unless @experiment.update_canvas(
to_archive, to_archive,
to_add, to_add,
to_rename, to_rename,
@ -213,13 +213,13 @@ class CanvasController < ApplicationController
render_403 and return render_403 and return
end end
# Save activities that modules were archived #Save activities that modules were archived
to_archive.each do |module_id| to_archive.each do |module_id|
my_module = MyModule.find_by_id(module_id) my_module = MyModule.find_by_id(module_id)
unless my_module.blank? unless my_module.blank?
Activity.create( Activity.create(
type_of: :archive_module, type_of: :archive_module,
project: my_module.project, project: my_module.experiment.project,
my_module: my_module, my_module: my_module,
user: current_user, user: current_user,
message: t( message: t(
@ -233,7 +233,7 @@ class CanvasController < ApplicationController
flash[:success] = t( flash[:success] = t(
"projects.canvas.update.success_flash") "projects.canvas.update.success_flash")
redirect_to canvas_project_path(@project) redirect_to canvas_experiment_path(@experiment)
end end
private private
@ -253,25 +253,25 @@ class CanvasController < ApplicationController
end end
def load_vars def load_vars
@project = Project.find_by_id(params[:id]) @experiment = Experiment.find_by_id(params[:id])
unless @project unless @experiment
respond_to do |format| respond_to do |format|
format.html { render_404 and return } format.html { render_404 and return }
format.any(:xml, :json, :js) { render(json: { redirect_url: not_found_url }, status: :not_found) and return } format.any(:xml, :json, :js) { render(json: { redirect_url: not_found_url }, status: :not_found) and return }
end end
end end
@my_modules = @project.active_modules @my_modules = @experiment.active_modules
end end
def check_edit_canvas def check_edit_canvas
unless can_edit_canvas(@project) unless can_edit_canvas(@experiment.project)
render_403 and return render_403 and return
end end
end end
def check_view_canvas def check_view_canvas
unless can_view_project(@project) unless can_view_project(@experiment.project)
render_403 and return render_403 and return
end end
end end

View file

@ -1,7 +1,7 @@
<div id="diagram-container"> <div id="diagram-container">
<div id="diagram" class="diagram"> <div id="diagram" class="diagram">
<% my_modules.each do |my_module| %> <% my_modules.each do |my_module| %>
<%= render partial: "canvas/full_zoom/my_module", locals: {project: project, my_module: my_module} %> <%= render partial: "canvas/full_zoom/my_module", locals: {experiment: experiment, my_module: my_module} %>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -13,4 +13,4 @@
<%= render partial: "my_modules/modals/manage_due_date_modal" %> <%= render partial: "my_modules/modals/manage_due_date_modal" %>
<!-- Manage users modal --> <!-- Manage users modal -->
<%= render partial: "my_modules/modals/manage_users_modal" %> <%= render partial: "my_modules/modals/manage_users_modal" %>

View file

@ -1,7 +1,7 @@
<div id="diagram-container"> <div id="diagram-container">
<div id="diagram" class="diagram"> <div id="diagram" class="diagram">
<% my_modules.each do |my_module| %> <% my_modules.each do |my_module| %>
<%= render partial: "canvas/medium_zoom/my_module", locals: {project: project, my_module: my_module} %> <%= render partial: "canvas/medium_zoom/my_module", locals: {experiment: experiment, my_module: my_module} %>
<% end %> <% end %>
</div> </div>
</div> </div>

View file

@ -1,7 +1,7 @@
<div id="diagram-container"> <div id="diagram-container">
<div id="diagram" class="diagram"> <div id="diagram" class="diagram">
<% my_modules.each do |my_module| %> <% my_modules.each do |my_module| %>
<%= render partial: "canvas/small_zoom/my_module", locals: {project: project, my_module: my_module} %> <%= render partial: "canvas/small_zoom/my_module", locals: {experiment: experiment, my_module: my_module} %>
<% end %> <% end %>
</div> </div>
</div> </div>

View file

@ -26,12 +26,12 @@
<a class="edit-module" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.edit_module" %></a> <a class="edit-module" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.edit_module" %></a>
</li> </li>
<% end %> <% end %>
<% if can_edit_module_groups(my_module.project) %> <% if can_edit_module_groups(my_module.experiment.project) %>
<li <%= 'style=display:none;' if my_module.my_module_group.blank? %>> <li <%= 'style=display:none;' if my_module.my_module_group.blank? %>>
<a class="edit-module-group" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.edit_module_group" %></a> <a class="edit-module-group" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.edit_module_group" %></a>
</li> </li>
<% end %> <% end %>
<% if can_clone_modules(my_module.project) %> <% if can_clone_modules(my_module.experiment.project) %>
<li> <li>
<a class ="clone-module" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.clone_module" %></a> <a class ="clone-module" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.clone_module" %></a>
</li> </li>
@ -44,7 +44,7 @@
<a class="delete-module" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.delete_module" %></a> <a class="delete-module" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.delete_module" %></a>
</li> </li>
<% end %> <% end %>
<% if can_archive_modules(my_module.project) %> <% if can_archive_modules(my_module.experiment.project) %>
<li <%= 'style=display:none;' if my_module.my_module_group.blank? %>> <li <%= 'style=display:none;' if my_module.my_module_group.blank? %>>
<a class ="delete-module-group" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.delete_module_group" %></a> <a class ="delete-module-group" href="" data-module-id="<%= my_module.id %>"><%=t "projects.canvas.edit.delete_module_group" %></a>
</li> </li>
@ -54,7 +54,7 @@
</div> </div>
<% if can_edit_connections(my_module.project) %> <% if can_edit_connections(my_module.experiment.project) %>
<div class="panel-body ep"> <div class="panel-body ep">
<%=t "projects.canvas.edit.drag_connections" %> <%=t "projects.canvas.edit.drag_connections" %>
</div> </div>