diff --git a/app/controllers/dashboard/calendars_controller.rb b/app/controllers/dashboard/calendars_controller.rb index 65afdd28d..cbac57e26 100644 --- a/app/controllers/dashboard/calendars_controller.rb +++ b/app/controllers/dashboard/calendars_controller.rb @@ -3,6 +3,7 @@ module Dashboard class CalendarsController < ApplicationController include IconsHelper + include MyModulesListPartialHelper def show date = DateTime.parse(params[:date]) @@ -26,9 +27,11 @@ module Dashboard .where(projects: { archived: false }) .where('DATE(my_modules.due_date) = DATE(?)', date) .where(projects: { team_id: current_team.id }) - .my_modules_list_partial + my_modules_grouped = my_modules_list_partial(my_modules) render json: { - html: render_to_string(partial: 'shared/my_modules_list_partial.html.erb', locals: { task_groups: my_modules }) + html: render_to_string(partial: 'shared/my_modules_list_partial.html.erb', locals: { + task_groups: my_modules_grouped + }) } end end diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 3855c5753..90fb66b39 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -2,6 +2,7 @@ class RepositoryRowsController < ApplicationController include InputSanitizeHelper include ActionView::Helpers::TextHelper include ApplicationHelper + include MyModulesListPartialHelper before_action :load_info_modal_vars, only: %i(show assigned_task_list) before_action :load_vars, only: %i(edit update) @@ -183,10 +184,11 @@ class RepositoryRowsController < ApplicationController def assigned_task_list my_modules = @repository_row.my_modules.joins(experiment: :project) .search_by_name(current_user, current_team, params[:query]) - .my_modules_list_partial - + my_modules_grouped = my_modules_list_partial(my_modules) render json: { - html: render_to_string(partial: 'shared/my_modules_list_partial.html.erb', locals: { task_groups: my_modules }) + html: render_to_string(partial: 'shared/my_modules_list_partial.html.erb', locals: { + task_groups: my_modules_grouped + }) } end diff --git a/app/helpers/my_modules_list_partial_helper.rb b/app/helpers/my_modules_list_partial_helper.rb new file mode 100644 index 000000000..b35881a0c --- /dev/null +++ b/app/helpers/my_modules_list_partial_helper.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module MyModulesListPartialHelper + def my_modules_list_partial(my_modules) + ungrouped_tasks = my_modules.joins(experiment: :project) + .select('experiments.name as experiment_name, + experiments.archived as experiment_archived, + projects.name as project_name, + projects.archived as project_archived, + my_modules.*') + ungrouped_tasks.group_by { |i| [i[:project_name], i[:experiment_name]] }.map do |group, tasks| + { + project_name: group[0], + project_archived: tasks[0]&.project_archived, + experiment_name: group[1], + experiment_archived: tasks[0]&.experiment_archived, + tasks: tasks + } + end + end +end diff --git a/app/helpers/repository_datatable_helper.rb b/app/helpers/repository_datatable_helper.rb index aecf7485e..0055766f4 100644 --- a/app/helpers/repository_datatable_helper.rb +++ b/app/helpers/repository_datatable_helper.rb @@ -7,7 +7,7 @@ module RepositoryDatatableHelper repository_rows.map do |record| row = { 'DT_RowId': record.id, - '1': assigned_row(record, repository), + '1': assigned_row(record), '2': record.id, '3': escape_input(record.name), '4': I18n.l(record.created_at, format: :full), @@ -64,12 +64,12 @@ module RepositoryDatatableHelper end end - def assigned_row(record, repository) + def assigned_row(record) { tasks: record.assigned_my_modules_count, experiments: record.assigned_experiments_count, projects: record.assigned_projects_count, - task_list_url: assigned_task_list_repository_repository_row_path(repository, record) + task_list_url: assigned_task_list_repository_repository_row_path(record.repository, record) } end diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 6d893615e..86503139b 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -523,24 +523,6 @@ class MyModule < ApplicationRecord self.completed_on = nil end - def self.my_modules_list_partial - ungrouped_tasks = joins(experiment: :project) - .select('experiments.name as experiment_name, - experiments.archived as experiment_archived, - projects.name as project_name, - projects.archived as project_archived, - my_modules.*') - ungrouped_tasks.group_by { |i| [i[:project_name], i[:experiment_name]] }.map do |group, tasks| - { - project_name: group[0], - project_archived: tasks[0]&.project_archived, - experiment_name: group[1], - experiment_archived: tasks[0]&.experiment_archived, - tasks: tasks - } - end - end - def assign_user(user, assigned_by = nil) user_my_modules.create( assigned_by: assigned_by || user, diff --git a/app/views/shared/_my_modules_list_partial.html.erb b/app/views/shared/_my_modules_list_partial.html.erb index b39049ae9..5edb1447c 100644 --- a/app/views/shared/_my_modules_list_partial.html.erb +++ b/app/views/shared/_my_modules_list_partial.html.erb @@ -5,12 +5,12 @@ <% if task_group[:project_archived]%> <%= t('general.archived') %> <% end %> - <%= escape_input(task_group[:project_name]) %> + <%= task_group[:project_name] %> / <% if task_group[:experiment_archived] %> <%= t('general.archived') %> <% end %> - <%= escape_input(task_group[:experiment_name]) %> + <%= task_group[:experiment_name] %>