Skip to content

Commit 5ab7640

Browse files
committed
Remove force_file_* global vars and param
Uses a HTML data attribute instead. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 2ea4e59 commit 5ab7640

7 files changed

Lines changed: 11 additions & 26 deletions

File tree

‎js/src/export.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,9 @@ window.AJAX.registerOnload('export.js', function () {
599599
* Disables the view output as text option if the output must be saved as a file
600600
*/
601601
$('#plugins').on('change', function () {
602-
var activePlugin = $('#plugins').find('option:selected').val();
603-
var forceFile = $('#force_file_' + activePlugin).val();
604-
if (forceFile === 'true') {
602+
const isBinary = $('#plugins').find('option:selected')
603+
.attr('data-is-binary') === 'true';
604+
if (isBinary) {
605605
if ($('#radio_dump_asfile').prop('checked') !== true) {
606606
$('#radio_dump_asfile').prop('checked', true);
607607
Export.toggleSaveToFile();

‎libraries/classes/Controllers/Import/ImportController.php‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,7 @@ public function __invoke(ServerRequest $request): void
251251
return;
252252
}
253253

254-
$post_patterns = [
255-
'/^force_file_/',
256-
'/^' . $GLOBALS['format'] . '_/',
257-
];
254+
$post_patterns = ['/^' . $GLOBALS['format'] . '_/'];
258255

259256
Core::setPostAsGlobal($post_patterns);
260257

‎libraries/classes/Plugins.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public static function getDefault($section, $opt)
259259
* @param ExportPlugin[]|ImportPlugin[]|SchemaPlugin[] $list
260260
*
261261
* @return array<int, array<string, bool|string>>
262-
* @psalm-return list<array{name: non-empty-lowercase-string, text: string, is_selected: bool, force_file: bool}>
262+
* @psalm-return list<array{name: non-empty-lowercase-string, text: string, is_selected: bool, is_binary: bool}>
263263
*/
264264
public static function getChoice(array $list, string $default): array
265265
{
@@ -271,7 +271,7 @@ public static function getChoice(array $list, string $default): array
271271
'name' => $pluginName,
272272
'text' => self::getString($properties->getText()),
273273
'is_selected' => $pluginName === $default,
274-
'force_file' => $properties->getForceFile(),
274+
'is_binary' => $properties->getForceFile(),
275275
];
276276
}
277277

‎templates/database/designer/schema_export.twig‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
{% endfor %}
99
</select>
1010

11-
{% for option in plugins_choice %}
12-
<input type="hidden" id="force_file_{{ option.name }}" value="true">
13-
{% endfor %}
14-
1511
<input type="hidden" name="page_number" value="{{ page }}">
1612
{{ options|raw }}
1713
</fieldset>

‎templates/export.twig‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,9 @@
120120
<div class="card-body">
121121
<select class="form-select" id="plugins" name="what" aria-label="{% trans 'File format to export' %}">
122122
{% for option in plugins_choice %}
123-
<option value="{{ option.name }}"{{ option.is_selected ? ' selected' }}>{{ option.text }}</option>
123+
<option value="{{ option.name }}"{{ option.is_selected ? ' selected' }} data-is-binary="{{ option.is_binary ? 'true' : 'false' }}">{{ option.text }}</option>
124124
{% endfor %}
125125
</select>
126-
127-
{% for option in plugins_choice %}
128-
<input type="hidden" id="force_file_{{ option.name }}" value="{{ option.force_file ? 'true' : 'false' }}">
129-
{% endfor %}
130126
</div>
131127
</div>
132128

‎templates/import.twig‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@
170170
{% endfor %}
171171
</select>
172172

173-
{% for option in plugins_choice %}
174-
<input type="hidden" id="force_file_{{ option.name }}" value="true">
175-
{% endfor %}
176-
177173
<div id="import_notification"></div>
178174
</div>
179175
</div>

‎test/classes/PluginsTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ public function testGetChoice(): void
133133
];
134134
$actual = Plugins::getChoice($exportList, 'xml');
135135
$expected = [
136-
['name' => 'json', 'text' => 'JSON', 'is_selected' => false, 'force_file' => false],
137-
['name' => 'ods', 'text' => 'OpenDocument Spreadsheet', 'is_selected' => false, 'force_file' => true],
138-
['name' => 'sql', 'text' => 'SQL', 'is_selected' => false, 'force_file' => false],
139-
['name' => 'xml', 'text' => 'XML', 'is_selected' => true, 'force_file' => false],
136+
['name' => 'json', 'text' => 'JSON', 'is_selected' => false, 'is_binary' => false],
137+
['name' => 'ods', 'text' => 'OpenDocument Spreadsheet', 'is_selected' => false, 'is_binary' => true],
138+
['name' => 'sql', 'text' => 'SQL', 'is_selected' => false, 'is_binary' => false],
139+
['name' => 'xml', 'text' => 'XML', 'is_selected' => true, 'is_binary' => false],
140140
];
141141
$this->assertEquals($expected, $actual);
142142
}

0 commit comments

Comments
 (0)