From 69a2a922f76acfc93fb57309dbf98c0ec1d2b91d Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 15 Aug 2019 12:57:17 +0500 Subject: [PATCH] Improve breadcrumbs --- app/helpers/navs_helper.rb | 23 +++++++++++++++++++ app/views/federal_subjects/index.html.erb | 8 +------ app/views/federal_subjects/show.html.erb | 16 ++++--------- app/views/staffs/accounts/index.html.erb | 15 ++++-------- app/views/staffs/accounts/show.html.erb | 20 ++++------------ app/views/staffs/home/show.html.erb | 8 +------ app/views/staffs/people/index.html.erb | 15 ++++-------- .../staffs/people/passports/index.html.erb | 20 ++++------------ .../people/person_comments/index.html.erb | 20 ++++------------ .../people/relationships/index.html.erb | 20 ++++------------ app/views/staffs/people/show.html.erb | 20 ++++------------ 11 files changed, 62 insertions(+), 123 deletions(-) diff --git a/app/helpers/navs_helper.rb b/app/helpers/navs_helper.rb index 7c0b3ac..aec972f 100644 --- a/app/helpers/navs_helper.rb +++ b/app/helpers/navs_helper.rb @@ -6,6 +6,29 @@ module NavsHelper pills: 'nav nav-pills d-flex d-sm-none flex-column', }.freeze + def nav_breadcrumb(*args, active_text) + tag.nav 'aria-label': 'breadcrumb' do + tag.ol class: 'breadcrumb' do + args.each do |(text, url)| + concat nav_breadcrumb_item text, url + end + concat nav_breadcrumb_item active_text + end + end + end + + def nav_breadcrumb_item(text, url = nil) + if url + tag.li class: 'breadcrumb-item' do + link_to text, url + end + else + tag.li class: 'breadcrumb-item active', 'aria-current': 'page' do + text + end + end + end + def nav_tabs(scope_name, active_tab_name, options) capture do concat nav_tabs_list scope_name, active_tab_name, :tabs, options diff --git a/app/views/federal_subjects/index.html.erb b/app/views/federal_subjects/index.html.erb index 89bd9e2..c7ec1e3 100644 --- a/app/views/federal_subjects/index.html.erb +++ b/app/views/federal_subjects/index.html.erb @@ -1,11 +1,5 @@
- + <%= nav_breadcrumb FederalSubject.model_name.human count: 0 %> diff --git a/app/views/federal_subjects/show.html.erb b/app/views/federal_subjects/show.html.erb index 931abe1..7caf22b 100644 --- a/app/views/federal_subjects/show.html.erb +++ b/app/views/federal_subjects/show.html.erb @@ -1,16 +1,8 @@
- + <%= nav_breadcrumb( + [FederalSubject.model_name.human(count: 0), federal_subjects_path], + @federal_subject.display_name, + ) %>

<%= @federal_subject.native_name %>

diff --git a/app/views/staffs/accounts/index.html.erb b/app/views/staffs/accounts/index.html.erb index bcd0153..1f11033 100644 --- a/app/views/staffs/accounts/index.html.erb +++ b/app/views/staffs/accounts/index.html.erb @@ -1,15 +1,8 @@
- + <%= nav_breadcrumb( + [translate(:staff_services), staff_root_path], + Account.model_name.human(count: 0), + ) %>
diff --git a/app/views/staffs/accounts/show.html.erb b/app/views/staffs/accounts/show.html.erb index 99596a1..d0ec827 100644 --- a/app/views/staffs/accounts/show.html.erb +++ b/app/views/staffs/accounts/show.html.erb @@ -1,19 +1,9 @@
- + <%= nav_breadcrumb( + [translate(:staff_services), staff_root_path], + [Account.model_name.human(count: 0), staff_accounts_path], + @account.nickname, + ) %> <% if @account.superuser? %>
diff --git a/app/views/staffs/home/show.html.erb b/app/views/staffs/home/show.html.erb index 74008a8..6740744 100644 --- a/app/views/staffs/home/show.html.erb +++ b/app/views/staffs/home/show.html.erb @@ -1,11 +1,5 @@
- + <%= nav_breadcrumb translate :staff_services %>
    <% if policy(%i[staff account]).index? %> diff --git a/app/views/staffs/people/index.html.erb b/app/views/staffs/people/index.html.erb index 57183b9..da9c153 100644 --- a/app/views/staffs/people/index.html.erb +++ b/app/views/staffs/people/index.html.erb @@ -1,15 +1,8 @@
    - + <%= nav_breadcrumb( + [translate(:staff_services), staff_root_path], + Person.model_name.human(count: 0), + ) %>
diff --git a/app/views/staffs/people/passports/index.html.erb b/app/views/staffs/people/passports/index.html.erb index 1d930e6..233913e 100644 --- a/app/views/staffs/people/passports/index.html.erb +++ b/app/views/staffs/people/passports/index.html.erb @@ -1,19 +1,9 @@
- + <%= nav_breadcrumb( + [translate(:staff_services), staff_root_path], + [Person.model_name.human(count: 0), staff_people_path], + @person.full_name, + ) %> <%= render partial: 'staffs/people/nav_tabs', locals: { person: @person, tab: :passports } %> diff --git a/app/views/staffs/people/person_comments/index.html.erb b/app/views/staffs/people/person_comments/index.html.erb index 9516434..97184d1 100644 --- a/app/views/staffs/people/person_comments/index.html.erb +++ b/app/views/staffs/people/person_comments/index.html.erb @@ -1,19 +1,9 @@
- + <%= nav_breadcrumb( + [translate(:staff_services), staff_root_path], + [Person.model_name.human(count: 0), staff_people_path], + @person.full_name, + ) %> <%= render partial: 'staffs/people/nav_tabs', locals: { person: @person, tab: :person_comments } %> diff --git a/app/views/staffs/people/relationships/index.html.erb b/app/views/staffs/people/relationships/index.html.erb index 3e2451d..fe197c6 100644 --- a/app/views/staffs/people/relationships/index.html.erb +++ b/app/views/staffs/people/relationships/index.html.erb @@ -1,19 +1,9 @@
- + <%= nav_breadcrumb( + [translate(:staff_services), staff_root_path], + [Person.model_name.human(count: 0), staff_people_path], + @person.full_name, + ) %> <%= render partial: 'staffs/people/nav_tabs', locals: { person: @person, tab: :relationships } %> diff --git a/app/views/staffs/people/show.html.erb b/app/views/staffs/people/show.html.erb index b4678af..a59b002 100644 --- a/app/views/staffs/people/show.html.erb +++ b/app/views/staffs/people/show.html.erb @@ -1,19 +1,9 @@
- + <%= nav_breadcrumb( + [translate(:staff_services), staff_root_path], + [Person.model_name.human(count: 0), staff_people_path], + @person.full_name, + ) %> <%= render partial: 'nav_tabs', locals: { person: @person, tab: :overview } %>