12519: Updated search box placeholder message
[arvados.git] / apps / workbench / app / assets / javascripts / components / collections.js
index fad7e749e03a61f1724f8810ddcc0e6ed7dc11ae..b1233d0ce8f0b5fc6b8e365365eb0ec7d4cc6669 100644 (file)
@@ -2,11 +2,10 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-window.components = window.components || {}
-window.components.collection_table = {
+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
@@ -37,6 +36,7 @@ window.components.collection_table = {
         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'),
@@ -45,38 +45,44 @@ window.components.collection_table = {
                 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', {
+                                    title: 'Show '+item.objectType.description,
+                                    href: item.workbenchBaseURL()+'/'+item.objectType.wb_path+'/'+item.uuid,
+                                }, item.objectType.label),
+                        ]),
                         m('td.arvados-uuid', item.uuid),
                         m('td', item.name || '(unnamed)'),
-                        m('td', m(window.components.datetime, {parse: item.modified_at})),
+                        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')),
             ])),
         ])
     },
 }
 
-window.components.collection_search = {
+window.CollectionsSearch = {
     oninit: function(vnode) {
-        vnode.state.sessionDB = new window.models.SessionDB()
+        vnode.state.sessionDB = new SessionDB()
         vnode.state.searchEntered = m.stream()
         vnode.state.searchActive = m.stream()
         // When searchActive changes (e.g., when restoring state
@@ -86,25 +92,60 @@ window.components.collection_search = {
         // with the given search term.
         vnode.state.searchActive.map(function(q) {
             var sessions = vnode.state.sessionDB.loadActive()
-            vnode.state.loader = new window.models.MergingLoader({
+            vnode.state.loader = new MergingLoader({
                 children: Object.keys(sessions).map(function(key) {
                     var session = sessions[key]
-                    return new window.models.MultipageLoader({
-                        loadFunc: function(filters) {
-                            if (q)
-                                filters.push(['any', '@@', q+':*'])
-                            return vnode.state.sessionDB.request(session, 'arvados/v1/collections', {
-                                data: {
-                                    filters: JSON.stringify(filters),
-                                    count: 'none',
+                    var workbenchBaseURL = function() {
+                        return vnode.state.sessionDB.workbenchBaseURL(session)
+                    }
+                    var searchable_objects = [
+                        {
+                            wb_path: 'groups',
+                            api_path: 'arvados/v1/groups',
+                            filters: [['group_class', '=', 'project']],
+                            label: 'P',
+                            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){
+                            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)
+                                    }
+                                    return vnode.state.sessionDB.request(session, obj_type.api_path, {
+                                        data: {
+                                            filters: JSON.stringify(filters),
+                                            count: 'none',
+                                        },
+                                    }).then(function(resp) {
+                                        resp.items.map(function(item) {
+                                            item.workbenchBaseURL = workbenchBaseURL
+                                            item.objectType = obj_type
+                                        })
+                                        return resp
+                                    })
                                 },
-                            }).then(function(resp) {
-                                resp.items.map(function(item) {
-                                    item.session = session
-                                })
-                                return resp
                             })
-                        },
+                        })
                     })
                 })
             })
@@ -115,21 +156,21 @@ window.components.collection_search = {
         return m('form', {
             onsubmit: function() {
                 vnode.state.searchActive(vnode.state.searchEntered())
-                vnode.state.forgetSavedState = true
+                vnode.state.forgetSavedHeight = true
                 return false
             },
         }, [
-            m(window.components.save_state, {
+            m(SaveUIState, {
                 defaultState: '',
                 currentState: vnode.state.searchActive,
-                forgetSavedState: vnode.state.forgetSavedState,
+                forgetSavedHeight: vnode.state.forgetSavedHeight,
                 saveBodyHeight: true,
             }),
             vnode.state.loader && [
                 m('.row', [
                     m('.col-md-6', [
                         m('.input-group', [
-                            m('input#search.form-control[placeholder=Search]', {
+                            m('input#search.form-control[placeholder=Search collections and projects]', {
                                 oninput: m.withAttr('value', vnode.state.searchEntered),
                                 value: vnode.state.searchEntered(),
                             }),
@@ -140,20 +181,18 @@ window.components.collection_search = {
                     ]),
                     m('.col-md-6', [
                         'Searching sites: ',
-                        Object.keys(sessions).length == 0
+                        vnode.state.loader.children.length == 0
                             ? m('span.label.label-xs.label-danger', 'none')
-                            : Object.keys(sessions).sort().map(function(key) {
+                            : vnode.state.loader.children.map(function(child) {
                                 return [m('span.label.label-xs', {
-                                    className: !vnode.state.loader.children[key] ? 'label-default' :
-                                        vnode.state.loader.children[key].items() ? 'label-success' :
-                                        'label-warning',
-                                }, key), ' ']
+                                    className: child.state == child.LOADING ? 'label-warning' : 'label-success',
+                                }, child.sessionKey), ' ']
                             }),
                         ' ',
                         m('a[href="/sessions"]', 'Add/remove sites'),
                     ]),
                 ]),
-                m(window.components.collection_table, {
+                m(CollectionsTable, {
                     loader: vnode.state.loader,
                 }),
             ],