From e43aa30193ea58f85c15701391709e167079cf2e Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 13 Oct 2022 13:55:36 +0200 Subject: [PATCH] Unify tags loading order [SCI-6943] --- app/controllers/my_module_tags_controller.rb | 2 +- app/models/my_module.rb | 7 +------ app/services/reports/docx/draw_my_module.rb | 6 +++--- app/views/canvas/_tags.html.erb | 2 +- app/views/reports/elements/_my_module_element.html.erb | 4 ++-- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/controllers/my_module_tags_controller.rb b/app/controllers/my_module_tags_controller.rb index 912d2d290..a62025545 100644 --- a/app/controllers/my_module_tags_controller.rb +++ b/app/controllers/my_module_tags_controller.rb @@ -7,7 +7,7 @@ class MyModuleTagsController < ApplicationController def index_edit @my_module_tags = @my_module.my_module_tags.order(:id) - @unassigned_tags = @my_module.unassigned_tags + @unassigned_tags = @my_module.unassigned_tags.order(:id) @new_mmt = MyModuleTag.new(my_module: @my_module) @new_tag = Tag.new(project: @my_module.experiment.project) diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 12f609cad..456f1a636 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -188,12 +188,7 @@ class MyModule < ApplicationRecord end def unassigned_tags - Tag.find_by_sql( - "SELECT DISTINCT tags.id, tags.name, tags.color FROM tags " + - "INNER JOIN experiments ON experiments.project_id = tags.project_id " + - "WHERE experiments.id = #{experiment_id.to_s} AND tags.id NOT IN " + - "(SELECT DISTINCT tag_id FROM my_module_tags WHERE my_module_tags.my_module_id = #{id.to_s})" - ) + experiment.project.tags.where.not(id: tags) end def last_activities(count = Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT) diff --git a/app/services/reports/docx/draw_my_module.rb b/app/services/reports/docx/draw_my_module.rb index 989c5fadc..c377af53c 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -6,7 +6,7 @@ module Reports::Docx::DrawMyModule link_style = @link_style scinote_url = @scinote_url my_module = subject.my_module - tags = my_module.tags + tags = my_module.tags.order(:id) return unless can_read_my_module?(@user, my_module) @docx.h3 do @@ -48,10 +48,10 @@ module Reports::Docx::DrawMyModule end end - if tags.any? + if tags.present? @docx.p do text I18n.t('projects.reports.elements.module.tags_header') - my_module.tags.each do |tag| + tags.each do |tag| text ' ' text "[#{tag.name}]", color: tag.color.delete('#') end diff --git a/app/views/canvas/_tags.html.erb b/app/views/canvas/_tags.html.erb index 5d6f43d3e..ed8a04a75 100644 --- a/app/views/canvas/_tags.html.erb +++ b/app/views/canvas/_tags.html.erb @@ -1,5 +1,5 @@
- <% tags2 = my_module.tags[0..3] %> + <% tags2 = my_module.tags.order(:id).take(4) %> <% tags2.each do |tag| %>
" diff --git a/app/views/reports/elements/_my_module_element.html.erb b/app/views/reports/elements/_my_module_element.html.erb index 4032e894e..bbd06a841 100644 --- a/app/views/reports/elements/_my_module_element.html.erb +++ b/app/views/reports/elements/_my_module_element.html.erb @@ -39,8 +39,8 @@
<%= t('projects.reports.elements.module.tags_header') %>
- <% if my_module.tags.present? %> - <% my_module.tags.each do |tag| %> + <% if (tags = my_module.tags.order(:id)).present? %> + <% tags.each do |tag| %>
<%= tag.name %>