12515: Use workbenchUrl advertised by API server discovery doc.
[arvados.git] / apps / workbench / app / assets / javascripts / components / collections.js
index 9f7c80489ed2fbc9b730483c361a1425e74df8c5..591bf38aa74b162e353c9705da1ecbcbba2d8cde 100644 (file)
@@ -5,7 +5,7 @@
 window.CollectionsTable = {
     maybeLoadMore: function(dom) {
         var loader = this.loader
-        if (loader.done || loader.loading)
+        if (loader.state != loader.READY)
             // Can't start getting more items anyway: no point in
             // checking anything else.
             return
@@ -36,6 +36,7 @@ window.CollectionsTable = {
         window.removeEventListener('resize', vnode.state.maybeLoadMore)
     },
     view: function(vnode) {
+        var loader = vnode.attrs.loader
         return m('table.table.table-condensed', [
             m('thead', m('tr', [
                 m('th'),
@@ -44,30 +45,35 @@ window.CollectionsTable = {
                 m('th', 'last modified'),
             ])),
             m('tbody', [
-                vnode.attrs.loader.items() && vnode.attrs.loader.items().map(function(item) {
+                loader.items().map(function(item) {
                     return m('tr', [
-                        m('td', m('a.btn.btn-xs.btn-default', {href: item.session.baseURL.replace('://', '://workbench.')+'collections/'+item.uuid}, 'Show')),
+                        m('td', [
+                            item.workbenchBaseURL() &&
+                                m('a.btn.btn-xs.btn-default', {
+                                    href: item.workbenchBaseURL()+'collections/'+item.uuid,
+                                }, 'Show'),
+                        ]),
                         m('td.arvados-uuid', item.uuid),
                         m('td', item.name || '(unnamed)'),
                         m('td', m(LocalizedDateTime, {parse: item.modified_at})),
                     ])
                 }),
             ]),
-            m('tfoot', m('tr', [
-                vnode.attrs.loader.done ? null : m('th[colspan=4]', m('button.btn.btn-xs', {
-                    className: vnode.attrs.loader.loading ? 'btn-default' : 'btn-primary',
+            loader.state == loader.DONE ? null : m('tfoot', m('tr', [
+                m('th[colspan=4]', m('button.btn.btn-xs', {
+                    className: loader.state == loader.LOADING ? 'btn-default' : 'btn-primary',
                     style: {
                         display: 'block',
                         width: '12em',
                         marginLeft: 'auto',
                         marginRight: 'auto',
                     },
-                    disabled: vnode.attrs.loader.loading,
+                    disabled: loader.state == loader.LOADING,
                     onclick: function() {
-                        vnode.attrs.loader.loadMore()
+                        loader.loadMore()
                         return false
                     },
-                }, vnode.attrs.loader.loading ? '(loading)' : 'Load more')),
+                }, loader.state == loader.LOADING ? '(loading)' : 'Load more')),
             ])),
         ])
     },
@@ -88,11 +94,17 @@ window.CollectionsSearch = {
             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) {
-                            if (q)
-                                filters.push(['any', '@@', q+':*'])
+                            var tsquery = to_tsquery(q)
+                            if (tsquery) {
+                                filters = filters.slice(0)
+                                filters.push(['any', '@@', tsquery])
+                            }
                             return vnode.state.sessionDB.request(session, 'arvados/v1/collections', {
                                 data: {
                                     filters: JSON.stringify(filters),
@@ -100,7 +112,7 @@ window.CollectionsSearch = {
                                 },
                             }).then(function(resp) {
                                 resp.items.map(function(item) {
-                                    item.session = session
+                                    item.workbenchBaseURL = workbenchBaseURL
                                 })
                                 return resp
                             })
@@ -115,14 +127,14 @@ window.CollectionsSearch = {
         return m('form', {
             onsubmit: function() {
                 vnode.state.searchActive(vnode.state.searchEntered())
-                vnode.state.forgetSavedState = true
+                vnode.state.forgetSavedHeight = true
                 return false
             },
         }, [
             m(SaveUIState, {
                 defaultState: '',
                 currentState: vnode.state.searchActive,
-                forgetSavedState: vnode.state.forgetSavedState,
+                forgetSavedHeight: vnode.state.forgetSavedHeight,
                 saveBodyHeight: true,
             }),
             vnode.state.loader && [
@@ -144,7 +156,7 @@ window.CollectionsSearch = {
                             ? m('span.label.label-xs.label-danger', 'none')
                             : vnode.state.loader.children.map(function(child) {
                                 return [m('span.label.label-xs', {
-                                    className: child.items() ? 'label-success' : 'label-warning',
+                                    className: child.state == child.LOADING ? 'label-warning' : 'label-success',
                                 }, child.sessionKey), ' ']
                             }),
                         ' ',