diff --git a/app/assets/javascripts/annotations.js.coffee b/app/assets/javascripts/annotations.js.coffee index 41b434f1c..ab448a4f6 100644 --- a/app/assets/javascripts/annotations.js.coffee +++ b/app/assets/javascripts/annotations.js.coffee @@ -8,8 +8,12 @@ proposalId = -> App.annotations = initialize: -> - new annotator.App() - .include(annotator.ui.main, {element: $(proposalSelector)[0]}) - .include(annotator.storage.http, {id: 1, prefix: ""}) + app = new annotator.App() + .include(annotator.ui.main, { element: $(proposalSelector)[0] }) + .include(annotator.storage.http, { prefix: "", urls: { search: "/annotations/search" } }) .include(proposalId) - .start(); \ No newline at end of file + + app.start() + .then( -> + app.annotations.load( { proposal_id: $(proposalSelector).data("id") } ) + ) \ No newline at end of file diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index e8267d593..05e48e64b 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -22,6 +22,12 @@ class AnnotationsController < ApplicationController render json: { status: :ok } end + def search + @annotations = Annotation.where(proposal_id: params[:proposal_id]) + annotations_hash = { total: @annotations.size, rows: @annotations } + render json: annotations_hash.to_json + end + private def annotation_params diff --git a/config/routes.rb b/config/routes.rb index d722f2e35..5f016ee0c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,7 +61,11 @@ Rails.application.routes.draw do end end - resources :annotations + resources :annotations do + collection do + get :search + end + end resources :users, only: [:show]