Completed first-found updates for the API keys list view.

This commit is contained in:
Matt Scott 2023-02-20 09:39:13 -05:00
parent 4a12d62828
commit db70e34c98

View File

@ -1,153 +1,156 @@
{% extends "base.html" %} {% extends "base.html" %}
{% set active_page = "admin_keys" %} {% set active_page = "admin_keys" %}
{% block title %}<title>API Keys - {{ SITE_NAME }}</title>{% endblock %}
{% block title %}
<title>
Key Management - {{ SITE_NAME }}
</title>
{% endblock %}
{% block dashboard_stat %} {% block dashboard_stat %}
<div class="content-header"> <div class="content-header">
<div class="container-fluid"> <div class="container-fluid">
<div class="row mb-2"> <div class="row mb-2">
<div class="col-sm-6"> <div class="col-sm-6">
<h1 class="m-0 text-dark"> <h1 class="m-0 text-dark">API Keys</h1>
API Keys </div>
<small>Management</small> <div class="col-sm-6">
</h1> <ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ url_for('dashboard.dashboard') }}">Dashboard</a></li>
<li class="breadcrumb-item active">API Keys</li>
</ol>
</div>
</div>
</div> </div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ url_for('dashboard.dashboard') }}">Dashboard</a></li>
<li class="breadcrumb-item active">API Keys</li>
</ol>
</div>
</div>
</div> </div>
</div>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<section class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
<div class="card"> <div class="card">
<div class="card-header with-border"> <div class="card-header with-border">
<h3 class="card-title">Key Management</h3> <h3 class="card-title">API Keys</h3>
<a href="{{ url_for('admin.edit_key') }}"> <div class="card-tools">
<button type="button" class="btn btn-primary float-right button_add_key"> <a href="{{ url_for('admin.edit_key') }}">
<i class="fa-solid fa-plus"></i>&nbsp;Add Key <button type="button" class="btn btn-primary float-right button_add_key" title="Create Key">
</button> <i class="fa-solid fa-plus"></i>&nbsp;Create Key
</a> </button>
</div> </a>
<div class="card-body"> </div>
<table id="tbl_keys" class="table table-bordered table-striped"> <!-- /.card-tools -->
<thead> </div>
<tr> <!-- /.card-header -->
<th>Id</th> <div class="card-body table-responsive">
<th>Role</th> <table id="tbl_keys" class="table table-bordered table-striped table-hover table-sm records">
<th>Description</th> <thead>
<th>Domains</th> <tr>
<th>Accounts</th> <th>Id</th>
<th>Actions</th> <th>Role</th>
</tr> <th>Description</th>
</thead> <th>Domains</th>
<tbody> <th>Accounts</th>
{% for key in keys %} <th>Actions</th>
<tr class="odd gradeX"> </tr>
<td>{{ key.id }}</td> </thead>
<td>{{ key.role.name }}</td> <tbody>
<td>{{ key.description }}</td> {% for key in keys %}
<td>{% for domain in key.domains %}{{ domain.name }}{% if not loop.last %}, {% endif %}{% endfor %}</td> <tr class="odd gradeX">
<td>{% for account in key.accounts %}{{ account.name }}{% if not loop.last %}, {% endif %}{% endfor %}</td> <td>{{ key.id }}</td>
<td width="15%"> <td>{{ key.role.name }}</td>
<div class="dropdown"> <td>{{ key.description }}</td>
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <td>{% for domain in key.domains %}{{ domain.name }}{% if not loop.last %},
<i class="fa-solid fa-bars"></i>&nbsp;Actions {% endif %}{% endfor %}</td>
</button> <td>{% for account in key.accounts %}{{ account.name }}{% if not loop.last %},
<div class="dropdown-menu" aria-labelledby="dropdownMenu"> {% endif %}{% endfor %}</td>
<button type="button" class="dropdown-item btn-warning" onclick="window.location.href='{{ url_for('admin.edit_key', key_id=key.id) }}'"> <td>
<i class="fa-solid fa-edit"></i>&nbsp;Edit API Key <div class="dropdown">
</button> <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu"
<div class="dropdown-divider"></div> data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button type="button"class="dropdown-item btn-secondary button_delete" id="{{ key.id }}"> <i class="fa-solid fa-bars"></i>
<font color="red"> </button>
<i class="fa-solid fa-trash"></i>&nbsp;Delete API Key <div class="dropdown-menu" aria-labelledby="dropdownMenu">
</font> <button type="button" class="dropdown-item btn-warning"
</button> onclick="window.location.href='{{ url_for('admin.edit_key', key_id=key.id) }}'">
</div> <i class="fa-solid fa-edit"></i>&nbsp;Edit API Key
</div> </button>
</td> <div class="dropdown-divider"></div>
</tr> <button type="button" class="dropdown-item btn-secondary button_delete"
{% endfor %} id="{{ key.id }}">
</tbody> <font color="red">
</table> <i class="fa-solid fa-trash"></i>&nbsp;Delete API Key
</div> </font>
</div> </button>
</div> </div>
</section> </div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
</div>
<!-- /.container-fluid -->
</section>
{% endblock %} {% endblock %}
{% block extrascripts %} {% block extrascripts %}
<script> <script>
// set up key data table // set up key data table
$("#tbl_keys").DataTable({ $("#tbl_keys").DataTable({
"paging": true, "paging": true,
"lengthChange": true, "lengthChange": true,
"searching": true, "searching": true,
"ordering": true, "ordering": true,
"info": false, "info": false,
"autoWidth": false, "autoWidth": false,
"lengthMenu": [ "lengthMenu": [
[10, 25, 50, 100, -1], [10, 25, 50, 100, -1],
[10, 25, 50, 100, "All"] [10, 25, 50, 100, "All"]
], ],
"pageLength": 10 "pageLength": 10
}); });
// handle deletion of keys // handle deletion of keys
$(document.body).on('click', '.button_delete', function () { $(document.body).on('click', '.button_delete', function () {
var modal = $("#modal_delete"); var modal = $("#modal_delete");
var key_id = $(this).prop('id'); var key_id = $(this).prop('id');
var info = "Are you sure you want to delete key #" + key_id + "?"; var info = "Are you sure you want to delete key #" + key_id + "?";
modal.find('.modal-body p').text(info); modal.find('.modal-body p').text(info);
modal.find('#button_delete_confirm').click(function () { modal.find('#button_delete_confirm').click(function () {
var postdata = { var postdata = {
'action': 'delete_key', 'action': 'delete_key',
'data': key_id, 'data': key_id,
'_csrf_token': '{{ csrf_token() }}' '_csrf_token': '{{ csrf_token() }}'
} }
applyChanges(postdata, $SCRIPT_ROOT + '/admin/manage-keys', false, true); applyChanges(postdata, $SCRIPT_ROOT + '/admin/manage-keys', false, true);
modal.modal('hide'); modal.modal('hide');
}) })
modal.modal('show'); modal.modal('show');
}); });
</script> </script>
{% endblock %} {% endblock %}
{% block modals %} {% block modals %}
<div class="modal fade modal-warning" id="modal_delete"> <div class="modal fade modal-warning" id="modal_delete">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title">Confirmation</h4> <h4 class="modal-title">Confirmation</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-danger" id="button_delete_confirm">
Delete
</button>
</div>
</div>
</div> </div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-danger" id="button_delete_confirm">
Delete
</button>
</div>
</div>
</div> </div>
</div>
{% endblock %} {% endblock %}