mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-01 02:05:41 +08:00
Move helper method to my_module_helper
This commit is contained in:
parent
8ec7a4b7b4
commit
2728df5bac
5 changed files with 23 additions and 28 deletions
|
@ -3,7 +3,7 @@
|
|||
module Dashboard
|
||||
class CalendarsController < ApplicationController
|
||||
include IconsHelper
|
||||
include MyModulesListPartialHelper
|
||||
include MyModulesHelper
|
||||
|
||||
def show
|
||||
date = DateTime.parse(params[:date])
|
||||
|
@ -27,10 +27,9 @@ module Dashboard
|
|||
.where(projects: { archived: false })
|
||||
.where('DATE(my_modules.due_date) = DATE(?)', date)
|
||||
.where(projects: { team_id: current_team.id })
|
||||
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_grouped
|
||||
my_modules: my_modules
|
||||
})
|
||||
}
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ class RepositoryRowsController < ApplicationController
|
|||
include InputSanitizeHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
include ApplicationHelper
|
||||
include MyModulesListPartialHelper
|
||||
include MyModulesHelper
|
||||
|
||||
before_action :load_info_modal_vars, only: %i(show assigned_task_list)
|
||||
before_action :load_vars, only: %i(edit update)
|
||||
|
@ -184,10 +184,9 @@ 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_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_grouped
|
||||
my_modules: my_modules
|
||||
})
|
||||
}
|
||||
end
|
||||
|
|
|
@ -55,4 +55,22 @@ module MyModulesHelper
|
|||
def is_results_page?
|
||||
action_name == 'results'
|
||||
end
|
||||
|
||||
def grouped_by_prj_exp(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
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
# 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
|
|
@ -1,5 +1,5 @@
|
|||
<div class="my-modules-list-partial">
|
||||
<% task_groups.each do |task_group| %>
|
||||
<% grouped_by_prj_exp(my_modules).each do |task_group| %>
|
||||
<div class="task-group">
|
||||
<div class="header">
|
||||
<% if task_group[:project_archived]%>
|
||||
|
|
Loading…
Reference in a new issue