Class: NotesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- NotesController
- Defined in:
- app/controllers/notes_controller.rb
Instance Method Summary collapse
-
#api_index ⇒ Object
GET /api/v1/notes.
- #api_params ⇒ Object private
-
#api_show ⇒ Object
GET /api/v1/notes/:id.
- #autocomplete ⇒ Object
-
#create ⇒ Object
POST /notes POST /notes.json.
-
#destroy ⇒ Object
DELETE /notes/1 DELETE /notes/1.json.
-
#download ⇒ Object
GET /notes/download.
- #edit ⇒ Object
- #filter_params ⇒ Object private
-
#index ⇒ Object
GET /notes GET /notes.json GET /<model>/:id/notes.json.
- #list ⇒ Object
- #new ⇒ Object
- #note_params ⇒ Object private
-
#search ⇒ Object
GET /notes/search.
- #set_note ⇒ Object private
-
#update ⇒ Object
PATCH/PUT /notes/1 PATCH/PUT /notes/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_index ⇒ Object
GET /api/v1/notes
111 112 113 114 115 116 117 |
# File 'app/controllers/notes_controller.rb', line 111 def api_index @notes = Queries::Note::Filter.new(api_params).all .order('notes.id') .page(params[:page]) .per(params[:per]) render '/notes/api/v1/index' end |
#api_params ⇒ Object (private)
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/controllers/notes_controller.rb', line 139 def api_params params.permit( :text, :note_object_id, :note_object_type, :object_global_id, note_object_id: [], note_object_type: [], ).to_h .merge(shallow_object_global_param) .merge(project_id: sessions_current_project_id) end |
#api_show ⇒ Object
GET /api/v1/notes/:id
120 121 122 |
# File 'app/controllers/notes_controller.rb', line 120 def api_show render '/notes/api/v1/show' end |
#autocomplete ⇒ Object
98 99 100 101 |
# File 'app/controllers/notes_controller.rb', line 98 def autocomplete render json: {} and return if params[:term].blank? @notes = Queries::Note::Autocomplete.new(params.require(:term), project_id: sessions_current_project_id).autocomplete end |
#create ⇒ Object
POST /notes POST /notes.json
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/notes_controller.rb', line 36 def create @note = Note.new(note_params) respond_to do |format| if @note.save format.html { redirect_to url_for(@note.note_object.), 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 |
#destroy ⇒ Object
DELETE /notes/1 DELETE /notes/1.json
70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/notes_controller.rb', line 70 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 |
#download ⇒ Object
GET /notes/download
104 105 106 107 108 |
# File 'app/controllers/notes_controller.rb', line 104 def download send_data Export::Download.generate_csv(Note.where(project_id: sessions_current_project_id)), type: 'text', filename: "notes_#{DateTime.now}.csv" end |
#edit ⇒ Object
30 31 32 |
# File 'app/controllers/notes_controller.rb', line 30 def edit @note = Note.find_by_id(params[:id]). end |
#filter_params ⇒ Object (private)
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/notes_controller.rb', line 126 def filter_params params.permit( :text, :note_object_id, :note_object_type, :object_global_id, note_object_id: [], note_object_type: [], ).to_h .merge(shallow_object_global_param) .merge(project_id: sessions_current_project_id) end |
#index ⇒ Object
GET /notes GET /notes.json GET /<model>/:id/notes.json
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/notes_controller.rb', line 11 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(filter_params) .all .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
80 81 82 |
# File 'app/controllers/notes_controller.rb', line 80 def list @notes = Note.where(project_id: sessions_current_project_id).order(:note_object_type).page(params[:page]) end |
#new ⇒ Object
26 27 28 |
# File 'app/controllers/notes_controller.rb', line 26 def new @note = Note.new(note_params) end |
#note_params ⇒ Object (private)
156 157 158 159 160 |
# File 'app/controllers/notes_controller.rb', line 156 def note_params params.require(:note).permit( :text, :note_object_id, :note_object_type, :note_object_attribute, :annotated_global_entity) end |
#search ⇒ Object
GET /notes/search
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/notes_controller.rb', line 85 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 if @note = Note.find(params[:id]) redirect_to url_for(@note.note_object.) else redirect_to note_path, notice: 'You must select an item from the list with a click or tab press before clicking show.' end end end |
#set_note ⇒ Object (private)
152 153 154 |
# File 'app/controllers/notes_controller.rb', line 152 def set_note @note = Note.where(project_id: sessions_current_project_id).find(params[:id]) end |
#update ⇒ Object
PATCH/PUT /notes/1 PATCH/PUT /notes/1.json
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/notes_controller.rb', line 54 def update respond_to do |format| if @note.update(note_params) format.html { redirect_to url_for(@note.note_object.), 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 |