Permalink
Browse files

Links example file, move hard-coded links to json file, some limited …

…error handling
  • Loading branch information...
1 parent 3ac6c73 commit f2ab2b28c256a9d61b5c0bdc24f32b88ba417c32 @TotallyInformation committed Apr 20, 2012
Showing with 49 additions and 62 deletions.
  1. +1 −0 README.md
  2. +34 −8 routes/index.js
  3. +5 −48 views/index.jade
  4. +1 −1 views/layout.jade
  5. +8 −5 views/utime.jade
View
@@ -10,6 +10,7 @@ Webmin.js is my first proper experiment with [Node.js](http://nodejs.org). I wan
* Creates an https server assigned to a free port (starting at 8000)
* Uses an external js file (example included as [docs/.secureme.example](./docs/.secureme.example)) that can be require'd to provide certificate and http basic authentication details.
* Uses a simple JSON variable to create a menu of links
+* Uses a JSON file to provide a grouped list of links for display on the index page. See [docs/links.json.example](./docs/links.json.example)
* Provides a [package.json](package.json) file for npm installation. You can check out the [github project](https://TotallyInformation@github.com/TotallyInformation/webmin.git) and run `npm install -d` at the command prompt to get the dependencies.
* Commands currently implemented:
View
@@ -29,7 +29,7 @@ function jk_cmd(cmd, callback) {
});
}
-var links = {
+var menu = {
'Home' : '/'
, 'Test' : '/test'
, 'Uptime' : '/utime'
@@ -49,6 +49,17 @@ var links = {
* Aptitude/npm/pecl
*/
+function getLinks(filename) {
+ var fs = require('fs');
+ var filename = filename || './links.json';
+
+ try {
+ return JSON.parse(fs.readFileSync(filename));
+ } catch(err) {
+ return {"Error": err};
+ }
+}
+
// Default parameters for cmdexec.jade template
var cmdParams = {};
// We have to reset these for each cmd... fn call
@@ -64,20 +75,34 @@ function setCmdParams() {
, cmdHint: "Enter a command"
, btnTxt: "Submit"
//, layout: "layoutname"
- , links: links
+ , menu: menu
};
}
/*
* Functions to render pages
*/
+/**
+ * Default index page for webmin.js
+ * @param {object} req HTTP Request object
+ * @param {object} res HTTP Response object
+ * @return {null}
+ */
exports.index = function(req, res){
+ /**
+ * @param {string} templateName
+ * @param {JSON} localVars variables required for the template:
+ * title: title string
+ * description: string
+ * menu: JSON, list of link-name:link as a menu
+ * links: JSON, list of link-name:link grouped by a group title
+ */
res.render('index', {
title: 'Node.js Webmin Replacement'
- , layout: 'layout.jade'
, description: 'Webmin replacement in Node.js<br>Use the menu at the top of the page to continue.'
- , links: links
+ , menu: menu
+ , links: getLinks() || {}
})
};
@@ -101,7 +126,8 @@ exports.test = function(req, res){
'<hr>' +
'Res.Locals: <pre>' + inspect(res.locals) + '</pre>' +
'Res: <pre>' + inspect(res) + '</pre>'
- , links: links
+ , menu: menu
+ , links: {}
})
};
@@ -113,7 +139,7 @@ exports.utime = function(req, res){
, uptime: secondsToString(os.uptime())
, loadavg: os.loadavg()[0] + ", " + os.loadavg()[1] + ", " + os.loadavg()[2]
, freemem: os.freemem()/1024
- , links: links
+ , menu: menu
})
};
@@ -186,14 +212,14 @@ exports.fsedit = function(req, res){
res.render('fsedit', {
title: "Edit File"
- , links: links
+ , menu: menu
, file: edFile
, out: out
});
};
/*
* To Do
- * List log files with links to each (tail)
+ * List log files with menu to each (tail)
* Editor
*/
View
@@ -8,51 +8,8 @@ block content
p!= description
hr
- h3 Lnks
- ul
- li
- a(href="https://totallyinformation.net/_man.php") Man Pages
- li
- a(href="https://totallyinformation.net:8080/") Webmin
- li
- a(href="https://totallyinformation.net/wiki") Knowledgebase
- li
- a(href="https://totallyinformation.net/doc/") Server Doc Pages
- li
- a(href="https://totallyinformation.net/ajaxterm/") aTerm
- h3 Testing Only
- ul
- li
- a(href="https://totallyinformation.net/wa/") Webalizer
- li
- a(href="https://totallyinformation.net/fm/") ajaxPlorer
- li
- a(href="https://totallyinformation.net/extplorer/") Extplorer
- li
- a(href="https://totallyinformation.net/pa/") Postfix Admin
- li
- a(href="https://totallyinformation.net/la/") Log Analyzer
- li
- a(href="https://totallyinformation.net/wm2/") Webmail Lite
- li
- a(href="https://totallyinformation.net/ma/") ISOqLog
- li
- a(href="https://totallyinformation.net/ss/") EpyLog
- li
- a(href="https://totallyinformation.net/awstats/") AWStats
- li
- a(href="https://totallyinformation.net/ti-info/") Old Knowledgebase
- li
- a(href="https://totallyinformation.net/awefull/") Awefull
- li
- a(href="https://totallyinformation.net/kb/") PmWiki
- li
- a(href="https://totallyinformation.net/m/") MediaWiki
- li
- a(href="https://totallyinformation.net/wm-beta/") Roundcube Beta
- li
- a(href="https://totallyinformation.net/mysh") Test Shell
- li
- a(href="https://totallyinformation.net/moin") MoinMoin Wiki
- li
- a(href="https://totallyinformation.net/wiki") Knowledgebase
+ each link, name in links
+ h4 #{name}
+ each lnk, i in link
+ li
+ a(href=lnk)= i
View
@@ -8,7 +8,7 @@ html
//- Show menu on every page using json 'links' var
div#menu
ul(class="csl")
- each link, name in links
+ each link, name in menu
li
a(href=link) #{name}
block content
View
@@ -1,5 +1,8 @@
-//- comment
-h3= title
-p Uptime: #{uptime}
-p Load Average: #{loadavg}
-p Free Memory: #{freemem}
+extends layout
+
+block content
+ //- comment
+ h3= title
+ p Uptime: #{uptime}
+ p Load Average: #{loadavg}
+ p Free Memory: #{freemem}

0 comments on commit f2ab2b2

Please sign in to comment.