mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
add quota to user list
This commit is contained in:
parent
4a39865903
commit
03ae69b82a
3 changed files with 29 additions and 15 deletions
|
@ -53,6 +53,13 @@ class User extends \descartes\Controller
|
||||||
public function list_json()
|
public function list_json()
|
||||||
{
|
{
|
||||||
$entities = $this->internal_user->list();
|
$entities = $this->internal_user->list();
|
||||||
|
|
||||||
|
foreach ($entities as &$entity)
|
||||||
|
{
|
||||||
|
$quota_percentage = $this->internal_quota->get_usage_percentage($entity['id']);
|
||||||
|
$entity['quota_percentage'] = $quota_percentage * 100;
|
||||||
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo json_encode(['data' => $entities]);
|
echo json_encode(['data' => $entities]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,14 +58,14 @@ namespace models;
|
||||||
* @param \DateTime $at : date to get usage percent at
|
* @param \DateTime $at : date to get usage percent at
|
||||||
* @return float : percent of used credits
|
* @return float : percent of used credits
|
||||||
*/
|
*/
|
||||||
public function get_usage_percentage (int $id_user, \DateTime $at): int
|
public function get_usage_percentage (int $id_user, \DateTime $at): float
|
||||||
{
|
{
|
||||||
$query = '
|
$query = '
|
||||||
SELECT (consumed / (credit + additional)) AS usage_percentage
|
SELECT (consumed / (credit + additional)) AS usage_percentage
|
||||||
FROM quota
|
FROM quota
|
||||||
WHERE id_user = :id_user
|
WHERE id_user = :id_user
|
||||||
AND start_date <= :at
|
AND start_date <= :at
|
||||||
AND end_date > :at';
|
AND expiration_date > :at';
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'id_user' => $id_user,
|
'id_user' => $id_user,
|
||||||
|
@ -74,7 +74,7 @@ namespace models;
|
||||||
|
|
||||||
$result = $this->_run_query($query, $params);
|
$result = $this->_run_query($query, $params);
|
||||||
|
|
||||||
return ($result[0]['usage_percentage'] ?? 0);
|
return (float) ($result[0]['usage_percentage'] ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,12 +36,13 @@
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<form method="GET">
|
<form method="GET">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-bordered table-hover table-striped datatable" id="table-users">
|
<table class="table table-bordered table-hover table-striped datatable" id="table-users" style="width:100%">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Email</th>
|
<th>Email</th>
|
||||||
<th>Admin</th>
|
<th>Admin</th>
|
||||||
<th>Statut</th>
|
<th>Statut</th>
|
||||||
|
<th>Crédit utilisé</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn">✓</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -61,7 +62,6 @@
|
||||||
<button class="btn btn-default btn-confirm" type="submit" formaction="<?php echo \descartes\Router::url('User', 'delete', ['csrf' => $_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</button>
|
<button class="btn btn-default btn-confirm" type="submit" formaction="<?php echo \descartes\Router::url('User', 'delete', ['csrf' => $_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -92,6 +92,13 @@ jQuery(document).ready(function ()
|
||||||
{data: 'email', render: jQuery.fn.dataTable.render.text()},
|
{data: 'email', render: jQuery.fn.dataTable.render.text()},
|
||||||
{data: 'admin', render: jQuery.fn.dataTable.render.text()},
|
{data: 'admin', render: jQuery.fn.dataTable.render.text()},
|
||||||
{data: 'status', render: jQuery.fn.dataTable.render.text()},
|
{data: 'status', render: jQuery.fn.dataTable.render.text()},
|
||||||
|
{
|
||||||
|
data: 'quota_percentage',
|
||||||
|
render: function (data, type, row, meta) {
|
||||||
|
return jQuery.fn.dataTable.render.text().display(data) + "%";
|
||||||
|
return '<input name="user_ids[]" type="checkbox" value="' + data + '">';
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
data: 'id',
|
data: 'id',
|
||||||
render: function (data, type, row, meta) {
|
render: function (data, type, row, meta) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue