<commit_before>class ActivityCategoriesController < ApplicationController
  load_and_authorize_resource
  skip_before_action :authenticate_user!, only: [:index]
  before_action :set_activity_category, only: [:show, :edit, :update, :destroy]

  # GET /activity_categories
  # GET /activity_categories.json
  def index
    @key_stage_filter_names = work_out_which_filters_to_set
    @key_stage_tags = ActsAsTaggableOn::Tag.includes(:taggings).where(taggings: { context: 'key_stages' }).order(:name).to_a
    @activity_categories = ActivityCategory.all.order(:name)
  end

  # GET /activity_categories/1
  # GET /activity_categories/1.json
  def show
  end

  # GET /activity_categories/new
  def new
    @activity_category = ActivityCategory.new
  end

  # GET /activity_categories/1/edit
  def edit
  end

  # POST /activity_categories
  # POST /activity_categories.json
  def create
    @activity_category = ActivityCategory.new(activity_category_params)

    respond_to do |format|
      if @activity_category.save
        format.html { redirect_to @activity_category, notice: 'Activity category was successfully created.' }
        format.json { render :show, status: :created, location: @activity_category }
      else
        format.html { render :new }
        format.json { render json: @activity_category.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /activity_categories/1
  # PATCH/PUT /activity_categories/1.json
  def update
    respond_to do |format|
      if @activity_category.update(activity_category_params)
        format.html { redirect_to @activity_category, notice: 'Activity category was successfully updated.' }
        format.json { render :show, status: :ok, location: @activity_category }
      else
        format.html { render :edit }
        format.json { render json: @activity_category.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /activity_categories/1
  # DELETE /activity_categories/1.json
  def destroy
    # activity categories should be marked inactive rather than deleted
    # this method does NOT delete the activity category
    # @activity_category.destroy
    respond_to do |format|
      format.html { redirect_to activity_categories_url, notice: 'Activity category not deleted' }
      format.json { head :no_content }
    end
  end

private

  # Use callbacks to share common setup or constraints between actions.
  def set_activity_category
    @activity_category = ActivityCategory.find(params[:id])
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def activity_category_params
    params.require(:activity_category).permit(:name, :description, :badge_name)
  end

  def activity_category_filter_params
    params.permit(key_stage_tag: { key_stage_names: []})
  end

  def work_out_which_filters_to_set
    key_stage_tag = activity_category_filter_params[:key_stage_tag]

    if key_stage_tag.nil?
      if current_user.nil? || current_user.school.nil?
        # TODO remove this hardcoding
        %w(KS1 KS2 KS3)
      else
        # Set for the school defaults
        current_user.school.key_stage_list
      end
    else
      filters = key_stage_tag[:key_stage_names]
      filters.delete("")
      filters
    end
  end
end
<commit_msg>Fix style issue<commit_after>class ActivityCategoriesController < ApplicationController
  load_and_authorize_resource
  skip_before_action :authenticate_user!, only: [:index]
  before_action :set_activity_category, only: [:show, :edit, :update, :destroy]

  # GET /activity_categories
  # GET /activity_categories.json
  def index
    @key_stage_filter_names = work_out_which_filters_to_set
    @key_stage_tags = ActsAsTaggableOn::Tag.includes(:taggings).where(taggings: { context: 'key_stages' }).order(:name).to_a
    @activity_categories = ActivityCategory.all.order(:name)
  end

  # GET /activity_categories/1
  # GET /activity_categories/1.json
  def show
  end

  # GET /activity_categories/new
  def new
    @activity_category = ActivityCategory.new
  end

  # GET /activity_categories/1/edit
  def edit
  end

  # POST /activity_categories
  # POST /activity_categories.json
  def create
    @activity_category = ActivityCategory.new(activity_category_params)

    respond_to do |format|
      if @activity_category.save
        format.html { redirect_to @activity_category, notice: 'Activity category was successfully created.' }
        format.json { render :show, status: :created, location: @activity_category }
      else
        format.html { render :new }
        format.json { render json: @activity_category.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /activity_categories/1
  # PATCH/PUT /activity_categories/1.json
  def update
    respond_to do |format|
      if @activity_category.update(activity_category_params)
        format.html { redirect_to @activity_category, notice: 'Activity category was successfully updated.' }
        format.json { render :show, status: :ok, location: @activity_category }
      else
        format.html { render :edit }
        format.json { render json: @activity_category.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /activity_categories/1
  # DELETE /activity_categories/1.json
  def destroy
    # activity categories should be marked inactive rather than deleted
    # this method does NOT delete the activity category
    # @activity_category.destroy
    respond_to do |format|
      format.html { redirect_to activity_categories_url, notice: 'Activity category not deleted' }
      format.json { head :no_content }
    end
  end

private

  # Use callbacks to share common setup or constraints between actions.
  def set_activity_category
    @activity_category = ActivityCategory.find(params[:id])
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def activity_category_params
    params.require(:activity_category).permit(:name, :description, :badge_name)
  end

  def activity_category_filter_params
    params.permit(key_stage_tag: { key_stage_names: [] })
  end

  def work_out_which_filters_to_set
    key_stage_tag = activity_category_filter_params[:key_stage_tag]

    if key_stage_tag.nil?
      if current_user.nil? || current_user.school.nil?
        # TODO remove this hardcoding
        %w(KS1 KS2 KS3)
      else
        # Set for the school defaults
        current_user.school.key_stage_list
      end
    else
      filters = key_stage_tag[:key_stage_names]
      filters.delete("")
      filters
    end
  end
end

{'fraction_non_alphanumeric': 0.07781983345950037, 'fraction_numerical': 0.003028009084027252, 'mean_word_length': 3.5875, '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': '2006166', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1906, 'n_words': 490}