Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a few edits #241

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added contents/images/Loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contents/images/Simple-Loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contents/images/details_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contents/images/details_open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contents/images/sort_asc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contents/images/sort_both.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contents/images/sort_desc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions contents/js/jquery-1.10.2.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions contents/js/jquery-3.6.0.min.js

Large diffs are not rendered by default.

15,333 changes: 15,333 additions & 0 deletions contents/js/jquery.dataTables-1.11.3.js

Large diffs are not rendered by default.

14,623 changes: 14,623 additions & 0 deletions contents/js/jquery.dataTables.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions contents/js/jquery.min.js

Large diffs are not rendered by default.

1,407 changes: 1,407 additions & 0 deletions contents/js/modernizr.js

Large diffs are not rendered by default.

467 changes: 467 additions & 0 deletions contents/static/jquery.dataTables.css

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions src/ansiblecmdb/data/tpl/html_fancy.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## -*- coding: utf-8 -*-
<%! from ansiblecmdb.util import to_bool %>
<%! import os %>

<%namespace name="defs" file="/html_fancy_defs.html" import="*" />

Expand All @@ -18,9 +19,13 @@ cols.extend(cust_cols)

# Set the Javascript resource URL (local disk or CDN)
if local_js is False:
res_url = "https://cdn.datatables.net/1.10.2/"
res_url = os.getenv('STATIC_ROOT_URL', ".")
jquery_res_uri = os.getenv('JQUERY_RES_URI', "js/jquery-1.10.2.min.js")
dataTable_res_uri = os.getenv('DATATABLE_RES_URI', "js/jquery.dataTables.js")
else:
res_url = "file://" + data_dir + "/static/"
res_url = "."
jquery_res_uri = "js/jquery-1.10.2.min.js"
dataTable_res_uri = "js/jquery.dataTables.js"

# Set the link type for the host overview table's 'host' column (the link that
# takes you to the host details).
Expand All @@ -29,7 +34,7 @@ if host_details is False:
link_type = "none"
%>

<% html_header("Ansible Overview", local_js, res_url) %>
<% html_header("Ansible Overview", local_js, res_url, jquery_res_uri, dataTable_res_uri) %>
<% html_header_bar("Host overview") %>
<% html_col_toggles(cols) %>
<% html_host_overview(cols, hosts, skip_empty=skip_empty, link_type=link_type) %>
Expand Down
128 changes: 104 additions & 24 deletions src/ansiblecmdb/data/tpl/html_fancy_defs.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<%! import datetime %>
<%! import socket %>
<%! import getpass %>
<%! import os %>
<%! from ansiblecmdb.util import to_bool %>
<%! from mako.template import Template %>

Expand Down Expand Up @@ -116,7 +117,7 @@
##
## HTML fragments
##
<%def name="html_header(title, local_js, res_url)">
<%def name="html_header(title, local_js, res_url, jquery_res_uri, dataTable_res_uri)">
<html>
<head>
<meta charset="UTF-8">
Expand Down Expand Up @@ -218,21 +219,44 @@
#hosts table.net_overview td, #hosts table.net_overview th { text-align: left; padding: 0px 0px 8px 16px; margin: 0px; }
#hosts table.net_overview { margin: 16px 0px 16px 0px; }
#hosts .error { color: #FF0000; }

/* my Custom CSS */
/* Paste this css to your style sheet file or under head tag */
/* This only works with JavaScript,
if it's not present, don't show loader */
.no-js #loader { display: none; }
.js #loader { display: block; position: absolute; left: 100px; top: 0; }
.se-pre-con {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url(${res_url}/images/Loading.gif) center no-repeat #fff;
}

td { line-height: 1.4; }

<link rel="stylesheet" href="${res_url}/js/jquery.dataTables.css">

</style>
<!-- DataTables assets -->
% if local_js is False:
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="${res_url}/${jquery_res_uri}"></script>
% else:
<script type="text/javascript" charset="utf8" src="${res_url}/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="${res_url}/${jquery_res_uri}"></script>
% endif
<script type="text/javascript" charset="utf8" src="${res_url}/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf8" src="${res_url}/${dataTable_res_uri}"></script>
<script type="text/javascript" charset="utf8" src="${res_url}/js/modernizr.js"></script>
</head>
<body>
<div class="se-pre-con"></div>
</%def>

