1+ /**
2+ * Created by Alexey Ostrovsky.
3+ * Date: 05.08.13
4+ * Time: 19:12
5+ */
6+
7+
8+ var mongoose = require ( 'mongoose' ) ;
9+
10+ // data model
11+ var Bubble = mongoose . model ( 'Bubble' , {
12+ specURI : String ,
13+ section : Number ,
14+ x : String ,
15+ y : String ,
16+ text : String ,
17+ name : String ,
18+ timestamp : String
19+ } ) ;
20+
21+ var getBubbles = function ( req , res ) {
22+ var specURI = req . query . pathToDataFile ;
23+
24+ var opts = { } ;
25+
26+ if ( specURI != null ) {
27+ opts = {
28+ specURI : specURI
29+ } ;
30+ }
31+
32+ Bubble . find ( opts , function ( err , data ) {
33+ if ( ! err ) {
34+ res . jsonp ( data ) ;
35+ }
36+ } )
37+ } ;
38+
39+ var setBubble = function ( req , res ) {
40+ var bubble = new Bubble ( {
41+ specURI : req . query . specURI ,
42+ section : req . query . section ,
43+ x : req . query . x ,
44+ y : req . query . y ,
45+ text : req . query . text ,
46+ name : req . query . name ,
47+ timestamp : req . query . timestamp
48+ }
49+ ) ;
50+
51+ bubble . save ( function ( err , data ) {
52+ if ( ! err ) {
53+ res . jsonp ( data ) ;
54+ }
55+ } ) ;
56+ } ;
57+
58+ var removeBubble = function ( req , res ) {
59+ var id = req . query . id ;
60+
61+ Bubble . remove ( { _id : id } , function ( err , data ) {
62+ if ( ! err ) {
63+ res . jsonp ( data ) ;
64+ }
65+ } ) ;
66+ } ;
67+
68+ var countBubbles = function ( req , res ) {
69+ var specURI = req . query . specURI ;
70+
71+ Bubble . count ( { specURI : specURI } , function ( err , data ) {
72+ if ( ! err ) {
73+ res . jsonp ( data ) ;
74+ } else {
75+ res . send ( err ) ;
76+ }
77+ } ) ;
78+ } ;
79+
80+ var removeAllBubbles = function ( req , res ) {
81+ Bubble . remove ( function ( err , data ) {
82+ if ( ! err ) {
83+ res . send ( 'removed all' ) ;
84+ }
85+ } ) ;
86+ } ;
87+
88+ global . app . get ( '/getBubbles' , getBubbles ) ;
89+ global . app . get ( '/setBubble' , setBubble ) ;
90+ global . app . get ( '/removeBubble' , removeBubble ) ;
91+ global . app . get ( '/countBubbles' , countBubbles ) ;
92+ global . app . get ( '/removeAllBubbles' , removeAllBubbles ) ;
0 commit comments