Class: Decidim::Notify::ConversationsController
- Inherits:
-
ApplicationController
- Object
- Components::BaseController
- ApplicationController
- Decidim::Notify::ConversationsController
- Includes:
- Broadcasts, NeedsAjaxRescue, FormFactory
- Defined in:
- app/controllers/decidim/notify/conversations_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/decidim/notify/conversations_controller.rb', line 21 def create :create, :notes @form = form(NoteForm).from_params(params) CreateNote.call(@form) do on(:ok) do |note, new_chapter| broadcast_create_chapter new_chapter if new_chapter broadcast_create_note note render json: { message: "✔" } end on(:invalid) do || render json: { message: I18n.t("decidim.notify.conversations.create.error", message: ) }, status: :unprocessable_entity end end end |
#destroy ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/decidim/notify/conversations_controller.rb', line 55 def destroy :destroy, :notes DeleteNote.call(params[:id]) do on(:ok) do broadcast_destroy_note params[:id] render json: { message: "✔" } end on(:invalid) do || render json: { message: I18n.t("decidim.notify.conversations.destroy.error", message: ) }, status: :unprocessable_entity end end end |
#index ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/controllers/decidim/notify/conversations_controller.rb', line 12 def index return render :private unless allowed_to? :index, :notes @unclassified = Chapter.new(notes: unclassified_notes) @participants = Author.for(current_component).participants @note_takers = Author.for(current_component).note_takers @form = form(NoteForm).instance end |
#update ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/decidim/notify/conversations_controller.rb', line 38 def update :update, :notes @form = form(NoteForm).from_params(params) UpdateNote.call(@form) do on(:ok) do |note, new_chapter| broadcast_create_chapter new_chapter if new_chapter broadcast_update_note note render json: { message: "✔" } end on(:invalid) do || render json: { message: I18n.t("decidim.notify.conversations.update.error", message: ) }, status: :unprocessable_entity end end end |
#users ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/decidim/notify/conversations_controller.rb', line 69 def users :create, :notes respond_to do |format| format.json do if (term = params[:term].to_s).present? query = Author.for(current_component).joins(:user) query = query.where("decidim_notify_authors.code=:code OR decidim_users.name ILIKE :term OR decidim_users.nickname ILIKE :term", code: term.to_i, term: "%#{term}%") render json: query.all.collect { |u| { id: u.code, name: u.name, avatar: u.attached_uploader(:avatar).path, nickname: u.nickname, text: format_user_name(u) } } else render json: [] end end end end |