Skip to content

Commit 8fead6b

Browse files
committed
Add a flash to the config page showing what has changed.
1 parent 3d611f6 commit 8fead6b

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

webapp/src/Controller/Jury/ConfigController.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,30 @@ public function indexAction(EventLogService $eventLogService, Request $request):
6565
}
6666
}
6767
}
68+
$before = $this->config->all();
6869
$errors = $this->config->saveChanges($data, $eventLogService, $this->dj, $options);
70+
$after = $this->config->all();
71+
72+
// Compile a list of differences.
73+
$diffs = [];
74+
foreach ($before as $key => $value) {
75+
if (!array_key_exists($key, $after)) {
76+
$diffs[$key] = ['before' => $value, 'after' => null];
77+
} elseif ($value !== $after[$key]) {
78+
$diffs[$key] = ['before' => $value, 'after' => $after[$key]];
79+
}
80+
}
81+
foreach ($after as $key => $value) {
82+
if (!array_key_exists($key, $before)) {
83+
$diffs[$key] = ['before' => null, 'after' => $value];
84+
}
85+
}
6986

7087
if (empty($errors)) {
7188
$this->addFlash('scoreboard_refresh', 'After changing specific ' .
7289
'settings, you might need to refresh the scoreboard.');
7390

74-
return $this->redirectToRoute('jury_config');
91+
return $this->redirectToRoute('jury_config', ['diffs' => json_encode($diffs)]);
7592
} else {
7693
$this->addFlash('danger', 'Some errors occurred while saving configuration, ' .
7794
'please check the data you entered.');
@@ -114,10 +131,15 @@ public function indexAction(EventLogService $eventLogService, Request $request):
114131
'data' => $data
115132
];
116133
}
134+
$diffs = $request->query->get('diffs');
135+
if ($diffs !== null) {
136+
$diffs = json_decode($diffs, true);
137+
}
117138
return $this->render('jury/config.html.twig', [
118139
'options' => $allData,
119140
'errors' => $errors ?? [],
120141
'activeCategory' => $activeCategory ?? 'Scoring',
142+
'diffs' => $diffs,
121143
]);
122144
}
123145

webapp/templates/jury/config.html.twig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@
1515
{% endblock %}
1616

1717
{% block content %}
18+
{% if diffs is not null %}
19+
{% if diffs %}
20+
<div class="alert alert-info" role="alert">
21+
Saved changes:
22+
<ul>
23+
{% for key, change in diffs %}
24+
<li>
25+
<code>{{ key }}</code>:
26+
{{ change.before | json_encode }}
27+
28+
{{ change.after | json_encode }}
29+
</li>
30+
{% endfor %}
31+
</ul>
32+
</div>
33+
{% else %}
34+
<div class="alert alert-warning" role="alert">
35+
<p>No changes made, no changes saved.</p>
36+
</div>
37+
{% endif %}
38+
39+
{% endif %}
1840
<h1>Configuration</h1>
1941

2042
<form method="post">

0 commit comments

Comments
 (0)