Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/stochss/stochss into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
BryanRumsey committed Jun 1, 2021
2 parents 2d586d6 + 530a979 commit 02fa237
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 88 deletions.
108 changes: 86 additions & 22 deletions client/pages/file-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ let FileBrowser = PageView.extend({
'click [data-hook=file-browser-help]' : function () {
let modal = $(modals.operationInfoModalHtml('file-browser')).modal();
},
'click [data-hook=empty-trash]' : 'emptyTrash'
},
initialize: function (attrs, options) {
PageView.prototype.initialize.apply(this, arguments)
Expand Down Expand Up @@ -78,7 +79,10 @@ let FileBrowser = PageView.extend({
if(op === 'move_node' && more && more.ref && more.ref.type && !(more.ref.type == 'folder' || more.ref.type == 'root')){
return false
}
if(op === 'move_node' && more && more.ref && more.ref.type && more.ref.type === 'folder'){
if(op === 'move_node' && more && more.ref && more.ref.original && path.dirname(more.ref.original._path).split("/").includes("trash")){
return false
}
if(op === 'move_node' && more && more.ref && more.ref.type && more.ref.type === 'folder' && more.ref.text !== "trash"){
if(!more.ref.state.loaded){
return false
}
Expand Down Expand Up @@ -110,6 +114,11 @@ let FileBrowser = PageView.extend({
node.original._path = path.join(newDir, file);
if(node.type === "folder") {
$('#models-jstree').jstree().refresh_node(node);
}else if(newDir.endsWith("trash")) {
$(self.queryByHook('empty-trash')).prop('disabled', false);
$('#models-jstree').jstree().refresh_node(par);
}else if(oldPath.split("/").includes("trash")) {
$('#models-jstree').jstree().refresh_node(par);
}
},
error: function (err, response, body) {
Expand Down Expand Up @@ -763,7 +772,6 @@ let FileBrowser = PageView.extend({
if(o && o.original && o.original.type !== "root"){
parentPath = o.original._path
}
console.log(parentPath)
if(isModel) {
let ext = isSpatial ? ".smdl" : ".mdl"
let modelName = o && o.type === "project" ? input.value.trim().split("/").pop() + ext : input.value.trim() + ext;
Expand Down Expand Up @@ -853,6 +861,43 @@ let FileBrowser = PageView.extend({
}
});
},
moveToTrash: function (o) {
if(document.querySelector('#moveToTrashConfirmModal')) {
document.querySelector('#moveToTrashConfirmModal').remove();
}
let self = this;
let modal = $(modals.moveToTrashConfirmHtml("model")).modal();
let yesBtn = document.querySelector('#moveToTrashConfirmModal .yes-modal-btn');
yesBtn.addEventListener('click', function (e) {
modal.modal('hide');
let queryStr = "?srcPath=" + o.original._path + "&dstPath=" + path.join("trash", o.text)
let endpoint = path.join(app.getApiPath(), "file/move") + queryStr
app.getXHR(endpoint, {
always: function (err, response, body) {
$(self.queryByHook('empty-trash')).prop('disabled', false);
$('#models-jstree').jstree().refresh();
}
});
});
},
emptyTrash: function (e) {
if(document.querySelector("#emptyTrashConfirmModal")) {
document.querySelector("#emptyTrashConfirmModal").remove()
}
let self = this;
let modal = $(modals.emptyTrashConfirmHtml()).modal();
let yesBtn = document.querySelector('#emptyTrashConfirmModal .yes-modal-btn');
yesBtn.addEventListener('click', function (e) {
modal.modal('hide');
let endpoint = path.join(app.getApiPath(), "file/empty-trash") + "?path=trash";
app.getXHR(endpoint, {
success: function (err, response, body) {
self.refreshJSTree();
$(self.queryByHook('empty-trash')).prop('disabled', true);
}
});
});
},
setupJstree: function () {
var self = this;
$.jstree.defaults.contextmenu.items = (o, cb) => {
Expand Down Expand Up @@ -898,6 +943,17 @@ let FileBrowser = PageView.extend({
self.duplicateFileOrDirectory(o, null)
}
},
"MoveToTrash" : {
"label" : "Move To Trash",
"_disabled" : false,
"separator_before" : false,
"separator_after" : false,
"action" : function (data) {
self.moveToTrash(o);
}
}
}
let delete_node = {
"Delete" : {
"label" : "Delete",
"_disabled" : false,
Expand Down Expand Up @@ -1261,6 +1317,12 @@ let FileBrowser = PageView.extend({
if (o.type === 'root'){
return folder
}
if (o.text === "trash") {
return {"Refresh": folder.Refresh}
}
if (o.original._path.split("/")[0] === "trash") {
return delete_node
}
if (o.type === 'folder') {
return $.extend(folder, common)
}
Expand Down Expand Up @@ -1319,26 +1381,28 @@ let FileBrowser = PageView.extend({
var file = e.target.text
var node = $('#models-jstree').jstree().get_node(e.target)
var _path = node.original._path;
if(file.endsWith('.mdl') || file.endsWith('.smdl')){
window.location.href = path.join(app.getBasePath(), "stochss/models/edit")+"?path="+_path;
}else if(file.endsWith('.ipynb')){
var notebookPath = path.join(app.getBasePath(), "notebooks", _path)
window.open(notebookPath, '_blank')
}else if(file.endsWith('.sbml')){
var openPath = path.join(app.getBasePath(), "edit", _path)
window.open(openPath, '_blank')
}else if(file.endsWith('.proj')){
window.location.href = path.join(app.getBasePath(), "stochss/project/manager")+"?path="+_path;
}else if(file.endsWith('.wkfl')){
window.location.href = path.join(app.getBasePath(), "stochss/workflow/edit")+"?path="+_path+"&type=none";
}else if(file.endsWith('.domn')) {
let queryStr = "?domainPath=" + _path
window.location.href = path.join(app.getBasePath(), "stochss/domain/edit") + queryStr
}else if(node.type === "folder" && $('#models-jstree').jstree().is_open(node) && $('#models-jstree').jstree().is_loaded(node)){
$('#models-jstree').jstree().refresh_node(node)
}else if(node.type === "other"){
var openPath = path.join(app.getBasePath(), "view", _path);
window.open(openPath, "_blank");
if(!(_path.split("/")[0] === "trash")) {
if(file.endsWith('.mdl') || file.endsWith('.smdl')){
window.location.href = path.join(app.getBasePath(), "stochss/models/edit")+"?path="+_path;
}else if(file.endsWith('.ipynb')){
var notebookPath = path.join(app.getBasePath(), "notebooks", _path)
window.open(notebookPath, '_blank')
}else if(file.endsWith('.sbml')){
var openPath = path.join(app.getBasePath(), "edit", _path)
window.open(openPath, '_blank')
}else if(file.endsWith('.proj')){
window.location.href = path.join(app.getBasePath(), "stochss/project/manager")+"?path="+_path;
}else if(file.endsWith('.wkfl')){
window.location.href = path.join(app.getBasePath(), "stochss/workflow/edit")+"?path="+_path+"&type=none";
}else if(file.endsWith('.domn')) {
let queryStr = "?domainPath=" + _path
window.location.href = path.join(app.getBasePath(), "stochss/domain/edit") + queryStr
}else if(node.type === "folder" && $('#models-jstree').jstree().is_open(node) && $('#models-jstree').jstree().is_loaded(node)){
$('#models-jstree').jstree().refresh_node(node)
}else if(node.type === "other"){
var openPath = path.join(app.getBasePath(), "view", _path);
window.open(openPath, "_blank");
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion client/pages/project-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ let ProjectManager = PageView.extend({
let yesBtn = document.querySelector('#emptyTrashConfirmModal .yes-modal-btn');
yesBtn.addEventListener('click', function (e) {
modal.modal('hide');
let endpoint = path.join(app.getApiPath(), "project/empty-trash")+"?path="+path.join(self.model.directory, "trash");
let endpoint = path.join(app.getApiPath(), "file/empty-trash")+"?path="+path.join(self.model.directory, "trash");
app.getXHR(endpoint, {
success: function (err, response, body) {
$(self.queryByHook('empty-project-trash')).prop('disabled', true);
Expand Down
4 changes: 3 additions & 1 deletion client/templates/pages/fileBrowser.pug
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ section.page

button.btn.btn-primary.box-shadow(id="options-for-node" data-hook="options-for-node" disabled) Actions

button.btn.btn-primary.inline.box-shadow(id="refresh-jstree" data-hook="refresh-jstree") Refresh
button.btn.btn-primary.inline.box-shadow(id="refresh-jstree" data-hook="refresh-jstree") Refresh

button.btn.btn-primary.inline.box-shadow(id="empty-trash" data-hook="empty-trash") Empty Trash
15 changes: 8 additions & 7 deletions client/views/edit-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,25 @@ let template = require('../templates/includes/editProject.pug');
module.exports = View.extend({
template: template,
events: {
'click [data-hook=remove-project-btn]' : 'handleRemoveProjectClick'
'click [data-hook=remove-project-btn]' : 'handleMoveToTrash'
},
initialize: function (attrs, options) {
View.prototype.initialize.apply(this, arguments);
},
render: function (attrs, options) {
View.prototype.render.apply(this, arguments);
},
handleRemoveProjectClick: function (e) {
if(document.querySelector('#deleteFileModal')) {
document.querySelector('#deleteFileModal').remove();
handleMoveToTrash: function (e) {
if(document.querySelector('#moveToTrashConfirmModal')) {
document.querySelector('#moveToTrashConfirmModal').remove();
}
let self = this;
let endpoint = path.join(app.getApiPath(), "file/delete")+"?path="+this.model.directory;
let modal = $(modals.deleteFileHtml("project")).modal();
let yesBtn = document.querySelector('#deleteFileModal .yes-modal-btn');
let modal = $(modals.moveToTrashConfirmHtml("model")).modal();
let yesBtn = document.querySelector('#moveToTrashConfirmModal .yes-modal-btn');
yesBtn.addEventListener('click', function (e) {
modal.modal('hide');
let queryStr = "?srcPath=" + self.model.directory + "&dstPath=" + path.join("trash", self.model.directory.split("/").pop());
let endpoint = path.join(app.getApiPath(), "file/move") + queryStr
app.getXHR(endpoint, {
success: function (err, response, body) {
self.model.collection.remove(self.model);
Expand Down
44 changes: 23 additions & 21 deletions client/views/file-browser-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ module.exports = View.extend({
if (o.text === "trash"){
return refresh
}
if (o.original._path.includes("trash")) {
if (o.original._path.includes(".proj/trash/")) {
return {"Delete": common.Delete}
}
if (o.type === 'folder') {
Expand Down Expand Up @@ -1441,26 +1441,28 @@ module.exports = View.extend({
var file = e.target.text
var node = $('#models-jstree-view').jstree().get_node(e.target)
var _path = node.original._path;
if(file.endsWith('.mdl') || file.endsWith('.smdl')){
window.location.href = path.join(app.getBasePath(), "stochss/models/edit")+"?path="+_path;
}else if(file.endsWith('.ipynb')){
var notebookPath = path.join(app.getBasePath(), "notebooks", _path)
window.open(notebookPath, '_blank')
}else if(file.endsWith('.sbml')){
var openPath = path.join(app.getBasePath(), "edit", _path)
window.open(openPath, '_blank')
}else if(file.endsWith('.proj')){
window.location.href = path.join(app.getBasePath(), "stochss/project/manager")+"?path="+_path;
}else if(file.endsWith('.wkfl')){
window.location.href = path.join(app.getBasePath(), "stochss/workflow/edit")+"?path="+_path+"&type=none";
}else if(file.endsWith('.domn')) {
let queryStr = "?domainPath=" + _path
window.location.href = path.join(app.getBasePath(), "stochss/domain/edit") + queryStr
}else if(node.type === "folder" && $('#models-jstree-view').jstree().is_open(node) && $('#models-jstree-view').jstree().is_loaded(node)){
$('#models-jstree-view').jstree().refresh_node(node)
}else if(node.type === "other"){
var openPath = path.join(app.getBasePath(), "view", _path);
window.open(openPath, "_blank");
if(!_path.includes(".proj/trash/")){
if(file.endsWith('.mdl') || file.endsWith('.smdl')){
window.location.href = path.join(app.getBasePath(), "stochss/models/edit")+"?path="+_path;
}else if(file.endsWith('.ipynb')){
var notebookPath = path.join(app.getBasePath(), "notebooks", _path)
window.open(notebookPath, '_blank')
}else if(file.endsWith('.sbml')){
var openPath = path.join(app.getBasePath(), "edit", _path)
window.open(openPath, '_blank')
}else if(file.endsWith('.proj')){
window.location.href = path.join(app.getBasePath(), "stochss/project/manager")+"?path="+_path;
}else if(file.endsWith('.wkfl')){
window.location.href = path.join(app.getBasePath(), "stochss/workflow/edit")+"?path="+_path+"&type=none";
}else if(file.endsWith('.domn')) {
let queryStr = "?domainPath=" + _path
window.location.href = path.join(app.getBasePath(), "stochss/domain/edit") + queryStr
}else if(node.type === "folder" && $('#models-jstree-view').jstree().is_open(node) && $('#models-jstree-view').jstree().is_loaded(node)){
$('#models-jstree-view').jstree().refresh_node(node)
}else if(node.type === "other"){
var openPath = path.join(app.getBasePath(), "view", _path);
window.open(openPath, "_blank");
}
}
});
})
Expand Down
2 changes: 1 addition & 1 deletion stochss/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_page_handlers(route_start):
(r"/stochss/api/file/upload\/?", UploadFileAPIHandler),
(r"/stochss/api/file/upload-from-link\/?", UploadFileFromLinkAPIHandler),
(r"/stochss/api/file/move\/?", MoveFileAPIHandler),
(r"/stochss/api/file/empty-trash\/?", EmptyTrashAPIHandler),
(r"/stochss/api/file/delete\/?", DeleteFileAPIHandler),
(r"/stochss/api/file/rename\/?", RenameAPIHandler),
(r"/stochss/api/file/download\/?", DownloadAPIHandler),
Expand Down Expand Up @@ -88,7 +89,6 @@ def get_page_handlers(route_start):
(r"/stochss/api/project/add-existing-model\/?", AddExistingModelAPIHandler),
(r"/stochss/api/project/extract-model\/?", ExtractModelAPIHandler),
(r"/stochss/api/project/extract-workflow\/?", ExtractWorkflowAPIHandler),
(r"/stochss/api/project/empty-trash\/?", EmptyTrashAPIHandler),
(r"/stochss/api/project/export-combine\/?", ExportAsCombineAPIHandler),
(r"/stochss/api/project/meta-data\/?", ProjectMetaDataAPIHandler),
(r"/stochss/api/project/save-annotation\/?", UpdateAnnotationAPIHandler),
Expand Down
29 changes: 29 additions & 0 deletions stochss/handlers/file_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,35 @@ async def get(self):
self.finish()


class EmptyTrashAPIHandler(APIHandler):
'''
##############################################################################
Handler for a projects trash directory
##############################################################################
'''
@web.authenticated
def get(self):
'''
Empty the trash directory.
Attributes
----------
'''
self.set_header('Content-Type', 'application/json')
path = self.get_query_argument(name="path")
log.debug("Path to the trash directory: %s", path)
try:
log.info("Emptying the trash")
folder = StochSSFolder(path=path)
resp = folder.empty()
log.debug("Response message: %s", resp)
log.info("Successfully emptied the trash")
self.write(resp)
except StochSSAPIError as err:
report_error(self, log, err)
self.finish()


class DeleteFileAPIHandler(APIHandler):
'''
################################################################################################
Expand Down
6 changes: 4 additions & 2 deletions stochss/handlers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ async def get(self):
self.set_header('Content-Type', 'application/json')
try:
folder = StochSSFolder(path="")
resp = folder.get_file_list(ext=".domn")
test = lambda ext, root, file: bool("trash" in root.split("/"))
resp = folder.get_file_list(ext=".domn", test=test)
log.debug("Response: %s", resp)
self.write(resp)
except StochSSAPIError as err:
Expand All @@ -340,7 +341,8 @@ async def get(self):
self.set_header('Content-Type', 'application/json')
try:
folder = StochSSFolder(path="")
resp = folder.get_file_list(ext=".txt")
test = lambda ext, root, file: bool("trash" in root.split("/"))
resp = folder.get_file_list(ext=".txt", test=test)
log.debug("Response: %s", resp)
self.write(resp)
except StochSSAPIError as err:
Expand Down
31 changes: 1 addition & 30 deletions stochss/handlers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def get(self):
folder = StochSSFolder(path="")
# file will be excluded if test passes
test = lambda ext, root, file: bool(".wkfl" in root or f"{path}" in root or \
"trash" in root)
"trash" in root.split("/"))
data = folder.get_file_list(ext=[".mdl", ".smdl"], test=test)
log.debug("List of models: %s", data)
self.write(data)
Expand Down Expand Up @@ -276,35 +276,6 @@ def get(self):
self.finish()


class EmptyTrashAPIHandler(APIHandler):
'''
##############################################################################
Handler for a projects trash directory
##############################################################################
'''
@web.authenticated
def get(self):
'''
Empty the trash directory.
Attributes
----------
'''
self.set_header('Content-Type', 'application/json')
path = self.get_query_argument(name="path")
log.debug("Path to the trash directory: %s", path)
try:
log.info("Emptying the trash")
folder = StochSSFolder(path=path)
resp = folder.empty()
log.debug("Response message: %s", resp)
log.info("Successfully emptied the trash")
self.write(resp)
except StochSSAPIError as err:
report_error(self, log, err)
self.finish()


class ProjectMetaDataAPIHandler(APIHandler):
'''
##############################################################################
Expand Down
2 changes: 2 additions & 0 deletions stochss/handlers/util/stochss_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def get_new_path(self, dst_path):
New path for the file object from the users home directory
'''
new_path = os.path.join(self.user_dir, dst_path)
if dst_path.startswith("trash/") and not "trash" in os.listdir(self.user_dir):
os.mkdir(os.path.join(self.user_dir, "trash"))
if new_path.split().pop().replace('.', '', 5).isdigit():
return new_path.replace(new_path.split().pop(), "").strip()
if "trash/" in new_path and os.path.exists(new_path):
Expand Down
Loading

0 comments on commit 02fa237

Please sign in to comment.