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 included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods inherited from ApplicationController

#digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #project_matches, #record_not_found, #set_project_from_params

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Methods included from InterceptApi

#intercept_api, #token_authenticate

Instance Method Details

- (Object) autocomplete



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/notes_controller.rb', line 90

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/notes_controller.rb', line 32

def create
  @note = Note.new(note_params)

  respond_to do |format|
    if @note.save
      format.html { redirect_to url_for(@note.note_object.metamorphosize),
                    notice: 'Note was successfully created.' }
      format.json { render json: @note, status: :created, location: @note }
    else
      format.html { redirect_back(fallback_location: (request.referer || root_path),
                                  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



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

def destroy
  @note.destroy
  respond_to do |format|
    # TODO: probably needs to be changed
    format.html { redirect_back(fallback_location: (request.referer || root_path),
                                notice:            'Note was successfully destroyed.') }
    format.json { head :no_content }
  end
end

- (Object) download

GET /notes/download



107
108
109
110
111
# File 'app/controllers/notes_controller.rb', line 107

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

- (Object) edit



26
27
28
# File 'app/controllers/notes_controller.rb', line 26

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

- (Object) index

GET /notes GET /notes.json GET /<model>/:id/notes.json



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/notes_controller.rb', line 9

def index
  respond_to do |format|
    format.html {
      @recent_objects = Note.where(project_id: sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @notes = Queries::Note::Filter.new(params).all
        .where(project_id: sessions_current_project_id).page(params[:page]).per(500)
    }
  end
end

- (Object) list



76
77
78
# File 'app/controllers/notes_controller.rb', line 76

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

- (Object) new



22
23
24
# File 'app/controllers/notes_controller.rb', line 22

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

- (Object) note_params (private)



119
120
121
122
# File 'app/controllers/notes_controller.rb', line 119

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

- (Object) search

GET /notes/search



81
82
83
84
85
86
87
88
# File 'app/controllers/notes_controller.rb', line 81

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)



115
116
117
# File 'app/controllers/notes_controller.rb', line 115

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

- (Object) update

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



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/notes_controller.rb', line 50

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