Commit a0db71b3 authored by Randall Leeds's avatar Randall Leeds

Use serviceUrl in store

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