Skip to content

Commit

Permalink
Restore console config values only when necessary
Browse files Browse the repository at this point in the history
This reduces the need of unnecessary HTTP requests.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Mar 29, 2024
1 parent f9600dd commit e299aef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
36 changes: 29 additions & 7 deletions resources/js/src/modules/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,35 @@ var Console = {
consoleContent.classList.toggle('console_dark_theme', isDarkTheme);
});

$('#pma_console_options').find('.button.default').on('click', function () {
(document.getElementById('consoleOptionsAlwaysExpandCheckbox') as HTMLInputElement).checked = false;
(document.getElementById('consoleOptionsStartHistoryCheckbox') as HTMLInputElement).checked = false;
(document.getElementById('consoleOptionsCurrentQueryCheckbox') as HTMLInputElement).checked = true;
(document.getElementById('consoleOptionsEnterExecutesCheckbox') as HTMLInputElement).checked = false;
(document.getElementById('consoleOptionsDarkThemeCheckbox') as HTMLInputElement).checked = false;
Config.update();
const restoreConsoleOptionsButton = document.getElementById('pma_console_options').querySelector('.button.default');
restoreConsoleOptionsButton?.addEventListener('click', function (): void {
if (consoleOptionsAlwaysExpandCheckbox.checked) {
consoleOptionsAlwaysExpandCheckbox.checked = false;
Config.set('AlwaysExpand', false);
}

if (consoleOptionsStartHistoryCheckbox.checked) {
consoleOptionsStartHistoryCheckbox.checked = false;
Config.set('StartHistory', false);
}

if (! consoleOptionsCurrentQueryCheckbox.checked) {
consoleOptionsCurrentQueryCheckbox.checked = true;
Config.set('CurrentQuery', true);
}

if (consoleOptionsEnterExecutesCheckbox.checked) {
consoleOptionsEnterExecutesCheckbox.checked = false;
Config.set('EnterExecutes', false);
ConsoleMessages.showInstructions(false);
}

if (consoleOptionsDarkThemeCheckbox.checked) {
consoleOptionsDarkThemeCheckbox.checked = false;
Config.set('DarkTheme', false);
const consoleContent = document.getElementById('pma_console').querySelector('.content');
consoleContent.classList.remove('console_dark_theme');
}
});

$(document).on('ajaxComplete', function (event, xhr, ajaxOptions) {
Expand Down
18 changes: 0 additions & 18 deletions resources/js/src/modules/console/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,6 @@ export const Config = {
this[key] = value;
setConfigValue(key, value);
},

/**
* Used for update console config
*/
update: function (): void {
this.set('AlwaysExpand', !! (document.getElementById('consoleOptionsAlwaysExpandCheckbox') as HTMLInputElement).checked);
this.set('StartHistory', !! (document.getElementById('consoleOptionsStartHistoryCheckbox') as HTMLInputElement).checked);
this.set('CurrentQuery', !! (document.getElementById('consoleOptionsCurrentQueryCheckbox') as HTMLInputElement).checked);
this.set('EnterExecutes', !! (document.getElementById('consoleOptionsEnterExecutesCheckbox') as HTMLInputElement).checked);
this.set('DarkTheme', !! (document.getElementById('consoleOptionsDarkThemeCheckbox') as HTMLInputElement).checked);
/* Setting the dark theme of the console*/
const consoleContent = document.getElementById('pma_console').querySelector('.content');
if (this.DarkTheme) {
consoleContent.classList.add('console_dark_theme');
} else {
consoleContent.classList.remove('console_dark_theme');
}
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/console/display.twig
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<span>{{ 'Options'|trans }}</span>
</div>
<div class="button default">
<span>{{ 'Set default'|trans }}</span>
<span>{{ 'Restore default values'|trans }}</span>
</div>
</div>

Expand Down

0 comments on commit e299aef

Please sign in to comment.