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 ...@@ -156,6 +156,11 @@ class App
$scope.toggleHighlightingMode() $scope.toggleHighlightingMode()
, 500 , 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) -> $scope.$watch 'frame.visible', (newValue) ->
if newValue if newValue
annotator.show() annotator.show()
...@@ -194,7 +199,9 @@ class App ...@@ -194,7 +199,9 @@ class App
collapsed: !show collapsed: !show
tab: 'login' 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) -> $scope.$on 'success', (event, action) ->
if action == 'claim' if action == 'claim'
...@@ -237,6 +244,7 @@ class App ...@@ -237,6 +244,7 @@ class App
$scope.createUnattachedAnnotation = -> $scope.createUnattachedAnnotation = ->
console.log "Should create unattached annotation" console.log "Should create unattached annotation"
<<<<<<< HEAD
# Searchbar initialization # Searchbar initialization
@user_filter = $filter('userName') @user_filter = $filter('userName')
search_query = '' search_query = ''
...@@ -389,7 +397,7 @@ class App ...@@ -389,7 +397,7 @@ class App
@visualSearch.searchBox.searchEvent('') @visualSearch.searchBox.searchEvent('')
, 1500 , 1500
$scope.reloadAnnotations = => $scope.reloadAnnotations = ->
if annotator.plugins.Store? if annotator.plugins.Store?
$scope.$root.annotations = [] $scope.$root.annotations = []
annotator.threading.thread [] annotator.threading.thread []
...@@ -412,11 +420,13 @@ class App ...@@ -412,11 +420,13 @@ class App
Store._apiRequest = angular.noop Store._apiRequest = angular.noop
# * Remove the plugin and re-add it to the annotator. # * Remove the plugin and re-add it to the annotator.
delete annotator.plugins.Store delete annotator.plugins.Store
annotator.considerSocialView Store.options
annotator.addStore Store.options annotator.addStore Store.options
href = annotator.plugins.Store.options.loadFromSearch.uri href = annotator.plugins.Store.options.loadFromSearch.uri
for uri in annotator.plugins.Document.uris() 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 annotator.plugins.Store.loadAnnotationsFromSearch uri: uri
class Annotation class Annotation
......
...@@ -50,8 +50,8 @@ class Hypothesis extends Annotator ...@@ -50,8 +50,8 @@ class Hypothesis extends Annotator
viewer: viewer:
addField: (-> ) addField: (-> )
this.$inject = ['$document', '$location', '$rootScope', '$route', 'drafts'] this.$inject = ['$document', '$location', '$rootScope', '$route', 'authentication', 'drafts']
constructor: ($document, $location, $rootScope, $route, drafts) -> constructor: ($document, $location, $rootScope, $route, authentication, drafts) ->
Gettext.prototype.parse_locale_data annotator_locale_data Gettext.prototype.parse_locale_data annotator_locale_data
super ($document.find 'body') super ($document.find 'body')
...@@ -133,6 +133,10 @@ class Hypothesis extends Annotator ...@@ -133,6 +133,10 @@ class Hypothesis extends Annotator
# Reload the route after annotations are loaded # Reload the route after annotations are loaded
this.subscribe 'annotationsLoaded', -> $route.reload() this.subscribe 'annotationsLoaded', -> $route.reload()
@auth = authentication
@socialView =
name: "none" # "single-player"
_setupXDM: -> _setupXDM: ->
$location = @element.injector().get '$location' $location = @element.injector().get '$location'
$rootScope = @element.injector().get '$rootScope' $rootScope = @element.injector().get '$rootScope'
...@@ -338,6 +342,22 @@ class Hypothesis extends Annotator ...@@ -338,6 +342,22 @@ class Hypothesis extends Annotator
# Give angular a chance to react # Give angular a chance to react
$rootScope.$digest() $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) => serviceDiscovery: (options) =>
$location = @element.injector().get '$location' $location = @element.injector().get '$location'
$rootScope = @element.injector().get '$rootScope' $rootScope = @element.injector().get '$rootScope'
...@@ -357,6 +377,7 @@ class Hypothesis extends Annotator ...@@ -357,6 +377,7 @@ class Hypothesis extends Annotator
loadFromSearch: loadFromSearch:
limit: 1000 limit: 1000
uri: href uri: href
this.considerSocialView options
this.addStore(options) this.addStore(options)
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