From 530168fca0a93ebb8117b5c1dd7bcd666d74cbb9 Mon Sep 17 00:00:00 2001 From: Juan Cook Date: Mon, 9 Nov 2015 18:28:17 -0300 Subject: [PATCH 1/8] new file blank --- client/demo/ex/assignment1/index.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 client/demo/ex/assignment1/index.html diff --git a/client/demo/ex/assignment1/index.html b/client/demo/ex/assignment1/index.html new file mode 100644 index 0000000..efcef94 --- /dev/null +++ b/client/demo/ex/assignment1/index.html @@ -0,0 +1,23 @@ + + + + + + + + + +
+
dasdasdas +

Text Analyzer

d + +

Stats

+

Chars: {{text.length}} Words: {{(text.split(' ')).length}}

+
    +
  • {{word | uppercase}}
  • +
+
+
+ + + From a7f091f15a70ab47c45337a36436db89766605ef Mon Sep 17 00:00:00 2001 From: Juan Cook Date: Tue, 10 Nov 2015 16:31:14 -0300 Subject: [PATCH 2/8] assign1 almost finish --- client/demo/ex/assignment1/index.html | 116 +++++++++++++++++++++++--- 1 file changed, 105 insertions(+), 11 deletions(-) diff --git a/client/demo/ex/assignment1/index.html b/client/demo/ex/assignment1/index.html index efcef94..ed960e4 100644 --- a/client/demo/ex/assignment1/index.html +++ b/client/demo/ex/assignment1/index.html @@ -5,19 +5,113 @@ + Expense App Assignment1 -
-
dasdasdas -

Text Analyzer

d - -

Stats

-

Chars: {{text.length}} Words: {{(text.split(' ')).length}}

-
    -
  • {{word | uppercase}}
  • -
-
+
+

Expenses

+
+ +
+

Create Expense

+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+
+
+
+ + + + + + + + + + + + + + + + +
DateTypeDescriptionAmount
{{ exp.date | date: 'dd/MM/yy'}}{{ exp.type }}{{ exp.description }}{{ exp.amount }} + + +
+
+
+

Totals by Type

+
+ + + + + + + + + + + +
TypeTotal
{{type}}{{ exp.amount + total }} +
+
+
+

Total All Types

+
+
+

{{ exp.amount + total}}

+
+
+
- From 8aa7bf987ac3cb985dcbb77aea9b37c7adea913b Mon Sep 17 00:00:00 2001 From: Juan Cook Date: Tue, 17 Nov 2015 17:22:13 -0300 Subject: [PATCH 3/8] new files of ex2-not finished --- client/demo/ex/assignment2/app.js | 52 +++++++++++++++ client/demo/ex/assignment2/index.html | 95 +++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 client/demo/ex/assignment2/app.js create mode 100644 client/demo/ex/assignment2/index.html diff --git a/client/demo/ex/assignment2/app.js b/client/demo/ex/assignment2/app.js new file mode 100644 index 0000000..3fb0532 --- /dev/null +++ b/client/demo/ex/assignment2/app.js @@ -0,0 +1,52 @@ +angular + .module('expensesApp', []); + +angular + .module('expensesApp') + .controller('ExpenseController', ExpenseController); + + +ExpenseController.$inject = ['$scope']; + +function ExpenseController($scope){ + vm = this; + + vm.expenses = []; + vm.expense = {}; + vm.types = ['food', 'transportation', 'lodging', 'financial', 'sales', 'other.']; + vm.isEditing = false; + + vm.total = 0; + + vm.newExpense = function(){ + console.debug(vm.expense); + vm.expenses.push(vm.expense); + vm.expense = {}; + }; + + vm.delete = function(exp){ + console.debug(exp); + vm.expenses.splice(vm.expenses.indexOf(exp),1); + }; + + vm.edit = function(exp){ + vm.expense = angular.copy(exp); + vm.isEditing = true; + }; + + vm.update = function(exp){ + vm.expenses.splice(vm.expenses.indexOf(exp), 1); + exp = vm.expense; + vm.isEditing = false; + + + vm.expenses.push(vm.expense); + + vm.expense = {}; + }; + + vm.cancel = function(){ + vm.expense = {}; + }; + +} \ No newline at end of file diff --git a/client/demo/ex/assignment2/index.html b/client/demo/ex/assignment2/index.html new file mode 100644 index 0000000..917e464 --- /dev/null +++ b/client/demo/ex/assignment2/index.html @@ -0,0 +1,95 @@ + + + + + + + + + + Expense App Assignment1 + + +
+

