Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

WIP: Import and Export File to Dev-App #114

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions client/js/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,64 @@
}
};

$scope.importFile = function () {
var file = filePath;
if (file) {
if (isLeaf) {
var cached = file.split("/");
cached.pop();
file = cached.join("/");
}
var dialog = $('<div></div>').
html($compile('<form ng-controller="editor"> <input' +
Copy link
Contributor

@brunobottazzini brunobottazzini May 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, AngularJS does not allow declaration of the the same controller in two different forms.

Also, the $compile and $scope would inject the new code inside the editor controller so this form is not needed.

' type="file" class="inputControls"' +
' multiple onChange="angular.element(this).scope().filesChanged(this)"/> <input type="button" class="inputControls" ng-click="uploadFiles()" value="Upload" /><li ng-repeat="file in files">{{file.name}}</li></form>')($scope)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try breaking some lines here it is too wide

dialog({
title: "Choose file to import",
autoOpen: false,
modal: true,
position: { at: "center top"},
height: 167,
width: 300,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

height and width too small to me here,

I put the following values:
height: 225
width: 300

show: { effect: "fade", duration: 300 },
hide: {effect: "fade", duration: 300 },
resizable: 'disable',
buttons: {
Cancel: function() {
$(this).dialog("close");
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create Upload button like the Cancel one (with the same style and position).

It should be something like this:

buttons: {
      "Upload": function () {
            // Do something here
       },
      Cancel: function() {
            $(this).dialog("close");
       }
},

Try avoiding creating the html button you've created for Upload :)

close: function(ev, ui){
$(this).dialog("close");
}
});
dialog.dialog("open");
} else {
console.log("Error: repository not selected");
alert("Folder destination must be selected!");
}
};

$scope.filesChanged = function(elm){
$scope.files = elm.files
$scope.$apply();
}

$scope.uploadFiles = function() {
var formdata = new FormData();
angular.forEach($scope.files,function(file){
formdata.append('file',file)
})
$http.post('/api/git/repo/upload',formdata,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you haven't created this api so, I would change the name to

/api/file/upload

{
transformRequest:angular.identity,
headers:{'Content-Type':undefined}
})
.success(function(d){
console.log(d)
});
};

$scope.remove = function () {
if (filePath) {
var file_name = filePath.split("/").pop();
Expand Down Expand Up @@ -943,6 +1001,9 @@
case "file.remove":
$scope.remove();
break;
case "file.importfile":
$scope.importFile();
break;
case "file.import":
$scope.importGITProject();
break;
Expand Down
5 changes: 5 additions & 0 deletions server/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@
New File
</md-button>
</md-menu-item>
<md-menu-item>
<md-button ng-click="ctrl.menuAction('file.importfile', $event)">
Import File
</md-button>
</md-menu-item>
<md-menu-divider></md-menu-divider>
<md-menu-item>
<md-button ng-disabled="!shouldSave" ng-click="ctrl.menuAction('file.save', $event)">
Expand Down