Commit 93e7b9bc authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Fix loader state when there are many items, fix #1531.

parent c610aa95
......@@ -83,6 +83,19 @@ class FSAjaxController(AbstractController):
else:
return "Failed"
@cherrypy.expose
@cherrypy.tools.ajax()
def filecount(self, path):
self.release_session()
fs = self.get('fs')
self.release_database()
count = fs.get_file_count(path)
if count < 0:
raise MessageException("%s does not exist" % path)
else:
return {"count": count}
@cherrypy.expose
@cherrypy.tools.ajax(encoded=True)
def filelist(self, path, deep=False, filefilter=None, reverse=False):
......
......@@ -49,42 +49,47 @@ var FileBase = Class.extend({
updateView: function() {
var self = this;
self.instance.setLoading(true, 30);
// remove the links needed for the preview lightbox
$("a[data-lightbox=" + this.view.previewBoxID + "]").remove();
if (self.workflow.lastRefresh === null || $.now() - self.workflow.lastRefresh > 500) {
// Check if last request is less than one second away
var promise = this.instance.GET("/ajax/fs/filelist", {
"path": this.workflow.path,
});
self.workflow.lastRefresh = $.now();
if (this.view.fileContentContainer !== null) {
self.selections.unselectAll()
this.view.fileContentContainer.empty();
};
promise.done(function(content) {
if (content.filelist.length < 10) {
self.instance.setLoading(false);
}
this.instance.GET("/ajax/fs/filecount", {
path: this.workflow.path
}).done(function(res) {
self.instance.setLoading(true, res.count > 50 ? 0 : null);
// Check if last request is less than one second away
var promise = self.instance.GET("/ajax/fs/filelist", {
"path": self.workflow.path
});
self.workflow.lastRefresh = $.now();
if (Object.keys(content.filelist).length == 1 && content.filelist[0].warning !==
undefined) {
self.instance.alert(content.filelist[0].warning);
vispa.messenger.error(content.filelist[0].warning);
content.filelist = [];
}
self.refresh(content);
self.instance.setLoading(false)
if (self.view.fileContentContainer !== null) {
self.selections.unselectAll()
self.view.fileContentContainer.empty();
};
promise.done(function(content) {
self.workflow.lastRefresh = $.now();
if (Object.keys(content.filelist).length == 1 && content.filelist[0].warning !==
undefined) {
self.instance.alert(content.filelist[0].warning);
vispa.messenger.error(content.filelist[0].warning);
content.filelist = [];
}
self.refresh(content);
}).fail(function(err) {
self.instance.setLoading(false);
});
});
} else {
this.instance.setLoading(false);
}
},
refresh: function(content, sort, reverse, filter) {
var self = this;
if (!content) {
return this;
return;
}
sort = sort === undefined ? this.workflow.sort : sort;
reverse = reverse === undefined ? this.workflow.reverse : reverse;
......@@ -109,10 +114,8 @@ var FileBase = Class.extend({
}
this.helper.sortItems(content, sort, reverse);
this.workflow.currentView.setContent(content);
setTimeout(function() {
self.menuitems.hideMenu();
self.instance.setLabel(self.workflow.path, true);
}, 0);
this.menuitems.hideMenu();
this.instance.setLabel(this.workflow.path, true);
this.instance.setLoading(false);
}
});
\ No newline at end of file
......@@ -94,6 +94,13 @@ class FileSystem(object):
return None
return target_type if target_type == type else None
def get_file_count(self, path):
path = self.expand(path)
if os.path.exists(path):
return len(os.listdir(path))
else:
return -1
def get_file_list(self, path, deep=False,
filter=None, reverse=False,
hide_hidden=True, encode_json=True):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment