Skip to content

Commit

Permalink
PHRAS-3903 Admin - object inspector - record index debug tools (#4369)
Browse files Browse the repository at this point in the history
* add admin record index tools

* add databox_id filter

* add url encode

* use options provider

* return uri along with es result

---------

Co-authored-by: jygaulier <[email protected]>
  • Loading branch information
aynsix and jygaulier authored Sep 7, 2023
1 parent ec4a225 commit 06193f2
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 136 deletions.
38 changes: 38 additions & 0 deletions lib/Alchemy/Phrasea/Controller/Admin/RootController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use Alchemy\Phrasea\Core\Event\Record\Structure\StatusBitEvent;
use Alchemy\Phrasea\Core\Event\Record\Structure\StatusBitUpdatedEvent;
use Alchemy\Phrasea\Exception\SessionNotFound;
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions;
use Alchemy\Phrasea\Status\StatusStructureProviderInterface;
use GuzzleHttp\Client;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

Expand Down Expand Up @@ -360,6 +362,42 @@ public function submitStatusBitAction(Request $request, $databox_id, $bit) {
return $this->app->redirectPath('database_display_statusbit', ['databox_id' => $databox_id, 'success' => 1]);
}

public function displayInspector(Request $request)
{
$databoxIds = array_map(function (\databox $databox) {
return $databox->get_sbas_id();
},
$this->app->getApplicationBox()->get_databoxes()
);

return $this->render('admin/inspector/record-index.html.twig', ['databoxIds' => $databoxIds]);
}

public function getESRecord(Request $request)
{
$client = new Client();

/** @var ElasticsearchOptions $options */
$options = $this->app['elasticsearch.options'];

$uri = $options->getHost() . ":" . $options->getPort() . "/" . urlencode($options->getIndexName()) . "/record/" . urlencode($request->query->get('databoxId')) . "_" . urlencode($request->query->get('recordId'));

$ret = [
'uri' => $uri
];
$js = $client->get($uri, ['http_errors' => false])->getBody()->getContents();
$arr = json_decode($js,true);
if(is_null($arr)) {
$ret['result'] = "*** error decoding json ***";
$ret['raw'] = $js;
}
else {
$ret['result'] = $arr;
}

return json_encode($ret, JSON_PRETTY_PRINT, 512);
}

private function dispatchEvent($eventName, StatusBitEvent $event = null)
{
$this->app['dispatcher']->dispatch($eventName, $event);
Expand Down
6 changes: 6 additions & 0 deletions lib/Alchemy/Phrasea/ControllerProvider/Admin/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public function connect(Application $app)
->assert('bit', '\d+')
->bind('database_submit_statusbit');

$controllers->get('/inspector/', 'controller.admin.root:displayInspector')
->bind('admin_inspector');

$controllers->get('/inspector/record/', 'controller.admin.root:getESRecord')
->bind('admin_inspector_record');

return $controllers;
}
}
82 changes: 49 additions & 33 deletions resources/locales/messages.de.xlf

Large diffs are not rendered by default.

82 changes: 49 additions & 33 deletions resources/locales/messages.en.xlf

Large diffs are not rendered by default.

82 changes: 49 additions & 33 deletions resources/locales/messages.fr.xlf

Large diffs are not rendered by default.

82 changes: 49 additions & 33 deletions resources/locales/messages.nl.xlf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/locales/validators.de.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2023-08-30T11:26:01Z" source-language="en" target-language="de" datatype="plaintext" original="not.available">
<file date="2023-09-05T15:25:53Z" source-language="en" target-language="de" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
Expand Down
2 changes: 1 addition & 1 deletion resources/locales/validators.en.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2023-08-30T11:26:17Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<file date="2023-09-05T15:26:09Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
Expand Down
2 changes: 1 addition & 1 deletion resources/locales/validators.fr.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2023-08-30T11:26:36Z" source-language="en" target-language="fr" datatype="plaintext" original="not.available">
<file date="2023-09-05T15:26:28Z" source-language="en" target-language="fr" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
Expand Down
2 changes: 1 addition & 1 deletion resources/locales/validators.nl.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2023-08-30T11:26:59Z" source-language="en" target-language="nl" datatype="plaintext" original="not.available">
<file date="2023-09-05T15:26:51Z" source-language="en" target-language="nl" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
Expand Down
48 changes: 48 additions & 0 deletions templates/web/admin/inspector/record-index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="page-header">
<h1>{{ 'admin:: record index' | trans }}</h1>
</div>

<div>
<select id="es-databoxId" style="margin-left: 30px;">
<option value="">{{ 'button::choose databox' | trans }}</option>
{% for databoxId in databoxIds %}
<option value="{{ databoxId }}">{{ databoxId | sbas_labels(app) }}</option>
{% endfor %}
</select>

<input id="es-recordId" type="number" placeholder="recordId" style="margin-bottom: 0px;margin-left: 30px;">

<button class="btn btn-success find-record-index" style="margin-left: 30px;">{{ 'admin:: find record' | trans }}</button>
</div>

<div style="margin-top:30px;">
<pre id="admin-es-record-display" style="height: 400px;overflow-y: scroll;width: 60%;margin-left: 30px;">

</pre>
</div>

<script type="text/javascript">
$(document).ready(function() {
$('.find-record-index').on('click', function() {
let recordId = $('input#es-recordId').val();
let databoxId = $('select#es-databoxId').val();
if (databoxId == '' || recordId < 1) {
alert("Wrong databoxId or recordId value !");
} else {
$.ajax({
type: 'GET',
url: '/admin/inspector/record/',
dataType: 'json',
data: {
databoxId: databoxId,
recordId: recordId
},
success: function (data) {
$('#right-ajax #admin-es-record-display').empty().html(JSON.stringify(data, null, 2));
}
});
}
});
});
</script>
6 changes: 6 additions & 0 deletions templates/web/admin/tree.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
<span>{% trans %}Auth failure{% endtrans %}</span>
</a>
</li>
<li class="">
<a target="right" href="{{ path('admin_inspector') }}" class="ajax">
<img width="16" src="/assets/admin/images/searchengin.svg" />
<span>{{ 'admin:: object inspector' | trans }}</span>
</a>
</li>
{% endif %}

{% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::BAS_CHUPUB')) %}
Expand Down

0 comments on commit 06193f2

Please sign in to comment.