<commit_before>require 'open_food_network/spree_api_key_loader'

Spree::Admin::ProductsController.class_eval do
  include OpenFoodNetwork::SpreeApiKeyLoader
  before_filter :load_form_data, :only => [:bulk_edit, :new, :edit]
  before_filter :load_spree_api_key, :only => :bulk_edit

  alias_method :location_after_save_original, :location_after_save

  respond_to :json, :only => :clone

  respond_override create: { html: { 
    success: lambda {
      if params[:button] == "add_another"
        redirect_to new_admin_product_path
      else
        redirect_to '/admin/products/bulk_edit'
      end
    },
    failure: lambda {
      render :new
    } } }
  #respond_override :clone => { :json => {:success => lambda { redirect_to bulk_index_admin_products_url+"?q[id_eq]=#{@new.id}" } } }

  def product_distributions
  end

  def bulk_update
    collection_hash = Hash[params[:products].each_with_index.map { |p,i| [i,p] }]
    product_set = Spree::ProductSet.new({:collection_attributes => collection_hash})

    params[:filters] ||= {}
    bulk_index_query = params[:filters].reduce("") do |string, filter|
      "#{string}q[#{filter[:property][:db_column]}_#{filter[:predicate][:predicate]}]=#{filter[:value]};"
    end<commit_msg>Product controller loads correct data for create and update actions<commit_after>require 'open_food_network/spree_api_key_loader'

Spree::Admin::ProductsController.class_eval do
  include OpenFoodNetwork::SpreeApiKeyLoader
  before_filter :load_form_data, :only => [:bulk_edit, :new, :create, :edit, :update]
  before_filter :load_spree_api_key, :only => :bulk_edit

  alias_method :location_after_save_original, :location_after_save

  respond_to :json, :only => :clone

  respond_override create: { html: {
    success: lambda {
      if params[:button] == "add_another"
        redirect_to new_admin_product_path
      else
        redirect_to '/admin/products/bulk_edit'
      end
    },
    failure: lambda {
      render :new
    } } }
  #respond_override :clone => { :json => {:success => lambda { redirect_to bulk_index_admin_products_url+"?q[id_eq]=#{@new.id}" } } }

  def product_distributions
  end

  def bulk_update
    collection_hash = Hash[params[:products].each_with_index.map { |p,i| [i,p] }]
    product_set = Spree::ProductSet.new({:collection_attributes => collection_hash})

    params[:filters] ||= {}
    bulk_index_query = params[:filters].reduce("") do |string, filter|
      "#{string}q[#{filter[:property][:db_column]}_#{filter[:predicate][:predicate]}]=#{filter[:value]};"
    end
{'fraction_non_alphanumeric': 0.1380933699489996, 'fraction_numerical': 0.0, 'mean_word_length': 4.782312925170068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '2012559', 'n_tokens_mistral': 847, 'n_tokens_neox': 837, 'n_words': 146}