<commit_before>class PagesController < ApplicationController
  before_action :authorize
  before_action :set_page, only: [:show, :edit, :update, :destroy, :latest_change, :snapshots, :setup_compare]

  def latest_change
    change = @page.latest_change
    if change
      redirect_to page_change_path(change)
    else
      redirect_to edit_page_url(@page), notice: 'Not enough snapshots to diff.'
    end
  end

  def snapshots
    @snapshots = @page.page_snapshots.order('created_at DESC').select(:id, :created_at, :sha2_hash)
  end

  def setup_compare
    # TODO extract this
    snapshots = @page.page_snapshots.where(id: [params[:before], params[:after]]).order('created_at ASC').last(2) # TODO: this needs an integration test
    change = Change.where(before: snapshots.first, after: snapshots.last).first_or_create
    redirect_to page_change_path(change)
  end

  # GET /pages
  def index
    @pages = Page.all
  end

  # GET /pages/1
  def show
  end

  # GET /pages/new
  def new
    @page = Page.new
    @users = User.all
    @slack_integrations = SlackIntegration.all
  end

  # GET /pages/1/edit
  def edit
    @users = User.all
    @slack_integrations = SlackIntegration.all
  end

  # POST /pages
  def create
    @page = Page.new(page_params)<commit_msg>reliably sort pages in watching<commit_after>class PagesController < ApplicationController
  before_action :authorize
  before_action :set_page, only: [:show, :edit, :update, :destroy, :latest_change, :snapshots, :setup_compare]

  def latest_change
    change = @page.latest_change
    if change
      redirect_to page_change_path(change)
    else
      redirect_to edit_page_url(@page), notice: 'Not enough snapshots to diff.'
    end
  end

  def snapshots
    @snapshots = @page.page_snapshots.order('created_at DESC').select(:id, :created_at, :sha2_hash)
  end

  def setup_compare
    # TODO extract this
    snapshots = @page.page_snapshots.where(id: [params[:before], params[:after]]).order('created_at ASC').last(2) # TODO: this needs an integration test
    change = Change.where(before: snapshots.first, after: snapshots.last).first_or_create
    redirect_to page_change_path(change)
  end

  # GET /pages
  def index
    @pages = Page.order(:created_at).all
  end

  # GET /pages/1
  def show
  end

  # GET /pages/new
  def new
    @page = Page.new
    @users = User.all
    @slack_integrations = SlackIntegration.all
  end

  # GET /pages/1/edit
  def edit
    @users = User.all
    @slack_integrations = SlackIntegration.all
  end

  # POST /pages
  def create
    @page = Page.new(page_params)
{'fraction_non_alphanumeric': 0.10151104223169315, 'fraction_numerical': 0.0030995738086013174, 'mean_word_length': 3.578014184397163, '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': '6182832', 'n_tokens_mistral': 869, 'n_tokens_neox': 844, 'n_words': 211}