From 7a0aafe8b9dd2bc8c41489cf61e482220dbae775 Mon Sep 17 00:00:00 2001 From: Kamidi Preetham Date: Thu, 2 Jun 2016 01:24:51 +0530 Subject: [PATCH 1/3] Added 'multer': middleware to handle form-data Signed-off-by: Kamidi Preetham --- server/tools.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/tools.js b/server/tools.js index 4702b67..f80acfb 100644 --- a/server/tools.js +++ b/server/tools.js @@ -17,6 +17,7 @@ module.exports = function () { var fs = require('fs'); var path = require('path'); + var multer = require('multer'); require('./configuration.js')(); this.home_dir = function(user) { From 56cd1ee5c42c43de2b6ac63ea2ec66f6de45dda0 Mon Sep 17 00:00:00 2001 From: Kamidi Preetham Date: Thu, 2 Jun 2016 01:40:39 +0530 Subject: [PATCH 2/3] Added editor side support for Importing Files Signed-off-by: Kamidi Preetham --- client/css/app.css | 37 +++++++++++++++++ client/js/controllers/editor.js | 71 +++++++++++++++++++++++++++++++++ server/views/index.html | 5 +++ 3 files changed, 113 insertions(+) diff --git a/client/css/app.css b/client/css/app.css index 4409573..321e323 100644 --- a/client/css/app.css +++ b/client/css/app.css @@ -176,6 +176,43 @@ font-family: clearsans-light; padding-left: 10px; border-radius: 20px; } +.inputFileControls { + background-color: #262a2e; + border: 0; + color: #8c8c8c; + width: 0.1px; + height: 0.1px; + opacity: 0; + overflow: hidden; + position: absolute; + z-index: -1; +} +.inputFileControls + label { + font-size: 14px !important; + font-weight: normal; + font-family: clearsans !important; + color: #8c8c8c; + background-color: white; + display: inline-block; + margin-right: 10px; + padding: .4em 1em; + border-radius: 20px; + cursor: pointer; + text-align: center; +} +.list-item { + font-size: 14px !important; + width: auto; + font-weight: normal; + font-family: clearsans !important; + background-color: #262a2e; + margin-right: 10px; + padding: .3em 0.5em; + list-style-type: none; + border-radius: 13px; + color: #8c8c8c; + text-align: center; +} /* Overwrite jquery ui class*/ .ui-autocomplete-input, .ui-corner-right { background: none !important; diff --git a/client/js/controllers/editor.js b/client/js/controllers/editor.js index 9a4fa0a..470753a 100644 --- a/client/js/controllers/editor.js +++ b/client/js/controllers/editor.js @@ -831,6 +831,74 @@ } }; + $scope.filesChanged = function(elm) { + $scope.files = elm.files; + $scope.$apply(); + } + + $scope.importFile = function () { + var file = filePath; + if (file) { + if (isLeaf) { + var cached = file.split("/"); + cached.pop(); + file = cached.join("/"); + } + if($scope.folder !== 'demo') { + var dialog = $('
'). + html($compile('
'+ + ' '+ + '
  • {{file.name}}
  • '+ + ' ')($scope)). + dialog({ + title: "Choose file to import", + autoOpen: false, + modal: true, + position: { at: "center top"}, + height: 225, + width: 300, + show: { effect: "fade", duration: 300 }, + hide: { effect: "fade", duration: 300 }, + resizable: 'disable', + buttons: { + "Upload": function() { + var formdata = new FormData(); + var data=String(file); + formdata.append("upload_path", data); + angular.forEach($scope.files,function(file) { + formdata.append('file', file) + }); + $http.post('/api/file/upload',formdata, { + transformRequest: angular.identity, + headers:{'Content-Type':undefined} + }) + .success(function(d) { + console.log(d) + $scope.refreshTree(); + }); + $(this).dialog("close"); + }, + Cancel: function() { + $(this).dialog("close"); + } + }, + close: function(ev, ui) { + $(this).dialog("close"); + } + }); + dialog.dialog("open"); + }else{ + console.log("Error: Upload to demo folder not allowed"); + alert("Error: Upload to demo folder Forbidden!") + } + } else { + console.log("Error: repository not selected"); + alert("Folder destination must be selected!"); + } + }; + $scope.remove = function () { if (filePath) { var file_name = filePath.split("/").pop(); @@ -940,6 +1008,9 @@ case "file.save": $scope.saveFileManually(); break; + case "file.importfile": + $scope.importFile(); + break; case "file.remove": $scope.remove(); break; diff --git a/server/views/index.html b/server/views/index.html index b0daaba..91a6dd0 100644 --- a/server/views/index.html +++ b/server/views/index.html @@ -190,6 +190,11 @@ New File + + + Import File + + From f45194998bda0be5bbcadc123aea78fbf54876af Mon Sep 17 00:00:00 2001 From: Kamidi Preetham Date: Thu, 2 Jun 2016 01:50:57 +0530 Subject: [PATCH 3/3] Added server side support for Importing Files Signed-off-by: Kamidi Preetham --- server/routes.js | 12 ++++++++++++ server/tools.js | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/server/routes.js b/server/routes.js index 9c11693..a2819c5 100644 --- a/server/routes.js +++ b/server/routes.js @@ -378,6 +378,18 @@ } }); + router.post('/api/file/upload', function(req, res) { + upload(req,res,function(err) { + if(err) { + res.status(400).send("File Upload Failed!"); + return; + } + else { + res.send("File Uploaded Successfully!"); + } + }) + }); + router.post('/api/git/repo/delete/file', function (req, res) { var file_path = req.body.params.file_path; if (!file_path) { diff --git a/server/tools.js b/server/tools.js index f80acfb..f8afac9 100644 --- a/server/tools.js +++ b/server/tools.js @@ -248,6 +248,17 @@ module.exports = function () { } }; + this.storage = multer.diskStorage({ + destination: function(req, file, callback) { + callback(null, String(req.body.upload_path)) + }, + filename: function(req, file, callback) { + callback(null, file.originalname) + } + }); + + this.upload = multer({storage: storage }).single('file'); + this.getServerName = function(repo_url) { var url_array = repo_url.split("/"); var name = url_array.pop();