Sha256: 9fd44f1abf77ff2875d40f6474177f0c1333231847d42f205c1c72e37434fe18

Contents?: true

Size: 1.88 KB

Versions: 22

Compression:

Stored size: 1.88 KB

Contents

module Spina
  module Admin
    class NavigationsController < AdminController
      before_action :set_breadcrumb
      before_action :set_navigation, only: [:show, :edit, :update]
      
      admin_section :content
      
      def index
        navigation = Spina::Navigation.order(:position).first
        if navigation
          redirect_to spina.edit_admin_navigation_path(navigation)
        end
      end

      def edit
        @navigations = Spina::Navigation.order(:position)
        render layout: 'spina/admin/admin'
      end

      def update        
        if @navigation.update(navigation_params)
          redirect_to spina.edit_admin_navigation_path(@navigation)
        else
          render :edit
        end
      end

      def sort
        params[:ids].each.with_index do |id, index| 
          NavigationItem.where(id: id).update_all(position: index + 1)
        end
        
        flash.now[:info] = t("spina.navigations.sorting_saved")
        render_flash
      end

      private

        def update_navigation_item_position(navigation_item_id, position, parent_id = nil)
          Spina::NavigationItem.update(navigation_item_id, position: position.to_i + 1, parent_id: parent_id )
        end

        def update_child_pages_position(node)
          if node[:children].present?
            node[:children].each_pair do |child_pos, child_node|
              update_child_pages_position(child_node) if child_node[:children].present?
              update_navigation_item_position(child_node[:id], child_pos, node[:id])
            end
          end
        end

        def set_breadcrumb
          add_breadcrumb t('spina.navigations.navigations')
        end

        def navigation_params
          params.require(:navigation).permit(:label, :auto_add_pages, page_ids: [])
        end

        def set_navigation
          @navigation = Navigation.find(params[:id])
        end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
spina-2.12.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.11.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.10.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.9.1 app/controllers/spina/admin/navigations_controller.rb
spina-2.9.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.8.1 app/controllers/spina/admin/navigations_controller.rb
spina-2.8.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.7.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.6.2 app/controllers/spina/admin/navigations_controller.rb
spina-2.6.1 app/controllers/spina/admin/navigations_controller.rb
spina-2.6.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.5.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.4.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.3.5 app/controllers/spina/admin/navigations_controller.rb
spina-2.3.4 app/controllers/spina/admin/navigations_controller.rb
spina-2.3.3 app/controllers/spina/admin/navigations_controller.rb
spina-2.3.2 app/controllers/spina/admin/navigations_controller.rb
spina-2.3.1 app/controllers/spina/admin/navigations_controller.rb
spina-2.3.0 app/controllers/spina/admin/navigations_controller.rb
spina-2.2.0 app/controllers/spina/admin/navigations_controller.rb