Got directory perusing mostly working

This commit is contained in:
Kaelin Hooper
2016-06-28 18:44:22 -07:00
parent 4ead3755dc
commit d564be4bdd
3 changed files with 44 additions and 20 deletions
@@ -21,35 +21,54 @@ namespace PerfDataService.Controllers
[HttpGet]
public string Get([FromQuery]string path)
{
// Make sure the user provided a non-null query string parameter 'path'
if (String.IsNullOrEmpty(path))
{
return null; // TODO: Form proper respone notifying user that the path passed was nonexistent
}
path = cleanUpPath(path);
if (path == null) { return null; } // TODO: Form proper response
/* Create Dictionary to be returned as JSON in response */
// Dictionary containing entire hierarchy
Dictionary<string, object> tree = new Dictionary<string, object>();
tree.Add("status", "OK");
tree.Add("name", path.Split('\\').Last());
tree.Add("name", path.Split('/').Last());
tree.Add("path", path);
tree.Add("type", getTypeOfItem(path));
List<object> children = getChildrenForPath(path);
tree.Add("children", children);
try
{
List<object> children = getChildrenForPath(path);
tree.Add("children", children);
} catch (UnauthorizedAccessException)
{
// TODO: Form a proper response for this
}
string json = JsonConvert.SerializeObject(tree, Formatting.Indented);
if (json == null)
{
// Form a response using HttpResponseException
// TODO: Form a response using HttpResponseException
}
return json;
}
public string cleanUpPath(string path)
{
// Make sure the user provided a non-null query string parameter 'path'
if (String.IsNullOrEmpty(path))
{
return null; // TODO: Form proper respone notifying user that the path passed was nonexistent
}
if (path.Last() == '/' && !path.Equals("C:/") && !path.Equals("C:\\")) {
path = path.Substring(0, path.Length - 1);
}
return path;
}
public List<object> getChildrenForPath(string pathToItem)
{
List<object> childrenContainer = new List<object>();
@@ -1,13 +1,14 @@
function Delegate() {
var self = this;
var domain = "http://localhost:5000";
self.domain = "http://localhost:5000";
self.defaultDirectoryTreePath = "C:/Users/t-kahoop/Development/perfview/src/PerfView/bin/Debug";
this.log = function log(status) {
$("#statusBar span").text(status);
}
this.httpGet = function httpGet(url, callback) {
url = domain + url;
url = self.domain + url;
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
@@ -22,6 +23,16 @@ function Delegate() {
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
this.changeDirectoryTreePath = function changeDirectoryTreePath(path) {
self.httpGet("/api/data/open?path=" + path, function (response) {
console.log(response);
var items = response.children;
var htmlFromJSON = createTreeFromJSON(items);
$("#directoryTree").html(htmlFromJSON);
delegate.log("Completed: Directory Tree Path Update");
});
}
}
delegate = new Delegate();
@@ -17,7 +17,7 @@
<div class="wrapper">
<div id="sideBarContainer">
<input id="dirSelect" list="directories" type="text">
<input id="dirSelect" list="directories" type="text" onchange="delegate.changeDirectoryTreePath(this.value)">
<datalist id="directories">
<option value="dir0"/>
<option value="dir1"/>
@@ -33,7 +33,7 @@
</div>
<div id="treeContainer">
<ul class="mktree" id="mainTree">
<ul class="mktree" id="directoryTree">
</ul>
</div>
@@ -168,13 +168,7 @@
<script>
// GET all directories and items and append them to tree view
$(document).ready(function () {
treeView = delegate.httpGet("/api/data/open?path=C:\\Users\\t-kahoop\\Development\\perfview\\src\\PerfView\\bin\\Debug", function (response) {
console.log(response);
var items = response.children;
var htmlFromJSON = createTreeFromJSON(items);
$("#mainTree").append(htmlFromJSON);
delegate.log("Completed: View");
});
delegate.changeDirectoryTreePath(delegate.defaultDirectoryTreePath);
});
// Recursively parse JSON tree