<commit_before># encoding:UTF-8
class CarRentsController < ApplicationController  
  before_filter :authenticate, only: [:forman]
  before_action :set_edit
  before_action :set_rent
  before_action :set_rents, only: [:new,:edit,:create,:update]
  def main
    @bokningar = Rent.order(d_from: :asc).where.not(status: "nekad").where(d_from: Date.today..Date.today+30)
    respond_to do |format|      
        format.html 
        format.json { render :json => @bokningar}
    end 
  end
  def new    
    @avtal = Document.where(title: "Bilavtal").first
    @rent = Rent.new
    if(current_user)
      @profile = current_user.profile
      @rent.name = @profile.name
      @rent.lastname = @profile.lastname
      @rent.phone = @profile.phone
      @rent.email = @profile.email
      @utskott = []
      for @post in @profile.posts do
        if @post.car_rent == true
          @utskott << @post.council
        end
      end
    end    
  end
  def show
    if(@rent != nil)
      if(current_user) && (current_user.profile == @rent.profile) 
      elsif(current_user) && (current_user.moderator?(:bil))
      else
        redirect_to(:bil)
        flash[:notice] = 'Du har inte rättigheter för att se bokningen.'
      end
    else
      flash[:notice] = 'Hittade ingen bokning med ID ' + params[:id]+'.'
      redirect_to(:bil)
    end
    rescue ActionController::RedirectBackError
      redirect_to root_path           
  end
  def edit   
    if @rent.profile
      @profile = @rent.profile
      @utskott = []
      for @post in @profile.posts do
        if @post.car_rent == true
          @utskott << @post.council
        end
      end
    end
  end
  def create
    @rent = Rent.new(rent_params)
    if (current_user)
      @rent.profile = current_user.profile
      @rent.status = "Bekräftad"
    end    
    respond_to do |format|
      if @rent.save
        CarRentMailer.rent_email(@rent).deliver
        format.html { redirect_to [:car,@rent], :notice => 'Bokningen skapades!.' }
        format.json { render :json => @rent, :status => :created, :location => @rent }
      else
        @rent.disclaimer = false
        format.html { render :action => "new" }
        format.json { render :json => @rent.errors, :status => :unprocessable_entity }
      end
    end
  end
  def update           
    respond_to do |format|
      if params[:rent][:confirmed] == true
        Rails.logger.info @rent.update_attribute(:confirmed,true)
      else
        
        if @rent.update(rent_params) 
          format.html { redirect_to [:car,@rent], :notice => 'Bokningen sparades.' }
          format.json { render :json => @rent, :status => :created, :location => @rent }
        else        
          format.html { render :action => "edit" }
          format.json { render :json => @rent.errors, :status => :unprocessable_entity }
        end
      end
    end
  end
  def destroy    
    @rent.destroy
    respond_to do |format|
      format.html { redirect_to car_rents_path,notice: 'Bokningeng raderades.' }
      format.json { head :no_content }
    end
  end
  def forman    
    @rents = Rent.order(d_from: :asc).where(d_from: Date.today..Date.today+30)
    @rent_grid = initialize_grid(@rents)
  end
  def index
    if (current_user)
      @bokningar = current_user.profile.rents.order('d_from asc')
      render :action => 'user_index'
    else
      render :action => 'guest_index'
    end
  end
  
  def booking
    
  end
  private<commit_msg>Uppdaterat CarRent-controller, visar alla bokningar<commit_after># encoding:UTF-8
class CarRentsController < ApplicationController  
  before_filter :authenticate, only: [:forman]
  before_action :set_edit
  before_action :set_rent
  before_action :set_rents, only: [:new,:edit,:create,:update]
  def main
    @bokningar = Rent.order(d_from: :asc).where.not(status: "nekad").where(d_from: Date.today..Date.today+30)
    respond_to do |format|      
        format.html 
        format.json { render :json => Rent.order(d_from: :asc).where.not(status: "nekad")}
    end 
  end
  def new    
    @avtal = Document.where(title: "Bilavtal").first
    @rent = Rent.new
    if(current_user)
      @profile = current_user.profile
      @rent.name = @profile.name
      @rent.lastname = @profile.lastname
      @rent.phone = @profile.phone
      @rent.email = @profile.email
      @utskott = []
      for @post in @profile.posts do
        if @post.car_rent == true
          @utskott << @post.council
        end
      end
    end    
  end
  def show
    if(@rent != nil)
      if(current_user) && (current_user.profile == @rent.profile) 
      elsif(current_user) && (current_user.moderator?(:bil))
      else
        redirect_to(:bil)
        flash[:notice] = 'Du har inte rättigheter för att se bokningen.'
      end
    else
      flash[:notice] = 'Hittade ingen bokning med ID ' + params[:id]+'.'
      redirect_to(:bil)
    end
    rescue ActionController::RedirectBackError
      redirect_to root_path           
  end
  def edit   
    if @rent.profile
      @profile = @rent.profile
      @utskott = []
      for @post in @profile.posts do
        if @post.car_rent == true
          @utskott << @post.council
        end
      end
    end
  end
  def create
    @rent = Rent.new(rent_params)
    if (current_user)
      @rent.profile = current_user.profile
      @rent.status = "Bekräftad"
    end    
    respond_to do |format|
      if @rent.save
        CarRentMailer.rent_email(@rent).deliver
        format.html { redirect_to [:car,@rent], :notice => 'Bokningen skapades!.' }
        format.json { render :json => @rent, :status => :created, :location => @rent }
      else
        @rent.disclaimer = false
        format.html { render :action => "new" }
        format.json { render :json => @rent.errors, :status => :unprocessable_entity }
      end
    end
  end
  def update           
    respond_to do |format|
      if params[:rent][:confirmed] == true
        Rails.logger.info @rent.update_attribute(:confirmed,true)
      else
        
        if @rent.update(rent_params) 
          format.html { redirect_to [:car,@rent], :notice => 'Bokningen sparades.' }
          format.json { render :json => @rent, :status => :created, :location => @rent }
        else        
          format.html { render :action => "edit" }
          format.json { render :json => @rent.errors, :status => :unprocessable_entity }
        end
      end
    end
  end
  def destroy    
    @rent.destroy
    respond_to do |format|
      format.html { redirect_to car_rents_path,notice: 'Bokningeng raderades.' }
      format.json { head :no_content }
    end
  end
  def forman    
    @rents = Rent.order(d_from: :asc)
    @rent_grid = initialize_grid(@rents)
  end
  def index
    if (current_user)
      @bokningar = current_user.profile.rents.order('d_from asc')
      render :action => 'user_index'
    else
      render :action => 'guest_index'
    end
  end
  
  def booking
    
  end
  private
{'fraction_non_alphanumeric': 0.1172750790457028, 'fraction_numerical': 0.0011497556769186547, 'mean_word_length': 2.331258975586405, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, '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': '917375', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2263, 'n_words': 520}