Sha256: be436827e7007541b2dc6c7e13ad9bdf452ceb237d4d3beb43a20c32bbf1a2e1

Contents?: true

Size: 1.71 KB

Versions: 27

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module Decidim
  # This cell renders a collapsible list of elements. Each element from the
  # `model` array will be rendered with the `:cell` cell.
  #
  # The `model` must be an Integer representing how many elements we have right
  # now. Can be higher than the `:total` options value.
  #
  # Available options:
  #  - `:small` => Whether the progress bar should be small or not.
  #    This will probably be set to `true` if rendered in a collection view.
  #    Defaults to `false`.
  #  - `:total` => The amount that will set the progress bar to 100%, the objective
  #    to reach.
  #  - `:units_name` => The I18n key representing the name of the elements we're
  #    counting (votes, signatures, answers...). Can have the `%{count}` format.
  #  - `:element_id` => A String representing the ID that will be given to the
  #    progress bar HTML element.
  #  - `:subtitle_text` => An I18n key representing a subtitle for the element.
  #
  # Example:
  #
  #    cell(
  #      "decidim/progress_bar_list",
  #      7,
  #      element_id: "my-id",
  #      units_name: "my.i18n.key",
  #      small: true,
  #      total: 10,
  #      subtitle_text: I18n.t("my.subtitle.key")
  #    )
  class ProgressBarCell < Decidim::ViewModel
    private

    def element_id
      options[:element_id]
    end

    def units_name
      options[:units_name]
    end

    def units_name_text
      I18n.t(units_name, count: progress)
    end

    def subtitle_text
      options[:subtitle_text]
    end

    def small?
      options[:small].to_s == "true"
    end

    def progress
      model
    end

    def total
      options[:total]
    end

    def percentage
      (progress.to_f / total) * 100
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
decidim-core-0.22.0 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.21.0 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.20.1 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.20.0 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.19.1 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.18.1 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.19.0 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.17.2 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.18.0 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.17.1 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.16.1 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.17.0 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.16.0 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.15.2 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.15.1 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.15.0 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.14.4 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.14.3 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.14.2 app/cells/decidim/progress_bar_cell.rb
decidim-core-0.14.1 app/cells/decidim/progress_bar_cell.rb