From e0018d6895dfb6fb57e7d7e653d54b361037c5f6 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Sun, 26 Apr 2015 15:08:37 -0700 Subject: [PATCH 01/20] Added fixes for the flights demo --- .../js/collections/airportCollection.js | 33 +++++- .../APP/frontend/js/routers/router.js | 13 ++- .../APP/frontend/js/templates/demoView.ejs | 1 + .../APP/frontend/js/views/demoView.js | 110 ++++++++++++++++-- .../aardvark/APP/frontend/scss/_demo.scss | 11 ++ .../aardvark/APP/frontend/scss/style.scss | 2 +- 6 files changed, 149 insertions(+), 21 deletions(-) create mode 100644 js/apps/system/_admin/aardvark/APP/frontend/scss/_demo.scss diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/collections/airportCollection.js b/js/apps/system/_admin/aardvark/APP/frontend/js/collections/airportCollection.js index f9b95f4ff2..6ce69d49ea 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/collections/airportCollection.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/collections/airportCollection.js @@ -7,7 +7,8 @@ window.Airports = Backbone.Collection.extend({ - initialize: function() { + initialize: function(options) { + this.collectionName = options.collectionName; }, getAirports: function(callback) { @@ -35,6 +36,27 @@ }); }, + getFlightDistribution: function(callback) { + $.ajax({ + type: "POST", + url: "/_api/cursor", + data: JSON.stringify({ + query: "FOR f IN @@flights COLLECT dest = f._to " + + "WITH COUNT INTO n SORT n RETURN {Dest: SPLIT(dest, '/')[1], count: n}", + bindVars: { + "@flights": this.collectionName + } + }), + contentType: "application/json", + processData: false, + success: function (data) { + callback(data.result); + }, + error: function (data) { + } + }); + }, + getFlightsForAirport: function(airport, callback) { var self = this; @@ -42,9 +64,12 @@ type: "POST", url: "/_api/cursor", data: JSON.stringify({ - query: "for f in flights12 filter f.Origin == @airport COLLECT dest = f.Dest " + - "WITH COUNT INTO n SORT n RETURN {Dest: dest, count: n}", - bindVars: {"airport": airport} + query: "for f in @@flights filter f._from == @airport COLLECT dest = f._to " + + "WITH COUNT INTO n SORT n RETURN {Dest: SPLIT(dest, '/')[1], count: n}", + bindVars: { + "airport": "airports/" + airport, + "@flights": this.collectionName + } }), contentType: "application/json", processData: false, diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js index 04d5092b62..59fd1b064b 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js @@ -26,13 +26,18 @@ "userManagement": "userManagement", "userProfile": "userProfile", "logs": "logs", - "demo": "demo" + "demo": "demo", + "demo/:collection": "demo" }, - demo: function () { - + demo: function (collection) { + if (!collection) { + collection = "flights"; + } if (!this.demoView) { - this.demoView = new window.DemoView({}); + this.demoView = new window.DemoView({ + collectionName: collection + }); } this.demoView.render(); diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/templates/demoView.ejs b/js/apps/system/_admin/aardvark/APP/frontend/js/templates/demoView.ejs index 03da9831ce..540c92c9be 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/templates/demoView.ejs +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/templates/demoView.ejs @@ -5,6 +5,7 @@
+
    -
      +