From 31015eef0e0de73e5c5119432ad58acaa33fb80f Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 09:40:15 -0800 Subject: [PATCH 01/13] buy/sell method added --- src/models/quote.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/models/quote.js b/src/models/quote.js index 4fbf466..263bb81 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -8,10 +8,12 @@ const Quote = Backbone.Model.extend({ buy() { // Implement this function to increase the price by $1.00 + this.set('price', this.get('price') + 1.00); }, sell() { // Implement this function to decrease the price by $1.00 + this.set('price', this.get('price') - 1.00); }, }); From 56bd2d0a3f37124ac8604bb010cf700ea847c5dd Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 10:07:03 -0800 Subject: [PATCH 02/13] changed location of models/quote to locate correctly --- src/collections/quote_list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collections/quote_list.js b/src/collections/quote_list.js index 8da08cb..bfa112d 100644 --- a/src/collections/quote_list.js +++ b/src/collections/quote_list.js @@ -1,5 +1,5 @@ import Backbone from 'backbone'; -import Quote from 'models/quote'; +import Quote from '../models/quote'; const QuoteList = Backbone.Collection.extend({ model: Quote, From c4657c3a57a4010e443f52978236860157e408c8 Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 10:09:00 -0800 Subject: [PATCH 03/13] added imports --- src/app.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app.js b/src/app.js index 03ec910..04d3b0d 100644 --- a/src/app.js +++ b/src/app.js @@ -2,9 +2,14 @@ import 'foundation-sites/dist/foundation.css'; import 'css/app.css'; import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; import Simulator from 'models/simulator'; import QuoteList from 'collections/quote_list'; +import Quote from 'models/quote'; +import QuoteListView from 'views/quote_list_view'; +import QuoteView from 'views/quote_view'; const quoteData = [ { From 66a128ac91f39ba3ceeae0f582aa3fb34f3e4efb Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 10:09:37 -0800 Subject: [PATCH 04/13] working view for simulator --- src/app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/app.js b/src/app.js index 04d3b0d..2e0c3df 100644 --- a/src/app.js +++ b/src/app.js @@ -37,4 +37,12 @@ $(document).ready(function() { }); simulator.start(); + let quoteTemplate = _.template($('#quote-template').html()); + + const quoteListView = new QuoteListView({ + el: 'main', + model: quotes, + template: quoteTemplate, + }); + quoteListView.render(); }); From 042fa973f1a750f62a1f037abbea26e79d769cff Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 10:16:10 -0800 Subject: [PATCH 05/13] added quote view file and import/export --- src/views/quote_view.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/views/quote_view.js diff --git a/src/views/quote_view.js b/src/views/quote_view.js new file mode 100644 index 0000000..0350028 --- /dev/null +++ b/src/views/quote_view.js @@ -0,0 +1,5 @@ +import Backbone from 'backbone'; +import Quote from '../models/quote'; + + +export default QuoteView; From 90d4ae797790d8c5f859e5ca3f2d69a4508781f7 Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 10:17:15 -0800 Subject: [PATCH 06/13] events added for quote view --- src/views/quote_view.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/views/quote_view.js b/src/views/quote_view.js index 0350028..2b914d9 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -1,5 +1,31 @@ import Backbone from 'backbone'; import Quote from '../models/quote'; +const QuoteView = Backbone.View.extend({ + initialize(params) { + this.template = params.template, + this.listenTo(this.model, 'change', this.render) + }, + render() { + const compiledTemplate = this.template(this.model.toJSON()); + + this.$el.html(compiledTemplate); + + return this; + }, + events: { + 'click button.btn-buy': 'buy', + 'click button.btn-sell': 'sell', + }, + buy(event) { + console.log(event); + this.model.buy(); + }, + sell(event) { + console.log(event); + this.model.sell(); + } + +}); export default QuoteView; From 7d46804ed2a27e85a915ac230f86cfdb22d9a0d2 Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 10:18:31 -0800 Subject: [PATCH 07/13] quote list view file and import/export added --- src/views/quote_list_view.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/views/quote_list_view.js diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js new file mode 100644 index 0000000..0f9fd81 --- /dev/null +++ b/src/views/quote_list_view.js @@ -0,0 +1,7 @@ +import Backbone from 'backbone'; +import Quote from '../models/quote'; +import QuoteView from './quote_view'; + + + +export default QuoteListView; From 826c14ce1b53fa84942d05c8b402f4c9a5be571f Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 10:19:55 -0800 Subject: [PATCH 08/13] rendering for quote list view --- src/views/quote_list_view.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index 0f9fd81..d4350d9 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -2,6 +2,27 @@ import Backbone from 'backbone'; import Quote from '../models/quote'; import QuoteView from './quote_view'; +const QuoteListView = Backbone.View.extend({ + initialize(params) { + this.template = params.template; + this.listenTo(this.model, 'update', this.render); + }, + render() { + this.$('#quotes').empty(); + + 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; From 5ba4eccd9ed9f188709ca5760d7414d42af33d04 Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 11:24:35 -0800 Subject: [PATCH 09/13] wave 1 complete, minor clean up --- src/views/quote_list_view.js | 2 +- src/views/quote_view.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/views/quote_list_view.js b/src/views/quote_list_view.js index d4350d9..b7238ef 100644 --- a/src/views/quote_list_view.js +++ b/src/views/quote_list_view.js @@ -22,7 +22,7 @@ const QuoteListView = Backbone.View.extend({ 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 index 2b914d9..f02004d 100644 --- a/src/views/quote_view.js +++ b/src/views/quote_view.js @@ -18,11 +18,9 @@ const QuoteView = Backbone.View.extend({ 'click button.btn-sell': 'sell', }, buy(event) { - console.log(event); this.model.buy(); }, sell(event) { - console.log(event); this.model.sell(); } From 0730503c460e35d5c2d01730a44c12b4446caff7 Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 14:13:35 -0800 Subject: [PATCH 10/13] buy/sell trigger trade --- src/models/quote.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/models/quote.js b/src/models/quote.js index 263bb81..193918e 100644 --- a/src/models/quote.js +++ b/src/models/quote.js @@ -7,11 +7,21 @@ const Quote = Backbone.Model.extend({ }, buy() { + this.trigger('trade', { + buy: true, + price: this.get('price'), + symbol: this.get('symbol') + }); // Implement this function to increase the price by $1.00 this.set('price', this.get('price') + 1.00); }, sell() { + this.trigger('trade', { + buy: false, + price: this.get('price'), + symbol: this.get('symbol') + }); // Implement this function to decrease the price by $1.00 this.set('price', this.get('price') - 1.00); }, From 665ae81a630bc2804d0a43fdd0d514adfb062e10 Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 14:15:25 -0800 Subject: [PATCH 11/13] history view page added with import/export info --- src/views/history_view.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/views/history_view.js diff --git a/src/views/history_view.js b/src/views/history_view.js new file mode 100644 index 0000000..cc852c9 --- /dev/null +++ b/src/views/history_view.js @@ -0,0 +1,7 @@ +import Backbone from 'backbone'; + +const TradeHistoryView = Backbone.View.extend({ + +}); + +export default TradeHistoryView; From 72a221c76c15aca7c575073410412a47bce0f690 Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 13 Dec 2017 14:37:02 -0800 Subject: [PATCH 12/13] trade history showing correctly --- src/app.js | 11 +++++++++++ src/views/history_view.js | 26 +++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index 2e0c3df..86369ec 100644 --- a/src/app.js +++ b/src/app.js @@ -10,6 +10,7 @@ import QuoteList from 'collections/quote_list'; import Quote from 'models/quote'; import QuoteListView from 'views/quote_list_view'; import QuoteView from 'views/quote_view'; +import TradeHistoryView from 'views/history_view'; const quoteData = [ { @@ -45,4 +46,14 @@ $(document).ready(function() { template: quoteTemplate, }); quoteListView.render(); + + let tradeHistoryTemplate = _.template($('#trade-template').html()); + + const tradeHistoryView = new TradeHistoryView({ + el: 'main', + model: quotes, + template: tradeHistoryTemplate + }); + + tradeHistoryView.bind(); }); diff --git a/src/views/history_view.js b/src/views/history_view.js index cc852c9..a17734e 100644 --- a/src/views/history_view.js +++ b/src/views/history_view.js @@ -1,7 +1,31 @@ import Backbone from 'backbone'; const TradeHistoryView = Backbone.View.extend({ - + initialize(params) { + this.trades = []; + this.template = params.template; + + this.listenTo(this.model, 'update', this.bind); + }, + bind() { + this.stopListening(); + + this.model.each((quote) => { + this.listenTo(quote, 'trade', this.render); + }); + }, + render(info) { + this.trades.push(info); + + this.$('#trades').empty(); + + for (let i = 0; i < this.trades.length; i++) { + let compiledTemplate = this.template(this.trades[i]); + this.$('#trades').prepend(compiledTemplate); + } + + return this; + } }); export default TradeHistoryView; From 4115dc1ceaecb78e3f628a39210716d316f8fb6d Mon Sep 17 00:00:00 2001 From: Kayla Ecker Date: Wed, 20 Dec 2017 22:43:27 -0800 Subject: [PATCH 13/13] wave 3 --- src/app.js | 31 ++++++++++++++++- src/collections/order_list.js | 9 +++++ src/models/order.js | 11 ++++++ src/views/open_order_list_view.js | 37 ++++++++++++++++++++ src/views/open_order_view.js | 50 ++++++++++++++++++++++++++ src/views/order_form_view.js | 58 +++++++++++++++++++++++++++++++ src/views/trade_history_view.js | 23 ++++++++++++ 7 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 src/collections/order_list.js create mode 100644 src/models/order.js create mode 100644 src/views/open_order_list_view.js create mode 100644 src/views/open_order_view.js create mode 100644 src/views/order_form_view.js create mode 100644 src/views/trade_history_view.js diff --git a/src/app.js b/src/app.js index 86369ec..dd14701 100644 --- a/src/app.js +++ b/src/app.js @@ -7,10 +7,18 @@ import Backbone from 'backbone'; import Simulator from 'models/simulator'; import QuoteList from 'collections/quote_list'; +import OrderList from 'collections/order_list'; + import Quote from 'models/quote'; +import Order from 'models/order'; + +import OpenOrderView from 'views/open_order_view'; +import OpenOrderListView from 'views/open_order_list_view'; import QuoteListView from 'views/quote_list_view'; import QuoteView from 'views/quote_view'; import TradeHistoryView from 'views/history_view'; +import OrderFormView from 'views/order_form_view'; + const quoteData = [ { @@ -56,4 +64,25 @@ $(document).ready(function() { }); tradeHistoryView.bind(); -}); + +const order = new Order; +const orders = new OrderList(); + + let orderTemplate = _.template($('#order-template').html()); + + const openOrderListView = new OpenOrderListView({ + el: 'main', + model: orders, + template: orderTemplate, + }); + + const orderFormView = new OrderFormView({ + el: '.order-entry-form', + orderList: orders, + quoteList: quotes, + }); + + openOrderListView.render(); + orderFormView.render(); + + }); diff --git a/src/collections/order_list.js b/src/collections/order_list.js new file mode 100644 index 0000000..1c56940 --- /dev/null +++ b/src/collections/order_list.js @@ -0,0 +1,9 @@ + +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..f2f3824 --- /dev/null +++ b/src/models/order.js @@ -0,0 +1,11 @@ +import Backbone from 'backbone'; + +const Order = Backbone.Model.extend({ + defaults: { + symbol: 'UNDEF', + targetPrice: 0.00, + buy: true, + }, +}); + +export default Order; diff --git a/src/views/open_order_list_view.js b/src/views/open_order_list_view.js new file mode 100644 index 0000000..a07a219 --- /dev/null +++ b/src/views/open_order_list_view.js @@ -0,0 +1,37 @@ + +import Backbone from 'backbone'; +import Order from '../models/order'; +import OpenOrderView from './open_order_view'; +import Quote from '../models/quote'; +import QuoteView from '../views/quote_view'; +import QuoteList from '../collections/quote_list'; +import $ from 'jquery'; + +const OpenOrderListView = Backbone.View.extend({ + initialize(params) { + this.template = params.template; + this.model = params.model; + + this.listenTo(this.model, 'update', this.render); + }, + render() { + console.log('you are in the open order list view'); + this.$('#orders').empty(); + console.log('in the render in open order list view'); + console.log(this.model); + + this.model.each((order) => { + const openOrderView = new OpenOrderView({ + model: order, + template: this.template, + tagName: 'li', + className: 'orders', + }); + + this.$('#orders').append(openOrderView.render().$el); + }); + return this; + } +}); + +export default OpenOrderListView; diff --git a/src/views/open_order_view.js b/src/views/open_order_view.js new file mode 100644 index 0000000..b3a8232 --- /dev/null +++ b/src/views/open_order_view.js @@ -0,0 +1,50 @@ +import Backbone from 'backbone'; +import Quote from '../models/quote'; +import Order from '../models/order'; +import OrderList from '../collections/order_list'; +import $ from 'jquery'; + +const OpenOrderView = Backbone.View.extend({ + initialize(params) { + this.template = params.template; + this.model = params.model; + this.listenTo(this.model, 'change', this.render); + this.listenTo(this.model.get('quote'), 'change', this.completeOrder); + + }, + completeOrder() { + console.log('the complete order method is being called'); + let quote = this.model.get('quote'); + + if (this.model.get('buy')) { + if (this.model.get('targetPrice') >= quote.get('price')) { + quote.buy(); + this.model.destroy(); + this.remove(); + } + } else { + if (this.model.get('targetPrice') <= quote.get('price')) { + quote.sell(); + this.model.destroy(); + this.remove(); + } + } + }, + render() { + const compiledTemplate = this.template(this.model.toJSON()); + + this.$el.html(compiledTemplate); + + return this; + }, + events: { + 'click button.btn-cancel': 'cancel', + }, + cancel(event) { + if (confirm("Are you sure?") === true){ + this.model.destroy(); + } + }, +}); + +export default OpenOrderView; diff --git a/src/views/order_form_view.js b/src/views/order_form_view.js new file mode 100644 index 0000000..d89fa17 --- /dev/null +++ b/src/views/order_form_view.js @@ -0,0 +1,58 @@ +import Backbone from 'backbone'; +import Quote from '../models/quote'; +import Order from '../models/order'; +import OrderList from '../collections/order_list'; +import $ from 'jquery'; + +const OrderFormView = Backbone.View.extend({ + initialize(params) { + this.orderList = params.orderList; + this.quoteList = params.quoteList; + console.log(params); + }, + render() { + console.log('you are in the order form view render'); + + this.quoteList.each((quote)=> { + console.log(quote.get('symbol')); + this.$('#select').append($(``)); + }); + return this; + }, + events: { + 'click button.btn-buy': 'buy', + 'click button.btn-sell': 'sell', + }, + buy(event) { + console.log(event); + event.isBuy = true; + this.addNewOrder(event); + }, + sell(event) { + console.log(event); + event.isBuy = false; + this.addNewOrder(event); + + }, + addNewOrder(event) { + console.log('in the add new order'); + event.preventDefault(); + const orderData = {}; + orderData['symbol'] = $('select[name=symbol]').val(); + orderData['targetPrice'] = parseFloat($('input[name=price-target]').val()); + orderData['quote'] = this.quoteList.findWhere({symbol: orderData['symbol']}); + + orderData['buy'] = event.isBuy; + + console.log(orderData); + + const newOrder = new Order(orderData); + this.orderList.push(newOrder); + console.log(this.orderList); + + this.$('select[name=symbol]').val(''); + this.$('input[name=price-target]').val(''); + }, +}); + +export default OrderFormView; diff --git a/src/views/trade_history_view.js b/src/views/trade_history_view.js new file mode 100644 index 0000000..e461a44 --- /dev/null +++ b/src/views/trade_history_view.js @@ -0,0 +1,23 @@ +import Backbone from 'backbone'; + +const TradeHistoryView = Backbone.View.extend({ + initialize(params) { + this.template = params.template; + + }, + bind() { + + this.model.each((quote) => { + this.listenTo(quote, 'trade', this.render); + }); + }, + render(data) { + + let compiledTemplate = this.template(data); + this.$('#trades').prepend(compiledTemplate); + + return this; + } +}); + +export default TradeHistoryView;