<commit_before>class TimeSheetsController < ApplicationController
  before_action :set_time_sheet, only: [:show, :edit, :update, :destroy]

  def show
  end

  def new
    @time_sheet = TimeSheet.new
  end

  def edit
  end

  def hand_in
    TimeSheet.find(params[:id]).update(status: 'pending', handed_in: true, hand_in_date: Date.today)
    redirect_to user_path(current_user)
  end

  def accept
    TimeSheet.find(params[:id]).update(status: 'accepted', last_modified: Date.today, signer: current_user.id)
    redirect_to user_path(current_user)
  end

  def reject
    TimeSheet.find(params[:id]).update(status: 'rejected', handed_in: false, last_modified: Date.today, signer: current_user.id)
    redirect_to user_path(current_user)
  end

  def update
    if @time_sheet.update(time_sheet_params)
      flash[:success] = 'Time Sheet was successfully updated.'
      redirect_to work_days_path(month: @time_sheet.month, year: @time_sheet.year, project: @time_sheet.project)
    else
      render :edit
    end
  end

  def accept_reject
    set_time_sheet
    if params[:commit] == I18n.t('time_sheets.show_footer.reject')
      @time_sheet.update(time_sheet_params)
      reject
    else
      @time_sheet.update(wimi_signed: time_sheet_params[:wimi_signed])
      accept
    end
  end

  private

  def set_time_sheet<commit_msg>relocated set_time_sheet call for accept_reject<commit_after>class TimeSheetsController < ApplicationController
  before_action :set_time_sheet, only: [:show, :edit, :update, :destroy, :accept_reject]

  def show
  end

  def new
    @time_sheet = TimeSheet.new
  end

  def edit
  end

  def hand_in
    TimeSheet.find(params[:id]).update(status: 'pending', handed_in: true, hand_in_date: Date.today)
    redirect_to user_path(current_user)
  end

  def accept
    TimeSheet.find(params[:id]).update(status: 'accepted', last_modified: Date.today, signer: current_user.id)
    redirect_to user_path(current_user)
  end

  def reject
    TimeSheet.find(params[:id]).update(status: 'rejected', handed_in: false, last_modified: Date.today, signer: current_user.id)
    redirect_to user_path(current_user)
  end

  def update
    if @time_sheet.update(time_sheet_params)
      flash[:success] = 'Time Sheet was successfully updated.'
      redirect_to work_days_path(month: @time_sheet.month, year: @time_sheet.year, project: @time_sheet.project)
    else
      render :edit
    end
  end

  def accept_reject
    if params[:commit] == I18n.t('time_sheets.show_footer.reject')
      @time_sheet.update(time_sheet_params)
      reject
    else
      @time_sheet.update(wimi_signed: time_sheet_params[:wimi_signed])
      accept
    end
  end

  private

  def set_time_sheet
{'fraction_non_alphanumeric': 0.09604728481714074, 'fraction_numerical': 0.0014776505356483192, 'mean_word_length': 4.080675422138837, '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': '5513767', 'n_tokens_mistral': 919, 'n_tokens_neox': 887, 'n_words': 193}