Skip to content

Commit fd71008

Browse files
authored
Merge pull request #19 from aligent/improve-json-view
Pretty print json serialized data
2 parents d3dd2e9 + 7209f3f commit fd71008

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

Model/Details.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getDetails(string $uuid): array
5353
$asyncEventId = $collection->getFirstItem()->getData('subscription_id');
5454

5555
try {
56-
$asyncEvent = $this->asyncEventRepository->get($asyncEventId)->getData();
56+
$asyncEvent = $this->asyncEventRepository->get((int) $asyncEventId)->getData();
5757
$this->traceCache[$uuid] = [
5858
'traces' => $traces['items'],
5959
'async_event' => $asyncEvent

Ui/DataProvider/AsyncEventsTrace.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,18 @@ public function getData(): array
6161
{
6262
$uuid = $this->request->getParam($this->requestFieldName);
6363
$details = $this->traceDetails->getDetails($uuid);
64+
$trace = current($details['traces']);
65+
66+
/**
67+
* Prettify JSON by decoding and re-encoding with the JSON_PRETTY_PRINT flag
68+
*/
69+
$prettyPrint = json_decode($trace['serialized_data'], true);
70+
$prettyPrint = json_encode($prettyPrint, JSON_PRETTY_PRINT);
71+
$trace['serialized_data'] = $prettyPrint;
6472

6573
return [
6674
$uuid => [
67-
'general' => current($details['traces'])
75+
'general' => $trace
6876
]
6977
];
7078
}

view/adminhtml/ui_component/async_events_logs_trace.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
</item>
6262
</argument>
6363
<settings>
64+
<elementTmpl>Aligent_AsyncEvents/content/json</elementTmpl>
6465
<dataType>text</dataType>
6566
<label translate="true">Serialized Data</label>
6667
</settings>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<pre data-bind="text: value"
2+
style="background: #f6f6f6;
3+
border: 1px solid #cccccc;
4+
color: #111111;
5+
line-height: calc(20/14);
6+
margin: 0 0 10px;
7+
padding: 10px;
8+
font-size: 1.2rem;
9+
display: block;
10+
word-wrap: break-word;"
11+
>
12+
</pre>

0 commit comments

Comments
 (0)