Class: Decidim::NavigationMaps::SaveBlueprints

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/navigation_maps/save_blueprints.rb

Overview

This command creates or updates the blueprints for the organization and content block.

Instance Method Summary collapse

Constructor Details

#initialize(forms) ⇒ SaveBlueprints

Creates a blueprint.

forms - The form with the data.



11
12
13
14
# File 'app/commands/decidim/navigation_maps/save_blueprints.rb', line 11

def initialize(forms)
  @forms = forms
  @blueprints = forms.blueprints || {}
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid

  • :invalid if the form wasn't valid and we couldn't proceed.

Returns nothing.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/commands/decidim/navigation_maps/save_blueprints.rb', line 22

def call
  @blueprints.each do |form|
    next if form.invalid?

    initialize_blueprint(form)
    if form.remove
      destroy_blueprint!(form)
    else
      create_areas(form.blueprint) if form.blueprint
      destroy_areas_except(form.blueprint.keys) if form.blueprint
      update_blueprint!(form)
    end
  end

  broadcast(:ok)
end