-
Notifications
You must be signed in to change notification settings - Fork 14
Implement Query history #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ace4faa
Create history obj in servershell
Mihitoko 3a780a7
Create history button
Mihitoko dc02e99
Move search auto complete into function
Mihitoko 5d287df
Add history svg
Mihitoko 25fc5c8
Close history on focus los
Mihitoko 68f17a7
Rename search to term
Mihitoko 4455ed1
Store queried entries
Mihitoko 4d990e4
Implement additional settings
Mihitoko ca3f937
Add disclaimer to history.js
Mihitoko feba596
Apply PR suggestions
Mihitoko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
serveradmin/servershell/static/js/servershell/autocomplete/history.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Autocomplete History - Copyright (c) 2026 InnoGames GmbH | ||
| * | ||
| * This module ads auto complete while searching the query history | ||
| */ | ||
|
|
||
| servershell.autocomplete_history_enabled = false; | ||
|
|
||
| servershell.close_history_autocomplete = function () { | ||
| const autocomplete_search_input = $('#term'); | ||
| autocomplete_search_input.autocomplete('destroy'); | ||
Mihitoko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| servershell.autocomplete_history_enabled = false; | ||
| servershell.enable_search_autocomplete(); | ||
| $('#history-toggle').removeClass('active'); | ||
| } | ||
|
|
||
| servershell.open_history_autocomplete = function () { | ||
| const autocomplete_search_input = $('#term'); | ||
| autocomplete_search_input.autocomplete('destroy'); | ||
| autocomplete_search_input.autocomplete({ | ||
| source: function (request, response) { | ||
| const displayLimit = 20; | ||
| const search = request.term; | ||
|
|
||
| const history = servershell.history.get() | ||
| const possibleChoices = history.filter((entry) => entry.term.toLowerCase().includes(search.toLowerCase())) | ||
| .map((entry) => entry.term); | ||
| response(possibleChoices.slice(0, Math.min(displayLimit, possibleChoices.length))); | ||
| }, | ||
|
|
||
| select: function (_, ui) { | ||
| const term = ui.item.value; | ||
| const [, entry] = servershell.history.findMatchingEntry(term); | ||
|
|
||
| servershell.term = term; | ||
|
|
||
| const manageAttributes = $('#history_attributes')[0].checked; | ||
| if (manageAttributes && entry) { | ||
| servershell.shown_attributes = entry.shown_attributes; | ||
| } else { | ||
| servershell.submit_search(); | ||
| } | ||
| servershell.close_history_autocomplete(); | ||
| } | ||
| }); | ||
| autocomplete_search_input.autocomplete('enable'); | ||
| autocomplete_search_input.autocomplete('option', 'autoFocus', $('#autoselect')[0].checked); | ||
| autocomplete_search_input.autocomplete('option', 'minLength', 0); | ||
| autocomplete_search_input.autocomplete('option', 'delay', $('#autocomplete_delay_search')[0].value); | ||
|
|
||
| // When history is opened show all item, regardless of the current input text | ||
| autocomplete_search_input.autocomplete('search', ""); | ||
| autocomplete_search_input.focus(); | ||
| servershell.autocomplete_history_enabled = true; | ||
| $('#history-toggle').addClass('active'); | ||
| } | ||
|
|
||
| $(document).ready(function () { | ||
| $(document).keydown(function (event) { | ||
| if (event.shiftKey && event.ctrlKey) { | ||
| if (event.key !== 'F') { | ||
| return; | ||
| } | ||
| if (servershell.autocomplete_history_enabled) { | ||
| servershell.close_history_autocomplete(); | ||
| return; | ||
| } | ||
| servershell.open_history_autocomplete(); | ||
| } | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * History - Copyright (c) 2026 InnoGames GmbH | ||
| * | ||
| * This module implements interactions with localstorage to serve the history array. | ||
| */ | ||
|
|
||
| const historyStorageKey = "servershell_history" | ||
|
|
||
| servershell.history = { | ||
| get: function () { | ||
| const history = localStorage.getItem(historyStorageKey); | ||
| if (!history) { | ||
| return []; | ||
| } | ||
|
|
||
| return JSON.parse(history); | ||
| }, | ||
|
|
||
| storeEntry: function (entry) { | ||
| const history = servershell.history.get(); | ||
|
|
||
| const [matching] = servershell.history.findMatchingEntry(entry.term); | ||
| if (matching !== -1) { | ||
| history.splice(matching, 1); | ||
| } | ||
|
|
||
| const maxSize = parseInt($('#history_size').val()); | ||
| while (history.length >= maxSize) { | ||
| history.pop(); | ||
| } | ||
|
|
||
| history.unshift(entry); | ||
|
|
||
| localStorage.setItem(historyStorageKey, JSON.stringify(history)); | ||
| }, | ||
|
|
||
| clear: function () { | ||
| localStorage.setItem(historyStorageKey, "[]"); | ||
| }, | ||
|
|
||
| findMatchingEntry: function (term) { | ||
| const history = servershell.history.get(); | ||
| const index = history.findIndex((i) => term === i.term) | ||
| if (index === -1) { | ||
| return [-1, undefined] | ||
| } | ||
|
|
||
| return [index, history[index]]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.