Add file browser button to volume listing
This commit is contained in:
+35
-19
@@ -2603,22 +2603,24 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
|
||||
// FileManager API
|
||||
// mode can be 'download', 'open', 'link' or 'data'
|
||||
Client.prototype.filesGet = function (appId, path, mode, callback) {
|
||||
Client.prototype.filesGet = function (id, type, path, mode, callback) {
|
||||
var objpath = (type === 'app' ? 'apps/' : 'volumes/') + id;
|
||||
|
||||
if (mode === 'download') {
|
||||
window.open(client.apiOrigin + '/api/v1/apps/' + appId + '/files/' + path + '?download=true&access_token=' + token);
|
||||
window.open(client.apiOrigin + '/api/v1/' + objpath + '/files/' + path + '?download=true&access_token=' + token);
|
||||
callback(null);
|
||||
} else if (mode === 'open') {
|
||||
window.open(client.apiOrigin + '/api/v1/apps/' + appId + '/files/' + path + '?download=false&access_token=' + token);
|
||||
window.open(client.apiOrigin + '/api/v1/' + objpath + '/files/' + path + '?download=false&access_token=' + token);
|
||||
callback(null);
|
||||
} else if (mode === 'link') {
|
||||
callback(null, client.apiOrigin + '/api/v1/apps/' + appId + '/files/' + path + '?download=false&access_token=' + token);
|
||||
callback(null, client.apiOrigin + '/api/v1/' + objpath + '/files/' + path + '?download=false&access_token=' + token);
|
||||
} else {
|
||||
function responseHandler(data, headers, status) {
|
||||
if (headers()['content-type'] && headers()['content-type'].indexOf('application/json') !== -1) return JSON.parse(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
get('/api/v1/apps/' + appId + '/files/' + path, { transformResponse: responseHandler }, function (error, data, status) {
|
||||
get('/api/v1/' + objpath + '/files/' + path, { transformResponse: responseHandler }, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
@@ -2627,8 +2629,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
}
|
||||
};
|
||||
|
||||
Client.prototype.filesRemove = function (appId, path, callback) {
|
||||
del('/api/v1/apps/' + appId + '/files/' + path, null, function (error, data, status) {
|
||||
Client.prototype.filesRemove = function (id, type, path, callback) {
|
||||
var objpath = (type === 'app' ? 'apps/' : 'volumes/') + id;
|
||||
|
||||
del('/api/v1/' + objpath + '/files/' + path, null, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
@@ -2636,8 +2640,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.filesExtract = function (appId, path, callback) {
|
||||
put('/api/v1/apps/' + appId + '/files/' + path, { action: 'extract' }, {}, function (error, data, status) {
|
||||
Client.prototype.filesExtract = function (id, type, path, callback) {
|
||||
var objpath = (type === 'app' ? 'apps/' : 'volumes/') + id;
|
||||
|
||||
put('/api/v1/' + objpath + '/files/' + path, { action: 'extract' }, {}, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
@@ -2645,8 +2651,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.filesChown = function (appId, path, uid, recursive, callback) {
|
||||
put('/api/v1/apps/' + appId + '/files/' + path, { action: 'chown', uid: uid, recursive: recursive }, {}, function (error, data, status) {
|
||||
Client.prototype.filesChown = function (id, type, path, uid, recursive, callback) {
|
||||
var objpath = (type === 'app' ? 'apps/' : 'volumes/') + id;
|
||||
|
||||
put('/api/v1/' + objpath + '/files/' + path, { action: 'chown', uid: uid, recursive: recursive }, {}, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
@@ -2654,8 +2662,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.filesRename = function (appId, path, newPath, callback) {
|
||||
put('/api/v1/apps/' + appId + '/files/' + path, { action: 'rename', newFilePath: newPath }, {}, function (error, data, status) {
|
||||
Client.prototype.filesRename = function (id, type, path, newPath, callback) {
|
||||
var objpath = (type === 'app' ? 'apps/' : 'volumes/') + id;
|
||||
|
||||
put('/api/v1/' + objpath + '/files/' + path, { action: 'rename', newFilePath: newPath }, {}, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
@@ -2663,8 +2673,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.filesCreateDirectory = function (appId, path, callback) {
|
||||
post('/api/v1/apps/' + appId + '/files/' + path, { directory: path }, {}, function (error, data, status) {
|
||||
Client.prototype.filesCreateDirectory = function (id, type, path, callback) {
|
||||
var objpath = (type === 'app' ? 'apps/' : 'volumes/') + id;
|
||||
|
||||
post('/api/v1/' + objpath + '/files/' + path, { directory: path }, {}, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
@@ -2672,8 +2684,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.filesCreateFile = function (appId, path, callback) {
|
||||
post('/api/v1/apps/' + appId + '/files/' + path, {}, {}, function (error, data, status) {
|
||||
Client.prototype.filesCreateFile = function (id, type, path, callback) {
|
||||
var objpath = (type === 'app' ? 'apps/' : 'volumes/') + id;
|
||||
|
||||
post('/api/v1/' + objpath + '/files/' + path, {}, {}, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
@@ -2681,7 +2695,9 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.filesUpload = function (appId, path, file, overwrite, progressHandler, callback) {
|
||||
Client.prototype.filesUpload = function (id, type, path, file, overwrite, progressHandler, callback) {
|
||||
var objpath = (type === 'app' ? 'apps/' : 'volumes/') + id;
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append('file', file);
|
||||
|
||||
@@ -2695,7 +2711,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
|
||||
}
|
||||
|
||||
$http({
|
||||
url: client.apiOrigin + '/api/v1/apps/' + appId + '/files/' + path,
|
||||
url: client.apiOrigin + '/api/v1/' + objpath + '/files/' + path,
|
||||
method: 'POST',
|
||||
data: fd,
|
||||
transformRequest: angular.identity,
|
||||
|
||||
+22
-18
@@ -67,8 +67,9 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
$scope.client = Client;
|
||||
$scope.cwd = '';
|
||||
$scope.cwdParts = [];
|
||||
$scope.appId = search.appId;
|
||||
$scope.app = null;
|
||||
$scope.id = search.appId || search.volumeId;
|
||||
$scope.type = search.appId ? 'app' : 'volume';
|
||||
$scope.title = '';
|
||||
$scope.entries = [];
|
||||
$scope.dropToBody = false;
|
||||
$scope.sortAsc = true;
|
||||
@@ -157,7 +158,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
$scope.extractStatus.error = null;
|
||||
$scope.extractStatus.busy = true;
|
||||
|
||||
Client.filesExtract($scope.appId, filePath, function (error) {
|
||||
Client.filesExtract($scope.id, $scope.type, filePath, function (error) {
|
||||
$scope.extractStatus.busy = false;
|
||||
|
||||
if (error) {
|
||||
@@ -177,7 +178,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
|
||||
if (entry.isDirectory) return;
|
||||
|
||||
Client.filesGet($scope.appId, filePath, 'download', function (error) {
|
||||
Client.filesGet($scope.id, $scope.type, filePath, 'download', function (error) {
|
||||
if (error) return Client.error(error);
|
||||
});
|
||||
}
|
||||
@@ -259,7 +260,8 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
$scope.refresh = function () {
|
||||
$scope.busy = true;
|
||||
|
||||
Client.filesGet($scope.appId, $scope.cwd, 'data', function (error, result) {
|
||||
console.log('getting', $scope.id, $scope.type, $scope.cwd);
|
||||
Client.filesGet($scope.id, $scope.type, $scope.cwd, 'data', function (error, result) {
|
||||
$scope.busy = false;
|
||||
if (error) return Client.error(error);
|
||||
|
||||
@@ -299,11 +301,11 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
if (mimeGroup === 'video' || mimeGroup === 'image') {
|
||||
$scope.mediaViewer.show(entry);
|
||||
} else if (mimeType === 'application/pdf') {
|
||||
Client.filesGet($scope.appId, filePath, 'open', function (error) { if (error) return Client.error(error); });
|
||||
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.appId, filePath, 'open', function (error) { if (error) return Client.error(error); });
|
||||
Client.filesGet($scope.id, $scope.type, filePath, 'open', function (error) { if (error) return Client.error(error); });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -368,7 +370,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
|
||||
$scope.uploadStatus.fileName = file.name;
|
||||
|
||||
Client.filesUpload($scope.appId, filePath, file, overwrite, function (loaded) {
|
||||
Client.filesUpload($scope.id, $scope.type, filePath, file, overwrite, function (loaded) {
|
||||
$scope.uploadStatus.percentDone = ($scope.uploadStatus.done+loaded) * 100 / $scope.uploadStatus.size;
|
||||
}, function (error) {
|
||||
if (error) return callback(error);
|
||||
@@ -439,7 +441,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
|
||||
var filePath = sanitize($scope.cwd + '/' + $scope.newDirectory.name);
|
||||
|
||||
Client.filesCreateDirectory($scope.appId, filePath, function (error) {
|
||||
Client.filesCreateDirectory($scope.id, $scope.type, filePath, function (error) {
|
||||
$scope.newDirectory.busy = false;
|
||||
if (error && error.statusCode === 409) return $scope.newDirectory.error = 'Already exists';
|
||||
if (error) return Client.error(error);
|
||||
@@ -473,7 +475,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
|
||||
var filePath = sanitize($scope.cwd + '/' + $scope.newFile.name);
|
||||
|
||||
Client.filesUpload($scope.appId, filePath, new File([], $scope.newFile.name), false, function () {}, function (error) {
|
||||
Client.filesUpload($scope.id, $scope.type, filePath, new File([], $scope.newFile.name), false, function () {}, function (error) {
|
||||
$scope.newFile.busy = false;
|
||||
if (error && error.statusCode === 409) return $scope.newFile.error = 'Already exists';
|
||||
if (error) return Client.error(error);
|
||||
@@ -506,7 +508,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
var oldFilePath = sanitize($scope.cwd + '/' + $scope.renameEntry.entry.fileName);
|
||||
var newFilePath = sanitize(($scope.renameEntry.newName[0] === '/' ? '' : ($scope.cwd + '/')) + $scope.renameEntry.newName);
|
||||
|
||||
Client.filesRename($scope.appId, oldFilePath, newFilePath, function (error) {
|
||||
Client.filesRename($scope.id, $scope.type, oldFilePath, newFilePath, function (error) {
|
||||
$scope.renameEntry.busy = false;
|
||||
if (error) return Client.error(error);
|
||||
|
||||
@@ -525,7 +527,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
show: function (entry) {
|
||||
var filePath = sanitize($scope.cwd + '/' + entry.fileName);
|
||||
|
||||
Client.filesGet($scope.appId, filePath, 'link', function (error, result) {
|
||||
Client.filesGet($scope.id, $scope.type, filePath, 'link', function (error, result) {
|
||||
if (error) return Client.error(error);
|
||||
|
||||
$scope.mediaViewer.entry = entry;
|
||||
@@ -557,7 +559,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
var filePath = sanitize($scope.cwd + '/' + entry.fileName);
|
||||
var language = getLanguage(entry.fileName);
|
||||
|
||||
Client.filesGet($scope.appId, filePath, 'data', function (error, result) {
|
||||
Client.filesGet($scope.id, $scope.type, filePath, 'data', function (error, result) {
|
||||
if (error) return Client.error(error);
|
||||
|
||||
if (!$scope.textEditor.editor) {
|
||||
@@ -583,7 +585,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
var filePath = sanitize($scope.cwd + '/' + $scope.textEditor.entry.fileName);
|
||||
var file = new File([newContent], 'file');
|
||||
|
||||
Client.filesUpload($scope.appId, filePath, file, true, function () {}, function (error) {
|
||||
Client.filesUpload($scope.id, $scope.type, filePath, file, true, function () {}, function (error) {
|
||||
if (error) return Client.error(error);
|
||||
|
||||
$timeout(function () {
|
||||
@@ -635,7 +637,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
|
||||
var filePath = sanitize($scope.cwd + '/' + $scope.chownEntry.entry.fileName);
|
||||
|
||||
Client.filesChown($scope.appId, filePath, $scope.chownEntry.newOwner, $scope.chownEntry.recursive, function (error) {
|
||||
Client.filesChown($scope.id, $scope.type, filePath, $scope.chownEntry.newOwner, $scope.chownEntry.recursive, function (error) {
|
||||
$scope.chownEntry.busy = false;
|
||||
if (error) return Client.error(error);
|
||||
|
||||
@@ -663,7 +665,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
|
||||
var filePath = sanitize($scope.cwd + '/' + $scope.entryRemove.entry.fileName);
|
||||
|
||||
Client.filesRemove($scope.appId, filePath, function (error) {
|
||||
Client.filesRemove($scope.id, $scope.type, filePath, function (error) {
|
||||
$scope.entryRemove.busy = false;
|
||||
if (error) return Client.error(error);
|
||||
|
||||
@@ -701,13 +703,15 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio
|
||||
Client.refreshUserInfo(function (error) {
|
||||
if (error) return Client.initError(error, init);
|
||||
|
||||
Client.getApp($scope.appId, function (error, result) {
|
||||
var getter = $scope.type === 'app' ? Client.getApp.bind(Client, $scope.id) : Client.getVolume.bind(Client, $scope.id);
|
||||
|
||||
getter(function (error, result) {
|
||||
if (error) {
|
||||
$scope.initialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.app = result;
|
||||
$scope.title = $scope.type === 'app' ? (result.label || result.fqdn) : result.name;
|
||||
|
||||
// now mark the Client to be ready
|
||||
Client.setReady();
|
||||
|
||||
Reference in New Issue
Block a user