Calculate annotations weight and add weight css classes for color intensity
This commit is contained in:
@@ -153,6 +153,26 @@ App.LegislationAnnotatable =
|
||||
return
|
||||
), 100)
|
||||
|
||||
propotionalWeight: (v, max) ->
|
||||
Math.floor(v*5/(max+1)) + 1
|
||||
|
||||
addWeightClasses: ->
|
||||
annotationsLoaded: (annotations) ->
|
||||
return if annotations.length == 0
|
||||
weights = annotations.map (ann) -> ann.weight
|
||||
max_weight = Math.max.apply(null, weights)
|
||||
last_annotation = annotations[annotations.length - 1]
|
||||
|
||||
checkExist = setInterval((->
|
||||
if $("span[data-annotation-id='" + last_annotation.id + "']").length
|
||||
for annotation in annotations
|
||||
ann_weight = App.LegislationAnnotatable.propotionalWeight(annotation.weight, max_weight)
|
||||
el = $("span[data-annotation-id='" + annotation.id + "']")
|
||||
el.addClass('weight-' + ann_weight)
|
||||
clearInterval checkExist
|
||||
return
|
||||
), 100)
|
||||
|
||||
initialize: ->
|
||||
$(document).off("renderLegislationAnnotation").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments)
|
||||
$(document).off('click', '[data-annotation-id]').on('click', '[data-annotation-id]', App.LegislationAnnotatable.onClick)
|
||||
@@ -184,6 +204,7 @@ App.LegislationAnnotatable =
|
||||
editorExtensions: [App.LegislationAnnotatable.editorExtension]
|
||||
})
|
||||
.include(App.LegislationAnnotatable.scrollToAnchor)
|
||||
.include(App.LegislationAnnotatable.addWeightClasses)
|
||||
.include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } })
|
||||
|
||||
App.LegislationAnnotatable.app.start().then ->
|
||||
|
||||
@@ -103,6 +103,22 @@
|
||||
background: rgba(255, 255, 10, 0.2);
|
||||
}
|
||||
|
||||
.annotator-hl.weight-1 {
|
||||
background: rgba(255, 255, 10, 0.2);
|
||||
}
|
||||
.annotator-hl.weight-2 {
|
||||
background: rgba(255, 255, 10, 0.4);
|
||||
}
|
||||
.annotator-hl.weight-3 {
|
||||
background: rgba(255, 255, 10, 0.6);
|
||||
}
|
||||
.annotator-hl.weight-4 {
|
||||
background: rgba(255, 255, 10, 0.8);
|
||||
}
|
||||
.annotator-hl.weight-5 {
|
||||
background: rgba(255, 255, 10, 1);
|
||||
}
|
||||
|
||||
.current-annotation {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class Legislation::AnnotationsController < ApplicationController
|
||||
def search
|
||||
@annotations = @draft_version.annotations.order("LENGTH(quote) DESC")
|
||||
annotations_hash = { total: @annotations.size, rows: @annotations }
|
||||
render json: annotations_hash.to_json
|
||||
render json: annotations_hash.to_json(methods: :weight)
|
||||
end
|
||||
|
||||
def comments
|
||||
|
||||
@@ -51,4 +51,8 @@ class Legislation::Annotation < ActiveRecord::Base
|
||||
def title
|
||||
text[0..50]
|
||||
end
|
||||
|
||||
def weight
|
||||
comments_count + comments.sum(:cached_votes_total)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user