diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-02-20 11:53:25 -0800 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-02-20 11:59:19 -0800 |
commit | d53ae7f14d7c24ee590ba57632d267ec01706aa4 (patch) | |
tree | 930d407446a93197bfd41e4accd8800c95810a80 | |
parent | 57d16552ff769cc5b41737de803bc2ddc4813f4e (diff) | |
download | gitlab-ce-d53ae7f14d7c24ee590ba57632d267ec01706aa4.tar.gz |
Add "Mark all as done" button
-rw-r--r-- | app/controllers/dashboard/todos_controller.rb | 16 | ||||
-rw-r--r-- | app/helpers/todos_helper.rb | 26 | ||||
-rw-r--r-- | app/views/dashboard/todos/index.html.haml | 12 |
3 files changed, 49 insertions, 5 deletions
diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb index ed11ca5c0eb..4e8ebfb06a0 100644 --- a/app/controllers/dashboard/todos_controller.rb +++ b/app/controllers/dashboard/todos_controller.rb @@ -1,6 +1,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController + before_filter :find_todos, only: [:index, :destroy_all] + def index - @todos = TodosFinder.new(current_user, params).execute @todos = @todos.page(params[:page]).per(PER_PAGE) end @@ -13,9 +14,22 @@ class Dashboard::TodosController < Dashboard::ApplicationController 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 def todo @todo ||= current_user.todos.find(params[:id]) end + + def find_todos + @todos = TodosFinder.new(current_user, params).execute + end end diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index cbbfc1e04f5..9bcfbd2da35 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -19,6 +19,32 @@ module TodosHelper todo.project, todo.target], anchor: anchor) 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 actions = [ OpenStruct.new(id: '', title: 'Any Action'), diff --git a/app/views/dashboard/todos/index.html.haml b/app/views/dashboard/todos/index.html.haml index 8340c799c53..946d7df3933 100644 --- a/app/views/dashboard/todos/index.html.haml +++ b/app/views/dashboard/todos/index.html.haml @@ -4,21 +4,25 @@ .top-area %ul.nav-links %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 To do %span{class: 'badge'} = todos_pending_count %li{class: ('active' if params[:state] == 'done')} - = link_to page_filter_path(state: 'done') do + = link_to todos_filter_path(state: 'done') do %span Done %span{class: 'badge'} = 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 .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 = select_tag('project_id', todo_projects_options, class: 'select2 trigger-submit', include_blank: true, @@ -47,7 +51,7 @@ = render group[1] = paginate @todos, theme: "gitlab" - else - .nothing-here-block No todos to show + .nothing-here-block You're all done! :javascript new UsersSelect(); |