Commit f5ae332f authored by Ujvari Gergely's avatar Ujvari Gergely

Basic displayer real-time update for newly created replies

parent c72e5a12
angular.module('h.displayer',[])
.controller('DisplayerCtrl',
($scope, $element) ->
$scope.toggleCollapse = (event, replynumber, thread) ->
get_quote = (annotation) ->
if not 'target' in annotation then return ''
quote = '(This is a reply annotation)'
for target in annotation['target']
for selector in target['selector']
if selector['type'] is 'TextQuoteSelector'
quote = selector['exact'] + ' '
quote
class Displayer
this.$inject = ['$scope','$element','$timeout']
constructor: ($scope, $element, $timeout) ->
$scope.replies = []
$scope.reply_count = 0
$scope.id = document.body.attributes.internalid.value
$scope.filter =
match_policy : 'include_all'
clauses : [
field: "/references"
operator: "first_of"
value: $scope.id
]
actions :
create: true
edit: true
delete: true
past_data:
load_past: 'hits'
go_back: 5
hits: 100
console.log $scope.filter
$scope.open = ->
transports = ['xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']
$scope.sock = new SockJS(window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + '/__streamer__', transports)
$scope.sock.onopen = ->
$scope.sock.send JSON.stringify $scope.filter
$scope.sock.onclose = ->
$timeout $scope.open, 5000
$scope.sock.onmessage = (msg) =>
console.log 'Got something'
console.log msg
$scope.$apply =>
data = msg.data[0]
unless data instanceof Array then data = [data]
action = msg.data[1]
for annotation in data
annotation.quote = get_quote annotation
switch action
when 'create', 'past'
$scope.reply_count += 1
#Find the thread for the reply
replies = $scope.replies
list = replies
for reference in annotation.references
for reply in replies
if reply.id is reference
list = reply
reply.reply_count += 1
replies = reply.replies
break
#Find the place to insert annotation
pos = 0
for reply in replies
if reply.updated < annotation.updated
break
pos += 1
annotation.replies = []
annotation.reply_count = 0
replies.splice pos, 0, annotation
when 'edit'
console.log 'edit'
when 'delete'
console.log 'delete'
console.log $scope.replies
$scope.open()
#$scope.toggleCollapse = (event, replynumber, thread) ->
#Plus/minus sign and italics
elem = (angular.element event.srcElement).parent()
if elem.hasClass 'hyp-collapsed'
elem.removeClass 'hyp-collapsed'
expand = true
else elem.addClass 'hyp-collapsed'
# elem = (angular.element event.srcElement).parent()
# if elem.hasClass 'hyp-collapsed'
# elem.removeClass 'hyp-collapsed'
# expand = true
# else elem.addClass 'hyp-collapsed'
#Now for the replies
if replynumber
toggle_elem = $element.find('.thread_' + (thread+1)).parent().parent()
if expand? then toggle_elem.removeAttr 'style'
else toggle_elem.css 'display', 'none'
)
\ No newline at end of file
# if replynumber
# toggle_elem = $element.find('.thread_' + (thread+1)).parent().parent()
# if expand? then toggle_elem.removeAttr 'style'
# else toggle_elem.css 'display', 'none'
angular.module('h.displayer',['h.filters','bootstrap'])
.controller('DisplayerCtrl', Displayer)
......@@ -24,7 +24,7 @@ syntaxHighlight = (json) ->
class ClauseParser
filter_fields : ['thread', 'text', 'user','uri']
filter_fields : ['references', 'text', 'user','uri', 'id']
operators: ['=', '>', '<', '=>', '>=', '<=', '=<', '[', '#']
operator_mapping:
'=': 'equals'
......
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