Skip to content

Commit dfd1f48

Browse files
Merge pull request #29 from itk-dev/feature/masked-values
Masked run meta values
2 parents b511729 + 6a8c838 commit dfd1f48

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

fixtures/process_overview.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ App\Entity\ProcessOverview:
3232
metadata_columns:
3333
- label: Borger
3434
data: meta.cpr
35+
mask:
36+
search: '/\d{4}$/'
37+
replace: '-****'
3538
- label: Name
3639
data: meta.name
3740
# Missing

src/Controller/Admin/ProcessOverviewCrudController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function configureFields(string $pageName): iterable
106106
->setFormTypeOptions([
107107
// @todo Add search for process
108108
'choice_loader' => new CallbackChoiceLoader(function () use ($dataSource): array {
109-
$processes = $this->dataSourceHelper->getProcesses($dataSource);
109+
$processes = $this->dataSourceHelper->getProcesses($dataSource)['items'] ?? [];
110110
$options = array_combine(
111111
array_column($processes, 'name'),
112112
array_column($processes, 'id'),

src/Controller/ProcessOverviewController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ public function data(Request $request, ProcessOverview $overview, ProcessOvervie
6969
return new JsonResponse($data);
7070
}
7171

72+
#[Route('/{overview}/data/{run}/raw-data/{field}', name: 'raw_data_field')]
73+
public function getRawRunFieldValue(Request $request, ProcessOverview $overview, string $run, string $field, ProcessOverviewHelper $helper): Response
74+
{
75+
$data = $helper->getRawRunFieldValue($request, $overview, $run, $field);
76+
77+
return new JsonResponse($data);
78+
}
79+
7280
#[Route('/{overview}/search', name: 'search')]
7381
public function search(Request $request, ProcessOverview $overview, ProcessOverviewHelper $helper): Response
7482
{

src/DataSourceHelper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ public function getProcess(DataSource $dataSource, string $processId): array
2626
return $this->get($dataSource, 'processes/'.$processId);
2727
}
2828

29-
public function getProcessRun(DataSource $dataSource, string $processId, array $query): array
29+
public function getProcessRuns(DataSource $dataSource, string $processId, array $query): array
3030
{
3131
return $this->get($dataSource, 'runs/', ['process_id' => $processId] + $query);
3232
}
3333

34+
public function getProcessRun(DataSource $dataSource, string $processId, string $runId): array
35+
{
36+
return $this->get($dataSource, 'runs/'.$runId);
37+
}
38+
3439
private function get(DataSource $dataSource, string $path, array $query = []): array
3540
{
3641
$url = $this->buildUrl($dataSource, $path, $query);

src/ProcessOverviewHelper.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
use League\Uri\Modifier;
77
use Symfony\Component\HttpFoundation\Request;
88
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
9+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
910
use Symfony\Component\Yaml\Yaml;
1011

1112
class ProcessOverviewHelper
1213
{
1314
public function __construct(
1415
private readonly PropertyAccessorInterface $propertyAccessor,
1516
private readonly DataSourceHelper $dataSourceHelper,
17+
private readonly UrlGeneratorInterface $urlGenerator,
1618
) {
1719
}
1820

@@ -33,7 +35,7 @@ public function getData(Request $request, ProcessOverview $overview): array
3335
$query = [];
3436
}
3537
$query += $request->query->all();
36-
$data = $this->dataSourceHelper->getProcessRun($datasource, $processId, $query);
38+
$data = $this->dataSourceHelper->getProcessRuns($datasource, $processId, $query);
3739

3840
$metadataColumns = [];
3941
$metadataColumnsOptions = $this->getArrayValue($options, 'metadata_columns') ?? [];
@@ -61,10 +63,27 @@ public function getData(Request $request, ProcessOverview $overview): array
6163
}
6264
$rows[] = array_merge(
6365
array_map(
64-
fn (array $col) => [
65-
'type' => 'text',
66-
'value' => $this->getArrayValue($item, $col['data']),
67-
],
66+
function (array $col) use ($overview, $item) {
67+
$value = $this->getArrayValue($item, $col['data']);
68+
$result = [
69+
'type' => 'text',
70+
];
71+
72+
if (isset($col['mask']['search'], $col['mask']['replace'])) {
73+
$value = @preg_replace($col['mask']['search'], $col['mask']['replace'], $value);
74+
75+
$result['raw_value_url'] = $this->urlGenerator->generate('process_overview_raw_data_field',
76+
[
77+
'group' => $overview->getGroup()->getId(),
78+
'overview' => $overview->getId(),
79+
'run' => $item['id'],
80+
'field' => $col['data'],
81+
], UrlGeneratorInterface::ABSOLUTE_URL);
82+
}
83+
$result['value'] = $value;
84+
85+
return $result;
86+
},
6887
$metadataColumns
6988
),
7089
array_map(static fn (array $step) => $step + ['type' => 'step'], $steps),
@@ -101,6 +120,22 @@ public function getData(Request $request, ProcessOverview $overview): array
101120
}
102121
}
103122

123+
public function getRawRunFieldValue(Request $request, ProcessOverview $overview, string $run, string $field)
124+
{
125+
$datasource = $overview->getDataSource();
126+
$processId = $overview->getProcessId();
127+
if (empty($datasource) || empty($processId)) {
128+
return [];
129+
}
130+
131+
$data = $this->dataSourceHelper->getProcessRun($datasource, $processId, $run);
132+
133+
return [
134+
'field' => $field,
135+
'value' => $this->getArrayValue($data, $field),
136+
];
137+
}
138+
104139
private function getArrayValue(array $array, string $key): mixed
105140
{
106141
$propertyPath = '['.str_replace('.', '][', $key).']';

0 commit comments

Comments
 (0)