Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / app / assets / javascripts / components / search.js
index 319622ddbd5eab2e95133b20c56875686be170ee..83ed1a68d4995d568c65d78f384039c4b1deada6 100644 (file)
@@ -29,10 +29,6 @@ window.SearchResultsTable = {
     },
     onupdate: function(vnode) {
         vnode.state.loader = vnode.attrs.loader
-        // This activates bootstrap tooltip feature
-        $(function () {
-            $('[data-toggle="tooltip"]').tooltip()
-        })
     },
     onremove: function(vnode) {
         window.clearInterval(vnode.state.timer)
@@ -42,9 +38,11 @@ window.SearchResultsTable = {
     view: function(vnode) {
         var loader = vnode.attrs.loader
         var iconsMap = {
-            C: m('i.fa.fa-fw.fa-archive'),
-            P: m('i.fa.fa-fw.fa-folder'),
+            collections: m('i.fa.fa-fw.fa-archive'),
+            projects: m('i.fa.fa-fw.fa-folder'),
         }
+        var db = new SessionDB()
+        var sessions = db.loadActive()
         return m('table.table.table-condensed', [
             m('thead', m('tr', [
                 m('th'),
@@ -54,16 +52,29 @@ window.SearchResultsTable = {
             ])),
             m('tbody', [
                 loader.items().map(function(item) {
+                    var session = sessions[item.uuid.slice(0,5)]
+                    var tokenParam = ''
+                    // Add the salted token to search result links from federated
+                    // remote hosts.
+                    if (!session.isFromRails && session.token.indexOf('v2/') == 0) {
+                        tokenParam = session.token
+                    }
                     return m('tr', [
-                        m('td', [
+                        m('td', m('form', {
+                            action: item.workbenchBaseURL() + '/' + item.objectType.wb_path + '/' + item.uuid,
+                            method: 'GET'
+                        }, [
+                            tokenParam !== '' &&
+                                m('input[type=hidden][name=api_token]', {value: tokenParam}),
                             item.workbenchBaseURL() &&
-                                m('a.btn.btn-xs.btn-default', {
+                                m('button.btn.btn-xs.btn-default[type=submit]', {
                                     'data-original-title': 'show '+item.objectType.description,
                                     'data-placement': 'top',
                                     'data-toggle': 'tooltip',
-                                    href: item.workbenchBaseURL()+'/'+item.objectType.wb_path+'/'+item.uuid,
-                                }, iconsMap[item.objectType.label]),
-                        ]),
+                                    // Bootstrap's tooltip feature
+                                    oncreate: function(vnode) { $(vnode.dom).tooltip() },
+                                }, iconsMap[item.objectType.wb_path]),
+                        ])),
                         m('td.arvados-uuid', item.uuid),
                         m('td', item.name || '(unnamed)'),
                         m('td', m(LocalizedDateTime, {parse: item.modified_at})),
@@ -93,6 +104,7 @@ window.SearchResultsTable = {
 window.Search = {
     oninit: function(vnode) {
         vnode.state.sessionDB = new SessionDB()
+        vnode.state.sessionDB.autoRedirectToHomeCluster('/search')
         vnode.state.searchEntered = m.stream()
         vnode.state.searchActive = m.stream()
         // When searchActive changes (e.g., when restoring state
@@ -110,37 +122,33 @@ window.Search = {
                     }
                     var searchable_objects = [
                         {
-                            wb_path: 'groups',
+                            wb_path: 'projects',
                             api_path: 'arvados/v1/groups',
                             filters: [['group_class', '=', 'project']],
-                            label: 'P',
+                            description: 'project',
+                        },
+                        {
+                            wb_path: 'projects',
+                            api_path: 'arvados/v1/groups',
+                            filters: [['group_class', '=', 'filter']],
                             description: 'project',
                         },
                         {
                             wb_path: 'collections',
                             api_path: 'arvados/v1/collections',
                             filters: [],
-                            label: 'C',
                             description: 'collection',
                         },
                     ]
                     return new MergingLoader({
                         sessionKey: key,
                         // For every session, search for every object type
-                        children: searchable_objects.map(function(obj_type){
+                        children: searchable_objects.map(function(obj_type) {
                             return new MultipageLoader({
                                 sessionKey: key,
-                                objectKind: obj_type.label,
                                 loadFunc: function(filters) {
-                                    var tsquery = to_tsquery(q)
-                                    if (tsquery) {
-                                        filters = filters.slice(0)
-                                        filters.push(['any', '@@', tsquery])
-                                    }
-                                    // Apply additional type dependant filters, if any.
-                                    for (var f of obj_type.filters) {
-                                        filters.push(f)
-                                    }
+                                    // Apply additional type dependant filters
+                                    filters = filters.concat(obj_type.filters).concat(ilike_filters(q))
                                     return vnode.state.sessionDB.request(session, obj_type.api_path, {
                                         data: {
                                             filters: JSON.stringify(filters),
@@ -155,14 +163,13 @@ window.Search = {
                                     })
                                 },
                             })
-                        })
+                        }),
                     })
-                })
+                }),
             })
         })
     },
     view: function(vnode) {
-        var sessions = vnode.state.sessionDB.loadAll()
         return m('form', {
             onsubmit: function() {
                 vnode.state.searchActive(vnode.state.searchEntered())