12033: Fix typo in selector.
[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', [
22                 m('thead', m('tr', [
23                     m('th', 'status'),
24                     m('th', 'cluster ID'),
25                     m('th', 'username'),
26                     m('th', 'email'),
27                     m('th', 'actions'),
28                     m('th'),
29                 ])),
30                 m('tbody', [
31                     Object.keys(sessions).map(function(uuidPrefix) {
32                         var session = sessions[uuidPrefix]
33                         return m('tr', [
34                             session.token && session.user ? [
35                                 m('td', m('span.label.label-success', 'logged in')),
36                                 m('td', {title: session.baseURL}, uuidPrefix),
37                                 m('td', session.user.username),
38                                 m('td', session.user.email),
39                                 m('td', session.isFromRails ? null : m('button.btn.btn-xs.btn-default', {
40                                     uuidPrefix: uuidPrefix,
41                                     onclick: m.withAttr('uuidPrefix', db.logout),
42                                 }, 'Log out ', m('span.glyphicon.glyphicon-log-out'))),
43                             ] : [
44                                 m('td', m('span.label.label-default', 'logged out')),
45                                 m('td', {title: session.baseURL}, uuidPrefix),
46                                 m('td'),
47                                 m('td'),
48                                 m('td', m('a.btn.btn-xs.btn-primary', {
49                                     uuidPrefix: uuidPrefix,
50                                     onclick: db.login.bind(db, session.baseURL),
51                                 }, 'Log in ', m('span.glyphicon.glyphicon-log-in'))),
52                             ],
53                             m('td', session.isFromRails ? null : m('button.btn.btn-xs.btn-default', {
54                                 uuidPrefix: uuidPrefix,
55                                 onclick: m.withAttr('uuidPrefix', db.trash),
56                             }, 'Remove ', m('span.glyphicon.glyphicon-trash'))),
57                         ])
58                     }),
59                 ]),
60             ]),
61             m('.row', m('.col-md-6', [
62                 m('form', {
63                     onsubmit: function() {
64                         db.login(vnode.state.hostToAdd())
65                         return false
66                     },
67                 }, [
68                     m('.input-group', [
69                         m('input.form-control[type=text][name=apiHost][placeholder="API host"]', {
70                             oninput: m.withAttr('value', vnode.state.hostToAdd),
71                         }),
72                         m('.input-group-btn', [
73                             m('input.btn.btn-primary[type=submit][value="Log in"]', {
74                                 disabled: !vnode.state.hostToAdd(),
75                             }),
76                         ]),
77                     ]),
78                 ]),
79             ])),
80         ])
81     },
82 }