Class: Locomotive::EditableElementService

Inherits:
Struct
  • Object
show all
Includes:
Concerns::ActivityService
Defined in:
app/services/locomotive/editable_element_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::ActivityService

#track_activity, #without_tracking_activity

Instance Attribute Details

#accountObject

Returns the value of attribute account

Returns:

  • (Object)

    the current value of account



2
3
4
# File 'app/services/locomotive/editable_element_service.rb', line 2

def 
  @account
end

#localeObject

Returns the value of attribute locale

Returns:

  • (Object)

    the current value of locale



2
3
4
# File 'app/services/locomotive/editable_element_service.rb', line 2

def locale
  @locale
end

#siteObject

Returns the value of attribute site

Returns:

  • (Object)

    the current value of site



2
3
4
# File 'app/services/locomotive/editable_element_service.rb', line 2

def site
  @site
end

Instance Method Details

#update_all(list_of_attributes) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/locomotive/editable_element_service.rb', line 6

def update_all(list_of_attributes)
  [].tap do |elements|
    pages, modified_pages = {}, {}

    list_of_attributes.each do |attributes|
      page_id = attributes[:page_id]

      if page = (pages[page_id] || Locomotive::Page.find(page_id))
        pages[page_id] = page

        if element = page.editable_elements.find(attributes[:_id])
          element.attributes = clean_attributes_for(element, attributes)

          modified_pages[page_id] = page if element.changed?

          elements << [page, element]
        end
      end
    end

    save_all_pages(pages.values)

    track_activity 'editable_element.updated_bulk', locale: locale, parameters: {
      pages: modified_pages.values.map { |p| { title: p.title, _id: p._id } }
    } unless modified_pages.empty?
  end
end