add move file capabilities
This commit is contained in:
1 parent
f9387a46c3
commit
f3327eb3aa
4 files changed
+127
-1
No files matched your search
@@ -311,6 +311,10 @@ class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
"affected by this as well."),
|
||||
RoleNeed("files_download"),
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
FILES_MOVE = OctoPrintPermission("File Move",
|
||||
gettext("Allows users to move files"),
|
||||
RoleNeed("files_move"),
|
||||
default_groups=[USER_GROUP])
|
||||
FILES_DELETE = OctoPrintPermission("File Delete",
|
||||
gettext("Allows users to delete files"),
|
||||
RoleNeed("files_delete"),
|
||||
|
||||
@@ -75,6 +75,11 @@ $(function() {
|
||||
self.addingFolder = ko.observable(false);
|
||||
self.activeRemovals = ko.observableArray([]);
|
||||
|
||||
self.movingFile = ko.observable(false);
|
||||
self.moveSource = ko.observable({name:"",display:"",path:""}); // is there a better way to do this?
|
||||
self.moveDestination = ko.observable(undefined);
|
||||
self.moveError = ko.observable("");
|
||||
self.folderList = ko.observableArray(["/"]);
|
||||
self.addFolderDialog = undefined;
|
||||
self.addFolderName = ko.observable(undefined);
|
||||
self.enableAddFolder = ko.pureComputed(function() {
|
||||
@@ -197,6 +202,13 @@ $(function() {
|
||||
return result;
|
||||
});
|
||||
|
||||
self.folderDestinations = ko.pureComputed(function() {
|
||||
if (self.allItems()) {
|
||||
return ko.utils.arrayFilter(self.allItems(), function(item) {
|
||||
return item.type === "folder";
|
||||
});
|
||||
}
|
||||
});
|
||||
self.foldersOnlyList = ko.dependentObservable(function() {
|
||||
var filter = function(data) { return data["type"] && data["type"] === "folder"; };
|
||||
return _.filter(self.listHelper.paginatedItems(), filter);
|
||||
@@ -533,6 +545,78 @@ $(function() {
|
||||
}
|
||||
};
|
||||
|
||||
self.recursiveFolderList = function(entry) {
|
||||
if (entry.type === "folder") {
|
||||
var _folderPath = (entry.path !== "") ? "/" + entry.path : "/" + entry.name;
|
||||
if(!_.contains(self.folderList(), _folderPath)){
|
||||
self.folderList.push(_folderPath);
|
||||
}
|
||||
}
|
||||
if (entry.children) {
|
||||
_.each(entry.children, function (item) {
|
||||
self.recursiveFolderList(item);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
self.showMoveFileDialog = function(file, event) {
|
||||
if (!self.loginState.hasPermission(self.access.permissions.FILES_MOVE)) return;
|
||||
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.type === "folder") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.origin !== "local") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.moveFileDialog) {
|
||||
var activateSpinner = function(){},
|
||||
finishSpinner = function(){};
|
||||
if (event) {
|
||||
var element = $(event.currentTarget);
|
||||
if (element.length) {
|
||||
var icon = $("i.fa-arrow-right", element);
|
||||
if (icon.length) {
|
||||
activateSpinner = function() {
|
||||
icon.removeClass("fa-arrow-right").addClass("fa-spinner fa-spin");
|
||||
};
|
||||
finishSpinner = function() {
|
||||
icon.removeClass("fa-spinner fa-spin").addClass("fa-arrow-right");
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activateSpinner();
|
||||
self.moveSource(file);
|
||||
self.moveError("");
|
||||
|
||||
OctoPrint.files.list(true)
|
||||
.done(function(response) {
|
||||
if(response.files && response.files.length > 0){
|
||||
self.folderList(["/"]);
|
||||
_.each(response.files, self.recursiveFolderList);
|
||||
}
|
||||
if(self.folderList().length > 0){
|
||||
self.moveDestination("");
|
||||
self.moveFileDialog.modal("show");
|
||||
}
|
||||
})
|
||||
.fail(function() {
|
||||
console.log("error getting folder list")
|
||||
})
|
||||
.always(function() {
|
||||
finishSpinner();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
self.removeFile = function(file, event) {
|
||||
if (!self.loginState.hasPermission(self.access.permissions.FILES_DELETE)) return;
|
||||
|
||||
@@ -572,6 +656,18 @@ $(function() {
|
||||
OctoPrint.printer.refreshSd();
|
||||
};
|
||||
|
||||
self.moveFile = function(entry, event) {
|
||||
self.movingFile(true);
|
||||
self.movingFile(false);
|
||||
// start spinner here
|
||||
OctoPrint.files.move("local", self.moveSource().path, self.moveDestination())
|
||||
.done(function() {
|
||||
self.moveFileDialog.modal("hide");
|
||||
})
|
||||
.fail(function() {
|
||||
self.moveError(gettext("Unable to move file") + " " + self.moveSource().display + " " + gettext("to") + " " + self.moveDestination());
|
||||
});
|
||||
};
|
||||
self._removeEntry = function(entry, event) {
|
||||
self.activeRemovals.push(entry.origin + ":" + entry.path);
|
||||
var finishActiveRemoval = function() {
|
||||
@@ -679,6 +775,9 @@ $(function() {
|
||||
return self.loginState.hasPermission(self.access.permissions.FILES_DELETE) && !busy;
|
||||
};
|
||||
|
||||
self.enableMove = function(data) {
|
||||
return self.loginState.hasPermission(self.access.permissions.FILES_MOVE) // && some way to figure out if there are subfolders;
|
||||
};
|
||||
self.enableSelect = function(data) {
|
||||
return self.isLoadAndPrintActionPossible() && !self.listHelper.isSelected(data);
|
||||
};
|
||||
@@ -928,6 +1027,7 @@ $(function() {
|
||||
|
||||
self.listElement = $("#files").find(".scroll-wrapper");
|
||||
|
||||
self.moveFileDialog = $("#move_file_dialog");
|
||||
self.addFolderDialog = $("#add_folder_dialog");
|
||||
self.addFolderDialog.on("shown", function() {
|
||||
$("input", self.addFolderDialog).focus();
|
||||
@@ -1275,6 +1375,6 @@ $(function() {
|
||||
name: "filesViewModel",
|
||||
additionalNames: ["gcodeFilesViewModel"],
|
||||
dependencies: ["settingsViewModel", "loginStateViewModel", "printerStateViewModel", "slicingViewModel", "printerProfilesViewModel", "accessViewModel"],
|
||||
elements: ["#files_wrapper", "#add_folder_dialog"]
|
||||
elements: ["#files_wrapper", "#add_folder_dialog", "#move_file_dialog"]
|
||||
});
|
||||
});
|
||||
@@ -19,3 +19,24 @@
|
||||
<a href="#" class="btn btn-primary" data-bind="click: function() { if ($root.enableAddFolder()) { $root.addFolder() } }, enabled: $root.enableAddFolder(), css: {disabled: !$root.enableAddFolder()}"><i class="fa fa-spinner fa-spin" data-bind="visible: addingFolder"></i> {{ _('Create') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="move_file_dialog" class="modal hide fade">
|
||||
<div class="modal-header">
|
||||
<a href="#" class="close" data-dismiss="modal" aria-hidden="true">×</a>
|
||||
<h3>{{ _('Move File') }}</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-vertical" action="javascript:void(0)">
|
||||
<div class="control-group" data-bind="css: {error: moveError().length > 0}">
|
||||
<label class="control-label">{{ _('Select destination folder for ') }}<span data-bind="text: moveSource().display"/></label>
|
||||
<div class="controls">
|
||||
<select class="input-block-level" data-bind="value: moveDestination, options: folderList"></select>
|
||||
<span class="help-block"><small data-bind="text: moveError, visible: moveError().length > 0" style="display: none;"></small></span>
|
||||
</div>
|
||||
</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 ($root.enableMove()) { $root.moveFile() } }, enabled: $root.enableMove(), css: {disabled: !$root.enableMove()}"><i class="fa fa-spinner fa-spin" data-bind="visible: movingFile"></i> {{ _('Move') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -23,6 +23,7 @@
|
||||
<div class="btn-group action-buttons">
|
||||
<div class="btn btn-mini toggleAdditionalData" data-bind="click: function() { if ($root.enableAdditionalData($data)) { $root.toggleAdditionalData($data); } else { return; } }, css: { disabled: !$root.enableAdditionalData($data) }" title="{{ _('Additional data')|edq }}"><i class="fa fa-chevron-down"></i></div>
|
||||
<a class="btn btn-mini" data-bind="visible: $root.loginState.hasPermissionKo($root.access.permissions.FILES_DOWNLOAD), attr: {href: $root.downloadLink($data)}, css: {disabled: !$root.downloadLink($data)}" title="{{ _('Download')|edq }}"><i class="fa fa-download"></i></a>
|
||||
<div class="btn btn-mini" data-bind="visible: $root.loginState.hasPermissionKo($root.access.permissions.FILES_MOVE), click: function(data, event) { if ($root.enableMove($data)) { $root.showMoveFileDialog($data, event); } else { return; } }, css: {disabled: !$root.enableMove($data)}" title="{{ _('Move')|edq }}"><i class="fa fa-arrow-right"></i></div>
|
||||
<div class="btn btn-mini" data-bind="visible: $root.loginState.hasPermissionKo($root.access.permissions.FILES_DELETE), click: function(data, event) { if ($root.enableRemove($data)) { $root.removeFile($data, event); } else { return; } }, css: {disabled: !$root.enableRemove($data)}" title="{{ _('Remove')|edq }}"><i class="fa fa-trash-o"></i></div>
|
||||
<div class="btn btn-mini" data-bind="visible: $root.loginState.hasPermissionKo($root.access.permissions.FILES_SELECT), click: function() { if ($root.enableSelect($data)) { $root.loadFile($data, false); } else { return; } }, css: {disabled: !$root.enableSelect($data)}" title="{{ _('Load')|edq }}"><i class="fa fa-folder-open"></i></div>
|
||||
<div class="btn btn-mini" data-bind="visible: $root.loginState.hasPermissionKo($root.access.permissions.PRINT), click: function() { if ($root.enableSelectAndPrint($data)) { $root.loadFile($data, true); } else { return; } }, css: {disabled: !$root.enableSelectAndPrint($data)}" title="{{ _('Load and Print')|edq }}"><i class="fa fa-print"></i></div>
|
||||
|
||||
Reference in new issue
Block a user