# appends the rendered view to the DOM.
main = (graph_list_data) ->
graphs = new GraphList graph_list_data
- view = new GraphListView { 'collection': graphs }
+ view = new GraphListView { 'collection': graphs }
$ '#content .inner' .append view.el
# URL to query for saved graph JSON data.
-graph_list_url = '/graphslist'
+graph_list_url = '/graphs.json'
jQuery.ajax do
url : graph_list_url
fs = require 'fs'
path = require 'path'
yaml = require 'js-yaml'
+Seq = require 'seq'
{existsSync:exists} = path
{mkdirp, mkdirpAsync} = require '../mkdirp'
+{ readJSONFilesAsync,
+} = require '../files'
+
Controller = require '../controller'
console.error "GraphController.autoload(#id, #{typeof cb}) -->\nerr"
cb err
- # GET /graphs
+ # GET /graphs.:format?
index: (req, res) ->
- res.render 'graph/index'
+ # if format is json, then return the graph JSON
+ if (req.params.format == 'json')
+ pattern = @dataDir + "/*.json"
+ Seq()
+ # find list of data/graph/*.json files, send back the objects
+ .seq -> readJSONFilesAsync pattern, this
+ # remove filepath info
+ .seq (graphs) -> res.send _.values graphs
+ else
+ res.render 'graph/index'
# GET /graphs/:graph
show: (req, res) ->
res.send { result:"error", message:msg }, 501
else
res.send { result:"ok" }
-
+
module.exports = exports = GraphController
{existsSync:exists} = path
{exec, spawn} = require 'child_process'
{mkdirp, mkdirpAsync} = require './mkdirp'
-{ readFilesAsync, readJSONFilesAsync,
+{ readFilesAsync,
} = require './files'
console.error that if err.stack
res.send { error:String(err), partial_data:data }
-# FIXME: Make /graphs.json do this instead of graphslist.
-# : Can I use Seq .par to read in data and also parse the JSON?
-# Sends a JSON list of saved graphs. These
-# can be used to instantiate a GraphList of Graph Models.
-app.get '/graphslist' (req, res) ->
- Seq()
- # find list of data/graph/*.json files, send back the objects
- .seq -> readJSONFilesAsync "#DATA/graphs/*.json", this
- # remove filepath info
- .seq (graphs) -> res.send _.values graphs
-
app.get '/', (req, res) ->
res.render 'dashboard'
else
res.send "$ #cmd\n\n#stdout\n\n#stderr", 200
-
# }}}
exports import {