Skip to content

Commit 44344a5

Browse files
committed
agents: add clone button
1 parent 2778caf commit 44344a5

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

plugins/plugins-available/agents/templates/agents.tt

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<th class="w-20">Memory</th>
4747
<th class="w-20">Disk</th>
4848
<th class="w-24">Checks</th>
49-
<th class="w-32">
49+
<th class="w-20">
5050
<div class="flexrow flex-nowrap gap-x-1 justify-between">
5151
<div class="flexrow flex-nowrap gap-x-1 h-5">
5252
<a href="#" onclick="return agents_run_all(this, '.js-update-btn', {})"><i class="fa-solid fa-arrows-rotate text-sm" title="Update inventory for all visible servers"></i></a>
@@ -156,6 +156,7 @@
156156
<a href="#" class="js-update-btn" onclick="return send_form_in_background_and_reload(this)"><i class="fa-solid fa-arrows-rotate text-sm" title="Update inventory"></i></a>
157157
</form>
158158
<a href="agents.cgi?action=edit&amp;hostname=[% h.name | uri %]&backend=[% h.peer_key | uri %]"><i class="fa-solid fa-pencil text-sm" title='Edit this host'></i></a>
159+
<a href="agents.cgi?action=clone&amp;hostname=[% h.name | uri %]&backend=[% h.peer_key | uri %]"><i class="fa-solid fa-clone text-sm" title='Clone this host'></i></a>
159160
[% PROCESS _button btn = {
160161
form => { action => 'agents.cgi', },
161162
data => { 'action' => 'remove', 'hostname' => h.name, backend => h.peer_key, CSRFtoken => get_user_token(c), },

plugins/plugins-available/agents/templates/agents_edit.tt

+19-4
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,25 @@
310310
<a href="agents.cgi" class="button header-button rounded w-[70px]" title="Go back to agent list"><i class="uil uil-angle-double-left"></i>Back</a>
311311
</div>
312312
<h3>[% IF agent.hostname != "new" %]Edit[% ELSE%]Add[% END %] Agent</h3>
313-
<div class="w-40"></div>
313+
<div class="w-40 flex justify-end relative">
314+
<button class="w-fit ml-2 pr-1" onClick="toggleElement('action_menu', undefined, true); return false;">Actions <i class="uil uil-angle-down mr-0" title='More Host Actions'></i></button>
315+
<div id="action_menu" style="display: none;" class="context_menu w-[160px] left-0 top-[30px]">
316+
<form action="agents.cgi" method="POST">
317+
<input type="hidden" name="CSRFtoken" value="[% get_user_token(c) %]">
318+
<input type="hidden" name="hostname" value="[% agent.hostname | html %]">
319+
<input type="hidden" name="backend" value="[% agent.peer_key | html %]">
320+
<ul class="w-full">
321+
<li>
322+
<a href="agents.cgi?action=clone&amp;hostname=[% agent.hostname | uri %]&backend=[% agent.peer_key | uri %]" class="[% IF agent.hostname == "new" %]disabled[% END %]" onclick=""><i class="fa-solid fa-clone text-xs"></i> Clone</a>
323+
</li>
324+
<li><hr></li>
325+
<li class="[% IF agent.hostname != "new" %]hover-red[% END %]">
326+
<a href="" class="[% IF agent.hostname == "new" %]disabled[% END %]" onclick="if(confirm('really remove host: [% agent.hostname | html %]?')) { return send_form_in_background_and_forward(this, {action: 'remove' }, null, 'agents.cgi') }; return false;"><i class="fa-solid fa-trash text-xs"></i> Remove</a>
327+
</li>
328+
</ul>
329+
</form>
330+
</div>
331+
</div>
314332
</div>
315333
<form action="agents.cgi" method="POST" class="flexcol gap-y-0 w-full h-[calc(100%-50px)]" onsubmit="setFormBtnSpinner(this)">
316334
<input type="submit" onclick="return false;" class="hidden"><!--do not submit on enter-->
@@ -455,9 +473,6 @@
455473
[% PROCESS _check_type type="disabled" sub="sub_4" %]
456474
</div>
457475
</div>
458-
<div class="footer" style="flex: 0 0 40px;">
459-
[% IF agent.hostname != "new" %]<button name="action" value="remove" class="hover-red w-32" onclick="return(confirm('really remove host: [% agent.hostname | html %]?'))"><i class="uil uil-trash-alt"></i> Delete</button>[% END %]
460-
</div>
461476
</form>
462477
</div>
463478

root/thruk/javascript/thruk-3.20.2.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -5064,15 +5064,17 @@ function submitFormInBackground(form, cb, extraData) {
50645064
'Accept': "application/json; charset=utf-8"
50655065
},
50665066
success: function(data, textStatus, jqXHR) {
5067-
showMessageFromCookie();
50685067
if(cb) {
50695068
cb(form, true, data, textStatus, jqXHR);
5069+
} else {
5070+
showMessageFromCookie();
50705071
}
50715072
},
50725073
error: function(jqXHR, textStatus, errorThrown) {
5073-
showMessageFromCookie();
50745074
if(cb) {
50755075
cb(form, false, null, textStatus, jqXHR);
5076+
} else {
5077+
showMessageFromCookie();
50765078
}
50775079
ajax_xhr_error_logonly(jqXHR, textStatus, errorThrown);
50785080
}
@@ -5081,12 +5083,21 @@ function submitFormInBackground(form, cb, extraData) {
50815083
}
50825084

50835085
function send_form_in_background_and_reload(btn, extraData, skipTimeout) {
5084-
send_form_in_background_with_callback(btn, extraData, function() {
5086+
send_form_in_background_with_callback(btn, extraData, function(form, success) {
50855087
reloadPage();
50865088
}, skipTimeout);
50875089
return(false);
50885090
}
50895091

5092+
function send_form_in_background_and_forward(btn, extraData, skipTimeout, url) {
5093+
send_form_in_background_with_callback(btn, extraData, function(form, success) {
5094+
if(success) {
5095+
redirect_url(url);
5096+
}
5097+
}, skipTimeout);
5098+
return(false);
5099+
}
5100+
50905101
function send_form_in_background_with_callback(btn, extraData, cb, skipTimeout) {
50915102
var form = jQuery(btn).parents('FORM');
50925103
if(!checkRequiredFields(form)) {

themes/base.css

+3
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,9 @@ DIV.action_menu, DIV.context_menu {
15801580
SPAN.icon {
15811581
@apply inline-flex w-[20px] h-[20px];
15821582
}
1583+
&.disabled {
1584+
@apply cursor-default pointer-events-none;
1585+
}
15831586
}
15841587
&.no-hover {
15851588
@apply hover:bg-inherit;

0 commit comments

Comments
 (0)