Started first-round of updates on the activity feature AKA history, but it's a very broken implementation that will require a complete re-build. Saving that for later.

This commit is contained in:
Matt Scott 2023-02-19 20:41:26 -05:00
parent 761909f0f8
commit c4d9bf3a9c
2 changed files with 473 additions and 446 deletions

View File

@ -1,22 +1,13 @@
{% extends "base.html" %}
{% set active_page = "admin_history" %}
{% block title %}
<title>
History - {{ SITE_NAME }}
</title>
{% endblock %}
{% block title %}<title>Activity - {{ SITE_NAME }}</title>{% endblock %}
{% block dashboard_stat %}
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">
History
<small>Recent Events</small>
</h1>
<h1 class="m-0 text-dark">Activity</h1>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
@ -30,19 +21,22 @@
{% endblock %}
{% block content %}
{% import 'applied_change_macro.html' as applied_change_macro %}
<section class="content">
{% import 'applied_change_macro.html' as applied_change_macro %}
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card card-outline card-secondary">
<div class="card-header with-border">
<h3 class="card-title">History Management</h3>
{% if current_user.role.name != 'User' %}
<button type="button" class="btn btn-danger float-right" data-toggle="modal" data-target="#modal_clear_history" {% if current_user.role.name != 'Administrator' %}disabled{% endif %}>
<h3 class="card-title">Activity Search</h3>
{% if current_user.role.name == 'Administrator' %}
<div class="card-tools">
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#modal_clear_history" title="Clear Activity">
<i class="fa-solid fa-trash"></i>
&nbsp;Clear History
Clear Activity
</button>
</div>
{% endif %}
</div>
<div class="card-body clearfix">
@ -59,7 +53,8 @@
</a>
</li>
<li class="nav-item">
<a class="nav-link with-border" href="#tabs-account" data-toggle="pill" role="tab">
<a class="nav-link with-border" href="#tabs-account" data-toggle="pill"
role="tab">
Search By Account
</a>
</li>
@ -80,32 +75,40 @@
</td>
<td>
<div class="autocomplete" style="width:250px;">
<input type="text" class="form-control" id="domain_name_filter" name="domain_name_filter" placeholder="Enter * to search for any domain" value="">
<input type="text" class="form-control" id="domain_name_filter"
name="domain_name_filter"
placeholder="Enter * to search for any domain" value="">
</div>
</td>
<td>
<div style="position: relative; top:10px;">
<td>Record Changelog only &nbsp</td>
<td>
<input type="checkbox" id="domain_changelog_only_checkbox" name="domain_changelog_only_checkbox"
class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;">
</td>
</div>
</td>
</div>
<div class="tab-pane" id="tabs-account">
<td><label>Account Name</label></td>
<td>
<div class="autocomplete" style="width:250px;">
<input type="text" class="form-control" id="account_name_filter" name="account_name_filter" placeholder="Enter * to search for any account" value="">
</div>
</td>
</div>
<div class="tab-pane" id="tabs-auth">
<td><label>Username</label></td>
<div style="position: relative; top:10px;">
<td>Record Changelog only &nbsp</td>
<td>
<input type="checkbox" id="domain_changelog_only_checkbox"
name="domain_changelog_only_checkbox"
class="checkbox"
style="border:2px dotted #00f;display:block;background:#ff0000;">
</td>
</div>
</td>
</div>
<div class="tab-pane" id="tabs-account">
<td><label>Account Name</label></td>
<td>
<div class="autocomplete" style="width:250px;">
<input type="text" class="form-control" id="auth_name_filter" name="auth_name_filter" placeholder="Enter * to search for any username" value="">
<input type="text" class="form-control" id="account_name_filter"
name="account_name_filter"
placeholder="Enter * to search for any account" value="">
</div>
</td>
</div>
<div class="tab-pane" id="tabs-auth">
<td><label>Username</label></td>
<td>
<div class="autocomplete" style="width:250px;">
<input type="text" class="form-control" id="auth_name_filter"
name="auth_name_filter"
placeholder="Enter * to search for any username" value="">
</div>
</td>
@ -115,22 +118,29 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
<td>&nbsp All</td>
<td>
<input type="checkbox" checked id="auth_all_checkbox" name="auth_all_checkbox"
class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;">
class="checkbox"
style="border:2px dotted #00f;display:block;background:#ff0000;">
</td>
<td>&nbsp LOCAL</td>
<td>
<input type="checkbox" checked id="auth_local_only_checkbox" name="auth_local_only_checkbox"
class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;">
<input type="checkbox" checked id="auth_local_only_checkbox"
name="auth_local_only_checkbox"
class="checkbox"
style="border:2px dotted #00f;display:block;background:#ff0000;">
</td>
<td>&nbsp OAuth</td>
<td>
<input type="checkbox" checked id="auth_oauth_only_checkbox" name="auth_oauth_only_checkbox"
class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;">
<input type="checkbox" checked id="auth_oauth_only_checkbox"
name="auth_oauth_only_checkbox"
class="checkbox"
style="border:2px dotted #00f;display:block;background:#ff0000;">
</td>
<td>&nbsp SAML</td>
<td>
<input type="checkbox" checked id="auth_saml_only_checkbox" name="auth_saml_only_checkbox"
class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;">
<input type="checkbox" checked id="auth_saml_only_checkbox"
name="auth_saml_only_checkbox"
class="checkbox"
style="border:2px dotted #00f;display:block;background:#ff0000;">
</td>
</div>
</td>
@ -146,7 +156,8 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
<td><label>Changed by: &nbsp</label></td>
<td>
<div class="autocomplete" style="width:250px;">
<input type="text" style=" border:1px solid #d2d6de; width:250px; height: 34px;" id="user_name_filter" name="user_name_filter" value="">
<input type="text" style=" border:1px solid #d2d6de; width:250px; height: 34px;"
id="user_name_filter" name="user_name_filter" value="">
</div>
</td>
</tr>
@ -155,7 +166,8 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
<label>Minimum date: &nbsp</label>
</td>
<td style="position: relative; top:10px;">
<input type="text" id="min" name="min" class="datepicker" autocomplete="off" style=" border:1px solid #d2d6de; width:250px; height: 34px;">
<input type="text" id="min" name="min" class="datepicker" autocomplete="off"
style=" border:1px solid #d2d6de; width:250px; height: 34px;">
</td>
</tr>
<tr>
@ -163,17 +175,27 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
<label>Maximum date: &nbsp</label>
</td>
<td style="position: relative; top:20px;">
<input type="text" id="max" name="max" class="datepicker" autocomplete="off" style=" border:1px solid #d2d6de; width:250px; height: 34px;">
<input type="text" id="max" name="max" class="datepicker" autocomplete="off"
style=" border:1px solid #d2d6de; width:250px; height: 34px;">
</td>
</tr>
<tr><td>&nbsp</td></tr>
<tr><td>&nbsp</td></tr>
<tr>
<td>&nbsp</td>
</tr>
<tr>
<td>&nbsp</td>
</tr>
<tr>
<td>
<button type="submit" id="search-submit" name="search-submit" class="btn btn-primary button-filter"><i class="fa fa-search"></i>&nbsp;Search</button>
<button type="submit" id="search-submit" name="search-submit"
class="btn btn-primary button-filter"><i class="fa fa-search"></i>&nbsp;Search
</button>
</td>
<td>
<button id="clear-filters" name="clear-filters" class="btn btn-warning button-clearf"><i class="fa fa-trash"></i>&nbsp;Clear Filters</button>
<button id="clear-filters" name="clear-filters"
class="btn btn-warning button-clearf"><i class="fa fa-trash"></i>&nbsp;Clear
Filters
</button>
</td>
</tr>
</tbody>
@ -182,23 +204,24 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
</div>
<div id="table_from_ajax"></div>
</div>
</section>
</section>
{% endblock %}
{% block extrascripts %}
<script>
<script>
/* Don't let user search with a blank main field */
var canSearch=true;
var canSearch = true;
$(document).ready(function () {
$.ajax({
url: "/admin/history_table",
type: "get",
success: function(response) {
success: function (response) {
console.log('Submission was successful.');
$("#table_from_ajax").html(response);
},
error: function(xhr) {
error: function (xhr) {
console.log("Sending data: ", data, " failed")
}
});
@ -209,26 +232,26 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
// Show/hide filters
$('#domain_name_filter, #account_name_filter, #auth_name_filter').on('keyup change', function (e) {
if ( $('#domain_name_filter').val() == "" && $('#account_name_filter').val() == "" && $('#auth_name_filter').val() == "")
canSearch=false;
if ($('#domain_name_filter').val() == "" && $('#account_name_filter').val() == "" && $('#auth_name_filter').val() == "")
canSearch = false;
else
canSearch=true;
canSearch = true;
});
// Handle giving later mindate than current max
$('#min').on('change', function () {
if (minDate.val() > maxDate.val())
$('#max').datepicker('setDate', minDate.val() );
$('#max').datepicker('setDate', minDate.val());
});
// Handle giving earlier maxdate than current min
$('#max').on('keyup change', function () {
if (maxDate.val() < minDate.val())
$('#min').datepicker('setDate', maxDate.val() );
$('#min').datepicker('setDate', maxDate.val());
});
$(function() {
$( ".datepicker" ).datepicker({
$(function () {
$(".datepicker").datepicker({
changeMonth: true,
changeYear: true,
format: "yyyy-mm-dd",
@ -246,16 +269,15 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
});
//Handle "ALL" Checkbox
$('#auth_all_checkbox').on('ifChecked',function() {
$('#auth_all_checkbox').on('ifChecked', function () {
$('#auth_local_only_checkbox').iCheck('check');
$('#auth_oauth_only_checkbox').iCheck('check');
$('#auth_saml_only_checkbox').iCheck('check');
});
$('#auth_all_checkbox').on('ifUnchecked',function() {
$('#auth_all_checkbox').on('ifUnchecked', function () {
//check if all were checked
if($('#auth_local_only_checkbox').is(':checked') && $('#auth_oauth_only_checkbox').is(':checked') && $('#auth_saml_only_checkbox').is(':checked'))
{
if ($('#auth_local_only_checkbox').is(':checked') && $('#auth_oauth_only_checkbox').is(':checked') && $('#auth_saml_only_checkbox').is(':checked')) {
$('#auth_local_only_checkbox').iCheck('uncheck');
$('#auth_oauth_only_checkbox').iCheck('uncheck');
$('#auth_saml_only_checkbox').iCheck('uncheck');
@ -263,28 +285,28 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
});
//Handle other auth checkboxes
$('#auth_local_only_checkbox').on('ifChecked',function() {
$('#auth_local_only_checkbox').on('ifChecked', function () {
//check if all others were checked
if($('#auth_oauth_only_checkbox').is(':checked') && $('#auth_saml_only_checkbox').is(':checked'))
if ($('#auth_oauth_only_checkbox').is(':checked') && $('#auth_saml_only_checkbox').is(':checked'))
$('#auth_all_checkbox').iCheck('check');
});
$('#auth_local_only_checkbox').on('ifUnchecked',function() {
$('#auth_local_only_checkbox').on('ifUnchecked', function () {
$('#auth_all_checkbox').iCheck('uncheck');
});
$('#auth_oauth_only_checkbox').on('ifChecked',function() {
if($('#auth_local_only_checkbox').is(':checked') && $('#auth_saml_only_checkbox').is(':checked'))
$('#auth_oauth_only_checkbox').on('ifChecked', function () {
if ($('#auth_local_only_checkbox').is(':checked') && $('#auth_saml_only_checkbox').is(':checked'))
$('#auth_all_checkbox').iCheck('check');
});
$('#auth_oauth_only_checkbox').on('ifUnchecked',function() {
$('#auth_oauth_only_checkbox').on('ifUnchecked', function () {
$('#auth_all_checkbox').iCheck('uncheck');
});
$('#auth_saml_only_checkbox').on('ifChecked',function() {
if($('#auth_local_only_checkbox').is(':checked') && $('#auth_oauth_only_checkbox').is(':checked'))
$('#auth_saml_only_checkbox').on('ifChecked', function () {
if ($('#auth_local_only_checkbox').is(':checked') && $('#auth_oauth_only_checkbox').is(':checked'))
$('#auth_all_checkbox').iCheck('check');
});
$('#auth_saml_only_checkbox').on('ifUnchecked',function() {
$('#auth_saml_only_checkbox').on('ifUnchecked', function () {
$('#auth_all_checkbox').iCheck('uncheck');
});
@ -313,11 +335,13 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
the text field element and an array of possible autocompleted values:*/
var currentFocus;
/*execute a function when someone writes in the text field:*/
inp.addEventListener("input", function(e) {
inp.addEventListener("input", function (e) {
var a, b, i, val = this.value;
/*close any already open lists of autocompleted values*/
closeAllLists();
if (!val) { return false;}
if (!val) {
return false;
}
currentFocus = -1;
/*create a DIV element that will contain the items (values):*/
a = document.createElement("DIV");
@ -337,7 +361,7 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
/*insert a input field that will hold the current array item's value:*/
b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
/*execute a function when someone clicks on the item value (DIV element):*/
b.addEventListener("click", function(e) {
b.addEventListener("click", function (e) {
/*insert the value for the autocomplete text field:*/
inp.value = this.getElementsByTagName("input")[0].value;
/*close the list of autocompleted values,
@ -349,7 +373,7 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
}
});
/*execute a function presses a key on the keyboard:*/
inp.addEventListener("keydown", function(e) {
inp.addEventListener("keydown", function (e) {
var x = document.getElementById(this.id + "autocomplete-list");
if (x) x = x.getElementsByTagName("div");
if (e.keyCode == 40) {
@ -373,6 +397,7 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
}
}
});
function addActive(x) {
/*a function to classify an item as "active":*/
if (!x) return false;
@ -383,12 +408,14 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
/*add class "autocomplete-active":*/
x[currentFocus].classList.add("autocomplete-active");
}
function removeActive(x) {
/*a function to remove the "active" class from all autocomplete items:*/
for (var i = 0; i < x.length; i++) {
x[i].classList.remove("autocomplete-active");
}
}
function closeAllLists(elmnt) {
/*close all autocomplete lists in the document,
except the one passed as an argument:*/
@ -399,6 +426,7 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
}
}
}
/*execute a function when someone clicks in the document:*/
document.addEventListener("click", function (e) {
closeAllLists(e.target);
@ -413,77 +441,75 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
// prevent multiple filter field at the same time
$('#domain_tab').click(function() {
$('#domain_tab').click(function () {
$('#account_name_filter').val('');
$('#auth_name_filter').val('');
$('#user_name_filter').removeAttr('disabled');
canSearch=false;
main_field="Domain Name"
canSearch = false;
main_field = "Domain Name"
});
$('#account_tab').click(function() {
$('#account_tab').click(function () {
$('#domain_name_filter').val('');
$('#auth_name_filter').val('');
$('#user_name_filter').removeAttr('disabled');
canSearch=false;
main_field="Account Name"
canSearch = false;
main_field = "Account Name"
});
$('#user_auth_tab').click( function() {
$('#user_auth_tab').click(function () {
$('#domain_name_filter').val('');
$('#account_name_filter').val('');
$('#user_name_filter').val('');
$('#user_name_filter').attr('disabled','disabled');
canSearch=false;
main_field="Username"
$('#user_name_filter').attr('disabled', 'disabled');
canSearch = false;
main_field = "Username"
});
$('#activity_tab').click( function() {
$('#activity_tab').click(function () {
$('#domain_name_filter').val('');
$('#account_name_filter').val('');
$('#auth_name_filter').val('');
$('#user_name_filter').removeAttr('disabled');
$('#search-submit').removeAttr('disabled','disabled');
canSearch=true;
main_field=""
$('#search-submit').removeAttr('disabled', 'disabled');
canSearch = true;
main_field = ""
});
// if search submit is pressed, and max date not initialized
// then initialize it
$('#search-submit').on('click', function() {
$('#search-submit').on('click', function () {
if ($('#max').val() === "" || $('#max').val() === undefined)
$('#max').datepicker('setDate', 'now');
});
$("#history-search-form").submit(function(e){ // ajax call to load results on submition
$("#history-search-form").submit(function (e) { // ajax call to load results on submition
e.preventDefault(); // prevent page reloading
if(!canSearch)
{
if (!canSearch) {
showErrorModal("Please fill out the " + main_field + " field.");
}
else
{
} else {
var form = $(this);
var tzoffset = (new Date()).getTimezoneOffset();
$.ajax({
url: "/admin/history_table",
type: "get",
data: form.serialize() + "&tzoffset=" + tzoffset,
success: function(response) {
success: function (response) {
console.log('Submission was successful.');
$("#table_from_ajax").html(response);
},
error: function(xhr) {
error: function (xhr) {
console.log("Sending data: ", data, " failed")
}
});
}
});
</script>
</script>
{% endblock %}
{% block modals %}
<!-- Clear History Confirmation Box -->
<div class="modal fade modal-warning" id="modal_clear_history">
@ -500,7 +526,8 @@ class="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger float-right" onclick="applyChanges({'_csrf_token': '{{ csrf_token() }}'}, $SCRIPT_ROOT + '/admin/history', false, true);">
<button type="button" class="btn btn-danger float-right"
onclick="applyChanges({'_csrf_token': '{{ csrf_token() }}'}, $SCRIPT_ROOT + '/admin/history', false, true);">
Clear History
</button>
</div>

View File

@ -136,7 +136,7 @@
<li class="{{ 'nav-item active' if active_page == 'admin_history' else 'nav-item' }}">
<a href="{{ url_for('admin.history') }}" class="nav-link">
<i class="nav-icon fa-solid fa-timeline"></i>
<p>History</p>
<p>Activity</p>
</a>
</li>
<li class="{{ 'nav-item active' if active_page == 'admin_domain_template' else 'nav-item' }}">