1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 $(document).on('ready', function() {
6 var db = new SessionDB();
9 db.autoLoadRemoteHosts();
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();
21 view: function(vnode) {
22 var db = vnode.state.db;
23 var sessions = db.loadAll();
24 return m('.container', [
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.'
30 m('table.table.table-condensed.table-hover', [
33 m('th', 'cluster ID'),
40 Object.keys(sessions).map(function(uuidPrefix) {
41 var session = sessions[uuidPrefix];
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')))
55 m('td', m('span.label.label-default', 'logged out')),
56 m('td', {title: session.baseURL}, uuidPrefix),
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')))
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'))
74 m('.row', m('.col-md-6', [
76 onsubmit: function() {
77 vnode.state.error(null)
78 vnode.state.checking(true)
79 db.findAPI(vnode.state.hostToAdd())
82 vnode.state.error(true)
84 .then(vnode.state.checking.bind(null, null))
89 'To add a remote Arvados site, paste the remote site\'s host here (see "ARVADOS_API_HOST" on the "current token" page).',
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),
95 m('.input-group-btn', [
96 m('input.btn.btn-primary[type=submit][value="Log in"]', {
97 disabled: !vnode.state.hostToAdd(),
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...'),