Move new file and folder logic as well as restart to the main filemanager controller

This commit is contained in:
Johannes Zellner
2022-08-25 21:42:28 +02:00
parent 6603087f72
commit 536bb84ade
4 changed files with 190 additions and 169 deletions
+6 -118
View File
@@ -10,6 +10,8 @@ angular.module('Application').component('filetree', {
view: '<',
onUploadFile: '&',
onUploadFolder: '&',
onNewFile: '&',
onNewFolder: '&',
onRenameEntry: '&',
onExtractEntry: '&',
onChownEntries: '&',
@@ -471,87 +473,8 @@ function FileTreeController($scope, $translate, $timeout, Client) {
// just events to the parent controller
$scope.onUploadFile = function () { ctrl.onUploadFile({ cwd: $scope.cwd }); };
$scope.onUploadFolder = function () { ctrl.onUploadFolder({ cwd: $scope.cwd }); };
$scope.restartBusy = false;
$scope.onRestartApp = function () {
$scope.restartBusy = true;
function waitUntilRestarted(callback) {
Client.getApp($scope.backendId, function (error, result) {
if (error) return callback(error);
if (result.installationState === ISTATES.INSTALLED) return callback();
setTimeout(waitUntilRestarted.bind(null, callback), 2000);
});
}
Client.restartApp($scope.backendId, function (error) {
if (error) console.error('Failed to restart app.', error);
waitUntilRestarted(function (error) {
if (error) console.error('Failed wait for restart.', error);
$scope.restartBusy = false;
});
});
};
$scope.onRestartMail = function () {
$scope.restartBusy = true;
function waitUntilRestarted(callback) {
Client.getService('mail', function (error, result) {
if (error) return callback(error);
if (result.status === 'active') return callback();
setTimeout(waitUntilRestarted.bind(null, callback), 2000);
});
}
Client.restartService('mail', function (error) {
if (error) console.error('Failed to restart mail.', error);
waitUntilRestarted(function (error) {
if (error) console.error('Failed wait for restart.', error);
$scope.restartBusy = false;
});
});
};
$scope.newDirectory = {
busy: false,
error: null,
name: '',
show: function () {
$scope.newDirectory.error = null;
$scope.newDirectory.name = '';
$scope.newDirectory.busy = false;
$scope.newDirectoryForm.$setUntouched();
$scope.newDirectoryForm.$setPristine();
$('#newDirectoryModal-' + $scope.$id).modal('show');
},
submit: function () {
$scope.newDirectory.busy = true;
$scope.newDirectory.error = null;
var filePath = sanitize($scope.cwd + '/' + $scope.newDirectory.name);
Client.filesCreateDirectory($scope.backendId, $scope.backendType, filePath, function (error) {
$scope.newDirectory.busy = false;
if (error && error.statusCode === 409) return $scope.newDirectory.error = 'exists';
if (error) return Client.error(error);
$scope.refresh();
$('#newDirectoryModal-' + $scope.$id).modal('hide');
});
}
};
$scope.onNewFile = function () { ctrl.onNewFile({ cwd: $scope.cwd }); };
$scope.onNewFolder = function () { ctrl.onNewFolder({ cwd: $scope.cwd }); };
$scope.mediaViewer = {
type: '',
@@ -576,41 +499,6 @@ function FileTreeController($scope, $translate, $timeout, Client) {
}
};
$scope.newFile = {
busy: false,
error: null,
name: '',
show: function () {
$scope.newFile.error = null;
$scope.newFile.name = '';
$scope.newFile.busy = false;
$scope.newFileForm.$setUntouched();
$scope.newFileForm.$setPristine();
$('#newFileModal-' + $scope.$id).modal('show');
},
submit: function () {
$scope.newFile.busy = true;
$scope.newFile.error = null;
var filePath = sanitize($scope.cwd + '/' + $scope.newFile.name);
Client.filesUpload($scope.backendId, $scope.backendType, filePath, new File([], $scope.newFile.name), false, function () {}, function (error) {
$scope.newFile.busy = false;
if (error && error.statusCode === 409) return $scope.newFile.error = 'exists';
if (error) return Client.error(error);
$scope.refresh();
$('#newFileModal-' + $scope.$id).modal('hide');
});
}
};
$translate(['filemanager.list.menu.edit', 'filemanager.list.menu.cut', 'filemanager.list.menu.copy', 'filemanager.list.menu.paste', 'filemanager.list.menu.rename', 'filemanager.list.menu.chown', 'filemanager.list.menu.extract', 'filemanager.list.menu.download', 'filemanager.list.menu.delete' ]).then(function (tr) {
$scope.menuOptions = [
{
@@ -657,10 +545,10 @@ function FileTreeController($scope, $translate, $timeout, Client) {
$scope.menuOptionsBlank = [
{
text: tr['filemanager.toolbar.newFile'],
click: function ($itemScope, $event) { $scope.newFile.show(); }
click: function ($itemScope, $event) { ctrl.onNewFile({ cwd: $scope.cwd }); }
}, {
text: tr['filemanager.toolbar.newFolder'],
click: function ($itemScope, $event) { $scope.newDirectory.show(); }
click: function ($itemScope, $event) { ctrl.onNewFolder({ cwd: $scope.cwd }); }
}, {
text: tr['filemanager.list.menu.paste'],
hasTopDivider: true,