Commit c0897c5e authored by Ujvari Gergely's avatar Ujvari Gergely

Get rid of angular orderBy:sortThread:true filter

The main cause of this problem was that angular was calling this filter very frequently.
Now the annotation.reply_list is maintained that it stores the replies sorted and using the filter is no longer necessary.
parent 5ca08d0f
...@@ -744,9 +744,19 @@ class Annotation ...@@ -744,9 +744,19 @@ class Annotation
$scope.model.$modelValue.highlightText = $scope.model.$modelValue.highlightText =
$scope.model.$modelValue.highlightText.replace regexp, annotator.highlighter $scope.model.$modelValue.highlightText.replace regexp, annotator.highlighter
sortAnnotations: (a, b) ->
a_upd = if a.updated? then new Date(a.updated) else new Date()
b_upd = if b.updated? then new Date(b.updated) else new Date()
a_upd.getTime() - b_upd.getTime()
$scope.$on 'updateReplies', -> $scope.$on 'updateReplies', ->
unless $scope.model.$modelValue.references?.length
return
thread = threading.getContainer $scope.model.$modelValue.id thread = threading.getContainer $scope.model.$modelValue.id
$scope.model.$modelValue.reply_list = (r.message for r in (thread.children or [])) reply_list = (r.message for r in (thread.children or []))
$scope.model.$modelValue.reply_list = reply_list.sort(@sortAnnotations).reverse()
class Editor class Editor
this.$inject = ['$location', '$routeParams', '$scope', 'annotator'] this.$inject = ['$location', '$routeParams', '$scope', 'annotator']
...@@ -801,16 +811,17 @@ class Viewer ...@@ -801,16 +811,17 @@ class Viewer
thread = threading.getContainer annotation.id thread = threading.getContainer annotation.id
(r.message for r in (thread.children or [])) (r.message for r in (thread.children or []))
$scope.sortThread = (thread) -> sortAnnotations: (a, b) ->
if thread?.message?.updated a_upd = if a.updated? then new Date(a.updated) else new Date()
return new Date(thread.message.updated) b_upd = if b.updated? then new Date(b.updated) else new Date()
else a_upd.getTime() - b_upd.getTime()
return new Date()
$scope.$on 'updateReplies', -> $scope.$on 'updateReplies', ->
console.log 'top updateReplies'
for annotation in $rootScope.annotations for annotation in $rootScope.annotations
thread = threading.getContainer annotation.id thread = threading.getContainer annotation.id
annotation.reply_list = (r.message for r in (thread.children or [])) reply_list = (r.message for r in (thread.children or []))
annotation.reply_list = reply_list.sort(@sortAnnotations).reverse()
class Search class Search
...@@ -1029,17 +1040,16 @@ class Search ...@@ -1029,17 +1040,16 @@ class Search
$scope.ann_info.shown[next_id] = true $scope.ann_info.shown[next_id] = true
pos += 1 pos += 1
sortAnnotations: (a, b) ->
$scope.sortThread = (thread) -> a_upd = if a.updated? then new Date(a.updated) else new Date()
if thread?.message?.updated b_upd = if b.updated? then new Date(b.updated) else new Date()
return new Date(thread.message.updated) a_upd.getTime() - b_upd.getTime()
else
return new Date()
$scope.$on 'updateReplies', -> $scope.$on 'updateReplies', ->
for annotation in $scope.threads for annotation in $scope.threads
thread = threading.getContainer annotation.id thread = threading.getContainer annotation.id
annotation.reply_list = (r.message for r in (thread.children or [])) reply_list = (r.message for r in (thread.children or []))
annotation.reply_list = reply_list.sort(@sortAnnotations).reverse()
refresh() refresh()
......
...@@ -260,11 +260,17 @@ class Hypothesis extends Annotator ...@@ -260,11 +260,17 @@ class Hypothesis extends Annotator
# Do nothing in the app frame, let the host handle it. # Do nothing in the app frame, let the host handle it.
setupAnnotation: (annotation) -> annotation setupAnnotation: (annotation) -> annotation
sortAnnotations: (a, b) ->
a_upd = if a.updated? then new Date(a.updated) else new Date()
b_upd = if b.updated? then new Date(b.updated) else new Date()
a_upd.getTime() - b_upd.getTime()
buildReplyList: (annotations=[]) => buildReplyList: (annotations=[]) =>
$filter = @element.injector().get '$filter'
for annotation in annotations for annotation in annotations
thread = @threading.getContainer annotation.id thread = @threading.getContainer annotation.id
children = (r.message for r in (thread.children or [])) children = (r.message for r in (thread.children or []))
annotation.reply_list = children annotation.reply_list = children.sort(@sortAnnotations).reverse()
@buildReplyList children @buildReplyList children
updateViewer: (annotations=[]) => updateViewer: (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