Expenses

+
+
+

Create Expense

+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+
+
+
+ + + + + + + + + + + + + + + + +
DateTypeDescriptionAmount
{{ expen.date | date: 'dd/MM/yy'}}{{ expen.type }}{{ expen.description }}{{ expen.amount }} + + +
+
+
+

Totals by Type

+
+ + + + + + + + + + + +
TypeTotal
{{type}}{{ e.amount + total }}
+
+
+

Total All Types

+
+
+

{{ e.amount + total}}

+
+
+
+
+ + From 5af9140ba454e9f4655113d92984ffd33c4ca63b Mon Sep 17 00:00:00 2001 From: Juan Cook Date: Fri, 20 Nov 2015 17:15:59 -0300 Subject: [PATCH 4/8] finished assignment 2 with subtotals, total, background colors on types and also hides on empty subtotal. --- client/demo/ex/assignment1/index2.html | 118 ++++++++++++++++++ client/demo/ex/assignment2/app.js | 52 +------- .../demo/ex/assignment2/expensesController.js | 101 +++++++++++++++ client/demo/ex/assignment2/index.html | 61 +++++---- 4 files changed, 259 insertions(+), 73 deletions(-) create mode 100644 client/demo/ex/assignment1/index2.html create mode 100644 client/demo/ex/assignment2/expensesController.js diff --git a/client/demo/ex/assignment1/index2.html b/client/demo/ex/assignment1/index2.html new file mode 100644 index 0000000..fac60cd --- /dev/null +++ b/client/demo/ex/assignment1/index2.html @@ -0,0 +1,118 @@ + + + + + + + + + + +
+
+

Todo List #{{list.length}}

