Class: Decidim::Gallery::MainCell

Inherits:
ViewModel
  • Object
show all
Defined in:
app/cells/decidim/gallery/main_cell.rb

Defined Under Namespace

Classes: Settings, Video

Instance Method Summary collapse

Instance Method Details

#browserObject



58
59
60
61
62
63
# File 'app/cells/decidim/gallery/main_cell.rb', line 58

def browser
  @browser ||= Browser.new(
    request.headers["User-Agent"],
    accept_language: request.headers["Accept-Language"]
  )
end

#collectionObject



15
16
17
# File 'app/cells/decidim/gallery/main_cell.rb', line 15

def collection
  render "#{gallery_type}_collection"
end

#current_participatory_spaceObject



65
66
67
# File 'app/cells/decidim/gallery/main_cell.rb', line 65

def current_participatory_space
  controller.try(:current_participatory_space)
end


54
55
56
# File 'app/cells/decidim/gallery/main_cell.rb', line 54

def gallery_component
  @gallery_component ||= Decidim::Component.find_by(id: model.gallery_id)
end


34
35
36
37
# File 'app/cells/decidim/gallery/main_cell.rb', line 34

def gallery_path(**options)
  current_params = try(:params) || {}
  EngineRouter.main_proxy(gallery_component).root_path({ locale: current_params[:locale] }.reverse_merge(options))
end

#itemsObject



25
26
27
28
29
30
31
32
# File 'app/cells/decidim/gallery/main_cell.rb', line 25

def items
  @items ||= Decidim::Gallery::GalleryItem
             .published
             .where(decidim_component_id: gallery_component.id)
             .order(weight: :asc, published_at: :asc)
             .page(options[:page])
             .per(per_page)
end

#list_itemsObject



19
20
21
22
23
# File 'app/cells/decidim/gallery/main_cell.rb', line 19

def list_items
  return "" if gallery_type == "video"

  render "#{gallery_type}_list"
end

#showObject



9
10
11
12
13
# File 'app/cells/decidim/gallery/main_cell.rb', line 9

def show
  snippets.add(:foot, helpers.javascript_pack_tag("decidim_gallery", defer: false))

  render gallery_type.to_sym if gallery_component.present?
end

#stubbed_video_object(item) ⇒ Object



42
43
44
45
46
47
48
# File 'app/cells/decidim/gallery/main_cell.rb', line 42

def stubbed_video_object(item)
  Video.new(settings: Settings.new(
    video_url: translated_attribute(item.video_url),
    title: translated_attribute(item.title)
  ),
            cache_key_with_version: item.cache_key_with_version)
end

#titleObject



50
51
52
# File 'app/cells/decidim/gallery/main_cell.rb', line 50

def title
  translated_attribute(gallery_component.name)
end