From f6f1ed3182696b8302f90c68c6e1a335fd713906 Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Thu, 11 Apr 2019 15:30:09 +0200 Subject: [PATCH] sidebar --- app/assets/images/favicon.ico | Bin 0 -> 4286 bytes app/helpers/sidemenu_helper.rb | 113 +++++++++++++++++++++++++ app/views/layouts/application.html.erb | 107 ++--------------------- 3 files changed, 119 insertions(+), 101 deletions(-) create mode 100644 app/assets/images/favicon.ico create mode 100644 app/helpers/sidemenu_helper.rb diff --git a/app/assets/images/favicon.ico b/app/assets/images/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..1eefdd4fc1738b63a29c7797dc3b4afc23f394a9 GIT binary patch literal 4286 zcmeH}NiQr>6vwNH&}`m9o>@07@)9DA7-DF>vcY#CSos$C6h1*)^@0yzh_JIUgqVj- zcLZz0dG$MTz3Ntt>LG9O-s#+~Tc_%t^S@{K-?A*9{R;*y{;k*#%lc_q)-QY5Dl2La z^eXnVP{-SNQ&^V#7mdKv)013ZU(5OV`GMMXtYUth0tuH1u(xD-TU%RFU0p4;wY93dxVRAFRES&{ z|6pK_;H#mbL1O@h#>Pe&9v)VGzGLC$|MvD)`uh4bCd9$#^J!iTzIWpC-6>5Nr_(l ze!tYz)aYQ&v$C=>86O{)ot+)C^jlYAZ!i$^gM)*Vb?~vtMNdzU%+Jru+S-~N9UaN> z@v(Bn!oq^IwY4dZ=H_NuU0qGF@zo6&@WDRPF^~%|P?O1IQeIzQUCo`Ip33Cpq!bqy z3mCk{fqfecoB@Z2hpv7;Q&N{;U>_3`6Q1h`)j%SCua0|d3m|^_q$=o zgnf5+cWa)>H8|)`B-i*8S2z{Bi;Ig6uYabW`8V~4jcn=S+9Lcr+j33St_?#F_O-<>UXP%iWdn4v1?(h%qvWB%@&m&{kT(`Hkl}q7N?83pB zB%Oa*n-5u8SN0;sS`(2#m rmYSTNp4Q%k9~ks0x@^8bzU$lh9yJF)z-zgDe>rXbD|5R}{;K>2I4t2( literal 0 HcmV?d00001 diff --git a/app/helpers/sidemenu_helper.rb b/app/helpers/sidemenu_helper.rb new file mode 100644 index 0000000..0812d0e --- /dev/null +++ b/app/helpers/sidemenu_helper.rb @@ -0,0 +1,113 @@ +# frozen_string_literal: true + +# Module for building side menu +module SidemenuHelper + def build_side_menu + ret = nav_link('Home', '/', '', 'fa-home') + ret += divider + ret += heading('Nazwa') + submenu = ['other components:', ['Buttons', '/', '/'], + ['Cards', '/home/index', '/home/index']] + ret += nav_link_submenu(['Components', 'fa-cog', 'Comp'], + submenu, + ['/', '/home/index']) + ret.html_safe + end + + # divider for menu + def divider + # + tag.hr class: 'sidebar-divider' + end + + # heading for menu + def heading(name) + # + content_tag(:div, name, class: 'sidebar-heading') + end + + # link without submenu + def nav_link(text, link, for_active, icon) + nav_class = check_link_active(for_active) ? 'nav-item active' : 'nav-item' + content_tag(:li, nav_link_to(text, icon, link), class: nav_class) + end + + # link_to for navigation + def nav_link_to(text, icon, link, name = nil, expand = nil) + icon_text = icon.nil? ? '' : "" + if name.nil? + link_to(raw("#{icon_text}#{text}"), + link, class: 'nav-link') + else + link_to(raw("#{icon_text}#{text}"), + link, class: "nav-link#{expand ? '' : ' collapsed'}", + data: { toggle: 'collapse', target: "#collapse#{name}" }, + aria: { expanded: "#{expand}", controls: "collapse#{name}" }) + end + end + + # create link with sub_menu + # @params: + # a_name [Array] - [name of menu, icon, div_id] + # submenu [Array] - array of : + # -> [name of link {str}, link{str}, active{str or arr}] + # -> nil - to add divider to menu + # -> 'String' - to add header to menu + # for_active - all links in this submenu + def nav_link_submenu(a_name, submenu, for_active) + content_tag :li, class: 'nav-item' do + expand = check_link_active(for_active) + r = nav_link_to(a_name[0], a_name[1], '#', a_name[2], expand) + r += content_tag(:div, inner_submenu(submenu), + id: "collapse#{a_name[2]}", + class: "collapse#{expand ? ' show' : ''}", + aria: { labelledby: "heading#{a_name[2]}" }, + data: { parent: '#accordionSidebar' }) + r + end + end + + # creates inner_submenu + # submenu [Array] - array of : + # -> [name of link {str}, link{str}, active{str or arr}] + # -> nil - to add divider to menu + # -> 'String' - to add header to menu + def inner_submenu(submenu) + content_tag :div, class: 'bg-white py-2 collapse-inner rounded' do + r = nil + submenu.each do |sub| + r += submenu_element(sub) unless r.nil? + r = submenu_element(sub) if r.nil? + end + r + end + end + + def submenu_element(sub) + if sub.nil? + # divider + tag.div class: 'collapse-divider' + elsif sub.class.to_s == 'String' + # header + content_tag :h6, sub, class: 'collapse-header' + elsif sub.class.to_s == 'Array' + # link (menu item) + activecl = check_link_active(sub[2]) ? ' active' : '' + link_to(sub[0], sub[1], class: "collapse-item#{activecl}") + end + end + + # check if this link is active + def check_link_active(for_active) + is_active = false + if for_active.class.to_s == 'String' + is_active = controller_path.to_s.include?(for_active) + elsif for_active.class.to_s == 'Array' + for_active.each do |fa| + is_active = true if controller_path.to_s.include?(fa) + break if is_active + end + end + is_active + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5128737..4e26dc8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,6 +4,7 @@ PassKeep <%= csrf_meta_tags %> <%= csp_meta_tag %> + <%= favicon_link_tag %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> @@ -17,115 +18,22 @@ @@ -134,15 +42,12 @@
-