From 8ea18c37611ccb86b286761cc373c01199d64878 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 3 Oct 2016 09:58:55 +0100 Subject: [PATCH] Moved todo due date to helper method --- app/helpers/todos_helper.rb | 9 +++++++-- app/views/dashboard/todos/_todo.html.haml | 8 +------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 26d61c32744..9542d3d7941 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -115,9 +115,14 @@ module TodosHelper end def todo_due_date(todo) - is_due_today = todo.target.due_date.try(:today?) + return unless todo.target.try(:due_date) - "Due #{is_due_today ? "today" : todo.target.due_date.to_s(:medium)}" + is_due_today = todo.target.due_date.try(:today?) + is_overdue = todo.target.try(:overdue?) + + content_tag :span, class: [('text-warning' if is_due_today), ('text-danger' if is_overdue)] do + "Due #{is_due_today ? "today" : todo.target.due_date.to_s(:medium)}" + end end private diff --git a/app/views/dashboard/todos/_todo.html.haml b/app/views/dashboard/todos/_todo.html.haml index 45d50f323e1..cc77388563f 100644 --- a/app/views/dashboard/todos/_todo.html.haml +++ b/app/views/dashboard/todos/_todo.html.haml @@ -19,13 +19,7 @@ (removed) · #{time_ago_with_tooltip(todo.created_at)} - - - if todo.target.try(:due_date) - - is_due_today = todo.target.due_date.try(:today?) - - is_overdue = todo.target.try(:overdue?) - · - %span{ class: [('text-warning' if is_due_today), ('text-danger' if is_overdue)] } - = todo_due_date(todo) + · #{todo_due_date(todo)} .todo-body .todo-note