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

Commit

Permalink
Allow to save FBP file when it is not attached to a project
Browse files Browse the repository at this point in the history
This patch creates a dialog that allow the creation of a new file and project
when the code was developed disattached of a project.

Signed-off-by: Bruno Bottazzini <bruno.bottazzini@intel.com>
  • Loading branch information
Bruno Bottazzini committed Apr 29, 2016
1 parent a6688de commit a34bf0e
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 19 deletions.
112 changes: 93 additions & 19 deletions client/js/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,30 +453,37 @@
if ($scope.shouldSave) {
var file = filePath;
var body = editor.getSession().getValue();
if (file && body) {
$http.get('api/file/write',
{params: {
"file_path": file,
"file_body": body
}
}).success(function(data) {
$scope.shouldSave = false;
//pop * from the string
$scope.fileName = $scope.fileName.substring(0, $scope.fileName.length-1);
}).error(function(){
alert("Failed to save file on server. Try again.");
$scope.shouldSave = true;
});
if (filePath === "/tmp/cached.fbp") {
$scope.createProjectFromScratch();
} else {
alert("Something went terrbile wrong.\nFailed to save file on server. Try again.");
if (file && body) {
$http.get('api/file/write',
{params: {
"file_path": file,
"file_body": body
}
}).success(function(data) {
$scope.shouldSave = false;
//pop * from the string
if ($scope.fileName) {
$scope.fileName = $scope.fileName.substring(0, $scope.fileName.length-1);
}
}).error(function(){
alert("Failed to save file on server. Try again.");
$scope.shouldSave = true;
});
} else {
alert("Something went terrbile wrong.\nFailed to save file on server. Try again.");
}
}
}
};

editor.keyBinding.onCommandKey = function(e, hashId, keyCode) {
if ($scope.shouldSave === false && $scope.fileName &&
$scope.folder !== "demo") {
$scope.fileName = $scope.fileName + "*";
if ($scope.shouldSave === false && $scope.folder !== "demo") {
if ($scope.fileName) {
$scope.fileName = $scope.fileName + "*";
}
$scope.shouldSave = true;
}
this.origOnCommandKey(e, hashId, keyCode);
Expand Down Expand Up @@ -521,6 +528,74 @@

}

$scope.createProjectFromScratch = function () {
var dialog = $('<div></div>').
html($compile('<div>Project name <input class="inputControls"' +
' type="text" style="width: 256px; outline: 0;"' +
' ng-model="prj_name" /></div>' +
'<br><div> File name <input class="inputControls"' +
' type="text" style="width: 256px; outline: 0;"' +
' ng-model="file_name" /></div>')($scope)).
dialog({
title: "Create Project",
autoOpen: false,
modal: true,
position: { at: "center top"},
height: 270,
width: 300,
show: { effect: "fade", duration: 300 },
hide: {effect: "fade", duration: 300 },
resizable: 'disable',
closeOnEscape: false,
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
buttons: {
"Create": function() {
if ($scope.prj_name && $scope.file_name) {
$(".ui-dialog-buttonpane button:contains('Close')").button("disable");
$(".ui-dialog-buttonpane button:contains('Create')").button("disable");
var body = editor.getSession().getValue();
$http.post('/api/git/repo/create/new/project',
{
params: {
"project_name": $scope.prj_name,
"file_name": $scope.file_name,
"file_code": body
}
}).success(function(data) {
var repo_data = data;
var file_data = data + "/" + $scope.file_name;
var t = $("#jstree").jstree(true);
$("#jstree").one("refresh.jstree", function () {
$("#jstree").one("open_node.jstree", function () {
t.select_node(file_data);
});
t.open_node(repo_data);
});
$scope.refreshTree();
$scope.shouldSave = false;
$(".ui-dialog-buttonpane button:contains('Close')").button("enable");
$(".ui-dialog-buttonpane button:contains('Create')").button("enable");
dialog.dialog("close");
}).error(function(data) {
alert("Failed to create project aborting. Reason: " + data);
$(".ui-dialog-buttonpane button:contains('Close')").button("enable");
$(".ui-dialog-buttonpane button:contains('Create')").button("enable");
});
} else {
alert("Invalid project or file name.");
}
},
Close: function() {
$(this).dialog("close");
}
},
close: function(ev, ui){
$(this).dialog("close");
}
});
dialog.dialog("open");
};

$scope.createProject = function () {
var dialog = $('<div></div>').
html($compile('<input class="inputControls"' +
Expand Down Expand Up @@ -605,7 +680,6 @@
$(".ui-dialog-buttonpane button:contains('Import')").button("enable");
});
$scope.startSpin();
console.log(dialog);
$(".ui-dialog-buttonpane button:contains('Close')").button("disable");
$(".ui-dialog-buttonpane button:contains('Import')").button("disable");
},
Expand Down
26 changes: 26 additions & 0 deletions server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,32 @@
}
});

router.post('/api/git/repo/create/new/project', function (req, res) {
var project_name = req.body.params.project_name;
var file_name = req.body.params.file_name;
var code = req.body.params.file_code;
if (!project_name || !file_name || !code) {
res.status(400).send("Failed to get project, file name or code");
} else {
var project_path = home_dir(current_user(req)) + project_name;
var file_path = home_dir(current_user(req)) + project_name + "/" +
file_name;
execOnServer('mkdir ' + home_dir(current_user(req)) + project_name,
function(returns) {
if (returns.error === true) {
res.status(400).send("Failed to run command on server");
} else {
if(!writeFile(file_path, code)) {
var prj = project_path.split("server/../");
res.send(prj[0] + prj[1]);
} else {
res.status(400).send("Failed to run command on server");
}
}
});
}
});

router.get('/api/configuration', function (req, res) {
try {
res.send(getConfigurationJson());
Expand Down

0 comments on commit a34bf0e

Please sign in to comment.