Sha256: 84c11029fd8c29af9ce51c8449d1eb93a546a855fbf17066c1481afef749486d

Contents?: true

Size: 1.2 KB

Versions: 14

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object used to attach a feature to a participatory process from the
    # admin panel.
    #
    class FeatureForm < Decidim::Form
      include TranslatableAttributes

      mimic :feature

      translatable_attribute :name, String
      validates :name, translatable_presence: true

      attribute :settings, Object
      attribute :default_step_settings, Object
      attribute :manifest
      attribute :weight, Integer, default: 0

      attribute :step_settings, Hash[String => Object]
      attribute :participatory_process

      def map_model(model)
        self.attributes = model.attributes
        self.settings = model.settings
        self.default_step_settings = model.default_step_settings
      end

      def settings?
        settings.manifest.attributes.any?
      end

      def default_step_settings?
        default_step_settings.manifest.attributes.any?
      end

      def step_settings?
        return false unless participatory_process.steps.any?

        step_settings
          .values
          .map(&:manifest)
          .flat_map(&:attributes)
          .flat_map(&:keys)
          .any?
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
decidim-admin-0.5.1 app/forms/decidim/admin/feature_form.rb
decidim-0.5.1 decidim-admin/app/forms/decidim/admin/feature_form.rb
decidim-admin-0.5.0 app/forms/decidim/admin/feature_form.rb
decidim-0.5.0 decidim-admin/app/forms/decidim/admin/feature_form.rb
decidim-admin-0.4.4 app/forms/decidim/admin/feature_form.rb
decidim-0.4.4 decidim-admin/app/forms/decidim/admin/feature_form.rb
decidim-admin-0.4.3 app/forms/decidim/admin/feature_form.rb
decidim-admin-0.4.2 app/forms/decidim/admin/feature_form.rb
decidim-admin-0.4.1 app/forms/decidim/admin/feature_form.rb
decidim-0.4.3 decidim-admin/app/forms/decidim/admin/feature_form.rb
decidim-0.4.2 decidim-admin/app/forms/decidim/admin/feature_form.rb
decidim-0.4.1 decidim-admin/app/forms/decidim/admin/feature_form.rb
decidim-admin-0.4.0 app/forms/decidim/admin/feature_form.rb
decidim-0.4.0 decidim-admin/app/forms/decidim/admin/feature_form.rb