Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend ui #4

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.py[cod]

config.coffee
# C extensions
*.so

Expand Down
3 changes: 1 addition & 2 deletions app.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
app = require './app/main'
http = require 'http'

server = (http.createServer app).listen process.env.PORT or 43313

server = (http.createServer app).listen 80
console.log "Express server listening on port %d in %s mode", server.address().port, app.settings.env
41 changes: 41 additions & 0 deletions app/routes/couchdb-importer.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Underscore utility
_ = require("underscore")

# Miso library
Miso = require("miso.dataset")

# Nano library
nano = require("nano")

#
# * The Couchdb importer is responsible for fetching data from a CouchDB
# * database.
# *
# * Parameters:
# * options
# * auth - Authentication to the database server
# * host - Address to the database server
# * db - Name of the database
# * query - Query to make to the database
#
Miso.Importers.Couchdb = (options) ->
_.defaults this, options,
auth: ""
host: ""
db: ""
query: ""


# Generate the CouchDB url
url = [@auth, @host, @db].join("")

# Establish a connection
@connection = nano([url, @query and "?" + @query].join(""))

_.extend Miso.Importers.Couchdb::,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to explicitly say .prototype just to be clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't need to use these anymore ever since I switched from miso dataset to google

fetch: (options) ->
if _.isFunction(@view)
@view @connection, (err, data) ->
return options.error(err) if err
options.success data.rows

59 changes: 59 additions & 0 deletions app/routes/couchdb-parser.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Underscore utility
_ = require("underscore")

# Miso library
Miso = require("miso.dataset")
Miso.Parsers.Couchdb = (data, options) ->

_.extend Miso.Parsers.Couchdb::,
parse: (rows) ->
columns = undefined
valueIsObject = undefined
data = {}

# No data to process
unless rows.length
return (
columns: []
data: {}
)

# If doc property is present, use this as the value
if _.isObject(rows[0].doc)

# Iterate over every row and swap the doc for the value
_.each rows, (row) ->

# Swap the value for the document
row.value = row.doc


# Set columns based off the first row.
if _.isObject(rows[0].value)
columns = _.keys(rows[0].value)

# Set this flag for assignment later on
valueIsObject = true

# If the first row is not an object, use key/val
else
columns = ["key", "value"]

# Ensure each column has an array for data.
_.each columns, (column) ->
data[column] = []


# Iterate over every row and column and insert the data fetched
# correctly.
_.each rows, (row) ->
_.each columns, (column) ->

# Add to the respective column, if its not an object, use key/val
data[column].push (if valueIsObject then row.value[column] else row[column])



# Expected format for dataset.
columns: columns
data: data
Loading