Commit 24f15509 authored by Ziirish's avatar Ziirish

show labels on client stats view

parent 93c224ff
Pipeline #1661 canceled with stages
in 59 seconds
......@@ -1048,21 +1048,22 @@ class ClientLabels(Resource):
return {'labels': labels}
@staticmethod
def _get_labels(client, server):
def _get_labels(client, server=None):
key = 'labels-{}-{}'.format(client, server)
ret = cache.cache.get(key)
if ret is not None:
return ret
labels = bui.client.get_client_labels(client, agent=server)
ret = []
ignore = re.compile('|'.join(bui.ignore_labels)) if bui.ignore_labels else None
reformat = [(re.compile(regex), replace) for regex, replace in bui.format_labels] if bui.format_labels else []
for label in labels:
if bui.ignore_labels and \
re.search('|'.join(bui.ignore_labels), label):
ignore.search(label):
continue
tmp_label = label
if bui.format_labels:
for regex, replace in bui.format_labels:
tmp_label = re.sub(regex, replace, tmp_label)
for regex, replace in reformat:
tmp_label = regex.sub(replace, tmp_label)
ret.append(tmp_label)
cache.cache.set(key, ret, 1800)
return ret
......
......@@ -17,7 +17,15 @@
{% if current_user and current_user.is_authenticated and (current_user.is_admin or current_user.is_moderator) -%}
{% set extra_features = True %}
{% endif -%}
<h1 class="page-header">{{ cname }} {% if extra_features %}<a href="{{ url_for("view.cli_settings", server=server, client=cname) }}" class="btn btn-info" title="{{ _('edit') }}"><i class="fa fa-pencil" aria-hidden="true"></i></a>{% endif %}</h1>
<div class="row page-header">
<div class="col-md-4">
<h1>{{ cname }} {% if extra_features %}<a href="{{ url_for("view.cli_settings", server=server, client=cname) }}" class="btn btn-info" title="{{ _('edit') }}"><i class="fa fa-pencil" aria-hidden="true"></i></a>{% endif %}</h1>
</div>
<div class="col-md-8">
<div class="pull-right" id="client-labels">
</div>
</div>
</div>
<h2 class="sub-header">{{ _('Backups') }} <span id="running-status" class="label pull-right"></span></h2>
<p>
......
......@@ -213,10 +213,12 @@ var refresh_status = function( is_running ) {
{% endif %}
var url = '{{ url_for(api_running_clients, client=cname, server=server) }}';
var client_status_url = '{{ url_for("api.client_running_status", name=cname, server=server) }}';
var client_labels_url = '{{ url_for("api.client_labels", name=cname, server=server) }}';
var _get_running = undefined;
var _get_status = undefined;
var _client_running = false;
var _span = $('#running-status');
var _labels = $('#client-labels');
var _inner_format_status = function(status) {
var _content = '<i class="'+__icons[status.state]+'" aria-hidden="true"></i>&nbsp;';
if (status.state == '{{ _("running") }}') {
......@@ -242,6 +244,13 @@ var refresh_status = function( is_running ) {
_span.addClass(__status[_status.state]);
});
};
$.getJSON(client_labels_url, function(labels) {
var _labels_span = '';
_.forEach(labels, function(label) {
_labels_span += '<span class="label label-info">' + label + '</span>&nbsp;';
});
_labels.html(_labels_span);
});
if (is_running) {
_get_running = $.getJSON(url, function(running) {
if (_.indexOf(running, '{{ cname }}') != -1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment