Skip to content

Commit

Permalink
Merge pull request #10 from pikesley/full-api
Browse files Browse the repository at this point in the history
Full api
  • Loading branch information
Sam Pikesley committed Jan 3, 2016
2 parents 0fb0c82 + e93a2af commit f5e902a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 182 deletions.
62 changes: 61 additions & 1 deletion lib/assets/javascripts/dashboard.js
@@ -1,3 +1,63 @@
function githubLink(json) {
return '<a href="' + json['url'] + '">Source</a>'
return '<a href="' + json['source-url'] + '">Source</a>'
}

function cellContent(id, content) {
return "<div class='col-md-12' id='#" + id + "'>" + content + "</div>"
}

function graph(json) {
ecks = Object.keys(json['data'][0])[0]
why = Object.keys(json['data'][0])[1]
var points = [
{
x: json['data'].map(function(item){ return item[ecks] }),
y: json['data'].map(function(item){ return item[why] }),
type: 'scatter'
}
]

var layout = {
title: json['title'] + ' (' + githubLink(json) + ')',
xaxis: {
tickformat: "%b %Y",
tickangle: 90
},
yaxis: {
title: why,
titlefont: {
size: 14,
color: '#7f7f7f'
}
},
margin: {
l: 50, r: 10
}
}

$('#data').html("<div id='" + json['id'] + "' class='col-md-12' style='height: 400px'></div>")
Plotly.newPlot(json['id'], points, layout)
}

function latestCell(json) {
d = json['data'][json['data'].length -1][json['date-field']]
fixedDate = moment(d, 'YYYY-MM-DD').format('Do MMMM')
age = moment(d, 'YYYY-MM-DD').fromNow()
content = '<h1><small>Last</small> '
content += json['title'] + ':</h1>'
if(json['special_fields']) {
content += '<h4>'

json['special_fields'].forEach(function(field) {
content += json['data'][json['data'].length -1][field]
content += ' '
})

content += '</h4>'
}
content += '<h2>' + fixedDate + '</h2>'
content += '<h3>(' + age + ')</h3>'
content += githubLink(json)

return cellContent(json['id'], content)
}
7 changes: 5 additions & 2 deletions lib/dashboard.rb
Expand Up @@ -21,7 +21,6 @@

module Dashboard
class App < Sinatra::Base
set :views, 'lib/views'

helpers do
include Dashboard::Helpers
Expand All @@ -34,13 +33,17 @@ class App < Sinatra::Base
end

get '/:repo' do
# I have literally no idea
if params[:repo] == 'favicon'
return 200
end

respond_to do |wants|
headers 'Vary' => 'Accept'

wants.html do
@title = Cleaner.lookups[params[:repo]]['title']
erb :dashboard, layout: :default
# erb :grid, layout: :default
end

wants.json do
Expand Down
24 changes: 2 additions & 22 deletions lib/dashboard/assets.rb
@@ -1,27 +1,7 @@
module Dashboard
class App < Sinatra::Base
set :root, File.dirname(__FILE__)
set :public_folder, Proc.new { File.join(root, '..', "assets") }
set :views, 'lib/views'
set :public_folder, 'public'

set :sass, { :load_paths => [
"../assets/css"
]}

register Sinatra::AssetPack
assets do
serve '/js', from: '../assets/javascripts'
js :app, [
'/js/dashboard.js',
'/js/plotly-latest.min.js'
]

serve '/css', from: '../assets/css'
css :application, [
'/css/application.css'
]

js_compression :jsmin
css_compression :sass
end
end
end
2 changes: 1 addition & 1 deletion lib/dashboard/racks.rb
Expand Up @@ -4,7 +4,7 @@ class App < Sinatra::Base
conneg.set :accept_all_extensions, false
conneg.set :fallback, :html
conneg.ignore('/css/')
conneg.ignore('/js/')
conneg.ignore('/javascripts/')
conneg.provide [
:html,
:json
Expand Down
65 changes: 0 additions & 65 deletions lib/views/dataset.erb
Expand Up @@ -2,7 +2,6 @@

<script>
$.getJSON(document.URL, function(json) {
console.log(json['type'])
if (json['type'] === 'latest') {
$('#data').append(
latestCell(json)
Expand All @@ -12,68 +11,4 @@
graph(json)
}
})

function graph(json) {
ecks = Object.keys(json['data'][0])[0]
why = Object.keys(json['data'][0])[1]
var points = [
{
x: json['data'].map(function(item){ return item[ecks] }),
y: json['data'].map(function(item){ return item[why] }),
type: 'scatter'
}
]

var layout = {
title: json['title'] + ' (' + githubLink(json) + ')',
xaxis: {
tickformat: "%b %Y",
tickangle: 90
},
yaxis: {
title: why,
titlefont: {
size: 14,
color: '#7f7f7f'
}
},
margin: {
l: 50, r: 10
}
}

$('#data').html("<div id='" + json['id'] + "' class='col-md-12' style='height: 400px'></div>")
Plotly.newPlot(json['id'], points, layout)
}

function latestCell(json) {
d = json['data'][json['data'].length -1][json['date-field']]
fixedDate = moment(d, 'YYYY-MM-DD').format('Do MMMM')
age = moment(d, 'YYYY-MM-DD').fromNow()
content = '<h1><small>Last</small> '
content += json['title'] + ':</h1>'
if(json['special_fields']) {
content += '<h4>'

json['special_fields'].forEach(function(field) {
content += json['data'][json['data'].length -1][field]
content += ' '
})

content += '</h4>'
}
content += '<h2>' + fixedDate + '</h2>'
content += '<h3>(' + age + ')</h3>'
content += githubLink(json)

return cellContent(json['id'], content)
}

function githubLink(json) {
return '<a href="' + json['url'] + '">Source</a>'
}

function cellContent(id, content) {
return "<div class='col-md-12' id='#" + id + "'>" + content + "</div>"
}
</script>
86 changes: 0 additions & 86 deletions lib/views/grid.erb

This file was deleted.

7 changes: 3 additions & 4 deletions lib/views/includes/header.erb
Expand Up @@ -9,8 +9,7 @@
<script src='https://oss.maxcdn.com/respond/1.4.2/respond.min.js'></script>
<![endif]-->

<!-- <script src='//cdn.plot.ly/plotly-latest.min.js'></script> -->
<script src='/js/plotly-latest.min.js'></script>
<!--<script src='//cdn.plot.ly/plotly-latest.min.js'></script>-->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
Expand All @@ -22,6 +21,6 @@
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />

<link rel="stylesheet" href="/css/application.css" />

<link rel='icon' type='image/png' href='/assets/favicon.ico' />
<script src='/javascripts/dashboard.js'></script>
<script src='/javascripts/plotly-latest.min.js'></script>
<title><%= @title %></title>
1 change: 0 additions & 1 deletion lib/views/simple.erb
Expand Up @@ -2,7 +2,6 @@
<html lang='en'>
<head>
<%= erb :'includes/header' %>
<link rel="stylesheet" href="/public/simple.css" />
</head>

<body>
Expand Down

0 comments on commit f5e902a

Please sign in to comment.