Merge branch 'master' into 12033-multisite-search
[arvados.git] / apps / workbench / app / assets / javascripts / components / sessions.js
index be4b7e39dd8fd59885cff4c898d6fb9335f7603b..17c144c589ac9e952b056ad263f01bf5b2b4cb47 100644 (file)
@@ -3,51 +3,60 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 $(document).on('ready', function() {
-    var db = new window.models.SessionDB()
+    var db = new SessionDB()
     db.checkForNewToken()
     db.fillMissingUUIDs()
 })
 
-window.components = window.components || {}
-window.components.sessions = {
+window.SessionsTable = {
     oninit: function(vnode) {
-        vnode.state.db = new window.models.SessionDB()
+        vnode.state.db = new SessionDB()
         vnode.state.hostToAdd = m.stream('')
     },
     view: function(vnode) {
         var db = vnode.state.db
         var sessions = db.loadAll()
-        return m('container', [
-            m('table.table.table-condensed.table-hover', m('tbody', [
-                Object.keys(sessions).map(function(uuidPrefix) {
-                    var session = sessions[uuidPrefix]
-                    return m('tr', [
-                        session.token && session.user ? [
-                            m('td', m('a.btn.btn-xs.btn-default', {
+        return m('.container', [
+            m('table.table.table-condensed.table-hover', [
+                m('thead', m('tr', [
+                    m('th', 'status'),
+                    m('th', 'cluster ID'),
+                    m('th', 'username'),
+                    m('th', 'email'),
+                    m('th', 'actions'),
+                    m('th'),
+                ])),
+                m('tbody', [
+                    Object.keys(sessions).map(function(uuidPrefix) {
+                        var session = sessions[uuidPrefix]
+                        return m('tr', [
+                            session.token && session.user ? [
+                                m('td', m('span.label.label-success', 'logged in')),
+                                m('td', {title: session.baseURL}, uuidPrefix),
+                                m('td', session.user.username),
+                                m('td', session.user.email),
+                                m('td', session.isFromRails ? null : m('button.btn.btn-xs.btn-default', {
+                                    uuidPrefix: uuidPrefix,
+                                    onclick: m.withAttr('uuidPrefix', db.logout),
+                                }, 'Log out ', m('span.glyphicon.glyphicon-log-out'))),
+                            ] : [
+                                m('td', m('span.label.label-default', 'logged out')),
+                                m('td', {title: session.baseURL}, uuidPrefix),
+                                m('td'),
+                                m('td'),
+                                m('td', m('a.btn.btn-xs.btn-primary', {
+                                    uuidPrefix: uuidPrefix,
+                                    onclick: db.login.bind(db, session.baseURL),
+                                }, 'Log in ', m('span.glyphicon.glyphicon-log-in'))),
+                            ],
+                            m('td', session.isFromRails ? null : m('button.btn.btn-xs.btn-default', {
                                 uuidPrefix: uuidPrefix,
-                                onclick: m.withAttr('uuidPrefix', db.logout),
-                            }, 'log out')),
-                            m('td', m('span.label.label-info', 'logged in')),
-                            m('td', {title: session.baseURL}, uuidPrefix),
-                            m('td', session.user.username),
-                            m('td', session.user.email),
-                        ] : [
-                            m('td', m('a.btn.btn-xs.btn-info', {
-                                uuidPrefix: uuidPrefix,
-                                onclick: m.withAttr('uuidPrefix', db.login),
-                            }, 'log in')),
-                            m('td', 'span.label.label-default', 'logged out'),
-                            m('td', {title: session.baseURL}, uuidPrefix),
-                            m('td'),
-                            m('td'),
-                        ],
-                        m('td', m('a.glyphicon.glyphicon-trash', {
-                            uuidPrefix: uuidPrefix,
-                            onclick: m.withAttr('uuidPrefix', db.trash),
-                        })),
-                    ])
-                }),
-            ])),
+                                onclick: m.withAttr('uuidPrefix', db.trash),
+                            }, 'Remove ', m('span.glyphicon.glyphicon-trash'))),
+                        ])
+                    }),
+                ]),
+            ]),
             m('.row', m('.col-md-6', [
                 m('form', {
                     onsubmit: function() {