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

Commit

Permalink
editor: When creating new project check if it already exists
Browse files Browse the repository at this point in the history
If the user click yes it will erase the existed project and create a new one.
If the user click no it will cancel the creation.

Signed-off-by: Bruno Bottazzini <bruno.bottazzini@intel.com>
  • Loading branch information
Bruno Bottazzini committed Jun 10, 2016
1 parent ba60c10 commit 50f7db8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
81 changes: 55 additions & 26 deletions client/js/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,46 @@
return test;
}

function confirmProjectCreation(prj_name, fbp_name, body) {
$http.post('/api/git/repo/create/new/project',
{
params: {
"project_name": prj_name,
"file_name": fbp_name,
"file_code": body
}
}).success(function(data) {
var repo_data = data;
var file_data = data + "/" + fbp_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");
}).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");
});
}

function isProjectExists(project_name) {
var test = false;
$.each($("#tree li"), function(key, li) {
var prj = li.id.split("/").pop();
if (project_name === prj) {
test = true;
}
});
return test;
}

$scope.createProjectFromScratch = function () {
var dialog = $('<div></div>').
html($compile('<div>Project name <input class="inputControls"' +
Expand Down Expand Up @@ -624,33 +664,22 @@
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": fbp_name,
"file_code": body
}
}).success(function(data) {
var repo_data = data;
var file_data = data + "/" + fbp_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");
if (!isProjectExists($scope.prj_name)) {
confirmProjectCreation($scope.prj_name, fbp_name, body);
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 {
sure_dialog("Project", "The project " + $scope.prj_name +
" already exists, do you want to override it?",
function(close_id) {
if(close_id) {
confirmProjectCreation($scope.prj_name, fbp_name, body);
dialog.dialog("close");
} else {
$(".ui-dialog-buttonpane button:contains('Close')").button("enable");
$(".ui-dialog-buttonpane button:contains('Create')").button("enable")
}
});
}
} else {
alert("Invalid project or file name.");
}
Expand Down
3 changes: 2 additions & 1 deletion server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@
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,
execOnServer('rm -rf ' + home_dir(current_user(req)) + project_name +
' && mkdir ' + home_dir(current_user(req)) + project_name,
function(returns) {
if (returns.error === true) {
res.status(400).send("Failed to run command on server");
Expand Down

0 comments on commit 50f7db8

Please sign in to comment.