Commit cf14b3ee authored by Ujvari Gergely's avatar Ujvari Gergely

Get rid of replies(annotation) call from the Viewer.

The replies(annotation) call of the viewer.html ng-repeat was called in every $digest cycle yet it only needs to be updated upon annotation creation, reply creation, delete.
Therefore an updateReplies event is introduced which is emitted up in the hieararchy and every annotation updates it's new reply_list property (which as it's namesake suggest keep a list of the annotation's replies)
parent 121e0c6b
......@@ -638,6 +638,7 @@ class Annotation
switch $scope.action
when 'create'
annotator.publish 'annotationCreated', annotation
$scope.$emit 'updateReplies'
when 'delete'
root = $scope.$root.annotations
root = (a for a in root when a isnt root)
......@@ -663,6 +664,7 @@ class Annotation
# XXX: This is ugly -- it's the one place we refer to the plugin directly
annotator.plugins.Threading.thread reply
$scope.$emit 'updateReplies'
$scope.edit = ->
$scope.action = 'edit'
......@@ -688,6 +690,7 @@ class Annotation
annotator.deleteAnnotation reply
annotator.deleteAnnotation annotation
$scope.$emit 'updateReplies'
else
$scope.action = 'delete'
$scope.editing = true
......@@ -741,6 +744,9 @@ class Annotation
$scope.model.$modelValue.highlightText =
$scope.model.$modelValue.highlightText.replace regexp, annotator.highlighter
$scope.$on 'updateReplies', ->
thread = threading.getContainer $scope.model.$modelValue.id
$scope.model.$modelValue.reply_list = (r.message for r in (thread.children or []))
class Editor
this.$inject = ['$location', '$routeParams', '$scope', 'annotator']
......@@ -773,11 +779,11 @@ class Editor
class Viewer
this.$inject = [
'$location', '$routeParams', '$scope',
'$location', '$rootScope', '$routeParams', '$scope',
'annotator'
]
constructor: (
$location, $routeParams, $scope,
$location, $rootScope, $routeParams, $scope,
annotator
) ->
{provider, threading} = annotator
......@@ -801,6 +807,11 @@ class Viewer
else
return new Date()
$scope.$on 'updateReplies', ->
for annotation in $rootScope.annotations
thread = threading.getContainer annotation.id
annotation.reply_list = (r.message for r in (thread.children or []))
class Search
this.$inject = ['$filter', '$location', '$routeParams', '$scope', 'annotator']
......@@ -1025,6 +1036,11 @@ class Search
else
return new Date()
$scope.$on 'updateReplies', ->
for annotation in $scope.threads
thread = threading.getContainer annotation.id
annotation.reply_list = (r.message for r in (thread.children or []))
refresh()
......
......@@ -263,7 +263,10 @@ class Hypothesis extends Annotator
updateViewer: (annotations=[]) =>
@element.injector().invoke [
'$location', '$rootScope',
($location, $rootScope) ->
($location, $rootScope) =>
for annotation in annotations
thread = @threading.getContainer annotation.id
annotation.reply_list = (r.message for r in (thread.children or []))
$rootScope.annotations = annotations
$location.path('/viewer').replace()
$rootScope.$digest()
......
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