Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added edit, new and show view in a new dataset folder, updated css rules. Also added a bugfix: if data was pushed to a dataset with no variables, the app would crash. Not anymore.
- Loading branch information
Showing
5 changed files
with
242 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
extends ../layout | ||
|
||
block content | ||
div.col-md-6 | ||
h1=dataset.name | ||
div.col-md-12 | ||
h2 Api Keys | ||
div.col-md-6 | ||
h3 Read | ||
form(action="/datasets/update/key",method="POST") | ||
input(type="hidden",value="read",name="key") | ||
div.form-group | ||
input(type="hidden",value="#{dataset._id}",name="id") | ||
pre=dataset.read_key | ||
button#newReadKey.btn.btn-warning(role="submit") Regenerate | ||
div.col-md-6 | ||
h3 Write | ||
form(action="/datasets/update/key",method="POST") | ||
input(type="hidden",value="write",name="key") | ||
input(type="hidden",value="#{dataset._id}",name="id") | ||
pre=dataset.write_key | ||
button#newWriteKey.btn.btn-warning(role="submit") Regenerate | ||
div.col-md-12 | ||
h2 Options | ||
div.col-md-6 | ||
form(action="/datasets/#{dataset._id}",method="post",name="updateDataset") | ||
div.form-group | ||
label(for="inputName") Name: | ||
input#inputName.form-control(type="text", value="#{dataset.name}", name="name") | ||
div.form-group | ||
label(for="inputPublic") Public: | ||
input#inputPublic(type="checkbox", name="public", checked="#{dataset.public}") | ||
label Variables: | ||
ul#variablesList.list-unstyled | ||
script. | ||
var varId=1; | ||
if dataset.data | ||
- each variable, i in dataset.data | ||
script. | ||
varId++ | ||
li.variable-option | ||
button.btn.btn-link.delete-variable-btn | ||
span.glyphicon.glyphicon-minus-sign | ||
| Title: | ||
input.form-control.variable-input(type="text", value="#{variable.name}", name=i) | ||
| tag: #{i} | ||
li.add-variable | ||
button.btn.btn-link.add-variable-btn | ||
span.glyphicon.glyphicon-plus-sign | ||
input(type="hidden",value="PUT",name="_method") | ||
button#btnSubmit.btn.btn-success(type="submit"). | ||
Save changes | ||
|
||
block inPageScript | ||
script. | ||
// Add new variable input if add button clicked | ||
$(".add-variable-btn").click(function(e) { | ||
e.preventDefault(); // prevents button from submitting | ||
|
||
var html = "<li class='variable-option'><button class='btn btn-link delete-variable-btn'><span class='glyphicon glyphicon-minus-sign'></span></button> Title: <input class='form-control variable-input', type='text', placeholder='variable%s', name='var%s'> tag: var%s</li>".replace(/%s/g, varId); | ||
$(html).insertBefore(".add-variable") | ||
varId++; | ||
}); | ||
|
||
// Delete variable input if delete button clicked | ||
// We use the 'on' method here because otherwise newly inserted DOM elements wouldn't trigger | ||
$(document).on("click", ".delete-variable-btn", function(e) { | ||
e.preventDefault(); // prevents button from submitting | ||
|
||
$(this).closest("li").remove(); | ||
varId--; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
extends ../layout | ||
|
||
block content | ||
div.col-md-3 | ||
h1 New dataset | ||
form#formAddDataset(name="addDataset", method="post", action="/datasets") | ||
div.form-group | ||
label(for="inputName") Name: | ||
input#inputName.form-control(type="text", placeholder="ex: Weather Data", name="name") | ||
div.form-group | ||
label(for="inputPublic") Public: | ||
input#inputPublic(type="checkbox", name="public") | ||
label Variables: | ||
ul#variablesList.list-unstyled | ||
li.add-variable | ||
button.btn.btn-link.add-variable-btn | ||
span.glyphicon.glyphicon-plus-sign | ||
button#btnSubmit.btn.btn-success(type="submit"). | ||
Create | ||
|
||
block inPageScript | ||
script. | ||
// used to add the correct tag to each new variable input | ||
var varId = 1; | ||
|
||
// Add new variable input if add button clicked | ||
$(".add-variable-btn").click(function(e) { | ||
e.preventDefault(); // prevents button from submitting | ||
|
||
var html = "<li class='variable-option'><button class='btn btn-link delete-variable-btn'><span class='glyphicon glyphicon-minus-sign'></span></button> Title: <input class='form-control variable-input', type='text', placeholder='ex: variable%s', name='var%s'> tag: var%s</li>".replace(/%s/g, varId); | ||
$(html).insertBefore(".add-variable") | ||
varId++; | ||
}); | ||
|
||
// Delete variable input if delete button clicked | ||
// we use the 'on' method here because otherwise newly inserted DOM elements wouldn't trigger 'click' | ||
$(document).on("click", ".delete-variable-btn", function(e) { | ||
e.preventDefault(); // prevents button from submitting | ||
|
||
$(this).closest("li").remove(); | ||
varId--; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
extends ../layout | ||
|
||
block content | ||
h1=dataset.name | ||
ul.list-unstyled | ||
li | ||
p | ||
strong Created at: | ||
| #{dataset.created_at} | ||
p | ||
strong Last entry at: | ||
| #{dataset.last_entry_at} | ||
p | ||
strong Entries number: | ||
| #{dataset.entries_number} | ||
|
||
if dataset.data | ||
- each variable, i in dataset.data | ||
div.col-md-6 | ||
if variable.name | ||
h3.text-center #{variable.name} | ||
else | ||
h3.text-center #{i} | ||
canvas(id="#{i}_canvas", height="400px", width="800px") | ||
|
||
script(type="text/javascript", src="/javascripts/Chart.min.js") | ||
script. | ||
// Unserialize dataset object so that we can interract with it from the script | ||
var datasetObject =!{JSON.stringify(dataset)} | ||
var data = datasetObject.data | ||
|
||
// For each variable in the dataset, extract title, tag name and values | ||
// then instanciate the chart with theses values | ||
for (var property in data) { | ||
if (data.hasOwnProperty(property)) { | ||
var varTag = property; | ||
var varData = data[property]; | ||
var label = varData.name; | ||
var xLabels = []; | ||
var yValues = []; | ||
|
||
for (var i in varData.values) { | ||
// extract values | ||
yValues.push(varData.values[i][0]); | ||
// extract timestamp in a Date object and format the output in a string | ||
var t = new Date(varData.values[i][1]); | ||
var cleanTime = t.getDay() +"/"+ t.getMonth() + " " + t.getHours() + ":" + t.getMinutes() | ||
// add formated timestamp to the array holding values for x axis | ||
xLabels.push(cleanTime) | ||
} | ||
} | ||
|
||
var chartData = { | ||
labels: xLabels, | ||
datasets: [ | ||
{ | ||
label: label, | ||
fillColor: "rgba(220,220,220,0.2)", | ||
strokeColor: "rgba(220,220,220,1)", | ||
pointColor: "rgba(220,220,220,1)", | ||
pointStrokeColor: "#fff", | ||
pointHighlightFill: "#fff", | ||
pointHighlightStroke: "rgba(220,220,220,1)", | ||
data: yValues | ||
} | ||
] | ||
} | ||
|
||
var ctx = document.getElementById(varTag+"_canvas").getContext("2d"); | ||
|
||
new Chart(ctx).Line(chartData, { | ||
bezierCurve: false | ||
}); | ||
} |