filemanager: implement direct entry and thus history support
This commit is contained in:
@@ -124,6 +124,73 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
|
||||
return filePath;
|
||||
}
|
||||
|
||||
function openPath(path) {
|
||||
path = sanitize(path);
|
||||
|
||||
var parentPath = sanitize(path + '/..');
|
||||
|
||||
// nothing changes here, mostly triggered when editor is closed
|
||||
if ($scope.cwd === path) {
|
||||
$scope.busy = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($scope.cwd === parentPath) {
|
||||
var entry = $scope.entries.find(function (e) { return path === sanitize(parentPath + '/' + e.fileName); });
|
||||
if (!entry) return Client.error('No such file or folder: ' + path);
|
||||
|
||||
if (entry.isDirectory) {
|
||||
$scope.changeDirectory(path);
|
||||
} else if (entry.isFile) {
|
||||
var mimeType = Mimer().get(entry.fileName);
|
||||
var mimeGroup = mimeType.split('/')[0];
|
||||
|
||||
if (mimeGroup === 'video' || mimeGroup === 'image') {
|
||||
$scope.mediaViewer.show(entry);
|
||||
} else if (mimeType === 'application/pdf') {
|
||||
Client.filesGet($scope.id, $scope.type, path, 'open', function (error) { if (error) return Client.error(error); });
|
||||
} else if (mimeGroup === 'text' || mimeGroup === 'application') {
|
||||
$scope.textEditor.show(entry);
|
||||
} else {
|
||||
Client.filesGet($scope.id, $scope.type, path, 'open', function (error) { if (error) return Client.error(error); });
|
||||
}
|
||||
}
|
||||
|
||||
$scope.busy = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Client.filesGet($scope.id, $scope.type, parentPath, 'data', function (error, result) {
|
||||
if (error) return Client.error(error);
|
||||
|
||||
// amend icons
|
||||
result.entries.forEach(function (e) {
|
||||
e.icon = 'fa-file';
|
||||
|
||||
if (e.isDirectory) e.icon = 'fa-folder';
|
||||
if (e.isSymbolicLink) e.icon = 'fa-link';
|
||||
if (e.isFile) {
|
||||
var mimeType = Mimer().get(e.fileName);
|
||||
var mimeGroup = mimeType.split('/')[0];
|
||||
if (mimeGroup === 'text') e.icon = 'fa-file-alt';
|
||||
if (mimeGroup === 'image') e.icon = 'fa-file-image';
|
||||
if (mimeGroup === 'video') e.icon = 'fa-file-video';
|
||||
if (mimeGroup === 'audio') e.icon = 'fa-file-audio';
|
||||
if (mimeType === 'text/csv') e.icon = 'fa-file-csv';
|
||||
if (mimeType === 'application/pdf') e.icon = 'fa-file-pdf';
|
||||
}
|
||||
});
|
||||
|
||||
$scope.entries = result.entries;
|
||||
$scope.cwd = parentPath;
|
||||
$scope.cwdParts = parentPath.split('/').filter(function (p) { return !!p; }).map(function (p, i) { return { name: decodeURIComponent(p), path: path.split('/').slice(0, i+1).join('/') }; });
|
||||
|
||||
// call itself now that we know
|
||||
openPath(path);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.isSelected = function (entry) {
|
||||
return $scope.selected.indexOf(entry) !== -1;
|
||||
};
|
||||
@@ -322,26 +389,7 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
|
||||
};
|
||||
|
||||
$scope.open = function (entry) {
|
||||
if ($scope.busy) return;
|
||||
|
||||
var filePath = sanitize($scope.cwd + '/' + entry.fileName);
|
||||
|
||||
if (entry.isDirectory) {
|
||||
$scope.changeDirectory(filePath);
|
||||
} else if (entry.isFile) {
|
||||
var mimeType = Mimer().get(entry.fileName);
|
||||
var mimeGroup = mimeType.split('/')[0];
|
||||
|
||||
if (mimeGroup === 'video' || mimeGroup === 'image') {
|
||||
$scope.mediaViewer.show(entry);
|
||||
} else if (mimeType === 'application/pdf') {
|
||||
Client.filesGet($scope.id, $scope.type, filePath, 'open', function (error) { if (error) return Client.error(error); });
|
||||
} else if (mimeGroup === 'text' || mimeGroup === 'application') {
|
||||
$scope.textEditor.show(entry);
|
||||
} else {
|
||||
Client.filesGet($scope.id, $scope.type, filePath, 'open', function (error) { if (error) return Client.error(error); });
|
||||
}
|
||||
}
|
||||
location.hash = sanitize($scope.cwd + '/' + entry.fileName);
|
||||
};
|
||||
|
||||
$scope.select = function ($event, entry) {
|
||||
@@ -490,6 +538,7 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
|
||||
|
||||
$scope.cwd = path;
|
||||
$scope.cwdParts = path.split('/').filter(function (p) { return !!p; }).map(function (p, i) { return { name: decodeURIComponent(p), path: path.split('/').slice(0, i+1).join('/') }; });
|
||||
|
||||
$scope.refresh();
|
||||
};
|
||||
|
||||
@@ -732,6 +781,10 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
|
||||
|
||||
$('#mediaViewerModal').modal('show');
|
||||
});
|
||||
},
|
||||
|
||||
close: function () {
|
||||
$('#mediaViewerModal').modal('hide');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -940,7 +993,7 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
|
||||
// now mark the Client to be ready
|
||||
Client.setReady();
|
||||
|
||||
$scope.changeDirectory(window.location.hash.slice(1));
|
||||
openPath(window.location.hash.slice(1));
|
||||
|
||||
$scope.initialized = true;
|
||||
});
|
||||
@@ -952,7 +1005,11 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
|
||||
|
||||
window.addEventListener('hashchange', function () {
|
||||
$scope.$apply(function () {
|
||||
$scope.changeDirectory(window.location.hash.slice(1));
|
||||
// first close all dialogs
|
||||
$scope.mediaViewer.close();
|
||||
$scope.textEditor.close();
|
||||
|
||||
openPath(window.location.hash.slice(1));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1066,6 +1123,11 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
|
||||
});
|
||||
});
|
||||
|
||||
// this will update the hash
|
||||
$('#mediaViewerModal').on('hidden.bs.modal', function () {
|
||||
location.hash = $scope.cwd;
|
||||
});
|
||||
|
||||
// selects filename (without extension)
|
||||
['renameEntryModal'].forEach(function (id) {
|
||||
$('#' + id).on('shown.bs.modal', function () {
|
||||
|
||||
Reference in New Issue
Block a user