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