This changes the error handling in loading ignores slightly: - There is a new ParseError type that is returned as the error (somewhere in the chain) when the problem was not an I/O error loading the file, but some issue with the contents. - If the file was read successfully but not parsed successfully we still return the lines read (in addition to nil patterns and a ParseError). - In the API, if the error IsParseError then we return a successful HTTP response with the lines and the actual error included in the JSON object. - In the GUI, as long as the HTTP call to load the ignores was successful we can edit the ignores. If there was an error we show this as a validation error on the dialog. Also some cleanup on the Javascript side as it for some reason used jQuery instead of Angular for this editor...
This commit is contained in:
@@ -52,6 +52,11 @@ angular.module('syncthing.core')
|
||||
$scope.metricRates = false;
|
||||
$scope.folderPathErrors = {};
|
||||
$scope.currentFolder = {};
|
||||
$scope.ignores = {
|
||||
text: '',
|
||||
error: null,
|
||||
disabled: false,
|
||||
};
|
||||
resetRemoteNeed();
|
||||
|
||||
try {
|
||||
@@ -433,8 +438,8 @@ angular.module('syncthing.core')
|
||||
}
|
||||
|
||||
function refreshNoAuthWarning() {
|
||||
if (!$scope.system || !$scope.config) {
|
||||
// We need both to be able to determine the state.
|
||||
if (!$scope.system || !$scope.config || !$scope.config.gui) {
|
||||
// We need all to be able to determine the state.
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1766,16 +1771,18 @@ angular.module('syncthing.core')
|
||||
}
|
||||
$scope.currentFolder.externalCommand = $scope.currentFolder.externalCommand || "";
|
||||
|
||||
$('#folder-ignores textarea').val($translate.instant("Loading..."));
|
||||
$('#folder-ignores textarea').attr('disabled', 'disabled');
|
||||
$scope.ignores.text = 'Loading...';
|
||||
$scope.ignores.error = null;
|
||||
$scope.ignores.disabled = true;
|
||||
$http.get(urlbase + '/db/ignores?folder=' + encodeURIComponent($scope.currentFolder.id))
|
||||
.success(function (data) {
|
||||
$scope.currentFolder.ignores = data.ignore || [];
|
||||
$('#folder-ignores textarea').val($scope.currentFolder.ignores.join('\n'));
|
||||
$('#folder-ignores textarea').removeAttr('disabled');
|
||||
$scope.ignores.text = $scope.currentFolder.ignores.join('\n');
|
||||
$scope.ignores.error = data.error;
|
||||
$scope.ignores.disabled = false;
|
||||
})
|
||||
.error(function (err) {
|
||||
$('#folder-ignores textarea').val($translate.instant("Failed to load ignore patterns."));
|
||||
$scope.ignores.text = $translate.instant("Failed to load ignore patterns.");
|
||||
$scope.emitHTTPError(err);
|
||||
});
|
||||
|
||||
@@ -1802,8 +1809,9 @@ angular.module('syncthing.core')
|
||||
$scope.currentFolder = angular.copy($scope.folderDefaults);
|
||||
$scope.currentFolder.id = (data.random.substr(0, 5) + '-' + data.random.substr(5, 5)).toLowerCase();
|
||||
$scope.currentFolder.unrelatedDevices = $scope.otherDevices();
|
||||
$('#folder-ignores textarea').val("");
|
||||
$('#folder-ignores textarea').removeAttr('disabled');
|
||||
$scope.ignores.text = '';
|
||||
$scope.ignores.error = null;
|
||||
$scope.ignores.disabled = false;
|
||||
$scope.editFolderModal();
|
||||
});
|
||||
};
|
||||
@@ -1818,8 +1826,9 @@ angular.module('syncthing.core')
|
||||
};
|
||||
$scope.currentFolder.selectedDevices[device] = true;
|
||||
$scope.currentFolder.unrelatedDevices = $scope.otherDevices();
|
||||
$('#folder-ignores textarea').val("");
|
||||
$('#folder-ignores textarea').removeAttr('disabled');
|
||||
$scope.ignores.text = '';
|
||||
$scope.ignores.error = null;
|
||||
$scope.ignores.disabled = false;
|
||||
$scope.editFolderModal();
|
||||
};
|
||||
|
||||
@@ -1899,8 +1908,8 @@ angular.module('syncthing.core')
|
||||
delete folderCfg.versioning;
|
||||
}
|
||||
|
||||
var ignoresLoaded = !$('#folder-ignores textarea').is(':disabled');
|
||||
var ignores = $('#folder-ignores textarea').val().split('\n');
|
||||
var ignoresLoaded = !$scope.ignores.disabled;
|
||||
var ignores = $scope.ignores.text.split('\n');
|
||||
// Split always returns a minimum 1-length array even for no patterns
|
||||
if (ignores.length === 1 && ignores[0] === "") {
|
||||
ignores = [];
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<li><a data-toggle="tab" href="#folder-advanced"><span class="fas fa-cogs"></span> <span translate>Advanced</span></a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
|
||||
<div id="folder-general" class="tab-pane in active">
|
||||
<div class="form-group" ng-class="{'has-error': folderEditor.folderLabel.$invalid && folderEditor.folderLabel.$dirty}">
|
||||
<label for="folderLabel"><span translate>Folder Label</span></label>
|
||||
@@ -43,6 +44,7 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="folder-sharing" class="tab-pane">
|
||||
<div class="form-group" ng-if="currentFolder.sharedDevices.length">
|
||||
<label translate>Currently Shared With Devices</label>
|
||||
@@ -82,6 +84,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="folder-versioning" class="tab-pane">
|
||||
<div class="form-group">
|
||||
<label translate>File Versioning</label> <a href="https://docs.syncthing.net/users/versioning.html" target="_blank"><span class="fas fa-question-circle"></span> <span translate>Help</span></a>
|
||||
@@ -142,9 +145,15 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="folder-ignores" class="tab-pane">
|
||||
<p translate>Enter ignore patterns, one per line.</p>
|
||||
<textarea class="form-control" rows="5"></textarea>
|
||||
<div ng-class="{'has-error': ignores.error != null}">
|
||||
<textarea class="form-control" rows="5" ng-model="ignores.text" ng-disabled="ignores.disabled"></textarea>
|
||||
<p class="help-block" ng-if="ignores.error">
|
||||
{{ignores.error}}
|
||||
</p>
|
||||
</div>
|
||||
<hr />
|
||||
<p class="small"><span translate>Quick guide to supported patterns</span> (<a href="https://docs.syncthing.net/users/ignoring.html" target="_blank" translate>full documentation</a>):</p>
|
||||
<dl class="dl-horizontal dl-narrow small">
|
||||
@@ -165,6 +174,7 @@
|
||||
<span translate ng-show="editingExisting" translate-value-path="{{currentFolder.path}}{{system.pathSeparator}}.stignore">Editing {%path%}.</span>
|
||||
<span translate ng-show="!editingExisting" translate-value-path="{{currentFolder.path}}{{system.pathSeparator}}.stignore">Creating ignore patterns, overwriting an existing file at {%path%}.</span>
|
||||
</div>
|
||||
|
||||
<div id="folder-advanced" class="tab-pane">
|
||||
<div class="row form-group" ng-class="{'has-error': folderEditor.rescanIntervalS.$invalid && folderEditor.rescanIntervalS.$dirty}">
|
||||
<div class="col-md-12">
|
||||
|
||||
Reference in New Issue
Block a user