Commit e2c76244 authored by murban's avatar murban
Browse files

Updates in filesystem: get_file_list now returns an object and removal of some expandvars / ..user

parent ae7c93da
......@@ -86,6 +86,7 @@ class FSAjaxController(AbstractController):
# get the files with the filter
files = fs.get_file_list(
path, deep=deep, filter=filter, reverse=reverse)
rjson = vispa.rpc.get(cherrypy.request.user, cherrypy.request.workspace).getmodule("json")
cherrypy.response.headers['Content-Type'] = "application/json"
return rjson.dumps(files)
......
......@@ -22,7 +22,6 @@ class FileBrowserExtension(AbstractExtension):
self.js(platform, 'js/extension.js')
self.js(platform, 'js/browser.js')
self.js(platform, 'js/view.js')
self.js(platform, 'js/ajax.js')
self.js(platform, 'js/actions.js')
self.css(platform, 'css/styles.css')
self.remote()
\ No newline at end of file
......@@ -29,4 +29,5 @@ var FileBrowserActions = FileBaseActions.extend({
url = encodeURI(url.slice(0,url.lastIndexOf("="))+"="+data.path);
$.Helpers.changeUrl(url);
}
});
\ No newline at end of file
});
var FileBrowserAjaxHandler = FileBaseAjaxHandler.extend({
init: function(owner) {
this._super(owner);
}
});
\ No newline at end of file
......@@ -9,7 +9,6 @@ var FileBrowser = FileBase.extend({
this.instance = instance;
this.view = new FileBrowserView(this);
this.ajax = new FileBrowserAjaxHandler(this);
this.actions = new FileBrowserActions(this);
// variables that may change in this workflow
......
......@@ -70,7 +70,8 @@ class FileSystem(object):
def get_file_list(self, path, deep=False, filter=[], reverse=False, hide_hidden=True):
filelist = []
for elem in os.listdir(os.path.expanduser(os.path.expandvars(path))):
path_expand = os.path.expanduser(os.path.expandvars(path))
for elem in os.listdir(path_expand):
# hide hidden files?
if elem.startswith('.') and hide_hidden:
continue
......@@ -83,22 +84,26 @@ class FileSystem(object):
if match != reverse:
continue
fullpath = os.path.join(path, elem)
fullpath = os.path.join(path_expand, elem)
# get locales, mtime, etc
locale.setlocale(locale.LC_ALL, '')
stats = os.stat(os.path.expanduser(os.path.expandvars(fullpath)))
stats = os.stat(path_expand)
size = locale.format('%d', stats.st_size, grouping=True)
mtime = datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S')
if os.path.isdir(os.path.expanduser(os.path.expandvars(fullpath))):
if os.path.isdir(fullpath):
filelist.append({'name': elem, 'type': 'd', 'parent': path, 'extension': '', 'mtime': mtime, 'size': size, 'path': fullpath})
if deep:
filelist.extend(self.get_file_list(fullpath, deep, filter, reverse))
else:
extension = elem.split('.')[-1]
filelist.append({'name': elem, 'type': 'f', 'parent': path, 'extension': extension, 'mtime': mtime, 'size': size, 'path': fullpath})
return filelist
# Determine the parent
parentpath = path_expand[:-1] if path_expand.endswith(os.sep) and path_expand!=os.sep else path_expand
parentpath = os.path.dirname(path_expand)
return {'filelist': filelist, 'parentpath': parentpath}
def get_suggestions(self, path, length=1, append_hidden=True):
suggestions = []
......
var FileBaseAjaxHandler = Class.extend({
init: function(owner) {
this.owner = owner;
},
exists: function(path) {
var exists = false;
var promise = $.ajax({
type: 'POST',
async: false,
url: this.owner.urlFormatter('ajax/fs/exists'),
data: {
path: path
}
});
$.when(promise).then(function(response) {
if (response.success) {
exists = true;
} else {
// TODO
}
});
return exists;
},
fileList: function(path) {
var list = [];
var promise = $.ajax({
type: 'POST',
async: false,
url: this.owner.urlFormatter('ajax/fs/filelist'),
data: {
path: path
}
});
$.when(promise).then(function(response) {
if (response.success) {
list = response.files;
} else {
// TODO
}
});
return list;
},
folderup: function(path) {
var folderup_path = "";
var promise = $.ajax({
type: 'POST',
async: false,
url: this.owner.urlFormatter('ajax/fs/folderup'),
data: {
path: path
}
});
$.when(promise).then(function(response) {
if (response.success) {
folderup_path = response.folderuppath;
} else {
console.log("Error in AJAX");
}
});
return folderup_path;
}
});
\ No newline at end of file
......@@ -3,7 +3,7 @@ var FileBase = Class.extend({
init: function(path, urlFormatter) {
// components
this.view = new FileBaseView(this);
this.ajax = new FileBaseAjaxHandler(this);
// this.ajax = new FileBaseAjaxHandler(this);
this.events = new FileBaseEvents(this);
this.actions = new FileBaseActions(this);
......
......@@ -34,7 +34,7 @@ var Symbolview = Class.extend({
//empty the existing container
_this.owner.view.mainContainer.html("");
var folderupPath = _this.owner.ajax.folderup(_this.owner.workflow.path);
var folderupPath = data.parentpath;
var folderupData = {
"extension": "",
"mtime": "",
......@@ -47,8 +47,7 @@ var Symbolview = Class.extend({
var folderup = _this.makeIcon(folderupData);
_this.owner.view.mainContainer.append(folderup);
$.each(data, function(i, file) {
// console.log(file)
$.each(data.filelist, function(i, file) {
var contentdiv = _this.makeIcon(file);
// owner.view.mainContainer.isotope('insert', contentdiv);
......
var FileSelector = FileBase.extend({
init: function(instance, path) {
// use urlHandler.dynamic as urlFormatter
var formatter = function(path) {
return instance._vispa.urlHandler.dynamic(path);
}
this._super(path, formatter);
}
})
\ No newline at end of file
......@@ -73,7 +73,6 @@
"helpers.js",
"file/filebase/base.js",
"file/filebase/view.js",
"file/filebase/ajax.js",
"file/filebase/events.js",
"file/filebase/actions.js",
"file/filebase/views/symbol/view.js",
......
Supports Markdown
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