mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-29 03:01:58 +08:00
Create helper for partial
This commit is contained in:
parent
b01ff206e8
commit
8076d8f464
6 changed files with 38 additions and 30 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
21
app/helpers/my_modules_list_partial_helper.rb
Normal file
21
app/helpers/my_modules_list_partial_helper.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
<% if task_group[:project_archived]%>
|
||||
<span class="archived"><%= t('general.archived') %></span>
|
||||
<% end %>
|
||||
<span class="project" title="<%= task_group[:project_name] %>"><%= escape_input(task_group[:project_name]) %></span>
|
||||
<span class="project" title="<%= task_group[:project_name] %>"><%= task_group[:project_name] %></span>
|
||||
<span class="slash">/</span>
|
||||
<% if task_group[:experiment_archived] %>
|
||||
<span class="archived"><%= t('general.archived') %></span>
|
||||
<% end %>
|
||||
<span class="experiment" title="<%= task_group[:experiment_name] %>"><%= escape_input(task_group[:experiment_name]) %></span>
|
||||
<span class="experiment" title="<%= task_group[:experiment_name] %>"><%= task_group[:experiment_name] %></span>
|
||||
</div>
|
||||
<div class="tasks">
|
||||
<% task_group[:tasks].each do |task| %>
|
||||
|
@ -20,9 +20,9 @@
|
|||
<span class="archived"><%= t('general.archived') %></span>
|
||||
<% end %>
|
||||
<% if can_read_experiment?(current_user, task.experiment) %>
|
||||
<%= link_to(escape_input(task.name), protocols_my_module_path(task.id), {class: "task-link", title: escape_input(task.name), target: "_blank"}) %>
|
||||
<%= link_to(task.name, protocols_my_module_path(task.id), {class: "task-link", title: task.name, target: "_blank"}) %>
|
||||
<% else %>
|
||||
<%= escape_input(task.name) %>
|
||||
<%= task.name %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue