gui: Refactor out-of-sync modal (#6452)

This commit is contained in:
Simon Frei 2020-04-02 16:18:41 +02:00 committed by GitHub
parent 32245435e2
commit f69c0b550c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 33 deletions

View File

@ -42,9 +42,8 @@ angular.module('syncthing.core')
$scope.folderStats = {}; $scope.folderStats = {};
$scope.progress = {}; $scope.progress = {};
$scope.version = {}; $scope.version = {};
$scope.needed = []; $scope.needed = {}
$scope.neededCurrentPage = 1; $scope.neededFolder = '';
$scope.neededPageSize = 10;
$scope.failed = {}; $scope.failed = {};
$scope.localChanged = {}; $scope.localChanged = {};
$scope.scanProgress = {}; $scope.scanProgress = {};
@ -299,12 +298,12 @@ angular.module('syncthing.core')
for (var folder in $scope.progress) { for (var folder in $scope.progress) {
if (!(folder in progress)) { if (!(folder in progress)) {
if ($scope.neededFolder === folder) { if ($scope.neededFolder === folder) {
refreshNeed(folder); refreshNeed($scope.needed.page, $scope.needed.perpage);
} }
} else if ($scope.neededFolder === folder) { } else if ($scope.neededFolder === folder) {
for (file in $scope.progress[folder]) { for (file in $scope.progress[folder]) {
if (!(file in progress[folder])) { if (!(file in progress[folder])) {
refreshNeed(folder); refreshNeed($scope.needed.page, $scope.needed.perpage);
break; break;
} }
} }
@ -580,18 +579,16 @@ angular.module('syncthing.core')
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
} }
function refreshNeed(folder) { $scope.refreshNeed = function (page, perpage) {
if (!$scope.neededFolder) { if (!$scope.neededFolder) {
return; return;
} }
var url = urlbase + "/db/need?folder=" + encodeURIComponent(folder); var url = urlbase + "/db/need?folder=" + encodeURIComponent($scope.neededFolder);
url += "&page=" + $scope.neededCurrentPage; url += "&page=" + page;
url += "&perpage=" + $scope.neededPageSize; url += "&perpage=" + perpage;
$http.get(url).success(function (data) { $http.get(url).success(function (data) {
if ($scope.neededFolder === folder) { console.log("refreshNeed", $scope.neededFolder, data);
console.log("refreshNeed", folder, data); parseNeeded(data);
parseNeeded(data);
}
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
} }
@ -611,6 +608,7 @@ angular.module('syncthing.core')
} }
function parseNeeded(data) { function parseNeeded(data) {
$scope.needed = data;
var merged = []; var merged = [];
data.progress.forEach(function (item) { data.progress.forEach(function (item) {
item.type = "progress"; item.type = "progress";
@ -627,7 +625,7 @@ angular.module('syncthing.core')
item.action = needAction(item); item.action = needAction(item);
merged.push(item); merged.push(item);
}); });
$scope.needed = merged; $scope.needed.items = merged;
} }
function pathJoin(base, name) { function pathJoin(base, name) {
@ -682,16 +680,6 @@ angular.module('syncthing.core')
}); });
}; };
$scope.neededPageChanged = function (page) {
$scope.neededCurrentPage = page;
refreshNeed($scope.neededFolder);
};
$scope.neededChangePageSize = function (perpage) {
$scope.neededPageSize = perpage;
refreshNeed($scope.neededFolder);
};
$scope.refreshFailed = function (page, perpage) { $scope.refreshFailed = function (page, perpage) {
if (!$scope.failed || !$scope.failed.folder) { if (!$scope.failed || !$scope.failed.folder) {
return; return;
@ -2223,11 +2211,10 @@ angular.module('syncthing.core')
$scope.showNeed = function (folder) { $scope.showNeed = function (folder) {
$scope.neededFolder = folder; $scope.neededFolder = folder;
refreshNeed(folder); $scope.refreshNeed(1, 10);
$('#needed').modal().one('hidden.bs.modal', function () { $('#needed').modal().one('hidden.bs.modal', function () {
$scope.neededFolder = undefined;
$scope.needed = undefined; $scope.needed = undefined;
$scope.neededCurrentPage = 1; $scope.neededFolder = '';
}); });
}; };
@ -2377,8 +2364,8 @@ angular.module('syncthing.core')
$scope.bumpFile = function (folder, file) { $scope.bumpFile = function (folder, file) {
var url = urlbase + "/db/prio?folder=" + encodeURIComponent(folder) + "&file=" + encodeURIComponent(file); var url = urlbase + "/db/prio?folder=" + encodeURIComponent(folder) + "&file=" + encodeURIComponent(file);
// In order to get the right view of data in the response. // In order to get the right view of data in the response.
url += "&page=" + $scope.neededCurrentPage; url += "&page=" + $scope.needed.page;
url += "&perpage=" + $scope.neededPageSize; url += "&perpage=" + $scope.needed.perpage;
$http.post(url).success(function (data) { $http.post(url).success(function (data) {
if ($scope.neededFolder === folder) { if ($scope.neededFolder === folder) {
console.log("bumpFile", folder, data); console.log("bumpFile", folder, data);

View File

@ -14,7 +14,7 @@
<table class="table table-striped table-condensed"> <table class="table table-striped table-condensed">
<tr dir-paginate="f in needed | itemsPerPage: neededPageSize" current-page="neededCurrentPage" total-items="model[neededFolder].needTotalItems" pagination-id="needed"> <tr dir-paginate="f in needed.items | itemsPerPage: needed.perpage" current-page="needed.page" total-items="model[neededFolder].needTotalItems" pagination-id="needed">
<!-- Icon --> <!-- Icon -->
<td class="small-data col-xs-2"> <td class="small-data col-xs-2">
@ -56,10 +56,10 @@
</tr> </tr>
</table> </table>
<dir-pagination-controls on-page-change="neededPageChanged(newPageNumber)" pagination-id="needed"></dir-pagination-controls> <dir-pagination-controls on-page-change="refreshNeed(newPageNumber, needed.perpage)" pagination-id="needed" ></dir-pagination-controls>
<ul class="pagination pull-right"> <ul class="pagination pull-right">
<li ng-repeat="option in [10, 25, 50]" ng-class="{ active: neededPageSize == option }"> <li ng-repeat="option in [10, 25, 50]" ng-class="{ active: needed.perpage == option }">
<a href="#" ng-click="neededChangePageSize(option)">{{option}}</a> <a href="#" ng-click="refreshNeed(needed.page, option)">{{option}}</a>
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>