diff --git a/app/assets/javascripts/dashboard/current_tasks.js b/app/assets/javascripts/dashboard/current_tasks.js index 2c7726965..b6f832e0f 100644 --- a/app/assets/javascripts/dashboard/current_tasks.js +++ b/app/assets/javascripts/dashboard/current_tasks.js @@ -7,20 +7,9 @@ var DasboardCurrentTasksWidget = (function() { var projectFilter = '.current-tasks-filters .project-filter'; var experimentFilter = '.current-tasks-filters .experiment-filter'; - function generateTasksListHtml(json, container) { + function appendTasksList(json, container) { $.each(json.data, (i, task) => { - var currentTaskItem = ` -
${task.project}/${task.experiment}
-
${task.name}
-
- - ${task.due_date.text} - -
-
- ${task.status_name} -
-
`; + var currentTaskItem = task; $(container).append(currentTaskItem); }); } @@ -53,7 +42,7 @@ var DasboardCurrentTasksWidget = (function() { InfiniteScroll.init('.current-tasks-list', { url: $('.current-tasks-list').data('tasksListUrl'), customResponse: (json, container) => { - generateTasksListHtml(json, container); + appendTasksList(json, container); }, customParams: (params) => { params.project_id = dropdownSelector.getValues(projectFilter); @@ -143,7 +132,7 @@ var DasboardCurrentTasksWidget = (function() { $currentTasksList.find('.widget-placeholder').addClass($('.current-tasks-navbar .active').data('mode')); } } - generateTasksListHtml(result, $currentTasksList); + appendTasksList(result, $currentTasksList); PerfectSb().update_all(); if (newList) InfiniteScroll.resetScroll('.current-tasks-list'); animateSpinner($currentTasksList, false); diff --git a/app/controllers/dashboard/current_tasks_controller.rb b/app/controllers/dashboard/current_tasks_controller.rb index 808e07dea..b5882a59b 100644 --- a/app/controllers/dashboard/current_tasks_controller.rb +++ b/app/controllers/dashboard/current_tasks_controller.rb @@ -3,6 +3,7 @@ module Dashboard class CurrentTasksController < ApplicationController include InputSanitizeHelper + helper_method :current_task_date before_action :load_project, only: %i(show experiment_filter) before_action :load_experiment, only: :show @@ -47,14 +48,7 @@ module Dashboard .preload(experiment: :project).page(page).per(Constants::INFINITE_SCROLL_LIMIT) tasks_list = tasks.map do |task| - { id: task.id, - link: protocols_my_module_path(task.id), - experiment: escape_input(task.experiment.name), - project: escape_input(task.experiment.project.name), - name: escape_input(task.name), - due_date: prepare_due_date(task), - status_color: task.status_color, - status_name: task.status_name } + render_to_string(partial: 'dashboards/current_tasks/task', locals: { task: task }) end render json: { data: tasks_list, next_page: tasks.next_page } @@ -92,24 +86,27 @@ module Dashboard private - def prepare_due_date(task) - if task.completed? - return { state: '', text: I18n.t('dashboard.current_tasks.completed_on_html', - date: I18n.l(task.completed_on, format: :full_date)) } - end - if task.due_date.present? - due_date_formatted = I18n.l(task.due_date, format: :full_date) - if task.is_overdue? - return { state: 'overdue', text: I18n.t('dashboard.current_tasks.due_date_overdue_html', - date: due_date_formatted) } - elsif task.is_one_day_prior? - return { state: 'day-prior', text: I18n.t('dashboard.current_tasks.due_date_html', - date: due_date_formatted) } - end + def current_task_date(task) + span_class, translation_key, date = nil - return { state: '', text: I18n.t('dashboard.current_tasks.due_date_html', date: due_date_formatted) } + if task.completed? + translation_key = 'completed_on_html' + date = task.completed_on + elsif task.due_date.present? + date = task.due_date + + if task.is_overdue? + span_class = 'overdue' + translation_key = 'due_date_overdue_html' + elsif task.is_one_day_prior? + span_class = 'day-prior' + translation_key = 'due_date_html' + else + span_class = '' + translation_key = 'due_date_html' + end end - { state: nil, text: nil } + { span_class: span_class, translation_key: translation_key, date: date } end def task_filters diff --git a/app/views/dashboards/current_tasks/_task.html.erb b/app/views/dashboards/current_tasks/_task.html.erb new file mode 100644 index 000000000..7c4db6821 --- /dev/null +++ b/app/views/dashboards/current_tasks/_task.html.erb @@ -0,0 +1,17 @@ +<% task_date = current_task_date(task) %> + +
<%= task.experiment.project.name %> + /<%= task.experiment.name %>
+
+ <%= task.name %> +
+
+ <% if task_date[:date] %> + + <%= t("dashboard.current_tasks.#{task_date[:translation_key]}", date: l(task_date[:date], format: :full_date)) %> + <% end %> +
+
+ <%= task.status_name %> +
+