Files
rengine/web/targetApp/templates/target/list.html
T
2022-04-24 22:57:30 +05:30

232 lines
12 KiB
HTML

{% extends 'base/base.html' %}
{% load static %}
{% load humanize %}
{% block title %}
List all targets
{% endblock title %}
{% block custom_js_css_link %}
<link rel="stylesheet" type="text/css" href="{% static 'plugins/datatable/datatables.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'plugins/datatable/global.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'plugins/datatable/custom.css' %}">
{% endblock custom_js_css_link %}
{% block breadcrumb_title %}
<li class="breadcrumb-item active"><a href="{% url 'list_target' %}">Targets</a></li>
<li class="breadcrumb-item"><a href="#">All Targets</a></li>
{% endblock breadcrumb_title %}
{% block page_title %}
Targets
{% endblock page_title %}
{% block main_content %}
<div class="row">
<div class="col-12">
<div class="card">
<div class="p-2">
<div class="row">
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="filterMenu">
Filter <i class="fe-filter"></i>
</button>
<div class="dropdown-menu" style="width: 30%">
<div class="px-4 py-3">
<h4 class="headline-title">Filters</h4>
<label for="filterByOrganization" class="form-label">Filter by Organization</label>
<select class="form-control" id="filterByOrganization">
</select>
</div>
<div class="dropdown-divider"></div>
<a href="#" class="dropdown-ite text-primary float-end" id="resetFilters">Reset Filters</a>
</div>
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
<a class="btn btn-soft-danger float-end disabled ms-1" href="#" onclick="deleteMultipleTargets()" id="delete_multiple_button">Delete Multiple Targets</a>
<a class="btn btn-soft-primary float-end disabled ms-1" href="#" onclick="scanMultipleTargets()" id="scan_multiple_button">Scan Multiple Targets</a>
<a class="btn btn-soft-success float-end ms-1" href="{% url 'add_target' %}" data-toggle="tooltip" data-placement="top" title="Add New Targets">Add Targets</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<form method="POST" id="multiple_targets_form" action="../../scan/start/multiple/">
{% csrf_token %}
<table id="list_target_table" class="table style-3 table-hover">
<thead>
<tr>
<th class="checkbox-column text-center">Serial Number</th>
<th>Serial Number</th>
<th class="text-center">Domain Name</th>
<th>Organization</th>
<th>Description</th>
<th class="text-center">Added on</th>
<th class="text-center">Last Scanned</th>
<th class="text-center">Summary</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
{% for domain in domains.all %}
<tr>
<td class="checkbox-column"> {{ domain.id }} </td>
<td class=""> {{ domain.id }} </td>
<td>
<b>{{ domain.name }}</b>
{% if domain.get_recent_scan_id %}
<br>
<a href="{% url 'detail_scan' domain.get_recent_scan_id %}" class="text-info">Recent Scan&nbsp;<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-external-link"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg></a>
{% endif %}
</td>
<td class="">
{% for organization in domain.get_organization %}
<span class="badge bg-dark m-1" data-toggle="tooltip" data-placement="top" title="Domain {{domain.name}} belongs to organization {{organization.name}}">{{ organization.name }}</span>
{% endfor %}
</td>
<td>{% if domain.description %}{{domain.description}}{% endif %}</td>
<td class="text-center"><span data-toggle="tooltip" data-placement="top" title="{{domain.insert_date}}">{{ domain.insert_date|naturaltime }}</span></td>
{% if domain.start_scan_date %}
<td class="text-center"><span data-toggle="tooltip" data-placement="top" title="{{domain.start_scan_date}}">{{domain.start_scan_date|naturaltime}}</span></td>
{% else %}
<td class="text-center"><span class="shadow-none badge badge-warning">Never Scanned Before</span></td>
{% endif %}
<td class="text-center"><a href="{% url 'target_summary' domain.id %}" class="btn btn-outline-primary">View</a></td>
<td class="text-center">
<a href="{% url 'start_scan' domain.id %}" data-toggle="tooltip" data-placement="top" title="Quick Scan">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather table-scan feather-zap" id="myInput" value="helloworld">
<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon>
</svg>
</a>
<a href="{% url 'schedule_scan' domain.id %}" class="bs-tooltip open-domain" data-toggle="tooltip" data-placement="top" title="Schedule Scan">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-watch table-schedule"><circle cx="12" cy="12" r="7"></circle><polyline points="12 9 12 12 13.5 13.5"></polyline><path d="M16.51 17.35l-.35 3.83a2 2 0 0 1-2 1.82H9.83a2 2 0 0 1-2-1.82l-.35-3.83m.01-10.7l.35-3.83A2 2 0 0 1 9.83 1h4.35a2 2 0 0 1 2 1.82l.35 3.83"></path></svg>
</a>
<a href="{% url 'update_target' domain.id %}" class="bs-tooltip open-domain text-primary" data-toggle="tooltip" data-placement="top" title="Update target">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather table-edit feather-edit-2">
<path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path>
</svg>
</a>
<a onclick="delete_target({{ domain.id }}, '{{ domain.name }}')" class="bs-tooltip btnDelDomain text-danger" href="#" data-toggle="tooltip" data-placement="top" title="Delete target">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather table-delete feather-x-circle">
<circle cx="12" cy="12" r="10"></circle>
<line x1="15" y1="9" x2="9" y2="15"></line>
<line x1="9" y1="9" x2="15" y2="15"></line>
</svg>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
</div>
</div>
</div>
{% endblock main_content %}
{% block page_level_script %}
<script src="{% static 'custom/custom.js' %}"></script>
<script src="{% static 'targetApp/js/custom_domain.js' %}"></script>
<script src="{% static 'plugins/datatable/datatables.js' %}"></script>
<script>
$(document).ready(function(){
var table = $('#list_target_table').DataTable({
headerCallback:function(e, a, t, n, s) {
e.getElementsByTagName("th")[0].innerHTML='<input type="checkbox" class="float-start form-check-input chk-parent" id="head_checkbox" onclick=mainCheckBoxSelected()>\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span>\n'
},
"columnDefs":[
{ 'visible': false, 'targets': [1] },
{
"targets":0, "width":"20px", "className":"", "orderable":!1, render:function(e, a, t, n) {
return'<input type="checkbox" name="targets_checkbox['+ e + ']" class="float-start form-check-input targets_checkbox" value="' + e + '" onchange=toggleMultipleTargetButton()>\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span>'
},
}],
"order": [[1, 'desc']],
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center mt-sm-0 mt-3'f><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center'l>>>" +
"<'table-responsive'tr>" +
"<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>",
"oLanguage": {
"oPaginate": { "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>', "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>' },
"sInfo": "Showing page _PAGE_ of _PAGES_",
"sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"stripeClasses": [],
"lengthMenu": [5, 10, 20, 30, 40, 50],
"pageLength": 20,
});
multiCheck(table);
// Handle form submission event
$('#frm-example').on('submit', function(e){
var form = this;
table.$('input[type="checkbox"]').each(function(){
if(!$.contains(document, this)){
if(this.checked){
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('name', this.name)
.val(this.value)
);
}
}
});
e.preventDefault();
});
// filter organization populate
$.getJSON(`/api/listOrganizations?&format=json`, function(data) {
data = data['organizations']
for (organization in data) {
name = htmlEncode(data[organization]['name']);
select = document.getElementById('filterByOrganization');
var option = document.createElement('option');
option.value = name;
option.innerHTML = name;
select.appendChild(option);
}
}).fail(function(){
});
var a = document.getElementById('filterByOrganization');
a.addEventListener('click', function() {
table.search(this.value).draw();
document.getElementById('filteringText').innerHTML = `<span class="badge badge-primary m-2">Organization: ${this.value}
<span id="clearFilterChip" class="badge-link" onclick="document.getElementById('resetFilters').click()">X</span>
</span>`;
Snackbar.show({
text: `Filtering by organization ${this.value}`,
pos: 'top-center'
});
}, false);
// reset filtering
var reset_filter = document.getElementById('resetFilters');
reset_filter.addEventListener('click', function() {
resetFilters(table);
}, false);
$('[data-toggle=tooltip]').tooltip();
});
function resetFilters(table_obj) {
table_obj.search("").draw();
Snackbar.show({
text: `Filters Reset`,
pos: 'top-center'
});
document.getElementById('filteringText').innerHTML = '';
}
</script>
{% endblock page_level_script %}