Skip to content

Commit

Permalink
PHRAS-4018: admin inspector log_docs (#4476)
Browse files Browse the repository at this point in the history
* inspector log_docs

* add column owner login in api information
  • Loading branch information
aynsix authored Feb 17, 2024
1 parent c396596 commit 3bf99cb
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 13 deletions.
47 changes: 34 additions & 13 deletions lib/Alchemy/Phrasea/Controller/Admin/RootController.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,27 +414,32 @@ public function getRecordDetails(Request $request)
if ($detailsType == 'subdef') {
$databox = $this->getApplicationBox()->get_databox($databoxId);

$record = $databox->get_record($recordId);
try {
$record = $databox->get_record($recordId);

$databoxSubdefs = $databox->get_subdef_structure()->getSubdefGroup($record->getType());
$databoxSubdefs = $databox->get_subdef_structure()->getSubdefGroup($record->getType());

$availableSubdefs = [];
$availableSubdefs = [];

foreach ($databoxSubdefs as $sub) {
$availableSubdefs[$sub->get_name()] = $sub->get_name();
}
foreach ($databoxSubdefs as $sub) {
$availableSubdefs[$sub->get_name()] = $sub->get_name();
}

/** @var MediaSubdefRepository $mediaSubdefRepository */
$mediaSubdefRepository = $this->app['provider.repo.media_subdef']->getRepositoryForDatabox($request->query->get('databoxId'));
/** @var MediaSubdefRepository $mediaSubdefRepository */
$mediaSubdefRepository = $this->app['provider.repo.media_subdef']->getRepositoryForDatabox($request->query->get('databoxId'));

$mediaSubdefs = $mediaSubdefRepository->findByRecordIdsAndNames([$request->query->get('recordId')]);
$mediaSubdefs = $mediaSubdefRepository->findByRecordIdsAndNames([$request->query->get('recordId')]);

$notGeneratedSubdefs = $availableSubdefs;
$notGeneratedSubdefs = $availableSubdefs;

foreach ($mediaSubdefs as $mediaSubdef) {
if (in_array($mediaSubdef->get_name(), $notGeneratedSubdefs)) {
unset($notGeneratedSubdefs[$mediaSubdef->get_name()]);
foreach ($mediaSubdefs as $mediaSubdef) {
if (in_array($mediaSubdef->get_name(), $notGeneratedSubdefs)) {
unset($notGeneratedSubdefs[$mediaSubdef->get_name()]);
}
}
} catch (\Exception $e) {
$mediaSubdefs = [];
$notGeneratedSubdefs = [];
}

return $this->render('admin/inspector/record-detail.html.twig', [
Expand Down Expand Up @@ -464,6 +469,22 @@ public function getRecordDetails(Request $request)
'recordParents' => $recordParents,
'type' => 'story'
]);
} elseif ($detailsType == 'log') {
$databox = $this->getApplicationBox()->get_databox($databoxId);
$sql = "SELECT d.* , l.usrid
FROM log_docs d
LEFT JOIN log l ON l.id = d.log_id
WHERE d.record_id =" . $recordId . " ORDER BY date LIMIT 1000";

$stmt = $databox->get_connection()->prepare($sql);
$stmt->execute();
$logDocs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();

return $this->render('admin/inspector/record-detail.html.twig', [
'logDocs' => $logDocs,
'type' => 'log'
]);
}
}

Expand Down
73 changes: 73 additions & 0 deletions templates/web/admin/inspector/record-detail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,76 @@
</tbody>
</table>
{% endif %}

{% if type == 'log' %}
<table class="admintable" style="border:1px solid #a5a0a0; width:90%">
<thead>
<th>{{ 'log_docs id' }}</th>
<th>{{ 'Date'}}</th>
<th>{{ 'Action'}}</th>
<th>{{ 'Final' }}</th>
<th>{{ 'Comment' }}</th>
</thead>
<tbody>
{% for logDoc in logDocs %}
<tr>
<td>{{ logDoc.id }}</td>
<td>{{ logDoc.date | date('Y-m-d H:i:s') }}</td>
<td>
{% if logDoc.action == 'push' %}
{% set n_user = logDoc.final | length %}
{% trans with {'%n_user%' : n_user } %}report::Push vers %n_user% utilisateurs depuis lapplication box{% endtrans %}
{% elseif logDoc.action == 'validate' %}
{% set n_user = logDoc.final | length %}
{% trans with {'%n_user%' : n_user } %}report::Demande de validation vers %n_user% utilisateurs depuis lapplication box{% endtrans %}
{% elseif logDoc.action == 'edit' %}
{{ 'report::Edition des meta-donnees' | trans }}
{% elseif logDoc.action == 'collection' %}
{% set dest = logDoc.final | join(', ') %}
{% set coll_name = dest|bas_labels(app) %}
{% trans with {'%coll_name%' : coll_name} %}report::Changement de collection vers : %coll_name%{% endtrans %}
{% elseif logDoc.action == 'status' %}
{{ 'report::Edition des status' | trans }}
{% elseif logDoc.action == 'print' %}
{% set format = logDoc.final | join(', ') %}
{% trans with {'%format%' : format} %}report::Impression des formats : %format%{% endtrans %}
{% elseif logDoc.action == 'substit' %}
{% set dest = logDoc.final | join(', ') %}
{% trans with {'%dest%' : dest} %}report::Substitution de %dest%{% endtrans %}
{% elseif logDoc.action == 'publish' %}
{% set dest = logDoc.final | join(', ') %}
{% trans with {'%dest%' : dest} %}report::Publication de %dest%{% endtrans %}
{% elseif logDoc.action == 'download' %}
{% set dest = logDoc.final | join(', ') %}
{% trans with {'%dest%' : dest} %}report::Telechargement de %dest%{% endtrans %}
{% elseif logDoc.action == 'mail' %}
{% set dest = logDoc.comment | join(', ') %}
{% set content = logDoc.final | join(', ') %}
{% trans with {'%dest%' : dest, '%content%' : content} %}Envoi par mail a %dest% de %content%{% endtrans %}
{% elseif logDoc.action == 'ftp' %}
{% set dest = logDoc.comment | join(', ') %}
{% set content = logDoc.final | join(', ') %}
{% trans with {'%dest%' : dest, '%content%' : content} %}Envoi par ftp a %dest% de %content%{% endtrans %}
{% elseif logDoc.action == 'delete' %}
{{ 'report::supression du document' | trans }}
{% elseif logDoc.action == 'add' %}
{{ 'report::ajout du documentt' | trans }}
{% else %}
{{ 'report::Modification du document -- je ne me souviens plus de quoi...' | trans }}
{% endif %}

{% if logDoc.usrid is not null %}
{% set user = app['repo.users'].find(logDoc.usrid) %}
{% set user_infos = user.getDisplayName() | e %}
{% trans with {'%user_infos%' : user_infos} %}report:: par %user_infos%{% endtrans %}
{% endif %}

</td>
<td>{{ logDoc.final }}</td>
<td>{{ logDoc.comment }}</td>

</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
18 changes: 18 additions & 0 deletions templates/web/admin/inspector/record-index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
</div>
</div>

<div style="margin-top:40px; margin-left: 30px; padding-bottom: 30px;">
<button class="btn btn-success record-details record-log-docs">{{ 'Get log docs' | trans }}</button>

<div style="margin-top:20px; overflow-x: scroll;" id="record-log-docs">
</div>
</div>

<div style="margin-left: 30px; margin-top:40px;">
<button class="btn btn-success find-record-index">{{ 'admin:: find record' | trans }}</button>
<div style="margin-top:20px; padding-bottom: 30px;">
Expand All @@ -67,6 +74,7 @@
<th>{{ 'admin::inspector: api ID' | trans }}</th>
<th>{{ 'admin::inspector: api name' | trans }}</th>
<th>{{ 'admin::inspector: api owner ID' | trans }}</th>
<th>{{ 'Owner login' }}</th>
<th>{{ 'admin::inspector: api password granted' | trans }}</th>
<th>{{ 'admin::inspector: api application type' | trans }}</th>
<th>{{ 'admin::inspector: api webhook url' | trans }}</th>
Expand All @@ -87,6 +95,13 @@
-
{% endif %}
</td>
<td>
{% if apiApplication.getCreator() is not null %}
{{ apiApplication.getCreator().getLogin() }}
{% else %}
-
{% endif %}
</td>
<td>
{% if apiApplication.isPasswordGranted() %}
{{ 'admin::users: password granted' | trans }}
Expand Down Expand Up @@ -165,6 +180,9 @@
} else if ($(this).hasClass('record-stories')) {
elOut = $('#right-ajax #record-stories');
type = 'story';
} else if ($(this).hasClass('record-log-docs')) {
elOut = $('#right-ajax #record-log-docs');
type = 'log';
}
let recordId = $('input#es-recordId').val();
Expand Down

0 comments on commit 3bf99cb

Please sign in to comment.