Sha256: bfb5c5028c3a34f9061e27d779fdfb4f04686d71a1b7fcc023f21cadee1b48be

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    # This class holds a Form to close a meeting from Decidim's public views.
    class CloseMeetingForm < Decidim::Form
      attribute :closing_report, String
      attribute :proposal_ids, Array[Integer]
      attribute :proposals
      attribute :closed_at, Decidim::Attributes::TimeWithZone, default: ->(_form, _attribute) { Time.current }

      validates :closing_report, presence: true

      # Private: Gets the proposals from the meeting and injects them to the form.
      #
      # Returns nothing.
      def map_model(model)
        self.proposal_ids = model.linked_resources(:proposals, "proposals_from_meeting").pluck(:id)
        presenter = MeetingPresenter.new(model)
        self.closing_report = presenter.closing_report(all_locales: false)
      end

      def proposals
        @proposals ||= Decidim.find_resource_manifest(:proposals)
                              .try(:resource_scope, current_component)
                              &.where(id: proposal_ids)
                              &.order(title: :asc)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-meetings-0.24.3 app/forms/decidim/meetings/close_meeting_form.rb
decidim-meetings-0.24.2 app/forms/decidim/meetings/close_meeting_form.rb
decidim-meetings-0.24.1 app/forms/decidim/meetings/close_meeting_form.rb
decidim-meetings-0.24.0 app/forms/decidim/meetings/close_meeting_form.rb
decidim-meetings-0.24.0.rc2 app/forms/decidim/meetings/close_meeting_form.rb
decidim-meetings-0.24.0.rc1 app/forms/decidim/meetings/close_meeting_form.rb