<%def name="html_header_bar(title)">
<header>
<h1>${title}</h1>
<h1><a href="/">${title}</a></h1>
<span id="top"><a href="#">Back to top</a></span>
<span id="clear_settings"><a href="javascript:window.localStorage.clear('columnVisibility'); location.reload();" title="If things are acting weird, press this button">Clear settings</a></span>
<span id="generated">Generated on <span class="detail">${datetime.datetime.now().strftime('%c')}</span> by <span class="detail">${getpass.getuser()}</span> @ <span class="detail">${socket.getfqdn()}</span></span>
Expand All @@ -241,7 +265,8 @@ <h1>${title}</h1>

<%def name="html_footer_bar(version)">
<footer>
<p>Generated by <a href="https://github.com/fboender/ansible-cmdb">ansible-cmdb</a> v${version} &dash; &copy; Ferry Boender 2017</p>
<p>Edited by <a href="https://github.com/miladpav/ansible-cmdb">ansible-cmdb</a> v${version} &dash; &copy; Milad PourAllahverdi 2021</p>
<p>Main Project <a href="https://github.com/fboender/ansible-cmdb">ansible-cmdb</a>&dash; &copy; Ferry Boender 2017</p>
</footer>
</%def>

Expand Down Expand Up @@ -270,6 +295,8 @@ <h2>Shown columns</h2>
<div id="host_overview">
<h2>Host overview</h2>
<div id="host_overview_tbl_wrapper">
<!-- export to csv Added -->
<button type="button" onclick="exportTableToCSV('servers.csv')">Download CSV</button>
<table id="host_overview_tbl" class="demo display dataTable compact">
<thead>
<tr>
Expand All @@ -282,14 +309,14 @@ <h2>Host overview</h2>
% for hostname, host in sorted(hosts.items()):
<% log.debug(u"Rendering host overview for {0}".format(hostname)) %>
% if skip_empty is False or 'ansible_facts' in host:
<tr>\
<tr>
% for col in cols:
% if "func" in col:
<td>${col["func"](host, **kwargs)}</td>\
<td>${col["func"](host, **kwargs)}</td>
% elif "jsonxs" in col:
<td>${col__cust_jsonxs(host, col=col, **kwargs)}</td>\
<td>${col__cust_jsonxs(host, col=col, **kwargs)}</td>
% elif "tpl" in col:
<td>${col__cust_tpl(host, col=col, **kwargs)}</td>\
<td>${col__cust_tpl(host, col=col, **kwargs)}</td>
% endif
% endfor
</tr>
Expand Down Expand Up @@ -479,6 +506,49 @@ <h3 class="toggle-collapse ${collapsed_host_class}" id="${host['name']}" data-ho
});
</%def>


// export csv button on click
<%def name="js_export_to_csv()">
function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;
csvFile = new Blob([csv], {type: "text/csv"});
downloadLink = document.createElement("a");
downloadLink.download = filename;
downloadLink.href = window.URL.createObjectURL(csvFile);
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}

function exportTableToCSV(filename) {
var csv = [];
var rows = document.querySelectorAll("table tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++) {
var concatenate_lines = '';
var lines = cols[j].querySelectorAll("ul li");
if(lines.length > 1){
for (var k = 0; k < lines.length; k++)
concatenate_lines += ' ' + lines[k].innerText + ';';
} else{
concatenate_lines += ' ' + cols[j].innerText;
}
row.push(concatenate_lines);
}
csv.push(row.join(","));
}
downloadCSV(csv.join("\n"), filename);
}

</%def>






##
## Column functions
##
Expand All @@ -504,16 +574,16 @@ <h3 class="toggle-collapse ${collapsed_host_class}" id="${host['name']}" data-ho
elem_class = "error"
%>
% if link_type == "anchor":
<a href="#${jsonxs(host, 'name')}" class="${elem_class}">${jsonxs(host, "name")}</a>
<span><a href="#${jsonxs(host, 'name')}" class="${elem_class}">${jsonxs(host, "name")}</a></span>
% elif link_type == "external":
<a href="${jsonxs(host, 'name')}.html" class="${elem_class}">${jsonxs(host, 'name')}</a>
<span><a href="/cmdb/${jsonxs(host, 'name')}.html" class="${elem_class}">${jsonxs(host, 'name')}</a></span>
% else:
${jsonxs(host, "name")}
% endif
</%def>

