-
Notifications
You must be signed in to change notification settings - Fork 13
V1 - Import files to Dev-App #116
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = $('<div></div>'). | ||
html($compile('<form ng-submit="Upload()"><input' + | ||
' type="file" id="inputFile" class="inputFileControls"' + | ||
' onChange="angular.element(this).scope().filesChanged(this)"/>'+ | ||
' <label for="inputFile">Select Files</label>'+ | ||
' <li class="list-item" ng-repeat="file in files">{{file.name}}</li>'+ | ||
' </form>')($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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove this console.log |
||
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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -378,6 +378,18 @@ | |
} | ||
}); | ||
|
||
router.post('/api/file/upload', function(req, res) { | ||
upload(req,res,function(err) { | ||
if(err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything "all-together-here" Try spliting things here:
|
||
res.status(400).send("File Upload Failed!"); | ||
return; | ||
} | ||
else { | ||
res.send("File Uploaded Successfully!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put like the rest of the code was done by putting the } together with the else.
|
||
} | ||
}) | ||
}); | ||
|
||
router.post('/api/git/repo/delete/file', function (req, res) { | ||
var file_path = req.body.params.file_path; | ||
if (!file_path) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
module.exports = function () { | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var multer = require('multer'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lib multer has to be added in package.json, to do it run the command
|
||
require('./configuration.js')(); | ||
|
||
this.home_dir = function(user) { | ||
|
@@ -247,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(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me the best message here would be:
"Error: Upload to demo folder is not allowed"
Also, you can remove the console.log here since we already have the alert