Commit 085ec139 authored by Kristof Csillag's avatar Kristof Csillag

Merge pull request #1100 from hypothesis/1091-scope-cleanup-1

Scope cleanup part 1

Fixes #1099
parents 56401850 bfbad4ad
...@@ -674,11 +674,13 @@ class Viewer ...@@ -674,11 +674,13 @@ class Viewer
annotator annotator
) -> ) ->
{providers, threading} = annotator {providers, threading} = annotator
$scope.view = 'Screen' $rootScope.view = 'Screen'
$scope.sort = 'Newest' $scope.sort = 'Newest'
$scope.views = [ $scope.views = [
{view:'Screen'} {view:'Screen'}
{view:'Document'}] {view:'Document'}
{view:"Comments"}
]
$scope.sorts = [ $scope.sorts = [
{sort:'Newest'} {sort:'Newest'}
{sort:'Oldest'} {sort:'Oldest'}
...@@ -704,20 +706,29 @@ class Viewer ...@@ -704,20 +706,29 @@ class Viewer
method: 'scrollTo' method: 'scrollTo'
params: annotation.$$tag params: annotation.$$tag
$scope.applyview = (view) -> $scope.applyView = (view) ->
$scope.view = view switch view
if $scope.view == 'Screen' when 'Screen'
annotator.updateViewer($rootScope.annotations) # Go over all providers, and switch them to dynamic mode
# They will, in turn, call back updateView
# with the right set of annotations
for p in providers
p.channel.notify method: 'setDynamicBucketMode', params: true
break
if $scope.view == 'Document' when 'Document'
annotator.updateViewer(annotator.plugins.Store.annotations) for p in providers
p.channel.notify method: 'showAll'
break
for p in providers when 'Comments'
p.channel.notify for p in providers
method: 'setDynamicBucketMode' p.channel.notify method: 'showComments'
params: $scope.view == 'Screen'
else
throw new Error "Unknown view requested: " + view
$scope.applysort = (sort) -> $scope.applySort = (sort) ->
$scope.sort = sort $scope.sort = sort
if $scope.sort == 'Newest' if $scope.sort == 'Newest'
$scope.predicate = 'updated' $scope.predicate = 'updated'
......
...@@ -132,6 +132,24 @@ class Annotator.Guest extends Annotator ...@@ -132,6 +132,24 @@ class Annotator.Guest extends Annotator
} }
) )
.bind('showComments', => @plugins.Heatmap.commentClick())
.bind('showAll', =>
# Switch off dynamic mode on the heatmap
if @plugins.Heatmap
@plugins.Heatmap.dynamicBucket = false
# Collect all successfully attached annotations
annotations = []
for page, anchors of @anchors
for anchor in anchors
unless anchor.annotation in annotations
annotations.push anchor.annotation
# Show all the annotations
@showViewer "Document", annotations
)
.bind('setTool', (ctx, name) => .bind('setTool', (ctx, name) =>
this.setTool name this.setTool name
this.publish 'setTool', name this.publish 'setTool', name
...@@ -164,11 +182,21 @@ class Annotator.Guest extends Annotator ...@@ -164,11 +182,21 @@ class Annotator.Guest extends Annotator
_setupViewer: -> this _setupViewer: -> this
_setupEditor: -> this _setupEditor: -> this
showViewer: (annotations) => showViewer: (viewName, annotations) =>
@panel?.notify method: "showViewer", params: (a.id for a in annotations) @panel?.notify
method: "showViewer"
params: [
viewName
(a.id for a in annotations)
]
updateViewer: (annotations) => updateViewer: (viewName, annotations) =>
@panel?.notify method: "updateViewer", params: (a.id for a in annotations) @panel?.notify
method: "updateViewer"
params: [
viewName
(a.id for a in annotations)
]
showEditor: (annotation) => @plugins.Bridge.showEditor annotation showEditor: (annotation) => @plugins.Bridge.showEditor annotation
...@@ -254,7 +282,7 @@ class Annotator.Guest extends Annotator ...@@ -254,7 +282,7 @@ class Annotator.Guest extends Annotator
return unless (@tool is 'highlight') or @visibleHighlights and @noBack return unless (@tool is 'highlight') or @visibleHighlights and @noBack
# Tell sidebar to show the viewer for these annotations # Tell sidebar to show the viewer for these annotations
this.showViewer annotations this.showViewer "Selection", annotations
# We have already prevented closing the sidebar, now reset this flag # We have already prevented closing the sidebar, now reset this flag
@noBack = false @noBack = false
......
...@@ -463,10 +463,12 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -463,10 +463,12 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
else if (@isLower bucket) else if (@isLower bucket)
@dynamicBucket = true @dynamicBucket = true
@_jumpMinMax @buckets[bucket], "down" @_jumpMinMax @buckets[bucket], "down"
else if (@isComment bucket)
@commentClick()
else else
d3.event.stopPropagation() d3.event.stopPropagation()
@dynamicBucket = false @dynamicBucket = false
annotator.showViewer @buckets[bucket] annotator.showViewer "Tab", @buckets[bucket]
tabs.exit().remove() tabs.exit().remove()
...@@ -498,8 +500,15 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -498,8 +500,15 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
acc acc
, [] , []
# $.merge visible, @annotator.comments # $.merge visible, @annotator.comments
@annotator.updateViewer visible @annotator.updateViewer "Screen", visible
_getCommentBucket: => @index.length - 2
isUpper: (i) => i == 1 isUpper: (i) => i == 1
isLower: (i) => i == @index.length - 3 isLower: (i) => i == @index.length - 3
isComment: (i) => i == @index.length - 2 isComment: (i) => i is @_getCommentBucket()
# Simulate clicking on the comments tab
commentClick: =>
@dynamicBucket = false
annotator.showViewer "Comments", @buckets[@_getCommentBucket()]
...@@ -216,13 +216,15 @@ class Hypothesis extends Annotator ...@@ -216,13 +216,15 @@ class Hypothesis extends Annotator
$rootScope.$apply => this.show() $rootScope.$apply => this.show()
) )
.bind('showViewer', (ctx, ids=[]) => .bind('showViewer', (ctx, [viewName, ids]) =>
ids ?= []
return unless this.discardDrafts() return unless this.discardDrafts()
$rootScope.$apply => this.showViewer this._getAnnotationsFromIDs ids $rootScope.$apply => this.showViewer viewName, this._getAnnotationsFromIDs ids
) )
.bind('updateViewer', (ctx, ids=[]) => .bind('updateViewer', (ctx, [viewName, ids]) =>
$rootScope.$apply => this.updateViewer this._getAnnotationsFromIDs ids ids ?= []
$rootScope.$apply => this.updateViewer viewName, this._getAnnotationsFromIDs ids
) )
.bind('setTool', (ctx, name) => .bind('setTool', (ctx, name) =>
...@@ -313,24 +315,25 @@ class Hypothesis extends Annotator ...@@ -313,24 +315,25 @@ class Hypothesis extends Annotator
annotation.reply_list = children.sort(@sortAnnotations).reverse() annotation.reply_list = children.sort(@sortAnnotations).reverse()
@buildReplyList children @buildReplyList children
updateViewer: (annotations=[]) => updateViewer: (viewName, annotations=[]) =>
annotations = annotations.filter (a) -> a? annotations = annotations.filter (a) -> a?
@element.injector().invoke [ @element.injector().invoke [
'$rootScope', '$rootScope',
($rootScope) => ($rootScope) =>
@buildReplyList annotations @buildReplyList annotations
$rootScope.annotations = annotations $rootScope.annotations = annotations
$rootScope.view = viewName
] ]
this this
showViewer: (annotations=[]) => showViewer: (viewName, annotations=[]) =>
this.show() this.show()
@element.injector().invoke [ @element.injector().invoke [
'$location', '$location',
($location) => ($location) =>
$location.path('/viewer').replace() $location.path('/viewer').replace()
] ]
this.updateViewer annotations this.updateViewer viewName, annotations
addEmphasis: (annotations=[]) => addEmphasis: (annotations=[]) =>
annotations = annotations.filter (a) -> a? # Filter out null annotations annotations = annotations.filter (a) -> a? # Filter out null annotations
......
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