<%def name="col_dtap(host, **kwargs)">
${jsonxs(host, 'hostvars.dtap', default='')}
<span>${jsonxs(host, 'hostvars.dtap', default='')}</span>
</%def>

<%def name="col_groups(host, **kwargs)">
Expand All @@ -538,7 +608,7 @@ <h3 class="toggle-collapse ${collapsed_host_class}" id="${host['name']}" data-ho
else:
default_ipv4 = jsonxs(host, 'ansible_facts.ansible_default_ipv4.address', default='')
%>
${default_ipv4}
<span>${default_ipv4.strip()}</span>
</%def>

<%def name="col_all_ip4(host, **kwargs)">
Expand All @@ -548,7 +618,11 @@ <h3 class="toggle-collapse ${collapsed_host_class}" id="${host['name']}" data-ho
else:
ipv4_addresses = jsonxs(host, 'ansible_facts.ansible_all_ipv4_addresses', default=[])
%>
${'<br>'.join(ipv4_addresses)}
<ul>
% for address in ipv4_addresses:
<li>${address}</li>
% endfor
</ul>
</%def>

<%def name="col_all_ip6(host, **kwargs)">
Expand Down Expand Up @@ -578,7 +652,7 @@ <h3 class="toggle-collapse ${collapsed_host_class}" id="${host['name']}" data-ho
<%def name="col_cpu_type(host, **kwargs)">
<% cpu_type = jsonxs(host, 'ansible_facts.ansible_processor', default=0)%>
% if isinstance(cpu_type, list) and len(cpu_type) > 0:
<a href="http://www.cpubenchmark.net/cpu.php?cpu=${ cpu_type[-1] }">${ cpu_type[-1] }</a>
<span>${ cpu_type[-1] }</span>
% endif
</%def>

Expand Down Expand Up @@ -639,6 +713,7 @@ <h3 class="toggle-collapse ${collapsed_host_class}" id="${host['name']}" data-ho
</%def>

<%def name="col_disk_usage(host, **kwargs)">
<ul>
% for i in jsonxs(host, 'ansible_facts.ansible_mounts', default=[]):
% try:
<%
Expand All @@ -654,26 +729,31 @@ <h3 class="toggle-collapse ${collapsed_host_class}" id="${host['name']}" data-ho
detail_total = 0
%>
## hidden sort helper
<span style="display:none">${sort_used}</span>
<div class="bar">
<span class="prog_bar_full" style="width:100px">
<span class="prog_bar_used" style="width:${used}px"></span>
</span> ${i['mount']} <span class="usage_detail">(${detail_used} / ${detail_total} GiB)</span>
</div>
<li>
<span style="display:none">${sort_used}</span>
<div class="bar">
<span class="prog_bar_full" style="width:100px">
<span class="prog_bar_used" style="width:${used}px"></span>
</span> ${i['mount']} <span class="usage_detail">(${detail_used} / ${detail_total} GiB)</span>
</div>
</li>
% except:
n/a
<%
break ## Stop listing disks, since there was an error.
%>
% endtry
% endfor
</ul>
</%def>

<%def name="col_physdisk_sizes(host, **kwargs)">
% try:
<ul>
% for physdisk_name, physdisk_info in jsonxs(host, 'ansible_facts.ansible_devices', default={}).items():
${physdisk_name}: ${jsonxs(physdisk_info, 'size', default='')}<br />
<li>${physdisk_name}: ${jsonxs(physdisk_info, 'size', default='')}</li>
% endfor
</ul>
% except AttributeError:
% endtry
</%def>
Expand Down Expand Up @@ -812,7 +892,7 @@ <h4 class="toggle-collapse ${collapsed_class}">Hardware</h4>
<tr><th>Virtualization role</th><td>${jsonxs(host, 'ansible_facts.ansible_virtualization_role', default='')}</td></tr>
<tr><th>Virtualization type</th><td>${jsonxs(host, 'ansible_facts.ansible_virtualization_type', default='')}</td></tr>
<tr><th>Machine</th><td>${jsonxs(host, 'ansible_facts.ansible_machine', default='')}</td></tr>
<tr><th>Processor type</th><td><a href="http://www.cpubenchmark.net/cpu.php?cpu=${jsonxs(host, 'ansible_facts.ansible_processor[-1]', default='')}">${jsonxs(host, 'ansible_facts.ansible_processor[-1]', default='')}</a></td></tr>
<tr><th>Processor type</th><td>${jsonxs(host, 'ansible_facts.ansible_processor[-1]', default='')}</td></tr>
<tr><th>Processor count</th><td>${jsonxs(host, 'ansible_facts.ansible_processor_count', default='')}</td></tr>
<tr><th>Processor cores</th><td>${jsonxs(host, 'ansible_facts.ansible_processor_cores', default='')}</td></tr>
<tr><th>Processor threads per core</th><td>${jsonxs(host, 'ansible_facts.ansible_processor_threads_per_core', default='')}</td></tr>
Expand Down
19 changes: 16 additions & 3 deletions src/ansiblecmdb/data/tpl/html_fancy_split_detail.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## -*- coding: utf-8 -*-
<%! from ansiblecmdb.util import to_bool %>
<%! import os %>

