Merge pull request #4114 from sparxooo/filefolder-rename
File/Folder renaming in OctoPrint web UI
This commit is contained in:
4 files changed
+42
-12
No files matched your search
@@ -143,6 +143,7 @@ date of first contribution):
|
||||
* [Karthikeyan Singaravelan](https://github.com/tirkarthi)
|
||||
* [Yvan Rodrigues](https://github.com/TwoRedCells)
|
||||
* [Elton Law](https://github.com/eltonlaw)
|
||||
* ["sparxooo"] (https://github.com/sparxooo)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
||||
@@ -1088,18 +1088,25 @@ def gcodeFileCommand(filename, target):
|
||||
target, dst_path, fileManager.sanitize_name(target, dst_name)
|
||||
)
|
||||
|
||||
if (
|
||||
_verifyFolderExists(target, destination)
|
||||
and sanitized_destination != filename
|
||||
):
|
||||
# destination is an existing folder and not ourselves (= display rename), we'll assume we are supposed
|
||||
# to move filename to this folder under the same name
|
||||
destination = fileManager.join_path(target, destination, name)
|
||||
# Check for exception thrown by _verifyFolderExists, if outside the root directory
|
||||
try:
|
||||
if (
|
||||
_verifyFolderExists(target, destination)
|
||||
and sanitized_destination != filename
|
||||
):
|
||||
# destination is an existing folder and not ourselves (= display rename), we'll assume we are supposed
|
||||
# to move filename to this folder under the same name
|
||||
destination = fileManager.join_path(target, destination, name)
|
||||
|
||||
if _verifyFileExists(target, destination) or _verifyFolderExists(
|
||||
target, destination
|
||||
):
|
||||
abort(409, description="File or folder does already exist")
|
||||
if _verifyFileExists(target, destination) or _verifyFolderExists(
|
||||
target, destination
|
||||
):
|
||||
abort(409, description="File or folder does already exist")
|
||||
|
||||
except Exception:
|
||||
abort(
|
||||
409, description="Exception thrown by storage, bad folder/file name?"
|
||||
)
|
||||
|
||||
is_file = fileManager.file_exists(target, filename)
|
||||
is_folder = fileManager.folder_exists(target, filename)
|
||||
|
||||
@@ -83,6 +83,20 @@ $(function () {
|
||||
self.moveEntry = ko.observable({name: "", display: "", path: ""}); // is there a better way to do this?
|
||||
self.moveSource = ko.observable(undefined);
|
||||
self.moveDestination = ko.observable(undefined);
|
||||
self.moveSourceFilename = ko.observable(undefined);
|
||||
self.moveDestinationFilename = ko.observable(undefined);
|
||||
self.moveDestinationFullpath = ko.pureComputed(function () {
|
||||
// Join the paths for renaming
|
||||
if (self.moveSourceFilename() != self.moveDestinationFilename()) {
|
||||
if (self.moveDestination() === "/") {
|
||||
return self.moveDestination() + self.moveDestinationFilename();
|
||||
} else {
|
||||
return self.moveDestination() + "/" + self.moveDestinationFilename();
|
||||
}
|
||||
} else {
|
||||
return self.moveDestination();
|
||||
}
|
||||
});
|
||||
self.moveError = ko.observable("");
|
||||
|
||||
self.folderList = ko.observableArray(["/"]);
|
||||
@@ -680,6 +694,8 @@ $(function () {
|
||||
self.moveError("");
|
||||
self.moveSource(current);
|
||||
self.moveDestination(current);
|
||||
self.moveSourceFilename(entry.name);
|
||||
self.moveDestinationFilename(entry.name);
|
||||
self.moveDialog.modal("show");
|
||||
};
|
||||
|
||||
|
||||
@@ -33,12 +33,18 @@
|
||||
<select class="input-block-level" data-bind="value: moveDestination, options: folderList"></select>
|
||||
<span class="help-block"><small class="text-error" data-bind="text: moveError, visible: moveError().length > 0" style="display: none"></small></span>
|
||||
</div>
|
||||
<label class="control-label">{{ _('Set destination filename ') }} ({{ _('Currently:') }} <span data-bind="text: moveSourceFilename()"></span>)</label>
|
||||
<div class="controls">
|
||||
<input class="input-block-level" data-bind="value: moveDestinationFilename" />
|
||||
</div>
|
||||
|
||||
<p> {{ _('File/Folder will be moved to: ') }} <span data-bind="text: moveDestinationFullpath()"></span></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn" data-dismiss="modal" aria-hidden="true">{{ _('Cancel') }}</a>
|
||||
<a href="#" class="btn btn-primary" data-bind="click: function() { if (moveSource() !== moveDestination() && !movingFileOrFolder()) { $root.moveFileOrFolder(moveEntry().path, moveDestination()) } else {} }, css: {disabled: moveSource() === moveDestination() || movingFileOrFolder()}"><i class="fas fa-spinner fa-spin" data-bind="visible: movingFileOrFolder"></i> {{ _('Move') }}</a>
|
||||
<a href="#" class="btn btn-primary" data-bind="click: function() { if ((moveSource() !== moveDestination() || moveSourceFilename() !== moveDestinationFilename()) && !movingFileOrFolder()) { $root.moveFileOrFolder(moveEntry().path, moveDestinationFullpath()) } else {} }, css: {disabled: (moveSource() === moveDestination() && moveSourceFilename() === moveDestinationFilename()) || movingFileOrFolder()}"><i class="fas fa-spinner fa-spin" data-bind="visible: movingFileOrFolder"></i> {{ _('Move') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user