Sha256: 7f32c30a0e9e3d43e87c382884ccdf13298f8ad1ea9c1c5910ad92037518da48

Contents?: true

Size: 1.27 KB

Versions: 77

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Decidim
  module AdminLog
    # This class holds the logic to present a `Decidim::Scope`
    # for the `AdminLog` log.
    #
    # Usage should be automatic and you shouldn't need to call this class
    # directly, but here's an example:
    #
    #    action_log = Decidim::ActionLog.last
    #    view_helpers # => this comes from the views
    #    ScopePresenter.new(action_log, view_helpers).present
    class ScopePresenter < Decidim::Log::BasePresenter
      private

      def diff_fields_mapping
        {
          code: :string,
          name: :i18n,
          parent_id: :scope,
          scope_type_id: :scope_type
        }
      end

      def action_string
        case action
        when "create", "delete", "update"
          if parent_name.present?
            "decidim.admin_log.scope.#{action}_with_parent"
          else
            "decidim.admin_log.scope.#{action}"
          end
        else
          super
        end
      end

      def i18n_labels_scope
        "activemodel.attributes.scope"
      end

      def i18n_params
        super.merge(
          parent_scope: h.translated_attribute(parent_name)
        )
      end

      def parent_name
        action_log.extra.dig("extra", "parent_name")
      end
    end
  end
end

Version data entries

77 entries across 77 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.8 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.7 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.6 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.26.10 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.26.9 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.5 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.26.8 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.4 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.3 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.26.7 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.26.5 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.2 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.1 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.26.4 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.0 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.26.3 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.0.rc2 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.27.0.rc1 app/presenters/decidim/admin_log/scope_presenter.rb
decidim-core-0.26.2 app/presenters/decidim/admin_log/scope_presenter.rb