From bb5da1af7f8f189f110ea26b0a2d082130d060a6 Mon Sep 17 00:00:00 2001 From: Abigail Sosa Date: Wed, 18 Nov 2015 09:11:28 -0700 Subject: [PATCH] Se agrega usuario autor a cada anotacion --- app/assets/javascripts/annotations.js.coffee | 7 ++++--- app/controllers/annotations_controller.rb | 2 +- app/models/annotation.rb | 1 + app/views/proposals/show.html.erb | 2 +- db/migrate/20151118160928_add_user_to_annotations.rb | 5 +++++ db/schema.rb | 7 +++++-- 6 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20151118160928_add_user_to_annotations.rb diff --git a/app/assets/javascripts/annotations.js.coffee b/app/assets/javascripts/annotations.js.coffee index ab448a4f6..260b3252a 100644 --- a/app/assets/javascripts/annotations.js.coffee +++ b/app/assets/javascripts/annotations.js.coffee @@ -1,9 +1,10 @@ proposalSelector = ".proposal-show" -proposalId = -> +annotationsMetadata = -> return { beforeAnnotationCreated: (ann) -> - ann.proposal_id = $(proposalSelector).data("id") + ann.proposal_id = $(proposalSelector).data("id"); + ann.user_id = $(proposalSelector).data("user-id"); }; App.annotations = @@ -11,7 +12,7 @@ App.annotations = app = new annotator.App() .include(annotator.ui.main, { element: $(proposalSelector)[0] }) .include(annotator.storage.http, { prefix: "", urls: { search: "/annotations/search" } }) - .include(proposalId) + .include(annotationsMetadata) app.start() .then( -> diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index 05e48e64b..9717d8a99 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -34,6 +34,6 @@ class AnnotationsController < ApplicationController params .require(:annotation) .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) - .merge(proposal_id: params[:proposal_id]) + .merge(proposal_id: params[:proposal_id], user_id: params[:user_id]) end end \ No newline at end of file diff --git a/app/models/annotation.rb b/app/models/annotation.rb index 9e9ee9b5e..b747efd3b 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -2,4 +2,5 @@ class Annotation < ActiveRecord::Base serialize :ranges, Array belongs_to :proposal + belongs_to :user end \ No newline at end of file diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 1296f0d33..eb49837e6 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -6,7 +6,7 @@ social_description: @proposal.summary %> <% end %> <% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> -
> +
data-user-id=<%= current_user.id %>>
  diff --git a/db/migrate/20151118160928_add_user_to_annotations.rb b/db/migrate/20151118160928_add_user_to_annotations.rb new file mode 100644 index 000000000..0594a4bf3 --- /dev/null +++ b/db/migrate/20151118160928_add_user_to_annotations.rb @@ -0,0 +1,5 @@ +class AddUserToAnnotations < ActiveRecord::Migration + def change + add_reference :annotations, :user, index: true, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 16a002e04..a19695fae 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: 20151111202657) do +ActiveRecord::Schema.define(version: 20151118160928) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -57,9 +57,11 @@ ActiveRecord::Schema.define(version: 20151111202657) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "proposal_id" + t.integer "user_id" end add_index "annotations", ["proposal_id"], name: "index_annotations_on_proposal_id", using: :btree + add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree create_table "campaigns", force: :cascade do |t| t.string "name" @@ -182,7 +184,7 @@ ActiveRecord::Schema.define(version: 20151111202657) do create_table "locks", force: :cascade do |t| t.integer "user_id" t.integer "tries", default: 0 - t.datetime "locked_until", default: '2000-01-01 08:01:01', null: false + t.datetime "locked_until", default: '2000-01-01 07:01:01', null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -388,6 +390,7 @@ ActiveRecord::Schema.define(version: 20151111202657) do add_foreign_key "administrators", "users" add_foreign_key "annotations", "proposals" + add_foreign_key "annotations", "users" add_foreign_key "failed_census_calls", "users" add_foreign_key "flags", "users" add_foreign_key "identities", "users"