Se agregan anotaciones a propuestas existentes

This commit is contained in:
Abigail Sosa
2015-11-17 16:54:01 -07:00
committed by rgarcia
parent 0d8a233c22
commit 189a6426b1
29 changed files with 638 additions and 3 deletions

View File

@@ -0,0 +1,15 @@
proposalSelector = ".proposal-show"
proposalId = ->
return {
beforeAnnotationCreated: (ann) ->
ann.proposal_id = $(proposalSelector).data("id")
};
App.annotations =
initialize: ->
new annotator.App()
.include(annotator.ui.main, {element: $(proposalSelector)[0]})
.include(annotator.storage.http, {id: 1, prefix: ""})
.include(proposalId)
.start();

View File

@@ -29,9 +29,11 @@
//= require moderator_debates
//= require moderator_proposals
//= require prevent_double_submission
//= require annotator.min
//= require tags
//= require users
//= require votes
//= require annotations
var initialize_modules = function() {
@@ -44,6 +46,7 @@ var initialize_modules = function() {
App.CheckAllNone.initialize();
App.PreventDoubleSubmission.initialize();
App.IeAlert.initialize();
App.annotations.initialize();
};
$(function(){

View File

@@ -6,4 +6,5 @@
@import "admin";
@import "layout";
@import "participation";
@import "c3";
@import "c3";
@import "annotator.min";

View File

@@ -0,0 +1,19 @@
class AnnotationsController < ApplicationController
skip_before_action :verify_authenticity_token
load_and_authorize_resource
def create
@annotation = Annotation.new(annotation_params)
if @annotation.save
render json: @annotation.to_json
end
end
private
def annotation_params
params
.require(:annotation)
.permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset])
.merge(proposal_id: params[:proposal_id])
end
end

View File

@@ -32,6 +32,8 @@ module Abilities
can :comment_as_administrator, [Debate, Comment, Proposal]
can [:search, :create, :index, :destroy], ::Moderator
can :manage, Annotation
end
end
end

View File

@@ -40,6 +40,8 @@ module Abilities
can :vote_featured, Proposal
end
can :manage, Annotation
end
end
end

5
app/models/annotation.rb Normal file
View File

@@ -0,0 +1,5 @@
class Annotation < ActiveRecord::Base
serialize :ranges, Array
belongs_to :proposal
end

View File

@@ -14,6 +14,7 @@ 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,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 %>
<section class="proposal-show">
<section class="proposal-show annotate" data-id=<%= @proposal.id %>>
<div id="<%= dom_id(@proposal) %>" class="row">
<div class="small-12 medium-9 column">
<i class="icon-angle-left left"></i>&nbsp;