Module: PinboardItemsHelper
- Defined in:
- app/helpers/pinboard_items_helper.rb
Instance Method Summary collapse
-
#get_pinboard_item_from_object(object, user) ⇒ Object
TODO: remove user throughout this chain and use sessions user?.
- #insert_pinboard_item_link(pinboard_item) ⇒ Object
-
#inserted_pinboard_item_object_for_klass(klass) ⇒ Integer, false
TODO: change to nil not false.
- #next_object_by_inserted_keyword(object, keyword) ⇒ Object
- #next_previous_by_inserted_keyword(object) ⇒ Object
- #pin_item_to_pinboard_link(object, user) ⇒ Object
- #pinboard_item_li_tag(pinboard_item) ⇒ Object
- #pinboard_item_options(pinboard_item) ⇒ Object
- #previous_object_by_inserted_keyword(object, keyword) ⇒ Object
Instance Method Details
#get_pinboard_item_from_object(object, user) ⇒ Object
TODO: remove user throughout this chain and use sessions user?
20 21 22 23 24 |
# File 'app/helpers/pinboard_items_helper.rb', line 20 def get_pinboard_item_from_object(object, user) if object.pinned?(user, sessions_current_project_id) PinboardItem.where(pinned_object_id: object.id, user_id: user).first end end |
#insert_pinboard_item_link(pinboard_item) ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/helpers/pinboard_items_helper.rb', line 11 def insert_pinboard_item_link(pinboard_item) if pinboard_item.is_inserted link_to('Disable default', pinboard_item_path(pinboard_item, pinboard_item: {is_inserted: false}), title: 'Disable default', class: ['circle-button', 'button-pinboard-default', 'button-delete', 'option-default'], method: :put, remote: true ) else link_to('Make default', pinboard_item_path(pinboard_item, pinboard_item: {is_inserted: true}), title: 'Make default', class: ['circle-button', 'button-pinboard-default','button-submit', 'option-default'], method: :put, remote: true ) end end |
#inserted_pinboard_item_object_for_klass(klass) ⇒ Integer, false
TODO: change to nil not false
58 59 60 61 |
# File 'app/helpers/pinboard_items_helper.rb', line 58 def inserted_pinboard_item_object_for_klass(klass) object = klass.constantize.joins(:pinboard_items).where(project_id: sessions_current_project_id, pinboard_items: {user_id: sessions_current_user_id, is_inserted: true}).first object ? object : false end |
#next_object_by_inserted_keyword(object, keyword) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/pinboard_items_helper.rb', line 63 def next_object_by_inserted_keyword(object, keyword) return nil if keyword.nil? || object.nil? t = object.class.base_class.name.tableize base = object.class.base_class .joins(:tags) .where(tags: {keyword: keyword}) .where("#{t}.id > #{object.id}") .order("#{t}.id ASC") .limit(1) if respond_to?(:project_id) base.where(project_id: sessions_current_project_id).first else base.first end end |
#next_previous_by_inserted_keyword(object) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/pinboard_items_helper.rb', line 95 def next_previous_by_inserted_keyword(object) k = inserted_pinboard_item_object_for_klass('Keyword') return [nil, nil] if k == false [ previous_object_by_inserted_keyword(object, k)&.id, next_object_by_inserted_keyword(object, k)&.id ] end |
#pin_item_to_pinboard_link(object, user) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/helpers/pinboard_items_helper.rb', line 3 def pin_item_to_pinboard_link(object, user) if !object.pinned?(user, sessions_current_project_id) link_to('', pinboard_items_path(pinboard_item: { pinned_object_id: object.id, pinned_object_type: object..class.name, is_inserted: true }), data: { "pin-button-item-id": object.id }, class: 'navigation-item pin-button', remote: true, method: :post) else link_to('', pinboard_item_path(get_pinboard_item_from_object(object, user)), class: 'unpin-button', data: { "pin-button-item-id": object.id }, method: :delete, remote: true) end end |
#pinboard_item_li_tag(pinboard_item) ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/helpers/pinboard_items_helper.rb', line 43 def pinboard_item_li_tag(pinboard_item) content_tag(:li, class: 'slide-panel-category-item', id: "order_#{pinboard_item.id}", data: { pinboard_object_id: pinboard_item.pinned_object.id, pinboard_item_id: pinboard_item.id, insert: pinboard_item.is_inserted }) do content_tag(:div, class: [:handle, 'flex-separate', :middle]) do object_home_link(pinboard_item.pinned_object) + (pinboard_item) end end end |
#pinboard_item_options(pinboard_item) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/pinboard_items_helper.rb', line 26 def (pinboard_item) = [ link_to('Remove', pinboard_item_path(pinboard_item), class: [ :remove, 'circle-button', 'button-delete', 'd-block' ], method: :delete, remote: true), insert_pinboard_item_link(pinboard_item) ] .unshift(source_document_viewer_option_tag(pinboard_item.pinned_object)) if pinboard_item.pinned_object.kind_of?(Source) content_tag(:div, class: ['pinboard-dropdown']) do content_tag(:div, '', class: ['pinboard-menu-bar']) + content_tag(:div, '', class: ['pinboard-menu-bar']) + content_tag(:div, '', class: ['pinboard-menu-bar']) + content_tag(:div, class: [ 'itemOptions', 'pinboard-dropdown-content', 'gap-small']) do .compact.join.html_safe end end.html_safe end |
#previous_object_by_inserted_keyword(object, keyword) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/pinboard_items_helper.rb', line 79 def previous_object_by_inserted_keyword(object, keyword) return nil if keyword.nil? || object.nil? t = object.class.base_class.name.tableize base = object.class.base_class .joins(:tags) .where(tags: {keyword: keyword}) .where("#{t}.id < #{object.id}") .order("#{t}.id DESC") .limit(1) if respond_to?(:project_id) base.where(project_id: sessions_current_project_id).first else base.first end end |