Skip to content

Commit

Permalink
Added ability to edit tree lines, added input auto suggest to trees
Browse files Browse the repository at this point in the history
  • Loading branch information
jrossi227 committed Dec 7, 2015
1 parent e98e07d commit 6b28850
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/main/java/net/apachegui/conf/ConfigurationTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static JSONObject toTreeJSON(ParsableLine parsableLines[], String rootNod

JSONObject children = new JSONObject();

children.put("id", 0);
children.put("id", "0");
children.put("name", rootNodeName);
children.put("type", "rootNode");
children.put("value", "");
Expand Down Expand Up @@ -105,7 +105,7 @@ private static JSONArray toTreeJSON(ParsableLine parsableLines[], int lineNum) t
String name = getNameFromParts(parts);

JSONObject children = new JSONObject();
children.put("id", lineNum);
children.put("id", String.valueOf(lineNum));
children.put("name", name);
children.put("type", parts[0]);
children.put("value", name.replaceAll("<span.*</span> ", ""));
Expand All @@ -126,7 +126,7 @@ private static JSONArray toTreeJSON(ParsableLine parsableLines[], int lineNum) t
String name = getNameFromParts(parts);

JSONObject directive = new JSONObject();
directive.put("id", lineNum);
directive.put("id", String.valueOf(lineNum));
directive.put("name", name);
directive.put("type", parts[0]);
directive.put("value", name.replaceAll("<span.*</span> ", ""));
Expand Down Expand Up @@ -157,7 +157,7 @@ public static JSONObject toTreeJSON(Enclosure enclosure) {
String name = getNameFromParts(parts);

JSONObject children = new JSONObject();
children.put("id", 0);
children.put("id", "0");
children.put("name", name);
children.put("type", parts[0]);
children.put("value", name.replaceAll("<span.*</span> ", ""));
Expand Down Expand Up @@ -194,7 +194,7 @@ private static JSONArray toTreeJSON(Enclosure enclosure, int lineNum) {
String name = getNameFromParts(parts);

JSONObject children = new JSONObject();
children.put("id", lineNum);
children.put("id", String.valueOf(lineNum));
children.put("name", name);
children.put("type", parts[0]);
children.put("value", name.replaceAll("<span.*</span> ", ""));
Expand All @@ -216,7 +216,7 @@ private static JSONArray toTreeJSON(Enclosure enclosure, int lineNum) {
String name = getNameFromParts(parts);

JSONObject directive = new JSONObject();
directive.put("id", lineNum);
directive.put("id", String.valueOf(lineNum));
directive.put("name", name);
directive.put("type", parts[0]);
directive.put("value", name.replaceAll("<span.*</span> ", ""));
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/net/apachegui/web/ConfigurationTreeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.apachegui.web;

import apache.conf.parser.File;
import net.apachegui.conf.ConfFiles;
import net.apachegui.conf.Configuration;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/web/ConfigurationTree")
public class ConfigurationTreeController {

private final String LINE_TYPE_ENCLOSURE = "enclosure";

private JSONObject populateFileModifiedResponse(String file) {

JSONObject result = new JSONObject();
result.put("result", "success");
result.put("lastModifiedTime", new File(file).lastModified());
result.put("file", file);

return result;

}

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

String line;
if(lineType.equals(LINE_TYPE_ENCLOSURE)) {
line = "<" + type + " " + value + ">";
} else {
line = type + " " + value;
}

String originalContents = ConfFiles.replaceLinesInConfigFile(new File(file), new String[]{line}, lineOfStart, lineOfEnd);

Configuration.testChanges(file, originalContents);

JSONObject result = populateFileModifiedResponse(file);

return result.toString();
}

}
80 changes: 80 additions & 0 deletions src/main/webapp/WEB-INF/jsp/views/ConfigurationTree.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div data-dojo-type="dijit/Dialog" id="editLineDialog" title="Edit " style="width: 700px; display: none">
<table>
<tr class="dijitDialogPaneContentArea">
<td>
<label for='editLineType'>
Type:
</label>
</td>
<td>
<span id="editLineType" class="directive_type"></span>
</td>
</tr>
<tr class="dijitDialogPaneContentArea">
<td>
<label for='editLineValue'>
Value:
</label>
</td>
<td>
<input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" id="editLineValue" style="width: 630px;" />
</td>
</tr>
</table>

<input type="hidden" id="editLineLineType" value=""/>
<input type="hidden" id="editLineLineOfStart" value=""/>
<input type="hidden" id="editLineFile" value=""/>
<input type="hidden" id="editLineLineOfEnd" value=""/>

<div class="dijitDialogPaneActionBar">
<button id="editLineSubmit" data-dojo-type="dijit.form.Button" type="button">
Submit
</button>
<button id="editLineCancel" data-dojo-type="dijit.form.Button" type="button">
Cancel
</button>
</div>
</div>

<div data-dojo-type="dijit/Dialog" id="addLineDialog" title="Add " style="width: 700px; display: none">
<table>
<tr class="dijitDialogPaneContentArea">
<td>
<label for='addLineType'>
Type:
</label>
</td>
<td>
<input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" id="addLineType" style="width: 630px;" />
</td>
</tr>
<tr class="dijitDialogPaneContentArea">
<td>
<label for='addLineValue'>
Value:
</label>
</td>
<td>
<input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" id="addLineValue" style="width: 630px;" />
</td>
</tr>
</table>

<input type="hidden" id="addLineBeforeLineType" value=""/>
<input type="hidden" id="addLineLineType" value=""/>
<input type="hidden" id="addLineLineOfStart" value=""/>

<div class="dijitDialogPaneActionBar">
<button id="addLineSubmit" data-dojo-type="dijit.form.Button" type="button">
Submit
</button>
<button id="addLineCancel" data-dojo-type="dijit.form.Button" type="button">
Cancel
</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<jsp:include page="/jsp/ConfigurationTree.jsp" flush="true" />

<div id="global_tree_container">

Expand Down
Loading

0 comments on commit 6b28850

Please sign in to comment.