Class: TusurHeader::Links
- Inherits:
-
Object
- Object
- TusurHeader::Links
- Includes:
- ActionView::Helpers
- Defined in:
- lib/tusur_header/menu_links.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #edit_user_link ⇒ Object
- #edit_user_url ⇒ Object
-
#initialize(user) ⇒ Links
constructor
A new instance of Links.
- #links ⇒ Object
- #links_data ⇒ Object
- #links_from_system_infos(key) ⇒ Object
- #list ⇒ Object
- #profile_url ⇒ Object
- #sign_out_link ⇒ Object
- #sign_out_url ⇒ Object
- #system_infos ⇒ Object
Constructor Details
#initialize(user) ⇒ Links
Returns a new instance of Links.
34 35 36 |
# File 'lib/tusur_header/menu_links.rb', line 34 def initialize(user) @user = user end |
Instance Attribute Details
#user ⇒ Object
Returns the value of attribute user.
31 32 33 |
# File 'lib/tusur_header/menu_links.rb', line 31 def user @user end |
Instance Method Details
#edit_user_link ⇒ Object
56 57 58 |
# File 'lib/tusur_header/menu_links.rb', line 56 def edit_user_link Settings['profile.url'] || profile_url end |
#edit_user_url ⇒ Object
60 61 62 |
# File 'lib/tusur_header/menu_links.rb', line 60 def edit_user_url %(#{edit_user_link}/#{ I18n.locale == :ru ? nil : %(#{I18n.locale}/) }users/edit) end |
#links ⇒ Object
38 39 40 41 42 |
# File 'lib/tusur_header/menu_links.rb', line 38 def links return [] unless user links_data.map { |e| Link.new e[:title], e[:url], e[:options], e[:separator] } end |
#links_data ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/tusur_header/menu_links.rb', line 78 def links_data @links_hash ||= begin my_urls = [] if links_from_system_infos('my_url').any? links_from_system_infos('my_url').reject{ |elem| elem['link'].blank? }.each do |elem| my_urls << { title: elem['title'], url: elem['link'] } end my_urls = my_urls.sort{ |a, b| a[:title] <=> b[:title] } my_urls << { separator: true } end urls = [] urls << { title: I18n.t('menu_links.profile'), url: "#{profile_url}/#{ I18n.locale == :ru ? nil : %(#{I18n.locale}/) }dashboard" } if links_from_system_infos('url').any? links_from_system_infos('url').reject{ |elem| elem['link'].blank? }.each do |elem| urls << { title: elem['title'], url: elem['link'] } end end urls << { title: 'Система дистанционного обучения', url: 'https://sdo.tusur.ru' } if I18n.locale == :ru urls << { title: 'Облачное хранилище ТУСУРа', url: 'https://cloud.tusur.ru' } if I18n.locale == :ru && (employee? || student? || aspirant?) urls = urls.sort{ |a, b| a[:title] <=> b[:title] } urls << { separator: true } array = my_urls + urls array << { title: I18n.t('menu_links.edit_profile'), url: edit_user_url } array << { title: I18n.t('menu_links.sign_out'), url: sign_out_url, options: { method: :delete } } array end end |
#links_from_system_infos(key) ⇒ Object
72 73 74 75 76 |
# File 'lib/tusur_header/menu_links.rb', line 72 def links_from_system_infos(key) system_infos.inject([]) do |array, data| array += JSON.parse(data.last).select { |k, _| k.to_s == key }.values end end |
#list ⇒ Object
44 45 46 |
# File 'lib/tusur_header/menu_links.rb', line 44 def list content_tag :ul, links.join.html_safe, class: 'dropdown-menu' end |
#profile_url ⇒ Object
52 53 54 |
# File 'lib/tusur_header/menu_links.rb', line 52 def profile_url 'https://profile.tusur.ru' end |
#sign_out_link ⇒ Object
64 65 66 |
# File 'lib/tusur_header/menu_links.rb', line 64 def sign_out_link Settings['profile.url'] || profile_url end |
#sign_out_url ⇒ Object
68 69 70 |
# File 'lib/tusur_header/menu_links.rb', line 68 def sign_out_url "#{sign_out_link}/#{ I18n.locale == :ru ? nil : %(#{I18n.locale}/) }users/sign_out?redirect_url=#{Settings['app.url']}" end |
#system_infos ⇒ Object
48 49 50 |
# File 'lib/tusur_header/menu_links.rb', line 48 def system_infos RedisUserConnector.get(user.id).select { |k,_| k =~ /_info/ } end |