Show annotation context in annotation page
Only works with quotes within the same html node for now
This commit is contained in:
@@ -14,7 +14,7 @@ class Legislation::Annotation < ActiveRecord::Base
|
|||||||
validates :draft_version, presence: true
|
validates :draft_version, presence: true
|
||||||
validates :author, presence: true
|
validates :author, presence: true
|
||||||
|
|
||||||
before_save :store_range
|
before_save :store_range, :store_context
|
||||||
after_create :create_first_comment
|
after_create :create_first_comment
|
||||||
|
|
||||||
def store_range
|
def store_range
|
||||||
@@ -24,6 +24,15 @@ class Legislation::Annotation < ActiveRecord::Base
|
|||||||
self.range_end_offset = ranges.first["endOffset"]
|
self.range_end_offset = ranges.first["endOffset"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def store_context
|
||||||
|
html = draft_version.body_html
|
||||||
|
doc = Nokogiri::HTML(html)
|
||||||
|
selector = "/#{range_start}"
|
||||||
|
text = doc.xpath(selector).text
|
||||||
|
text[quote] = "<span class=annotator-hl>#{quote}</span>"
|
||||||
|
self.context = text
|
||||||
|
end
|
||||||
|
|
||||||
def create_first_comment
|
def create_first_comment
|
||||||
comments.create(body: self.text, user: self.author)
|
comments.create(body: self.text, user: self.author)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<div class="comment-section">
|
<div class="comment-section">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 medium-10 column legislation-comment">
|
<div class="small-12 medium-10 column legislation-comment">
|
||||||
<%= @annotation.quote %>
|
<%= @annotation.context.html_safe || @annotation.quote %>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-12 medium-2 column legislation-comment">
|
<div class="small-12 medium-2 column legislation-comment">
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddContextForLegislationAnnotations < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :legislation_annotations, :context, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -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: 20170125093101) do
|
ActiveRecord::Schema.define(version: 20170210083026) 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"
|
||||||
@@ -339,6 +339,7 @@ ActiveRecord::Schema.define(version: 20170125093101) do
|
|||||||
t.integer "range_start_offset"
|
t.integer "range_start_offset"
|
||||||
t.string "range_end"
|
t.string "range_end"
|
||||||
t.integer "range_end_offset"
|
t.integer "range_end_offset"
|
||||||
|
t.text "context"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "legislation_annotations", ["author_id"], name: "index_legislation_annotations_on_author_id", using: :btree
|
add_index "legislation_annotations", ["author_id"], name: "index_legislation_annotations_on_author_id", using: :btree
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ describe Legislation::AnnotationsController do
|
|||||||
post :create, process_id: @process.id,
|
post :create, process_id: @process.id,
|
||||||
draft_version_id: @draft_version.id,
|
draft_version_id: @draft_version.id,
|
||||||
legislation_annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"ipsum",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
}
|
}
|
||||||
expect(Ahoy::Event.where(name: :legislation_annotation_created).count).to eq 1
|
expect(Ahoy::Event.where(name: :legislation_annotation_created).count).to eq 1
|
||||||
@@ -30,8 +30,8 @@ describe Legislation::AnnotationsController do
|
|||||||
post :create, process_id: @process.id,
|
post :create, process_id: @process.id,
|
||||||
draft_version_id: @final_version.id,
|
draft_version_id: @final_version.id,
|
||||||
legislation_annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"ipsum",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +45,8 @@ describe Legislation::AnnotationsController do
|
|||||||
xhr :post, :create, process_id: @process.id,
|
xhr :post, :create, process_id: @process.id,
|
||||||
draft_version_id: @draft_version.id,
|
draft_version_id: @draft_version.id,
|
||||||
legislation_annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"ipsum",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
}
|
}
|
||||||
end.to change { @draft_version.annotations.count }.by(1)
|
end.to change { @draft_version.annotations.count }.by(1)
|
||||||
@@ -60,8 +60,8 @@ describe Legislation::AnnotationsController do
|
|||||||
xhr :post, :create, process_id: @process.id,
|
xhr :post, :create, process_id: @process.id,
|
||||||
draft_version_id: @draft_version.id,
|
draft_version_id: @draft_version.id,
|
||||||
legislation_annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"ipsum",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
}
|
}
|
||||||
end.to_not change { @draft_version.annotations.count }
|
end.to_not change { @draft_version.annotations.count }
|
||||||
@@ -74,8 +74,8 @@ describe Legislation::AnnotationsController do
|
|||||||
xhr :post, :create, process_id: @process.id,
|
xhr :post, :create, process_id: @process.id,
|
||||||
draft_version_id: @draft_version.id,
|
draft_version_id: @draft_version.id,
|
||||||
legislation_annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"ipsum",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}].to_json,
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}].to_json,
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
}
|
}
|
||||||
end.to change { @draft_version.annotations.count }.by(1)
|
end.to change { @draft_version.annotations.count }.by(1)
|
||||||
@@ -83,16 +83,16 @@ describe Legislation::AnnotationsController do
|
|||||||
|
|
||||||
it 'should create a new comment on an existing annotation when range is the same' do
|
it 'should create a new comment on an existing annotation when range is the same' do
|
||||||
annotation = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation",
|
annotation = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation",
|
||||||
ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}],
|
ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}],
|
||||||
range_start: "/p[1]", range_start_offset: 5, range_end: "/p[1]", range_end_offset: 10)
|
range_start: "/p[1]", range_start_offset: 6, range_end: "/p[1]", range_end_offset: 11)
|
||||||
sign_in @user
|
sign_in @user
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
xhr :post, :create, process_id: @process.id,
|
xhr :post, :create, process_id: @process.id,
|
||||||
draft_version_id: @draft_version.id,
|
draft_version_id: @draft_version.id,
|
||||||
legislation_annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"ipsum",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
}
|
}
|
||||||
end.to_not change { @draft_version.annotations.count }
|
end.to_not change { @draft_version.annotations.count }
|
||||||
|
|||||||
@@ -505,7 +505,19 @@ FactoryGirl.define do
|
|||||||
changelog "What changed in this version"
|
changelog "What changed in this version"
|
||||||
status "draft"
|
status "draft"
|
||||||
final_version false
|
final_version false
|
||||||
body "Body of the legislation text"
|
body <<-LOREM_IPSUM
|
||||||
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
|
||||||
|
|
||||||
|
Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id.
|
||||||
|
|
||||||
|
His audiam deserunt in, eum ubique voluptatibus te. In reque dicta usu. Ne rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata at quo, insolens complectitur te eos, ea pri dico munere propriae. Vel ferri facilis ut, qui paulo ridens praesent ad. Possim alterum qui cu. Accusamus consulatu ius te, cu decore soleat appareat usu.
|
||||||
|
|
||||||
|
Est ei erat mucius quaeque. Ei his quas phaedrum, efficiantur mediocritatem ne sed, hinc oratio blandit ei sed. Blandit gloriatur eam et. Brute noluisse per et, verear disputando neglegentur at quo. Sea quem legere ei, unum soluta ne duo. Ludus complectitur quo te, ut vide autem homero pro.
|
||||||
|
|
||||||
|
Vis id minim dicant sensibus. Pri aliquip conclusionemque ad, ad malis evertitur torquatos his. Has ei solum harum reprimique, id illum saperet tractatos his. Ei omnis soleat antiopam quo. Ad augue inani postulant mel, mel ea qualisque forensibus.
|
||||||
|
|
||||||
|
Lorem salutandi eu mea, eam in soleat iriure assentior. Tamquam lobortis id qui. Ea sanctus democritum mei, per eu alterum electram adversarium. Ea vix probo dicta iuvaret, posse epicurei suavitate eam an, nam et vidit menandri. Ut his accusata petentium.
|
||||||
|
LOREM_IPSUM
|
||||||
|
|
||||||
trait :published do
|
trait :published do
|
||||||
status "published"
|
status "published"
|
||||||
@@ -520,12 +532,12 @@ FactoryGirl.define do
|
|||||||
draft_version factory: :legislation_draft_version
|
draft_version factory: :legislation_draft_version
|
||||||
author factory: :user
|
author factory: :user
|
||||||
quote "ipsum"
|
quote "ipsum"
|
||||||
text "Loremp ipsum dolor"
|
text "a comment"
|
||||||
ranges [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}]
|
ranges [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}]
|
||||||
range_start "/div[1]"
|
range_start "/p[1]"
|
||||||
range_start_offset 5
|
range_start_offset 6
|
||||||
range_end "/div[1]"
|
range_end "/p[1]"
|
||||||
range_end_offset 10
|
range_end_offset 11
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :legislation_question, class: 'Legislation::Question' do
|
factory :legislation_question, class: 'Legislation::Question' do
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ feature 'Legislation Draft Versions' do
|
|||||||
|
|
||||||
scenario 'Visit as anonymous' do
|
scenario 'Visit as anonymous' do
|
||||||
logout
|
logout
|
||||||
draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
|
draft_version = create(:legislation_draft_version, :published)
|
||||||
|
|
||||||
visit legislation_process_draft_version_path(draft_version.process, draft_version)
|
visit legislation_process_draft_version_path(draft_version.process, draft_version)
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ feature 'Legislation Draft Versions' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Create' do
|
scenario 'Create' do
|
||||||
draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
|
draft_version = create(:legislation_draft_version, :published)
|
||||||
|
|
||||||
visit legislation_process_draft_version_path(draft_version.process, draft_version)
|
visit legislation_process_draft_version_path(draft_version.process, draft_version)
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ feature 'Legislation Draft Versions' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario 'View annotations and comments' do
|
scenario 'View annotations and comments' do
|
||||||
draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
|
draft_version = create(:legislation_draft_version, :published)
|
||||||
annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}])
|
annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}])
|
||||||
annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>12, "end"=>"/p[1]", "endOffset"=>19}])
|
annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>12, "end"=>"/p[1]", "endOffset"=>19}])
|
||||||
|
|
||||||
@@ -187,8 +187,8 @@ feature 'Legislation Draft Versions' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Publish new comment for an annotation from comments box" do
|
scenario "Publish new comment for an annotation from comments box" do
|
||||||
draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
|
draft_version = create(:legislation_draft_version, :published)
|
||||||
annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}])
|
annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}])
|
||||||
|
|
||||||
visit legislation_process_draft_version_path(draft_version.process, draft_version)
|
visit legislation_process_draft_version_path(draft_version.process, draft_version)
|
||||||
|
|
||||||
@@ -205,25 +205,25 @@ feature 'Legislation Draft Versions' do
|
|||||||
|
|
||||||
context "Annotations page" do
|
context "Annotations page" do
|
||||||
background do
|
background do
|
||||||
@draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
|
@draft_version = create(:legislation_draft_version, :published)
|
||||||
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "first quote")
|
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum", ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}])
|
||||||
@annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "second quote")
|
@annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", ranges: [{"start"=>"/p[3]", "startOffset"=>6, "end"=>"/p[3]", "endOffset"=>11}])
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "See all annotations for a draft version" do
|
scenario "See all annotations for a draft version" do
|
||||||
visit legislation_process_draft_version_annotations_path(@draft_version.process, @draft_version)
|
visit legislation_process_draft_version_annotations_path(@draft_version.process, @draft_version)
|
||||||
|
|
||||||
expect(page).to have_content "first quote"
|
expect(page).to have_content "ipsum"
|
||||||
expect(page).to have_content "second quote"
|
expect(page).to have_content "audiam"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "switching versions" do
|
context "switching versions" do
|
||||||
background do
|
background do
|
||||||
@process = create(:legislation_process)
|
@process = create(:legislation_process)
|
||||||
@draft_version_1 = create(:legislation_draft_version, :published, process: @process, title: "Version 1", body: Faker::Lorem.paragraph)
|
@draft_version_1 = create(:legislation_draft_version, :published, process: @process, title: "Version 1", body: "Text with quote for version 1")
|
||||||
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version_1, text: "annotation for version 1", quote: "quote for version 1")
|
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version_1, text: "annotation for version 1", quote: "quote for version 1", ranges: [{"start"=>"/p[1]", "startOffset"=>11, "end"=>"/p[1]", "endOffset"=>30}])
|
||||||
@draft_version_2 = create(:legislation_draft_version, :published, process: @process, title: "Version 2", body: Faker::Lorem.paragraph)
|
@draft_version_2 = create(:legislation_draft_version, :published, process: @process, title: "Version 2", body: "Text with quote for version 2")
|
||||||
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version_2, text: "annotation for version 2", quote: "quote for version 2")
|
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version_2, text: "annotation for version 2", quote: "quote for version 2", ranges: [{"start"=>"/p[1]", "startOffset"=>11, "end"=>"/p[1]", "endOffset"=>30}])
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "without js" do
|
scenario "without js" do
|
||||||
@@ -251,17 +251,18 @@ feature 'Legislation Draft Versions' do
|
|||||||
|
|
||||||
context "Annotation comments page" do
|
context "Annotation comments page" do
|
||||||
background do
|
background do
|
||||||
@draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
|
@draft_version = create(:legislation_draft_version, :published)
|
||||||
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "first quote")
|
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum", ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}])
|
||||||
@annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "second quote")
|
@annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", ranges: [{"start"=>"/p[3]", "startOffset"=>6, "end"=>"/p[3]", "endOffset"=>11}])
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "See one annotation with replies for a draft version" do
|
scenario "See one annotation with replies for a draft version" do
|
||||||
visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation_2)
|
visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation_2)
|
||||||
|
|
||||||
expect(page).to_not have_content "first quote"
|
expect(page).to_not have_content "ipsum"
|
||||||
expect(page).to have_content "second quote"
|
|
||||||
expect(page).to_not have_content "my annotation"
|
expect(page).to_not have_content "my annotation"
|
||||||
|
|
||||||
|
expect(page).to have_content "audiam"
|
||||||
expect(page).to have_content "my other annotation"
|
expect(page).to have_content "my other annotation"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user