Commit 5f7179fa authored by Aron Carroll's avatar Aron Carroll

Move baseURI helper into own file

This is now consistent with the formHelpers file. The baseURI method
is now available on the documentHelpers object.
parent 73d3cc7c
imports = [ imports = [
'h.helpers'
'h.session' 'h.session'
] ]
identityFactory = [ identityFactory = [
'$rootScope', 'baseURI', 'session', '$rootScope', 'session',
($rootScope, baseURI, session) -> ($rootScope, session) ->
loggedInUser = undefined loggedInUser = undefined
onlogin = null onlogin = null
......
imports = [ imports = [
'ngResource' 'ngResource'
'h.flash' 'h.flash'
'h.helpers' 'h.helpers.documentHelpers'
] ]
...@@ -61,8 +61,8 @@ class SessionProvider ...@@ -61,8 +61,8 @@ class SessionProvider
@options = {} @options = {}
$get: [ $get: [
'$q', '$resource', 'baseURI', 'flash', '$q', '$resource', 'documentHelpers', 'flash',
($q, $resource, baseURI, flash) -> ($q, $resource, documentHelpers, flash) ->
actions = {} actions = {}
process = (data, headersGetter) -> process = (data, headersGetter) ->
...@@ -89,7 +89,8 @@ class SessionProvider ...@@ -89,7 +89,8 @@ class SessionProvider
actions[name] = angular.extend {}, options, @options actions[name] = angular.extend {}, options, @options
actions[name].transformResponse = process actions[name].transformResponse = process
$resource("#{baseURI}app", {}, actions).load() endpoint = documentHelpers.absoluteURI('/app')
$resource(endpoint, {}, actions).load()
] ]
# Function providing a server-side user profile resource. # Function providing a server-side user profile resource.
...@@ -98,8 +99,8 @@ class SessionProvider ...@@ -98,8 +99,8 @@ class SessionProvider
# for manipulating server-side account-profile settings. It defines the # for manipulating server-side account-profile settings. It defines the
# actions (such as 'login', 'register') as REST-ish actions # actions (such as 'login', 'register') as REST-ish actions
profileProvider = [ profileProvider = [
'$q', '$resource', 'baseURI', '$q', '$resource', 'documentHelpers',
($q, $resource, baseURI) -> ($q, $resource, documentHelpers) ->
defaults = defaults =
email: "" email: ""
password: "" password: ""
...@@ -116,7 +117,8 @@ profileProvider = [ ...@@ -116,7 +117,8 @@ profileProvider = [
__formid__: "disable_user" __formid__: "disable_user"
withCredentials: true withCredentials: true
$resource("#{baseURI}app", {}, actions) endpoint = documentHelpers.absoluteURI('/app')
$resource(endpoint, {}, actions)
] ]
...@@ -126,9 +128,10 @@ configure = ['$httpProvider', ($httpProvider) -> ...@@ -126,9 +128,10 @@ configure = ['$httpProvider', ($httpProvider) ->
# Use the Pyramid XSRF header name # Use the Pyramid XSRF header name
defaults.xsrfHeaderName = 'X-CSRF-Token' defaults.xsrfHeaderName = 'X-CSRF-Token'
$httpProvider.interceptors.push ['baseURI', (baseURI) -> $httpProvider.interceptors.push ['documentHelpers', (documentHelpers) ->
request: (config) -> request: (config) ->
if config.url.match("#{baseURI}app")?.index == 0 endpoint = documentHelpers.absoluteURI('/app')
if config.url.indexOf(endpoint) == 0
# Set the cross site request forgery token # Set the cross site request forgery token
cookieName = config.xsrfCookieName || defaults.xsrfCookieName cookieName = config.xsrfCookieName || defaults.xsrfCookieName
headerName = config.xsrfHeaderName || defaults.xsrfHeaderName headerName = config.xsrfHeaderName || defaults.xsrfHeaderName
......
imports = [ imports = [
'bootstrap' 'bootstrap'
'h.flash' 'h.flash'
'h.helpers' 'h.helpers.documentHelpers'
'h.identity' 'h.identity'
'h.services' 'h.services'
'h.socket' 'h.socket'
...@@ -13,12 +13,12 @@ class App ...@@ -13,12 +13,12 @@ class App
this.$inject = [ this.$inject = [
'$element', '$location', '$q', '$rootScope', '$route', '$scope', '$timeout', '$element', '$location', '$q', '$rootScope', '$route', '$scope', '$timeout',
'annotator', 'flash', 'identity', 'queryparser', 'socket', 'annotator', 'flash', 'identity', 'queryparser', 'socket',
'streamfilter', 'viewFilter' 'streamfilter', 'viewFilter', 'documentHelpers'
] ]
constructor: ( constructor: (
$element, $location, $q, $rootScope, $route, $scope, $timeout $element, $location, $q, $rootScope, $route, $scope, $timeout
annotator, flash, identity, queryparser, socket, annotator, flash, identity, queryparser, socket,
streamfilter, viewFilter streamfilter, viewFilter, documentHelpers
) -> ) ->
{plugins, host, providers} = annotator {plugins, host, providers} = annotator
...@@ -259,7 +259,8 @@ class App ...@@ -259,7 +259,8 @@ class App
# Configure the Auth plugin with the issued assertion as refresh token. # Configure the Auth plugin with the issued assertion as refresh token.
annotator.addPlugin 'Auth', annotator.addPlugin 'Auth',
tokenUrl: "#{baseURI}api/token?assertion=#{assertion}" tokenUrl: documentHelpers.absoluteURI(
"/api/token?assertion=#{assertion}")
# Set the user from the token. # Set the user from the token.
plugins.Auth.withToken (token) -> plugins.Auth.withToken (token) ->
......
imports = [ imports = [
'ngSanitize' 'ngSanitize'
'h.helpers' 'h.helpers.documentHelpers'
'h.services' 'h.services'
] ]
...@@ -17,12 +17,12 @@ class Annotation ...@@ -17,12 +17,12 @@ class Annotation
this.$inject = [ this.$inject = [
'$element', '$location', '$rootScope', '$sce', '$scope', '$timeout', '$element', '$location', '$rootScope', '$sce', '$scope', '$timeout',
'$window', '$window',
'annotator', 'baseURI', 'drafts' 'annotator', 'documentHelpers', 'drafts'
] ]
constructor: ( constructor: (
$element, $location, $rootScope, $sce, $scope, $timeout, $element, $location, $rootScope, $sce, $scope, $timeout,
$window, $window,
annotator, baseURI, drafts annotator, documentHelpers, drafts
) -> ) ->
model = $scope.model model = $scope.model
{plugins, threading} = annotator {plugins, threading} = annotator
...@@ -164,7 +164,8 @@ class Annotation ...@@ -164,7 +164,8 @@ class Annotation
if drafts.contains $scope.model if drafts.contains $scope.model
$scope.editing = true $scope.editing = true
$scope.shared_link = "#{baseURI}a/#{$scope.model.id}" link = documentHelpers.absoluteURI("/a/#{$scope.model.id}")
$scope.shared_link = link
$scope.$watch 'model.target', (targets) -> $scope.$watch 'model.target', (targets) ->
return unless targets return unless targets
......
baseURI = [
'$document'
($document) ->
# Strip an empty hash and end in exactly one slash
baseURI = $document[0].baseURI
# XXX: IE workaround for the lack of document.baseURI property
if not baseURI
baseTags = $document[0].getElementsByTagName "base"
baseURI = if baseTags.length then baseTags[0].href else $document[0].URL
baseURI.replace(/#$/, '').replace(/\/+$/, '/')
]
angular.module('h.helpers', [])
.factory('baseURI', baseURI)
createDocumentHelpers = [
'$document'
($document) ->
baseURI: do ->
baseURI = $document.prop('baseURI')
# XXX: IE workaround for the lack of document.baseURI property
unless baseURI
baseURI = $document.find('base').prop('href') or $document.prop('URL')
# Strip an empty hash and end in exactly one slash
baseURI.replace(/#$/, '').replace(/\/+$/, '/')
absoluteURI: (path) ->
"#{@baseURI}#{path.replace(/^\//, '')}"
]
angular.module('h.helpers.documentHelpers', [])
.factory('documentHelpers', createDocumentHelpers)
imports = [ imports = [
'h.helpers' 'h.helpers.documentHelpers'
] ]
...@@ -16,8 +16,8 @@ run = ['clientID', (clientID) -> ...@@ -16,8 +16,8 @@ run = ['clientID', (clientID) ->
"X-Client-Id": clientID "X-Client-Id": clientID
] ]
socket = ['baseURI', 'clientID', (baseURI, clientID) -> socket = ['documentHelpers', 'clientID', (documentHelpers, clientID) ->
-> new Socket(clientID, "#{baseURI}__streamer__") -> new Socket(clientID, "#{documentHelpers.baseURI}__streamer__")
] ]
......
...@@ -4,7 +4,6 @@ imports = [ ...@@ -4,7 +4,6 @@ imports = [
'h.directives' 'h.directives'
'h.filters' 'h.filters'
'h.flash' 'h.flash'
'h.helpers'
'h.searchfilters' 'h.searchfilters'
] ]
......
...@@ -25,7 +25,7 @@ describe 'h.directives.annotation', -> ...@@ -25,7 +25,7 @@ describe 'h.directives.annotation', ->
$timeout: sinon.spy() $timeout: sinon.spy()
$window: {} $window: {}
annotator: {plugins: {}} annotator: {plugins: {}}
baseURI: null documentHelpers: {baseURI: '', absoluteURI: sinon.spy()}
drafts: null drafts: null
it 'provides a document title', -> it 'provides a document title', ->
......
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