Class: Archangel::Backend::EntriesController

Inherits:
Archangel::BackendController show all
Includes:
Controllers::ResourcefulConcern
Defined in:
app/controllers/archangel/backend/entries_controller.rb

Overview

Backend collection entries controller

Instance Method Summary collapse

Methods included from Controllers::ResourcefulConcern

#create, #destroy, #edit, #index, #new, #show, #update

Methods included from Controllers::MetatagableConcern

#assign_meta_tags

Methods inherited from ApplicationController

#current_site, #render_401_error, #render_404_error, #render_error

Methods included from Controllers::PaginatableConcern

#page_num, #per_page

Methods included from Controllers::ActionableConcern

#action, #collection_action?, #member_action?

Instance Method Details

#sortObject

Update collection entry sort order

Formats

JSON

Params

[String] slug - the collection slug

Request

POST /backend/collections/:slug/entries/sort
POST /backend/collections/:slug/entries/sort.json

Parameters

{
  "collection_entry": {
    "sort": ["0" => "1234", "1" => "5678", "2" => "4321"]
  }
}

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/archangel/backend/entries_controller.rb', line 34

def sort
  parent_resource_content

  sort_order = sort_resource_params.fetch(:sort)

  ApplicationRecord.transaction do
    sort_order.each do |index, entry_id|
      entry = current_site.entries
                          .where(collection: @collection)
                          .find_by(id: entry_id.to_i)

      authorize entry

      entry.set_list_position(index)
    end
  end

  render json: { success: true }, status: :accepted
end