From 58013e215dc8d6e07c478b6dcea1c7796cc6033e Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Thu, 22 Oct 2020 08:02:15 +0200 Subject: [PATCH 1/2] Add lock icon to current task section on dashboard --- .../javascripts/dashboard/current_tasks.js | 19 ++++--------------- .../dashboard/current_tasks_controller.rb | 18 ++++++------------ .../dashboards/current_tasks/_task.html.erb | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 app/views/dashboards/current_tasks/_task.html.erb diff --git a/app/assets/javascripts/dashboard/current_tasks.js b/app/assets/javascripts/dashboard/current_tasks.js index 7c2f1aea9..f75a7a057 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); }); } @@ -42,7 +31,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); @@ -130,7 +119,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..854dac270 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 :prepare_due_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 } @@ -95,19 +89,19 @@ module Dashboard 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)) } + date: I18n.l(task.completed_on, format: :full_date)).html_safe } 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) } + date: due_date_formatted).html_safe } elsif task.is_one_day_prior? return { state: 'day-prior', text: I18n.t('dashboard.current_tasks.due_date_html', - date: due_date_formatted) } + date: due_date_formatted).html_safe } end - return { state: '', text: I18n.t('dashboard.current_tasks.due_date_html', date: due_date_formatted) } + return { state: '', text: I18n.t('dashboard.current_tasks.due_date_html', date: due_date_formatted).html_safe } end { state: nil, text: nil } end 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..392afb1c1 --- /dev/null +++ b/app/views/dashboards/current_tasks/_task.html.erb @@ -0,0 +1,15 @@ + +
<%= task.experiment.project.name %> + /<%= task.experiment.name %>
+
+ <%= task.name %> +
+
+ + <%= prepare_due_date(task)[:text] %> + +
+
+ <%= task.status_name %> +
+
From 431b9161b6fe9d185be026df9d00cc0e81664d04 Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Mon, 26 Oct 2020 11:03:43 +0100 Subject: [PATCH 2/2] Code cleanup --- .../dashboard/current_tasks_controller.rb | 37 ++++++++++--------- .../dashboards/current_tasks/_task.html.erb | 10 +++-- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/controllers/dashboard/current_tasks_controller.rb b/app/controllers/dashboard/current_tasks_controller.rb index 854dac270..b5882a59b 100644 --- a/app/controllers/dashboard/current_tasks_controller.rb +++ b/app/controllers/dashboard/current_tasks_controller.rb @@ -3,7 +3,7 @@ module Dashboard class CurrentTasksController < ApplicationController include InputSanitizeHelper - helper_method :prepare_due_date + helper_method :current_task_date before_action :load_project, only: %i(show experiment_filter) before_action :load_experiment, only: :show @@ -86,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)).html_safe } - 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).html_safe } - elsif task.is_one_day_prior? - return { state: 'day-prior', text: I18n.t('dashboard.current_tasks.due_date_html', - date: due_date_formatted).html_safe } - 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).html_safe } + 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 index 392afb1c1..7c4db6821 100644 --- a/app/views/dashboards/current_tasks/_task.html.erb +++ b/app/views/dashboards/current_tasks/_task.html.erb @@ -1,13 +1,15 @@ +<% task_date = current_task_date(task) %>
<%= task.experiment.project.name %> /<%= task.experiment.name %>
<%= task.name %>
-
- - <%= prepare_due_date(task)[:text] %> - +
+ <% if task_date[:date] %> + + <%= t("dashboard.current_tasks.#{task_date[:translation_key]}", date: l(task_date[:date], format: :full_date)) %> + <% end %>
<%= task.status_name %>