From e1b700b76c9a2e43401e401e586e19be55226a6b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 31 Aug 2010 09:44:30 -0400 Subject: [PATCH] Basic directory listing on the web. --- src/paths.go | 6 +++++- web_frontend/index.html | 4 ++++ web_frontend/main.js | 29 +++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/paths.go b/src/paths.go index 896b5cd..7deab6f 100644 --- a/src/paths.go +++ b/src/paths.go @@ -34,7 +34,11 @@ func List(the_path string) (files vector.StringVector, err os.Error) { } for _, info := range fileinfos { - files.Push(info.Name) + name := info.Name + if info.IsDirectory() { + name += "/" + } + files.Push(name) } return files, nil } diff --git a/web_frontend/index.html b/web_frontend/index.html index 71f866d..ab951eb 100644 --- a/web_frontend/index.html +++ b/web_frontend/index.html @@ -5,6 +5,10 @@ +

List /

+ + + diff --git a/web_frontend/main.js b/web_frontend/main.js index 4fe11ca..27a695e 100644 --- a/web_frontend/main.js +++ b/web_frontend/main.js @@ -1,13 +1,12 @@ goog.provide('armadillo'); +goog.require('goog.array'); +goog.require('goog.dom'); goog.require('goog.net.XhrIo'); goog.require('goog.Uri.QueryData'); armadillo.Main = function() { - var callback = function(response) { - console.log('response = ' + response); - } - armadillo.Request('list', {}, callback); + armadillo.List('/'); }; /** @@ -22,3 +21,25 @@ armadillo.Request = function(action, extra_data, callback) { data.extend(extra_data); goog.net.XhrIo.send('/service', callback, 'POST', data); }; + +/** + * Updates the directory listing for a given path. + * @param {string} path Path to list; relative to jail. + */ +armadillo.List = function(path) { + var callback = function(e) { + var data = e.target.getResponseJson(); + if (data['status']) { + return; // Error. + } + goog.dom.setTextContent(goog.dom.getElement('pwd'), path); + var list = goog.dom.getElement('ls'); + goog.dom.removeChildren(list); + goog.array.forEach(data, function(file) { + var elm = goog.dom.createElement('li'); + goog.dom.setTextContent(elm, file); + goog.dom.appendChild(list, elm); + }); + } + armadillo.Request('list', {'path':path}, callback); +}; -- 2.43.5