Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding button example

  • Loading branch information...
commit 30473076b826e5c359ec8d6959256511f1b26744 1 parent 762211a
@jeffsu authored
View
18 mock/button.rb
@@ -0,0 +1,18 @@
+require 'sinatra'
+require 'haml'
+require 'uri'
+require 'net/http'
+
+get '/' do
+ if btn = params[:button]
+ Net::HTTP.post_form(URI.parse('http://localhost:3000/stats/buttons'), { btn => 1 })
+ end
+
+ haml <<END
+%button(onclick="location.href='/?button=one'") One
+%button(onclick="location.href='/?button=two'") Two
+%button(onclick="location.href='/?button=three'") Three
+END
+
+
+end
View
3  mock/example.yml
@@ -63,6 +63,9 @@ stats:
urls:
strategy: counter
+ buttons:
+ strategy: counter
+
response-times:
strategy: average
View
11 mock/my-server.js
@@ -18,6 +18,7 @@ var upbeatClient = new upbeat.Client({ redis: { port: 6379, host: '127.0.0.1' }
var urls = upbeatClient.getStats('urls');
var times = upbeatClient.getStats('response-times');
var success = upbeatClient.getStats('success');
+var request = require('request');
var app = express();
app.configure(function () {
@@ -26,6 +27,16 @@ app.configure(function () {
app.use(app.router);
});
+app.get('/', function (req, res) {
+ var btn = req.query.button;
+ var form = {};
+ form[btn] = 1;
+ if (btn) request.post('http://localhost:3000/stats/buttons').form(form);
+ res.end('<html><ol><li><a href="/?button=1">One</a></li>' +
+ '<li><a href="/?button=2">Two</a></li>' +
+ '<li><a href="/?button=3">Three</a></li></ol></html>');
+});
+
app.get('/:speed/:uptime', function (req, res) {
var shortest = (SPEEDS[req.params.speed] || SPEEDS.average) - 100;
var delta = Math.round(Math.random() * 200);
View
7 www/app.ms
@@ -12,13 +12,13 @@ module.exports = #(server, config) {
week: []
};
- for (var i=12; i>0; i--) {
+ for (var i=11; i>=0; i--) {
LABELS.min.push(i * 5);
LABELS.hour.push(i * 5);
}
- for (var i=24; i>0; i--) LABELS.day.push(i);
- for (var i=7; i>0; i--) {
+ for (var i=23; i>=0; i--) LABELS.day.push(i);
+ for (var i=6; i>=0; i--) {
LABELS.week.push(i);
for (var j=0; j<5; j++) {
LABELS.week.push('');
@@ -157,6 +157,7 @@ module.exports = #(server, config) {
app.post('/stats/:stats', #(req, res, next) {
var stats = getResource(req.params);
+ console.log(req.body);
for (var k in req.body) {
var val = parseInt(req.body[k]);
if (val > 0) stats.inc(k, val);
View
1  www/public/javascripts/charts.js
@@ -25,6 +25,7 @@ function startChart(par) {
}
}
+
if (!first) {
return $div.chart({ values: payload.data });
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.