12033: Style uuid column.
[arvados.git] / apps / workbench / app / assets / javascripts / components / collections.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 window.components = window.components || {}
6 window.components.collection_table = {
7     view: function(vnode) {
8         return m('table.table.table-condensed', [
9             m('thead', m('tr', [
10                 m('th'),
11                 m('th', 'uuid'),
12                 m('th', 'name'),
13                 m('th', 'last modified'),
14             ])),
15             m('tbody', [
16                 vnode.attrs.loader.displayable.map(function(item) {
17                     return m('tr', [
18                         m('td', m('a.btn.btn-xs.btn-default', {href: item.session.baseURL.replace('://', '://workbench.')+'/collections/'+item.uuid}, 'Show')),
19                         m('td.arvados-uuid', item.uuid),
20                         m('td', item.name || '(unnamed)'),
21                         m('td', m(window.components.datetime, {parse: item.modified_at})),
22                     ])
23                 }),
24             ]),
25             m('tfoot', m('tr', [
26                 m('th[colspan=4]', m('button.btn.btn-xs', {
27                     className: vnode.attrs.loader.loadMore ? 'btn-primary' : 'btn-default',
28                     style: {
29                         display: 'block',
30                         width: '12em',
31                         marginLeft: 'auto',
32                         marginRight: 'auto',
33                     },
34                     disabled: !vnode.attrs.loader.loadMore,
35                     onclick: function() {
36                         vnode.attrs.loader.loadMore()
37                         return false
38                     },
39                 }, vnode.attrs.loader.loadMore ? 'Load more' : '(loading)')),
40             ])),
41         ])
42     },
43 }
44
45 window.components.collection_search = {
46     oninit: function(vnode) {
47         vnode.state.sessionDB = new window.models.SessionDB()
48         vnode.state.searchEntered = m.stream('')
49         vnode.state.searchStart = m.stream('')
50         vnode.state.searchStart.map(function(q) {
51             vnode.state.loader = new window.models.MultisiteLoader({
52                 loadFunc: function(session, filters) {
53                     if (q)
54                         filters.push(['any', '@@', q+':*'])
55                     return vnode.state.sessionDB.request(session, 'arvados/v1/collections', {
56                         data: {
57                             filters: JSON.stringify(filters),
58                             count: 'none',
59                         },
60                     })
61                 },
62                 sessionDB: vnode.state.sessionDB,
63             })
64         })
65     },
66     view: function(vnode) {
67         var sessions = vnode.state.sessionDB.loadAll()
68         return m('form', {
69             onsubmit: function() {
70                 vnode.state.searchStart(vnode.state.searchEntered())
71                 return false
72             },
73         }, [
74             m('.row', [
75                 m('.col-md-6', [
76                     m('.input-group', [
77                         m('input#search.form-control[placeholder=Search]', {
78                             oninput: m.withAttr('value', vnode.state.searchEntered),
79                         }),
80                         m('.input-group-btn', [
81                             m('input.btn.btn-primary[type=submit][value="Search"]'),
82                         ]),
83                     ]),
84                 ]),
85                 m('.col-md-6', [
86                     'Searching sites: ',
87                     Object.keys(sessions).length == 0
88                         ? m('span.label.label-xs.label-danger', 'none')
89                         : Object.keys(sessions).sort().map(function(key) {
90                             return [m('span.label.label-xs', {
91                                 className: vnode.state.loader.pagers[key].items() ? 'label-info' : 'label-default',
92                             }, key), ' ']
93                         }),
94                     ' ',
95                     m('a[href="/sessions"]', 'Add/remove sites'),
96                 ]),
97             ]),
98             m(window.components.collection_table, {
99                 loader: vnode.state.loader,
100             }),
101         ])
102     },
103 }