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

Commit

Permalink
New project button now asks for FBP file name
Browse files Browse the repository at this point in the history
When typing the name of the FBP if it does not contain .fbp as prefix
it will be added automatically.

Also, this patch adds enter as a submit button for better navigability in
dialogs.

Signed-off-by: Bruno Bottazzini <bruno.bottazzini@intel.com>
  • Loading branch information
Bruno Bottazzini committed May 17, 2016
1 parent 570dd52 commit 052b569
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 74 deletions.
106 changes: 53 additions & 53 deletions client/js/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@
$(this).dialog("close");
}
});
dialog.keypress(function(e) {
if (e.keyCode === $.ui.keyCode.ENTER) {
callback(true);
$(this).dialog("close");
}
});
dialog.dialog("open");

}
Expand All @@ -570,7 +576,7 @@
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"' +
'<br><div> FBP file name <input class="inputControls"' +
' type="text" style="width: 256px; outline: 0;"' +
' ng-model="file_name" /></div>')($scope)).
dialog({
Expand All @@ -584,23 +590,39 @@
hide: {effect: "fade", duration: 300 },
resizable: 'disable',
closeOnEscape: false,
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
open: function(event, ui) {
$(".ui-dialog-titlebar-close").hide();
dialog.keyup(function(e) {
if (e.keyCode === $.ui.keyCode.ENTER) {
$(".ui-dialog-buttonpane button:contains('Create')").click();
}
});
},
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();
var body;
if (filePath) {
body = editor.getSession().getValue();
}
console.log(filePath);
console.log(body);
var fbp_name = $scope.file_name;
if (fbp_name.substr(fbp_name.length - 4) !== ".fbp") {
fbp_name = fbp_name + ".fbp";
}
$http.post('/api/git/repo/create/new/project',
{
params: {
"project_name": $scope.prj_name,
"file_name": $scope.file_name,
"file_name": fbp_name,
"file_code": body
}
}).success(function(data) {
var repo_data = data;
var file_data = data + "/" + $scope.file_name;
var file_data = data + "/" + fbp_name;
var t = $("#jstree").jstree(true);
$("#jstree").one("refresh.jstree", function () {
$("#jstree").one("open_node.jstree", function () {
Expand Down Expand Up @@ -633,52 +655,6 @@
dialog.dialog("open");
};

$scope.createProject = function () {
var dialog = $('<div></div>').
html($compile('<input class="inputControls"' +
' type="text" style="width: 256px; outline: 0;"' +
' ng-model="prj_name" />')($scope)).
dialog({
title: "Choose the name of the project",
autoOpen: false,
modal: true,
position: { at: "center top"},
height: 167,
width: 300,
show: { effect: "fade", duration: 300 },
hide: {effect: "fade", duration: 300 },
resizable: 'disable',
buttons: {
"Create": function() {
var name = "/" + $scope.prj_name;
if (name) {
$http.post('/api/git/repo/create/project',
{
params: {
"project_name": name
}
}).success(function(data) {
$scope.refreshTree();
}).error(function(){
alert("Oh uh, something went wrong. Try again");
});
} else {
alert("Oh uh, something went wrong. Try again");
}
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
},
close: function(ev, ui){
$(this).dialog("close");
}
});
dialog.dialog("open");

};

$scope.importGITProject = function () {
var dialog = $('<div id="importGITDialog"></div>').
html($compile('<div class="spin_sync" style="margin-top: -9px; float: right; margin-right: 46px;"' +
Expand All @@ -695,7 +671,15 @@
height: 170,
width: 520,
closeOnEscape: false,
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
open: function(event, ui) {
$(".ui-dialog-titlebar-close").hide();
dialog.keyup(function(e) {
if (e.keyCode === $.ui.keyCode.ENTER) {
console.log("Import");
$(".ui-dialog-buttonpane button:contains('Import')").click();
}
});
},
show: { effect: "fade", duration: 300 },
hide: {effect: "fade", duration: 300 },
resizable: 'disable',
Expand Down Expand Up @@ -750,6 +734,14 @@
show: { effect: "fade", duration: 300 },
hide: {effect: "fade", duration: 300 },
resizable: 'disable',
open: function(event, ui) {
dialog.keyup(function(e) {
if (e.keyCode === $.ui.keyCode.ENTER) {
console.log("Import");
$(".ui-dialog-buttonpane button:contains('Create')").click();
}
});
},
buttons: {
"Create": function() {
var name = "/" + $scope.folder_name;
Expand Down Expand Up @@ -802,6 +794,14 @@
show: { effect: "fade", duration: 300 },
hide: {effect: "fade", duration: 300 },
resizable: 'disable',
open: function(event, ui) {
dialog.keyup(function(e) {
if (e.keyCode === $.ui.keyCode.ENTER) {
console.log("Import");
$(".ui-dialog-buttonpane button:contains('Create')").click();
}
});
},
buttons: {
"Create": function() {
var name = "/" + $scope.file_name;
Expand Down Expand Up @@ -934,7 +934,7 @@
this.menuAction = function(name, ev) {
switch(name) {
case "file.projectnew":
$scope.createProject();
$scope.createProjectFromScratch();
break;
case "file.folder":
$scope.newFolder();
Expand Down
37 changes: 16 additions & 21 deletions server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,6 @@
}
});

router.post('/api/git/repo/create/project', function (req, res) {
var project_name = req.body.params.project_name;
if (!project_name) {
res.status(400).send("Failed to get project 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 {
res.send(returns.message);
}
});
});

router.post('/api/git/repo/create/folder', function (req, res) {
var folder_path = req.body.params.folder_path;
if (!folder_path) {
Expand Down Expand Up @@ -416,22 +401,32 @@
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");
if (!project_name || !file_name) {
res.status(400).send("Failed to get project or file name");
} else {
var project_path = home_dir(current_user(req)) + project_name;
var prj = project_path.split("server/../");
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]);
if (code) {
if(!writeFile(file_path, code)) {
res.send(prj[0] + prj[1]);
} else {
res.status(400).send("Failed to run command on server");
}
} else {
res.status(400).send("Failed to run command on server");
execOnServer('touch ' + file_path, function(returns) {
if (returns.error === true) {
res.status(400).send("Failed to run command on server");
} else {
res.send(prj[0] + prj[1]);
}
});
}
}
});
Expand Down

0 comments on commit 052b569

Please sign in to comment.