Commit 172e3e9d authored by Ujvari Gergely's avatar Ujvari Gergely Committed by Randall Leeds

Blinking tabs on realtime updates

- Now if a realtime update arrives, the tab numbers are recalculated
- The new (or updated) annotations' parents  are marked with the _updatedAnnotation property
- The new blinkBuckets() function in the heatmap checks for these annotations and does the blinking in the relevant buckets and removes that property (so only one blinking will occur)
- This new property is transferred via the bridge plugin
parent 7733c035
......@@ -424,7 +424,7 @@ class App
user = if p? then "acct:" + p.username + "@" + p.provider else ''
unless data instanceof Array then data = [data]
$scope.$apply =>
if data.length > 0 then $scope.new_updates += 1
#if data.length > 0 then $scope.new_updates += 1
if $scope.socialView.name is 'single-player'
owndata = data.filter (d) -> d.user is user
......@@ -432,23 +432,54 @@ class App
else
$scope.applyUpdates action, data
$scope.markAnnotationUpdate = (data) =>
for annotation in data
# We need to flag the top level
if annotation.references?
container = annotator.threading.getContainer annotation.references[0]
if container?.message?
container.message._updatedAnnotation = true
# Temporary workarund to force publish changes
if annotator.plugins.Store?
annotator.plugins.Store._onLoadAnnotations [container.message]
else
annotation._updatedAnnotation = true
$scope.applyUpdates = (action, data) =>
switch action
when 'create'
# XXX: Temporary workaround until solving the race condition for annotationsLoaded event
# Between threading and bridge plugins
for annotation in data
annotator.plugins.Threading.thread annotation
$scope.markAnnotationUpdate data
$scope.$apply =>
if annotator.plugins.Store?
annotator.plugins.Store._onLoadAnnotations data
when 'update'
if annotator.plugins.Store?
annotator.plugins.Store._onLoadAnnotations data
$scope.markAnnotationUpdate data
annotator.plugins.Store._onLoadAnnotations data
when 'delete'
$scope.markAnnotationUpdate data
for annotation in data
#ToDo: only do this to existing annotations
container = annotator.threading.getContainer annotation.id
if container.message
container.message._clientdeleteonly = true
annotator.deleteAnnotation container.message
# Finally blink the changed tabs
$timeout =>
for p in annotator.providers
p.channel.notify
method: 'updateHeatmap'
for p in annotator.providers
p.channel.notify
method: 'blinkBuckets'
, 500
$timeout =>
$scope.initUpdater()
, 5000
......
......@@ -160,6 +160,14 @@ class Annotator.Guest extends Annotator
this.publish 'setVisibleHighlights', state
)
.bind('blinkBuckets', =>
@plugins.Heatmap.blinkBuckets()
)
.bind('updateHeatmap', =>
@plugins.Heatmap._scheduleUpdate()
)
scanDocument: (reason = "something happened") =>
try
console.log "Analyzing host frame, because " + reason + "..."
......
......@@ -427,6 +427,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
@index.forEach (b, i) =>
if @buckets[i].length > 0 or @isUpper(i) or @isLower(i)
buckets.push i
@bucketIndices = buckets
buckets
tabs.enter().append('div')
......@@ -488,6 +489,8 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
if @dynamicBucket
this._fillDynamicBucket()
@tabs = tabs
_fillDynamicBucket: =>
top = window.pageYOffset
bottom = top + $(window).innerHeight()
......@@ -503,6 +506,23 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
_getCommentBucket: => @index.length - 2
blinkBuckets: =>
for tab, index in @tabs[0]
bucket = @buckets[@bucketIndices[index]]
hasUpdate = false
for annotation in bucket
if annotation._updatedAnnotation?
hasUpdate = true
delete annotation._updatedAnnotation
unless hasUpdate then continue
element = $(tab)
element.toggle('fg_highlight', {color: 'lightblue'})
setTimeout ->
element.toggle('fg_highlight', {color: 'lightblue'})
, 500
isUpper: (i) => i == 1
isLower: (i) => i == @index.length - 3
isComment: (i) => i is @_getCommentBucket()
......
......@@ -89,7 +89,7 @@ class Hypothesis extends Annotator
# between the host page and the panel widget.
whitelist = [
'diffHTML', 'inject', 'quote', 'ranges', 'target', 'id', 'references',
'uri', 'diffCaseOnly', 'document'
'uri', 'diffCaseOnly', 'document', '_updatedAnnotation'
]
this.addPlugin 'Bridge',
gateway: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment