20259: Add documentation for banner and tooltip features
[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 SessionDB();
7     db.checkForNewToken();
8     db.fillMissingUUIDs();
9     db.autoLoadRemoteHosts();
10 });
11
12 window.SessionsTable = {
13     oninit: function(vnode) {
14         vnode.state.db = new SessionDB();
15         vnode.state.db.autoRedirectToHomeCluster('/sessions');
16         vnode.state.db.migrateNonFederatedSessions();
17         vnode.state.hostToAdd = m.stream('');
18         vnode.state.error = m.stream();
19         vnode.state.checking = m.stream();
20     },
21     view: function(vnode) {
22         var db = vnode.state.db;
23         var sessions = db.loadAll();
24         return m('.container', [
25             m('p', [
26                 'You can log in to multiple Arvados sites here, then use the ',
27                 m('a[href="/search"]', 'multi-site search'),
28                 ' page to search collections and projects on all sites at once.'
29             ]),
30             m('table.table.table-condensed.table-hover', [
31                 m('thead', m('tr', [
32                     m('th', 'status'),
33                     m('th', 'cluster ID'),
34                     m('th', 'username'),
35                     m('th', 'email'),
36                     m('th', 'actions'),
37                     m('th')
38                 ])),
39                 m('tbody', [
40                     Object.keys(sessions).map(function(uuidPrefix) {
41                         var session = sessions[uuidPrefix];
42                         return m('tr', [
43                             session.token && session.user ? [
44                                 m('td', session.user.is_active ?
45                                     m('span.label.label-success', 'logged in') :
46                                     m('span.label.label-warning', 'inactive')),
47                                 m('td', {title: session.baseURL}, uuidPrefix),
48                                 m('td', session.user.username),
49                                 m('td', session.user.email),
50                                 m('td', session.isFromRails ? null : m('button.btn.btn-xs.btn-default', {
51                                     uuidPrefix: uuidPrefix,
52                                     onclick: m.withAttr('uuidPrefix', db.logout),
53                                 }, session.listedHost ? 'Disable ':'Log out ', m('span.glyphicon.glyphicon-log-out')))
54                             ] : [
55                                 m('td', m('span.label.label-default', 'logged out')),
56                                 m('td', {title: session.baseURL}, uuidPrefix),
57                                 m('td'),
58                                 m('td'),
59                                 m('td', m('a.btn.btn-xs.btn-primary', {
60                                     uuidPrefix: uuidPrefix,
61                                     onclick: db.login.bind(db, session.baseURL),
62                                 }, session.listedHost ? 'Enable ':'Log in ', m('span.glyphicon.glyphicon-log-in')))
63                             ],
64                             m('td', (session.isFromRails || session.listedHost) ? null :
65                                 m('button.btn.btn-xs.btn-default', {
66                                     uuidPrefix: uuidPrefix,
67                                     onclick: m.withAttr('uuidPrefix', db.trash),
68                                 }, 'Remove ', m('span.glyphicon.glyphicon-trash'))
69                             ),
70                         ])
71                     }),
72                 ]),
73             ]),
74             m('.row', m('.col-md-6', [
75                 m('form', {
76                     onsubmit: function() {
77                         vnode.state.error(null)
78                         vnode.state.checking(true)
79                         db.findAPI(vnode.state.hostToAdd())
80                             .then(db.login)
81                             .catch(function() {
82                                 vnode.state.error(true)
83                             })
84                             .then(vnode.state.checking.bind(null, null))
85                         return false
86                     },
87                 }, [
88                     m('p', [
89                         'To add a remote Arvados site, paste the remote site\'s host here (see "ARVADOS_API_HOST" on the "current token" page).',
90                     ]),
91                     m('.input-group', { className: vnode.state.error() && 'has-error' }, [
92                         m('input.form-control[type=text][name=apiHost][placeholder="zzzzz.arvadosapi.com"]', {
93                             oninput: m.withAttr('value', vnode.state.hostToAdd),
94                         }),
95                         m('.input-group-btn', [
96                             m('input.btn.btn-primary[type=submit][value="Log in"]', {
97                                 disabled: !vnode.state.hostToAdd(),
98                             }),
99                         ]),
100                     ]),
101                 ]),
102                 m('p'),
103                 vnode.state.error() && m('p.alert.alert-danger', 'Request failed. Make sure this is a working API server address.'),
104                 vnode.state.checking() && m('p.alert.alert-info', 'Checking...'),
105             ])),
106         ])
107     },
108 }