Reingrate log view directly at the bottom of the service status page, now that we have at least the journalctl as a meaninful log. + various cosmetic and button tweaks

This commit is contained in:
Alexandre Aubin 2019-11-18 16:10:58 +01:00
parent e187e4b61a
commit c6b1bfb1c2
2 changed files with 53 additions and 42 deletions

View file

@ -40,15 +40,26 @@
// Status & actions for a service
app.get('#/services/:service', function (c) {
c.api('GET', '/services/'+ c.params['service'], {}, function(data) {
c.api('GET', '/services/'+ c.params['service'] +'/log', {number: 50}, function(data_log) {
data.name = c.params['service'];
if (data.last_state_change == 'unknown')
{
data.last_state_change = 0;
}
data.logs = [];
$.each(data_log, function(k, v) {
data.logs.push({filename: k, filecontent: v.join('\n')});
});
// Sort logs by filename, put the journalctl/systemd log on top
data.logs.sort(function(a,b) { return a.filename === "journalctl" ? -1 : b.filename === "journalctl" ? 1 : a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0; });
c.view('service/service_info', data, function() {
// Configure behavior for enable/disable and start/stop buttons
$('button[data-action]').on('click', function() {
$('button[data-action="start"], button[data-action="stop"]').on('click', function() {
var service = $(this).data('service');
var action = $(this).data('action');
@ -58,32 +69,35 @@
var method = null,
endurl = service;
switch (action) {
case 'start':
method = 'PUT';
break;
case 'stop':
method = 'DELETE';
break;
case 'enable':
method = 'PUT';
endurl += '/enable';
break;
case 'disable':
method = 'DELETE';
endurl += '/enable';
break;
default:
c.flash('fail', y18n.t('unknown_action', [action]));
c.refresh();
return;
}
method = action === "start" ? 'PUT' : 'DELETE';
c.api(method, '/services/'+ endurl, {}, function() { c.refresh(); });
});
});
// Configure behavior for enable/disable and start/stop buttons
$('button[data-action="share"]').on('click', function() {
c.showLoader();
// Send to paste.yunohost.org
$.ajax({
type: "POST",
url: 'https://paste.yunohost.org/documents',
data: $("#logs").text(),
})
.success(function(data, textStatus, jqXHR) {
window.open('https://paste.yunohost.org/' + data.key, '_blank');
})
.fail(function() {
c.flash('fail', y18n.t('paste_error'));
})
.always(function(){
c.hideLoader();
});
});
});
});
});
});
// Service log

View file

@ -9,14 +9,20 @@
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title"><span class="fa-fw fa-info-circle"></span> {{t 'infos'}}</h2>
<h2 class="panel-title" style="display: inline-block; margin-right: 10px;"><span class="fa-fw fa-info-circle"></span> {{t name}}</h2>
{{#if (eq status "running")}}
<button class="btn btn-sm btn-danger pull-right" data-service="{{name}}" data-action="stop">
<span class="fa-stop"></span> {{t 'stop'}}
</button>
{{else}}
<button class="btn btn-sm btn-success pull-right" data-service="{{name}}" data-action="start">
<span class="fa-play"></span> {{t 'start'}}
</button>
{{/if}}
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt>{{t 'name'}}</dt>
<dd>{{name}}</dd>
<dt>{{t 'description'}}</dt>
<dd>{{description}}</dd>
@ -55,24 +61,15 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title"><span class="fa-fw fa-wrench"></span> {{t 'operations'}}</h2>
<h2 class="panel-title" style="display: inline-block; margin-right: 10px;"><span class="fa-fw fa-book"></span> {{t 'logs'}}</h2>
<button class="btn btn-sm btn-success pull-right" data-action="share"><span class="fa-cloud-upload"></span> {{t 'logs_share_with_yunopaste'}}</button>
</div>
<div class="panel-body">
<dl class="dl-horizontal">
{{#if (eq status "running")}}
<button class="btn btn-danger" data-service="{{name}}" data-action="stop">
<span class="fa-stop"></span> {{t 'stop'}}
</button>
{{else}}
<button class="btn btn-success" data-service="{{name}}" data-action="start">
<span class="fa-play"></span> {{t 'start'}}
</button>
{{/if}}
</dl>
<div id="logs" class="panel-body">
{{#logs}}
<h2>{{filename}}</h2>
<pre class="service-log">{{filecontent}}</pre>
{{/logs}}
</div>
</div>