Sha256: d3d51dc4b4ae33799d0590dbe6458b5b04e7f41d603e76ca07b4069f72fc927c

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Decidim
  # This cell renders tabs and panels based on an items array wich contains
  # hashes with items required to render them. Each item represent a panel
  # and a tab and has the following keys:
  #
  # - enabled: Whether the tab has to be displayed
  # - id: Suffix used to generate the id of each tab and panel
  # - text: Text of the panel
  # - icon: Icon key of the panel
  # - method: The method to render the panel content (for example, :cell or
  #           :render)
  # - args: The arguments to be passed to the method to render the panel
  #         content
  #
  # The `model` is expected to be a resource with HasAttachments concern
  #
  class TabPanelsCell < Decidim::ViewModel
    def show
      return if model.blank?

      render :show
    end

    def items
      @items ||= model.select { |item| item[:enabled] }
    end

    def tabs
      @tabs ||= items.map { |item| item.slice(:id, :text, :icon) }
    end

    def panels
      @panels ||= items.map { |item| item.slice(:id, :method, :args) }
    end

    def selected_tab
      @selected_tab ||= items.find { |item| item[:selected] }
    end

    def selected?(tab, index)
      if selected_tab
        tab[:id] == selected_tab[:id]
      else
        index.zero?
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-core-0.30.0.rc3 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.30.0.rc2 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.30.0.rc1 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.29.2 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.29.1 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.29.0 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.29.0.rc4 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.29.0.rc3 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.29.0.rc2 app/cells/decidim/tab_panels_cell.rb
decidim-core-0.29.0.rc1 app/cells/decidim/tab_panels_cell.rb