From e225747475c58892518d846e26e2474534079dc1 Mon Sep 17 00:00:00 2001 From: barbarajacob Date: Mon, 9 Sep 2013 20:07:21 +0100 Subject: [PATCH 1/7] schema plus removed unneeded references from package.json --- .gitignore | 3 + .idea/encodings.xml | 5 + .idea/engine.iml | 9 ++ .idea/libraries/sass_stdlib.xml | 8 ++ .idea/misc.xml | 5 + .idea/modules.xml | 9 ++ .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 7 ++ package.json | 2 - schema/schema.json | 183 ++++++++++++++++++++++++++++++++ 10 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/engine.iml create mode 100644 .idea/libraries/sass_stdlib.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vcs.xml create mode 100644 schema/schema.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4ee6e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +bower_components/ +node_modules/ \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..7c62b52 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/engine.iml b/.idea/engine.iml new file mode 100644 index 0000000..3b09ca3 --- /dev/null +++ b/.idea/engine.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/libraries/sass_stdlib.xml b/.idea/libraries/sass_stdlib.xml new file mode 100644 index 0000000..8962a7d --- /dev/null +++ b/.idea/libraries/sass_stdlib.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..262e5d3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d46fdb0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..0d5175c --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..ab55cf1 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/package.json b/package.json index 72e4955..42dc4f2 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,6 @@ }, "dependencies": { "express": "3.3.4", - "jade": "*", - "ejs": "~0.8.4", "lodash": "~1.3.1", "when": "~2.3.0", "firebase": "~0.6.3" diff --git a/schema/schema.json b/schema/schema.json new file mode 100644 index 0000000..e2325d4 --- /dev/null +++ b/schema/schema.json @@ -0,0 +1,183 @@ +{"root" : [ + { + "user" : { + "user_id" : 1, + "user_name" : "Joe", + "user_surname" : "Bloggs", + "user_screen_name" : "joebloggs", + "user_reputation" : 0, + "user_level" : 1 + }, + "report" : { + "report_id" : 2, + "report_title" : "UFO sighting", + "report_description" : "Saw a flying saucepan earlier today", + "report_time_start" : 1378743848616, + "report_time_end" : null, + "report_timezone" : "BST", + "report_lat" : 51.505300, + "report_long" : -0.165477, + "report_media" : { + "media_video" : [], + "media_pictures" : [], + "media_audio" : [], + "media_links" : [] + }, + "report_tags" : ["awesome", "UFO"], + "report_importance" : 1, + "report_editable" : false, + "report_upvotes" : 2, + "report_downvotes" : 2 + }, + "event" : { + "event_id" : 3, + "event_name" : "London ufo sightings of 09/09/13", + "event_reports" : [2,5,10], + "event_time_start" : 1378743848616, + "event_time_end" : null, + "event_timezone" : "BST", + "event_lat" : 51.507298, + "event_long" : -0.127392, + "event_importance" : 2, + "event_upvotes" : 3, + "event_downvotes" : 2, + "event_category" : "custom" + } + }, + { + "user" : { + "user_id" : 1, + "user_name" : "Joe", + "user_surname" : "Bloggs", + "user_screen_name" : "joebloggs", + "user_reputation" : 0, + "user_level" : 1 + }, + "report" : { + "report_id" : 5, + "report_title" : "Another UFO sighting", + "report_description" : "Really really there was a flying saucepan, ain't kiddin'", + "report_time_start" : 1378743849619, + "report_time_end" : null, + "report_timezone" : "BST", + "report_lat" : 51.505300, + "report_long" : -0.165477, + "report_media" : { + "media_video" : [], + "media_pictures" : [], + "media_audio" : [], + "media_links" : [] + }, + "report_tags" : ["awesome", "UFO"], + "report_importance" : 0, + "report_editable" : false, + "report_upvotes" : 0, + "report_downvotes" : 0 + }, + "event" : { + "event_id" : 3, + "event_name" : "London ufo sightings of 09/09/13", + "event_reports" : [2,5,10], + "event_time_start" : 1378743848616, + "event_time_end" : null, + "event_timezone" : "BST", + "event_lat" : 51.507298, + "event_long" : -0.127392, + "event_importance" : 2, + "event_upvotes" : 3, + "event_downvotes" : 2, + "event_category" : "custom" + } + }, + { + "user" : { + "user_id" : 1, + "user_name" : "Bernardo", + "user_surname" : "Bertolucci", + "user_screen_name" : "bernardone", + "user_reputation" : 4, + "user_level" : 1 + }, + "report" : { + "report_id" : 10, + "report_title" : "Strange light in the sky", + "report_description" : "There is an UFO hovering over London", + "report_time_start" : 1378743848821, + "report_time_end" : null, + "report_timezone" : "BST", + "report_lat" : 51.505955, + "report_long" : -0.14863, + "report_media" : { + "media_video" : [], + "media_pictures" : [], + "media_audio" : [], + "media_links" : [] + }, + "report_tags" : ["strange"], + "report_importance" : 1, + "report_editable" : false, + "report_upvotes" : 2, + "report_downvotes" : 2 + }, + "event" : { + "event_id" : 3, + "event_name" : "London ufo sightings of 09/09/13", + "event_reports" : [2,5,10], + "event_time_start" : 1378743848616, + "event_time_end" : null, + "event_timezone" : "BST", + "event_lat" : 51.505300, + "event_long" : -0.165477, + "event_importance" : 2, + "event_upvotes" : 3, + "event_downvotes" : 2, + "event_category" : "custom" + } + }, + { + "user" : { + "user_id" : 1, + "user_name" : "Joe", + "user_surname" : "Bloggs", + "user_screen_name" : "joebloggs", + "user_reputation" : 0, + "user_level" : 1 + }, + "report" : { + "report_id" : 15, + "report_title" : "Topshop sale", + "report_description" : "Oxford Circus's topshop has announced a sale", + "report_time_start" : 1378743848616, + "report_time_end" : null, + "report_timezone" : "BST", + "report_lat" : 51.505300, + "report_long" : -0.165477, + "report_media" : { + "media_video" : [], + "media_pictures" : [], + "media_audio" : [], + "media_links" : [] + }, + "report_tags" : ["awesome"], + "report_importance" : 1, + "report_editable" : false, + "report_upvotes" : 0, + "report_downvotes" : 0 + }, + "event" : { + "event_id" : 20, + "event_name" : "Topshop sale", + "event_reports" : [15], + "event_time_start" : 1433804400000, + "event_time_end" : 1381359600000, + "event_timezone" : "BST", + "event_lat" : 51.515366, + "event_long" : -0.141344, + "event_importance" : 2, + "event_upvotes" : 3, + "event_downvotes" : 2, + "event_category" : "around town" + } + } +] +} \ No newline at end of file From a31a24a52de1c1fa33e49f67b3cf28c463fa3e79 Mon Sep 17 00:00:00 2001 From: barbarajacob Date: Mon, 9 Sep 2013 20:51:18 +0100 Subject: [PATCH 2/7] changes to the schema --- schema/schema.json | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/schema/schema.json b/schema/schema.json index e2325d4..2045feb 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -1,4 +1,4 @@ -{"root" : [ +[ { "user" : { "user_id" : 1, @@ -6,7 +6,11 @@ "user_surname" : "Bloggs", "user_screen_name" : "joebloggs", "user_reputation" : 0, - "user_level" : 1 + "user_level" : 1, + "user_twitter" : "joeblog04", + "user_email" : "joe@bloggs.za", + "user_description" : "A normal dude", + "user_picture" : "09.jpg" }, "report" : { "report_id" : 2, @@ -51,7 +55,11 @@ "user_surname" : "Bloggs", "user_screen_name" : "joebloggs", "user_reputation" : 0, - "user_level" : 1 + "user_level" : 1, + "user_twitter" : "joeblog04", + "user_email" : "joe@bloggs.za", + "user_description" : "A normal dude", + "user_picture" : "09.jpg" }, "report" : { "report_id" : 5, @@ -96,7 +104,11 @@ "user_surname" : "Bertolucci", "user_screen_name" : "bernardone", "user_reputation" : 4, - "user_level" : 1 + "user_level" : 1, + "user_twitter" : "bernardbert", + "user_email" : "bbrb@gmail.com", + "user_description" : "Professional reporter", + "user_picture" : "bbernardone.jpg" }, "report" : { "report_id" : 10, @@ -141,7 +153,11 @@ "user_surname" : "Bloggs", "user_screen_name" : "joebloggs", "user_reputation" : 0, - "user_level" : 1 + "user_level" : 1, + "user_twitter" : "joeblog04", + "user_email" : "joe@bloggs.za", + "user_description" : "A normal dude", + "user_picture" : "09.jpg" }, "report" : { "report_id" : 15, @@ -179,5 +195,4 @@ "event_category" : "around town" } } -] -} \ No newline at end of file +] \ No newline at end of file From 502128d1a0f8e9e308ac641d78d233ee50ee3921 Mon Sep 17 00:00:00 2001 From: barbarajacob Date: Mon, 9 Sep 2013 22:53:10 +0100 Subject: [PATCH 3/7] Restructured the schema --- schema/schema.json | 281 +++++++++++++++++---------------------------- src/User.js | 12 +- src/yip.js | 7 +- 3 files changed, 119 insertions(+), 181 deletions(-) diff --git a/schema/schema.json b/schema/schema.json index 2045feb..4fff060 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -1,198 +1,131 @@ -[ - { - "user" : { - "user_id" : 1, - "user_name" : "Joe", - "user_surname" : "Bloggs", - "user_screen_name" : "joebloggs", - "user_reputation" : 0, - "user_level" : 1, - "user_twitter" : "joeblog04", - "user_email" : "joe@bloggs.za", - "user_description" : "A normal dude", - "user_picture" : "09.jpg" +{ + "users" : { + "joebloggs" : { + "name" : "Joe", + "surname" : "Bloggs", + "reputation" : 0, + "level" : 1, + "twitter" : "joeblog04", + "email" : "joe@bloggs.za", + "description" : "A normal dude", + "picture" : "09.jpg" }, - "report" : { - "report_id" : 2, - "report_title" : "UFO sighting", - "report_description" : "Saw a flying saucepan earlier today", - "report_time_start" : 1378743848616, - "report_time_end" : null, - "report_timezone" : "BST", - "report_lat" : 51.505300, - "report_long" : -0.165477, - "report_media" : { + "bernardone" : { + "name" : "Bernardo", + "surname" : "Bertolucci", + "screen_name" : "bernardone", + "reputation" : 4, + "level" : 1, + "twitter" : "bernardbert", + "email" : "bbrb@gmail.com", + "description" : "Professional reporter", + "picture" : "bbernardone.jpg" + }}, + "reports" : { + "ufo_sighting" : { + "title" : "UFO sighting", + "reporter" : 1, + "description" : "Saw a flying saucepan earlier today", + "time_start" : 1378743848616, + "time_end" : null, + "timezone" : "BST", + "location" : [51.505300, -0.165477], + "media" : { "media_video" : [], "media_pictures" : [], "media_audio" : [], "media_links" : [] }, - "report_tags" : ["awesome", "UFO"], - "report_importance" : 1, - "report_editable" : false, - "report_upvotes" : 2, - "report_downvotes" : 2 + "tags" : ["awesome", "UFO"], + "importance" : 1, + "editable" : false, + "upvotes" : 2, + "downvotes" : 2 }, - "event" : { - "event_id" : 3, - "event_name" : "London ufo sightings of 09/09/13", - "event_reports" : [2,5,10], - "event_time_start" : 1378743848616, - "event_time_end" : null, - "event_timezone" : "BST", - "event_lat" : 51.507298, - "event_long" : -0.127392, - "event_importance" : 2, - "event_upvotes" : 3, - "event_downvotes" : 2, - "event_category" : "custom" - } - }, - { - "user" : { - "user_id" : 1, - "user_name" : "Joe", - "user_surname" : "Bloggs", - "user_screen_name" : "joebloggs", - "user_reputation" : 0, - "user_level" : 1, - "user_twitter" : "joeblog04", - "user_email" : "joe@bloggs.za", - "user_description" : "A normal dude", - "user_picture" : "09.jpg" - }, - "report" : { - "report_id" : 5, - "report_title" : "Another UFO sighting", - "report_description" : "Really really there was a flying saucepan, ain't kiddin'", - "report_time_start" : 1378743849619, - "report_time_end" : null, - "report_timezone" : "BST", - "report_lat" : 51.505300, - "report_long" : -0.165477, - "report_media" : { + "another_ufo_sighting" : { + "title" : "Another UFO sighting", + "reporter" : 1, + "description" : "Really really there was a flying saucepan, ain't kiddin'", + "time_start" : 1378743849619, + "time_end" : null, + "timezone" : "BST", + "location" : [51.505309, -0.165487], + "media" : { "media_video" : [], "media_pictures" : [], "media_audio" : [], "media_links" : [] }, - "report_tags" : ["awesome", "UFO"], - "report_importance" : 0, - "report_editable" : false, - "report_upvotes" : 0, - "report_downvotes" : 0 - }, - "event" : { - "event_id" : 3, - "event_name" : "London ufo sightings of 09/09/13", - "event_reports" : [2,5,10], - "event_time_start" : 1378743848616, - "event_time_end" : null, - "event_timezone" : "BST", - "event_lat" : 51.507298, - "event_long" : -0.127392, - "event_importance" : 2, - "event_upvotes" : 3, - "event_downvotes" : 2, - "event_category" : "custom" - } - }, - { - "user" : { - "user_id" : 1, - "user_name" : "Bernardo", - "user_surname" : "Bertolucci", - "user_screen_name" : "bernardone", - "user_reputation" : 4, - "user_level" : 1, - "user_twitter" : "bernardbert", - "user_email" : "bbrb@gmail.com", - "user_description" : "Professional reporter", - "user_picture" : "bbernardone.jpg" + "tags" : ["awesome", "UFO"], + "importance" : 0, + "editable" : false, + "upvotes" : 0, + "downvotes" : 0 }, - "report" : { - "report_id" : 10, - "report_title" : "Strange light in the sky", - "report_description" : "There is an UFO hovering over London", - "report_time_start" : 1378743848821, - "report_time_end" : null, - "report_timezone" : "BST", - "report_lat" : 51.505955, - "report_long" : -0.14863, - "report_media" : { + "strange_light_in_the_sky" : { + "title" : "Strange light in the sky", + "reporter" : 3, + "description" : "There is an UFO hovering over London", + "time_start" : 1378743848821, + "time_end" : null, + "timezone" : "BST", + "location" : [51.505955, -0.14863], + "media" : { "media_video" : [], "media_pictures" : [], "media_audio" : [], "media_links" : [] }, - "report_tags" : ["strange"], - "report_importance" : 1, - "report_editable" : false, - "report_upvotes" : 2, - "report_downvotes" : 2 + "tags" : ["strange"], + "importance" : 1, + "editable" : false, + "upvotes" : 2, + "downvotes" : 2 }, - "event" : { - "event_id" : 3, - "event_name" : "London ufo sightings of 09/09/13", - "event_reports" : [2,5,10], - "event_time_start" : 1378743848616, - "event_time_end" : null, - "event_timezone" : "BST", - "event_lat" : 51.505300, - "event_long" : -0.165477, - "event_importance" : 2, - "event_upvotes" : 3, - "event_downvotes" : 2, - "event_category" : "custom" - } - }, - { - "user" : { - "user_id" : 1, - "user_name" : "Joe", - "user_surname" : "Bloggs", - "user_screen_name" : "joebloggs", - "user_reputation" : 0, - "user_level" : 1, - "user_twitter" : "joeblog04", - "user_email" : "joe@bloggs.za", - "user_description" : "A normal dude", - "user_picture" : "09.jpg" - }, - "report" : { - "report_id" : 15, - "report_title" : "Topshop sale", - "report_description" : "Oxford Circus's topshop has announced a sale", - "report_time_start" : 1378743848616, - "report_time_end" : null, - "report_timezone" : "BST", - "report_lat" : 51.505300, - "report_long" : -0.165477, - "report_media" : { + "topshop_sale" : { + "title" : "Topshop sale", + "reporter" : 1, + "description" : "Oxford Circus's topshop has announced a sale", + "time_start" : 1378743848616, + "time_end" : null, + "timezone" : "BST", + "location" : [51.505300, -0.165477], + "media" : { "media_video" : [], "media_pictures" : [], "media_audio" : [], "media_links" : [] }, - "report_tags" : ["awesome"], - "report_importance" : 1, - "report_editable" : false, - "report_upvotes" : 0, - "report_downvotes" : 0 - }, - "event" : { - "event_id" : 20, - "event_name" : "Topshop sale", - "event_reports" : [15], - "event_time_start" : 1433804400000, - "event_time_end" : 1381359600000, - "event_timezone" : "BST", - "event_lat" : 51.515366, - "event_long" : -0.141344, - "event_importance" : 2, - "event_upvotes" : 3, - "event_downvotes" : 2, - "event_category" : "around town" - } - } -] \ No newline at end of file + "tags" : ["awesome"], + "importance" : 1, + "editable" : false, + "upvotes" : 0, + "downvotes" : 0 + }}, + "events" : { + "london_ufo_sightings_of_sept_2013" : { + "name" : "London ufo sightings of sept 2013", + "description" : "A spate of ufo sightings", + "ríeports" : [2,5,10], + "time_start" : 1378743848616, + "time_end" : null, + "timezone" : "BST", + "location" : [51.505300, -0.165477], + "importance" : 2, + "upvotes" : 3, + "downvotes" : 2, + "category" : "custom" + },"topshop_sale" : { + "name" : "Topshop sale", + "description" : "Big sale in town", + "reports" : [15], + "time_start" : 1433804400000, + "time_end" : 1381359600000, + "timezone" : "BST", + "location" : [51.515366, -0.141344], + "importance" : 2, + "upvotes" : 3, + "downvotes" : 2, + "category" : "around town" + }} +} \ No newline at end of file diff --git a/src/User.js b/src/User.js index ba150f7..1dc4db5 100644 --- a/src/User.js +++ b/src/User.js @@ -11,10 +11,14 @@ var User = Model.extend({ ref: 'https://{firebaseName}.firebaseio.com/users/{id}', defaults: { - id: null, - name: '', - email: '', - twitter: '' + "name" : "", + "surname" : "", + "reputation" : 0, + "level" : 1, + "twitter" : "", + "email" : "", + "description" : "", + "picture" : "" }, init: function() { diff --git a/src/yip.js b/src/yip.js index 36e74ca..231fa6a 100644 --- a/src/yip.js +++ b/src/yip.js @@ -54,16 +54,17 @@ yip.Engine = function YipEngine(config) { console.log('Start'); var y = new yip.Engine({ - firebase: 'jp1990' + //firebase: 'jp1990' + firebase: 'bc2013' }); -var u = y.User.fromId('x43424'); +var u = y.User.fromId('joebloggs'); u.then(function(user) { console.log('Ok got something', user.get()); user.on('change', function() { - console.log('Something has changed!', user.get());; + console.log('Something has changed!', user.get()); }); }); From a38951cc775cac269e6293bdd915db3e21f5e07b Mon Sep 17 00:00:00 2001 From: barbarajacob Date: Mon, 9 Sep 2013 22:57:14 +0100 Subject: [PATCH 4/7] erm, removing a folder added by mistake --- .idea/encodings.xml | 5 ----- .idea/engine.iml | 9 --------- .idea/libraries/sass_stdlib.xml | 8 -------- .idea/misc.xml | 5 ----- .idea/modules.xml | 9 --------- .idea/scopes/scope_settings.xml | 5 ----- .idea/vcs.xml | 7 ------- 7 files changed, 48 deletions(-) delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/engine.iml delete mode 100644 .idea/libraries/sass_stdlib.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 7c62b52..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/engine.iml b/.idea/engine.iml deleted file mode 100644 index 3b09ca3..0000000 --- a/.idea/engine.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/libraries/sass_stdlib.xml b/.idea/libraries/sass_stdlib.xml deleted file mode 100644 index 8962a7d..0000000 --- a/.idea/libraries/sass_stdlib.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 262e5d3..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index d46fdb0..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 0d5175c..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index ab55cf1..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - From e73cfe03dcea227be4822f07e912304646faac55 Mon Sep 17 00:00:00 2001 From: barbarajacob Date: Wed, 11 Sep 2013 23:35:57 +0100 Subject: [PATCH 5/7] stub of the validation --- schema/schema.json | 4 ++-- src/User.js | 3 +++ src/util/Model.js | 14 ++++++++++++++ src/util/validation.js | 31 +++++++++++++++++++++++++++++++ src/util/validationRules.js | 15 +++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/util/validation.js create mode 100644 src/util/validationRules.js diff --git a/schema/schema.json b/schema/schema.json index 4fff060..42103bb 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -5,7 +5,7 @@ "surname" : "Bloggs", "reputation" : 0, "level" : 1, - "twitter" : "joeblog04", + "twitter" : "@joeblog04", "email" : "joe@bloggs.za", "description" : "A normal dude", "picture" : "09.jpg" @@ -16,7 +16,7 @@ "screen_name" : "bernardone", "reputation" : 4, "level" : 1, - "twitter" : "bernardbert", + "twitter" : "@bernardbert", "email" : "bbrb@gmail.com", "description" : "Professional reporter", "picture" : "bbernardone.jpg" diff --git a/src/User.js b/src/User.js index 1dc4db5..6b4e4be 100644 --- a/src/User.js +++ b/src/User.js @@ -2,12 +2,15 @@ var Model = require('./util/Model'); + /** * 1st Class Entity under Yip * A User */ var User = Model.extend({ + name: 'user', + ref: 'https://{firebaseName}.firebaseio.com/users/{id}', defaults: { diff --git a/src/util/Model.js b/src/util/Model.js index d879d78..26b52dd 100644 --- a/src/util/Model.js +++ b/src/util/Model.js @@ -3,6 +3,7 @@ var _ = require('lodash'); var when = require('when'); var Firebase = require('firebase'); +var Validation = require('./Validation'); var hasOwn = {}.hasOwnProperty; var toString = {}.toString; @@ -13,7 +14,9 @@ module.exports = Model; * Model Class */ function Model(data, engine) { + this.data = _.extend({}, this.defaults, data || {}); + this.engine = engine; this._isSynced = false; // is synced to db via engine? @@ -26,6 +29,8 @@ function Model(data, engine) { this.__initPromise__ = this._spawnPromise(function(resolve, reject, notify) { // This }); + + this.validation = new Validation(this); } /** @@ -72,13 +77,22 @@ _.extend(Model.prototype, { defaults: {}, set: function(k, v) { + if (toString.call(k) === '[object Object]') { for (var i in k) { if (hasOwn.call(k, i)) { + if (k[i] && this.rules && this.rules[i] && !this.rules[i].call(this, k[i])) { + console.error("Invalid data for ", k[i]); + return false; + } this.data[i] = k[i]; } } } else { + if (v && this.rules && this.rules[k] && !this.rules[k].call(this, v)) { + console.error("Invalid data for ", v); + return false; + } this.data[k] = v; } }, diff --git a/src/util/validation.js b/src/util/validation.js new file mode 100644 index 0000000..139e7ac --- /dev/null +++ b/src/util/validation.js @@ -0,0 +1,31 @@ +var rules = require('./validationRules'); + +var Validation = function(model) { + var modelRuleSet = model.name ? rules[model.name] : rules, + hasOwn = {}.hasOwnProperty, + key, ruleString, func = 'var value = arguments[0];\r\n var isValid=true;\r\n', str; + + model.rules = model.rules || {}; + + for (var i in model.defaults) { + if (hasOwn.call(model.defaults, i)) { + func = ''; + console.log(i,model.defaults,modelRuleSet, modelRuleSet[key]); + ruleString = modelRuleSet[i].split(','); + for (var a = 0, len = ruleString.length ; a < len ; a++) { + str = ruleString[a]; + if(!str.indexOf('is ')) { + func += ' if (!typeof value !== "' + str.substr(3) + '"){isValid = false}\r\n'; + } else if (!str.indexOf('test ')) { + func += ' if (!value.test(' + str.substr(5) + '){isValid = false}\r\n'; + } else if (!str.indexOf('assert ')) { + func += ' if (!value ' + str.substr(7) + '){isValid = false}\r\n'; + } + } + func += 'return isValid'; + model.rules[i] = new Function(func); + } + } +}; + +module.exports = Validation; \ No newline at end of file diff --git a/src/util/validationRules.js b/src/util/validationRules.js new file mode 100644 index 0000000..ac72f46 --- /dev/null +++ b/src/util/validationRules.js @@ -0,0 +1,15 @@ +var validationRules = { + user : { + "name" : "is string, assert >1", + "surname" : "is string", + "reputation" : "is integer", + "level" : "is integer, assert >0", + "twitter" : "is string, test /^@?(\w){1,15}$/", + "email" : "is string", + "description" : "is string", + "picture" : "is string" + } + +}; + +module.exports = validationRules; \ No newline at end of file From b03e79c552ebe616244d8cfe3873e4d9767fb65b Mon Sep 17 00:00:00 2001 From: barbarajacob Date: Thu, 12 Sep 2013 23:16:47 +0100 Subject: [PATCH 6/7] fixed the validation plus some changes to the schema --- schema/schema.json | 40 ++++++++++++++++++++----------------- src/User.js | 2 +- src/util/Model.js | 2 +- src/util/validation.js | 11 +++++----- src/util/validationRules.js | 6 +++--- 5 files changed, 33 insertions(+), 28 deletions(-) diff --git a/schema/schema.json b/schema/schema.json index 42103bb..1c0198e 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -7,7 +7,7 @@ "level" : 1, "twitter" : "@joeblog04", "email" : "joe@bloggs.za", - "description" : "A normal dude", + "bio" : "A normal dude", "picture" : "09.jpg" }, "bernardone" : { @@ -18,16 +18,16 @@ "level" : 1, "twitter" : "@bernardbert", "email" : "bbrb@gmail.com", - "description" : "Professional reporter", + "bio" : "Professional reporter", "picture" : "bbernardone.jpg" - }}, - "reports" : { + } + }, + "updates" : { "ufo_sighting" : { "title" : "UFO sighting", "reporter" : 1, "description" : "Saw a flying saucepan earlier today", - "time_start" : 1378743848616, - "time_end" : null, + "time" : 1378743848616, "timezone" : "BST", "location" : [51.505300, -0.165477], "media" : { @@ -46,8 +46,7 @@ "title" : "Another UFO sighting", "reporter" : 1, "description" : "Really really there was a flying saucepan, ain't kiddin'", - "time_start" : 1378743849619, - "time_end" : null, + "time" : 1378743849619, "timezone" : "BST", "location" : [51.505309, -0.165487], "media" : { @@ -66,8 +65,7 @@ "title" : "Strange light in the sky", "reporter" : 3, "description" : "There is an UFO hovering over London", - "time_start" : 1378743848821, - "time_end" : null, + "time" : 1378743848821, "timezone" : "BST", "location" : [51.505955, -0.14863], "media" : { @@ -86,8 +84,7 @@ "title" : "Topshop sale", "reporter" : 1, "description" : "Oxford Circus's topshop has announced a sale", - "time_start" : 1378743848616, - "time_end" : null, + "time" : 1378743848616, "timezone" : "BST", "location" : [51.505300, -0.165477], "media" : { @@ -101,12 +98,14 @@ "editable" : false, "upvotes" : 0, "downvotes" : 0 - }}, - "events" : { + } + }, + "reports" : { "london_ufo_sightings_of_sept_2013" : { "name" : "London ufo sightings of sept 2013", "description" : "A spate of ufo sightings", - "ríeports" : [2,5,10], + "reporter" : 1, + "updates" : [2,5,10], "time_start" : 1378743848616, "time_end" : null, "timezone" : "BST", @@ -114,11 +113,14 @@ "importance" : 2, "upvotes" : 3, "downvotes" : 2, + "editable" : true, "category" : "custom" - },"topshop_sale" : { + }, + "topshop_sale" : { "name" : "Topshop sale", "description" : "Big sale in town", - "reports" : [15], + "reporter" : 1, + "updates" : [15], "time_start" : 1433804400000, "time_end" : 1381359600000, "timezone" : "BST", @@ -126,6 +128,8 @@ "importance" : 2, "upvotes" : 3, "downvotes" : 2, + "editable" : true, "category" : "around town" - }} + } + } } \ No newline at end of file diff --git a/src/User.js b/src/User.js index 6b4e4be..a7c6db0 100644 --- a/src/User.js +++ b/src/User.js @@ -20,7 +20,7 @@ var User = Model.extend({ "level" : 1, "twitter" : "", "email" : "", - "description" : "", + "bio" : "", "picture" : "" }, diff --git a/src/util/Model.js b/src/util/Model.js index 26b52dd..49fea36 100644 --- a/src/util/Model.js +++ b/src/util/Model.js @@ -83,7 +83,7 @@ _.extend(Model.prototype, { if (hasOwn.call(k, i)) { if (k[i] && this.rules && this.rules[i] && !this.rules[i].call(this, k[i])) { console.error("Invalid data for ", k[i]); - return false; + continue; } this.data[i] = k[i]; } diff --git a/src/util/validation.js b/src/util/validation.js index 139e7ac..4d591e1 100644 --- a/src/util/validation.js +++ b/src/util/validation.js @@ -1,5 +1,6 @@ var rules = require('./validationRules'); +//TODO: sanitation, error messages var Validation = function(model) { var modelRuleSet = model.name ? rules[model.name] : rules, hasOwn = {}.hasOwnProperty, @@ -9,21 +10,21 @@ var Validation = function(model) { for (var i in model.defaults) { if (hasOwn.call(model.defaults, i)) { - func = ''; - console.log(i,model.defaults,modelRuleSet, modelRuleSet[key]); + func = 'var isValid=true;\r\n'; ruleString = modelRuleSet[i].split(','); for (var a = 0, len = ruleString.length ; a < len ; a++) { str = ruleString[a]; if(!str.indexOf('is ')) { - func += ' if (!typeof value !== "' + str.substr(3) + '"){isValid = false}\r\n'; + func += ' if (typeof value !== "' + str.substr(3) + '"){isValid = false}\r\n'; } else if (!str.indexOf('test ')) { func += ' if (!value.test(' + str.substr(5) + '){isValid = false}\r\n'; } else if (!str.indexOf('assert ')) { func += ' if (!value ' + str.substr(7) + '){isValid = false}\r\n'; } } - func += 'return isValid'; - model.rules[i] = new Function(func); + func += 'return isValid;'; + + model.rules[i] = new Function('value', func); } } }; diff --git a/src/util/validationRules.js b/src/util/validationRules.js index ac72f46..412d8df 100644 --- a/src/util/validationRules.js +++ b/src/util/validationRules.js @@ -2,11 +2,11 @@ var validationRules = { user : { "name" : "is string, assert >1", "surname" : "is string", - "reputation" : "is integer", - "level" : "is integer, assert >0", + "reputation" : "is number", + "level" : "is number, assert >0", "twitter" : "is string, test /^@?(\w){1,15}$/", "email" : "is string", - "description" : "is string", + "bio" : "is string", "picture" : "is string" } From 03c07f010bd6882ac1a64ef12233507ec22db028 Mon Sep 17 00:00:00 2001 From: barbarajacob Date: Thu, 12 Sep 2013 23:57:07 +0100 Subject: [PATCH 7/7] rrreally fixed the validation plus some changes to the schema --- schema/schema.json | 6 ++++-- src/Report.js | 26 ++++++++++++++++---------- src/util/validation.js | 11 ++++++----- src/util/validationRules.js | 11 ++++++++++- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/schema/schema.json b/schema/schema.json index 1c0198e..1f8c1ea 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -104,12 +104,13 @@ "london_ufo_sightings_of_sept_2013" : { "name" : "London ufo sightings of sept 2013", "description" : "A spate of ufo sightings", - "reporter" : 1, + "reporter" : "joebloggs", "updates" : [2,5,10], "time_start" : 1378743848616, "time_end" : null, "timezone" : "BST", "location" : [51.505300, -0.165477], + "tags" : ["awesome"], "importance" : 2, "upvotes" : 3, "downvotes" : 2, @@ -119,12 +120,13 @@ "topshop_sale" : { "name" : "Topshop sale", "description" : "Big sale in town", - "reporter" : 1, + "reporter" : "joebloggs", "updates" : [15], "time_start" : 1433804400000, "time_end" : 1381359600000, "timezone" : "BST", "location" : [51.515366, -0.141344], + "tags" : ["awesome"], "importance" : 2, "upvotes" : 3, "downvotes" : 2, diff --git a/src/Report.js b/src/Report.js index bae027f..e93208d 100644 --- a/src/Report.js +++ b/src/Report.js @@ -8,17 +8,23 @@ var Model = require('./util/Model'); */ module.exports = Model.extend({ + name : 'report', + defaults: { - title: '', - description: '', - location: [0, 0], - timeFrom: 0, - timeTo: Infinity, - timeExceptions: [], - updates: [ - // { contentType, content, ... } - ], - tags: [] + "name" : "Unnamed event", + "description" : "", + "reporter" : 1, + "updates" : [], + "time_start" : 1433804400000, + "time_end" : 1381359600000, + "timezone" : "GMT", + "location" : [0,0], + "tags" : [], + "importance" : 0, + "upvotes" : 0, + "downvotes" : 0, + "editable" : true, + "category" : "" }, init: function() { diff --git a/src/util/validation.js b/src/util/validation.js index 4d591e1..ec50f50 100644 --- a/src/util/validation.js +++ b/src/util/validation.js @@ -2,6 +2,7 @@ var rules = require('./validationRules'); //TODO: sanitation, error messages var Validation = function(model) { + var modelRuleSet = model.name ? rules[model.name] : rules, hasOwn = {}.hasOwnProperty, key, ruleString, func = 'var value = arguments[0];\r\n var isValid=true;\r\n', str; @@ -9,17 +10,17 @@ var Validation = function(model) { model.rules = model.rules || {}; for (var i in model.defaults) { - if (hasOwn.call(model.defaults, i)) { + if (hasOwn.call(model.defaults, i) && modelRuleSet[i]) { func = 'var isValid=true;\r\n'; - ruleString = modelRuleSet[i].split(','); + ruleString = modelRuleSet[i].split(', '); for (var a = 0, len = ruleString.length ; a < len ; a++) { - str = ruleString[a]; + str = ruleString[a].trim(); if(!str.indexOf('is ')) { func += ' if (typeof value !== "' + str.substr(3) + '"){isValid = false}\r\n'; } else if (!str.indexOf('test ')) { - func += ' if (!value.test(' + str.substr(5) + '){isValid = false}\r\n'; + func += ' if (!' + str.substr(5) + '.test(value)){isValid = false}\r\n'; } else if (!str.indexOf('assert ')) { - func += ' if (!value ' + str.substr(7) + '){isValid = false}\r\n'; + func += ' if (!value' + str.substr(7) + '){isValid = false}\r\n'; } } func += 'return isValid;'; diff --git a/src/util/validationRules.js b/src/util/validationRules.js index 412d8df..1d6f4de 100644 --- a/src/util/validationRules.js +++ b/src/util/validationRules.js @@ -1,6 +1,6 @@ var validationRules = { user : { - "name" : "is string, assert >1", + "name" : "is string, assert .length>0", "surname" : "is string", "reputation" : "is number", "level" : "is number, assert >0", @@ -8,6 +8,15 @@ var validationRules = { "email" : "is string", "bio" : "is string", "picture" : "is string" + }, + + report : { + "updates" : "is array", + "time_start" : "is number", + "time_end" : "is number", + "location" : "is array", + "tags" : "is array", + "editable" : "is boolean" } };