loader.items().map(function(item) {
return m('tr', [
m('td', [
- // Guess workbench.{apihostport} is a
- // Workbench... unless the host part of
- // apihostport is an IPv4 or [IPv6]
- // address.
- item.session.baseURL.match('://(\\[|\\d+\\.\\d+\\.\\d+\\.\\d+[:/])') ? null :
+ item.workbenchBaseURL() &&
m('a.btn.btn-xs.btn-default', {
- href: item.session.baseURL.replace('://', '://workbench.')+'collections/'+item.uuid,
+ href: item.workbenchBaseURL()+'collections/'+item.uuid,
}, 'Show'),
]),
m('td.arvados-uuid', item.uuid),
vnode.state.loader = new MergingLoader({
children: Object.keys(sessions).map(function(key) {
var session = sessions[key]
+ var workbenchBaseURL = function() {
+ return vnode.state.sessionDB.workbenchBaseURL(session)
+ }
return new MultipageLoader({
sessionKey: key,
loadFunc: function(filters) {
},
}).then(function(resp) {
resp.items.map(function(item) {
- item.session = session
+ item.workbenchBaseURL = workbenchBaseURL
})
return resp
})
window.SessionDB = function() {
var db = this
Object.assign(db, {
+ discoveryCache: {},
loadFromLocalStorage: function() {
try {
return JSON.parse(window.localStorage.getItem('sessions')) || {}
})
})
},
+ // Return the Workbench base URL advertised by the session's
+ // API server, or a reasonable guess, or (if neither strategy
+ // works out) null.
+ workbenchBaseURL: function(session) {
+ var dd = db.discoveryDoc(session)()
+ if (!dd)
+ // Don't fall back to guessing until we receive the discovery doc
+ return null
+ if (dd.workbenchUrl)
+ return dd.workbenchUrl
+ // Guess workbench.{apihostport} is a Workbench... unless
+ // the host part of apihostport is an IPv4 or [IPv6]
+ // address.
+ if (!session.baseURL.match('://(\\[|\\d+\\.\\d+\\.\\d+\\.\\d+[:/])'))
+ return session.baseURL.replace('://', '://workbench.')
+ return null
+ },
+ // Return a m.stream that will get fulfilled with the
+ // discovery doc from a session's API server.
+ discoveryDoc: function(session) {
+ var cache = db.discoveryCache[session.baseURL]
+ if (!cache) {
+ db.discoveryCache[session.baseURL] = cache = m.stream()
+ m.request(session.baseURL+'discovery/v1/apis/arvados/v1/rest').then(cache)
+ }
+ return cache
+ },
request: function(session, path, opts) {
opts = opts || {}
opts.headers = opts.headers || {}