Skip to content
This repository was archived by the owner on Mar 31, 2021. It is now read-only.

Commit e7be5ac

Browse files
committed
Basic log browser UI
1 parent 31dda2f commit e7be5ac

30 files changed

+20036
-3
lines changed

app.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@ var config = require('./config.json');
88
var servers = require('./server');
99
var request = require('request');
1010
var _ = require('underscore');
11+
var socketio = require('socket.io');
1112

1213
var app = module.exports = express.createServer();
14+
var io = socketio.listen(app);
1315

1416
// Configuration
1517

1618
app.configure(function(){
1719
app.set('views', __dirname + '/views');
1820
app.set('view engine', 'jade');
21+
app.set('view options', {
22+
layout: false
23+
});
24+
// make a custom html template
25+
app.register('.html', {
26+
compile: function(str, options){
27+
return function(locals){
28+
return str;
29+
};
30+
}
31+
});
1932
app.use(express.bodyParser());
2033
app.use(express.methodOverride());
2134
app.use(app.router);
@@ -29,6 +42,10 @@ app.configure('development', function(){
2942
var numServers = config.numServers;
3043
var startPort = config.startPort;
3144

45+
app.get('/', function(req, res){
46+
res.render('index.html');
47+
});
48+
3249
app.listen(startPort, function(){
3350
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
3451
});
@@ -57,6 +74,7 @@ var pad = function(number, length) {
5774
return str;
5875
}
5976

77+
var sockets = [];
6078
var logs = [];
6179
var peers = [];
6280
_.each(_.range(numServers), function(idx) {
@@ -72,12 +90,26 @@ _.each(_.range(numServers), function(idx) {
7290
var args = _.toArray(arguments);
7391
args.unshift(prefix + date + "[" + port + "]");
7492
console.log.apply(console, args);
93+
94+
if(sockets[port]) {
95+
var socket = sockets[port];
96+
socket.emit("log", args);
97+
}
7598
}
7699

77100
peers.push(port);
78101
logs.push(log);
79102

80103
servers.create(port, log);
104+
105+
io.of("/" + port).on('connection', function (socket) {
106+
sockets[port] = socket;
107+
});
108+
});
109+
110+
io.sockets.on('connection', function (socket) {
111+
socket.emit("setup", {ports: peers});
112+
start();
81113
});
82114

83115
var start = null;
@@ -89,7 +121,7 @@ for(var port in senders) {
89121
sender("/setup", {peers: peers}, function(err, res) {
90122
setupCompleteCount--;
91123
if(setupCompleteCount === 0) {
92-
start();
124+
93125
}
94126
});
95127
}

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"numServers": 3,
3-
"startPort": 6000
3+
"startPort": 3000
44
}
4.25 KB
Loading
4.25 KB
Loading

public/js/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
## 2.0 BOOTSTRAP JS PHILOSOPHY
2+
These are the high-level design rules which guide the development of Bootstrap's plugin apis.
3+
4+
---
5+
6+
### DATA-ATTRIBUTE API
7+
8+
We believe you should be able to use all plugins provided by Bootstrap purely through the markup API without writing a single line of javascript.
9+
10+
We acknowledge that this isn't always the most performant and sometimes it may be desirable to turn this functionality off altogether. Therefore, as of 2.0 we provide the ability to disable the data attribute API by unbinding all events on the body namespaced with `'data-api'`. This looks like this:
11+
12+
$('body').off('.data-api')
13+
14+
To target a specific plugin, just include the plugins name as a namespace along with the data-api namespace like this:
15+
16+
$('body').off('.alert.data-api')
17+
18+
---
19+
20+
### PROGRAMATIC API
21+
22+
We also believe you should be able to use all plugins provided by Bootstrap purely through the JS API.
23+
24+
All public APIs should be single, chainable methods, and return the collection acted upon.
25+
26+
$(".btn.danger").button("toggle").addClass("fat")
27+
28+
All methods should accept an optional options object, a string which targets a particular method, or null which initiates the default behavior:
29+
30+
$("#myModal").modal() // initialized with defaults
31+
$("#myModal").modal({ keyboard: false }) // initialized with now keyboard
32+
$("#myModal").modal('show') // initializes and invokes show immediately afterqwe2
33+
34+
---
35+
36+
### OPTIONS
37+
38+
Options should be sparse and add universal value. We should pick the right defaults.
39+
40+
All plugins should have a default object which can be modified to effect all instance's default options. The defaults object should be available via `$.fn.plugin.defaults`.
41+
42+
$.fn.modal.defaults = { … }
43+
44+
An options definition should take the following form:
45+
46+
*noun*: *adjective* - describes or modifies a quality of an instance
47+
48+
examples:
49+
50+
backdrop: true
51+
keyboard: false
52+
placement: 'top'
53+
54+
---
55+
56+
### EVENTS
57+
58+
All events should have an infinitive and past participle form. The infinitive is fired just before an action takes place, the past participle on completion of the action.
59+
60+
show | shown
61+
hide | hidden
62+
63+
---
64+
65+
### CONSTRUCTORS
66+
67+
Each plugin should expose it's raw constructor on a `Constructor` property -- accessed in the following way:
68+
69+
70+
$.fn.popover.Constructor
71+
72+
---
73+
74+
### DATA ACCESSOR
75+
76+
Each plugin stores a copy of the invoked class on an object. This class instance can be accessed directly through jQuery's data API like this:
77+
78+
$('[rel=popover]').data('popover') instanceof $.fn.popover.Constructor
79+
80+
---
81+
82+
### DATA ATTRIBUTES
83+
84+
Data attributes should take the following form:
85+
86+
- data-{{verb}}={{plugin}} - defines main interaction
87+
- data-target || href^=# - defined on "control" element (if element controls an element other than self)
88+
- data-{{noun}} - defines class instance options
89+
90+
examples:
91+
92+
// control other targets
93+
data-toggle="modal" data-target="#foo"
94+
data-toggle="collapse" data-target="#foo" data-parent="#bar"
95+
96+
// defined on element they control
97+
data-spy="scroll"
98+
99+
data-dismiss="modal"
100+
data-dismiss="alert"
101+
102+
data-toggle="dropdown"
103+
104+
data-toggle="button"
105+
data-toggle="buttons-checkbox"
106+
data-toggle="buttons-radio"

public/js/application.js

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
2+
// IT'S ALL JUST JUNK FOR OUR DOCS!
3+
// ++++++++++++++++++++++++++++++++++++++++++
4+
5+
!function ($) {
6+
7+
$(function(){
8+
9+
// Disable certain links in docs
10+
$('section [href^=#]').click(function (e) {
11+
e.preventDefault()
12+
})
13+
14+
// make code pretty
15+
window.prettyPrint && prettyPrint()
16+
17+
// add-ons
18+
$('.add-on :checkbox').on('click', function () {
19+
var $this = $(this)
20+
, method = $this.attr('checked') ? 'addClass' : 'removeClass'
21+
$(this).parents('.add-on')[method]('active')
22+
})
23+
24+
// position static twipsies for components page
25+
if ($(".twipsies a").length) {
26+
$(window).on('load resize', function () {
27+
$(".twipsies a").each(function () {
28+
$(this)
29+
.tooltip({
30+
placement: $(this).attr('title')
31+
, trigger: 'manual'
32+
})
33+
.tooltip('show')
34+
})
35+
})
36+
}
37+
38+
// add tipsies to grid for scaffolding
39+
if ($('#grid-system').length) {
40+
$('#grid-system').tooltip({
41+
selector: '.show-grid > div'
42+
, title: function () { return $(this).width() + 'px' }
43+
})
44+
}
45+
46+
// fix sub nav on scroll
47+
var $win = $(window)
48+
, $nav = $('.subnav')
49+
, navTop = $('.subnav').length && $('.subnav').offset().top - 40
50+
, isFixed = 0
51+
52+
processScroll()
53+
54+
$win.on('scroll', processScroll)
55+
56+
function processScroll() {
57+
var i, scrollTop = $win.scrollTop()
58+
if (scrollTop >= navTop && !isFixed) {
59+
isFixed = 1
60+
$nav.addClass('subnav-fixed')
61+
} else if (scrollTop <= navTop && isFixed) {
62+
isFixed = 0
63+
$nav.removeClass('subnav-fixed')
64+
}
65+
}
66+
67+
// tooltip demo
68+
$('.tooltip-demo.well').tooltip({
69+
selector: "a[rel=tooltip]"
70+
})
71+
72+
$('.tooltip-test').tooltip()
73+
$('.popover-test').popover()
74+
75+
// popover demo
76+
$("a[rel=popover]")
77+
.popover()
78+
.click(function(e) {
79+
e.preventDefault()
80+
})
81+
82+
// button state demo
83+
$('#fat-btn')
84+
.click(function () {
85+
var btn = $(this)
86+
btn.button('loading')
87+
setTimeout(function () {
88+
btn.button('reset')
89+
}, 3000)
90+
})
91+
92+
// carousel demo
93+
$('#myCarousel').carousel()
94+
95+
// javascript build logic
96+
var inputsComponent = $("#components.download input")
97+
, inputsPlugin = $("#plugins.download input")
98+
, inputsVariables = $("#variables.download input")
99+
100+
// toggle all plugin checkboxes
101+
$('#components.download .toggle-all').on('click', function (e) {
102+
e.preventDefault()
103+
inputsComponent.attr('checked', !inputsComponent.is(':checked'))
104+
})
105+
106+
$('#plugins.download .toggle-all').on('click', function (e) {
107+
e.preventDefault()
108+
inputsPlugin.attr('checked', !inputsPlugin.is(':checked'))
109+
})
110+
111+
$('#variables.download .toggle-all').on('click', function (e) {
112+
e.preventDefault()
113+
inputsVariables.val('')
114+
})
115+
116+
// request built javascript
117+
$('.download-btn').on('click', function () {
118+
119+
var css = $("#components.download input:checked")
120+
.map(function () { return this.value })
121+
.toArray()
122+
, js = $("#plugins.download input:checked")
123+
.map(function () { return this.value })
124+
.toArray()
125+
, vars = {}
126+
, img = ['glyphicons-halflings.png', 'glyphicons-halflings-white.png']
127+
128+
$("#variables.download input")
129+
.each(function () {
130+
$(this).val() && (vars[ $(this).prev().text() ] = $(this).val())
131+
})
132+
133+
$.ajax({
134+
type: 'POST'
135+
, url: 'http://bootstrap.herokuapp.com'
136+
, dataType: 'jsonpi'
137+
, params: {
138+
js: js
139+
, css: css
140+
, vars: vars
141+
, img: img
142+
}
143+
})
144+
})
145+
146+
})
147+
148+
// Modified from the original jsonpi https://github.com/benvinegar/jquery-jsonpi
149+
$.ajaxTransport('jsonpi', function(opts, originalOptions, jqXHR) {
150+
var url = opts.url;
151+
152+
return {
153+
send: function(_, completeCallback) {
154+
var name = 'jQuery_iframe_' + jQuery.now()
155+
, iframe, form
156+
157+
iframe = $('<iframe>')
158+
.attr('name', name)
159+
.appendTo('head')
160+
161+
form = $('<form>')
162+
.attr('method', opts.type) // GET or POST
163+
.attr('action', url)
164+
.attr('target', name)
165+
166+
$.each(opts.params, function(k, v) {
167+
168+
$('<input>')
169+
.attr('type', 'hidden')
170+
.attr('name', k)
171+
.attr('value', typeof v == 'string' ? v : JSON.stringify(v))
172+
.appendTo(form)
173+
})
174+
175+
form.appendTo('body').submit()
176+
}
177+
}
178+
})
179+
180+
}(window.jQuery)

0 commit comments

Comments
 (0)