Commit cde35500 authored by Kristof Csillag's avatar Kristof Csillag

Merge pull request #730 from hypothesis/688-digest-cleanup-1

Re-design lots of code path, so that digest cycles are triggered in a less insane manner.
parents 34660fd7 c37c73d5
......@@ -13,8 +13,21 @@ annotation = ['$filter', 'annotator', ($filter, annotator) ->
scope.$watch 'model.$modelValue.id', (id) ->
scope.thread = annotator.threading.idTable[id]
scope.auth = {}
scope.auth.delete =
if scope.model.$modelValue? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'delete', scope.model.$modelValue
else
true
scope.auth.update =
if scope.model.$modelValue? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'update', scope.model.$modelValue
else
true
# Publish the controller
scope.model = controller
controller: 'AnnotationController'
priority: 100 # Must run before ngModel
require: '?ngModel'
......
......@@ -95,7 +95,6 @@ class App
$scope.dynamicBucket = false
$location.search({'id' : null })
annotator.showViewer heatmap.buckets[bucket]
$scope.$digest()
$scope.$watch 'sheet.collapsed', (newValue) ->
$scope.sheet.tab = if newValue then null else 'login'
......@@ -633,6 +632,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)
......@@ -658,6 +658,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'
......@@ -683,6 +684,7 @@ class Annotation
annotator.deleteAnnotation reply
annotator.deleteAnnotation annotation
$scope.$emit 'updateReplies'
else
$scope.action = 'delete'
$scope.editing = true
......@@ -691,12 +693,6 @@ class Annotation
$scope.model.$modelValue.text = ''
$scope.model.$modelValue.tags = ''
$scope.authorize = (action) ->
if $scope.model.$modelValue? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize action, $scope.model.$modelValue
else
true
$scope.$on '$routeChangeStart', -> $scope.cancel() if $scope.editing
$scope.$on '$routeUpdate', -> $scope.cancel() if $scope.editing
......@@ -742,6 +738,14 @@ class Annotation
$scope.model.$modelValue.highlightText =
$scope.model.$modelValue.highlightText.replace regexp, annotator.highlighter
$scope.$on 'updateReplies', ->
unless $scope.model.$modelValue.references?.length
return
thread = threading.getContainer $scope.model.$modelValue.id
reply_list = (r.message for r in (thread.children or []))
$scope.model.$modelValue.reply_list = reply_list.sort(annotator.sortAnnotations).reverse()
class Editor
this.$inject = ['$location', '$routeParams', '$scope', 'annotator']
......@@ -774,11 +778,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
......@@ -796,11 +800,17 @@ class Viewer
thread = threading.getContainer annotation.id
(r.message for r in (thread.children or []))
$scope.sortThread = (thread) ->
if thread?.message?.updated
return new Date(thread.message.updated)
else
return new Date()
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', ->
console.log 'top updateReplies'
for annotation in $rootScope.annotations
thread = threading.getContainer annotation.id
reply_list = (r.message for r in (thread.children or []))
annotation.reply_list = reply_list.sort(@sortAnnotations).reverse()
class Search
......@@ -1019,12 +1029,11 @@ class Search
$scope.ann_info.shown[next_id] = true
pos += 1
$scope.sortThread = (thread) ->
if thread?.message?.updated
return new Date(thread.message.updated)
else
return new Date()
$scope.$on 'updateReplies', ->
for annotation in $scope.threads
thread = threading.getContainer annotation.id
reply_list = (r.message for r in (thread.children or []))
annotation.reply_list = reply_list.sort(annotator.sortAnnotations).reverse()
refresh()
......
......@@ -356,9 +356,33 @@ username = ['$filter', '$window', ($filter, $window) ->
template: '<span class="user" ng-click="uclick($event)">{{uname}}</span>'
]
fuzzytime = ['$filter', '$window', ($filter, $window) ->
link: (scope, elem, attr, ctrl) ->
return unless ctrl?
ctrl.$render = ->
scope.ftime = ($filter 'fuzzyTime') ctrl.$viewValue
timefunct = ->
$window.setInterval =>
scope.ftime = ($filter 'fuzzyTime') ctrl.$viewValue
scope.$digest()
, 5000
scope.timer = timefunct()
scope.$on '$destroy', ->
$window.clearInterval scope.timer
require: '?ngModel'
restrict: 'E'
template: '<span class="small">{{ftime | date:mediumDate}}</span>'
]
angular.module('h.directives', ['ngSanitize'])
.directive('authentication', authentication)
.directive('fuzzytime', fuzzytime)
.directive('markdown', markdown)
.directive('privacy', privacy)
.directive('recursive', recursive)
......
......@@ -278,10 +278,24 @@ class Hypothesis extends Annotator
# Do nothing in the app frame, let the host handle it.
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=[]) =>
$filter = @element.injector().get '$filter'
for annotation in annotations
thread = @threading.getContainer annotation.id
children = (r.message for r in (thread.children or []))
annotation.reply_list = children.sort(@sortAnnotations).reverse()
@buildReplyList children
updateViewer: (annotations=[]) =>
@element.injector().invoke [
'$location', '$rootScope',
($location, $rootScope) ->
($location, $rootScope) =>
@buildReplyList annotations
$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