mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-31 04:32:06 +08:00
Merge pull request #2438 from okriuchykhin/ok_SCI_4356
Improve loading of tasks statistics for dashboard [SCI-4356]
This commit is contained in:
commit
409c4b7f65
3 changed files with 22 additions and 35 deletions
|
@ -22,7 +22,7 @@ var DasboardCurrentTasksWidget = (function() {
|
|||
mode: $('.current-tasks-navbar .active').data('mode')
|
||||
};
|
||||
animateSpinner($currentTasksList, true);
|
||||
$.get($currentTasksList.attr('data-tasks-list-url'), params, function(data) {
|
||||
$.get($currentTasksList.data('tasksListUrl'), params, function(data) {
|
||||
// Toggle empty state
|
||||
if (data.tasks_list.length === 0) {
|
||||
$currentTasksList.append(emptyState);
|
||||
|
@ -143,7 +143,9 @@ var DasboardCurrentTasksWidget = (function() {
|
|||
}
|
||||
|
||||
function initNavbar() {
|
||||
$('.navbar-assigned, .navbar-all').on('click', function() {
|
||||
$('.navbar-assigned, .navbar-all').on('click', function(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
$('.current-tasks-navbar').find('a').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
loadCurrentTasksList();
|
||||
|
|
|
@ -34,20 +34,23 @@ module Dashboard
|
|||
tasks
|
||||
end
|
||||
|
||||
tasks = tasks.with_step_statistics.preload(experiment: :project)
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
tasks_list: tasks.map do |task|
|
||||
due_date = I18n.l(task.due_date, format: :full_with_comma) if task.due_date.present?
|
||||
{ id: task.id,
|
||||
link: protocols_my_module_path(task.id),
|
||||
experiment: task.experiment.name,
|
||||
project: task.experiment.project.name,
|
||||
experiment: escape_input(task.experiment.name),
|
||||
project: escape_input(task.experiment.project.name),
|
||||
name: escape_input(task.name),
|
||||
due_date: due_date,
|
||||
due_date: task.due_date.present? ? I18n.l(task.due_date, format: :full_with_comma) : nil,
|
||||
overdue: task.is_overdue?,
|
||||
state: task.state,
|
||||
steps_state: task.completed_steps_percentage }
|
||||
steps_state: { completed_steps: task.steps_completed,
|
||||
all_steps: task.steps_total,
|
||||
percentage: task.steps_completed_percentage } }
|
||||
end,
|
||||
status: :ok
|
||||
}
|
||||
|
@ -80,9 +83,7 @@ module Dashboard
|
|||
private
|
||||
|
||||
def task_filters
|
||||
params.permit(
|
||||
:project_id, :experiment_id, :mode, :view, :sort
|
||||
)
|
||||
params.permit(:project_id, :experiment_id, :mode, :view, :sort)
|
||||
end
|
||||
|
||||
def load_project
|
||||
|
|
|
@ -80,6 +80,15 @@ class MyModule < ApplicationRecord
|
|||
end)
|
||||
scope :workflow_ordered, -> { order(workflow_order: :asc) }
|
||||
scope :uncomplete, -> { where(state: 'uncompleted') }
|
||||
scope :with_step_statistics, (lambda do
|
||||
joins(protocols: :steps)
|
||||
.group(:id)
|
||||
.select('my_modules.*')
|
||||
.select('COUNT(steps.id) AS steps_total')
|
||||
.select('COUNT(steps.id) FILTER (where steps.completed = true) AS steps_completed')
|
||||
.select('((COUNT(steps.id) FILTER (where steps.completed = true)) * 100 / COUNT(steps.id)) '\
|
||||
'AS steps_completed_percentage')
|
||||
end)
|
||||
|
||||
# A module takes this much space in canvas (x, y) in database
|
||||
WIDTH = 30
|
||||
|
@ -492,31 +501,6 @@ class MyModule < ApplicationRecord
|
|||
state == 'completed'
|
||||
end
|
||||
|
||||
def completed_steps_percentage
|
||||
if protocol.steps.any?
|
||||
steps_percentage =
|
||||
MyModule.joins(protocols: :steps)
|
||||
.where(id: id)
|
||||
.group(:id)
|
||||
.select('my_modules.*')
|
||||
.select('COUNT(steps.id) AS all')
|
||||
.select('COUNT(steps.id) FILTER (where steps.completed = true) AS completed')
|
||||
.select('((COUNT(steps.id) FILTER (where steps.completed = true)) * 100 / COUNT(steps.id)) AS percentage')
|
||||
.take
|
||||
{
|
||||
completed_steps: steps_percentage.completed,
|
||||
all_steps: steps_percentage.all,
|
||||
percentage: steps_percentage.percentage
|
||||
}
|
||||
else
|
||||
{
|
||||
completed_steps: 0,
|
||||
all_steps: 0,
|
||||
percentage: 0
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Check if my_module is ready to become completed
|
||||
def check_completness_status
|
||||
if protocol && protocol.steps.count > 0
|
||||
|
|
Loading…
Reference in a new issue