Merge branch 'master' into 11850-singlecontainer-max-requirements
[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 ? null : m('button.btn.btn-xs.btn-default', {
65                                 uuidPrefix: uuidPrefix,
66                                 onclick: m.withAttr('uuidPrefix', db.trash),
67                             }, 'Remove ', m('span.glyphicon.glyphicon-trash'))),
68                         ])
69                     }),
70                 ]),
71             ]),
72             m('.row', m('.col-md-6', [
73                 m('form', {
74                     onsubmit: function() {
75                         vnode.state.error(null)
76                         vnode.state.checking(true)
77                         db.findAPI(vnode.state.hostToAdd())
78                             .then(db.login)
79                             .catch(function() {
80                                 vnode.state.error(true)
81                             })
82                             .then(vnode.state.checking.bind(null, null))
83                         return false
84                     },
85                 }, [
86                     m('p', [
87                         'To add a remote Arvados site, paste the remote site\'s host here (see "ARVADOS_API_HOST" on the "current token" page).',
88                     ]),
89                     m('.input-group', { className: vnode.state.error() && 'has-error' }, [
90                         m('input.form-control[type=text][name=apiHost][placeholder="zzzzz.arvadosapi.com"]', {
91                             oninput: m.withAttr('value', vnode.state.hostToAdd),
92                         }),
93                         m('.input-group-btn', [
94                             m('input.btn.btn-primary[type=submit][value="Log in"]', {
95                                 disabled: !vnode.state.hostToAdd(),
96                             }),
97                         ]),
98                     ]),
99                 ]),
100                 m('p'),
101                 vnode.state.error() && m('p.alert.alert-danger', 'Request failed. Make sure this is a working API server address.'),
102                 vnode.state.checking() && m('p.alert.alert-info', 'Checking...'),
103             ])),
104         ])
105     },
106 }