Skip to content

Commit

Permalink
Merge branch 'tasks/my-tasks' of https://github.com/dradis/dradis-ce
Browse files Browse the repository at this point in the history
…into tasks/my-tasks
  • Loading branch information
nicolachr committed Aug 14, 2024
2 parents 5258657 + 8ab41fd commit e1581c6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 51 deletions.
5 changes: 3 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def show
@nodes = current_project.nodes.in_tree
@tags = current_project.tags

# Arel.sql('-due_date desc') sorts the records by due_date with null due_date records last
@tasks = grouped_tasks(current_user.cards.order(Arel.sql('-due_date desc')))
# Using Arel.sql to sort the records by due_date with null due_date records last
@tasks = current_user.cards.order(Arel.sql('due_date IS NULL, due_date ASC'))
@tasks_limit = 5

@count_by_tag = { unassigned: 0 }
@issues_by_tag = Hash.new { |h, k| h[k] = [] }
Expand Down
24 changes: 10 additions & 14 deletions app/helpers/tasks_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@ def due_date_badge(task)
end
end

def grouped_tasks(tasks)
tasks.group_by do |task|
case task.due_date
when nil
:no_due_date
when ->(date) { date < Date.today }
:overdue
when Date.today
:today
when Date.tomorrow
:tomorrow
else
:future
end
def widget_task_class(task)
return unless task.due_date

case task.due_date
when Date.today
'due-today'
when Date.tomorrow
'due-tomorrow'
else
task.due_date < Date.today ? 'due-overdue' : 'due-future'
end
end

Expand Down
39 changes: 10 additions & 29 deletions app/views/projects/tasks/_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,21 @@
</div>
</span>
</h4>
<% if @tasks[:today]&.any? %>
<h5 class="mb-2 mt-4">Due today</h5>
<% if @tasks.any? %>
<ul class="list-group tasks">
<% @tasks[:today][0...tasks_widget_limit].each do |task| %>
<%= render partial: 'projects/tasks/task', locals: { task: task, task_class: 'due-today' } %>
<% @tasks.first(@tasks_limit).each do |task| %>
<li class="list-group-item">
<%= link_to project_board_list_card_path(current_project, task.board, task.list, task), class: "list-group-item-action #{widget_task_class(task)}" do %>
<span class="text-truncate" title="<%= task.name%>"><%= task.name %></span>
<% end %>
<span class="badge bg-primary"><%= task.board.name %></span>
</li>
<% end %>
</ul>

<p class="small mt-2 mb-0 text-center">&nbsp;
<% if @tasks[:today].size > tasks_widget_limit %>
+ <%= @tasks[:today].size - tasks_widget_limit %> more
<% end %>
</p>
<% end %>
<% if @tasks[:tomorrow]&.any? || @tasks[:future]&.any?%>
<h5 class="mb-2">Next</h5>
<ul class="list-group tasks future-tasks">
<% if @tasks[:tomorrow]&.any? %>
<% (@tasks[:tomorrow][0...tasks_widget_limit]).each do |task| %>
<%= render partial: 'projects/tasks/task', locals: { task: task, task_class: 'due-tomorrow' } %>
<% end %>
<% end %>
<% if @tasks[:tomorrow].blank? || @tasks[:tomorrow]&.size <= tasks_widget_limit %>
<% (@tasks[:future][0...(tasks_widget_limit - @tasks[:tomorrow]&.size || 0)] || []).each do |task| %>
<%= render partial: 'projects/tasks/task', locals: { task: task, task_class: 'due-future' } %>
<% end %>
<% end %>
</ul>

<p class="small mt-2 mb-0 text-center">&nbsp;
<% if ((@tasks[:tomorrow]&.size || 0) + (@tasks[:future]&.size || 0)) > tasks_widget_limit %>
+ <%= (@tasks[:tomorrow]&.size + @tasks[:future]&.size) - tasks_widget_limit %> more
<% if @tasks.size > @tasks_limit %>
+ <%= @tasks.size - @tasks_limit %> more
<% end %>
</p>
<% end %>
Expand Down
6 changes: 0 additions & 6 deletions app/views/projects/tasks/_task.html.erb

This file was deleted.

0 comments on commit e1581c6

Please sign in to comment.