Skip to content

Commit

Permalink
Implemented Delete Line
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Rossi committed Dec 22, 2015
1 parent 4cf3e87 commit 97062ba
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 16 deletions.
16 changes: 16 additions & 0 deletions src/main/java/net/apachegui/web/ConfigurationTreeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.regex.Pattern;

@RestController
@RequestMapping("/web/ConfigurationTree")
public class ConfigurationTreeController {
Expand Down Expand Up @@ -50,4 +52,18 @@ public String editLine(@RequestParam(value = "type") String type,
return result.toString();
}

@RequestMapping(method = RequestMethod.POST, params = "option=deleteLine", produces = "application/json;charset=UTF-8")
public String deleteLine(@RequestParam(value = "file") String file,
@RequestParam(value = "lineOfStart") int lineOfStart,
@RequestParam(value = "lineOfEnd") int lineOfEnd) throws Exception {

String originalContents = ConfFiles.deleteFromConfigFile(Pattern.compile(".*", Pattern.CASE_INSENSITIVE), new File(file), lineOfStart, lineOfEnd, true);

Configuration.testChanges(file, originalContents);

JSONObject result = populateFileModifiedResponse(file);

return result.toString();
}

}
99 changes: 90 additions & 9 deletions src/main/webapp/resources/net/apachegui/ConfigurationTree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//TODO stub out this file into a re-usable widget for GlobalTree.js
//TODO VirtualHost js should end up using this widget
define([
"dojo/_base/declare",
"dojo/dom",
Expand Down Expand Up @@ -34,6 +35,14 @@ define([
DIRECTIVE: 'directive'
},

/**
* This function should be overriden with a custom JSON loader
* @param callback(treeJSON) callback function to execute. treeJSON should be passed in as a parameter
*/
loadTreeJSON: function(callback) {

},

/**
* @param params - params are as follows:
* id - the id to give the tree
Expand All @@ -44,6 +53,7 @@ define([
this.id = params.id;
this.treeJSON = params.treeJSON || {};
this.autoExpand = params.autoExpand || false;
this.loadTreeJSON = params.loadTreeJSON || this.loadTreeJSON;

var store = new ItemFileWriteStore({
data : this.treeJSON
Expand Down Expand Up @@ -175,15 +185,19 @@ define([
this.editable = true;
},

reload: function(treeJSON) {
this.treeJSON = treeJSON;
this.tree.model.store = new ItemFileWriteStore({
data : this.treeJSON
});
reload: function() {
var that = this;

this.loadTreeJSON(function(treeJSON) {
that.treeJSON = treeJSON;
that.tree.model.store = new ItemFileWriteStore({
data : that.treeJSON
});

this.tree.reload();
that.tree.reload();

this._autoExpandRootNode();
that._autoExpandRootNode();
});
},

//--- PRIVATE FUNCTIONS -----------------------------------------------------------//
Expand Down Expand Up @@ -314,6 +328,7 @@ define([
registry.byId('editLineDialog').hide();

that.onAfterEditLine(type, value, response);
that.reload();
}, function(error) {
thisdialog.remove();

Expand All @@ -326,6 +341,58 @@ define([

_deleteLine: function() {
//todo implement delete line
var that = this;

if(!this.editable) {
this.onDisabledError();
return;
}

var item = this._getSelectedTreeItem();

if (!!item) {
var type = this._getItemProperty(item, 'type');
var value = this._getItemProperty(item, 'value');

var shouldShow = this.onShowDeleteDialog(type, value);
if(!shouldShow) {
return;
}

net.apachegui.Util.confirmDialog("Please Confirm", "Are you sure you want to delete the following " + this._getItemProperty(item,'lineType') + ":<br/><br/>" + this._getItemProperty(item,'name'), function confirm(conf) {
if (conf) {

var shouldDelete = that.onBeforeDeleteLine(type, value);
if(!shouldDelete) {
return;
}

var thisdialog = net.apachegui.Util.noCloseDialog('Deleting', 'Deleting Please Wait...');
thisdialog.show();

request.post("../web/ConfigurationTree", {
data : {
option : 'deleteLine',
file : that._getItemProperty(item,'file'),
lineOfStart : that._getItemProperty(item,'lineType') == 'enclosure' ? that._getItemProperty(item,'enclosureLineOfStart') : that._getItemProperty(item,'lineOfStart'),
lineOfEnd : that._getItemProperty(item,'lineType') == 'enclosure' ? that._getItemProperty(item,'enclosureLineOfEnd') : that._getItemProperty(item,'lineOfEnd')
},
handleAs : 'json',
sync : false
}).response.then(function(response) {
thisdialog.remove();

that.onAfterDeleteLine(type, value, response);
that.reload();
}, function(error) {
thisdialog.remove();
var response = error.response;
net.apachegui.Util.alert('Error', response.data.message);
that.onDeleteLineError(type, value, response);
});
}
});
}
},

_showAddLineDialog: function(type) {
Expand All @@ -335,8 +402,6 @@ define([
_addListeners: function() {
var that = this;

var that = this;

//todo implement tree line hover

on(registry.byId('editLineSubmit'), 'click', function() {
Expand Down Expand Up @@ -387,6 +452,22 @@ define([

onEditLineError: function(type, value, response) {
return true;
},

onShowDeleteDialog: function(type, value) {
return true;
},

onBeforeDeleteLine: function(type, value) {
return true;
},

onAfterDeleteLine: function(type, value, response) {
return true;
},

onDeleteLineError: function(type, value, response) {
return true;
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ define([
this.loadGlobalTreeJSON(function(treeJSON) {
that.configTree = new ConfigurationTree({
id: 'global_tree',
treeJSON: treeJSON
treeJSON: treeJSON,
loadTreeJSON: that.loadGlobalTreeJSON
});
that.configTree.startup();
that.addListeners();
Expand All @@ -51,12 +52,6 @@ define([
addListeners: function() {
var that = this;

this.configTree.on('aftereditline', function() {
that.loadGlobalTreeJSON(function(treeJSON) {
that.configTree.reload(treeJSON);
});
return true;
});
}

});
Expand Down

0 comments on commit 97062ba

Please sign in to comment.