12033: Add /collections/multisite search page.
[arvados.git] / apps / workbench / app / assets / javascripts / components / sessions.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 $(document).on('ready', function() {
6     var db = new window.models.SessionDB()
7     db.checkForNewToken()
8     db.fillMissingUUIDs()
9 })
10
11 window.components = window.components || {}
12 window.components.sessions = {
13     oninit: function(vnode) {
14         vnode.state.db = new window.models.SessionDB()
15         vnode.state.hostToAdd = m.stream('')
16     },
17     view: function(vnode) {
18         var db = vnode.state.db
19         var sessions = db.loadAll()
20         return m('container', [
21             m('table.table.table-condensed.table-hover', m('tbody', [
22                 Object.keys(sessions).map(function(uuidPrefix) {
23                     var session = sessions[uuidPrefix]
24                     return m('tr', [
25                         session.token && session.user ? [
26                             m('td', m('a.btn.btn-xs.btn-default', {
27                                 uuidPrefix: uuidPrefix,
28                                 onclick: m.withAttr('uuidPrefix', db.logout),
29                             }, 'log out')),
30                             m('td', m('span.label.label-info', 'logged in')),
31                             m('td', {title: session.baseURL}, uuidPrefix),
32                             m('td', session.user.username),
33                             m('td', session.user.email),
34                         ] : [
35                             m('td', m('a.btn.btn-xs.btn-info', {
36                                 uuidPrefix: uuidPrefix,
37                                 onclick: m.withAttr('uuidPrefix', db.login),
38                             }, 'log in')),
39                             m('td', 'span.label.label-default', 'logged out'),
40                             m('td', {title: session.baseURL}, uuidPrefix),
41                             m('td'),
42                             m('td'),
43                         ],
44                         m('td', m('a.glyphicon.glyphicon-trash', {
45                             uuidPrefix: uuidPrefix,
46                             onclick: m.withAttr('uuidPrefix', db.trash),
47                         })),
48                     ])
49                 }),
50             ])),
51             m('.row', m('.col-md-6', [
52                 m('form', {
53                     onsubmit: function() {
54                         db.login(vnode.state.hostToAdd())
55                         return false
56                     },
57                 }, [
58                     m('.input-group', [
59                         m('input.form-control[type=text][name=apiHost][placeholder="API host"]', {
60                             oninput: m.withAttr('value', vnode.state.hostToAdd),
61                         }),
62                         m('.input-group-btn', [
63                             m('input.btn.btn-primary[type=submit][value="Log in"]', {
64                                 disabled: !vnode.state.hostToAdd(),
65                             }),
66                         ]),
67                     ]),
68                 ]),
69             ])),
70         ])
71     },
72 }