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
annotator
) ->
{providers, threading} = annotator
$scope.view = 'Screen'
$rootScope.view = 'Screen'
$scope.sort = 'Newest'
$scope.views = [
{view:'Screen'}
{view:'Document'}]
{view:'Document'}
{view:"Comments"}
]
$scope.sorts = [
{sort:'Newest'}
{sort:'Oldest'}
......@@ -704,20 +706,29 @@ class Viewer
method: 'scrollTo'
params: annotation.$$tag
$scope.applyview = (view) ->
$scope.view = view
if $scope.view == 'Screen'
annotator.updateViewer($rootScope.annotations)
$scope.applyView = (view) ->
switch view
when 'Screen'
# 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'
annotator.updateViewer(annotator.plugins.Store.annotations)
when 'Document'
for p in providers
p.channel.notify method: 'showAll'
break
for p in providers
p.channel.notify
method: 'setDynamicBucketMode'
params: $scope.view == 'Screen'
when 'Comments'
for p in providers
p.channel.notify method: 'showComments'
else
throw new Error "Unknown view requested: " + view
$scope.applysort = (sort) ->
$scope.applySort = (sort) ->
$scope.sort = sort
if $scope.sort == 'Newest'
$scope.predicate = 'updated'
......
......@@ -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) =>
this.setTool name
this.publish 'setTool', name
......@@ -164,11 +182,21 @@ class Annotator.Guest extends Annotator
_setupViewer: -> this
_setupEditor: -> this
showViewer: (annotations) =>
@panel?.notify method: "showViewer", params: (a.id for a in annotations)
showViewer: (viewName, annotations) =>
@panel?.notify
method: "showViewer"
params: [
viewName
(a.id for a in annotations)
]
updateViewer: (annotations) =>
@panel?.notify method: "updateViewer", params: (a.id for a in annotations)
updateViewer: (viewName, annotations) =>
@panel?.notify
method: "updateViewer"
params: [
viewName
(a.id for a in annotations)
]
showEditor: (annotation) => @plugins.Bridge.showEditor annotation
......@@ -254,7 +282,7 @@ class Annotator.Guest extends Annotator
return unless (@tool is 'highlight') or @visibleHighlights and @noBack
# 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
@noBack = false
......
......@@ -463,10 +463,12 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
else if (@isLower bucket)
@dynamicBucket = true
@_jumpMinMax @buckets[bucket], "down"
else if (@isComment bucket)
@commentClick()
else
d3.event.stopPropagation()
@dynamicBucket = false
annotator.showViewer @buckets[bucket]
annotator.showViewer "Tab", @buckets[bucket]
tabs.exit().remove()
......@@ -498,8 +500,15 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
acc
, []
# $.merge visible, @annotator.comments
@annotator.updateViewer visible
@annotator.updateViewer "Screen", visible
_getCommentBucket: => @index.length - 2
isUpper: (i) => i == 1
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
$rootScope.$apply => this.show()
)
.bind('showViewer', (ctx, ids=[]) =>
.bind('showViewer', (ctx, [viewName, ids]) =>
ids ?= []
return unless this.discardDrafts()
$rootScope.$apply => this.showViewer this._getAnnotationsFromIDs ids
$rootScope.$apply => this.showViewer viewName, this._getAnnotationsFromIDs ids
)
.bind('updateViewer', (ctx, ids=[]) =>
$rootScope.$apply => this.updateViewer this._getAnnotationsFromIDs ids
.bind('updateViewer', (ctx, [viewName, ids]) =>
ids ?= []
$rootScope.$apply => this.updateViewer viewName, this._getAnnotationsFromIDs ids
)
.bind('setTool', (ctx, name) =>
......@@ -313,24 +315,25 @@ class Hypothesis extends Annotator
annotation.reply_list = children.sort(@sortAnnotations).reverse()
@buildReplyList children
updateViewer: (annotations=[]) =>
updateViewer: (viewName, annotations=[]) =>
annotations = annotations.filter (a) -> a?
@element.injector().invoke [
'$rootScope',
($rootScope) =>
@buildReplyList annotations
$rootScope.annotations = annotations
$rootScope.view = viewName
]
this
showViewer: (annotations=[]) =>
showViewer: (viewName, annotations=[]) =>
this.show()
@element.injector().invoke [
'$location',
($location) =>
$location.path('/viewer').replace()
]
this.updateViewer annotations
this.updateViewer viewName, annotations
addEmphasis: (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