Renaming and Refactoring
This commit is contained in:
parent
0dacfcdf8d
commit
95bcccb84c
5 changed files with 44 additions and 38 deletions
|
|
@ -479,7 +479,7 @@ class LocalFileStorage(StorageInterface):
|
|||
import shutil
|
||||
shutil.rmtree(folder_path)
|
||||
|
||||
def _copyMove1(self, source, destination):
|
||||
def _copyMove(self, source, destination):
|
||||
sourcepath, sourcename = self.sanitize(source)
|
||||
destinationpath, destinationname = self.sanitize(destination)
|
||||
|
||||
|
|
@ -503,8 +503,8 @@ class LocalFileStorage(StorageInterface):
|
|||
)
|
||||
return sourceObj, destinationObj
|
||||
|
||||
def _copyMove2(self, source, destination):
|
||||
sourceObj, destinationObj = self._copyMove1(source, destination)
|
||||
def _copyMoveWithMetadata(self, source, destination):
|
||||
sourceObj, destinationObj = self._copyMove(source, destination)
|
||||
|
||||
if not os.path.isfile(sourceObj["fullpath"]):
|
||||
raise RuntimeError("%s in %s is not a file" % (sourceObj["name"], sourceObj["path"]))
|
||||
|
|
@ -522,7 +522,7 @@ class LocalFileStorage(StorageInterface):
|
|||
return sourceObj, destinationObj
|
||||
|
||||
def copy_folder(self, source, destination):
|
||||
sourceObj, destinationObj = self._copyMove1(source, destination)
|
||||
sourceObj, destinationObj = self._copyMove(source, destination)
|
||||
|
||||
if not os.path.isdir(sourceObj["fullpath"]):
|
||||
raise RuntimeError("%s in %s is not a folder" % (sourceObj["name"], sourceObj["path"]))
|
||||
|
|
@ -533,7 +533,7 @@ class LocalFileStorage(StorageInterface):
|
|||
raise RuntimeError("Could not copy %s in %s to %s in %s" % (sourceObj["name"], sourceObj["path"], destinationObj["name"], destinationObj["path"]), e)
|
||||
|
||||
def move_folder(self, source, destination):
|
||||
sourceObj, destinationObj = self._copyMove1(source, destination)
|
||||
sourceObj, destinationObj = self._copyMove(source, destination)
|
||||
|
||||
if not os.path.isdir(sourceObj["fullpath"]):
|
||||
raise RuntimeError("%s in %s is not a folder" % (sourceObj["name"], sourceObj["path"]))
|
||||
|
|
@ -619,7 +619,7 @@ class LocalFileStorage(StorageInterface):
|
|||
self._save_metadata(path, metadata)
|
||||
|
||||
def copy_file(self, source, destination):
|
||||
sourceObj, destinationObj = self._copyMove2(source, destination)
|
||||
sourceObj, destinationObj = self._copyMoveWithMetadata(source, destination)
|
||||
|
||||
try:
|
||||
shutil.copy2(sourceObj["fullpath"], destinationObj["fullpath"])
|
||||
|
|
@ -632,7 +632,7 @@ class LocalFileStorage(StorageInterface):
|
|||
self._save_metadata(destinationObj["path"], destinationObj["metadata"])
|
||||
|
||||
def move_file(self, source, destination, allow_overwrite=False):
|
||||
sourceObj, destinationObj = self._copyMove2(source, destination)
|
||||
sourceObj, destinationObj = self._copyMoveWithMetadata(source, destination)
|
||||
|
||||
try:
|
||||
shutil.move(sourceObj["fullpath"], destinationObj["fullpath"])
|
||||
|
|
|
|||
|
|
@ -271,10 +271,12 @@ $(function() {
|
|||
},
|
||||
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
|
||||
setTimeout(function() {
|
||||
if (element.nodeName == "#comment")
|
||||
if (element.nodeName == "#comment") {
|
||||
// foreach is bound to a virtual element
|
||||
$(element.parentElement).slimScroll({scrollBy: 0});
|
||||
else
|
||||
} else {
|
||||
$(element).slimScroll({scrollBy: 0});
|
||||
}
|
||||
}, 10);
|
||||
return ko.bindingHandlers.foreach.update(element, valueAccessor(), allBindings, viewModel, bindingContext);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,6 +118,22 @@ $(function() {
|
|||
return _.filter(self.listHelper.paginatedItems(), filter);
|
||||
});
|
||||
|
||||
self.filesAndFolders = ko.dependentObservable(function() {
|
||||
var style = self.listStyle();
|
||||
if (style == "folders_files" || style == "files_folders") {
|
||||
var files = self.filesOnlyList();
|
||||
var folders = self.foldersOnlyList();
|
||||
|
||||
if (style == "folders_files") {
|
||||
return folders.concat(files);
|
||||
} else {
|
||||
return files.concat(folders);
|
||||
}
|
||||
} else {
|
||||
return self.listHelper.paginatedItems();
|
||||
}
|
||||
});
|
||||
|
||||
self.isLoadActionPossible = ko.computed(function() {
|
||||
return self.loginState.isUser() && !self.isPrinting() && !self.isPaused() && !self.isLoading();
|
||||
});
|
||||
|
|
@ -214,6 +230,12 @@ $(function() {
|
|||
self.listHelper.updateItems(data.children);
|
||||
};
|
||||
|
||||
self.navigateUp = function() {
|
||||
var path = self.currentPath().split("/");
|
||||
path.pop();
|
||||
self.changeFolderByPath(path.join("/"));
|
||||
};
|
||||
|
||||
self.changeFolderByPath = function(path) {
|
||||
var element = OctoPrint.files.elementByPath(path, { children: self.allItems() });
|
||||
if (element) {
|
||||
|
|
|
|||
|
|
@ -2,32 +2,10 @@
|
|||
<input type="text" class="input-block search-query" data-bind="value: searchQuery, valueUpdate: 'input'" placeholder="{{ _('Search...') }}">
|
||||
</form>
|
||||
<div class="gcode_files">
|
||||
<!-- ko if: currentPath() != "" -->
|
||||
<div class="entry" data-bind="click: function() { var path = $root.currentPath().split('/'); path.pop(); $root.changeFolderByPath(path.join('/')); }"><i class="icon-arrow-left"></i> {{ _('Back') }}</div>
|
||||
<!-- /ko -->
|
||||
<div class="entry" data-bind="visible: currentPath() != '', click: function() { $root.navigateUp(); }" style="display: none"><i class="icon-arrow-left"></i> {{ _('Back') }}</div>
|
||||
|
||||
<!-- ko if: listStyle() == 'folders_files' -->
|
||||
<!-- ko slimScrolledForeach: foldersOnlyList -->
|
||||
<div class="entry" data-bind="attr: { id: $root.getEntryId($data) }, template: { name: $root.templateFor($data), data: $data }"></div>
|
||||
<!-- /ko -->
|
||||
<!-- ko slimScrolledForeach: filesOnlyList -->
|
||||
<div class="entry" data-bind="attr: { id: $root.getEntryId($data) }, template: { name: $root.templateFor($data), data: $data }"></div>
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
|
||||
<!-- ko if: listStyle() == 'files_folders' -->
|
||||
<!-- ko slimScrolledForeach: filesOnlyList -->
|
||||
<div class="entry" data-bind="attr: { id: $root.getEntryId($data) }, template: { name: $root.templateFor($data), data: $data }"></div>
|
||||
<!-- /ko -->
|
||||
<!-- ko slimScrolledForeach: foldersOnlyList -->
|
||||
<div class="entry" data-bind="attr: { id: $root.getEntryId($data) }, template: { name: $root.templateFor($data), data: $data }"></div>
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
|
||||
<!-- ko if: listStyle() == 'mixed' -->
|
||||
<!-- ko slimScrolledForeach: listHelper.paginatedItems -->
|
||||
<div class="entry" data-bind="attr: { id: $root.getEntryId($data) }, template: { name: $root.templateFor($data), data: $data }"></div>
|
||||
<!-- /ko -->
|
||||
<!-- ko slimScrolledForeach: filesAndFolders -->
|
||||
<div class="entry" data-bind="attr: { id: $root.getEntryId($data) }, template: { name: $root.templateFor($data), data: $data }"></div>
|
||||
<!-- /ko -->
|
||||
|
||||
<script type="text/html" id="files_template_machinecode">
|
||||
|
|
|
|||
|
|
@ -3,13 +3,17 @@
|
|||
<span class="icon-wrench"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#" data-bind="click: function() { $root.listStyle('folders_files'); }"><i class="icon-ok" data-bind="style: {visibility: listStyle() == 'folders_files' ? 'visible' : 'hidden'}"></i> {{ _('Sort by Folders, Files') }}</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listStyle('files_folders'); }"><i class="icon-ok" data-bind="style: {visibility: listStyle() == 'files_folders' ? 'visible' : 'hidden'}"></i> {{ _('Sort by Files, Folders') }}</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listStyle('mixed'); }"><i class="icon-ok" data-bind="style: {visibility: listStyle() == 'mixed' ? 'visible' : 'hidden'}"></i> {{ _('Mixed') }}</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.changeSorting('name'); }"><i class="icon-ok" data-bind="style: {visibility: listHelper.currentSorting() == 'name' ? 'visible' : 'hidden'}"></i> {{ _('Sort by name') }} ({{ _('ascending') }})</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.changeSorting('upload'); }"><i class="icon-ok" data-bind="style: {visibility: listHelper.currentSorting() == 'upload' ? 'visible' : 'hidden'}"></i> {{ _('Sort by upload date') }} ({{ _('descending') }})</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.changeSorting('size'); }"><i class="icon-ok" data-bind="style: {visibility: listHelper.currentSorting() == 'size' ? 'visible' : 'hidden'}"></i> {{ _('Sort by file size') }} ({{ _('descending') }})</a></li>
|
||||
<li class="dropdown-submenu">
|
||||
<a href="#"><i class="icon-ok" style="visibility: hidden"></i> {{ _('Folders') }}</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#" data-bind="click: function() { $root.listStyle('folders_files'); }"><i class="icon-ok" data-bind="style: {visibility: listStyle() == 'folders_files' ? 'visible' : 'hidden'}"></i> {{ _('Sort by Folders, Files') }}</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listStyle('files_folders'); }"><i class="icon-ok" data-bind="style: {visibility: listStyle() == 'files_folders' ? 'visible' : 'hidden'}"></i> {{ _('Sort by Files, Folders') }}</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listStyle('mixed'); }"><i class="icon-ok" data-bind="style: {visibility: listStyle() == 'mixed' ? 'visible' : 'hidden'}"></i> {{ _('Mixed') }}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.toggleFilter('machinecode'); }"><i class="icon-ok" data-bind="style: {visibility: _.contains(listHelper.currentFilters(), 'machinecode') ? 'visible' : 'hidden'}"></i> {{ _('Only show GCode files') }}</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.toggleFilter('model'); }"><i class="icon-ok" data-bind="style: {visibility: _.contains(listHelper.currentFilters(), 'model') ? 'visible' : 'hidden'}"></i> {{ _('Only show STL files') }}</a></li>
|
||||
|
|
|
|||
Loading…
Reference in a new issue