diff --git a/app/assets/javascripts/annotations.js.coffee b/app/assets/javascripts/annotations.js.coffee index 260b3252a..58d39efec 100644 --- a/app/assets/javascripts/annotations.js.coffee +++ b/app/assets/javascripts/annotations.js.coffee @@ -1,20 +1,20 @@ -proposalSelector = ".proposal-show" +legislationSelector = ".annotate" annotationsMetadata = -> return { beforeAnnotationCreated: (ann) -> - ann.proposal_id = $(proposalSelector).data("id"); - ann.user_id = $(proposalSelector).data("user-id"); + ann.legislation_id = $(legislationSelector).data("id"); + ann.user_id = $(legislationSelector).data("user-id"); }; App.annotations = initialize: -> app = new annotator.App() - .include(annotator.ui.main, { element: $(proposalSelector)[0] }) + .include(annotator.ui.main, { element: $(legislationSelector)[0] }) .include(annotator.storage.http, { prefix: "", urls: { search: "/annotations/search" } }) .include(annotationsMetadata) app.start() .then( -> - app.annotations.load( { proposal_id: $(proposalSelector).data("id") } ) + app.annotations.load( { legislation_id: $(legislationSelector).data("id") } ) ) \ No newline at end of file diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index 9717d8a99..56104448e 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -23,7 +23,7 @@ class AnnotationsController < ApplicationController end def search - @annotations = Annotation.where(proposal_id: params[:proposal_id]) + @annotations = Annotation.where(legislation_id: params[:legislation_id]) annotations_hash = { total: @annotations.size, rows: @annotations } render json: annotations_hash.to_json end @@ -34,6 +34,6 @@ class AnnotationsController < ApplicationController params .require(:annotation) .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) - .merge(proposal_id: params[:proposal_id], user_id: params[:user_id]) + .merge(legislation_id: params[:legislation_id], user_id: params[:user_id]) end end \ No newline at end of file diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 5c916dd0c..22fb55cbd 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -14,7 +14,6 @@ class Proposal < ActiveRecord::Base belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' has_many :comments, as: :commentable - has_many :annotations validates :title, presence: true validates :question, presence: true diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 6e8245c8d..70827d65e 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -6,11 +6,8 @@ social_description: @proposal.summary %> <% end %> <% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> - <% if current_user %> -
data-user-id=<%= current_user.id %>> - <% else %> -
- <% end %> + +
  diff --git a/db/migrate/20151215115319_add_legislation_id_to_annotations.rb b/db/migrate/20151215115319_add_legislation_id_to_annotations.rb new file mode 100644 index 000000000..fc415f0a8 --- /dev/null +++ b/db/migrate/20151215115319_add_legislation_id_to_annotations.rb @@ -0,0 +1,6 @@ +class AddLegislationIdToAnnotations < ActiveRecord::Migration + def change + remove_reference :annotations, :proposal + add_reference :annotations, :legislation, index: true, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index c46d99fd7..cf5c51e2e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151118160928) do +ActiveRecord::Schema.define(version: 20151215115319) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -54,13 +54,13 @@ ActiveRecord::Schema.define(version: 20151118160928) do t.string "quote" t.text "ranges" t.text "text" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "proposal_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "user_id" + t.integer "legislation_id" end - add_index "annotations", ["proposal_id"], name: "index_annotations_on_proposal_id", using: :btree + add_index "annotations", ["legislation_id"], name: "index_annotations_on_legislation_id", using: :btree add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree create_table "campaigns", force: :cascade do |t| @@ -396,7 +396,7 @@ ActiveRecord::Schema.define(version: 20151118160928) do add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree add_foreign_key "administrators", "users" - add_foreign_key "annotations", "proposals" + add_foreign_key "annotations", "legislations" add_foreign_key "annotations", "users" add_foreign_key "failed_census_calls", "users" add_foreign_key "flags", "users"