From 89240659a7f26e58afaf9028e50b1e04f166faf5 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Fri, 11 Jan 2019 17:20:04 +0100 Subject: [PATCH 1/2] Fix task tags update on canvas cards [SCI-2875] --- app/assets/javascripts/projects/canvas.js.erb | 13 ++++++---- app/controllers/my_module_tags_controller.rb | 26 +++++++++++++++---- .../canvas/full_zoom/_my_module.html.erb | 3 +-- .../canvas/medium_zoom/_my_module.html.erb | 3 +-- app/views/experiments/canvas.html.erb | 2 +- config/routes.rb | 1 + 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/projects/canvas.js.erb b/app/assets/javascripts/projects/canvas.js.erb index 6c007e782..8df86898d 100644 --- a/app/assets/javascripts/projects/canvas.js.erb +++ b/app/assets/javascripts/projects/canvas.js.erb @@ -873,18 +873,21 @@ function bindEditTagsAjax(elements) { manageTagsModalBody = manageTagsModal.find(".modal-body"); // Reload tags HTML element when modal is closed - manageTagsModal.on("hide.bs.modal", function(){ + manageTagsModal.off().on("hide.bs.modal", function(){ var task = $("div.panel[data-module-id='" + manageTagsModal.data('module-id') + "']"); // Load HTML $.ajax({ - url: task.attr("data-module-tags-url"), + url: $('#canvas-container').attr('data-module-tags-url'), type: "GET", dataType: "json", - success: function(data){ - task.find(".edit-tags-link") - .html(data.html_canvas); + success: function(data) { + $.each(data.my_modules, function(index, my_module){ + $('div.panel[data-module-id=' + my_module.id + ']') + .find(".edit-tags-link") + .html(my_module.tags); + }); // initialize tooltips again $.initTooltips(); }, diff --git a/app/controllers/my_module_tags_controller.rb b/app/controllers/my_module_tags_controller.rb index 79ff20cb5..9a5eb5d31 100644 --- a/app/controllers/my_module_tags_controller.rb +++ b/app/controllers/my_module_tags_controller.rb @@ -1,5 +1,5 @@ class MyModuleTagsController < ApplicationController - before_action :load_vars + before_action :load_vars, except: :canvas_index before_action :check_view_permissions, only: :index before_action :check_manage_permissions, only: %i(create index_edit destroy) @@ -25,10 +25,6 @@ class MyModuleTagsController < ApplicationController respond_to do |format| format.json do render json: { - html_canvas: render_to_string( - partial: 'canvas/tags.html.erb', - locals: { my_module: @my_module } - ), html_module_header: render_to_string( partial: 'my_modules/tags.html.erb', locals: { my_module: @my_module } @@ -38,6 +34,26 @@ class MyModuleTagsController < ApplicationController end end + def canvas_index + experiment = Experiment.find(params[:id]) + render_403 unless can_read_experiment?(experiment) + res = [] + experiment.active_my_modules.each do |my_module| + res << { + id: my_module.id, + tags: render_to_string( + partial: 'canvas/tags.html.erb', + locals: { my_module: my_module } + ) + } + end + respond_to do |format| + format.json do + render json: { my_modules: res } + end + end + end + def create @mt = MyModuleTag.new(mt_params.merge(my_module: @my_module)) @mt.created_by = current_user diff --git a/app/views/canvas/full_zoom/_my_module.html.erb b/app/views/canvas/full_zoom/_my_module.html.erb index a01666266..1b3663781 100644 --- a/app/views/canvas/full_zoom/_my_module.html.erb +++ b/app/views/canvas/full_zoom/_my_module.html.erb @@ -9,8 +9,7 @@ data-module-x="<%= my_module.x %>" data-module-y="<%= my_module.y %>" data-module-conns="<%= construct_module_connections(my_module) %>" - data-module-tags-url="<%= my_module_my_module_tags_url(my_module, format: :json) %>" - data-module-users-tab-url="<%= my_module_user_my_modules_url(my_module_id: my_module.id, format: :json) %>"> + data-module-tags-url="<%= my_module_tags_experiment_path(my_module.experiment, format: :json) %>"> <% if can_manage_module?(my_module) %> diff --git a/app/views/canvas/medium_zoom/_my_module.html.erb b/app/views/canvas/medium_zoom/_my_module.html.erb index 3ffe35842..2ef03b8ff 100644 --- a/app/views/canvas/medium_zoom/_my_module.html.erb +++ b/app/views/canvas/medium_zoom/_my_module.html.erb @@ -8,8 +8,7 @@ <% end %> data-module-x="<%= my_module.x %>" data-module-y="<%= my_module.y %>" - data-module-conns="<%= construct_module_connections(my_module) %>" - data-module-tags-url="<%= my_module_my_module_tags_url(my_module, format: :json) %>"> + data-module-conns="<%= construct_module_connections(my_module) %>"> <% if can_manage_module?(my_module) %> diff --git a/app/views/experiments/canvas.html.erb b/app/views/experiments/canvas.html.erb index a9c7d008f..54cf13687 100644 --- a/app/views/experiments/canvas.html.erb +++ b/app/views/experiments/canvas.html.erb @@ -45,7 +45,7 @@ -
+
<%= render partial: 'canvas/full_zoom', locals: { experiment: @experiment, my_modules: @active_modules } %>
diff --git a/config/routes.rb b/config/routes.rb index 33259a0cc..761d57ce9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -311,6 +311,7 @@ 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 'my_module_tags', to: 'my_module_tags#canvas_index' get 'archive' # archive experiment get 'clone_modal' # return modal with clone options post 'clone' # clone experiment From 3a4b992f4e5bbde6b66f247d24f6e100bbd6c29b Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 14 Jan 2019 16:31:23 +0100 Subject: [PATCH 2/2] Code style fixies []SCI-2875] --- app/assets/javascripts/projects/canvas.js.erb | 2 +- app/controllers/my_module_tags_controller.rb | 2 +- app/views/experiments/canvas.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/projects/canvas.js.erb b/app/assets/javascripts/projects/canvas.js.erb index 8df86898d..d4f524071 100644 --- a/app/assets/javascripts/projects/canvas.js.erb +++ b/app/assets/javascripts/projects/canvas.js.erb @@ -886,7 +886,7 @@ function bindEditTagsAjax(elements) { $.each(data.my_modules, function(index, my_module){ $('div.panel[data-module-id=' + my_module.id + ']') .find(".edit-tags-link") - .html(my_module.tags); + .html(my_module.tags_html); }); // initialize tooltips again $.initTooltips(); diff --git a/app/controllers/my_module_tags_controller.rb b/app/controllers/my_module_tags_controller.rb index 9a5eb5d31..b40673108 100644 --- a/app/controllers/my_module_tags_controller.rb +++ b/app/controllers/my_module_tags_controller.rb @@ -41,7 +41,7 @@ class MyModuleTagsController < ApplicationController experiment.active_my_modules.each do |my_module| res << { id: my_module.id, - tags: render_to_string( + tags_html: render_to_string( partial: 'canvas/tags.html.erb', locals: { my_module: my_module } ) diff --git a/app/views/experiments/canvas.html.erb b/app/views/experiments/canvas.html.erb index 54cf13687..2769de66f 100644 --- a/app/views/experiments/canvas.html.erb +++ b/app/views/experiments/canvas.html.erb @@ -45,7 +45,7 @@ -
+
<%= render partial: 'canvas/full_zoom', locals: { experiment: @experiment, my_modules: @active_modules } %>