Improve two view pane

This commit is contained in:
Johannes Zellner
2022-08-25 12:23:38 +02:00
parent 2a69b3d523
commit ba9530eb32
5 changed files with 76 additions and 46 deletions
+31 -24
View File
@@ -74,22 +74,35 @@ function isModalVisible() {
return !!document.getElementsByClassName('modal in').length;
}
var VIEW = {
LEFT: 'left',
RIGHT: 'right'
};
app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Client', function ($scope, $translate, $timeout, Client) {
var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.split('='); }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {});
$scope.VIEW = VIEW;
$scope.initialized = false;
$scope.status = null;
$scope.client = Client;
$scope.title = '';
$scope.id = search.id;
$scope.type = search.type;
// move to this instead of above
$scope.backendId = search.id;
$scope.backendType = search.type;
$scope.volumes = [];
$scope.splitView = false;
$scope.activeView = VIEW.LEFT;
$scope.viewerOpen = false;
$scope.toggleSplitView = function () {
$scope.splitView = !$scope.splitView;
if (!$scope.splitView) $scope.activeView = VIEW.LEFT;
};
$scope.setActiveView = function (view) {
$scope.activeView = view;
};
// for monaco editor
var LANGUAGES = [];
@@ -124,13 +137,13 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
// clear model if any
if ($scope.textEditor.editor && $scope.textEditor.editor.getModel()) $scope.textEditor.editor.setModel(null);
$scope.view = 'textEditor';
$scope.viewerOpen = true;
// document.getElementById('textEditorModal').style['display'] = 'flex';
var filePath = sanitize($scope.textEditor.cwd + '/' + entry.fileName);
var language = getLanguage(entry.fileName);
Client.filesGet($scope.id, $scope.type, filePath, 'data', function (error, result) {
Client.filesGet($scope.backendId, $scope.backendType, filePath, 'data', function (error, result) {
if (error) return Client.error(error);
if (!$scope.textEditor.editor) {
@@ -156,7 +169,7 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
var filePath = sanitize($scope.textEditor.cwd + '/' + $scope.textEditor.entry.fileName);
var file = new File([newContent], 'file');
Client.filesUpload($scope.id, $scope.type, filePath, file, true, function () {}, function (error) {
Client.filesUpload($scope.backendId, $scope.backendType, filePath, file, true, function () {}, function (error) {
if (error) return Client.error(error);
// update size immediately for the list view to avoid reloading the whole list
@@ -172,11 +185,13 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
close: function () {
$scope.textEditor.visible = false;
$scope.viewerOpen = false;
$('#textEditorCloseModal').modal('hide');
},
onClose: function () {
$scope.textEditor.visible = false;
$scope.viewerOpen = false;
$('#textEditorCloseModal').modal('hide');
},
@@ -236,11 +251,11 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
if (error) return Client.initError(error, init);
var getter;
if ($scope.type === 'app') {
getter = Client.getApp.bind(Client, $scope.id);
} else if ($scope.type === 'volume') {
getter = Client.getVolume.bind(Client, $scope.id);
} else if ($scope.type === 'mail') {
if ($scope.backendType === 'app') {
getter = Client.getApp.bind(Client, $scope.backendId);
} else if ($scope.backendType === 'volume') {
getter = Client.getVolume.bind(Client, $scope.backendId);
} else if ($scope.backendType === 'mail') {
getter = function (next) { next(null, null); };
}
@@ -251,9 +266,9 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
}
// fine to do async
if ($scope.type === 'app') fetchVolumesInfo(result.mounts || []);
if ($scope.backendType === 'app') fetchVolumesInfo(result.mounts || []);
switch ($scope.type) {
switch ($scope.backendType) {
case 'app':
$scope.title = result.label || result.fqdn;
$scope.rootDirLabel = '/app/data/';
@@ -286,15 +301,7 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
// handle save shortcuts
window.addEventListener('keydown', function (event) {
if (event.key === 'ArrowDown') {
$scope.$apply(selectNext);
} else if (event.key === 'ArrowUp') {
$scope.$apply(selectPrev);
// } else if (event.key === 'Enter') {
// $scope.$apply(openSelected);
// } else if (event.key === 'Backspace') {
// if ($scope.view === 'fileTree') $scope.goDirectoryUp();
} else if((navigator.platform.match('Mac') ? event.metaKey : event.ctrlKey) && event.key === 's') {
if((navigator.platform.match('Mac') ? event.metaKey : event.ctrlKey) && event.key === 's') {
if ($scope.view !== 'textEditor') return;
event.preventDefault();