Commit f2e54345 authored by csillag's avatar csillag

Added framework for Social View support, with single player demo

Now the Hypothes.is class has a field called 'socialView',
which specifies the social view filters that should be used.

This is considered when loading annotations on init, and also on
later re-loads, because of login/logout.

When the filter is changed, annotations are automatically reloaded.

(And there were also some cosmetic fixes.)
parent 74d0c30f
......@@ -156,6 +156,11 @@ class App
$scope.toggleHighlightingMode()
, 500
$scope.$watch 'socialView.name', (newValue, oldValue) ->
return if newValue is oldValue
console.log "Social View changed to '" + newValue + "'. Reloading annotations."
$scope.reloadAnnotations()
$scope.$watch 'frame.visible', (newValue) ->
if newValue
annotator.show()
......@@ -194,7 +199,9 @@ class App
collapsed: !show
tab: 'login'
$scope.$on '$reset', => angular.extend $scope, @scope, auth: authentication
$scope.$on '$reset', => angular.extend $scope, @scope,
auth: authentication
socialView: annotator.socialView
$scope.$on 'success', (event, action) ->
if action == 'claim'
......@@ -237,6 +244,7 @@ class App
$scope.createUnattachedAnnotation = ->
console.log "Should create unattached annotation"
<<<<<<< HEAD
# Searchbar initialization
@user_filter = $filter('userName')
search_query = ''
......@@ -389,7 +397,7 @@ class App
@visualSearch.searchBox.searchEvent('')
, 1500
$scope.reloadAnnotations = =>
$scope.reloadAnnotations = ->
if annotator.plugins.Store?
$scope.$root.annotations = []
annotator.threading.thread []
......@@ -412,11 +420,13 @@ class App
Store._apiRequest = angular.noop
# * Remove the plugin and re-add it to the annotator.
delete annotator.plugins.Store
annotator.considerSocialView Store.options
annotator.addStore Store.options
href = annotator.plugins.Store.options.loadFromSearch.uri
for uri in annotator.plugins.Document.uris()
unless uri is href
unless uri is href # Do not load the href again
console.log "Also loading annotations for: " + uri
annotator.plugins.Store.loadAnnotationsFromSearch uri: uri
class Annotation
......
......@@ -50,8 +50,8 @@ class Hypothesis extends Annotator
viewer:
addField: (-> )
this.$inject = ['$document', '$location', '$rootScope', '$route', 'drafts']
constructor: ($document, $location, $rootScope, $route, drafts) ->
this.$inject = ['$document', '$location', '$rootScope', '$route', 'authentication', 'drafts']
constructor: ($document, $location, $rootScope, $route, authentication, drafts) ->
Gettext.prototype.parse_locale_data annotator_locale_data
super ($document.find 'body')
......@@ -133,6 +133,10 @@ class Hypothesis extends Annotator
# Reload the route after annotations are loaded
this.subscribe 'annotationsLoaded', -> $route.reload()
@auth = authentication
@socialView =
name: "none" # "single-player"
_setupXDM: ->
$location = @element.injector().get '$location'
$rootScope = @element.injector().get '$rootScope'
......@@ -338,6 +342,22 @@ class Hypothesis extends Annotator
# Give angular a chance to react
$rootScope.$digest()
considerSocialView: (options) ->
switch @socialView.name
when "none"
# Sweet, nothing to do, just clean up previous filters
console.log "Not applying any Social View filters."
delete options.loadFromSearch.user
when "single-player"
if (p = @auth.persona)?
console.log "Social View filter: single player mode."
options.loadFromSearch.user = "acct:" + p.username + "@" + p.provider
else
console.log "Social View: single-player mode, but ignoring it, since not logged in."
delete options.loadFromSearch.user
else
console.warn "Unsupported Social View: '" + @socialView.name + "'!"
serviceDiscovery: (options) =>
$location = @element.injector().get '$location'
$rootScope = @element.injector().get '$rootScope'
......@@ -357,6 +377,7 @@ class Hypothesis extends Annotator
loadFromSearch:
limit: 1000
uri: href
this.considerSocialView options
this.addStore(options)
addStore: (options) ->
......
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