+
+ +
+
+ Date: +
+
+ +
+
+ Type: +
+
+ +
+
+ Description: +
+
+ +
+
+ Amount: +
+
+ +
+
+
+
+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
DateTypeDescriptionAmountAction
{{item.date}}{{item.type}}{{item.description}}{{item.amount}} + + + +
+ + + + + + + + + + + + + +
TypeTotal
{{type}}{{total + item.amout * 1}}
+ +
+
+
+ + \ No newline at end of file diff --git a/client/demo/ex/assignment2/app.js b/client/demo/ex/assignment2/app.js index 3fb0532..954b27e 100644 --- a/client/demo/ex/assignment2/app.js +++ b/client/demo/ex/assignment2/app.js @@ -1,52 +1,2 @@ angular - .module('expensesApp', []); - -angular - .module('expensesApp') - .controller('ExpenseController', ExpenseController); - - -ExpenseController.$inject = ['$scope']; - -function ExpenseController($scope){ - vm = this; - - vm.expenses = []; - vm.expense = {}; - vm.types = ['food', 'transportation', 'lodging', 'financial', 'sales', 'other.']; - vm.isEditing = false; - - vm.total = 0; - - vm.newExpense = function(){ - console.debug(vm.expense); - vm.expenses.push(vm.expense); - vm.expense = {}; - }; - - vm.delete = function(exp){ - console.debug(exp); - vm.expenses.splice(vm.expenses.indexOf(exp),1); - }; - - vm.edit = function(exp){ - vm.expense = angular.copy(exp); - vm.isEditing = true; - }; - - vm.update = function(exp){ - vm.expenses.splice(vm.expenses.indexOf(exp), 1); - exp = vm.expense; - vm.isEditing = false; - - - vm.expenses.push(vm.expense); - - vm.expense = {}; - }; - - vm.cancel = function(){ - vm.expense = {}; - }; - -} \ No newline at end of file + .module('expensesApp', []); \ No newline at end of file diff --git a/client/demo/ex/assignment2/expensesController.js b/client/demo/ex/assignment2/expensesController.js new file mode 100644 index 0000000..805f8f7 --- /dev/null +++ b/client/demo/ex/assignment2/expensesController.js @@ -0,0 +1,101 @@ +angular + .module('expensesApp') + .controller('ExpenseController', ExpenseController); + + +ExpenseController.$inject = ['$filter']; + +function ExpenseController($filter){ + vm = this; + + vm.expenses = []; + vm.expense = {}; + vm.types = ['food', 'transportation', 'lodging', 'financial', 'sales', 'other.']; + vm.isEditing = false; + + vm.total = 0; + + vm.newExpense = function(){ + vm.expense.id = vm.expenses.length + 1; + vm.expenses.push(vm.expense); + //console.debug(vm.expense); + vm.expense = {}; + }; + + vm.delete = function(exp){ + vm.expenses.splice(vm.expenses.indexOf(exp),1); + }; + + vm.edit = function(exp){ + vm.expense = angular.copy(exp); + vm.isEditing = true; + }; + + vm.update = function(index, exp){ + var selectedExpense = $filter('filter')(vm.expenses, {id: exp.id})[0]; + selectedExpense.date = exp.date; + selectedExpense.type = exp.type; + selectedExpense.description = exp.description; + selectedExpense.amount = exp.amount; + + vm.isEditing = false; + vm.expense = {}; + }; + + vm.cancel = function(){ + vm.expense = {}; + vm.isEditing = false; + }; + + vm.getTotal = getTotal; + vm.getTotalByType = getTotalByType; + vm.setColor = setColor; + + function getTotal(){ + var totals = 0; + angular.forEach(vm.expenses, function(key, value){ + totals += key.amount; + }); + return totals; + } + + function getTotalByType(type){ + var totals = 0; + angular.forEach(vm.expenses, function(key, value){ + if (key.type == type){ + totals += key.amount; + } + }); + return totals; + } + + function setColor(type){ + console.log(type); + switch (type){ + case 'food': + return { 'background-color': "lightblue" }; + case 'transportation': + return { 'background-color': "lightcoral" }; + case 'lodging': + return { 'background-color': "lightgray" }; + case 'financial': + return { 'background-color': "lightgreen" }; + case 'sales': + return { 'background-color': "lightskyblue" }; + case 'other.': + return { 'background-color': "lightsalmon" }; + } + } +} + + + + + + + + + + + + diff --git a/client/demo/ex/assignment2/index.html b/client/demo/ex/assignment2/index.html index 917e464..ca7a34e 100644 --- a/client/demo/ex/assignment2/index.html +++ b/client/demo/ex/assignment2/index.html @@ -4,19 +4,23 @@ - - Expense App Assignment1 + + + + + Expense App Assignment2

Expenses

-
+

Create Expense

+
@@ -33,13 +37,14 @@

Create Expense

- +
+
@@ -49,7 +54,7 @@

Create Expense

- + @@ -67,26 +72,38 @@

Create Expense

Amount
{{ expen.date | date: 'dd/MM/yy'}} {{ expen.type }} {{ expen.description }}

-

Totals by Type

-
- - - - - - - - - - - -
TypeTotal
{{type}}{{ e.amount + total }}
+
+
+ Totals by Type +
+
+
+ + + + + + + + + + + +
TypeTotal
{{ type }}{{ exp.getTotalByType(type) }}
+
+
-

Total All Types

-
-

{{ e.amount + total}}

+
+
+ Total All Types +
+
+
+

Total: {{ exp.getTotal() }}

+
+
From 8aa93e86d7e7e74c4ec786b75346c5a98b224245 Mon Sep 17 00:00:00 2001 From: Juan Cook Date: Tue, 24 Nov 2015 10:52:17 -0300 Subject: [PATCH 5/8] assignment 2 --- .../pages/movie/movie-page.similar.route.js | 2 +- .../ex/assignment2/expensesController.spec.js | 29 +++++++ client/demo/ex/assignment2/index.html | 8 +- e2e/ex/main.spec.js | 76 +++++++++++++++++++ 4 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 client/demo/ex/assignment2/expensesController.spec.js create mode 100644 e2e/ex/main.spec.js diff --git a/client/app/pages/movie/movie-page.similar.route.js b/client/app/pages/movie/movie-page.similar.route.js index c327fac..29a503e 100644 --- a/client/app/pages/movie/movie-page.similar.route.js +++ b/client/app/pages/movie/movie-page.similar.route.js @@ -5,7 +5,7 @@ .module('moviesApp') .config(configRouteMovieSimilar); - configRouteListing.$inject = [ + configRouteMovieSimilar.$inject = [ '$stateProvider' ]; diff --git a/client/demo/ex/assignment2/expensesController.spec.js b/client/demo/ex/assignment2/expensesController.spec.js new file mode 100644 index 0000000..6dbf992 --- /dev/null +++ b/client/demo/ex/assignment2/expensesController.spec.js @@ -0,0 +1,29 @@ +describe('Controller: expensesController', function () { + 'use strict'; + var controller, + scope; + // Refresh the $filter every time. + beforeEach(module('expensesApp')); + beforeEach(inject(function (_$rootScope_, $controller) { + scope = _$rootScope_.$new(); + controller = $controller('ExpenseController', + {$scope: scope}); + }) + ); + + it('should start empty', function () { + expect(controller.expenses.length).to.equal(2); + }); + + //it('should add items', function () { + // controller.itemText = 'First item'; + // controller.add(controller.itemText); + // expect(controller.list.length).to.equal(1); + // controller.itemText = 'Second item'; + // controller.add(controller.itemText); + // expect(controller.list.length).to.equal(2); + // controller.remove(1); + // expect(controller.list.length).to.equal(1); + //}); + +}); diff --git a/client/demo/ex/assignment2/index.html b/client/demo/ex/assignment2/index.html index ca7a34e..e1be77c 100644 --- a/client/demo/ex/assignment2/index.html +++ b/client/demo/ex/assignment2/index.html @@ -46,7 +46,7 @@

Create Expense


- +
@@ -55,15 +55,15 @@

Create Expense

- + diff --git a/e2e/ex/main.spec.js b/e2e/ex/main.spec.js new file mode 100644 index 0000000..a3715cf --- /dev/null +++ b/e2e/ex/main.spec.js @@ -0,0 +1,76 @@ +'use strict'; + +describe('Expenses app', function () { + var page; + beforeEach(function () { + browser.get('/demo/ex/assignment2/'); + page = {}; + }); + + it('should include H1 title', function () { + expect(element(by.tagName('h1')).getText()).to.eventually.equal('Expenses'); + }); + + it('should add/edit/delete an item from/to the table', function () { + page.date = element(by.model('exp.expense.date')); + page.date.sendKeys('09/06/1988'); + + page.type = element(by.cssContainingText('option', 'transportation')).click(); + page.description = element(by.model('exp.expense.description')).sendKeys('Testing Expense'); + page.amount = element(by.model('exp.expense.amount')).sendKeys('1000'); + + page.button = element(by.id('create-button')); + page.button.click(); + + //Quantity + var items = element.all(by.repeater('expen in exp.expenses track by expen.id')); + expect(items.count()).to.eventually.equal(1); + + //Check content + element(by.css('.table.items')).all(by.css('tbody tr')).then(function (rows) { + return rows[0].$$('td').then(function (cols) { + expect(cols[0].getText()).to.eventually.equal('09/06/88'); + expect(cols[1].getText()).to.eventually.equal('transportation'); + expect(cols[2].getText()).to.eventually.equal('Testing Expense'); + expect(cols[3].getText()).to.eventually.equal('1000'); + }); + }); + + //Check if fields were cleaned + expect(page.date.getAttribute('value')).to.eventually.equal(''); + expect(page.description.getAttribute('value')).to.eventually.equal(''); + expect(page.amount.getAttribute('value')).to.eventually.equal(''); + + //Edit + var items = element.all(by.repeater('expen in exp.expenses track by expen.id')); + items.first().then(function () { + page.button = element(by.css('.edit-expense')); + page.button.click(); + }); + + page.date = element(by.model('exp.expense.date')); + page.date.sendKeys('01/01/2015'); + + page.button = element(by.id('update-button')); + page.button.click(); + + element(by.css('.table.items')).all(by.css('tbody tr')).then(function (rows) { + return rows[0].$$('td').then(function (cols) { + expect(cols[0].getText()).to.eventually.equal('01/01/15'); + expect(cols[1].getText()).to.eventually.equal('transportation'); + expect(cols[2].getText()).to.eventually.equal('Testing Expense'); + expect(cols[3].getText()).to.eventually.equal('1000'); + }); + }); + + //Delete + var items = element.all(by.repeater('expen in exp.expenses track by expen.id')); + items.first().then(function () { + page.button = element(by.css('.delete-expense')); + page.button.click(); + }); + + expect(element.all(by.repeater('expen in exp.expenses track by expen.id')).count()).to.eventually.equal(0); + }); + +}); From 9ee461b28b8e6f3263c72648ef826213e502c337 Mon Sep 17 00:00:00 2001 From: Juan Cook Date: Tue, 24 Nov 2015 17:01:28 -0300 Subject: [PATCH 6/8] almost finished unit test of controller --- .../demo/ex/assignment2/expensesController.js | 2 +- .../ex/assignment2/expensesController.spec.js | 67 ++++++++++++++++--- client/demo/ex/assignment2/index.html | 2 +- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/client/demo/ex/assignment2/expensesController.js b/client/demo/ex/assignment2/expensesController.js index 805f8f7..b474c08 100644 --- a/client/demo/ex/assignment2/expensesController.js +++ b/client/demo/ex/assignment2/expensesController.js @@ -31,7 +31,7 @@ function ExpenseController($filter){ vm.isEditing = true; }; - vm.update = function(index, exp){ + vm.update = function(exp){ var selectedExpense = $filter('filter')(vm.expenses, {id: exp.id})[0]; selectedExpense.date = exp.date; selectedExpense.type = exp.type; diff --git a/client/demo/ex/assignment2/expensesController.spec.js b/client/demo/ex/assignment2/expensesController.spec.js index 6dbf992..851cbfd 100644 --- a/client/demo/ex/assignment2/expensesController.spec.js +++ b/client/demo/ex/assignment2/expensesController.spec.js @@ -12,18 +12,63 @@ describe('Controller: expensesController', function () { ); it('should start empty', function () { - expect(controller.expenses.length).to.equal(2); + expect(controller.expenses.length).to.equal(0); }); - //it('should add items', function () { - // controller.itemText = 'First item'; - // controller.add(controller.itemText); - // expect(controller.list.length).to.equal(1); - // controller.itemText = 'Second item'; - // controller.add(controller.itemText); - // expect(controller.list.length).to.equal(2); - // controller.remove(1); - // expect(controller.list.length).to.equal(1); - //}); + it('should add/remove items', function () { + //Create + //First expense + controller.expense.date = '09/06/1988'; + controller.expense.type = 'transportation'; + controller.expense.description = 'Testing Expense'; + controller.expense.amount = 1000; + controller.newExpense(); + + expect(controller.expenses.length).to.equal(1); + + //Second expense + controller.expense.date = '01/01/2015'; + controller.expense.type = 'food'; + controller.expense.description = 'Testing Expense 2'; + controller.expense.amount = 10000; + + controller.newExpense(); + + expect(controller.expenses.length).to.equal(2); + + //Delete: + controller.delete(controller.expense); + expect(controller.expenses.length).to.equal(1); + + //Edit: + //controller.expense = {}; + //controller.expense.date = '09/06/1988'; + controller.expense.type = 'transportation'; + //controller.expense.description = 'Testing Expense'; + //controller.expense.amount = 1000; + controller.update(controller.expense); + expect(controller.expenses[0].type).to.equal('financial'); + }); }); + +//newExpense OK +//delete OK +//update + +//gettotal +//gettotalbytype +//setcolor + + +//vm.update = function(index, exp){ +// var selectedExpense = $filter('filter')(vm.expenses, {id: exp.id})[0]; +// selectedExpense.date = exp.date; +// selectedExpense.type = exp.type; +// selectedExpense.description = exp.description; +// selectedExpense.amount = exp.amount; +// +// vm.isEditing = false; +// vm.expense = {}; +//}; +// diff --git a/client/demo/ex/assignment2/index.html b/client/demo/ex/assignment2/index.html index e1be77c..7a49fc6 100644 --- a/client/demo/ex/assignment2/index.html +++ b/client/demo/ex/assignment2/index.html @@ -37,7 +37,7 @@

Create Expense

- +
From 8de42429ea3f498a2c9b00b3a3dd70c30b83cd16 Mon Sep 17 00:00:00 2001 From: Juan Cook Date: Wed, 25 Nov 2015 10:05:36 -0300 Subject: [PATCH 7/8] test case of controller --- .../ex/assignment2/expensesController.spec.js | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/client/demo/ex/assignment2/expensesController.spec.js b/client/demo/ex/assignment2/expensesController.spec.js index 851cbfd..539eaf8 100644 --- a/client/demo/ex/assignment2/expensesController.spec.js +++ b/client/demo/ex/assignment2/expensesController.spec.js @@ -39,36 +39,6 @@ describe('Controller: expensesController', function () { //Delete: controller.delete(controller.expense); expect(controller.expenses.length).to.equal(1); - - //Edit: - //controller.expense = {}; - //controller.expense.date = '09/06/1988'; - controller.expense.type = 'transportation'; - //controller.expense.description = 'Testing Expense'; - //controller.expense.amount = 1000; - controller.update(controller.expense); - expect(controller.expenses[0].type).to.equal('financial'); }); }); - -//newExpense OK -//delete OK -//update - -//gettotal -//gettotalbytype -//setcolor - - -//vm.update = function(index, exp){ -// var selectedExpense = $filter('filter')(vm.expenses, {id: exp.id})[0]; -// selectedExpense.date = exp.date; -// selectedExpense.type = exp.type; -// selectedExpense.description = exp.description; -// selectedExpense.amount = exp.amount; -// -// vm.isEditing = false; -// vm.expense = {}; -//}; -// From 029aafab95e8c51d731d3d5f301a181abd4bb423 Mon Sep 17 00:00:00 2001 From: Juan Cook Date: Thu, 26 Nov 2015 16:59:34 -0300 Subject: [PATCH 8/8] assignment 3 not finished yet --- .../movies-connector/connector.module.js | 9 ++- .../movieConnectorCache.factory.js | 73 +++++++++++++++++++ .../moviesConnector.factory.js | 61 ++++++++++++++-- client/index.html | 1 + 4 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 client/app/components/movies-connector/movieConnectorCache.factory.js diff --git a/client/app/components/movies-connector/connector.module.js b/client/app/components/movies-connector/connector.module.js index d5698e3..46f3838 100644 --- a/client/app/components/movies-connector/connector.module.js +++ b/client/app/components/movies-connector/connector.module.js @@ -1,5 +1,8 @@ 'use strict'; -angular.module('movies.connector', [ - -]); +angular + .module('movies.connector', []) + .constant('cache_calls', { + SEARCH_MOVIES: 100, + INFO_MOVIES: 100 + }); diff --git a/client/app/components/movies-connector/movieConnectorCache.factory.js b/client/app/components/movies-connector/movieConnectorCache.factory.js new file mode 100644 index 0000000..6bf5c3d --- /dev/null +++ b/client/app/components/movies-connector/movieConnectorCache.factory.js @@ -0,0 +1,73 @@ +(function() { + 'use strict'; + angular + .module('movies.connector') + .factory('moviesConnectorCache', moviesConnectorCacheFactory); + + /** + * @ngInject + */ + moviesConnectorCacheFactory.$inject = [ + 'cache_calls' + ]; + + function moviesConnectorCacheFactory( + cache_calls + ) { + var service = { + catchedInfo: [], + catchedSearch : [], + getCacheInfo: getCacheInfo, + addCacheInfo: addCacheInfo, + getCacheSearch: getCacheSearch, + addCacheSearch: addCacheSearch + }; + + function getCacheInfo(movieId) { + var result = {}; + result.hasCache = false; + result.data = {}; + angular.forEach(service.catchedInfo, function(obj){ + if (movieId == obj.movieId){ + result.hasCache = true; + result.data = obj; + console.log('cache INFO found!'); + } + }); + return result; + } + + function addCacheInfo(movieId, result){ + if (service.catchedInfo.length > cache_calls.INFO_MOVIES){ + console.log('Cleaning INFO cache'); + service.catchedInfo = []; + } + service.catchedInfo.push({ movieId: movieId, result: result}); + } + + function getCacheSearch(query) { + var result = {}; + result.hasCache = false; + result.data = {}; + angular.forEach(service.catchedSearch, function(obj){ + if (query == obj.query){ + result.hasCache = true; + result.data = obj; + console.log('cache MOVIES found!'); + } + }); + return result; + } + + function addCacheSearch(query, result){ + if (service.catchedSearch.length > cache_calls.SEARCH_MOVIES){ + console.log('Cleaning MOVIES cache'); + service.catchedSearch = []; + } + service.catchedSearch.push({ query: query, result: result}); + } + + return service; + } + +})(); diff --git a/client/app/components/movies-connector/moviesConnector.factory.js b/client/app/components/movies-connector/moviesConnector.factory.js index 5cd3886..6136bdb 100644 --- a/client/app/components/movies-connector/moviesConnector.factory.js +++ b/client/app/components/movies-connector/moviesConnector.factory.js @@ -9,29 +9,80 @@ */ moviesConnectorFactory.$inject = [ '$q', - '$http' + '$http', + 'moviesConnectorCache' ]; function moviesConnectorFactory( $q, - $http + $http, + moviesConnectorCache ) { var service = { cachedConfiguration: null, topRatedMovies: topRatedMovies, configuration: configuration, search: search, - movieInfo: movieInfo + movieInfo: movieInfo, + topRatedMoviesCompleteInfo: topRatedMoviesCompleteInfo }; function topRatedMovies() { return $http.get('/api/movies/'); } + + function topRatedMoviesCompleteInfo(){ + topRatedMovies() + .then(function(response){ + angular.forEach(response.results, function(obj){ + movieInfo(obj.id) + .then(function(response){ + console.log(response) + }); + }); + }); + + + } + function movieInfo(movieId) { - return $http.get('/api/movies/info/' + movieId); + var result = {}; + var deferred = $q.defer(); + + var cacheResult = moviesConnectorCache.getCacheInfo(movieId); + if (cacheResult.hasCache === true){ //the query has been catched: + result.data = cacheResult.data.result; + deferred.resolve(result); + } else { //that query has NOT been catched: + $http.get('/api/movies/info/' + movieId) + .then(function(response){ + result.data = response.data; + moviesConnectorCache.addCacheInfo(movieId, result.data); + deferred.resolve(result); + }); + } + + return deferred.promise; } + function search(query) { - return $http.get('/api/movies/search/' + query); + var result = {}; + var deferred = $q.defer(); + + var cacheResult = moviesConnectorCache.getCacheSearch(query); + if (cacheResult.hasCache === true){ //the query has been catched: + result.data = cacheResult.data.result; + deferred.resolve(result); + } else { //that query has NOT been catched: + $http.get('/api/movies/search/' + query) + .then(function(response){ + result.data = response.data; + moviesConnectorCache.addCacheSearch(query, result.data); + deferred.resolve(result); + }); + } + + return deferred.promise; } function configuration() { diff --git a/client/index.html b/client/index.html index 2f82e12..e20b97c 100644 --- a/client/index.html +++ b/client/index.html @@ -75,6 +75,7 @@ +
Date Type
{{ expen.date | date: 'dd/MM/yy'}}{{ expen.date | date: 'MM/dd/yy'}} {{ expen.type }} {{ expen.description }} {{ expen.amount }} - -