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 = [
'h.helpers'
'h.session'
]
identityFactory = [
'$rootScope', 'baseURI', 'session',
($rootScope, baseURI, session) ->
'$rootScope', 'session',
($rootScope, session) ->
loggedInUser = undefined
onlogin = null
......
imports = [
'ngResource'
'h.flash'
'h.helpers'
'h.helpers.documentHelpers'
]
......@@ -61,8 +61,8 @@ class SessionProvider
@options = {}
$get: [
'$q', '$resource', 'baseURI', 'flash',
($q, $resource, baseURI, flash) ->
'$q', '$resource', 'documentHelpers', 'flash',
($q, $resource, documentHelpers, flash) ->
actions = {}
process = (data, headersGetter) ->
......@@ -89,7 +89,8 @@ class SessionProvider
actions[name] = angular.extend {}, options, @options
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.
......@@ -98,8 +99,8 @@ class SessionProvider
# for manipulating server-side account-profile settings. It defines the
# actions (such as 'login', 'register') as REST-ish actions
profileProvider = [
'$q', '$resource', 'baseURI',
($q, $resource, baseURI) ->
'$q', '$resource', 'documentHelpers',
($q, $resource, documentHelpers) ->
defaults =
email: ""
password: ""
......@@ -116,7 +117,8 @@ profileProvider = [
__formid__: "disable_user"
withCredentials: true
$resource("#{baseURI}app", {}, actions)
endpoint = documentHelpers.absoluteURI('/app')
$resource(endpoint, {}, actions)
]
......@@ -126,9 +128,10 @@ configure = ['$httpProvider', ($httpProvider) ->
# Use the Pyramid XSRF header name
defaults.xsrfHeaderName = 'X-CSRF-Token'
$httpProvider.interceptors.push ['baseURI', (baseURI) ->
$httpProvider.interceptors.push ['documentHelpers', (documentHelpers) ->
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
cookieName = config.xsrfCookieName || defaults.xsrfCookieName
headerName = config.xsrfHeaderName || defaults.xsrfHeaderName
......
imports = [
'bootstrap'
'h.flash'
'h.helpers'
'h.helpers.documentHelpers'
'h.identity'
'h.services'
'h.socket'
......@@ -13,12 +13,12 @@ class App
this.$inject = [
'$element', '$location', '$q', '$rootScope', '$route', '$scope', '$timeout',
'annotator', 'flash', 'identity', 'queryparser', 'socket',
'streamfilter', 'viewFilter'
'streamfilter', 'viewFilter', 'documentHelpers'
]
constructor: (
$element, $location, $q, $rootScope, $route, $scope, $timeout
annotator, flash, identity, queryparser, socket,
streamfilter, viewFilter
streamfilter, viewFilter, documentHelpers
) ->
{plugins, host, providers} = annotator
......@@ -259,7 +259,8 @@ class App
# Configure the Auth plugin with the issued assertion as refresh token.
annotator.addPlugin 'Auth',
tokenUrl: "#{baseURI}api/token?assertion=#{assertion}"
tokenUrl: documentHelpers.absoluteURI(
"/api/token?assertion=#{assertion}")
# Set the user from the token.
plugins.Auth.withToken (token) ->
......
imports = [
'ngSanitize'
'h.helpers'
'h.helpers.documentHelpers'
'h.services'
]
......@@ -17,12 +17,12 @@ class Annotation
this.$inject = [
'$element', '$location', '$rootScope', '$sce', '$scope', '$timeout',
'$window',
'annotator', 'baseURI', 'drafts'
'annotator', 'documentHelpers', 'drafts'
]
constructor: (
$element, $location, $rootScope, $sce, $scope, $timeout,
$window,
annotator, baseURI, drafts
annotator, documentHelpers, drafts
) ->
model = $scope.model
{plugins, threading} = annotator
......@@ -164,7 +164,8 @@ class Annotation
if drafts.contains $scope.model
$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) ->
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 = [
'h.helpers'
'h.helpers.documentHelpers'
]
......@@ -16,8 +16,8 @@ run = ['clientID', (clientID) ->
"X-Client-Id": clientID
]
socket = ['baseURI', 'clientID', (baseURI, clientID) ->
-> new Socket(clientID, "#{baseURI}__streamer__")
socket = ['documentHelpers', 'clientID', (documentHelpers, clientID) ->
-> new Socket(clientID, "#{documentHelpers.baseURI}__streamer__")
]
......
......@@ -4,7 +4,6 @@ imports = [
'h.directives'
'h.filters'
'h.flash'
'h.helpers'
'h.searchfilters'
]
......
......@@ -25,7 +25,7 @@ describe 'h.directives.annotation', ->
$timeout: sinon.spy()
$window: {}
annotator: {plugins: {}}
baseURI: null
documentHelpers: {baseURI: '', absoluteURI: sinon.spy()}
drafts: null
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