Se agregan anotaciones a propuestas existentes
This commit is contained in:
15
app/assets/javascripts/annotations.js.coffee
Normal file
15
app/assets/javascripts/annotations.js.coffee
Normal 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();
|
||||
@@ -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(){
|
||||
|
||||
@@ -6,4 +6,5 @@
|
||||
@import "admin";
|
||||
@import "layout";
|
||||
@import "participation";
|
||||
@import "c3";
|
||||
@import "c3";
|
||||
@import "annotator.min";
|
||||
19
app/controllers/annotations_controller.rb
Normal file
19
app/controllers/annotations_controller.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -40,6 +40,8 @@ module Abilities
|
||||
can :vote_featured, Proposal
|
||||
end
|
||||
|
||||
can :manage, Annotation
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
5
app/models/annotation.rb
Normal file
5
app/models/annotation.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Annotation < ActiveRecord::Base
|
||||
serialize :ranges, Array
|
||||
|
||||
belongs_to :proposal
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user