mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -06:00
Remember the last used directory in the file manager. Fixes #1910
This commit is contained in:
parent
5d0a0e57e7
commit
8d71e888b4
@ -148,6 +148,11 @@ class FileManagerModule(PgAdminModule):
|
||||
gettext("Maximum file upload size (MB)"), 'integer', 50,
|
||||
category_label=gettext('Options')
|
||||
)
|
||||
self.last_directory_visited = self.preference.register(
|
||||
'options', 'last_directory_visited',
|
||||
gettext("Last directory visited"), 'text', '/',
|
||||
category_label=gettext('Options')
|
||||
)
|
||||
|
||||
|
||||
# Initialise the module
|
||||
@ -236,6 +241,14 @@ def delete_trans_id(trans_id):
|
||||
data={'status': True}
|
||||
)
|
||||
|
||||
@blueprint.route("/save_last_dir/<int:trans_id>", methods=["POST"])
|
||||
@login_required
|
||||
def save_last_directory_visited(trans_id):
|
||||
blueprint.last_directory_visited.set(req.json['path'])
|
||||
return make_json_response(
|
||||
data={'status': True}
|
||||
)
|
||||
|
||||
|
||||
class Filemanager(object):
|
||||
"""FileManager Class."""
|
||||
@ -299,9 +312,31 @@ class Filemanager(object):
|
||||
folders_only = False
|
||||
title = "Storage Manager"
|
||||
|
||||
# get last visited directory, if not present then traverse in reverse order
|
||||
# to find closest parent directory
|
||||
last_dir = blueprint.last_directory_visited.get()
|
||||
if storage_dir is None:
|
||||
if last_dir is None:
|
||||
last_dir = "/"
|
||||
else:
|
||||
if last_dir is not None:
|
||||
if len(last_dir) > 1 and last_dir.endswith('/'):
|
||||
last_dir = last_dir[:-1]
|
||||
while last_dir:
|
||||
if os.path.exists(storage_dir + last_dir):
|
||||
break;
|
||||
index = last_dir.rfind('/')
|
||||
last_dir = last_dir[0:index]
|
||||
if not last_dir:
|
||||
last_dir = "/"
|
||||
if not last_dir.endswith('/'):
|
||||
last_dir += "/"
|
||||
else:
|
||||
last_dir = "/"
|
||||
|
||||
# create configs using above configs
|
||||
configs = {
|
||||
"fileroot": "/",
|
||||
"fileroot": last_dir,
|
||||
"dialog_type": fm_type,
|
||||
"title": title,
|
||||
"upload": {
|
||||
@ -564,7 +599,10 @@ class Filemanager(object):
|
||||
Returns files and folders in give path
|
||||
"""
|
||||
trans_data = Filemanager.get_trasaction_selection(self.trans_id)
|
||||
dir = self.dir
|
||||
dir = self.dir if self.dir is not None else ''
|
||||
if not dir.endswith('/'):
|
||||
dir += '/';
|
||||
|
||||
filelist = self.list_filesystem(dir, path, trans_data, file_type)
|
||||
return filelist
|
||||
|
||||
|
@ -46,6 +46,15 @@ define([
|
||||
contentType: "application/json; charset=utf-8",
|
||||
});
|
||||
};
|
||||
|
||||
var set_last_traversed_dir = function(path, _url) {
|
||||
return $.ajax({
|
||||
url: _url,
|
||||
type: 'POST',
|
||||
data: JSON.stringify(path),
|
||||
contentType: 'application/json'
|
||||
});
|
||||
};
|
||||
// Declare the Storage dialog
|
||||
alertify.dialog('storageManagerDlg', function() {
|
||||
var controls = [], // Keep tracking of all the backform controls
|
||||
@ -141,6 +150,12 @@ define([
|
||||
var newFile = $('.currentpath').val() + sel_file;
|
||||
|
||||
pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:storage_dialog', newFile);
|
||||
|
||||
var _Url = "{{ url_for('file_manager.index') }}" + "save_last_dir/" + trans_id;
|
||||
var file_data = {
|
||||
'path': $('.currentpath').val()
|
||||
};
|
||||
set_last_traversed_dir(file_data, _Url);
|
||||
} else if (closeEvent.button.text == "{{ _('Cancel') }}") {
|
||||
if (removeTransId(trans_id)) {
|
||||
this.destroy();
|
||||
@ -258,6 +273,12 @@ define([
|
||||
|
||||
pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:select_file', newFile);
|
||||
removeTransId(trans_id);
|
||||
// Ajax call to store the last directory visited once user press select button
|
||||
var _Url = "{{ url_for('file_manager.index') }}" + "save_last_dir/" + trans_id;
|
||||
var file_data = {
|
||||
'path': $('.currentpath').val()
|
||||
};
|
||||
set_last_traversed_dir(file_data, _Url);
|
||||
} else if (closeEvent.button.text == "{{ _('Cancel') }}") {
|
||||
if (removeTransId(trans_id)) {
|
||||
this.destroy();
|
||||
@ -375,6 +396,12 @@ define([
|
||||
|
||||
pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:select_folder', newFile);
|
||||
removeTransId(trans_id);
|
||||
// Ajax call to store the last directory visited once user press select button
|
||||
var _Url = "{{ url_for('file_manager.index') }}" + "save_last_dir/" + trans_id;
|
||||
var file_data = {
|
||||
'path': $('.currentpath').val()
|
||||
};
|
||||
set_last_traversed_dir(file_data, _Url);
|
||||
} else if (closeEvent.button.text == "{{ _('Cancel') }}") {
|
||||
if (removeTransId(trans_id)) {
|
||||
this.destroy();
|
||||
@ -536,6 +563,12 @@ define([
|
||||
pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:create_file', newFile);
|
||||
removeTransId(trans_id);
|
||||
}
|
||||
|
||||
var _Url = "{{ url_for('file_manager.index') }}" + "save_last_dir/" + trans_id;
|
||||
var file_data = {
|
||||
'path': $('.currentpath').val()
|
||||
};
|
||||
set_last_traversed_dir(file_data, _Url);
|
||||
} else if (closeEvent.button.text == "{{ _('Cancel') }}") {
|
||||
if (removeTransId(trans_id)) {
|
||||
this.destroy();
|
||||
|
@ -183,6 +183,7 @@ var setUploader = function(path) {
|
||||
$('.storage_dialog #uploader h1').html(file_path);
|
||||
|
||||
$('.currentpath').val(path);
|
||||
enab_dis_level_up();
|
||||
if ($('.storage_dialog #uploader h1 span').length === 0) {
|
||||
$('<span>'+lg.current_folder+'</span>').appendTo($('.storage_dialog #uploader h1'));
|
||||
}
|
||||
@ -1155,7 +1156,7 @@ var enab_dis_level_up = function() {
|
||||
$level_up = $('.file_manager').find('button.level-up'),
|
||||
$home_btn = $('.file_manager').find('button.home');
|
||||
|
||||
if (b === fileRoot) {
|
||||
if (b === '/') {
|
||||
$level_up.attr('disabled', 'disabled');
|
||||
$home_btn.attr('disabled', 'disabled');
|
||||
} else {
|
||||
@ -1337,7 +1338,7 @@ $('.file_manager .uploader').on('click', 'a', function(e) {
|
||||
$('.file_manager .home').click(function() {
|
||||
var currentViewMode = $('.fileinfo').data('view');
|
||||
$('.fileinfo').data('view', currentViewMode);
|
||||
getFolderInfo(fileRoot);
|
||||
getFolderInfo('/');
|
||||
enab_dis_level_up();
|
||||
});
|
||||
|
||||
@ -1348,7 +1349,7 @@ $(".file_manager .level-up").click(function() {
|
||||
// Enable/Disable level up button
|
||||
enab_dis_level_up();
|
||||
|
||||
if (b != fileRoot) {
|
||||
if (b != '/') {
|
||||
parent = b.substring(0, b.slice(0, -1).lastIndexOf("/")) + "/";
|
||||
var d = $(".fileinfo").data("view");
|
||||
$(".fileinfo").data("view", d);
|
||||
|
Loading…
Reference in New Issue
Block a user