From 3d52e139b13ad077286f2f9f46b7e98f43ad9564 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Sat, 20 Feb 2016 11:59:59 -0200 Subject: Rename Tasks to Todos --- app/helpers/todos_helper.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/helpers/todos_helper.rb (limited to 'app/helpers/todos_helper.rb') diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb new file mode 100644 index 00000000000..7c360468945 --- /dev/null +++ b/app/helpers/todos_helper.rb @@ -0,0 +1,59 @@ +module TodosHelper + def todos_pending_count + current_user.todos.pending.count + end + + def todos_done_count + current_user.todos.done.count + end + + def todo_action_name(todo) + target = todo.target_type.titleize.downcase + + [todo.action_name, target].join(" ") + end + + def todo_target_link_html(todo) + link_to "##{todo.target_iid}", todo_target_path(todo) + end + + def todo_target_path(todo) + anchor = dom_id(todo.note) if todo.note.present? + + polymorphic_path([todo.project.namespace.becomes(Namespace), + todo.project, todo.target], anchor: anchor) + end + + def todo_actions_options + actions = [ + OpenStruct.new(id: '', title: 'Any Action'), + OpenStruct.new(id: Todo::ASSIGNED, title: 'Assigned'), + OpenStruct.new(id: Todo::MENTIONED, title: 'Mentioned') + ] + + options_from_collection_for_select(actions, 'id', 'title', params[:action_id]) + end + + def todo_projects_options + projects = current_user.authorized_projects.sorted_by_activity.non_archived + projects = projects.includes(:namespace) + + projects = projects.map do |project| + OpenStruct.new(id: project.id, title: project.name_with_namespace) + end + + projects.unshift(OpenStruct.new(id: '', title: 'Any Project')) + + options_from_collection_for_select(projects, 'id', 'title', params[:project_id]) + end + + def todo_types_options + types = [ + OpenStruct.new(title: 'Any Type', name: ''), + OpenStruct.new(title: 'Issue', name: 'Issue'), + OpenStruct.new(title: 'Merge Request', name: 'MergeRequest') + ] + + options_from_collection_for_select(types, 'name', 'title', params[:type]) + end +end -- cgit v1.2.1 From 57d16552ff769cc5b41737de803bc2ddc4813f4e Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sat, 20 Feb 2016 11:53:15 -0800 Subject: Include 'issue'/'merge request' in link --- app/helpers/todos_helper.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'app/helpers/todos_helper.rb') diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 7c360468945..cbbfc1e04f5 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -7,14 +7,9 @@ module TodosHelper current_user.todos.done.count end - def todo_action_name(todo) - target = todo.target_type.titleize.downcase - - [todo.action_name, target].join(" ") - end - - def todo_target_link_html(todo) - link_to "##{todo.target_iid}", todo_target_path(todo) + def todo_target_link(todo) + target = todo.target_type.titleize.downcase + link_to "#{target} #{todo.target.to_reference}", todo_target_path(todo) end def todo_target_path(todo) -- cgit v1.2.1 From d53ae7f14d7c24ee590ba57632d267ec01706aa4 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sat, 20 Feb 2016 11:53:25 -0800 Subject: Add "Mark all as done" button --- app/helpers/todos_helper.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'app/helpers/todos_helper.rb') 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'), -- cgit v1.2.1 From 42cbcb23478f7b07c0c49e0020a8d3c834322e87 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sat, 20 Feb 2016 12:01:50 -0800 Subject: "X assigned you Y" instead of "X assigned Y" --- app/helpers/todos_helper.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/helpers/todos_helper.rb') diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 9bcfbd2da35..4b745a5b969 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -7,6 +7,13 @@ module TodosHelper current_user.todos.done.count end + def todo_action_name(todo) + case todo.action + when Todo::ASSIGNED then 'assigned you' + when Todo::MENTIONED then 'mentioned you on' + end + end + def todo_target_link(todo) target = todo.target_type.titleize.downcase link_to "#{target} #{todo.target.to_reference}", todo_target_path(todo) -- cgit v1.2.1