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 = ->
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") } )
)

View File

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

View File

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

View File

@@ -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 %>
<section class="proposal-show annotate" data-id=<%= @proposal.id %> data-user-id=<%= current_user.id %>>
<% else %>
<section class="proposal-show">
<% end %>
<div id="<%= dom_id(@proposal) %>" class="row">
<div class="small-12 medium-9 column">
<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.
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"
@@ -56,11 +56,11 @@ ActiveRecord::Schema.define(version: 20151118160928) do
t.text "text"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "proposal_id"
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"