Class: NotesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/notes_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/notes_controller.rb', line 74

def autocomplete
  @notes = Note.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))

  data = @notes.collect do |t|
    str = render_to_string(partial: 'tag', locals: {note: t})
    {id: t.id,
     label: str,
     response_values: {
         params[:method] => t.id},
     label_html: str
    }
  end

  render :json => data
end

- (Object) create

POST /notes POST /notes.json



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/notes_controller.rb', line 23

def create
  @note = Note.new(note_params)

  respond_to do |format|
    if @note.save
      format.html { redirect_to @note.note_object.metamorphosize, notice: 'Note was successfully created.' }
      format.json { render json: @note, status: :created, location: @note }
    else
      format.html { redirect_to :back, notice: 'Note was NOT successfully created.' }
      format.json { render json: @note.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /notes/1 DELETE /notes/1.json



53
54
55
56
57
58
59
# File 'app/controllers/notes_controller.rb', line 53

def destroy
  @note.destroy
  respond_to do |format|
    format.html { redirect_to :back, notice: 'Note was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) download

GET /notes/download



91
92
93
# File 'app/controllers/notes_controller.rb', line 91

def download
  send_data Note.generate_download(Note.where(project_id: $project_id)), type: 'text', filename: "notes_#{DateTime.now.to_s}.csv"
end

- (Object) edit



10
11
12
# File 'app/controllers/notes_controller.rb', line 10

def edit
  @note = Note.find_by_id(params[:id]).metamorphosize
end

- (Object) index

GET /notes GET /notes.json



16
17
18
19
# File 'app/controllers/notes_controller.rb', line 16

def index
  @recent_objects = Note.where(project_id: $project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



61
62
63
# File 'app/controllers/notes_controller.rb', line 61

def list
  @notes = Note.where(project_id: $project_id).order(:note_object_type).page(params[:page])
end

- (Object) new



6
7
8
# File 'app/controllers/notes_controller.rb', line 6

def new
  @note = Note.new(note_params)
end

- (Object) note_params (private)

Never trust parameters from the scary internet, only allow the white list through.



103
104
105
# File 'app/controllers/notes_controller.rb', line 103

def note_params
  params.require(:note).permit(:text, :note_object_id, :note_object_type, :note_object_attribute)
end

- (Object) search

GET /notes/search



66
67
68
69
70
71
72
# File 'app/controllers/notes_controller.rb', line 66

def search
  if params[:id].blank?
    redirect_to note_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to note_path(params[:id])
  end
end

- (Object) set_note (private)

Use callbacks to share common setup or constraints between actions.



98
99
100
# File 'app/controllers/notes_controller.rb', line 98

def set_note
  @note = Note.with_project_id($project_id).find(params[:id])
end

- (Object) update

PATCH/PUT /notes/1 PATCH/PUT /notes/1.json



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/notes_controller.rb', line 39

def update
  respond_to do |format|
    if @note.update(note_params)
      format.html { redirect_to @note.note_object.metamorphosize, notice: 'Note was successfully created.' }
      format.json { render json: @note, status: :created, location: @note }
    else
      format.html { redirect_to :back, notice: 'Note was NOT successfully updated.' }
      format.json { render json: @note.errors, status: :unprocessable_entity }
    end
  end
end