1 module.exports = ArvApiStatusComponent;
3 var m = require('mithril')
4 , util = require('app/util');
6 function ArvApiStatusComponent(connection) {
8 apistatus.vm = (function() {
10 vm.connection = connection;
11 vm.dd = connection.discoveryDoc;
13 vm.init = function() {
18 vm.keepServices = m.prop();
20 vm.refresh = function() {
22 'KeepService', 'list', {}).then(vm.keepServices);
24 'Node', 'list', {}).then(vm.nodes);
26 vm.logout = function() {
27 vm.connection.token(undefined);
29 vm.ddSummary = function() {
30 return !vm.dd() ? {} : {
31 apiVersion: vm.dd().version + ' (' + vm.dd().revision + ')',
32 sourceVersion: m('a', {
33 href: 'https://arvados.org/projects/arvados/repository/changes?rev=' + vm.dd().source_version
34 }, vm.dd().source_version),
35 generatedAt: vm.dd().generatedAt,
36 websocket: util.choose(vm.connection.webSocket().readyState, {
37 0: m('span.label.label-warning', ['connecting']),
38 1: m('span.label.label-success', ['OK']),
39 2: m('span.label.label-danger', ['closing']),
40 3: m('span.label.label-danger', ['closed']),
41 }) || m('span.label.label-danger',
42 {title: ('advertised websocketUrl: ' +
43 vm.dd().websocketUrl)}, ['none'])
48 apistatus.controller = function() {
51 apistatus.view = function() {
52 var vm = apistatus.vm;
53 var ddSummary = vm.ddSummary();
54 return m('.panel.panel-info.arv-bs-api-status', [
56 vm.connection.apiPrefix(),
57 !vm.dd() ? '' : m('.pull-right', [
58 util.choose(!!vm.connection.token(), {
60 return m('a.btn.btn-xs.btn-default',
61 {onclick: vm.logout}, 'Log out');
64 return m('a.btn.btn-xs.btn-primary',
65 {href: vm.connection.loginLink()}, 'Log in');
70 m('.panel-body', !vm.dd() ? [vm.connection.state()] : [
73 Object.keys(ddSummary).map(function(key) {
75 m('.col-sm-4.lighten', key),
76 m('.col-sm-8', ddSummary[key]),
80 !vm.keepServices() ? '' : m('ul', [
81 '' + vm.keepServices().length + ' Keep services',
82 vm.keepServices().map(function(keepService) {
84 m('span.label.label-default',
85 keepService().service_type),
88 {href: '/show/'+keepService().uuid,
90 keepService().service_host,
92 keepService().service_port,
99 !vm.nodes() ? '' : m('ul', [
100 '' + vm.nodes().length + ' worker nodes',
101 vm.nodes().filter(function(node) {
102 return node().crunch_worker_state != 'down';
103 }).map(function(node) {
105 m('span.label.label-default', [
106 node().crunch_worker_state,
109 m('a', {href: '/show/'+node().uuid,
113 m('span.label.label-info', {title: 'time since last ping'}, [
114 ((new Date() - Date.parse(node().last_ping_at))/1000).toFixed(),
122 m('.row', 'Collection Job PipelineInstance'.split(' ').map(function(arvModelName) {
123 return m('.col-sm-2', [
124 m('a.btn.btn-xs.btn-default', {
125 style: 'width: 100%',
126 href: '/list/'+vm.connection.apiPrefix()+'/'+arvModelName,
128 }, arvModelName+'s'),