Skip to content

Commit

Permalink
Keyword search in config file editor
Browse files Browse the repository at this point in the history
  • Loading branch information
leiweibau committed Nov 11, 2024
1 parent 6da71b4 commit 165ebb5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
40 changes: 37 additions & 3 deletions front/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,10 @@

<div class="box box-solid box-danger collapsed-box" style="margin-top: -15px;">
<div class="box-header with-border" data-widget="collapse" id="configeditor_innerbox">
<h3 class="box-title"><?=$pia_lang['MT_ConfEditor_Hint'];?></h3>
<div class="box-tools pull-right">
<h3 class="box-title"><?=$pia_lang['MT_ConfEditor_Hint'];?></h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool"><i class="fa fa-plus"></i></button>
</div>
</div>
</div>
<div class="box-body">
<table class="table configeditor_help">
Expand Down Expand Up @@ -762,6 +762,8 @@
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Config Editor</h4>
<input type="text" id="searchInput" placeholder="<?=$pia_lang['Device_Searchbox'];?>..." class="form-control" style="margin-top: 10px; max-width: 200px; display: inline-block;">
<button type="button" id="nextButton" class="btn btn-primary" style="margin-left: 10px;">Next</button>
</div>
<div class="modal-body" style="text-align: left;">
<textarea class="form-control" name="txtConfigFileEditor" id="ConfigFileEditor" spellcheck="false" wrap="off" style="resize: none; font-family: monospace; height: 70vh;"><?=file_get_contents('../config/pialert.conf');?></textarea>
Expand Down Expand Up @@ -820,6 +822,38 @@
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})

let searchIndex = 0;

document.getElementById('searchInput').addEventListener('input', function () {
searchIndex = 0;
highlightNextMatch(false);
});

document.getElementById('nextButton').addEventListener('click', function () {
highlightNextMatch(false);
});

function highlightNextMatch() {
const searchText = document.getElementById('searchInput').value.toLowerCase();
const textarea = document.getElementById('ConfigFileEditor');
const text = textarea.value.toLowerCase();

if (searchText) {
const nextIndex = text.indexOf(searchText, searchIndex);
if (nextIndex !== -1) {
const beforeMatch = textarea.value.substring(0, nextIndex);
const lineHeight = textarea.scrollHeight / textarea.value.split('\n').length;
const lineNumber = beforeMatch.split('\n').length - 1;
textarea.scrollTop = lineHeight * lineNumber;
searchIndex = nextIndex + searchText.length;
} else {
searchIndex = 0;
alert('<?=$pia_lang['MT_ConfEditor_SearchEnd'];?>');
}
}
}

});
</script>

Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/de_de.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
$pia_lang['MT_Tool_logindisable_noti'] = 'Login deaktivieren';
$pia_lang['MT_Tool_logindisable_noti_text'] = 'Bist du dir sicher, dass du den Login deaktivieren möchtest?';
$pia_lang['MT_ConfEditor_Start'] = 'Pi.Alert Config bearbeiten';
$pia_lang['MT_ConfEditor_SearchEnd'] = 'Keine weiteren Treffer gefunden';
$pia_lang['MT_ConfEditor_Hint'] = 'Hinweise zum Editor';
$pia_lang['MT_ConfEditor_Backup'] = 'Backup anlegen';
$pia_lang['MT_ConfEditor_Restore'] = 'Vorherige Version';
Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/en_us.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
$pia_lang['MT_Tool_logindisable_noti'] = 'Disable Login';
$pia_lang['MT_Tool_logindisable_noti_text'] = 'Are you sure you want to deactivate the login?';
$pia_lang['MT_ConfEditor_Start'] = 'Edit Pi.Alert Config';
$pia_lang['MT_ConfEditor_SearchEnd'] = 'No further matches found';
$pia_lang['MT_ConfEditor_Hint'] = 'Notes to the editor';
$pia_lang['MT_ConfEditor_Backup'] = 'Create Backup';
$pia_lang['MT_ConfEditor_Restore'] = 'Prev. Version';
Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/es_es.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
$pia_lang['MT_Tool_logindisable_noti'] = 'Login desactivado.';
$pia_lang['MT_Tool_logindisable_noti_text'] = '¿Estás seguro de que quieres desactivar el inicio de sesión?';
$pia_lang['MT_ConfEditor_Start'] = 'Editar Pi.Alert Config';
$pia_lang['MT_ConfEditor_SearchEnd'] = 'No se encontraron más coincidencias';
$pia_lang['MT_ConfEditor_Hint'] = 'Notas sobre el editor';
$pia_lang['MT_ConfEditor_Backup'] = 'Crear copia de seguridad';
$pia_lang['MT_ConfEditor_Restore'] = 'A la última versión';
Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/fr_fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
$pia_lang['MT_Tool_logindisable_noti'] = 'Désactiver le login';
$pia_lang['MT_Tool_logindisable_noti_text'] = 'Es-tu sûr de vouloir désactiver le login ?';
$pia_lang['MT_ConfEditor_Start'] = 'Modifier la config Pi.Alert';
$pia_lang['MT_ConfEditor_SearchEnd'] = 'Aucun autre résultat trouvé';
$pia_lang['MT_ConfEditor_Hint'] = 'Remarques sur l&apos;éditeur';
$pia_lang['MT_ConfEditor_Backup'] = 'Créer une sauvegarde';
$pia_lang['MT_ConfEditor_Restore'] = 'Vers la dernière version';
Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/it_it.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
$pia_lang['MT_Tool_logindisable_noti'] = 'Disabilita accesso';
$pia_lang['MT_Tool_logindisable_noti_text'] = 'Sei sicuro di voler disabilitare l&apos;accesso?';
$pia_lang['MT_ConfEditor_Start'] = 'Modifica configurazione Pi.Alert';
$pia_lang['MT_ConfEditor_SearchEnd'] = 'Nessun altro risultato trovato';
$pia_lang['MT_ConfEditor_Hint'] = 'Note sull&apos;editor';
$pia_lang['MT_ConfEditor_Backup'] = 'Crea backup';
$pia_lang['MT_ConfEditor_Restore'] = 'Versione precedente';
Expand Down

0 comments on commit 165ebb5

Please sign in to comment.