<%namespace name="defs" file="/html_fancy_defs.html" import="*" />

Expand All @@ -10,12 +11,16 @@ collapsed = to_bool(context.get('collapsed', '0'))

# Set the Javascript resource URL (local disk or CDN)
if local_js is False:
res_url = "https://cdn.datatables.net/1.10.2/"
res_url = os.getenv('STATIC_ROOT_URL', ".")
jquery_res_uri = os.getenv('JQUERY_RES_URI', "js/jquery-1.10.2.min.js")
dataTable_res_uri = os.getenv('DATATABLE_RES_URI', "js/jquery.dataTables.js")
else:
res_url = "file://" + data_dir + "/static/"
res_url = "."
jquery_res_uri = "js/jquery-1.10.2.min.js"
dataTable_res_uri = "js/jquery.dataTables.js"
%>

<% html_header(host['name'], local_js, res_url) %>
<% html_header(host['name'], local_js, res_url, jquery_res_uri, dataTable_res_uri) %>
<% html_header_bar(host['name']) %>
<div id="hosts">
<% html_host_detail(host, collapsed=collapsed, skip_empty=skip_empty, is_split=True) %>
Expand All @@ -26,6 +31,14 @@ else:
$(document).ready( function () {
<% js_ev_collapse() %>
});

//paste this code under the head tag or in a separate js file.
// Wait for window load
$(window).load(function() {
// Animate loader off screen
$(".se-pre-con").fadeOut("slow");;
});

</script>

<% html_footer() %>
18 changes: 15 additions & 3 deletions src/ansiblecmdb/data/tpl/html_fancy_split_overview.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## -*- coding: utf-8 -*-
<%! from ansiblecmdb.util import to_bool %>
<%! import os %>

<%namespace name="defs" file="/html_fancy_defs.html" import="*" />

Expand All @@ -18,9 +19,13 @@ cols.extend(cust_cols)

# Set the Javascript resource URL (local disk or CDN)
if local_js is False:
res_url = "https://cdn.datatables.net/1.10.2/"
res_url = os.getenv('STATIC_ROOT_URL', ".")
jquery_res_uri = os.getenv('JQUERY_RES_URI', "js/jquery-1.10.2.min.js")
dataTable_res_uri = os.getenv('DATATABLE_RES_URI', "js/jquery.dataTables.js")
else:
res_url = "file://" + data_dir + "/static/"
res_url = "."
jquery_res_uri = "js/jquery-1.10.2.min.js"
dataTable_res_uri = "js/jquery.dataTables.js"

# Set the link type for the host overview table's 'host' column (the link that
# takes you to the host details).
Expand All @@ -29,7 +34,7 @@ if host_details is False:
link_type = "none"
%>

<% html_header("Ansible Overview", local_js, res_url) %>
<% html_header("Ansible Overview", local_js, res_url, jquery_res_uri, dataTable_res_uri) %>
<% html_header_bar("Host overview") %>
<% html_col_toggles(cols) %>
<% html_host_overview(cols, hosts, skip_empty=skip_empty, link_type=link_type) %>
Expand All @@ -38,5 +43,12 @@ $(document).ready( function () {
<% js_init_host_overview(cols) %>
<% js_ev_collapse() %>
});
<% js_export_to_csv() %>
//paste this code under the head tag or in a separate js file.
// Wait for window load
$(window).load(function() {
// Animate loader off screen
$(".se-pre-con").fadeOut("slow");;
});
</script>
<% html_footer() %>