-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.js
56 lines (45 loc) · 1.57 KB
/
frontend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
var $ = require('jquery');
var io = require('socket.io-client');
var env = process.env.NODE_ENV || 'production';
var config = require('./config/config.json')[env];
var debugModule = require('debug');
config.logging && debugModule.enable('socket');
var debug = debugModule('socket');
$(function() {
var GeneralView = require('./views/general.js');
var MapView = require('./views/map.js');
var FlowGraph = require('./views/flow.js');
var CurrenciesStore = require('./stores/currencies.js');
var currenciesStore = new CurrenciesStore();
var socket = io('http://' + config.socketHost + ':' + config.socketPort + '/');
socket.on('connect', function () {
debug('Socket connected!');
});
socket.on('message', function (data) {
debug(data);
currenciesStore.updateData(data);
});
socket.on('reset', function (data) {
debug('Reset');
// todo@ Implement it
});
var generalView = new GeneralView({
model: currenciesStore
});
$('header').append(generalView.render().el);
var mapView = new MapView({
title: 'Processed operations',
width: 750,
height: 450,
model: currenciesStore
});
$('body').append(mapView.render().el);
var flowGraph = new FlowGraph({
collection: currenciesStore.flowCollection,
title: 'Currencies flow graph',
width: Math.max($(window).width() - 50, 500),
height: 1200
});
$('body').append(flowGraph.render().el);
});