Commit d53ae7f1 authored by Douwe Maan's avatar Douwe Maan

Add "Mark all as done" button

parent 57d16552
class Dashboard::TodosController < Dashboard::ApplicationController class Dashboard::TodosController < Dashboard::ApplicationController
before_filter :find_todos, only: [:index, :destroy_all]
def index def index
@todos = TodosFinder.new(current_user, params).execute
@todos = @todos.page(params[:page]).per(PER_PAGE) @todos = @todos.page(params[:page]).per(PER_PAGE)
end end
...@@ -13,9 +14,22 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -13,9 +14,22 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end end
end end
def destroy_all
@todos.each(&:done)
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
format.js { render nothing: true }
end
end
private private
def todo def todo
@todo ||= current_user.todos.find(params[:id]) @todo ||= current_user.todos.find(params[:id])
end end
def find_todos
@todos = TodosFinder.new(current_user, params).execute
end
end end
...@@ -19,6 +19,32 @@ module TodosHelper ...@@ -19,6 +19,32 @@ module TodosHelper
todo.project, todo.target], anchor: anchor) todo.project, todo.target], anchor: anchor)
end end
def todos_filter_params
{
state: params[:state],
project_id: params[:project_id],
author_id: params[:author_id],
type: params[:type],
action_id: params[:action_id],
}
end
def todos_filter_path(options = {})
without = options.delete(:without)
options = todos_filter_params.merge(options)
if without.present?
without.each do |key|
options.delete(key)
end
end
path = request.path
path << "?#{options.to_param}"
path
end
def todo_actions_options def todo_actions_options
actions = [ actions = [
OpenStruct.new(id: '', title: 'Any Action'), OpenStruct.new(id: '', title: 'Any Action'),
......
...@@ -4,21 +4,25 @@ ...@@ -4,21 +4,25 @@
.top-area .top-area
%ul.nav-links %ul.nav-links
%li{class: ('active' if params[:state].blank? || params[:state] == 'pending')} %li{class: ('active' if params[:state].blank? || params[:state] == 'pending')}
= link_to page_filter_path(state: 'pending') do = link_to todos_filter_path(state: 'pending') do
%span %span
To do To do
%span{class: 'badge'} %span{class: 'badge'}
= todos_pending_count = todos_pending_count
%li{class: ('active' if params[:state] == 'done')} %li{class: ('active' if params[:state] == 'done')}
= link_to page_filter_path(state: 'done') do = link_to todos_filter_path(state: 'done') do
%span %span
Done Done
%span{class: 'badge'} %span{class: 'badge'}
= todos_done_count = todos_done_count
.nav-controls
- if @todos.any?(&:pending?)
= link_to 'Mark all as done', destroy_all_dashboard_todos_path(todos_filter_params), class: 'btn', method: :delete
.todos-filters .todos-filters
.gray-content-block.second-block .gray-content-block.second-block
= form_tag page_filter_path(without: [:assignee_id, :milestone_title, :label_name, :scope, :sort]), method: :get, class: 'filter-form' do = form_tag todos_filter_path(without: [:project_id, :author_id, :type, :action_id]), method: :get, class: 'filter-form' do
.filter-item.inline .filter-item.inline
= select_tag('project_id', todo_projects_options, = select_tag('project_id', todo_projects_options,
class: 'select2 trigger-submit', include_blank: true, class: 'select2 trigger-submit', include_blank: true,
...@@ -47,7 +51,7 @@ ...@@ -47,7 +51,7 @@
= render group[1] = render group[1]
= paginate @todos, theme: "gitlab" = paginate @todos, theme: "gitlab"
- else - else
.nothing-here-block No todos to show .nothing-here-block You're all done!
:javascript :javascript
new UsersSelect(); new UsersSelect();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment