<commit_before>class NotesController < ApplicationController
  before_filter :authenticate_user!
  before_filter :find_book_and_chapter
  before_filter :find_note, :only => [:show, :complete, :reopen]
  before_filter :find_notes, :only => [:index, :completed]

  def index
    @notes = @notes.select { |n| n.state != "complete" }
  end
  
  def show
    @chapter = @note._parent
    @comment = @note.comments.build
    @comments = @note.comments - [@comment]
  end

  def new
    @note = Note.new
    @notes = @chapter.notes.where(:element_id => params[:element_id])
  end
  
  def create
    element = @chapter.elements.where(:xml_id => params[:element_id]).first
    note = @chapter.notes.build(params[:note].merge(:element => element,
                                                    :element_id => params[:element_id],
                                                    :number => @book.notes_count + 1,
                                                    :user => current_user))
    if note.save
      # Increment notes count for the book
      @book.notes_count += 1
      @book.save
      # create.js.erb
    else
      # TODO: validation error if note text is blank
    end<commit_msg>Don't show accepted or rejected notes<commit_after>class NotesController < ApplicationController
  before_filter :authenticate_user!
  before_filter :find_book_and_chapter
  before_filter :find_note, :only => [:show, :complete, :reopen]
  before_filter :find_notes, :only => [:index, :completed]

  def index
    @notes = @notes.select { |n| n.state != "complete" ||
                                 n.state != "accepted" ||
                                 n.state != "rejected"}
  end
  
  def show
    @chapter = @note._parent
    @comment = @note.comments.build
    @comments = @note.comments - [@comment]
  end

  def new
    @note = Note.new
    @notes = @chapter.notes.where(:element_id => params[:element_id])
  end
  
  def create
    element = @chapter.elements.where(:xml_id => params[:element_id]).first
    note = @chapter.notes.build(params[:note].merge(:element => element,
                                                    :element_id => params[:element_id],
                                                    :number => @book.notes_count + 1,
                                                    :user => current_user))
    if note.save
      # Increment notes count for the book
      @book.notes_count += 1
      @book.save
      # create.js.erb
    else
      # TODO: validation error if note text is blank
    end
{'fraction_non_alphanumeric': 0.1117252270035531, 'fraction_numerical': 0.0015791551519936833, 'mean_word_length': 1.956826137689615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1668522', 'n_tokens_mistral': 715, 'n_tokens_neox': 689, 'n_words': 170}