From 691693bd91f33aa1c36c19560282c00bfdf38801 Mon Sep 17 00:00:00 2001 From: Emily Abrash Date: Mon, 28 Nov 2016 16:20:00 -0800 Subject: [PATCH 1/7] Waves 1 and 2 --- build/css/app.css | 2 +- src/app.js | 11 +++++++---- src/app/views/application_view.js | 20 +++++++++++++++++--- src/app/views/quote_view.js | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 src/app/views/quote_view.js diff --git a/build/css/app.css b/build/css/app.css index f335374..c18419a 100644 --- a/build/css/app.css +++ b/build/css/app.css @@ -30,7 +30,7 @@ header h1 { .quote .symbol { text-transform: uppercase; - font-size: 2.8em; + font-size: 2.0em; font-family: 'Rubik Mono One', sans-serif; color: #158745; } diff --git a/src/app.js b/src/app.js index cb932d5..6b42efd 100644 --- a/src/app.js +++ b/src/app.js @@ -17,14 +17,17 @@ const simulate = function(quote) { quote.trigger('change:price', change); }; +var stocks = [{symbol: "HUMOR", price: 88.50}, {symbol: "CLOTH", price: 81.70}, {symbol: "HABIT", price: 98.00}, {symbol: "SUPER", price: 83.10}] + $(document).ready(function() { var appView = new ApplicationView({ - el: '#application' + el: '#application', + stocks: stocks }); appView.render(); - setInterval(function() { - // Call simulate() on each quote in the ApplicationView - }, 1000); + // setInterval(function() { + // // Call simulate() on each quote in the ApplicationView + // }, 1000); }); diff --git a/src/app/views/application_view.js b/src/app/views/application_view.js index 30b6d0f..1a146d7 100644 --- a/src/app/views/application_view.js +++ b/src/app/views/application_view.js @@ -1,11 +1,25 @@ import Backbone from 'backbone'; +import QuoteView from 'app/views/quote_view'; +import $ from 'jquery'; +import _ from 'underscore'; -const ApplicationView = Backbone.View.extend({ - initialize: function() { +var ApplicationView = Backbone.View.extend({ + initialize: function(options) { + this.stocks = options.stocks; + this.quoteTemplate = _.template($("#tmpl-quote-view").html()); + this.quoteList = []; + for (var i = 0; i < this.stocks.length; i++){ + var newQuote = new QuoteView({quote: this.stocks[i], template: this.quoteTemplate}); + this.quoteList.push(newQuote); + } + this.containerForQuotes = $('.quotes'); }, render: function() { - this.$el.html('

Hello World

'); + this.containerForQuotes.empty(); + for (var i = 0; i < this.quoteList.length; i++){ + this.containerForQuotes.append(this.quoteList[i].render().$el); + } return this; } diff --git a/src/app/views/quote_view.js b/src/app/views/quote_view.js new file mode 100644 index 0000000..4b20b0f --- /dev/null +++ b/src/app/views/quote_view.js @@ -0,0 +1,18 @@ +import Backbone from 'backbone'; +import _ from 'underscore'; + +// We pass in an object to the function that contains multiple functions (initialize +// and render) + +var QuoteView = Backbone.View.extend({ + initialize: function(options){ + this.quote = options.quote; + this.template = options.template; + }, + render: function(){ + this.$el.html(this.template({symbol: this.quote.symbol, price: this.quote.price})); + return this; + } +}); + +export default QuoteView; From c8c95a7298d40beef3042505aa69ad3296b30d17 Mon Sep 17 00:00:00 2001 From: Emily Abrash Date: Mon, 28 Nov 2016 16:32:16 -0800 Subject: [PATCH 2/7] Wave 3 - buttons working --- build/index.html | 4 ++-- src/app/views/quote_view.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/build/index.html b/build/index.html index 79b1a0f..0ff7340 100644 --- a/build/index.html +++ b/build/index.html @@ -26,8 +26,8 @@

Ada Trader

<%- symbol %>

$<%- price.toFixed(2) %>

- - + +
diff --git a/src/app/views/quote_view.js b/src/app/views/quote_view.js index 4b20b0f..e912768 100644 --- a/src/app/views/quote_view.js +++ b/src/app/views/quote_view.js @@ -1,5 +1,6 @@ import Backbone from 'backbone'; import _ from 'underscore'; +import $ from 'jquery'; // We pass in an object to the function that contains multiple functions (initialize // and render) @@ -12,6 +13,18 @@ var QuoteView = Backbone.View.extend({ render: function(){ this.$el.html(this.template({symbol: this.quote.symbol, price: this.quote.price})); return this; + }, + events: { + 'click .btn-buy': 'buyStock', + 'click .btn-sell': 'sellStock' + }, + buyStock: function(event){ + this.quote.price += 1.00; + this.render(); + }, + sellStock: function(event){ + this.quote.price -= 1.00; + this.render(); } }); From 83af3feace70e7b9bea380aca175cb6cb5e542d6 Mon Sep 17 00:00:00 2001 From: Emily Abrash Date: Mon, 28 Nov 2016 18:46:22 -0800 Subject: [PATCH 3/7] Random price change updates implemented --- src/app.js | 10 +++++++--- src/app/views/quote_view.js | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/app.js b/src/app.js index 6b42efd..4776c6b 100644 --- a/src/app.js +++ b/src/app.js @@ -15,6 +15,7 @@ const simulate = function(quote) { // Actually trigger the change quote.trigger('change:price', change); + console.log(change); }; var stocks = [{symbol: "HUMOR", price: 88.50}, {symbol: "CLOTH", price: 81.70}, {symbol: "HABIT", price: 98.00}, {symbol: "SUPER", price: 83.10}] @@ -27,7 +28,10 @@ $(document).ready(function() { appView.render(); - // setInterval(function() { - // // Call simulate() on each quote in the ApplicationView - // }, 1000); + setInterval(function() { + // Call simulate() on each quote in the ApplicationView + for(var i = 0; i < appView.quoteList.length; i++){ + simulate(appView.quoteList[i]); + } + }, 1000); }); diff --git a/src/app/views/quote_view.js b/src/app/views/quote_view.js index e912768..6b7a25e 100644 --- a/src/app/views/quote_view.js +++ b/src/app/views/quote_view.js @@ -9,6 +9,11 @@ var QuoteView = Backbone.View.extend({ initialize: function(options){ this.quote = options.quote; this.template = options.template; + this.on('change:price', this.updatePrice); + }, + updatePrice: function(change){ + this.quote.price += change; + this.render(); }, render: function(){ this.$el.html(this.template({symbol: this.quote.symbol, price: this.quote.price})); From 85cd0cdffe84715ec36df616dc077c59ac13766e Mon Sep 17 00:00:00 2001 From: Emily Abrash Date: Mon, 28 Nov 2016 21:17:20 -0800 Subject: [PATCH 4/7] Fixed so does not go below zero --- src/app/views/quote_view.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/views/quote_view.js b/src/app/views/quote_view.js index 6b7a25e..ed162cf 100644 --- a/src/app/views/quote_view.js +++ b/src/app/views/quote_view.js @@ -13,6 +13,9 @@ var QuoteView = Backbone.View.extend({ }, updatePrice: function(change){ this.quote.price += change; + if (this.quote.price < 0.00){ + this.quote.price = 0.00; + } this.render(); }, render: function(){ @@ -29,6 +32,9 @@ var QuoteView = Backbone.View.extend({ }, sellStock: function(event){ this.quote.price -= 1.00; + if (this.quote.price < 0.00){ + this.quote.price = 0.00; + } this.render(); } }); From 0f0f2f6620be82bb363d3e436420eb2a5b305fd5 Mon Sep 17 00:00:00 2001 From: Emily Abrash Date: Mon, 28 Nov 2016 21:45:03 -0800 Subject: [PATCH 5/7] All buttons not working yet --- build/css/app.css | 4 ++++ build/index.html | 9 +++++++-- src/app.js | 1 - src/app/views/application_view.js | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/build/css/app.css b/build/css/app.css index c18419a..2c820a6 100644 --- a/build/css/app.css +++ b/build/css/app.css @@ -47,3 +47,7 @@ header h1 { margin-bottom: 0.25em; border-radius: 3px; } + +.all-buttons { + text-align: center; +} diff --git a/build/index.html b/build/index.html index 0ff7340..26b75b6 100644 --- a/build/index.html +++ b/build/index.html @@ -19,6 +19,11 @@

Ada Trader

+
+ + +
+