<commit_before># encoding: utf-8

module Admin
  class PageImagesController < Admin::AdminController
    before_action :find_page
    before_action :find_page_image, only: [:show, :edit, :update, :destroy]

    require_authorization(
      PageImage,
      proc { @page_image },
      collection: [:index, :reorder, :new, :create]
    )

    def index
      @page_images = @page.page_images
      respond_to do |format|
        format.json do
          render json: @page_images, each_serializer: Admin::PageImageSerializer
        end
      end
    end

    def reorder
      @page_images = params[:ids].map { |id| PageImage.find(id) }
      @page_images.each_with_index do |pi, i|
        pi.update(position: i)
      end
      respond_to do |format|
        format.json do
          render json: @page_images, each_serializer: Admin::PageImageSerializer
        end
      end
    end

    def show; end

    def new
      @page_image = @page.page_images.new
    end

    def create
      if page_images_params?
        page_images_params.each do |_index, attributes|
          if attributes[:image]
            @page.page_images.create(attributes.merge(locale: @locale))
          end
        end
      else<commit_msg>Fix for image sorting<commit_after># encoding: utf-8

module Admin
  class PageImagesController < Admin::AdminController
    before_action :find_page
    before_action :find_page_image, only: [:show, :edit, :update, :destroy]

    require_authorization(
      PageImage,
      proc { @page_image },
      collection: [:index, :reorder, :new, :create]
    )

    def index
      @page_images = @page.page_images
      respond_to do |format|
        format.json do
          render json: @page_images, each_serializer: Admin::PageImageSerializer
        end
      end
    end

    def reorder
      @page_images = params[:ids].map { |id| PageImage.find(id) }
      @page_images.each_with_index do |pi, i|
        pi.update(position: i + 1)
      end
      respond_to do |format|
        format.json do
          render json: @page_images, each_serializer: Admin::PageImageSerializer
        end
      end
    end

    def show; end

    def new
      @page_image = @page.page_images.new
    end

    def create
      if page_images_params?
        page_images_params.each do |_index, attributes|
          if attributes[:image]
            @page.page_images.create(attributes.merge(locale: @locale))
          end
        end
      else
{'fraction_non_alphanumeric': 0.08754071661237785, 'fraction_numerical': 0.0012214983713355048, 'mean_word_length': 2.3565573770491803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1077282', 'n_tokens_mistral': 750, 'n_tokens_neox': 735, 'n_words': 187}