Sha256: 3de9657f11d3a4e28381e5992cf87b0801b351f08ee6fde32a579eec9207d9ad

Contents?: true

Size: 2 KB

Versions: 21

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

class Admin::SidebarController < Admin::BaseController
  def index
    @available = SidebarRegistry.available_sidebars
    @ordered_sidebars = Sidebar.ordered_sidebars
  end

  # Just update a single active Sidebar instance at once
  def update
    @sidebar = Sidebar.where(id: params[:id]).first
    @old_s_index = @sidebar.staged_position || @sidebar.active_position
    @sidebar.update params[:configure][@sidebar.id.to_s].permit!
    respond_to do |format|
      format.js
      format.html do
        return redirect_to(admin_sidebar_index_path)
      end
    end
  end

  def destroy
    @sidebar = Sidebar.where(id: params[:id]).first
    @sidebar&.destroy
    respond_to do |format|
      format.html { return redirect_to(admin_sidebar_index_path) }
      format.js
    end
  end

  def publish
    Sidebar.apply_staging_on_active!
    redirect_to admin_sidebar_index_path
  end

  # Callback for admin sidebar sortable plugin
  def sortable
    sorted = params[:sidebar].map(&:to_i)

    Sidebar.transaction do
      sorted.each_with_index do |sidebar_id, staged_index|
        # DEV NOTE : Ok, that's a HUGE hack. Sidebar.available are Class, not
        # Sidebar instances. In order to use jQuery.sortable we need that hack:
        # Sidebar.available is an Array, so it's ordered. I arbitrary shift by?
        # IT'S OVER NINE THOUSAND! considering we'll never reach 9K Sidebar
        # instances or Sidebar specializations
        sidebar = if sidebar_id >= 9000
                    SidebarRegistry.available_sidebars[sidebar_id - 9000].
                      new(blog: this_blog)
                  else
                    Sidebar.valid.find(sidebar_id)
                  end
        sidebar.update(staged_position: staged_index)
      end
    end

    @ordered_sidebars = Sidebar.ordered_sidebars
    @available = SidebarRegistry.available_sidebars

    respond_to do |format|
      format.js
      format.html do
        return redirect_to admin_sidebar_index_path
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
HornsAndHooves-publify_core-10.5.0 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.4.0 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.3.0 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.2.0 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.10 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.1.1 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.1.0 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.0.3 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.0.2 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.0.1 app/controllers/admin/sidebar_controller.rb
HornsAndHooves-publify_core-10.0.0 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.9 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.8 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.7 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.6 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.5 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.4 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.3 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.2 app/controllers/admin/sidebar_controller.rb
publify_core-9.2.1 app/controllers/admin/sidebar_controller.rb