From a315c7429de537d80796636d52a5c670da822b4f Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 12 Dec 2017 17:08:06 -0800 Subject: [PATCH 01/12] created two views. added buy and sell methods --- dist/index.html | 1 + src/app.js | 14 ++++++++++++-- src/models/quote.js | 7 +++++-- src/views/quote_list_view.js | 25 +++++++++++++++++++++++++ src/views/quote_view.js | 29 +++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/views/quote_list_view.js create mode 100644 src/views/quote_view.js diff --git a/dist/index.html b/dist/index.html index 8a046fa..2473781 100644 --- a/dist/index.html +++ b/dist/index.html @@ -21,6 +21,7 @@

Ada Trader

Quotes

diff --git a/src/app.js b/src/app.js index 03ec910..ff9bc2f 100644 --- a/src/app.js +++ b/src/app.js @@ -1,11 +1,14 @@ +import $ from 'jquery'; +import _ from 'underscore'; + import 'foundation-sites/dist/foundation.css'; import 'css/app.css'; -import $ from 'jquery'; - import Simulator from 'models/simulator'; import QuoteList from 'collections/quote_list'; +import QuoteListView from 'views/quote_list_view'; + const quoteData = [ { symbol: 'HUMOR', @@ -30,6 +33,13 @@ $(document).ready(function() { const simulator = new Simulator({ quotes: quotes, }); + const quoteListView = new QuoteListView({ + model: quotes, + quoteTemplate: _.template($('#quote-template').html()), + el: 'main' + }) + + quoteListView.render(); simulator.start(); }); diff --git a/src/models/quote.js b/src/models/quote.js index 4fbf466..dfcfd95 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -7,11 +7,14 @@ const Quote = Backbone.Model.extend({ }, buy() { - // Implement this function to increase the price by $1.00 + const newBuyPrice = this.get('price') + 1 + return newBuyPrice; + ; }, sell() { - // Implement this function to decrease the price by $1.00 + const newBuyPrice = this.get('price') - 1 + return newBuyPrice; }, }); diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js new file mode 100644 index 0000000..be9856b --- /dev/null +++ b/src/views/quote_list_view.js @@ -0,0 +1,25 @@ +import Backbone from 'backbone'; +import _ from 'underscore'; +import QuoteView from '../views/quote_view'; +import Quote from '../models/quote'; + +const QuoteListView = Backbone.View.extend({ + initialize(params) { + this.template = params.quoteTemplate; + this.listenTo(this.model, 'update', this.render); + }, + render() { + this.model.each((quote) => { + const quoteView = new QuoteView({ + model: quote, + template: this.template, + tagName: 'li', + className: 'quote', + }); + this.$('#quotes').append(quoteView.render().$el); + }); + return this; + }, +}); + +export default QuoteListView; diff --git a/src/views/quote_view.js b/src/views/quote_view.js new file mode 100644 index 0000000..84dd979 --- /dev/null +++ b/src/views/quote_view.js @@ -0,0 +1,29 @@ +import Backbone from 'backbone'; +import Quote from '../models/quote'; +import Simulator from '../models/simulator'; + +const QuoteView = Backbone.View.extend({ + initialize(params) { + this.template = params.template; + this.listenTo(this.model,'change', this.render); + }, + events: { + 'click .btn-buy': 'buyQuote', + 'click .btn-sell': 'sellQuote', + }, + render() { + const compiledTemplate = this.template(this.model.toJSON()); + this.$el.html(compiledTemplate); + // this.$('#quotes').html(compiledTemplate); + return this; + }, + buyQuote: function(e) { + // console.log('clicked Buy button'); + this.model.set('price', this.model.buy()); + }, + sellQuote: function(e) { + this.model.set('price', this.model.sell()); + } +}); + +export default QuoteView; From 7d9a0da3b9f01deef7912613909ce013d560fd32 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 13 Dec 2017 15:42:18 -0800 Subject: [PATCH 02/12] created trade history --- dist/index.html | 2 +- src/app.js | 4 +++- src/models/quote.js | 11 ++++++----- src/views/quote_list_view.js | 14 ++++++++++++++ src/views/quote_view.js | 10 +++++++++- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/dist/index.html b/dist/index.html index 2473781..c2bc011 100644 --- a/dist/index.html +++ b/dist/index.html @@ -21,7 +21,7 @@

Ada Trader

Quotes

    - +
diff --git a/src/app.js b/src/app.js index ff9bc2f..a7314d9 100644 --- a/src/app.js +++ b/src/app.js @@ -6,7 +6,9 @@ import 'css/app.css'; import Simulator from 'models/simulator'; import QuoteList from 'collections/quote_list'; +import Quote from 'models/quote'; +import QuoteView from 'views/quote_view'; import QuoteListView from 'views/quote_list_view'; const quoteData = [ @@ -37,7 +39,7 @@ $(document).ready(function() { model: quotes, quoteTemplate: _.template($('#quote-template').html()), el: 'main' - }) + }); quoteListView.render(); diff --git a/src/models/quote.js b/src/models/quote.js index dfcfd95..bcf70ec 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -7,15 +7,16 @@ const Quote = Backbone.Model.extend({ }, buy() { - const newBuyPrice = this.get('price') + 1 - return newBuyPrice; - ; + return this.get('price') + 1; }, sell() { - const newBuyPrice = this.get('price') - 1 - return newBuyPrice; + return this.get('price') - 1; }, + + // postBuy() { + // + // } }); export default Quote; diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index be9856b..55e37be 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -1,4 +1,5 @@ import Backbone from 'backbone'; +import $ from 'jquery'; import _ from 'underscore'; import QuoteView from '../views/quote_view'; import Quote from '../models/quote'; @@ -16,10 +17,23 @@ const QuoteListView = Backbone.View.extend({ tagName: 'li', className: 'quote', }); + //Shaunna has a listener in here that appends the template (in a separate method) + //editMe becomes the name of the custom method we are triggering from the quoteview + //third parameter- is what is it going to do when it hears it + this.listenTo(quoteView, 'addBuy', this.prependQuote); this.$('#quotes').append(quoteView.render().$el); }); return this; }, + //we will append lines of HTML- not an object- from the template + prependQuote: function(quoteView){ + console.log('we are in the prependQuote method in teh QuoteListView'); + // console.log(this); + console.log(quoteView.model.attributes); + const tradeTemplate = _.template($('#trade-template').html()); + $('#trades').prepend(tradeTemplate(quoteView.model.attributes)); + // $('#trades').prepend(quoteView.render().$el); + } }); export default QuoteListView; diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 84dd979..7917588 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -18,8 +18,16 @@ const QuoteView = Backbone.View.extend({ return this; }, buyQuote: function(e) { - // console.log('clicked Buy button'); + console.log('clicked Buy button'); this.model.set('price', this.model.buy()); + //Shauna triggers an event that the quotelistview is listening for + // console.log(this.$el); + // console.log(this.model.get('symbol')); + // const quoteStored = new Quote({symbol: this.model.get('symbol'), price: this.model.get('price')}) + // console.log(quoteStored); + this.model.set('buy', true); + // this.trigger('addMe', quoteStored); + this.trigger('addBuy', this); }, sellQuote: function(e) { this.model.set('price', this.model.sell()); From 215fdfa889c189daa72760ab7940526cd50ce27a Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 13 Dec 2017 15:46:17 -0800 Subject: [PATCH 03/12] changed buy and sell methods in quote.js to set the price, rather than just returning it. the two initial tests now pass --- spec/models/quote_spec.js | 4 ++++ src/models/quote.js | 4 ++-- src/views/quote_list_view.js | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/models/quote_spec.js b/spec/models/quote_spec.js index be2e376..5638b88 100644 --- a/spec/models/quote_spec.js +++ b/spec/models/quote_spec.js @@ -12,8 +12,12 @@ describe('Quote spec', () => { describe('Buy function', () => { it('increases the price by $1.00', () => { const startPrice = quote.get('price'); + console.log(startPrice); + console.log(quote.attributes); quote.buy(); + console.log(startPrice); + console.log(quote.attributes); expect(quote.get('price')).toEqual(startPrice + 1.00); }); diff --git a/src/models/quote.js b/src/models/quote.js index bcf70ec..8989bdb 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -7,11 +7,11 @@ const Quote = Backbone.Model.extend({ }, buy() { - return this.get('price') + 1; + return this.set('price', this.get('price') + 1); }, sell() { - return this.get('price') - 1; + return this.set('price', this.get('price') - 1); }, // postBuy() { diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index 55e37be..25e8bb9 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -32,7 +32,6 @@ const QuoteListView = Backbone.View.extend({ console.log(quoteView.model.attributes); const tradeTemplate = _.template($('#trade-template').html()); $('#trades').prepend(tradeTemplate(quoteView.model.attributes)); - // $('#trades').prepend(quoteView.render().$el); } }); From db74454ad16ce48fbeb139764f33658f83623371 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 13 Dec 2017 16:25:18 -0800 Subject: [PATCH 04/12] fixed bug. Buy and sell methods were not returning the new value --- src/models/quote.js | 11 ++++++----- src/views/quote_list_view.js | 8 ++++---- src/views/quote_view.js | 17 ++++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/models/quote.js b/src/models/quote.js index 8989bdb..da733b8 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -7,16 +7,17 @@ const Quote = Backbone.Model.extend({ }, buy() { - return this.set('price', this.get('price') + 1); + console.log('In the buy() method in the quote model') + this.set('price', this.get('price') + 1); + return this.get('price')+1; }, sell() { - return this.set('price', this.get('price') - 1); + console.log('In the sell() method in the quote model') + this.set('price', this.get('price') - 1); + return this.get('price') - 1; }, - // postBuy() { - // - // } }); export default Quote; diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index 25e8bb9..c6b6c66 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -20,19 +20,19 @@ const QuoteListView = Backbone.View.extend({ //Shaunna has a listener in here that appends the template (in a separate method) //editMe becomes the name of the custom method we are triggering from the quoteview //third parameter- is what is it going to do when it hears it - this.listenTo(quoteView, 'addBuy', this.prependQuote); + this.listenTo(quoteView, 'addTrade', this.prependTrades); this.$('#quotes').append(quoteView.render().$el); }); return this; }, //we will append lines of HTML- not an object- from the template - prependQuote: function(quoteView){ - console.log('we are in the prependQuote method in teh QuoteListView'); + prependTrades: function(quoteView){ + console.log('we are in the prependTrades method in teh QuoteListView'); // console.log(this); console.log(quoteView.model.attributes); const tradeTemplate = _.template($('#trade-template').html()); $('#trades').prepend(tradeTemplate(quoteView.model.attributes)); - } + }, }); export default QuoteListView; diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 7917588..427f652 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -1,4 +1,6 @@ import Backbone from 'backbone'; +import $ from 'jquery'; +import _ from 'underscore'; import Quote from '../models/quote'; import Simulator from '../models/simulator'; @@ -20,17 +22,18 @@ const QuoteView = Backbone.View.extend({ buyQuote: function(e) { console.log('clicked Buy button'); this.model.set('price', this.model.buy()); - //Shauna triggers an event that the quotelistview is listening for - // console.log(this.$el); - // console.log(this.model.get('symbol')); - // const quoteStored = new Quote({symbol: this.model.get('symbol'), price: this.model.get('price')}) - // console.log(quoteStored); + console.log('made it pasdt the buy method'); this.model.set('buy', true); - // this.trigger('addMe', quoteStored); - this.trigger('addBuy', this); + console.log(this.model); + //triggers an event that the quotelistview is listening for: + this.trigger('addTrade', this); }, sellQuote: function(e) { + console.log('clicked Sell button'); this.model.set('price', this.model.sell()); + console.log('made it pasdt the sell method'); + this.model.set('buy', false); + this.trigger('addTrade', this); } }); From ce8fb4d4b742d3dccf6a9c09f0b3a14bdc69c494 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 13 Dec 2017 16:27:02 -0800 Subject: [PATCH 05/12] removed Wave 2 console logs --- src/models/quote.js | 4 ++-- src/views/quote_list_view.js | 4 ++-- src/views/quote_view.js | 5 ----- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/models/quote.js b/src/models/quote.js index da733b8..94a9bc6 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -7,13 +7,13 @@ const Quote = Backbone.Model.extend({ }, buy() { - console.log('In the buy() method in the quote model') + // console.log('In the buy() method in the quote model') this.set('price', this.get('price') + 1); return this.get('price')+1; }, sell() { - console.log('In the sell() method in the quote model') + // console.log('In the sell() method in the quote model') this.set('price', this.get('price') - 1); return this.get('price') - 1; }, diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index c6b6c66..9d207ba 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -27,9 +27,9 @@ const QuoteListView = Backbone.View.extend({ }, //we will append lines of HTML- not an object- from the template prependTrades: function(quoteView){ - console.log('we are in the prependTrades method in teh QuoteListView'); + // console.log('we are in the prependTrades method in teh QuoteListView'); // console.log(this); - console.log(quoteView.model.attributes); + // console.log(quoteView.model.attributes); const tradeTemplate = _.template($('#trade-template').html()); $('#trades').prepend(tradeTemplate(quoteView.model.attributes)); }, diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 427f652..7168187 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -20,18 +20,13 @@ const QuoteView = Backbone.View.extend({ return this; }, buyQuote: function(e) { - console.log('clicked Buy button'); this.model.set('price', this.model.buy()); - console.log('made it pasdt the buy method'); this.model.set('buy', true); - console.log(this.model); //triggers an event that the quotelistview is listening for: this.trigger('addTrade', this); }, sellQuote: function(e) { - console.log('clicked Sell button'); this.model.set('price', this.model.sell()); - console.log('made it pasdt the sell method'); this.model.set('buy', false); this.trigger('addTrade', this); } From 1b14eae5b1f37e1354e3ef83c258e17855b2da06 Mon Sep 17 00:00:00 2001 From: Julia Date: Fri, 15 Dec 2017 10:59:14 -0800 Subject: [PATCH 06/12] debugged two issues: incorrect import of orders in the app.js file and forgetting to put back the original class value of btn-buy... --- dist/index.html | 3 +- src/app.js | 28 ++++++++++++-- src/collections/order_list.js | 8 ++++ src/models/order.js | 29 +++++++++++++++ src/views/order_list_view.js | 69 +++++++++++++++++++++++++++++++++++ src/views/order_view.js | 23 ++++++++++++ src/views/quote_list_view.js | 10 +---- src/views/quote_view.js | 1 + 8 files changed, 158 insertions(+), 13 deletions(-) create mode 100644 src/collections/order_list.js create mode 100644 src/models/order.js create mode 100644 src/views/order_list_view.js create mode 100644 src/views/order_view.js diff --git a/dist/index.html b/dist/index.html index c2bc011..fa1d574 100644 --- a/dist/index.html +++ b/dist/index.html @@ -58,10 +58,9 @@

Open Orders

Order Entry Form

-
+ diff --git a/src/app.js b/src/app.js index a7314d9..57ec150 100644 --- a/src/app.js +++ b/src/app.js @@ -7,9 +7,13 @@ import 'css/app.css'; import Simulator from 'models/simulator'; import QuoteList from 'collections/quote_list'; import Quote from 'models/quote'; +import Order from 'models/order'; +import OrderList from 'collections/order_list'; import QuoteView from 'views/quote_view'; import QuoteListView from 'views/quote_list_view'; +import OrderView from 'views/order_view'; +import OrderListView from 'views/order_list_view'; const quoteData = [ { @@ -37,11 +41,29 @@ $(document).ready(function() { }); const quoteListView = new QuoteListView({ model: quotes, - quoteTemplate: _.template($('#quote-template').html()), - el: 'main' + quotesTemplate: _.template($('#quote-template').html()), + el: '.workspace' }); - quoteListView.render(); + function dropdown(){ + const $label = $(`select[name=symbol]`); + quotes.forEach(function(quote) { + let dropdownItem = ``; + $label.append(dropdownItem); + }); + } + dropdown(); + + const orders = new OrderList(); + const orderListView = new OrderListView({ + model: orders, + ordersTemplate: _.template($('#order-template').html()), + el: '#order-workspace' + }); + // orderListView.render(); + simulator.start(); + + orders.add(new Order({buy: true, price: 49.00, symbol: "JULIA"})); }); diff --git a/src/collections/order_list.js b/src/collections/order_list.js new file mode 100644 index 0000000..8d7cabd --- /dev/null +++ b/src/collections/order_list.js @@ -0,0 +1,8 @@ +import Backbone from 'backbone'; +import Order from 'models/order'; + +const OrderList = Backbone.Collection.extend({ + model: Order, +}); + +export default OrderList; diff --git a/src/models/order.js b/src/models/order.js new file mode 100644 index 0000000..e75ba37 --- /dev/null +++ b/src/models/order.js @@ -0,0 +1,29 @@ +import Backbone from 'backbone'; + +const Order = Backbone.Model.extend({ + defaults: { + symbol: 'UNDEF', + targetPrice: 0.00 + }, + validate(attributes) { + const errors = {}; + + if (!attributes.targetPrice) { + errors.targetPrice = ["Price is required"]; + } + + if (attributes.targetPrice === 0) { + errors.targetPrice = ["A valid price is required"]; + } + //TODO ADD more validations to make sure a symbol is present and only valid numbers are entered (not zero, not a string) + + if ( Object.keys(errors).length > 0 ) { + return errors; + } else { + return false; + } + }, + +}); + +export default Order; diff --git a/src/views/order_list_view.js b/src/views/order_list_view.js new file mode 100644 index 0000000..39efdb9 --- /dev/null +++ b/src/views/order_list_view.js @@ -0,0 +1,69 @@ +import Backbone from 'backbone'; +import $ from 'jquery'; +import _ from 'underscore'; +// import QuoteView from '../views/quote_view'; +// import Quote from '../models/quote'; +import OrderView from '../views/order_view'; +import Order from '../models/order'; + +const OrderListView = Backbone.View.extend({ + initialize(params) { + this.template = params.ordersTemplate; + this.listenTo(this.model, 'update', this.render); + }, + render() { + this.model.forEach((order) => { + const orderView = new OrderView({ + model: order, + template: this.template, + tagName: 'li', + className: 'order', + }); + this.$('#orders').append(orderView.render().$el); + }); + return this; + }, + events: { + 'click .btn-buy': 'buyOrder', + }, + buyOrder: function(event) { + + console.log('You pressed the Buy Order button.'); + event.preventDefault(); + this.addToOrders(event, true); + }, + addToOrders: function(event, buyIsTrue) { + const orderData ={}; + orderData['symbol'] = this.$(`input[name=symbol]`); + orderData['targetPrice']= this.$('input[name=price-target]'); + orderData['buy'] = buyIsTrue; + //TODO - need to add a validation + const newOrder = new Order(orderData) + if (newOrder.isValid()) { + this.model.add(newOrder); + } else { + newOrder.destroy(); + }; + }, + updateStatusMessageFrom: function(messageHash) { + const statusMessagesEl = this.$('.form-errors'); + statusMessagesEl.empty(); + _.each(messageHash, (messageType) => { + messageType.forEach((message) => { + statusMessagesEl.append(`
  • ${message}
  • `); + }) + }); + statusMessagesEl.show(); +}, +updateStatusMessageWith: function(message) { + const statusMessagesEl = this.$('.form-errors'); + statusMessagesEl.empty(); + statusMessagesEl.append(`
  • ${message}
  • `); + statusMessagesEl.show(); +} +}); + +export default OrderListView; + +//select the current element from the dropdown: +//this.$('select[name=symbol] option:selected') diff --git a/src/views/order_view.js b/src/views/order_view.js new file mode 100644 index 0000000..e1464a0 --- /dev/null +++ b/src/views/order_view.js @@ -0,0 +1,23 @@ +import Backbone from 'backbone'; +import $ from 'jquery'; +import _ from 'underscore'; +import Order from '../models/order'; +import Simulator from '../models/simulator'; + +const OrderView = Backbone.View.extend({ + initialize(params) { + this.template = params.template; + this.listenTo(this.model,'change', this.render); + }, + events: { + //add cancel order button here + }, + render() { + const compiledTemplate = this.template(this.model.toJSON()); + this.$el.html(compiledTemplate); + // this.$('#quotes').html(compiledTemplate); + return this; + }, +}); + +export default OrderView; diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index 9d207ba..cf1b6ac 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -6,7 +6,7 @@ import Quote from '../models/quote'; const QuoteListView = Backbone.View.extend({ initialize(params) { - this.template = params.quoteTemplate; + this.template = params.quotesTemplate; this.listenTo(this.model, 'update', this.render); }, render() { @@ -17,9 +17,6 @@ const QuoteListView = Backbone.View.extend({ tagName: 'li', className: 'quote', }); - //Shaunna has a listener in here that appends the template (in a separate method) - //editMe becomes the name of the custom method we are triggering from the quoteview - //third parameter- is what is it going to do when it hears it this.listenTo(quoteView, 'addTrade', this.prependTrades); this.$('#quotes').append(quoteView.render().$el); }); @@ -27,11 +24,8 @@ const QuoteListView = Backbone.View.extend({ }, //we will append lines of HTML- not an object- from the template prependTrades: function(quoteView){ - // console.log('we are in the prependTrades method in teh QuoteListView'); - // console.log(this); - // console.log(quoteView.model.attributes); const tradeTemplate = _.template($('#trade-template').html()); - $('#trades').prepend(tradeTemplate(quoteView.model.attributes)); + this.$('#trades').prepend(tradeTemplate(quoteView.model.attributes)); }, }); diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 7168187..4e8f84e 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -20,6 +20,7 @@ const QuoteView = Backbone.View.extend({ return this; }, buyQuote: function(e) { + console.log('You pressed the buy button in the Quote view') this.model.set('price', this.model.buy()); this.model.set('buy', true); //triggers an event that the quotelistview is listening for: From a930fdae9530401bdf5bd3198c5b80150d6d8d4f Mon Sep 17 00:00:00 2001 From: Julia Date: Fri, 15 Dec 2017 11:35:10 -0800 Subject: [PATCH 07/12] the order entry form now correctly adds orders to the Open Orders list and displays error messages --- src/app.js | 2 +- src/views/order_list_view.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/app.js b/src/app.js index 57ec150..da3d8fb 100644 --- a/src/app.js +++ b/src/app.js @@ -65,5 +65,5 @@ $(document).ready(function() { simulator.start(); - orders.add(new Order({buy: true, price: 49.00, symbol: "JULIA"})); + // orders.add(new Order({buy: true, price: 49.00, symbol: "JULIA"})); }); diff --git a/src/views/order_list_view.js b/src/views/order_list_view.js index 39efdb9..7d3d8da 100644 --- a/src/views/order_list_view.js +++ b/src/views/order_list_view.js @@ -34,15 +34,29 @@ const OrderListView = Backbone.View.extend({ }, addToOrders: function(event, buyIsTrue) { const orderData ={}; - orderData['symbol'] = this.$(`input[name=symbol]`); - orderData['targetPrice']= this.$('input[name=price-target]'); + + const symbol = this.$(`select[name=symbol] option:selected`).val(); + orderData['symbol'] = symbol; + console.log(symbol); + + const price = parseFloat(this.$('input[name=price-target]').val()); + orderData['targetPrice'] = price; + console.log(price); + orderData['buy'] = buyIsTrue; + + console.log(orderData) + //TODO - need to add a validation const newOrder = new Order(orderData) if (newOrder.isValid()) { this.model.add(newOrder); + console.log('order is valid'); + console.log(newOrder); + this.updateStatusMessageWith(`New order added: ${newOrder.get('symbol')} for ${newOrder.get('targetPrice')}`); } else { newOrder.destroy(); + this.updateStatusMessageFrom(newOrder.validationError); }; }, updateStatusMessageFrom: function(messageHash) { From 1fa9819d6e715b7bfb034af0c61a794eeab8ed4d Mon Sep 17 00:00:00 2001 From: Julia Date: Fri, 15 Dec 2017 13:50:18 -0800 Subject: [PATCH 08/12] added quotes to params of orderListView in app.js, and initialized the quotes collection in order_list_view.js. Identified the current market price for the symbol selected in the Order Entry Form, and adds this market price to the orderData hash to be validated in the Order model. Order model sends appropriate message to the view for target prices over or equal to the market price. --- src/app.js | 6 ++++-- src/models/order.js | 7 +++++++ src/views/order_list_view.js | 20 +++++++++++++------- src/views/order_view.js | 7 ++++++- src/views/quote_list_view.js | 1 - src/views/quote_view.js | 1 + 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/app.js b/src/app.js index da3d8fb..b3f41b4 100644 --- a/src/app.js +++ b/src/app.js @@ -59,9 +59,11 @@ $(document).ready(function() { const orderListView = new OrderListView({ model: orders, ordersTemplate: _.template($('#order-template').html()), - el: '#order-workspace' + el: '#order-workspace', + quotes: quotes }); - // orderListView.render(); + // orderListView.quotes = quotes; + orderListView.render(); simulator.start(); diff --git a/src/models/order.js b/src/models/order.js index e75ba37..d1707ca 100644 --- a/src/models/order.js +++ b/src/models/order.js @@ -15,6 +15,13 @@ const Order = Backbone.Model.extend({ if (attributes.targetPrice === 0) { errors.targetPrice = ["A valid price is required"]; } + + + if (attributes.buy && attributes.targetPrice >= attributes.marketPrice ) { + console.log('Price is higher than or equal to market value'); + errors.targetPrice = ["Price is great than or equal to market price"]; + } + //TODO ADD more validations to make sure a symbol is present and only valid numbers are entered (not zero, not a string) if ( Object.keys(errors).length > 0 ) { diff --git a/src/views/order_list_view.js b/src/views/order_list_view.js index 7d3d8da..f0fa213 100644 --- a/src/views/order_list_view.js +++ b/src/views/order_list_view.js @@ -5,13 +5,16 @@ import _ from 'underscore'; // import Quote from '../models/quote'; import OrderView from '../views/order_view'; import Order from '../models/order'; +import Quote from '../models/quote'; const OrderListView = Backbone.View.extend({ initialize(params) { this.template = params.ordersTemplate; this.listenTo(this.model, 'update', this.render); + this.quotes = params.quotes }, render() { + this.$('#orders').empty(); this.model.forEach((order) => { const orderView = new OrderView({ model: order, @@ -27,14 +30,13 @@ const OrderListView = Backbone.View.extend({ 'click .btn-buy': 'buyOrder', }, buyOrder: function(event) { - console.log('You pressed the Buy Order button.'); event.preventDefault(); + this.addToOrders(event, true); }, addToOrders: function(event, buyIsTrue) { const orderData ={}; - const symbol = this.$(`select[name=symbol] option:selected`).val(); orderData['symbol'] = symbol; console.log(symbol); @@ -45,14 +47,21 @@ const OrderListView = Backbone.View.extend({ orderData['buy'] = buyIsTrue; - console.log(orderData) + //finds the current market price and adds it to the orderData hash, to be validated in the model. + const currentQuoteModel = this.quotes.find({symbol: symbol}); + console.log(currentQuoteModel); + const currentMarketPrice = currentQuoteModel.get('price'); + console.log(currentMarketPrice); + orderData['marketPrice'] = currentMarketPrice; + + console.log(orderData); //TODO - need to add a validation const newOrder = new Order(orderData) if (newOrder.isValid()) { this.model.add(newOrder); console.log('order is valid'); - console.log(newOrder); + // console.log(newOrder); this.updateStatusMessageWith(`New order added: ${newOrder.get('symbol')} for ${newOrder.get('targetPrice')}`); } else { newOrder.destroy(); @@ -78,6 +87,3 @@ updateStatusMessageWith: function(message) { }); export default OrderListView; - -//select the current element from the dropdown: -//this.$('select[name=symbol] option:selected') diff --git a/src/views/order_view.js b/src/views/order_view.js index e1464a0..05fed93 100644 --- a/src/views/order_view.js +++ b/src/views/order_view.js @@ -8,9 +8,10 @@ const OrderView = Backbone.View.extend({ initialize(params) { this.template = params.template; this.listenTo(this.model,'change', this.render); + // this.listenTo(this.model, 'destroy', this.remove); }, events: { - //add cancel order button here + 'click .btn-cancel': 'cancelOrder' }, render() { const compiledTemplate = this.template(this.model.toJSON()); @@ -18,6 +19,10 @@ const OrderView = Backbone.View.extend({ // this.$('#quotes').html(compiledTemplate); return this; }, + // cancelOrder: function(event) { + // console.log('You pressed the Cancel button'); + // this.model.destroy(); + // }, }); export default OrderView; diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index cf1b6ac..619504b 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -22,7 +22,6 @@ const QuoteListView = Backbone.View.extend({ }); return this; }, - //we will append lines of HTML- not an object- from the template prependTrades: function(quoteView){ const tradeTemplate = _.template($('#trade-template').html()); this.$('#trades').prepend(tradeTemplate(quoteView.model.attributes)); diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 4e8f84e..18389e2 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -25,6 +25,7 @@ const QuoteView = Backbone.View.extend({ this.model.set('buy', true); //triggers an event that the quotelistview is listening for: this.trigger('addTrade', this); + console.log('trade added'); }, sellQuote: function(e) { this.model.set('price', this.model.sell()); From d36a1fb79bcb7171e2ebd16557da3a133005f17b Mon Sep 17 00:00:00 2001 From: Julia Date: Sun, 17 Dec 2017 17:42:38 -0800 Subject: [PATCH 09/12] added sellOrder method --- src/app.js | 10 +++++++--- src/models/quote.js | 4 ++-- src/views/order_list_view.js | 15 +++++++++++++-- src/views/order_view.js | 24 +++++++++++++++++++----- src/views/quote_list_view.js | 20 ++++++++++++++++++++ src/views/quote_view.js | 3 ++- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/app.js b/src/app.js index b3f41b4..eaeaf49 100644 --- a/src/app.js +++ b/src/app.js @@ -35,6 +35,9 @@ const quoteData = [ ]; $(document).ready(function() { + let bus = {}; + bus = _.extend(bus, Backbone.Events); + const quotes = new QuoteList(quoteData); const simulator = new Simulator({ quotes: quotes, @@ -42,7 +45,8 @@ $(document).ready(function() { const quoteListView = new QuoteListView({ model: quotes, quotesTemplate: _.template($('#quote-template').html()), - el: '.workspace' + el: '.workspace', + bus: bus, }); quoteListView.render(); @@ -60,9 +64,9 @@ $(document).ready(function() { model: orders, ordersTemplate: _.template($('#order-template').html()), el: '#order-workspace', - quotes: quotes + quotes: quotes, + bus: bus, }); - // orderListView.quotes = quotes; orderListView.render(); simulator.start(); diff --git a/src/models/quote.js b/src/models/quote.js index 94a9bc6..da733b8 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -7,13 +7,13 @@ const Quote = Backbone.Model.extend({ }, buy() { - // console.log('In the buy() method in the quote model') + console.log('In the buy() method in the quote model') this.set('price', this.get('price') + 1); return this.get('price')+1; }, sell() { - // console.log('In the sell() method in the quote model') + console.log('In the sell() method in the quote model') this.set('price', this.get('price') - 1); return this.get('price') - 1; }, diff --git a/src/views/order_list_view.js b/src/views/order_list_view.js index f0fa213..b7eb743 100644 --- a/src/views/order_list_view.js +++ b/src/views/order_list_view.js @@ -11,7 +11,8 @@ const OrderListView = Backbone.View.extend({ initialize(params) { this.template = params.ordersTemplate; this.listenTo(this.model, 'update', this.render); - this.quotes = params.quotes + this.quotes = params.quotes; + this.bus = params.bus; }, render() { this.$('#orders').empty(); @@ -21,20 +22,27 @@ const OrderListView = Backbone.View.extend({ template: this.template, tagName: 'li', className: 'order', + bus: this.bus, }); + // this.listenTo(this.bus, 'quoteViewSendsQuoteChange', this.checkChange); this.$('#orders').append(orderView.render().$el); }); return this; }, events: { 'click .btn-buy': 'buyOrder', + 'click .btn-sell': 'sellOrder', }, buyOrder: function(event) { console.log('You pressed the Buy Order button.'); event.preventDefault(); - this.addToOrders(event, true); }, + sellOrder: function(event) { + console.log('You pressed the Sell Order button.'); + event.preventDefault(); + this.addToOrders(event, false); + }, addToOrders: function(event, buyIsTrue) { const orderData ={}; const symbol = this.$(`select[name=symbol] option:selected`).val(); @@ -49,7 +57,10 @@ const OrderListView = Backbone.View.extend({ //finds the current market price and adds it to the orderData hash, to be validated in the model. const currentQuoteModel = this.quotes.find({symbol: symbol}); + currentQuoteModel.set('buy', buyIsTrue); + orderData['quote'] = currentQuoteModel; console.log(currentQuoteModel); + const currentMarketPrice = currentQuoteModel.get('price'); console.log(currentMarketPrice); orderData['marketPrice'] = currentMarketPrice; diff --git a/src/views/order_view.js b/src/views/order_view.js index 05fed93..b94eb62 100644 --- a/src/views/order_view.js +++ b/src/views/order_view.js @@ -6,9 +6,12 @@ import Simulator from '../models/simulator'; const OrderView = Backbone.View.extend({ initialize(params) { + this.bus = params.bus; this.template = params.template; + this.quote = this.model.get('quote'); + this.listenTo(this.quote, 'change', this.evaluateOrder); this.listenTo(this.model,'change', this.render); - // this.listenTo(this.model, 'destroy', this.remove); + this.listenTo(this.model, 'destroy', this.remove); }, events: { 'click .btn-cancel': 'cancelOrder' @@ -19,10 +22,21 @@ const OrderView = Backbone.View.extend({ // this.$('#quotes').html(compiledTemplate); return this; }, - // cancelOrder: function(event) { - // console.log('You pressed the Cancel button'); - // this.model.destroy(); - // }, + cancelOrder: function(event) { + console.log('You pressed the Cancel button'); + this.stopListening(this.model.get('quote'), 'change'); + this.model.destroy(); + }, + evaluateOrder: function(event) { + console.log('in evaluateOrder'); + if (this.quote.get('buy')) { + if(this.quote.get('price') <= this.model.get('targetPrice')) { + console.log('im ready to tradeMe'); + this.bus.trigger('tradeMe', this.quote); + this.cancelOrder(); + } + } + } }); export default OrderView; diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index 619504b..eb1d0e1 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -6,7 +6,9 @@ import Quote from '../models/quote'; const QuoteListView = Backbone.View.extend({ initialize(params) { + this.bus = params.bus; this.template = params.quotesTemplate; + this.listenTo(this.bus, 'tradeMe', this.tradeOrders); this.listenTo(this.model, 'update', this.render); }, render() { @@ -16,16 +18,34 @@ const QuoteListView = Backbone.View.extend({ template: this.template, tagName: 'li', className: 'quote', + bus: this.bus, }); this.listenTo(quoteView, 'addTrade', this.prependTrades); + // this.quote_list_views.push(quoteView); + this.listenTo(quoteView, 'aQuoteModelChange', this.quoteChange); this.$('#quotes').append(quoteView.render().$el); }); return this; }, + quoteChange: function(event) { + this.trigger('quoteListViewSendsQuoteChange', this); + }, prependTrades: function(quoteView){ + console.log('in prependTrades'); const tradeTemplate = _.template($('#trade-template').html()); this.$('#trades').prepend(tradeTemplate(quoteView.model.attributes)); }, + tradeOrders(quote) { + console.log('in trade orders'); + const tradeQuoteView = new QuoteView({ + model: quote, + template: this.template, + tagName: 'li', + className: 'quote', + bus: this.bus, + }); + this.prependTrades(tradeQuoteView); + } }); export default QuoteListView; diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 18389e2..6233f39 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -7,6 +7,7 @@ import Simulator from '../models/simulator'; const QuoteView = Backbone.View.extend({ initialize(params) { this.template = params.template; + // this.listenTo(this.model,'change', this.quoteModelChange); this.listenTo(this.model,'change', this.render); }, events: { @@ -16,7 +17,6 @@ const QuoteView = Backbone.View.extend({ render() { const compiledTemplate = this.template(this.model.toJSON()); this.$el.html(compiledTemplate); - // this.$('#quotes').html(compiledTemplate); return this; }, buyQuote: function(e) { @@ -31,6 +31,7 @@ const QuoteView = Backbone.View.extend({ this.model.set('price', this.model.sell()); this.model.set('buy', false); this.trigger('addTrade', this); + console.log('sold trade added'); } }); From 6e7148e7c5d314df226da5d825f281a24455da43 Mon Sep 17 00:00:00 2001 From: Julia Date: Sun, 17 Dec 2017 21:10:19 -0800 Subject: [PATCH 10/12] continue to try to find bug. Clicking buy/sell in the quotelist view incorrectly completes orders for sell order in Open Orders View, and incorrectly doesn't complete order when user manually changes price to meet order requirements --- src/views/order_view.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/views/order_view.js b/src/views/order_view.js index b94eb62..184e146 100644 --- a/src/views/order_view.js +++ b/src/views/order_view.js @@ -31,7 +31,14 @@ const OrderView = Backbone.View.extend({ console.log('in evaluateOrder'); if (this.quote.get('buy')) { if(this.quote.get('price') <= this.model.get('targetPrice')) { - console.log('im ready to tradeMe'); + console.log('im ready to tradeMe (buying)'); + this.bus.trigger('tradeMe', this.quote); + this.cancelOrder(); + } + } + if (this.quote.get('sell')) { + if(this.quote.get('price') >= this.model.get('targetPrice')) { + console.log('im ready to tradeMe (selling)'); this.bus.trigger('tradeMe', this.quote); this.cancelOrder(); } From 2d01e5494e79d6c67478371e38a6774c5d5bfd88 Mon Sep 17 00:00:00 2001 From: Julia Date: Sun, 17 Dec 2017 21:44:47 -0800 Subject: [PATCH 11/12] removed console log statements --- spec/models/quote_spec.js | 8 ++++---- src/models/order.js | 7 ++++++- src/models/quote.js | 4 ++-- src/views/order_list_view.js | 12 ++++++------ src/views/order_view.js | 11 ++++++----- src/views/quote_list_view.js | 9 ++------- src/views/quote_view.js | 6 +++--- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/spec/models/quote_spec.js b/spec/models/quote_spec.js index 5638b88..2086387 100644 --- a/spec/models/quote_spec.js +++ b/spec/models/quote_spec.js @@ -12,12 +12,12 @@ describe('Quote spec', () => { describe('Buy function', () => { it('increases the price by $1.00', () => { const startPrice = quote.get('price'); - console.log(startPrice); - console.log(quote.attributes); + // console.log(startPrice); + // console.log(quote.attributes); quote.buy(); - console.log(startPrice); - console.log(quote.attributes); + // console.log(startPrice); + // console.log(quote.attributes); expect(quote.get('price')).toEqual(startPrice + 1.00); }); diff --git a/src/models/order.js b/src/models/order.js index d1707ca..0ed3d4a 100644 --- a/src/models/order.js +++ b/src/models/order.js @@ -18,10 +18,15 @@ const Order = Backbone.Model.extend({ if (attributes.buy && attributes.targetPrice >= attributes.marketPrice ) { - console.log('Price is higher than or equal to market value'); + // console.log('Price is higher than or equal to market value'); errors.targetPrice = ["Price is great than or equal to market price"]; } + if (!attributes.buy && attributes.targetPrice <= attributes.marketPrice ) { + // console.log('Price is higher than or equal to market value'); + errors.targetPrice = ["Price is less than or equal to market price"]; + } + //TODO ADD more validations to make sure a symbol is present and only valid numbers are entered (not zero, not a string) if ( Object.keys(errors).length > 0 ) { diff --git a/src/models/quote.js b/src/models/quote.js index da733b8..94a9bc6 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -7,13 +7,13 @@ const Quote = Backbone.Model.extend({ }, buy() { - console.log('In the buy() method in the quote model') + // console.log('In the buy() method in the quote model') this.set('price', this.get('price') + 1); return this.get('price')+1; }, sell() { - console.log('In the sell() method in the quote model') + // console.log('In the sell() method in the quote model') this.set('price', this.get('price') - 1); return this.get('price') - 1; }, diff --git a/src/views/order_list_view.js b/src/views/order_list_view.js index b7eb743..52103f3 100644 --- a/src/views/order_list_view.js +++ b/src/views/order_list_view.js @@ -34,12 +34,12 @@ const OrderListView = Backbone.View.extend({ 'click .btn-sell': 'sellOrder', }, buyOrder: function(event) { - console.log('You pressed the Buy Order button.'); + // console.log('You pressed the Buy Order button.'); event.preventDefault(); this.addToOrders(event, true); }, sellOrder: function(event) { - console.log('You pressed the Sell Order button.'); + // console.log('You pressed the Sell Order button.'); event.preventDefault(); this.addToOrders(event, false); }, @@ -51,7 +51,7 @@ const OrderListView = Backbone.View.extend({ const price = parseFloat(this.$('input[name=price-target]').val()); orderData['targetPrice'] = price; - console.log(price); + // console.log(price); orderData['buy'] = buyIsTrue; @@ -62,16 +62,16 @@ const OrderListView = Backbone.View.extend({ console.log(currentQuoteModel); const currentMarketPrice = currentQuoteModel.get('price'); - console.log(currentMarketPrice); + // console.log(currentMarketPrice); orderData['marketPrice'] = currentMarketPrice; - console.log(orderData); + // console.log(orderData); //TODO - need to add a validation const newOrder = new Order(orderData) if (newOrder.isValid()) { this.model.add(newOrder); - console.log('order is valid'); + // console.log('order is valid'); // console.log(newOrder); this.updateStatusMessageWith(`New order added: ${newOrder.get('symbol')} for ${newOrder.get('targetPrice')}`); } else { diff --git a/src/views/order_view.js b/src/views/order_view.js index 184e146..fd57a9b 100644 --- a/src/views/order_view.js +++ b/src/views/order_view.js @@ -23,22 +23,23 @@ const OrderView = Backbone.View.extend({ return this; }, cancelOrder: function(event) { - console.log('You pressed the Cancel button'); + // console.log('Cancelled order'); this.stopListening(this.model.get('quote'), 'change'); this.model.destroy(); }, evaluateOrder: function(event) { - console.log('in evaluateOrder'); + // console.log('in OrderView: evaluateOrder'); if (this.quote.get('buy')) { if(this.quote.get('price') <= this.model.get('targetPrice')) { - console.log('im ready to tradeMe (buying)'); + // console.log('im ready to tradeMe (buying)'); this.bus.trigger('tradeMe', this.quote); this.cancelOrder(); } } - if (this.quote.get('sell')) { + else if (!this.quote.get('buy')) { + // console.log('in else if statement') if(this.quote.get('price') >= this.model.get('targetPrice')) { - console.log('im ready to tradeMe (selling)'); + // console.log('im ready to tradeMe (selling)'); this.bus.trigger('tradeMe', this.quote); this.cancelOrder(); } diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index eb1d0e1..84beeb6 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -21,22 +21,17 @@ const QuoteListView = Backbone.View.extend({ bus: this.bus, }); this.listenTo(quoteView, 'addTrade', this.prependTrades); - // this.quote_list_views.push(quoteView); - this.listenTo(quoteView, 'aQuoteModelChange', this.quoteChange); this.$('#quotes').append(quoteView.render().$el); }); return this; }, - quoteChange: function(event) { - this.trigger('quoteListViewSendsQuoteChange', this); - }, prependTrades: function(quoteView){ - console.log('in prependTrades'); + // console.log('in prependTrades'); const tradeTemplate = _.template($('#trade-template').html()); this.$('#trades').prepend(tradeTemplate(quoteView.model.attributes)); }, tradeOrders(quote) { - console.log('in trade orders'); + // console.log('in trade orders'); const tradeQuoteView = new QuoteView({ model: quote, template: this.template, diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 6233f39..279b4ac 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -20,18 +20,18 @@ const QuoteView = Backbone.View.extend({ return this; }, buyQuote: function(e) { - console.log('You pressed the buy button in the Quote view') + // console.log('You pressed the buy button in the Quote view') this.model.set('price', this.model.buy()); this.model.set('buy', true); //triggers an event that the quotelistview is listening for: this.trigger('addTrade', this); - console.log('trade added'); + // console.log('trade added'); }, sellQuote: function(e) { this.model.set('price', this.model.sell()); this.model.set('buy', false); this.trigger('addTrade', this); - console.log('sold trade added'); + // console.log('sold trade added'); } }); From b0f48f9629a6c0d15431db1d499d6a231f9e3972 Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 18 Dec 2017 09:26:00 -0800 Subject: [PATCH 12/12] added some comments --- src/app.js | 1 + src/models/order.js | 4 ++++ src/views/order_list_view.js | 2 +- src/views/quote_list_view.js | 1 + src/views/quote_view.js | 4 ++-- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app.js b/src/app.js index eaeaf49..bba7a25 100644 --- a/src/app.js +++ b/src/app.js @@ -38,6 +38,7 @@ $(document).ready(function() { let bus = {}; bus = _.extend(bus, Backbone.Events); + //populate the quote collection const quotes = new QuoteList(quoteData); const simulator = new Simulator({ quotes: quotes, diff --git a/src/models/order.js b/src/models/order.js index 0ed3d4a..1652bd9 100644 --- a/src/models/order.js +++ b/src/models/order.js @@ -13,6 +13,10 @@ const Order = Backbone.Model.extend({ } if (attributes.targetPrice === 0) { + errors.targetPrice = ["Cannot enter a zero value for the target price."]; + } + + if (NaN(attributes.targetPrice)) { errors.targetPrice = ["A valid price is required"]; } diff --git a/src/views/order_list_view.js b/src/views/order_list_view.js index 52103f3..c4f80dd 100644 --- a/src/views/order_list_view.js +++ b/src/views/order_list_view.js @@ -59,7 +59,7 @@ const OrderListView = Backbone.View.extend({ const currentQuoteModel = this.quotes.find({symbol: symbol}); currentQuoteModel.set('buy', buyIsTrue); orderData['quote'] = currentQuoteModel; - console.log(currentQuoteModel); + // console.log(currentQuoteModel); const currentMarketPrice = currentQuoteModel.get('price'); // console.log(currentMarketPrice); diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index 84beeb6..4caec59 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -7,6 +7,7 @@ import Quote from '../models/quote'; const QuoteListView = Backbone.View.extend({ initialize(params) { this.bus = params.bus; + this.model = params.model; this.template = params.quotesTemplate; this.listenTo(this.bus, 'tradeMe', this.tradeOrders); this.listenTo(this.model, 'update', this.render); diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 279b4ac..7aa6360 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -21,15 +21,15 @@ const QuoteView = Backbone.View.extend({ }, buyQuote: function(e) { // console.log('You pressed the buy button in the Quote view') - this.model.set('price', this.model.buy()); this.model.set('buy', true); + this.model.set('price', this.model.buy()); //triggers an event that the quotelistview is listening for: this.trigger('addTrade', this); // console.log('trade added'); }, sellQuote: function(e) { - this.model.set('price', this.model.sell()); this.model.set('buy', false); + this.model.set('price', this.model.sell()); this.trigger('addTrade', this); // console.log('sold trade added'); }