Use browser history to allow navigation

This commit is contained in:
Johannes Zellner
2020-07-15 14:48:29 +02:00
parent 6aa8602b96
commit 6d6fba873f
3 changed files with 32 additions and 19 deletions

View File

@@ -57,6 +57,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
$scope.initialized = false;
$scope.status = null;
$scope.busy = true;
$scope.client = Client;
$scope.cwd = '/';
$scope.cwdParts = [];
@@ -112,6 +113,16 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
return '/' + filePath;
}
function download(entry) {
var filePath = sanitize($scope.cwd + '/' + entry.fileName);
if (entry.isDirectory) return;
Client.filesGet($scope.appId, filePath, true, function (error) {
if (error) return Client.error(error);
});
};
$scope.dragEnter = function ($event, entry) {
$event.originalEvent.stopPropagation();
$event.originalEvent.preventDefault();
@@ -187,7 +198,10 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
}
$scope.refresh = function () {
$scope.busy = true;
Client.filesGet($scope.appId, $scope.cwd, false, function (error, result) {
$scope.busy = false;
if (error) return Client.error(error);
$scope.entries = result.entries;
@@ -195,42 +209,32 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
};
$scope.open = function (entry) {
if ($scope.busy) return;
var filePath = sanitize($scope.cwd + '/' + entry.fileName);
if (entry.isDirectory) {
setDirectory(filePath);
$scope.changeDirectory(filePath);
} else if (entry.isFile) {
$scope.textEditor.show(entry);
} else {}
};
function download(entry) {
var filePath = sanitize($scope.cwd + '/' + entry.fileName);
if (entry.isDirectory) return;
Client.filesGet($scope.appId, filePath, true, function (error) {
if (error) return Client.error(error);
});
};
$scope.goDirectoryUp = function () {
setDirectory($scope.cwd + '/..');
$scope.changeDirectory($scope.cwd + '/..');
};
$scope.changeDirectory = function (path) {
setDirectory(path);
};
function setDirectory(path) {
path = sanitize(path);
if ($scope.cwd === path) return;
location.hash = path;
$scope.cwd = path;
$scope.cwdParts = path.split('/').filter(function (p) { return !!p; }).map(function (p, i) { return { name: p, path: path.split('/').slice(0, i+2).join('/') }; });
$scope.refresh();
}
};
$scope.uploadStatus = {
busy: false,
@@ -532,6 +536,12 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
init();
window.addEventListener('hashchange', function () {
$scope.$apply(function () {
$scope.changeDirectory(window.location.hash.slice(1));
});
});
// setup all the dialog focus handling
['newDirectoryModal', 'renameEntryModal'].forEach(function (id) {
$('#' + id).on('shown.bs.modal', function () {
@@ -547,5 +557,4 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
elem[0].setSelectionRange(0, text.indexOf('.'));
});
});
}]);