2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
class NotesController < ApplicationController
|
2019-11-26 17:03:43 -05:00
|
|
|
respond_to :html, :json, :js
|
2018-04-02 13:51:26 -04:00
|
|
|
before_action :member_only, :except => [:index, :show, :search]
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-07-02 21:04:29 -04:00
|
|
|
def search
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def index
|
2018-04-02 13:51:26 -04:00
|
|
|
@notes = Note.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
2017-04-23 15:26:23 -04:00
|
|
|
respond_with(@notes) do |format|
|
2017-04-23 15:54:33 -04:00
|
|
|
format.html { @notes = @notes.includes(:creator) }
|
2011-05-16 09:27:06 -04:00
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def show
|
2011-01-19 14:28:22 -05:00
|
|
|
@note = Note.find(params[:id])
|
2017-07-03 23:05:53 -04:00
|
|
|
respond_with(@note) do |format|
|
|
|
|
format.html { redirect_to(post_path(@note.post, anchor: "note-#{@note.id}")) }
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def create
|
2018-04-02 13:51:26 -04:00
|
|
|
@note = Note.create(note_params(:create))
|
2011-05-29 03:47:06 -04:00
|
|
|
respond_with(@note) do |fmt|
|
|
|
|
fmt.json do
|
2015-08-04 19:58:28 -04:00
|
|
|
if @note.errors.any?
|
|
|
|
render :json => {:success => false, :reasons => @note.errors.full_messages}.to_json, :status => 422
|
|
|
|
else
|
|
|
|
render :json => @note.to_json(:methods => [:html_id])
|
|
|
|
end
|
2011-05-29 03:47:06 -04:00
|
|
|
end
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def update
|
2011-01-19 14:28:22 -05:00
|
|
|
@note = Note.find(params[:id])
|
2018-04-02 13:51:26 -04:00
|
|
|
@note.update(note_params(:update))
|
2013-05-26 10:25:00 -04:00
|
|
|
respond_with(@note) do |format|
|
|
|
|
format.json do
|
2015-08-04 19:58:28 -04:00
|
|
|
if @note.errors.any?
|
|
|
|
render :json => {:success => false, :reasons => @note.errors.full_messages}.to_json, :status => 422
|
|
|
|
else
|
|
|
|
render :json => @note.to_json
|
|
|
|
end
|
2013-05-26 10:25:00 -04:00
|
|
|
end
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def destroy
|
2011-01-19 14:28:22 -05:00
|
|
|
@note = Note.find(params[:id])
|
2019-09-09 12:37:58 -04:00
|
|
|
@note.update(:is_active => false)
|
2011-01-19 14:28:22 -05:00
|
|
|
respond_with(@note)
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-19 14:28:22 -05:00
|
|
|
def revert
|
|
|
|
@note = Note.find(params[:id])
|
2016-10-10 06:24:49 -04:00
|
|
|
@version = @note.versions.find(params[:version_id])
|
2011-01-20 17:41:54 -05:00
|
|
|
@note.revert_to!(@version)
|
2011-01-19 14:28:22 -05:00
|
|
|
respond_with(@note)
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2011-05-16 09:27:06 -04:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def note_params(context)
|
|
|
|
permitted_params = %i[x y width height body]
|
|
|
|
permitted_params += %i[post_id html_id] if context == :create
|
2016-10-19 23:39:57 -04:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
params.require(:note).permit(permitted_params)
|
2016-10-19 23:39:57 -04:00
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|