annotates legislations instead of proposals

This commit is contained in:
rgarcia
2015-12-15 13:08:53 +01:00
parent f2c14968f3
commit 60d6f1c41b
6 changed files with 21 additions and 19 deletions

View File

@@ -1,20 +1,20 @@
proposalSelector = ".proposal-show" legislationSelector = ".annotate"
annotationsMetadata = -> annotationsMetadata = ->
return { return {
beforeAnnotationCreated: (ann) -> beforeAnnotationCreated: (ann) ->
ann.proposal_id = $(proposalSelector).data("id"); ann.legislation_id = $(legislationSelector).data("id");
ann.user_id = $(proposalSelector).data("user-id"); ann.user_id = $(legislationSelector).data("user-id");
}; };
App.annotations = App.annotations =
initialize: -> initialize: ->
app = new annotator.App() 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(annotator.storage.http, { prefix: "", urls: { search: "/annotations/search" } })
.include(annotationsMetadata) .include(annotationsMetadata)
app.start() app.start()
.then( -> .then( ->
app.annotations.load( { proposal_id: $(proposalSelector).data("id") } ) app.annotations.load( { legislation_id: $(legislationSelector).data("id") } )
) )

View File

@@ -23,7 +23,7 @@ class AnnotationsController < ApplicationController
end end
def search 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 } annotations_hash = { total: @annotations.size, rows: @annotations }
render json: annotations_hash.to_json render json: annotations_hash.to_json
end end
@@ -34,6 +34,6 @@ class AnnotationsController < ApplicationController
params params
.require(:annotation) .require(:annotation)
.permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) .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
end end

View File

@@ -14,7 +14,6 @@ class Proposal < ActiveRecord::Base
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
has_many :comments, as: :commentable has_many :comments, as: :commentable
has_many :annotations
validates :title, presence: true validates :title, presence: true
validates :question, presence: true validates :question, presence: true

View File

@@ -6,11 +6,8 @@
social_description: @proposal.summary %> social_description: @proposal.summary %>
<% end %> <% end %>
<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> <% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %>
<% if current_user %>
<section class="proposal-show annotate" data-id=<%= @proposal.id %> data-user-id=<%= current_user.id %>> <section class="proposal-show">
<% else %>
<section class="proposal-show">
<% end %>
<div id="<%= dom_id(@proposal) %>" class="row"> <div id="<%= dom_id(@proposal) %>" class="row">
<div class="small-12 medium-9 column"> <div class="small-12 medium-9 column">
<i class="icon-angle-left left"></i>&nbsp; <i class="icon-angle-left left"></i>&nbsp;

View File

@@ -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

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -54,13 +54,13 @@ ActiveRecord::Schema.define(version: 20151118160928) do
t.string "quote" t.string "quote"
t.text "ranges" t.text "ranges"
t.text "text" t.text "text"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "proposal_id"
t.integer "user_id" t.integer "user_id"
t.integer "legislation_id"
end 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 add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree
create_table "campaigns", force: :cascade do |t| 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_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 "administrators", "users"
add_foreign_key "annotations", "proposals" add_foreign_key "annotations", "legislations"
add_foreign_key "annotations", "users" add_foreign_key "annotations", "users"
add_foreign_key "failed_census_calls", "users" add_foreign_key "failed_census_calls", "users"
add_foreign_key "flags", "users" add_foreign_key "flags", "users"