Commit a0db71b3 authored by Randall Leeds's avatar Randall Leeds

Use serviceUrl in store

parent e2e999c1
......@@ -10,15 +10,8 @@
# store.SearchResource().
###
module.exports = [
'$document', '$http', '$resource',
($document, $http, $resource) ->
# Find any service link tag
svc = $document.find('link')
.filter -> @rel is 'service' and @type is 'application/annotatorsvc+json'
.filter -> @href
.prop('href') or ''
'$http', '$resource', 'serviceUrl'
($http, $resource, serviceUrl) ->
camelize = (string) ->
string.replace /(?:^|_)([a-z])/g, (_, char) -> char.toUpperCase()
......@@ -26,7 +19,7 @@ module.exports = [
$resolved: false
# We call the service_url and the backend api gives back
# the actions and urls it provides.
$promise: $http.get(svc)
$promise: $http.get(serviceUrl)
.finally -> store.$resolved = true
.then (response) ->
for name, actions of response.data.links
......@@ -34,6 +27,6 @@ module.exports = [
# For the search resource, one URL is given for all actions.
# For the annotations, each action has its own URL.
prop = "#{camelize(name)}Resource"
store[prop] = $resource(actions.url or svc, {}, actions)
store[prop] = $resource(actions.url or serviceUrl, {}, actions)
store
]
......@@ -4,7 +4,6 @@ describe 'store', ->
$httpBackend = null
sandbox = null
store = null
fakeDocument = null
before ->
angular.module('h', ['ngResource'])
......@@ -14,18 +13,7 @@ describe 'store', ->
beforeEach module ($provide) ->
sandbox = sinon.sandbox.create()
link = document.createElement("link")
link.rel = 'service'
link.type = 'application/annotatorsvc+json'
link.href = 'http://example.com/api'
fakeDocument = {
find: sandbox.stub().returns($(link))
}
$provide.value '$document', fakeDocument
$provide.value 'serviceUrl', 'http://example.com/api'
return
afterEach ->
......
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