Skip to content
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

gui: Add search bar for logging (fixes #9252) #9255

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions gui/default/syncthing/core/logViewerModalView.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
</div>
</div>
<div class="modal-footer">
<div>
<input type="text" id="logSearchInput" class="form-control" style="margin-bottom: 10px;" ng-keyup="logging.filter_input($event)">
DAlba-sudo marked this conversation as resolved.
Show resolved Hide resolved
<div>
<input type="checkbox" ng-click="logging.isCaseSensitive = !logging.isCaseSensitive"><span>Case Sensitive</span>
DAlba-sudo marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>

<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">
<span class="fas fa-times"></span>&nbsp;<span translate>Close</span>
</button>
Expand Down
40 changes: 38 additions & 2 deletions gui/default/syncthing/core/syncthingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1495,13 +1495,45 @@ angular.module('syncthing.core')
timer: null,
entries: [],
paused: false,
filtered: [],
isFiltering: false,
isCaseSensitive: false,
lastFilterQuery: "",

content: function () {
var target_array = $scope.logging.isFiltering ? $scope.logging.filtered : $scope.logging.entries;
var content = "";
$.each($scope.logging.entries, function (idx, entry) {
$.each(target_array, function (idx, entry) {
content += entry.when.split('.')[0].replace('T', ' ') + ' ' + entry.message + "\n";
});
return content;
},

filter: function(search_query, array) {
if (search_query.length < 3) {
$scope.logging.isFiltering = false;
$scope.logging.filtered.length = 0;
$scope.logging.lastFilterQuery = "";
return;
}

$.each(array, function (idx, entry) {
let msg = !$scope.logging.isCaseSensitive ? entry.message.toLowerCase() : entry.message;
if (msg.includes(search_query)) {
$scope.logging.filtered.push(entry);
}
});
},

filter_input: function(event) {
let query = !$scope.logging.isCaseSensitive ? event.target.value.toLowerCase() : event.target.value;
$scope.logging.filtered.length = 0; // clears prevents "double writing" in the console
$scope.logging.filter(query, $scope.logging.entries);

$scope.logging.isFiltering = true;
$scope.logging.lastFilterQuery = query;
},

fetch: function () {
var textArea = $('#logViewerText');
if ($scope.logging.paused) {
Expand All @@ -1521,14 +1553,18 @@ angular.module('syncthing.core')
if (!$scope.logging.paused) {
if (data.messages) {
$scope.logging.entries.push.apply($scope.logging.entries, data.messages);
if ($scope.logging.isFiltering) {
$scope.logging.filter($scope.logging.lastFilterQuery, data.messages);
}

// Wait for the text area to be redrawn, adding new lines, and then scroll to bottom.
$timeout(function () {
textArea.scrollTop(textArea[0].scrollHeight);
});
}
}
});
}
},
};

$scope.about = {
Expand Down