diff --git a/src/filemanager.html b/src/filemanager.html index 4f4b62462..32c51e56a 100644 --- a/src/filemanager.html +++ b/src/filemanager.html @@ -53,6 +53,25 @@ Cloudron is offline. Reconnecting... + + +

@@ -83,7 +102,7 @@ - + Up @@ -99,7 +118,7 @@ {{ entry.size | prettyDiskSize }} {{ entry.uid | prettyOwner }} - + diff --git a/src/js/client.js b/src/js/client.js index 3af492d1d..ebd27ccaa 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -2394,6 +2394,15 @@ 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) { + if (error) return callback(error); + if (status !== 200) return callback(new ClientError(status, data)); + + callback(null, data); + }); + }; + client = new Client(); return client; }]); diff --git a/src/js/filemanager.js b/src/js/filemanager.js index 06b10d0ea..fdfb72f3c 100644 --- a/src/js/filemanager.js +++ b/src/js/filemanager.js @@ -1,6 +1,6 @@ 'use strict'; -/* global angular */ +/* global angular, $ */ // create main application module var app = angular.module('Application', ['angular-md5', 'ui-notification']); @@ -55,20 +55,22 @@ app.controller('FileManagerController', ['$scope', 'Client', function ($scope, C console.log('uploadFolder'); }; - $scope.remove = function (entry) { - console.log('remove', entry); - }; - $scope.open = function (entry) { + var filePath = sanitize($scope.cwd + '/' + entry.filePath); + if (entry.isDirectory) { - setDirectory($scope.cwd + '/' + entry.filePath); + setDirectory(filePath); } else if (entry.isFile) { - console.log('open', entry) + Client.filesGet($scope.appId, filePath, function (error, result) { + if (error) return Client.error(error); + + console.log('open', result); + }); } else {} }; $scope.goDirectoryUp = function () { - setDirectory($scope.cwd + '/..') + setDirectory($scope.cwd + '/..'); }; function setDirectory(path) { @@ -80,6 +82,36 @@ app.controller('FileManagerController', ['$scope', 'Client', function ($scope, C $scope.refresh(); } + $scope.entryRemove = { + busy: false, + error: null, + entry: {}, + + show: function (entry) { + $scope.entryRemove.error = null; + $scope.entryRemove.entry = entry; + + $('#entryRemoveModal').modal('show'); + }, + + submit: function () { + $scope.entryRemove.busy = true; + + var filePath = sanitize($scope.cwd + '/' + $scope.entryRemove.entry.filePath); + + Client.filesRemove($scope.appId, filePath, function (error, result) { + $scope.entryRemove.busy = false; + if (error) return Client.error(error); + + console.log('remove', result); + + $scope.refresh(); + + $('#entryRemoveModal').modal('hide'); + }); + } + }; + function init() { Client.getStatus(function (error, status) {