diff --git a/app/assets/javascripts/comments.js.erb b/app/assets/javascripts/comments.js.erb index bfdc5a599..b1a694f26 100644 --- a/app/assets/javascripts/comments.js.erb +++ b/app/assets/javascripts/comments.js.erb @@ -16,18 +16,21 @@ var Comments = (function() { $.each(comments, function(){ var that = $(this); var link = that.attr('data-href'); - $.ajax({ method: 'GET', - url: link, - beforeSend: animateSpinner(that, true) }) - .done(function(data) { - that.html(data.html); - initCommentForm(that); - initCommentsLink(that); - scrollBottom(that.find('.content-comments')); - }) - .always(function() { - animateSpinner(that, false); - }); + if(that.html().length === 0) { + $.ajax({ method: 'GET', + url: link, + beforeSend: animateSpinner(that, true) }) + .done(function(data) { + that.html(data.html); + + }) + .always(function() { + animateSpinner(that, false); + }); + } + initCommentForm(that); + initCommentsLink(that); + scrollBottom(that.find('.content-comments')); }); } } @@ -238,7 +241,8 @@ var Comments = (function() { } function initDeleteComments(parent) { - $(parent).on('click', '[data-action=delete-comment]', function() { + $(parent).on('click', '[data-action=delete-comment]', function(ev) { + ev.preventDefault(); var $this = $(this); if (confirm($this.attr('data-confirm-message'))) { $.ajax({ diff --git a/app/assets/javascripts/projects/canvas.js.erb b/app/assets/javascripts/projects/canvas.js.erb index ca2463470..fdf2047d2 100644 --- a/app/assets/javascripts/projects/canvas.js.erb +++ b/app/assets/javascripts/projects/canvas.js.erb @@ -873,23 +873,21 @@ function bindEditTagsAjax(elements) { // Reload tags HTML element when modal is closed manageTagsModal.on("hide.bs.modal", function(){ - var tasks = $("div.panel"); + var task = $("div.panel[data-module-id='" + + manageTagsModal.data('module-id') + "']"); - tasks.each(function(){ - var task = $(this); - // Load HTML - $.ajax({ - url: task.attr("data-module-tags-url"), - type: "GET", - dataType: "json", - success: function(data){ - task.find(".edit-tags-link") - .html(data.html_canvas); - }, - error: function(data){ - // TODO - } - }) + // Load HTML + $.ajax({ + url: task.attr("data-module-tags-url"), + type: "GET", + dataType: "json", + success: function(data){ + task.find(".edit-tags-link") + .html(data.html_canvas); + }, + error: function(data){ + // TODO + } }); }); diff --git a/app/controllers/result_comments_controller.rb b/app/controllers/result_comments_controller.rb index 44cc271ee..071e1980c 100644 --- a/app/controllers/result_comments_controller.rb +++ b/app/controllers/result_comments_controller.rb @@ -18,9 +18,9 @@ class ResultCommentsController < ApplicationController # messages. 'list' partial is used for showing more # comments. partial = 'index.html.erb' - partial = 'list.html.erb' if @last_comment_id > 0 + partial = 'list.html.erb' if @last_comment_id.positive? more_url = '' - if @comments.count > 0 + if @comments.size.positive? more_url = url_for(result_result_comments_path(@result, format: :json, from: @comments @@ -28,11 +28,14 @@ class ResultCommentsController < ApplicationController end render json: { perPage: @per_page, - resultsNumber: @comments.length, + resultsNumber: @comments.size, moreUrl: more_url, - html: render_to_string(partial: partial, - locals: { comments: @comments, - more_comments_url: more_url }) + html: render_to_string( + partial: partial, + locals: { + result: @result, comments: @comments, per_page: @per_page + } + ) } end end diff --git a/app/controllers/step_comments_controller.rb b/app/controllers/step_comments_controller.rb index 44fcb92e7..a0b66989d 100644 --- a/app/controllers/step_comments_controller.rb +++ b/app/controllers/step_comments_controller.rb @@ -19,20 +19,21 @@ class StepCommentsController < ApplicationController # messages. 'list' partial is used for showing more # comments. partial = 'index.html.erb' - partial = 'list.html.erb' if @last_comment_id > 0 + partial = 'list.html.erb' if @last_comment_id.positive? more_url = '' - if @comments.count > 0 + if @comments.size.positive? more_url = url_for(step_step_comments_path(@step, format: :json, from: @comments.first.id)) end render json: { perPage: @per_page, - resultsNumber: @comments.length, + resultsNumber: @comments.size, moreUrl: more_url, - html: render_to_string(partial: partial, - locals: { comments: @comments, - more_comments_url: more_url }) + html: render_to_string( + partial: partial, + locals: { step: @step, comments: @comments, per_page: @per_page } + ) } end end diff --git a/app/models/asset.rb b/app/models/asset.rb index 98f17659f..abfb9caa5 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -71,6 +71,7 @@ class Asset < ApplicationRecord # Needed because Paperclip validatates on creation after_initialize :filter_paperclip_errors, if: :new_record? before_destroy :paperclip_delete, prepend: true + after_save { result&.touch; step&.touch } attr_accessor :file_content, :file_info, :preview_cached diff --git a/app/models/checklist.rb b/app/models/checklist.rb index ba4e2e433..321ed514b 100644 --- a/app/models/checklist.rb +++ b/app/models/checklist.rb @@ -7,7 +7,7 @@ class Checklist < ApplicationRecord length: { maximum: Constants::TEXT_MAX_LENGTH } validates :step, presence: true - belongs_to :step, inverse_of: :checklists, optional: true + belongs_to :step, inverse_of: :checklists, touch: true, optional: true belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User', diff --git a/app/models/result.rb b/app/models/result.rb index 70ef6e6c8..adf74e146 100644 --- a/app/models/result.rb +++ b/app/models/result.rb @@ -19,17 +19,11 @@ class Result < ApplicationRecord class_name: 'User', optional: true belongs_to :my_module, inverse_of: :results, optional: true - has_one :result_asset, - inverse_of: :result, - dependent: :destroy + has_one :result_asset, inverse_of: :result, dependent: :destroy has_one :asset, through: :result_asset - has_one :result_table, - inverse_of: :result, - dependent: :destroy + has_one :result_table, inverse_of: :result, dependent: :destroy has_one :table, through: :result_table - has_one :result_text, - inverse_of: :result, - dependent: :destroy + has_one :result_text, inverse_of: :result, dependent: :destroy has_many :result_comments, foreign_key: :associated_id, dependent: :destroy has_many :report_elements, inverse_of: :result, dependent: :destroy diff --git a/app/models/result_asset.rb b/app/models/result_asset.rb index 53f2bcfb7..55ab7f51e 100644 --- a/app/models/result_asset.rb +++ b/app/models/result_asset.rb @@ -1,7 +1,7 @@ class ResultAsset < ApplicationRecord validates :result, :asset, presence: true - belongs_to :result, inverse_of: :result_asset, optional: true + belongs_to :result, inverse_of: :result_asset, touch: true, optional: true belongs_to :asset, inverse_of: :result_asset, dependent: :destroy, diff --git a/app/models/result_comment.rb b/app/models/result_comment.rb index d3d858aa2..955d4ab29 100644 --- a/app/models/result_comment.rb +++ b/app/models/result_comment.rb @@ -2,6 +2,7 @@ class ResultComment < Comment belongs_to :result, foreign_key: :associated_id, inverse_of: :result_comments, + touch: true, optional: true validates :result, presence: true diff --git a/app/models/result_table.rb b/app/models/result_table.rb index 26902412d..2d892c8e7 100644 --- a/app/models/result_table.rb +++ b/app/models/result_table.rb @@ -1,7 +1,7 @@ class ResultTable < ApplicationRecord validates :result, :table, presence: true - belongs_to :result, inverse_of: :result_table, optional: true + belongs_to :result, inverse_of: :result_table, touch: true, optional: true belongs_to :table, inverse_of: :result_table, dependent: :destroy, diff --git a/app/models/result_text.rb b/app/models/result_text.rb index 719c2c026..de40b186e 100644 --- a/app/models/result_text.rb +++ b/app/models/result_text.rb @@ -4,6 +4,6 @@ class ResultText < ApplicationRecord presence: true, length: { maximum: Constants::RICH_TEXT_MAX_LENGTH } validates :result, presence: true - belongs_to :result, inverse_of: :result_text, optional: true + belongs_to :result, inverse_of: :result_text, touch: true, optional: true has_many :tiny_mce_assets, inverse_of: :result_text, dependent: :destroy end diff --git a/app/models/step_asset.rb b/app/models/step_asset.rb index 60dfdbd33..46aa8622e 100644 --- a/app/models/step_asset.rb +++ b/app/models/step_asset.rb @@ -3,6 +3,7 @@ class StepAsset < ApplicationRecord belongs_to :step, inverse_of: :step_assets, + touch: true, optional: true belongs_to :asset, inverse_of: :step_asset, diff --git a/app/models/step_comment.rb b/app/models/step_comment.rb index bc13fd337..889b2495f 100644 --- a/app/models/step_comment.rb +++ b/app/models/step_comment.rb @@ -2,6 +2,7 @@ class StepComment < Comment belongs_to :step, foreign_key: :associated_id, inverse_of: :step_comments, + touch: true, optional: true validates :step, presence: true diff --git a/app/models/step_table.rb b/app/models/step_table.rb index b6e4d5cbd..103d192fe 100644 --- a/app/models/step_table.rb +++ b/app/models/step_table.rb @@ -1,6 +1,6 @@ class StepTable < ApplicationRecord validates :step, :table, presence: true - belongs_to :step, inverse_of: :step_tables, optional: true + belongs_to :step, inverse_of: :step_tables, touch: true, optional: true belongs_to :table, inverse_of: :step_table, optional: true end diff --git a/app/models/table.rb b/app/models/table.rb index 6df0bcfae..5648655f5 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -25,6 +25,7 @@ class Table < ApplicationRecord has_many :report_elements, inverse_of: :table, dependent: :destroy after_save :update_ts_index + after_save { result&.touch; step&.touch } #accepts_nested_attributes_for :table def self.search(user, diff --git a/app/models/tiny_mce_asset.rb b/app/models/tiny_mce_asset.rb index b8e966d62..03b7c3afe 100644 --- a/app/models/tiny_mce_asset.rb +++ b/app/models/tiny_mce_asset.rb @@ -5,8 +5,11 @@ class TinyMceAsset < ApplicationRecord after_destroy :release_team_space belongs_to :team, inverse_of: :tiny_mce_assets, optional: true - belongs_to :step, inverse_of: :tiny_mce_assets, optional: true - belongs_to :result_text, inverse_of: :tiny_mce_assets, optional: true + belongs_to :step, inverse_of: :tiny_mce_assets, touch: true, optional: true + belongs_to :result_text, + inverse_of: :tiny_mce_assets, + touch: true, + optional: true has_attached_file :image, styles: { large: [Constants::LARGE_PIC_FORMAT, :jpg] }, convert_options: { large: '-quality 100 -strip' } diff --git a/app/models/user_my_module.rb b/app/models/user_my_module.rb index 5b53a81a0..60cfbcd1b 100644 --- a/app/models/user_my_module.rb +++ b/app/models/user_my_module.rb @@ -1,7 +1,7 @@ class UserMyModule < ApplicationRecord validates :user, :my_module, presence: true - belongs_to :user, inverse_of: :user_my_modules, optional: true + belongs_to :user, inverse_of: :user_my_modules, touch: true, optional: true belongs_to :assigned_by, foreign_key: 'assigned_by_id', class_name: 'User', diff --git a/app/models/user_team.rb b/app/models/user_team.rb index f3547e091..0173fca3e 100644 --- a/app/models/user_team.rb +++ b/app/models/user_team.rb @@ -5,7 +5,7 @@ class UserTeam < ApplicationRecord validates :user, presence: true validates :team, presence: true - belongs_to :user, inverse_of: :user_teams, optional: true + belongs_to :user, inverse_of: :user_teams, touch: true, optional: true belongs_to :assigned_by, foreign_key: 'assigned_by_id', class_name: 'User', diff --git a/app/views/comments/_edit.html.erb b/app/views/comments/_edit.html.erb index 3ff6603cf..b756f358e 100644 --- a/app/views/comments/_edit.html.erb +++ b/app/views/comments/_edit.html.erb @@ -14,6 +14,6 @@ - <%= t('general.cancel') %> + <%= t('general.cancel') %> <% end %> diff --git a/app/views/my_modules/_result.html.erb b/app/views/my_modules/_result.html.erb index 66a9c2b3f..40fb1268e 100644 --- a/app/views/my_modules/_result.html.erb +++ b/app/views/my_modules/_result.html.erb @@ -51,6 +51,8 @@
+ <%= render partial: "result_comments/index.html.erb", + locals: { result: result, comments: result.last_comments, per_page: Constants::COMMENTS_SEARCH_LIMIT } %>
<% end %> diff --git a/app/views/my_modules/results.html.erb b/app/views/my_modules/results.html.erb index 98a9d9da1..bbd8f980a 100644 --- a/app/views/my_modules/results.html.erb +++ b/app/views/my_modules/results.html.erb @@ -48,7 +48,9 @@
<% ordered_result_of(@my_module).each do |result| %> - <%= render partial: "result", locals: { result: result } %> + <% cache [current_user, result] do %> + <%= render partial: "result", locals: { result: result } %> + <% end %> <% end %>
diff --git a/app/views/protocols/_steps.html.erb b/app/views/protocols/_steps.html.erb index f9ea69a15..d319b4c51 100644 --- a/app/views/protocols/_steps.html.erb +++ b/app/views/protocols/_steps.html.erb @@ -25,7 +25,9 @@
<% @protocol.steps.order(:position).each do |step| %> - <%= render partial: "steps/step.html.erb", locals: { step: step } %> + <% cache [current_user, step] do %> + <%= render partial: "steps/step.html.erb", locals: { step: step } %> + <% end %> <% end %>
<% if @protocol.steps.count == 0 %> diff --git a/app/views/result_comments/_comment.html.erb b/app/views/result_comments/_comment.html.erb index 14512fc93..5dd51f498 100644 --- a/app/views/result_comments/_comment.html.erb +++ b/app/views/result_comments/_comment.html.erb @@ -1,3 +1,4 @@ +
<%=t "my_modules.results.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %> @@ -28,7 +29,7 @@ data-action="delete-comment" data-url="<%= result_result_comment_path(comment.result, comment, format: :json) %>" data-confirm-message="<%= t('comments.delete_confirm') %>" - data-no-turbolink="true"> + data-turbolinks="false"> <%= t('comments.options_dropdown.delete') %> diff --git a/app/views/result_comments/_index.html.erb b/app/views/result_comments/_index.html.erb index 1c3d30497..0b1528f56 100644 --- a/app/views/result_comments/_index.html.erb +++ b/app/views/result_comments/_index.html.erb @@ -4,24 +4,30 @@

<% if can_create_comments_in_module?(@my_module) then %>