From a76d82d188584acf5f758d014a2368747a86d311 Mon Sep 17 00:00:00 2001 From: scibb Date: Mon, 22 Aug 2016 15:10:06 +0200 Subject: [PATCH 01/19] delete and edit comments for projects, protocols, results, and workflow elements --- app/assets/javascripts/my_modules.js | 1 + app/assets/javascripts/my_modules/results.js | 44 +++++++++++- app/assets/javascripts/projects/canvas.js | 44 +++++++++++- app/assets/javascripts/projects/index.js | 44 +++++++++++- app/assets/javascripts/protocols/steps.js | 45 +++++++++++- app/controllers/projects_controller.rb | 71 +++++++++++++++++++ app/controllers/protocols_controller.rb | 25 +++++++ .../my_module_comments/_comment.html.erb | 12 +++- app/views/my_module_comments/_list.html.erb | 5 +- app/views/project_comments/_comment.html.erb | 12 +++- app/views/project_comments/_list.html.erb | 2 +- app/views/result_comments/_comment.html.erb | 12 +++- app/views/result_comments/_list.html.erb | 2 +- app/views/step_comments/_comment.html.erb | 12 +++- app/views/step_comments/_index.html.erb | 2 +- app/views/step_comments/_list.html.erb | 2 +- config/routes.rb | 9 +++ 17 files changed, 329 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/my_modules.js b/app/assets/javascripts/my_modules.js index cbae6e069..3ad7e2fd7 100644 --- a/app/assets/javascripts/my_modules.js +++ b/app/assets/javascripts/my_modules.js @@ -1,3 +1,4 @@ + // Bind ajax for editing descriptions function bindEditDescriptionAjax() { var editDescriptionModal = $("#manage-module-description-modal"); diff --git a/app/assets/javascripts/my_modules/results.js b/app/assets/javascripts/my_modules/results.js index aa2c45a98..e153fbd54 100644 --- a/app/assets/javascripts/my_modules/results.js +++ b/app/assets/javascripts/my_modules/results.js @@ -1,3 +1,43 @@ +function results_comment_edit(id) { + document.getElementById('edit_comment_'+id).type='text'; + $('#span_comment_'+id).hide(); + return false; +} + +function results_update_comment(id) { + if (document.getElementById('edit_comment_'+id).type=='text') { + var txt = document.getElementById('edit_comment_'+id).value; + $.ajax({ + type: "POST", + url: '/projects/update_comment_results', + dataType: 'json', + data: {id: id, msg: txt}, + success: function (data) { + document.getElementById('edit_comment_'+id).type='hidden'; + var txt = document.getElementById('edit_comment_'+id).value; + $('#span_comment_'+id).text(txt); + $('#span_comment_'+id).show(); + } + }); + } +} + +function results_comment_delete(id) { + if (confirm('Are you sure you want to delete this comment?')) { + $.ajax({ + type: "POST", + url: '/projects/delete_comment_results', + dataType: 'json', + data: {id: id}, + success: function (data) { + $('.content-comments').find('#'+id).remove(); + } + }); + } + + return false; +} + function initHandsOnTables(root) { root.find("div.hot-table").each(function() { var $container = $(this).find(".step-result-hot-table"); @@ -41,13 +81,15 @@ function initResultCommentForm($el) { .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); + var s1 = data.html + var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); diff --git a/app/assets/javascripts/projects/canvas.js b/app/assets/javascripts/projects/canvas.js index 2d3be3200..e077ea582 100644 --- a/app/assets/javascripts/projects/canvas.js +++ b/app/assets/javascripts/projects/canvas.js @@ -676,13 +676,15 @@ function bindFullZoomAjaxTabs() { .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); + var s1 = data.html + var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); @@ -3484,3 +3486,43 @@ function showTutorial() { var currentProjectId = $("#canvas-container").attr("data-project-id"); return tutorialProjectId == currentProjectId; } + +function module_comment_edit(id) { + document.getElementById('edit_comment_'+id).type='text'; + $('#span_comment_'+id).hide(); + return false; +} + +function module_update_comment(id) { + if (document.getElementById('edit_comment_'+id).type=='text') { + var txt = document.getElementById('edit_comment_'+id).value; + $.ajax({ + type: "POST", + url: '/projects/update_comment_modules', + dataType: 'json', + data: {id: id, msg: txt}, + success: function (data) { + document.getElementById('edit_comment_'+id).type='hidden'; + var txt = document.getElementById('edit_comment_'+id).value; + $('#span_comment_'+id).text(txt); + $('#span_comment_'+id).show(); + } + }); + } +} + +function module_comment_delete(id) { + if (confirm('Are you sure you want to delete this comment?')) { + $.ajax({ + type: "POST", + url: '/projects/delete_comment_modules', + dataType: 'json', + data: {id: id}, + success: function (data) { + $('.content-comments').find('#'+id).remove(); + } + }); + } + + return false; +} diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index 746b790aa..21ada4c6f 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -7,6 +7,46 @@ // - refresh project users tab after manage user modal is closed // - refactor view handling using library, ex. backbone.js +function project_comment_edit(id) { + document.getElementById('edit_comment_'+id).type='text'; + $('#span_comment_'+id).hide(); + return false; +} + +function project_update_comment(id) { + if (document.getElementById('edit_comment_'+id).type=='text') { + var txt = document.getElementById('edit_comment_'+id).value; + $.ajax({ + type: "POST", + url: '/projects/update_comment_projects', + dataType: 'json', + data: {id: id, msg: txt}, + success: function (data) { + document.getElementById('edit_comment_'+id).type='hidden'; + var txt = document.getElementById('edit_comment_'+id).value; + $('#span_comment_'+id).text(txt); + $('#span_comment_'+id).show(); + } + }); + } +} + +function project_comment_delete(id) { + if (confirm('Are you sure you want to delete this comment?')) { + $.ajax({ + type: "POST", + url: '/projects/delete_comment_projects', + dataType: 'json', + data: {id: id}, + success: function (data) { + $('.content-comments').find('#'+id).remove(); + } + }); + } + + return false; +} + (function () { var newProjectModal = null; @@ -215,13 +255,15 @@ .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); + var s1 = data.html + var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); diff --git a/app/assets/javascripts/protocols/steps.js b/app/assets/javascripts/protocols/steps.js index 8508b7809..0f0f9d374 100644 --- a/app/assets/javascripts/protocols/steps.js +++ b/app/assets/javascripts/protocols/steps.js @@ -386,13 +386,15 @@ function initStepCommentForm($el) { .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); + var s1 = data.html + var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); @@ -423,9 +425,48 @@ function initStepCommentForm($el) { }); } +function comment_delete(id) { + if (confirm('Are you sure you want to delete this comment?')) { + $.ajax({ + type: "POST", + url: '/protocols/delete_comment', + dataType: 'json', + data: {id: id}, + success: function (data) { + $('.content-comments').find('#'+id).remove(); + } + }); + } + + return false; +} + +function update_comment(id) { + if (document.getElementById('edit_comment_'+id).type=='text') { + var txt = document.getElementById('edit_comment_'+id).value; + $.ajax({ + type: "POST", + url: '/protocols/update_comment', + dataType: 'json', + data: {id: id, msg: txt}, + success: function (data) { + document.getElementById('edit_comment_'+id).type='hidden'; + var txt = document.getElementById('edit_comment_'+id).value; + $('#span_comment_'+id).text(txt); + $('#span_comment_'+id).show(); + } + }); + } +} + +function comment_edit(id) { + document.getElementById('edit_comment_'+id).type='text'; + $('#span_comment_'+id).hide(); + return false; +} + // Initialize show more comments link. function initStepCommentsLink($el) { - $el.find(".btn-more-comments") .on("ajax:success", function (e, data) { if (data.html) { diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a9b04b088..b90408350 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -33,6 +33,77 @@ class ProjectsController < ApplicationController @project = Project.new end + def update_comment_modules + id = request.request_parameters[:id] + msg = request.request_parameters[:msg] + + Comment.where(id:id).update_all(message:msg) + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def delete_comment_modules + id = request.request_parameters[:id] + + MyModuleComment.where(comment_id:id).destroy_all + Comment.find(id).destroy + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def update_comment_projects + id = request.request_parameters[:id] + msg = request.request_parameters[:msg] + + Comment.where(id:id).update_all(message:msg) + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def delete_comment_projects + id = request.request_parameters[:id] + + ProjectComment.where(comment_id:id).destroy_all + Comment.find(id).destroy + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def update_comment_results + id = request.request_parameters[:id] + msg = request.request_parameters[:msg] + + Comment.where(id:id).update_all(message:msg) + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def delete_comment_results + id = request.request_parameters[:id] + + ResultComment.where(comment_id:id).destroy_all + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + def archive @filter_by_archived = true index diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 29705c8ba..68b5ac375 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -67,6 +67,31 @@ class ProtocolsController < ApplicationController def index end + def update_comment + id = request.request_parameters[:id] + msg = request.request_parameters[:msg] + + Comment.where(id:id).update_all(message:msg) + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def delete_comment + id = request.request_parameters[:id] + + + StepComment.where(comment_id:id).destroy_all + Comment.find(id).destroy + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + def datatable respond_to do |format| format.json { diff --git a/app/views/my_module_comments/_comment.html.erb b/app/views/my_module_comments/_comment.html.erb index 95d970ced..36b9416ba 100644 --- a/app/views/my_module_comments/_comment.html.erb +++ b/app/views/my_module_comments/_comment.html.erb @@ -1,3 +1,13 @@ <%= l comment.created_at, format: '%H:%M' %> <%= comment.user.full_name %>: -

    <%= comment.message %>

    \ No newline at end of file + + + <%= comment.message %> +
    + + +
    +
    \ No newline at end of file diff --git a/app/views/my_module_comments/_list.html.erb b/app/views/my_module_comments/_list.html.erb index f4224e036..74cddcedf 100644 --- a/app/views/my_module_comments/_list.html.erb +++ b/app/views/my_module_comments/_list.html.erb @@ -2,11 +2,12 @@ <% current_day = DateTime.current.strftime('%j').to_i %> <% comments.each do |comment| %> -
  • +
  • <% comment_day = comment.created_at.strftime('%j').to_i %> <% if comment_day < current_day and comment_day < day %> <% day = comment.created_at.strftime('%j').to_i %>

    <%= comment.created_at.strftime('%d.%m.%Y') %>

    <% end %> - <%= render 'project_comments/comment.html.erb', comment: comment %>
  • + <%= render 'my_module_comments/comment.html.erb', comment: comment %> + <% end %> diff --git a/app/views/project_comments/_comment.html.erb b/app/views/project_comments/_comment.html.erb index adf691da0..2655c2a20 100644 --- a/app/views/project_comments/_comment.html.erb +++ b/app/views/project_comments/_comment.html.erb @@ -1,3 +1,13 @@ <%= l comment.created_at, format: '%H:%M' %> <%= comment.user.full_name %>: -

    <%= comment.message %>

    + + + <%= comment.message %> +
    + + +
    +
    diff --git a/app/views/project_comments/_list.html.erb b/app/views/project_comments/_list.html.erb index 68e17ebd8..6f472b331 100644 --- a/app/views/project_comments/_list.html.erb +++ b/app/views/project_comments/_list.html.erb @@ -3,7 +3,7 @@ current_day = DateTime.current.strftime('%j').to_i %> <% comments.each do |comment| %> -
  • +
  • <% comment_day = comment.created_at.strftime('%j').to_i diff --git a/app/views/result_comments/_comment.html.erb b/app/views/result_comments/_comment.html.erb index 74715974a..cdb63ad5c 100644 --- a/app/views/result_comments/_comment.html.erb +++ b/app/views/result_comments/_comment.html.erb @@ -1,2 +1,12 @@ <%=t "my_modules.results.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %> -

    <%= comment.message %>

    + + + <%= comment.message %> +
    + + +
    +
    diff --git a/app/views/result_comments/_list.html.erb b/app/views/result_comments/_list.html.erb index 1d2941643..c5ca79bb1 100644 --- a/app/views/result_comments/_list.html.erb +++ b/app/views/result_comments/_list.html.erb @@ -2,7 +2,7 @@ <% current_day = DateTime.current.strftime('%j').to_i %> <% comments.each do |comment| %> -
  • +
  • <% comment_day = comment.created_at.strftime('%j').to_i %> <% if comment_day < current_day and comment_day < day %> <% day = comment.created_at.strftime('%j').to_i %> diff --git a/app/views/step_comments/_comment.html.erb b/app/views/step_comments/_comment.html.erb index 7a7516ad3..1415304ba 100644 --- a/app/views/step_comments/_comment.html.erb +++ b/app/views/step_comments/_comment.html.erb @@ -1,2 +1,12 @@ <%=t "protocols.steps.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %> -

    <%= comment.message %>

    + + + <%= comment.message %> +
    + + +
    +
    \ No newline at end of file diff --git a/app/views/step_comments/_index.html.erb b/app/views/step_comments/_index.html.erb index 86c1e3095..a8105d101 100644 --- a/app/views/step_comments/_index.html.erb +++ b/app/views/step_comments/_index.html.erb @@ -5,7 +5,7 @@
  • <%= t 'general.no_comments' %>
  • <% else %> <%= render 'step_comments/list.html.erb', comments: @comments %> - <% end %> + <% end %>¸ <% if @comments.length == @per_page %>
  • diff --git a/app/views/step_comments/_list.html.erb b/app/views/step_comments/_list.html.erb index 19683d30d..acfad058a 100644 --- a/app/views/step_comments/_list.html.erb +++ b/app/views/step_comments/_list.html.erb @@ -2,7 +2,7 @@ <% current_day = DateTime.current.strftime('%j').to_i %> <% comments.each do |comment| %> -
  • +
  • <% comment_day = comment.created_at.strftime('%j').to_i %> <% if comment_day < current_day and comment_day < day %> <% day = comment.created_at.strftime('%j').to_i %> diff --git a/config/routes.rb b/config/routes.rb index 7d53e1c61..20ff36cce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,13 @@ Rails.application.routes.draw do end get 'projects/archive', to: 'projects#archive', as: 'projects_archive' + + post 'projects/delete_comment_results', to: 'projects#delete_comment_results' + post 'projects/update_comment_results', to: 'projects#update_comment_results' + post 'projects/delete_comment_projects', to: 'projects#delete_comment_projects' + post 'projects/update_comment_projects', to: 'projects#update_comment_projects' + post 'projects/delete_comment_modules', to: 'projects#delete_comment_modules' + post 'projects/update_comment_modules', to: 'projects#update_comment_modules' resources :projects, except: [:new, :destroy] do resources :user_projects, path: "/users", only: [:new, :create, :index, :edit, :update, :destroy] @@ -229,6 +236,8 @@ Rails.application.routes.draw do get "edit_description_modal", to: "protocols#edit_description_modal" end collection do + post 'delete_comment', to: 'protocols#delete_comment' + post 'update_comment', to: 'protocols#update_comment' get "create_new_modal", to: "protocols#create_new_modal" post "datatable", to: "protocols#datatable" post "make_private", to: "protocols#make_private" From 5569a1e6d2ce486797b13532d10114109a19a90e Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 23 Aug 2016 15:37:32 +0200 Subject: [PATCH 02/19] Revert 2 files that contained no changes --- app/assets/javascripts/my_modules.js | 1 - app/views/step_comments/_index.html.erb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/assets/javascripts/my_modules.js b/app/assets/javascripts/my_modules.js index 3ad7e2fd7..cbae6e069 100644 --- a/app/assets/javascripts/my_modules.js +++ b/app/assets/javascripts/my_modules.js @@ -1,4 +1,3 @@ - // Bind ajax for editing descriptions function bindEditDescriptionAjax() { var editDescriptionModal = $("#manage-module-description-modal"); diff --git a/app/views/step_comments/_index.html.erb b/app/views/step_comments/_index.html.erb index a8105d101..86c1e3095 100644 --- a/app/views/step_comments/_index.html.erb +++ b/app/views/step_comments/_index.html.erb @@ -5,7 +5,7 @@
  • <%= t 'general.no_comments' %>
  • <% else %> <%= render 'step_comments/list.html.erb', comments: @comments %> - <% end %>¸ + <% end %> <% if @comments.length == @per_page %>
  • From 319bcc7850a7d82a3e679bde77a770ad62593d2b Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 24 Aug 2016 11:13:51 +0200 Subject: [PATCH 03/19] Add permissions for comments to permission_helper.rb --- app/helpers/permission_helper.rb | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/app/helpers/permission_helper.rb b/app/helpers/permission_helper.rb index 1fd6cf0ab..3f3cd2a71 100644 --- a/app/helpers/permission_helper.rb +++ b/app/helpers/permission_helper.rb @@ -302,6 +302,19 @@ module PermissionHelper is_technician_or_higher_of_project(project) end + def can_edit_project_comment(comment) + comment.project_comment.present? && + ( + comment.user == current_user || + is_owner_of_project(comment.project_comment.project) + ) + end + + def can_delete_project_comment(comment) + comment.user == current_user || + is_owner_of_project(project) + end + def can_restore_archived_modules(project) is_user_or_higher_of_project(project) end @@ -475,6 +488,26 @@ module PermissionHelper is_technician_or_higher_of_project(my_module.experiment.project) end + def can_edit_module_comment(comment) + comment.my_module_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.my_module_comment.my_module.experiment.project + ) + ) + end + + def can_delete_module_comment(comment) + comment.my_module_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.my_module_comment.my_module.experiment.project + ) + ) + end + def can_view_module_samples(my_module) can_view_module(my_module) and can_view_samples(my_module.experiment.project.organization) @@ -502,6 +535,26 @@ module PermissionHelper is_technician_or_higher_of_project(my_module.experiment.project) end + def can_edit_result_comment_in_module(comment) + comment.result_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.result_comment.result.my_module.experiment.project + ) + ) + end + + def can_delete_result_comment_in_module(comment) + comment.result_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.result_comment.result.my_module.experiment.project + ) + ) + end + # ---- RESULT TEXT PERMISSIONS ---- def can_create_result_text_in_module(my_module) @@ -874,6 +927,34 @@ module PermissionHelper end end + def can_edit_step_comment_in_protocol(comment) + if protocol.in_module? + comment.step_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.step_comment.step.protocol.my_module.experiment.project + ) + ) + else + false + end + end + + def can_delete_step_comment_in_protocol(comment) + if protocol.in_module? + comment.step_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.step_comment.step.protocol.my_module.experiment.project + ) + ) + else + false + end + end + def can_view_or_download_step_assets(protocol) if protocol.in_module? my_module = protocol.my_module From ff9bb17912fd708ca702b1a429a598c1f7640fdd Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 24 Aug 2016 11:27:29 +0200 Subject: [PATCH 04/19] Update routes.rb --- config/routes.rb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 20ff36cce..ad68e6068 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,17 +46,12 @@ Rails.application.routes.draw do end get 'projects/archive', to: 'projects#archive', as: 'projects_archive' - - post 'projects/delete_comment_results', to: 'projects#delete_comment_results' - post 'projects/update_comment_results', to: 'projects#update_comment_results' - post 'projects/delete_comment_projects', to: 'projects#delete_comment_projects' - post 'projects/update_comment_projects', to: 'projects#update_comment_projects' - post 'projects/delete_comment_modules', to: 'projects#delete_comment_modules' - post 'projects/update_comment_modules', to: 'projects#update_comment_modules' resources :projects, except: [:new, :destroy] do resources :user_projects, path: "/users", only: [:new, :create, :index, :edit, :update, :destroy] - resources :project_comments, path: "/comments", only: [:new, :create, :index] + resources :project_comments, + path: '/comments', + only: [:new, :create, :index, :update, :destroy] # Activities popup (JSON) for individual project in projects index, # as well as all activities page for single project (HTML) resources :project_activities, path: "/activities", only: [:index] @@ -152,7 +147,9 @@ Rails.application.routes.draw do resources :my_modules, path: "/modules", only: [:show, :edit, :update, :destroy] do resources :my_module_tags, path: "/tags", only: [:index, :create, :update, :destroy] resources :user_my_modules, path: "/users", only: [:index, :new, :create, :destroy] - resources :my_module_comments, path: "/comments", only: [:index, :new, :create] + resources :my_module_comments, + path: '/comments', + only: [:index, :new, :create, :update, :destroy] resources :sample_my_modules, path: "/samples_index", only: [:index] resources :result_texts, only: [:new, :create] resources :result_assets, only: [:new, :create] @@ -180,7 +177,9 @@ Rails.application.routes.draw do end resources :steps, only: [:edit, :update, :destroy, :show] do - resources :step_comments, path: "/comments", only: [:new, :create, :index] + resources :step_comments, + path: '/comments', + only: [:new, :create, :index, :update, :destroy] member do post 'checklistitem_state' post 'toggle_step_state' @@ -190,7 +189,9 @@ Rails.application.routes.draw do end resources :results, only: [:update] do - resources :result_comments, path: "/comments", only: [:new, :create, :index] + resources :result_comments, + path: '/comments', + only: [:new, :create, :index, :update, :destroy] end resources :samples, only: [:edit, :update, :destroy] @@ -236,8 +237,6 @@ Rails.application.routes.draw do get "edit_description_modal", to: "protocols#edit_description_modal" end collection do - post 'delete_comment', to: 'protocols#delete_comment' - post 'update_comment', to: 'protocols#update_comment' get "create_new_modal", to: "protocols#create_new_modal" post "datatable", to: "protocols#datatable" post "make_private", to: "protocols#make_private" From 8a73a3ab5c98ca6de868afdd0a085fc23c6fc38d Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 24 Aug 2016 11:36:09 +0200 Subject: [PATCH 05/19] Update permission_helper.rb and routes.rb --- app/helpers/permission_helper.rb | 7 +++++-- config/routes.rb | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/helpers/permission_helper.rb b/app/helpers/permission_helper.rb index 3f3cd2a71..320189d1c 100644 --- a/app/helpers/permission_helper.rb +++ b/app/helpers/permission_helper.rb @@ -311,8 +311,11 @@ module PermissionHelper end def can_delete_project_comment(comment) - comment.user == current_user || - is_owner_of_project(project) + comment.project_comment.present? && + ( + comment.user == current_user || + is_owner_of_project(comment.project_comment.project) + ) end def can_restore_archived_modules(project) diff --git a/config/routes.rb b/config/routes.rb index ad68e6068..aa164cc39 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,7 +51,7 @@ Rails.application.routes.draw do resources :user_projects, path: "/users", only: [:new, :create, :index, :edit, :update, :destroy] resources :project_comments, path: '/comments', - only: [:new, :create, :index, :update, :destroy] + only: [:new, :create, :index, :edit, :update, :destroy] # Activities popup (JSON) for individual project in projects index, # as well as all activities page for single project (HTML) resources :project_activities, path: "/activities", only: [:index] @@ -149,7 +149,7 @@ Rails.application.routes.draw do resources :user_my_modules, path: "/users", only: [:index, :new, :create, :destroy] resources :my_module_comments, path: '/comments', - only: [:index, :new, :create, :update, :destroy] + only: [:index, :new, :create, :edit, :update, :destroy] resources :sample_my_modules, path: "/samples_index", only: [:index] resources :result_texts, only: [:new, :create] resources :result_assets, only: [:new, :create] @@ -179,7 +179,7 @@ Rails.application.routes.draw do resources :steps, only: [:edit, :update, :destroy, :show] do resources :step_comments, path: '/comments', - only: [:new, :create, :index, :update, :destroy] + only: [:new, :create, :index, :edit, :update, :destroy] member do post 'checklistitem_state' post 'toggle_step_state' @@ -191,7 +191,7 @@ Rails.application.routes.draw do resources :results, only: [:update] do resources :result_comments, path: '/comments', - only: [:new, :create, :index, :update, :destroy] + only: [:new, :create, :index, :edit, :update, :destroy] end resources :samples, only: [:edit, :update, :destroy] From 9e3bb8edb71183d17a8211e055672f7c416aafa0 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 24 Aug 2016 14:00:30 +0200 Subject: [PATCH 06/19] Add dependant: :destroy to comments --- app/models/comment.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 1d2ed2dcf..7f6de1029 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -11,11 +11,11 @@ class Comment < ActiveRecord::Base belongs_to :user, inverse_of: :comments belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User' - has_one :step_comment, inverse_of: :comment - has_one :my_module_comment, inverse_of: :comment - has_one :result_comment, inverse_of: :comment - has_one :sample_comment, inverse_of: :comment - has_one :project_comment, inverse_of: :comment + has_one :step_comment, inverse_of: :comment, dependent: :destroy + has_one :my_module_comment, inverse_of: :comment, dependent: :destroy + has_one :result_comment, inverse_of: :comment, dependent: :destroy + has_one :sample_comment, inverse_of: :comment, dependent: :destroy + has_one :project_comment, inverse_of: :comment, dependent: :destroy def self.search( user, From 15c0baeee8758d2838aa4320640ea150fa918d5c Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 24 Aug 2016 15:45:49 +0200 Subject: [PATCH 07/19] Add delete project comment functionality This commit also removes the old code from @bberic. --- app/assets/javascripts/comments.js | 48 +++++++++++++++++ app/assets/javascripts/projects/index.js | 51 +++--------------- app/assets/stylesheets/colors.scss | 1 + app/assets/stylesheets/themes/scinote.scss | 23 +++++++- .../project_comments_controller.rb | 53 +++++++++++++++++++ app/views/project_comments/_comment.html.erb | 46 ++++++++++++---- app/views/project_comments/_index.html.erb | 2 +- app/views/project_comments/_list.html.erb | 11 ++-- config/initializers/assets.rb | 1 + config/locales/en.yml | 8 +++ 10 files changed, 183 insertions(+), 61 deletions(-) create mode 100644 app/assets/javascripts/comments.js diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js new file mode 100644 index 000000000..140746d84 --- /dev/null +++ b/app/assets/javascripts/comments.js @@ -0,0 +1,48 @@ +function initCommentOptions(scrollableContainer) { + document.addEventListener('scroll', function (event) { + var $target = $(event.target); + + if ($target.length && $target.is(scrollableContainer)) { + scrollCommentOptions($target.find(".dropdown-comment")); + } + }, true); +} + +function scrollCommentOptions(selector) { + _.each(selector, function(el) { + var $el = $(el); + $el.find(".dropdown-menu-fixed").css("top", $el.offset().top + 20); + }); +} + +function initDeleteComment(parent) { + $(parent).on("click", "[data-action=delete-comment]", function(e) { + var $this = $(this); + if (confirm($this.attr("data-confirm-message"))) { + $.ajax({ + url: $this.attr("data-url"), + type: "DELETE", + dataType: "json", + success: function (data) { + // There are 3 possible actions: + // - (A) comment is the last comment in project (not handled differently) + // - (B) comment is the last comment inside specific date (remove the date separator) + // - (C) comment is a usual comment + var commentEl = $this.closest(".comment"); + var otherComments = commentEl.siblings(".comment"); + if (commentEl.prev(".comment-date-separator").length > 0 && commentEl.next(".comment").length == 0) { + // Case B + commentEl.prev(".comment-date-separator").remove(); + } + commentEl.remove(); + + scrollCommentOptions($(parent).find(".dropdown-comment")); + }, + error: function (data) { + // Display alert + alert(data.responseJSON.message); + } + }); + } + }); +} \ No newline at end of file diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index 21ada4c6f..8ce463872 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -7,46 +7,7 @@ // - refresh project users tab after manage user modal is closed // - refactor view handling using library, ex. backbone.js -function project_comment_edit(id) { - document.getElementById('edit_comment_'+id).type='text'; - $('#span_comment_'+id).hide(); - return false; -} - -function project_update_comment(id) { - if (document.getElementById('edit_comment_'+id).type=='text') { - var txt = document.getElementById('edit_comment_'+id).value; - $.ajax({ - type: "POST", - url: '/projects/update_comment_projects', - dataType: 'json', - data: {id: id, msg: txt}, - success: function (data) { - document.getElementById('edit_comment_'+id).type='hidden'; - var txt = document.getElementById('edit_comment_'+id).value; - $('#span_comment_'+id).text(txt); - $('#span_comment_'+id).show(); - } - }); - } -} - -function project_comment_delete(id) { - if (confirm('Are you sure you want to delete this comment?')) { - $.ajax({ - type: "POST", - url: '/projects/delete_comment_projects', - dataType: 'json', - data: {id: id}, - success: function (data) { - $('.content-comments').find('#'+id).remove(); - } - }); - } - - return false; -} - +//= require comments (function () { var newProjectModal = null; @@ -255,15 +216,13 @@ function project_comment_delete(id) { .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); - var s1 = data.html - var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); @@ -309,6 +268,9 @@ function project_comment_delete(id) { } else { moreBtn.attr("href", data.more_url); } + + // Reposition dropdown comment options + scrollCommentOptions(listItem.closest(".content-comments").find(".dropdown-comment")); } }); } @@ -374,7 +336,6 @@ function project_comment_delete(id) { initUserRoleForms(); } - function init() { newProjectModal = $("#new-project-modal"); @@ -394,6 +355,8 @@ function project_comment_delete(id) { initNewProjectModal(); initEditProjectModal(); initManageUsersModal(); + initCommentOptions("ul.content-comments"); + initDeleteComment(".panel-project .tab-content"); // initialize project tab remote loading $(".panel-project .panel-footer [role=tab]") diff --git a/app/assets/stylesheets/colors.scss b/app/assets/stylesheets/colors.scss index 1f6e5546b..d70a53e0d 100644 --- a/app/assets/stylesheets/colors.scss +++ b/app/assets/stylesheets/colors.scss @@ -6,6 +6,7 @@ $color-theme-dark: #6d6e71; // Grayscales $color-white: #fff; $color-alabaster: #fcfcfc; +$color-wild-sand: #f5f5f5; $color-concrete: #f2f2f2; $color-gallery: #EEE; $color-alto: #d2d2d2; diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 138eeaeb1..14f9809a3 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1168,4 +1168,25 @@ html.turbolinks-progress-bar::before { height: 20px; display: inline-block; margin-right: 5px; -} \ No newline at end of file +} + +/* Comments */ + +.dropdown.dropdown-comment { + display: inline-block; + + a[data-role="comment-options"] { + color: $color-emperor; + } +} + +ul.dropdown-menu.dropdown-menu-fixed { + position: fixed; + left: auto; + top: auto; + + & > li:not(.dropdown-header):hover { + background-color: $color-wild-sand; + } +} + diff --git a/app/controllers/project_comments_controller.rb b/app/controllers/project_comments_controller.rb index 3a868d2e6..b0b20f9a3 100644 --- a/app/controllers/project_comments_controller.rb +++ b/app/controllers/project_comments_controller.rb @@ -2,6 +2,8 @@ class ProjectCommentsController < ApplicationController before_action :load_vars before_action :check_view_permissions, only: [ :index ] before_action :check_add_permissions, only: [ :new, :create ] + before_action :check_edit_permissions, only: [:edit, :update] + before_action :check_destroy_permissions, only: [:destroy] def index @comments = @project.last_comments(@last_comment_id, @per_page) @@ -76,6 +78,47 @@ class ProjectCommentsController < ApplicationController end end + def edit + respond_to do |format| + format.json do + render json: { + html: render_to_string( + partial: 'edit.html.erb', + locals: { + comment: @comment + } + ) + } + end + end + end + + def update + @comment.message = comment_params[:message] + respond_to do |format| + format.json do + if @comment.save + render json: {}, status: :ok + else + render json: @comment.errors, status: :unprocessable_entity + end + end + end + end + + def destroy + respond_to do |format| + format.json do + if @comment.destroy + render json: {}, status: :ok + else + render json: { message: I18n.t('comments.delete_error') }, + status: :unprocessable_entity + end + end + end + end + private def load_vars @@ -100,6 +143,16 @@ class ProjectCommentsController < ApplicationController end end + def check_edit_permissions + @comment = Comment.find_by_id(params[:id]) + render_403 unless @comment.present? && can_edit_project_comment(@comment) + end + + def check_destroy_permissions + @comment = Comment.find_by_id(params[:id]) + render_403 unless @comment.present? && can_delete_project_comment(@comment) + end + def comment_params params.require(:comment).permit(:message) end diff --git a/app/views/project_comments/_comment.html.erb b/app/views/project_comments/_comment.html.erb index 2655c2a20..a1aea95b0 100644 --- a/app/views/project_comments/_comment.html.erb +++ b/app/views/project_comments/_comment.html.erb @@ -1,13 +1,37 @@ -<%= l comment.created_at, format: '%H:%M' %> -<%= comment.user.full_name %>: - - - <%= comment.message %> -
    - -
    <%= comment.user.full_name %>: -

    <%= comment.message %>

    +
    +

    <%= comment.message %>

    +
    From c92d016f656f34201738624ed06d1dd0782fb337 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Thu, 25 Aug 2016 09:26:45 +0200 Subject: [PATCH 09/19] Add edit&delete module/task comments functionality This required a minor fix of comments.js. --- app/assets/javascripts/comments.js | 10 +-- app/assets/javascripts/projects/canvas.js | 64 ++++++------------- .../my_module_comments_controller.rb | 51 +++++++++++++++ .../my_module_comments/_comment.html.erb | 48 ++++++++++---- app/views/my_module_comments/_index.html.erb | 2 +- app/views/my_module_comments/_list.html.erb | 10 +-- 6 files changed, 122 insertions(+), 63 deletions(-) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index a34499150..f267f9524 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -1,17 +1,19 @@ -function initCommentOptions(scrollableContainer) { +function initCommentOptions(scrollableContainer, useParentOffset = true) { document.addEventListener('scroll', function (event) { var $target = $(event.target); if ($target.length && $target.is(scrollableContainer)) { - scrollCommentOptions($target.find(".dropdown-comment")); + scrollCommentOptions($target.find(".dropdown-comment"), useParentOffset); } }, true); } -function scrollCommentOptions(selector) { +function scrollCommentOptions(selector, useParentOffset = true) { _.each(selector, function(el) { var $el = $(el); - $el.find(".dropdown-menu-fixed").css("top", $el.offset().top + 20); + var offset = useParentOffset ? $el.offset().top : $el.position().top; + $el.find(".dropdown-menu-fixed") + .offset({ top: (offset + 20) }); }); } diff --git a/app/assets/javascripts/projects/canvas.js b/app/assets/javascripts/projects/canvas.js index e077ea582..c44411041 100644 --- a/app/assets/javascripts/projects/canvas.js +++ b/app/assets/javascripts/projects/canvas.js @@ -1,3 +1,5 @@ +//= require comments + //************************************ // CONSTANTS //************************************ @@ -321,6 +323,11 @@ function initializeFullZoom() { // Restore draggable position restoreDraggablePosition($("#diagram"), $("#canvas-container")); + + // Initialize comments + initCommentOptions("ul.content-comments", false); + initEditComments(".panel.module-large .tab-content"); + initDeleteComments(".panel.module-large .tab-content"); } function destroyFullZoom() { @@ -337,6 +344,13 @@ function destroyFullZoom() { $("li[data-module-id]").off("mouseenter mouseleave"); $("li[data-module-id] > span > a.canvas-center-on").off("click"); + // Clean up comments listeners + $(document).off("scroll"); + $(".panel.module-large .tab-content") + .off("click", "[data-action=edit-comment]"); + $(".panel.module-large .tab-content") + .off("click", "[data-action=delete-comment]"); + // Remember the draggable position rememberDraggablePosition($("#diagram"), $("#canvas-container")); } @@ -676,15 +690,13 @@ function bindFullZoomAjaxTabs() { .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); - var s1 = data.html - var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); @@ -730,6 +742,12 @@ function bindFullZoomAjaxTabs() { } else { moreBtn.attr("href", data.more_url); } + + // Reposition dropdown comment options + scrollCommentOptions( + listItem.closest(".content-comments").find(".dropdown-comment"), + false + ); } }); } @@ -3486,43 +3504,3 @@ function showTutorial() { var currentProjectId = $("#canvas-container").attr("data-project-id"); return tutorialProjectId == currentProjectId; } - -function module_comment_edit(id) { - document.getElementById('edit_comment_'+id).type='text'; - $('#span_comment_'+id).hide(); - return false; -} - -function module_update_comment(id) { - if (document.getElementById('edit_comment_'+id).type=='text') { - var txt = document.getElementById('edit_comment_'+id).value; - $.ajax({ - type: "POST", - url: '/projects/update_comment_modules', - dataType: 'json', - data: {id: id, msg: txt}, - success: function (data) { - document.getElementById('edit_comment_'+id).type='hidden'; - var txt = document.getElementById('edit_comment_'+id).value; - $('#span_comment_'+id).text(txt); - $('#span_comment_'+id).show(); - } - }); - } -} - -function module_comment_delete(id) { - if (confirm('Are you sure you want to delete this comment?')) { - $.ajax({ - type: "POST", - url: '/projects/delete_comment_modules', - dataType: 'json', - data: {id: id}, - success: function (data) { - $('.content-comments').find('#'+id).remove(); - } - }); - } - - return false; -} diff --git a/app/controllers/my_module_comments_controller.rb b/app/controllers/my_module_comments_controller.rb index ae755fa3d..7a06195c3 100644 --- a/app/controllers/my_module_comments_controller.rb +++ b/app/controllers/my_module_comments_controller.rb @@ -2,6 +2,8 @@ class MyModuleCommentsController < ApplicationController before_action :load_vars before_action :check_view_permissions, only: [ :index ] before_action :check_add_permissions, only: [ :new, :create ] + before_action :check_edit_permissions, only: [:edit, :update] + before_action :check_destroy_permissions, only: [:destroy] def index @comments = @my_module.last_comments(@last_comment_id, @per_page) @@ -77,6 +79,46 @@ class MyModuleCommentsController < ApplicationController end end + def edit + @update_url = my_module_my_module_comment_path(@my_module, @comment, format: :json) + respond_to do |format| + format.json do + render json: { + html: render_to_string( + partial: '/comments/edit.html.erb' + ) + } + end + end + end + + def update + @comment.message = comment_params[:message] + respond_to do |format| + format.json do + if @comment.save + render json: {}, status: :ok + else + render json: { errors: @comment.errors.to_hash(true) }, + status: :unprocessable_entity + end + end + end + end + + def destroy + respond_to do |format| + format.json do + if @comment.destroy + render json: {}, status: :ok + else + render json: { message: I18n.t('comments.delete_error') }, + status: :unprocessable_entity + end + end + end + end + private def load_vars @@ -101,6 +143,15 @@ class MyModuleCommentsController < ApplicationController end end + def check_edit_permissions + @comment = Comment.find_by_id(params[:id]) + render_403 unless @comment.present? && can_edit_module_comment(@comment) + end + + def check_destroy_permissions + @comment = Comment.find_by_id(params[:id]) + render_403 unless @comment.present? && can_delete_module_comment(@comment) + end def comment_params params.require(:comment).permit(:message) diff --git a/app/views/my_module_comments/_comment.html.erb b/app/views/my_module_comments/_comment.html.erb index 36b9416ba..82c7d47b7 100644 --- a/app/views/my_module_comments/_comment.html.erb +++ b/app/views/my_module_comments/_comment.html.erb @@ -1,13 +1,39 @@ -<%= l comment.created_at, format: '%H:%M' %> -<%= comment.user.full_name %>: - - - <%= comment.message %> -
    - -
    <% end %> diff --git a/app/views/step_comments/_comment.html.erb b/app/views/step_comments/_comment.html.erb index 0ad4d07d7..3ea3e1a53 100644 --- a/app/views/step_comments/_comment.html.erb +++ b/app/views/step_comments/_comment.html.erb @@ -16,21 +16,25 @@ <% end %> From a480c8d40300d627129e8c465e035d01dc01002e Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Thu, 25 Aug 2016 13:59:50 +0200 Subject: [PATCH 16/19] Styling fixes --- app/assets/stylesheets/themes/scinote.scss | 14 +++++++------- app/controllers/result_comments_controller.rb | 1 - app/models/result_comment.rb | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index ccf341af9..80e4d5013 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1170,28 +1170,28 @@ html.turbolinks-progress-bar::before { margin-right: 5px; } -/* Comments */ +// Comments .dropdown.dropdown-comment { display: inline-block; - a[data-role="comment-options"] { + [data-role="comment-options"] { color: $color-emperor; } } -ul.dropdown-menu.dropdown-menu-fixed { - position: fixed; +.dropdown-menu.dropdown-menu-fixed { left: auto; + position: fixed; top: auto; - & > li:not(.dropdown-header):hover { + li:not(.dropdown-header):hover { background-color: $color-wild-sand; } } -form.edit-comment-form { - span.help-block { +.edit-comment-form { + .help-block { display: inline; } } \ No newline at end of file diff --git a/app/controllers/result_comments_controller.rb b/app/controllers/result_comments_controller.rb index ed59b3088..63d311447 100644 --- a/app/controllers/result_comments_controller.rb +++ b/app/controllers/result_comments_controller.rb @@ -195,7 +195,6 @@ class ResultCommentsController < ApplicationController can_delete_result_comment_in_module(@comment) end - def comment_params params.require(:comment).permit(:message) end diff --git a/app/models/result_comment.rb b/app/models/result_comment.rb index 4e77638a4..a0a1e7f28 100644 --- a/app/models/result_comment.rb +++ b/app/models/result_comment.rb @@ -4,5 +4,5 @@ class ResultComment < ActiveRecord::Base belongs_to :result, inverse_of: :result_comments belongs_to :comment, - inverse_of: :result_comment + inverse_of: :result_comment end From 9cd99fc532096f81cbd3ce9dafd3ebbcd53dfb81 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Thu, 25 Aug 2016 17:01:30 +0200 Subject: [PATCH 17/19] Display "no comments" if you delete the last comment --- app/assets/javascripts/comments.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 4e20507f9..62fb1c5c3 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -30,13 +30,19 @@ function initDeleteComments(parent) { dataType: "json", success: function(data) { // There are 3 possible actions: - // - (A) comment is the last comment in project (not handled differently) + // - (A) comment is the last comment in project // - (B) comment is the last comment inside specific date (remove the date separator) // - (C) comment is a usual comment + var commentEl = $this.closest(".comment"); - var otherComments = commentEl.siblings(".comment"); + + // Case A + if (commentEl.prevAll(".comment").length == 0 && commentEl.next().length == 0) { + commentEl.after("
  • " + I18n.t("projects.index.no_comments") + "
  • "); + } + + // Case B if (commentEl.prev(".comment-date-separator").length > 0 && commentEl.next(".comment").length == 0) { - // Case B commentEl.prev(".comment-date-separator").remove(); } commentEl.remove(); From 7cd94e8b0da8ae4f344296e003bb832a209b0136 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Thu, 25 Aug 2016 17:09:55 +0200 Subject: [PATCH 18/19] Fix a minor bug on canvas --- app/assets/javascripts/projects/canvas.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/projects/canvas.js b/app/assets/javascripts/projects/canvas.js index deb9bd146..4d929e5c2 100644 --- a/app/assets/javascripts/projects/canvas.js +++ b/app/assets/javascripts/projects/canvas.js @@ -706,7 +706,8 @@ function bindFullZoomAjaxTabs() { .html("") .addClass("hide"); scrollCommentOptions( - list.parent().find(".content-comments .dropdown-comment") + list.parent().find(".content-comments .dropdown-comment"), + false ); } }) From b533b0aca6deb3028187f97fd16500eb5437cf07 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Thu, 25 Aug 2016 17:15:53 +0200 Subject: [PATCH 19/19] Fix another minor bug --- app/assets/javascripts/my_modules/results.js | 4 ++-- app/assets/javascripts/protocols/steps.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/my_modules/results.js b/app/assets/javascripts/my_modules/results.js index 684a3f478..f71a5b832 100644 --- a/app/assets/javascripts/my_modules/results.js +++ b/app/assets/javascripts/my_modules/results.js @@ -195,8 +195,8 @@ initTutorial(); applyCollapseLinkCallBack(); initCommentOptions("ul.content-comments"); -initEditComments(".panel .tab-content"); -initDeleteComments(".panel .tab-content"); +initEditComments("#results"); +initDeleteComments("#results"); $(function () { $("#results-collapse-btn").click(function () { diff --git a/app/assets/javascripts/protocols/steps.js b/app/assets/javascripts/protocols/steps.js index cd294a0ee..2075521c6 100644 --- a/app/assets/javascripts/protocols/steps.js +++ b/app/assets/javascripts/protocols/steps.js @@ -654,8 +654,8 @@ setupAssetsLoading(); // Init comments edit/delete initCommentOptions("ul.content-comments"); -initEditComments(".panel .tab-content"); -initDeleteComments(".panel .tab-content"); +initEditComments("#steps"); +initDeleteComments("#steps"); $(function () {