From 010b6fb1735399b50b7046dbd3a45bdf99134f9e Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 20 Jun 2023 13:15:23 +0200 Subject: [PATCH 1/7] Add basic filter feature --- app/controllers/contributors_controller.rb | 19 +++++++++++++++---- app/views/contributors/index.html.erb | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/controllers/contributors_controller.rb b/app/controllers/contributors_controller.rb index af03e7f52..c9a72e1bc 100644 --- a/app/controllers/contributors_controller.rb +++ b/app/controllers/contributors_controller.rb @@ -14,11 +14,15 @@ def message end def index - @filter = filter_param + @state = state_params + @tag_list = tag_list_params + @active_count = Contributor.active.count @inactive_count = Contributor.inactive.count + @available_tags = Contributor.all_tags_with_count.to_json - @contributors = @filter == :inactive ? Contributor.inactive : Contributor.active + @contributors = @state == :inactive ? Contributor.inactive : Contributor.active + @contributors = @contributors.with_tags(tag_list_params) @contributors = @contributors.with_attached_avatar.includes(:tags) end @@ -73,14 +77,21 @@ def count_params params.permit(tag_list: []) end - def filter_param - value = params.permit(:filter)[:filter]&.to_sym + def state_params + value = params.permit(:state)[:state]&.to_sym return :active unless %i[active inactive].include?(value) value end + def tag_list_params + value = params.permit(tag_list: [])[:tag_list] + return [] if value.blank? + + value&.reject(&:empty?) + end + def handle_failed_update flash.now[:error] = I18n.t('contributor.invalid', name: contributor.name) diff --git a/app/views/contributors/index.html.erb b/app/views/contributors/index.html.erb index d08c20797..cdcfa3931 100644 --- a/app/views/contributors/index.html.erb +++ b/app/views/contributors/index.html.erb @@ -17,20 +17,32 @@ <% header.tab_bar do %> <%= c('tab_bar', items: { - contributors_path => { + contributors_path(tag_list: @tag_list.present? ? @tag_list : nil) => { label: "Aktiv", - active: @filter == :active, + active: @state == :active, count: @active_count, }, - contributors_path(filter: :inactive) => { + contributors_path(state: :inactive, tag_list: @tag_list.present? ? @tag_list : nil) => { label: "Inaktiv", - active: @filter == :inactive, + active: @state == :inactive, count: @inactive_count, }, }) %> <% end %> <% end %> + <%= c 'section' do %> + <%= c 'heading' do %> + Filter by tag + <% end %> + <%= c 'form', url: contributors_path, method: 'get', multiple: true do %> + <%= hidden_field_tag :state, @state %> + + <%= c 'tags_input', available_tags: @available_tags, allow_new: false, name: 'tag_list[]', value: @tag_list %> + <%= c 'submit_button', label: 'Filter' %> + <% end %> + <% end %> + <%= c 'section' do %> <% @contributors.each do |contributor| %> <%= c 'contributor_row', contributor: contributor %> From 9aad16babb31d22ab68c1cca3985bf0a6cc6ef81 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Wed, 21 Jun 2023 10:18:47 +0200 Subject: [PATCH 2/7] Update TabBar to accept buttons, add filter button --- app/components/tab_bar/tab_bar.html.erb | 14 +++++----- app/components/tab_bar/tab_bar.js | 15 +++++++++++ app/views/contributors/index.html.erb | 36 ++++++++++++++----------- app/views/requests/index.html.erb | 10 ++++--- public/icons.svg | 1 + 5 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 app/components/tab_bar/tab_bar.js diff --git a/app/components/tab_bar/tab_bar.html.erb b/app/components/tab_bar/tab_bar.html.erb index 65f5ebfd0..fc0f0e0d2 100644 --- a/app/components/tab_bar/tab_bar.html.erb +++ b/app/components/tab_bar/tab_bar.html.erb @@ -1,17 +1,19 @@ -