Skip to content
Snippets Groups Projects
Commit c65a12dc authored by alvaro's avatar alvaro
Browse files

Improved version of editor

Create/remove components and single files
parent 7999224d
No related branches found
No related tags found
No related merge requests found
......@@ -127,7 +127,7 @@ textarea{ font-family: Monaco,'Droid Sans Mono'; font-size: 80%}
</div>
<div class='container'>
<img src='img/lodspeakr_logotype.png' style='opacity: 0.1; position: absolute; right:0px; top:60%'/>
<img src='../img/lodspeakr_logotype.png' style='opacity: 0.1; position: absolute; right:0px; top:60%'/>
";
private $foot =" </div>
</body>
......@@ -537,14 +537,14 @@ textarea{ font-family: Monaco,'Droid Sans Mono'; font-size: 80%}
<div class='container'>
<div class='row-fluid'>
<div class='span3 well'>
<legend>Views <!-- button class='btn btn-mini btn-info'>new</button --></legend>
<legend>Views <button class='btn btn-mini btn-info new-file-button hide new-file-button-view' data-component=''>new</button></legend>
<ul class='nav nav-list' id='template-list'>
</ul>
</div>
</div>
<div class='row-fluid'>
<div class='span3 well'>
<legend>Models <!-- button class='btn btn-mini btn-info'>new</button --></legend>
<legend>Models <button class='btn btn-mini btn-info new-file-button hide new-file-button-model' data-component=''>new</button></legend>
<ul class='nav nav-list' id='query-list'>
</ul>
</div>
......@@ -601,6 +601,20 @@ textarea{ font-family: Monaco,'Droid Sans Mono'; font-size: 80%}
HTTPStatus::send404($params[1]);
}
break;
case "add":
if(sizeof($params) > 2){
$this->addFile($params);
}else{
HTTPStatus::send404($params[1]);
}
break;
case "remove":
if(sizeof($params) > 2){
$this->deleteFile($params);
}else{
HTTPStatus::send404($params[1]);
}
break;
default:
HTTPStatus::send404($params[1]);
}
......@@ -696,6 +710,53 @@ textarea{ font-family: Monaco,'Droid Sans Mono'; font-size: 80%}
}
}
protected function deleteFile($params){
$path = "components/".implode("/", array_slice($params, 1));
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(sizeof($params) < 3){
HTTPStatus::send404();
exit(0);
}
$return_var = 0;
exec ("rm ".$path, &$output, $return_var);
if($return_var !== 0){
echo json_encode(array('success' => false, path => $path));
}else{
echo json_encode(array('success' => true, path => $path));
}
}else{
HTTPStatus::send406();
exit(0);
}
}
protected function addFile($params){
$path = "components/".implode("/", array_slice($params, 1));
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(sizeof($params) < 3){
HTTPStatus::send404();
exit(0);
}
$return_var = 0;
if(file_exists($path)){
echo json_encode(array('success' => false));
return;
}
exec("touch ".$path, &$output, $return_var);
//echo $return_var;exit(0);
if($return_var !== 0){
HTTPStatus::send500("touch ".$path);
}else{
echo json_encode(array('success' => true));
}
}else{
HTTPStatus::send406();
exit(0);
}
}
protected function stopEndpoint(){
$return_var = 0;
exec ("utils/modules/stop-endpoint.sh", &$output, $return_var);
......
......@@ -18,50 +18,67 @@ $(document).ready(function(){
$(".lodspk-delete-component").addClass("hide");
}
});
$(".lodspk-delete-component").on({
click: function(){
var componentName = $(this).attr("data-component-name");
var componentType = $(this).attr("data-component-type");
var url = "components/delete/"+componentType+"/"+componentName;
if (confirm("Are you sure you want to delete this component?")) {
$.ajax({
type: 'POST',
url: url,
data: {content: $("#template-editor").val()},
success: function(data){if(data.success == true){
$("#component-msg").removeClass('hide').addClass('alert-success').html("Component removed!").show().delay(2000).fadeOut("slow").removeClass('alert-success');
setTimeout(window.location.reload(), 2000);
}},
error: function(data){
$("#component-msg").removeClass('hide').addClass('alert-error').html("Error removing component!").show().delay(2000).fadeOut("slow").removeClass('alert-error');
},
dataType: 'json'
});
}
}
});
$(".new-button").on("click", function(e){
var componentName = prompt("Please enter the name of the new component","newComponent");
var url = "components/create/"+$(this).attr("data-type")+"/"+componentName;
$.ajax({
function executePost(url, data, message){
$.ajax({
type: 'POST',
url: url,
data: {content: $("#template-editor").val()},
data: data,
success: function(data){if(data.success == true){
$("#component-msg").removeClass('hide').addClass('alert-success').html("Saved!").show().delay(2000).fadeOut("slow").removeClass('alert-success');
setTimeout(window.location.reload(), 2000);
}},
$(message.id).removeClass('hide').addClass('alert-success').html(message.success).show().delay(2000).fadeOut("slow").removeClass('alert-success');
if(message.triggerElement != undefined && message.triggerEvent != undefined ){
$(message.triggerElement).trigger(message.triggerEvent);
}else{
setTimeout(window.location.reload(), 2000);
}
}else{
$(message.id).removeClass('hide').addClass('alert-error').html(message.failure).show().delay(2000).fadeOut("slow").removeClass('alert-error');
}
},
error: function(data){
$("#component-msg").removeClass('hide').addClass('alert-error').html("Error creating a new service!").show().delay(2000).fadeOut("slow").removeClass('alert-error');
$(message.id).removeClass('hide').addClass('alert-error').html(message.error).show().delay(2000).fadeOut("slow").removeClass('alert-error');
},
dataType: 'json'
});
}
$(".new-button").on("click", function(e){
var componentName = prompt("Please enter the name of the new component","newComponent");
if(componentName != null){
var url = "components/create/"+$(this).attr("data-type")+"/"+componentName;
var data = {content: $("#template-editor").val()};
var msgId = "#component-msg";
executePost(url, data, {id:msgId, success: "Saved!", failure: "Can't create new component. Probably permissions problem or component already exists", error: "Error creating a new component!"});
}
});
$(".new-file-button").on("click", function(e){
var componentName = prompt("Please enter the name of the new component","newComponent");
if(componentName != null){
var url = "components/add/"+$(this).attr("data-component")+"/"+componentName;
var data = {content: $("#template-editor").val()};
var msgId = "#component-msg";
executePost(url, data, {id:msgId, success: "Saved!", failure: "Can't create new file. Probably permissions problem or file already exists", error: "Error creating a new file!"});
}
});
$(".lodspk-delete-component").on({
click: function(){
var componentName = $(this).attr("data-component-name");
var componentType = $(this).attr("data-component-type");
var url = "components/delete/"+componentType+"/"+componentName;
if (confirm("Are you sure you want to delete this component?")) {
executePost(url, data, {id:msgId, success: "Component deleted!", failure: "Can't delete component. Probably permissions problem", error: "Error deleting component!"});
}
}
});
$(".lodspk-component").on("click", function(e){
var componentType = $(this).attr("data-component-type");
var componentName = $(this).attr("data-component-name");
var dataParent = ".lodspk-component[data-component-type="+componentType+"][data-component-name="+componentName+"]";
var url="components/details/"+componentType+"/"+componentName;
templateBuffer = "";
queryBuffer = "";
......@@ -72,13 +89,18 @@ $(document).ready(function(){
$("#query-list").empty()
$.each(data.views, function(i, item){
var viewUrl = relPos+componentType+"/"+componentName+"/"+item;
$("#template-list").append("<li><a class='lodspk-template' href='#template-save-button' data-url='"+viewUrl+"'>"+item+"</a></li>") ;
var viewFileUrl = componentType+"/"+componentName+"/"+item;
$("#template-list").append("<li class='file-li'><button type='button' class='close hide lodspk-delete-file' data-parent='"+dataParent+"' data-file='"+viewFileUrl+"' style='align:left'>x</button><a class='lodspk-template' href='#template-save-button' data-url='"+viewUrl+"'>"+item+"</a></li>") ;
});
$.each(data.models, function(i, item){
var modelUrl = relPos+componentType+"/"+componentName+"/queries/"+item;
$("#query-list").append("<li><a href='#query-save-button' class='lodspk-query' data-url='"+modelUrl+"'>"+item+"</a></li>")
var modelFileUrl = componentType+"/"+componentName+"/queries/"+item;
$("#query-list").append("<li class='file-li'><button type='button' class='close hide lodspk-delete-file' data-parent='"+dataParent+"' data-file='"+modelFileUrl+"' style='align:left'>x</button><a href='#query-save-button' class='lodspk-query' data-url='"+modelUrl+"'>"+item+"</a></li>")
});
updateEvents();
$(".new-file-button").removeClass("hide");
$(".new-file-button-view").attr("data-component", componentType+"/"+componentName );
$(".new-file-button-model").attr("data-component", componentType+"/"+componentName+"/queries" );
});
});
......@@ -116,6 +138,26 @@ $(document).ready(function(){
}
function updateEvents(){
$(".lodspk-delete-file").on({
click: function(){
var fileName = $(this).attr("data-file");
var url = "components/remove/"+fileName;
var msgId = "#component-msg";
if (confirm("Are you sure you want to delete this component?")) {
executePost(url, "", {id:msgId, success: "File deleted!", failure: "Can't delete file. Probably permissions problem", error: "Error deleting file!", triggerElement: $(this).attr("data-parent"), triggerEvent: 'click'});
}
}
});
$(".file-li").on({
mouseenter: function(){
$(this).children(".lodspk-delete-file").removeClass("hide");
},
mouseleave: function(){
$(".lodspk-delete-file").addClass("hide");
}
});
$(".lodspk-template").on("click", function(e){
var fileUrl = $(this).attr("data-url");
$.ajax({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment