From beff8b9bd077fea4bbcb09881396b57ba07f568e Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Sat, 27 Aug 2016 23:45:01 +0100 Subject: Swapped out author dropdown and started on swapping out project dropdown --- app/assets/javascripts/gl_dropdown.js | 1 + app/helpers/issuables_helper.rb | 13 ++++++++++++ app/helpers/todos_helper.rb | 26 ++++++++++-------------- app/views/dashboard/todos/index.html.haml | 33 ++++++++++++++++++++----------- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/gl_dropdown.js b/app/assets/javascripts/gl_dropdown.js index 77b2082cba0..ba59ce3c956 100644 --- a/app/assets/javascripts/gl_dropdown.js +++ b/app/assets/javascripts/gl_dropdown.js @@ -202,6 +202,7 @@ var ref, ref1, ref2, ref3, searchFields, selector, self; this.el = el1; this.options = options; + console.log(this.options); this.updateLabel = bind(this.updateLabel, this); this.hidden = bind(this.hidden, this); this.opened = bind(this.opened, this); diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index b9baeb1d6c4..dcf2ef6bb0a 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -49,6 +49,19 @@ module IssuablesHelper end end + def project_dropdown_label(project_id, default_label) + return default_label if project_id.nil? + return "Any project" if project_id == "0" + + project = Project.find_by(id: project_id) + + if project + project.name_with_namespace || project.name + else + default_label + end + end + def milestone_dropdown_label(milestone_title, default_label = "Milestone") if milestone_title == Milestone::Upcoming.name milestone_title = Milestone::Upcoming.title diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 0465327060e..a9f4c8b07b5 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -78,13 +78,11 @@ module TodosHelper 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') + [ + { id: '', text: 'Any Action' }, + { id: Todo::ASSIGNED, text: 'Assigned' }, + { id: Todo::MENTIONED, text: 'Mentioned' } ] - - options_from_collection_for_select(actions, 'id', 'title', params[:action_id]) end def todo_projects_options @@ -92,22 +90,18 @@ module TodosHelper projects = projects.includes(:namespace) projects = projects.map do |project| - OpenStruct.new(id: project.id, title: project.name_with_namespace) + { id: project.id, text: project.name_with_namespace } end - projects.unshift(OpenStruct.new(id: '', title: 'Any Project')) - - options_from_collection_for_select(projects, 'id', 'title', params[:project_id]) + projects.unshift({ id: '', text: 'Any Project' }).to_json 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') + [ + { text: 'Any Type', id: '' }, + { text: 'Issue', id: 'Issue' }, + { text: 'Merge Request', id: 'MergeRequest' } ] - - options_from_collection_for_select(types, 'name', 'title', params[:type]) end private diff --git a/app/views/dashboard/todos/index.html.haml b/app/views/dashboard/todos/index.html.haml index 6bcc37042ea..42dc1fd0118 100644 --- a/app/views/dashboard/todos/index.html.haml +++ b/app/views/dashboard/todos/index.html.haml @@ -28,20 +28,23 @@ .row-content-block.second-block = 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, - data: {placeholder: 'Project'}) + - if params[:project_id].present? + = hidden_field_tag(:project_id, params[:project_id]) + = dropdown_tag(project_dropdown_label(params[:project_id], 'Project'), options: { toggle_class: 'js-project-search js-filter-submit', title: 'Filter by project', filter: true, filterInput: 'input#search', dropdown_class: 'dropdown-menu-selectable dropdown-menu-project js-filter-submit', + placeholder: 'Search projects', data: { data: todo_projects_options, selected: params[:project_id], field_name: 'project_id', default_label: 'Project' } }) .filter-item.inline - = users_select_tag(:author_id, selected: params[:author_id], - placeholder: 'Author', class: 'trigger-submit', any_user: "Any Author", first_user: true, current_user: true) + - if params[:author_id].present? + = hidden_field_tag(:author_id, params[:author_id]) + = dropdown_tag(user_dropdown_label(params[:author_id], 'Author'), options: { toggle_class: 'js-user-search js-filter-submit js-author-search', title: 'Filter by author', filter: true, filterInput: 'input#search', dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit', + placeholder: 'Search authors', data: { any_user: 'Any Author', first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), selected: params[:author_id], field_name: 'author_id', default_label: 'Author' } }) .filter-item.inline - = select_tag('type', todo_types_options, - class: 'select2 trigger-submit', include_blank: true, - data: {placeholder: 'Type'}) + -# = select_tag('type', todo_types_options, + -# class: 'select2 trigger-submit', include_blank: true, + -# data: {placeholder: 'Type'}) .filter-item.inline.actions-filter - = select_tag('action_id', todo_actions_options, - class: 'select2 trigger-submit', include_blank: true, - data: {placeholder: 'Action'}) + -# = select_tag('action_id', todo_actions_options, + -# class: 'select2 trigger-submit', include_blank: true, + -# data: {placeholder: 'Action'}) .pull-right .dropdown.inline.prepend-left-10 @@ -80,6 +83,14 @@ :javascript new UsersSelect(); + $projectDropdown = $('.js-project-search'); + $projectDropdown.glDropdown({ + filterable: true, + selectable: true, + fieldName: 'project_id', + data: $projectDropdown.data('data') + }); + $('form.filter-form').on('submit', function (event) { event.preventDefault(); Turbolinks.visit(this.action + '&' + $(this).serialize()); -- cgit v1.2.1 From 0e2dd06f259a42e360cb73a9f17de46cc0ab31fd Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Sun, 28 Aug 2016 00:09:21 +0100 Subject: Completed project filter dropdown, still need to move it from inline to ProjectSelect.js (or different) --- app/assets/javascripts/gl_dropdown.js | 1 - app/helpers/issuables_helper.rb | 2 +- app/views/dashboard/todos/index.html.haml | 8 +++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/gl_dropdown.js b/app/assets/javascripts/gl_dropdown.js index ba59ce3c956..77b2082cba0 100644 --- a/app/assets/javascripts/gl_dropdown.js +++ b/app/assets/javascripts/gl_dropdown.js @@ -202,7 +202,6 @@ var ref, ref1, ref2, ref3, searchFields, selector, self; this.el = el1; this.options = options; - console.log(this.options); this.updateLabel = bind(this.updateLabel, this); this.hidden = bind(this.hidden, this); this.opened = bind(this.opened, this); diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index dcf2ef6bb0a..5c04bba323f 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -56,7 +56,7 @@ module IssuablesHelper project = Project.find_by(id: project_id) if project - project.name_with_namespace || project.name + project.name_with_namespace else default_label end diff --git a/app/views/dashboard/todos/index.html.haml b/app/views/dashboard/todos/index.html.haml index 42dc1fd0118..ffdb88975a5 100644 --- a/app/views/dashboard/todos/index.html.haml +++ b/app/views/dashboard/todos/index.html.haml @@ -88,7 +88,13 @@ filterable: true, selectable: true, fieldName: 'project_id', - data: $projectDropdown.data('data') + data: $projectDropdown.data('data'), + clicked: function() { + if ($projectDropdown.hasClass('js-filter-submit')) { + console.log('booM!'); + return $projectDropdown.closest('form').submit(); + } + } }); $('form.filter-form').on('submit', function (event) { -- cgit v1.2.1 From f157a9e5144fde90dc31add4006b9132e1489aa1 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Sun, 28 Aug 2016 00:18:48 +0100 Subject: Added type and action dropdowns, need to finalize by removing all inline and polishing off the selected dropdown states --- app/views/dashboard/todos/index.html.haml | 40 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/app/views/dashboard/todos/index.html.haml b/app/views/dashboard/todos/index.html.haml index ffdb88975a5..4a8536315a5 100644 --- a/app/views/dashboard/todos/index.html.haml +++ b/app/views/dashboard/todos/index.html.haml @@ -38,14 +38,15 @@ = dropdown_tag(user_dropdown_label(params[:author_id], 'Author'), options: { toggle_class: 'js-user-search js-filter-submit js-author-search', title: 'Filter by author', filter: true, filterInput: 'input#search', dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit', placeholder: 'Search authors', data: { any_user: 'Any Author', first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), selected: params[:author_id], field_name: 'author_id', default_label: 'Author' } }) .filter-item.inline - -# = select_tag('type', todo_types_options, - -# class: 'select2 trigger-submit', include_blank: true, - -# data: {placeholder: 'Type'}) + - if params[:type].present? + = hidden_field_tag(:type, params[:type]) + = dropdown_tag(params[:type] || 'Type', options: { toggle_class: 'js-type-search js-filter-submit', dropdown_class: 'dropdown-menu-selectable dropdown-menu-type js-filter-submit', + data: { data: todo_types_options, selected: params[:type], field_name: 'type', default_label: 'Type' } }) .filter-item.inline.actions-filter - -# = select_tag('action_id', todo_actions_options, - -# class: 'select2 trigger-submit', include_blank: true, - -# data: {placeholder: 'Action'}) - + - if params[:action_id].present? + = hidden_field_tag(:action_id, params[:action_id]) + = dropdown_tag(params[:action_id] || 'Action', options: { toggle_class: 'js-action-search js-filter-submit', dropdown_class: 'dropdown-menu-selectable dropdown-menu-action js-filter-submit', + data: { data: todo_actions_options, selected: params[:action_id], field_name: 'action_id', default_label: 'Action' } }) .pull-right .dropdown.inline.prepend-left-10 %button.dropdown-toggle.btn{type: 'button', 'data-toggle' => 'dropdown'} @@ -91,12 +92,35 @@ data: $projectDropdown.data('data'), clicked: function() { if ($projectDropdown.hasClass('js-filter-submit')) { - console.log('booM!'); return $projectDropdown.closest('form').submit(); } } }); + $typeDropdown = $('.js-type-search'); + $typeDropdown.glDropdown({ + selectable: true, + fieldName: 'type_id', + data: $typeDropdown.data('data'), + clicked: function() { + if ($typeDropdown.hasClass('js-filter-submit')) { + return $typeDropdown.closest('form').submit(); + } + } + }); + + $actionDropdown = $('.js-action-search'); + $actionDropdown.glDropdown({ + selectable: true, + fieldName: 'action_id', + data: $actionDropdown.data('data'), + clicked: function() { + if ($actionDropdown.hasClass('js-filter-submit')) { + return $actionDropdown.closest('form').submit(); + } + } + }); + $('form.filter-form').on('submit', function (event) { event.preventDefault(); Turbolinks.visit(this.action + '&' + $(this).serialize()); -- cgit v1.2.1 From 922b38a0bea8c5b8610120dfb5ea168db713f3e3 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Sun, 28 Aug 2016 16:24:48 +0100 Subject: Removed inline JS and improved dropdown labels --- app/assets/javascripts/todos.js | 56 +++++++++++++++++++++++++++++++ app/helpers/todos_helper.rb | 16 +++++++-- app/views/dashboard/todos/index.html.haml | 53 +++-------------------------- 3 files changed, 73 insertions(+), 52 deletions(-) diff --git a/app/assets/javascripts/todos.js b/app/assets/javascripts/todos.js index 06605320a35..ef1eadfb9c0 100644 --- a/app/assets/javascripts/todos.js +++ b/app/assets/javascripts/todos.js @@ -13,6 +13,7 @@ this.perPage = this.el.data('perPage'); this.clearListeners(); this.initBtnListeners(); + this.initFilters(); } Todos.prototype.clearListeners = function() { @@ -27,6 +28,61 @@ return $('.todo').on('click', this.goToTodoUrl); }; + Todos.prototype.initFilters = function() { + new UsersSelect(); + this.initProjectFilterDropdown(); + this.initTypeFilterDropdown(); + this.initActionFilterDropdown(); + + $('form.filter-form').on('submit', function (event) { + event.preventDefault(); + Turbolinks.visit(this.action + '&' + $(this).serialize()); + }); + }; + + Todos.prototype.initProjectFilterDropdown = function() { + $projectDropdown = $('.js-project-search'); + $projectDropdown.glDropdown({ + filterable: true, + selectable: true, + fieldName: 'project_id', + data: $projectDropdown.data('data'), + clicked: function() { + if ($projectDropdown.hasClass('js-filter-submit')) { + return $projectDropdown.closest('form.filter-form').submit(); + } + } + }); + }; + + Todos.prototype.initTypeFilterDropdown = function() { + $typeDropdown = $('.js-type-search'); + $typeDropdown.glDropdown({ + selectable: true, + fieldName: 'type', + data: $typeDropdown.data('data'), + clicked: function() { + if ($typeDropdown.hasClass('js-filter-submit')) { + return $typeDropdown.closest('form.filter-form').submit(); + } + } + }); + }; + + Todos.prototype.initActionFilterDropdown = function() { + $actionDropdown = $('.js-action-search'); + $actionDropdown.glDropdown({ + selectable: true, + fieldName: 'action_id', + data: $actionDropdown.data('data'), + clicked: function() { + if ($actionDropdown.hasClass('js-filter-submit')) { + return $actionDropdown.closest('form.filter-form').submit(); + } + } + }); + }; + Todos.prototype.doneClicked = function(e) { var $this; e.preventDefault(); diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index a9f4c8b07b5..1e86f648203 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -98,12 +98,22 @@ module TodosHelper def todo_types_options [ - { text: 'Any Type', id: '' }, - { text: 'Issue', id: 'Issue' }, - { text: 'Merge Request', id: 'MergeRequest' } + { id: '', text: 'Any Type' }, + { id: 'Issue', text: 'Issue' }, + { id: 'MergeRequest', text: 'Merge Request' } ] end + def todo_actions_dropdown_label(selected_action_id, default_action) + selected_action = todo_actions_options.find { |action| action[:id] == selected_action_id.to_i} + selected_action ? selected_action[:text] : default_action + end + + def todo_types_dropdown_label(selected_type, default_type) + selected_type = todo_types_options.find { |type| type[:id] == selected_type && type[:id] != '' } + selected_type ? selected_type[:text] : default_type + end + private def show_todo_state?(todo) diff --git a/app/views/dashboard/todos/index.html.haml b/app/views/dashboard/todos/index.html.haml index 4a8536315a5..70dd4db6aaf 100644 --- a/app/views/dashboard/todos/index.html.haml +++ b/app/views/dashboard/todos/index.html.haml @@ -40,13 +40,13 @@ .filter-item.inline - if params[:type].present? = hidden_field_tag(:type, params[:type]) - = dropdown_tag(params[:type] || 'Type', options: { toggle_class: 'js-type-search js-filter-submit', dropdown_class: 'dropdown-menu-selectable dropdown-menu-type js-filter-submit', - data: { data: todo_types_options, selected: params[:type], field_name: 'type', default_label: 'Type' } }) + = dropdown_tag(todo_types_dropdown_label(params[:type], 'Type'), options: { toggle_class: 'js-type-search js-filter-submit', dropdown_class: 'dropdown-menu-selectable dropdown-menu-type js-filter-submit', + data: { data: todo_types_options } }) .filter-item.inline.actions-filter - if params[:action_id].present? = hidden_field_tag(:action_id, params[:action_id]) - = dropdown_tag(params[:action_id] || 'Action', options: { toggle_class: 'js-action-search js-filter-submit', dropdown_class: 'dropdown-menu-selectable dropdown-menu-action js-filter-submit', - data: { data: todo_actions_options, selected: params[:action_id], field_name: 'action_id', default_label: 'Action' } }) + = dropdown_tag(todo_actions_dropdown_label(params[:action_id], 'Action'), options: { toggle_class: 'js-action-search js-filter-submit', dropdown_class: 'dropdown-menu-selectable dropdown-menu-action js-filter-submit', + data: { data: todo_actions_options }}) .pull-right .dropdown.inline.prepend-left-10 %button.dropdown-toggle.btn{type: 'button', 'data-toggle' => 'dropdown'} @@ -80,48 +80,3 @@ = paginate @todos, theme: "gitlab" - else .nothing-here-block You're all done! - -:javascript - new UsersSelect(); - - $projectDropdown = $('.js-project-search'); - $projectDropdown.glDropdown({ - filterable: true, - selectable: true, - fieldName: 'project_id', - data: $projectDropdown.data('data'), - clicked: function() { - if ($projectDropdown.hasClass('js-filter-submit')) { - return $projectDropdown.closest('form').submit(); - } - } - }); - - $typeDropdown = $('.js-type-search'); - $typeDropdown.glDropdown({ - selectable: true, - fieldName: 'type_id', - data: $typeDropdown.data('data'), - clicked: function() { - if ($typeDropdown.hasClass('js-filter-submit')) { - return $typeDropdown.closest('form').submit(); - } - } - }); - - $actionDropdown = $('.js-action-search'); - $actionDropdown.glDropdown({ - selectable: true, - fieldName: 'action_id', - data: $actionDropdown.data('data'), - clicked: function() { - if ($actionDropdown.hasClass('js-filter-submit')) { - return $actionDropdown.closest('form').submit(); - } - } - }); - - $('form.filter-form').on('submit', function (event) { - event.preventDefault(); - Turbolinks.visit(this.action + '&' + $(this).serialize()); - }); -- cgit v1.2.1 From bd595eb82cd239c123818be9144258fdbaaae79c Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Sun, 28 Aug 2016 17:46:01 +0100 Subject: Removed select2 from todos feature spec --- features/steps/dashboard/todos.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/features/steps/dashboard/todos.rb b/features/steps/dashboard/todos.rb index 0607086c166..344b6fda9a6 100644 --- a/features/steps/dashboard/todos.rb +++ b/features/steps/dashboard/todos.rb @@ -3,7 +3,6 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps include SharedPaths include SharedProject include SharedUser - include Select2Helper step '"John Doe" is a developer of project "Shop"' do project.team << [john_doe, :developer] @@ -55,7 +54,7 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps expect(page).to have_content 'To do 0' expect(page).to have_content 'Done 4' expect(page).to have_content "You're all done!" - expect(page).not_to have_link project.name_with_namespace + expect('.prepend-top-default').not_to have_link project.name_with_namespace should_not_see_todo "John Doe assigned you merge request #{merge_request.to_reference}" should_not_see_todo "John Doe mentioned you on issue #{issue.to_reference}" should_not_see_todo "John Doe assigned you issue #{issue.to_reference}" @@ -80,19 +79,31 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps end step 'I filter by "Enterprise"' do - select2(enterprise.id, from: "#project_id") + click_button 'Project' + page.within '.dropdown-menu-project' do + click_link enterprise.name_with_namespace + end end step 'I filter by "John Doe"' do - select2(john_doe.id, from: "#author_id") + click_button 'Author' + page.within '.dropdown-menu-author' do + click_link john_doe.username + end end step 'I filter by "Issue"' do - select2('Issue', from: "#type") + click_button 'Type' + page.within '.dropdown-menu-type' do + click_link 'Issue' + end end step 'I filter by "Mentioned"' do - select2("#{Todo::MENTIONED}", from: '#action_id') + click_button 'Action' + page.within '.dropdown-menu-action' do + click_link 'Mentioned' + end end step 'I should not see todos' do -- cgit v1.2.1 From 0ccdb41ced96c304658cf88b0869c5b78a4f15b7 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Tue, 30 Aug 2016 00:28:44 +0100 Subject: Review changes, simplified dropdown init --- app/assets/javascripts/todos.js | 51 ++++++------------------------- app/views/dashboard/todos/index.html.haml | 6 ++-- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/app/assets/javascripts/todos.js b/app/assets/javascripts/todos.js index ef1eadfb9c0..a908f730954 100644 --- a/app/assets/javascripts/todos.js +++ b/app/assets/javascripts/todos.js @@ -30,9 +30,9 @@ Todos.prototype.initFilters = function() { new UsersSelect(); - this.initProjectFilterDropdown(); - this.initTypeFilterDropdown(); - this.initActionFilterDropdown(); + this.initFilterDropdown($('.js-project-search'), 'project_id', true); + this.initFilterDropdown($('.js-type-search'), 'type'); + this.initFilterDropdown($('.js-action-search'), 'action_id'); $('form.filter-form').on('submit', function (event) { event.preventDefault(); @@ -40,47 +40,16 @@ }); }; - Todos.prototype.initProjectFilterDropdown = function() { - $projectDropdown = $('.js-project-search'); - $projectDropdown.glDropdown({ - filterable: true, + Todos.prototype.initFilterDropdown = function($dropdown, fieldName, isFilterable) { + $dropdown.glDropdown({ selectable: true, - fieldName: 'project_id', - data: $projectDropdown.data('data'), + filterable: isFilterable, + fieldName: fieldName, + data: $dropdown.data('data'), clicked: function() { - if ($projectDropdown.hasClass('js-filter-submit')) { - return $projectDropdown.closest('form.filter-form').submit(); - } + return $dropdown.closest('form.filter-form').submit(); } - }); - }; - - Todos.prototype.initTypeFilterDropdown = function() { - $typeDropdown = $('.js-type-search'); - $typeDropdown.glDropdown({ - selectable: true, - fieldName: 'type', - data: $typeDropdown.data('data'), - clicked: function() { - if ($typeDropdown.hasClass('js-filter-submit')) { - return $typeDropdown.closest('form.filter-form').submit(); - } - } - }); - }; - - Todos.prototype.initActionFilterDropdown = function() { - $actionDropdown = $('.js-action-search'); - $actionDropdown.glDropdown({ - selectable: true, - fieldName: 'action_id', - data: $actionDropdown.data('data'), - clicked: function() { - if ($actionDropdown.hasClass('js-filter-submit')) { - return $actionDropdown.closest('form.filter-form').submit(); - } - } - }); + }) }; Todos.prototype.doneClicked = function(e) { diff --git a/app/views/dashboard/todos/index.html.haml b/app/views/dashboard/todos/index.html.haml index 70dd4db6aaf..9d31f31c639 100644 --- a/app/views/dashboard/todos/index.html.haml +++ b/app/views/dashboard/todos/index.html.haml @@ -30,12 +30,12 @@ .filter-item.inline - if params[:project_id].present? = hidden_field_tag(:project_id, params[:project_id]) - = dropdown_tag(project_dropdown_label(params[:project_id], 'Project'), options: { toggle_class: 'js-project-search js-filter-submit', title: 'Filter by project', filter: true, filterInput: 'input#search', dropdown_class: 'dropdown-menu-selectable dropdown-menu-project js-filter-submit', - placeholder: 'Search projects', data: { data: todo_projects_options, selected: params[:project_id], field_name: 'project_id', default_label: 'Project' } }) + = dropdown_tag(project_dropdown_label(params[:project_id], 'Project'), options: { toggle_class: 'js-project-search js-filter-submit', title: 'Filter by project', filter: true, filterInput: 'input#project-search', dropdown_class: 'dropdown-menu-selectable dropdown-menu-project js-filter-submit', + placeholder: 'Search projects', data: { data: todo_projects_options } }) .filter-item.inline - if params[:author_id].present? = hidden_field_tag(:author_id, params[:author_id]) - = dropdown_tag(user_dropdown_label(params[:author_id], 'Author'), options: { toggle_class: 'js-user-search js-filter-submit js-author-search', title: 'Filter by author', filter: true, filterInput: 'input#search', dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit', + = dropdown_tag(user_dropdown_label(params[:author_id], 'Author'), options: { toggle_class: 'js-user-search js-filter-submit js-author-search', title: 'Filter by author', filter: true, filterInput: 'input#author-search', dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit', placeholder: 'Search authors', data: { any_user: 'Any Author', first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), selected: params[:author_id], field_name: 'author_id', default_label: 'Author' } }) .filter-item.inline - if params[:type].present? -- cgit v1.2.1 From e67a483752310e32bc4577c03dd9042565b71c0a Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Wed, 31 Aug 2016 18:33:12 +0100 Subject: Fixed project filtering --- app/assets/javascripts/todos.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/todos.js b/app/assets/javascripts/todos.js index a908f730954..23eda7d44ca 100644 --- a/app/assets/javascripts/todos.js +++ b/app/assets/javascripts/todos.js @@ -30,7 +30,7 @@ Todos.prototype.initFilters = function() { new UsersSelect(); - this.initFilterDropdown($('.js-project-search'), 'project_id', true); + this.initFilterDropdown($('.js-project-search'), 'project_id', ['text']); this.initFilterDropdown($('.js-type-search'), 'type'); this.initFilterDropdown($('.js-action-search'), 'action_id'); @@ -40,11 +40,12 @@ }); }; - Todos.prototype.initFilterDropdown = function($dropdown, fieldName, isFilterable) { + Todos.prototype.initFilterDropdown = function($dropdown, fieldName, searchFields) { $dropdown.glDropdown({ selectable: true, - filterable: isFilterable, + filterable: searchFields ? true : false, fieldName: fieldName, + search: { fields: searchFields }, data: $dropdown.data('data'), clicked: function() { return $dropdown.closest('form.filter-form').submit(); -- cgit v1.2.1 From 28db37de70fa94b2e7d287c9cfa31946f037125a Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Thu, 1 Sep 2016 14:05:58 +0100 Subject: Added todo filter tests --- features/dashboard/todos.feature | 20 --------- spec/features/todos/todos_filtering_spec.rb | 63 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 spec/features/todos/todos_filtering_spec.rb diff --git a/features/dashboard/todos.feature b/features/dashboard/todos.feature index 42f5d6d2af7..0b23bbb7951 100644 --- a/features/dashboard/todos.feature +++ b/features/dashboard/todos.feature @@ -22,26 +22,6 @@ Feature: Dashboard Todos And I mark all todos as done Then I should see all todos marked as done - @javascript - Scenario: I filter by project - Given I filter by "Enterprise" - Then I should not see todos - - @javascript - Scenario: I filter by author - Given I filter by "John Doe" - Then I should not see todos related to "Mary Jane" in the list - - @javascript - Scenario: I filter by type - Given I filter by "Issue" - Then I should not see todos related to "Merge Requests" in the list - - @javascript - Scenario: I filter by action - Given I filter by "Mentioned" - Then I should not see todos related to "Assignments" in the list - @javascript Scenario: I click on a todo row Given I click on the todo diff --git a/spec/features/todos/todos_filtering_spec.rb b/spec/features/todos/todos_filtering_spec.rb new file mode 100644 index 00000000000..83cf306437d --- /dev/null +++ b/spec/features/todos/todos_filtering_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe 'Dashboard > User filters todos', feature: true, js: true do + include WaitForAjax + + let(:user_1) { create(:user, username: 'user_1', name: 'user_1') } + let(:user_2) { create(:user, username: 'user_2', name: 'user_2') } + + let(:project_1) { create(:empty_project, name: 'project_1') } + let(:project_2) { create(:empty_project, name: 'project_2') } + + let(:issue) { create(:issue, title: 'issue', project: project_1) } + + let!(:merge_request) { create(:merge_request, source_project: project_2, title: 'merge_request') } + + before do + create(:todo, user: user_1, author: user_2, project: project_1, target: issue, action: 1) + create(:todo, user: user_1, author: user_1, project: project_2, target: merge_request, action: 2) + + project_1.team << [user_1, :developer] + project_2.team << [user_1, :developer] + login_as(user_1) + visit dashboard_todos_path + end + + it 'filters by project' do + click_button 'Project' + within '.dropdown-menu-project' do + fill_in 'Search projects', with: project_1.name_with_namespace + click_link project_1.name_with_namespace + end + wait_for_ajax + expect('.prepend-top-default').not_to have_content project_2.name_with_namespace + end + + it 'filters by author' do + click_button 'Author' + within '.dropdown-menu-author' do + fill_in 'Search authors', with: user_1.name + click_link user_1.name + end + wait_for_ajax + expect('.prepend-top-default').not_to have_content user_2.name + end + + it 'filters by type' do + click_button 'Type' + within '.dropdown-menu-type' do + click_link 'Issue' + end + wait_for_ajax + expect('.prepend-top-default').not_to have_content ' merge request !' + end + + it 'filters by action' do + click_button 'Action' + within '.dropdown-menu-action' do + click_link 'Assigned' + end + wait_for_ajax + expect('.prepend-top-default').not_to have_content ' mentioned ' + end +end -- cgit v1.2.1