From 5c1aac68f742cbd4e0a89130e3a4ddec09868526 Mon Sep 17 00:00:00 2001 From: Pablo Manuel Araya Date: Tue, 10 Nov 2015 15:41:57 -0300 Subject: [PATCH 1/8] Assignment1 app done. Pending Test --- bower.json | 3 +- client/demo/expenses/expenses-controller.js | 88 +++++++++++++++++++++ client/demo/expenses/index.html | 78 ++++++++++++++++++ client/demo/expenses/style.css | 16 ++++ client/demo/todo-list/style.css | 15 ++++ client/index.html | 3 + 6 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 client/demo/expenses/expenses-controller.js create mode 100644 client/demo/expenses/index.html create mode 100644 client/demo/expenses/style.css create mode 100644 client/demo/todo-list/style.css diff --git a/bower.json b/bower.json index 9ebfc71..eb6d9ed 100644 --- a/bower.json +++ b/bower.json @@ -12,7 +12,8 @@ "angular-bootstrap": "~0.14.0", "font-awesome": ">=4.1.0", "lodash": "~2.4.1", - "angular-ui-router": "~0.2.15" + "angular-ui-router": "~0.2.15", + "angular-ui-date": "~0.0.8" }, "devDependencies": { "angular-mocks": ">=1.2.*", diff --git a/client/demo/expenses/expenses-controller.js b/client/demo/expenses/expenses-controller.js new file mode 100644 index 0000000..540fe81 --- /dev/null +++ b/client/demo/expenses/expenses-controller.js @@ -0,0 +1,88 @@ +(function() { + 'use strict'; + + // Create module and controller + angular + .module('expensesApp',['ui.date']) + .controller('expensesController', expensesController); + + + expensesController.$inject = [ + ]; + + function expensesController() { + + // Controller as viewModel + var vm = this; + + // Initialization + vm.list = []; + vm.listTotal = []; + + vm.itemText = ''; + + // Controller methods + vm.add = add; + vm.remove = remove; + + /* Adds an item to the todo list */ + function add(descTxt,dateTxt,typeDdl,amountTxt) { + + vm.list.push({desc:descTxt,date:dateTxt, typeExpense:typeDdl, amount:amountTxt}); + + var searchTerm = typeDdl; + + var index = -1; + + for(var i = 0, len = vm.listTotal.length; i < len; i++) { + if (vm.listTotal[i].type === searchTerm) { + index = i; + break; + } + } + + if(index == -1){ + vm.listTotal.push({type:typeDdl, total:amountTxt}); + } + else{ + vm.listTotal[index].total = parseInt(vm.listTotal[index].total) + parseInt(amountTxt); + } + } + + + function remove(indexList) { + + var amountTxt = vm.list[indexList].amount; + var typeExpenseTxt = vm.list[indexList].typeExpense; + + var indexTotal = -1; + + for(var i = 0, len = vm.listTotal.length; i < len; i++) { + if (vm.listTotal[i].type === typeExpenseTxt) { + indexTotal = i; + break; + } + } + + vm.list.splice(indexList,1); + + vm.listTotal[indexTotal].total = parseInt(vm.listTotal[indexTotal].total) - parseInt(amountTxt); + + /* + var countAmountBytype = 0; + + for(var i = 0, len = vm.listTotal.length; i < len; i++) { + if (vm.listTotal[i].type === typeExpenseTxt) { + countAmountBytype++; + } + } + + if(countAmountBytype = 1){ + vm.listTotal.splice(vm.list.indexOf(typeExpenseTxt), 1) + } + else{ + vm.listTotal[index].total = parseInt(vm.listTotal[index].total) - parseInt(amountTxt); + }*/ + } + } +})(); diff --git a/client/demo/expenses/index.html b/client/demo/expenses/index.html new file mode 100644 index 0000000..7e96f1a --- /dev/null +++ b/client/demo/expenses/index.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + +
+
+

Expenses #{{expVM.list.length}}

+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

+ {{ item.desc }} + {{ item.date | date:'shortDate' }} + {{ item.typeExpense }} + {{ item.amount | currency }} + +

+
+
+
+

Totals:

+
+

+ {{item.type}} : {{item.total}} +

+
+
+
+
+ + \ No newline at end of file diff --git a/client/demo/expenses/style.css b/client/demo/expenses/style.css new file mode 100644 index 0000000..674a5d5 --- /dev/null +++ b/client/demo/expenses/style.css @@ -0,0 +1,16 @@ +.food { + background-color: gray; +} +.other { + background-color: red; +} +.finantial { + background-color: yellow; +} +.lodging { + background-color: blue; +} +.transp { + background-color: green; +} + diff --git a/client/demo/todo-list/style.css b/client/demo/todo-list/style.css new file mode 100644 index 0000000..5daced8 --- /dev/null +++ b/client/demo/todo-list/style.css @@ -0,0 +1,15 @@ +.transp { + background-color: green; +} +.food { + background-color: gray; +} +.lodging { + background-color: red; +} +.financial { + background-color: blue; +} +.other { + background-color: yellow; +} \ No newline at end of file diff --git a/client/index.html b/client/index.html index 687cba4..1471519 100644 --- a/client/index.html +++ b/client/index.html @@ -53,12 +53,15 @@ + + + From f0ce6b5455179c6a3c054872427c5b12a1af496f Mon Sep 17 00:00:00 2001 From: Pablo Manuel Araya Date: Tue, 10 Nov 2015 15:42:52 -0300 Subject: [PATCH 2/8] Assignment1 app done. Pending Test --- client/demo/todo-list/style.css | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 client/demo/todo-list/style.css diff --git a/client/demo/todo-list/style.css b/client/demo/todo-list/style.css deleted file mode 100644 index 5daced8..0000000 --- a/client/demo/todo-list/style.css +++ /dev/null @@ -1,15 +0,0 @@ -.transp { - background-color: green; -} -.food { - background-color: gray; -} -.lodging { - background-color: red; -} -.financial { - background-color: blue; -} -.other { - background-color: yellow; -} \ No newline at end of file From 78af8dadaae47c4edc66f6045c3de3be8f8139df Mon Sep 17 00:00:00 2001 From: Pablo Manuel Araya Date: Tue, 10 Nov 2015 16:20:43 -0300 Subject: [PATCH 3/8] Refact method --- client/demo/expenses/expenses-controller.js | 57 ++++++++------------- client/demo/expenses/index.html | 2 +- client/demo/expenses/style.css | 17 +++--- 3 files changed, 29 insertions(+), 47 deletions(-) diff --git a/client/demo/expenses/expenses-controller.js b/client/demo/expenses/expenses-controller.js index 540fe81..0e194d6 100644 --- a/client/demo/expenses/expenses-controller.js +++ b/client/demo/expenses/expenses-controller.js @@ -28,18 +28,9 @@ /* Adds an item to the todo list */ function add(descTxt,dateTxt,typeDdl,amountTxt) { - vm.list.push({desc:descTxt,date:dateTxt, typeExpense:typeDdl, amount:amountTxt}); - - var searchTerm = typeDdl; - - var index = -1; - - for(var i = 0, len = vm.listTotal.length; i < len; i++) { - if (vm.listTotal[i].type === searchTerm) { - index = i; - break; - } - } + vm.list.push({desc:descTxt,date:dateTxt, typeExpense:typeDdl, amount:amountTxt}); + + var index = getExpenseTypeIndex(typeDdl); if(index == -1){ vm.listTotal.push({type:typeDdl, total:amountTxt}); @@ -49,40 +40,32 @@ } } - + /* Remove and item to the expenses list */ function remove(indexList) { var amountTxt = vm.list[indexList].amount; var typeExpenseTxt = vm.list[indexList].typeExpense; - var indexTotal = -1; - - for(var i = 0, len = vm.listTotal.length; i < len; i++) { - if (vm.listTotal[i].type === typeExpenseTxt) { - indexTotal = i; - break; - } - } - + var indexTotal = getExpenseTypeIndex(typeExpenseTxt); + vm.list.splice(indexList,1); - vm.listTotal[indexTotal].total = parseInt(vm.listTotal[indexTotal].total) - parseInt(amountTxt); - - /* - var countAmountBytype = 0; - + vm.listTotal[indexTotal].total = parseInt(vm.listTotal[indexTotal].total) - parseInt(amountTxt); + } + + /* Get the index fro total list */ + function getExpenseTypeIndex(searchTerm) + { + var index = -1; + for(var i = 0, len = vm.listTotal.length; i < len; i++) { - if (vm.listTotal[i].type === typeExpenseTxt) { - countAmountBytype++; + if (vm.listTotal[i].type === searchTerm) { + index = i; + break; } - } - - if(countAmountBytype = 1){ - vm.listTotal.splice(vm.list.indexOf(typeExpenseTxt), 1) } - else{ - vm.listTotal[index].total = parseInt(vm.listTotal[index].total) - parseInt(amountTxt); - }*/ - } + + return index; + } } })(); diff --git a/client/demo/expenses/index.html b/client/demo/expenses/index.html index 7e96f1a..c32aa2e 100644 --- a/client/demo/expenses/index.html +++ b/client/demo/expenses/index.html @@ -55,7 +55,7 @@

Expenses #{{expVM.list.length}}

transp: item.typeExpense == 'transportation', lodging: item.typeExpense == 'lodging', other: item.typeExpense == 'other', - finantial: item.typeExpense == 'finantial'}"> + financial: item.typeExpense == 'financial'}"> {{ item.desc }} {{ item.date | date:'shortDate' }} {{ item.typeExpense }} diff --git a/client/demo/expenses/style.css b/client/demo/expenses/style.css index 674a5d5..5daced8 100644 --- a/client/demo/expenses/style.css +++ b/client/demo/expenses/style.css @@ -1,16 +1,15 @@ +.transp { + background-color: green; +} .food { background-color: gray; } -.other { +.lodging { background-color: red; } -.finantial { - background-color: yellow; -} -.lodging { +.financial { background-color: blue; } -.transp { - background-color: green; -} - +.other { + background-color: yellow; +} \ No newline at end of file From 35f0905830ec6977300072609bd14f9451dc4ca6 Mon Sep 17 00:00:00 2001 From: Pablo Manuel Araya Date: Tue, 10 Nov 2015 16:23:46 -0300 Subject: [PATCH 4/8] Change function name --- client/demo/expenses/expenses-controller.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/demo/expenses/expenses-controller.js b/client/demo/expenses/expenses-controller.js index 0e194d6..88b5ebe 100644 --- a/client/demo/expenses/expenses-controller.js +++ b/client/demo/expenses/expenses-controller.js @@ -30,7 +30,7 @@ vm.list.push({desc:descTxt,date:dateTxt, typeExpense:typeDdl, amount:amountTxt}); - var index = getExpenseTypeIndex(typeDdl); + var index = getIndexFromTotalListByType(typeDdl); if(index == -1){ vm.listTotal.push({type:typeDdl, total:amountTxt}); @@ -46,15 +46,15 @@ var amountTxt = vm.list[indexList].amount; var typeExpenseTxt = vm.list[indexList].typeExpense; - var indexTotal = getExpenseTypeIndex(typeExpenseTxt); + var indexTotal = getIndexFromTotalListByType(typeExpenseTxt); vm.list.splice(indexList,1); vm.listTotal[indexTotal].total = parseInt(vm.listTotal[indexTotal].total) - parseInt(amountTxt); } - /* Get the index fro total list */ - function getExpenseTypeIndex(searchTerm) + /* Get the index from total list */ + function getIndexFromTotalListByType(searchTerm) { var index = -1; From 7c305ee4f6363d71ef8ab6b5a059256b366e783c Mon Sep 17 00:00:00 2001 From: Pablo Manuel Araya Date: Wed, 11 Nov 2015 18:07:28 -0300 Subject: [PATCH 5/8] Style improvements --- client/demo/expenses/expenses-controller.js | 34 +++++- client/demo/expenses/index.html | 113 ++++++++++++-------- 2 files changed, 100 insertions(+), 47 deletions(-) diff --git a/client/demo/expenses/expenses-controller.js b/client/demo/expenses/expenses-controller.js index 88b5ebe..9d25221 100644 --- a/client/demo/expenses/expenses-controller.js +++ b/client/demo/expenses/expenses-controller.js @@ -16,14 +16,14 @@ var vm = this; // Initialization - vm.list = []; - vm.listTotal = []; - - vm.itemText = ''; + vm.types = ["food","transportation","lodging","financial","other"]; + vm.list = []; + vm.listTotal = []; // Controller methods vm.add = add; vm.remove = remove; + vm.edit = edit; /* Adds an item to the todo list */ function add(descTxt,dateTxt,typeDdl,amountTxt) { @@ -38,6 +38,8 @@ else{ vm.listTotal[index].total = parseInt(vm.listTotal[index].total) + parseInt(amountTxt); } + + cleanForm(); } /* Remove and item to the expenses list */ @@ -52,7 +54,29 @@ vm.listTotal[indexTotal].total = parseInt(vm.listTotal[indexTotal].total) - parseInt(amountTxt); } + + /* Edit a item from expenses list */ + function edit(indexList) { + + var amountTxt = vm.list[indexList].amount; + var typeExpenseTxt = vm.list[indexList].typeExpense; + + var indexTotal = getIndexFromTotalListByType(typeExpenseTxt); + + vm.list.splice(indexList,1); + + vm.listTotal[indexTotal].total = parseInt(vm.listTotal[indexTotal].total) - parseInt(amountTxt); + } + /* Clean form test */ + function cleanForm() + { + + vm.descTxt = ''; + vm.amountTxt = ''; + vm.dateTxt = ''; + } + /* Get the index from total list */ function getIndexFromTotalListByType(searchTerm) { @@ -67,5 +91,7 @@ return index; } + + } })(); diff --git a/client/demo/expenses/index.html b/client/demo/expenses/index.html index c32aa2e..11df6b9 100644 --- a/client/demo/expenses/index.html +++ b/client/demo/expenses/index.html @@ -17,62 +17,89 @@
-
-

Expenses #{{expVM.list.length}}

-
-
- -
+

Add Expense:

+
+ + + + + + + + + + + + + +
+ Desc + + Date + + Amount + + Type + +
- - -
+
- - -
+
- - -
+
+ + + +
+
+
+

Items (#{{expVM.list.length}}):

+ + - {{ item.desc }} - {{ item.date | date:'shortDate' }} - {{ item.typeExpense }} - {{ item.amount | currency }} - - - -
-
-

Totals:

-
-

+ financial: item.typeExpense == 'financial'}"> +

+ + + + + +
+ {{ item.desc }} + + {{ item.date | date:'shortDate' }} + + {{ item.typeExpense }} + + {{ item.amount | currency }} + + + +
+
+
+

Totals:

+ + + + +
{{item.type}} : {{item.total}} - - - - +
+
\ No newline at end of file From cda08543c757bc6e059291fc4d3d47e36be1f2d9 Mon Sep 17 00:00:00 2001 From: Pablo Manuel Araya Date: Thu, 12 Nov 2015 09:41:43 -0300 Subject: [PATCH 6/8] Code clean --- client/demo/expenses/index.html | 7 ------- 1 file changed, 7 deletions(-) diff --git a/client/demo/expenses/index.html b/client/demo/expenses/index.html index 11df6b9..028327c 100644 --- a/client/demo/expenses/index.html +++ b/client/demo/expenses/index.html @@ -48,13 +48,6 @@

Add Expense:

- Date: Thu, 12 Nov 2015 19:13:41 -0300 Subject: [PATCH 7/8] Edit items in line --- client/demo/expenses/expenses-controller.js | 88 ++++++++++++--------- client/demo/expenses/index.html | 13 ++- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/client/demo/expenses/expenses-controller.js b/client/demo/expenses/expenses-controller.js index 9d25221..db6b9a9 100644 --- a/client/demo/expenses/expenses-controller.js +++ b/client/demo/expenses/expenses-controller.js @@ -15,68 +15,81 @@ // Controller as viewModel var vm = this; - // Initialization - vm.types = ["food","transportation","lodging","financial","other"]; + // Initialization + vm.types = ["food","transportation","lodging","financial","other"]; vm.list = []; vm.listTotal = []; + vm.oldAmount = 0; // Controller methods vm.add = add; vm.remove = remove; vm.edit = edit; + vm.cancel = cancel; /* Adds an item to the todo list */ - function add(descTxt,dateTxt,typeDdl,amountTxt) { - - vm.list.push({desc:descTxt,date:dateTxt, typeExpense:typeDdl, amount:amountTxt}); - - var index = getIndexFromTotalListByType(typeDdl); - - if(index == -1){ - vm.listTotal.push({type:typeDdl, total:amountTxt}); - } - else{ - vm.listTotal[index].total = parseInt(vm.listTotal[index].total) + parseInt(amountTxt); - } - + function add(descTxt,dateTxt,typeDdl,amountTxt) { + vm.list.push({desc:descTxt,date:dateTxt, typeExpense:typeDdl, amount:amountTxt, editing:false}); + calculateTotals(); cleanForm(); } /* Remove and item to the expenses list */ - function remove(indexList) { - - var amountTxt = vm.list[indexList].amount; - var typeExpenseTxt = vm.list[indexList].typeExpense; - - var indexTotal = getIndexFromTotalListByType(typeExpenseTxt); - - vm.list.splice(indexList,1); - - vm.listTotal[indexTotal].total = parseInt(vm.listTotal[indexTotal].total) - parseInt(amountTxt); + function remove(indexList) { + vm.list.splice(indexList,1); + calculateTotals(); } /* Edit a item from expenses list */ - function edit(indexList) { + function edit(indexList) { - var amountTxt = vm.list[indexList].amount; - var typeExpenseTxt = vm.list[indexList].typeExpense; + vm.oldAmount = vm.list[indexList].amount; - var indexTotal = getIndexFromTotalListByType(typeExpenseTxt); - - vm.list.splice(indexList,1); + var isEditing = vm.list[indexList].editing; - vm.listTotal[indexTotal].total = parseInt(vm.listTotal[indexTotal].total) - parseInt(amountTxt); + if(isEditing){ + vm.list[indexList].editing = false; + calculateTotals(); + + }else{ + vm.list[indexList].editing = true; + } + } + + function cancel(indexList) { + vm.list[indexList].editing = false; + vm.list[indexList].amount = vm.oldAmount; + calculateTotals(); } /* Clean form test */ function cleanForm() - { - + { vm.descTxt = ''; vm.amountTxt = ''; vm.dateTxt = ''; } + + function calculateTotals() + { + vm.listTotal.splice(0,vm.listTotal.length); + + for(var i = 0, len = vm.list.length; i < len; i++){ + + var type = vm.list[i].typeExpense; + + var indextTotal = getIndexFromTotalListByType(type) + + if(indextTotal == -1){ + vm.listTotal.push({type:vm.list[i].typeExpense, total:vm.list[i].amount}); + } + else{ + vm.listTotal[indextTotal].total = parseInt(vm.listTotal[indextTotal].total) + parseInt(vm.list[i].amount); + } + } + } + /* Get the index from total list */ function getIndexFromTotalListByType(searchTerm) { @@ -87,11 +100,8 @@ index = i; break; } - } - + } return index; - } - - + } } })(); diff --git a/client/demo/expenses/index.html b/client/demo/expenses/index.html index 028327c..b6676dc 100644 --- a/client/demo/expenses/index.html +++ b/client/demo/expenses/index.html @@ -74,11 +74,18 @@

Items (#{{expVM.list.length}}):

{{ item.typeExpense }} - {{ item.amount | currency }} + {{ item.amount | currency }} + - - +
+ + +
+
+ + +
From f8c72e7130c7622040424e030222f3c545863319 Mon Sep 17 00:00:00 2001 From: pablomaraya Date: Wed, 9 Dec 2015 17:01:05 -0300 Subject: [PATCH 8/8] Assignment 3. Caching feature DONE --- .../moviesConnector.factory.js | 49 +++++++++++++++++-- .../pages/search/search-page.controller.js | 3 +- client/demo/expenses/expenses-controller.js | 36 ++++++++------ client/demo/expenses/index.html | 12 +++-- 4 files changed, 76 insertions(+), 24 deletions(-) diff --git a/client/app/components/movies-connector/moviesConnector.factory.js b/client/app/components/movies-connector/moviesConnector.factory.js index 0d2186b..d0d8586 100644 --- a/client/app/components/movies-connector/moviesConnector.factory.js +++ b/client/app/components/movies-connector/moviesConnector.factory.js @@ -16,6 +16,9 @@ $q, $http ) { + + var cachedMovies = []; + var service = { cachedConfiguration: null, topRatedMovies: topRatedMovies, @@ -27,16 +30,54 @@ return $http.get('/api/movies/'); } - function search(query) { - return $http.get('/api/movies/search/' + query); + function search(query) { + + var index = queryIsCached(query); + + if(index == -1){ + var httpPromise = $http.get('/api/movies/search/' + query); + httpPromise + .then(function (response) { + addResponseToCache(query,response); + }); + + return httpPromise; + } + else{ + return $q.when(cachedMovies[index].value); + } } + + function addResponseToCache(query, response){ + + if(cachedMovies.length > 100){ + cachedMovies.splice(0,cachedMovies.length); + } + + cachedMovies.push({key:query, value: response}); + } + + function queryIsCached(query) + { + var index = -1; + + for(var i = 0, len = cachedMovies.length; i < len; i++){ + + if( cachedMovies[i].key == query){ + index = i; + break; + } + } + + return index; + } function configuration() { if (service.cachedConfiguration) { return $q.when(service.cachedConfiguration); } - return $http.get('/api/movies/configuration').then(function(response) { - service.cachedConfiguration = response; + return $http.get('/api/movies/configuration').then(function sucessCallback(response) { + service.cachedConfiguration = response; return response; }); } diff --git a/client/app/pages/search/search-page.controller.js b/client/app/pages/search/search-page.controller.js index a54aa54..13ca8a0 100644 --- a/client/app/pages/search/search-page.controller.js +++ b/client/app/pages/search/search-page.controller.js @@ -25,7 +25,8 @@ function updatedSearch(query) { - moviesConnector.search(query).then(function (response) { + var searchPromise = moviesConnector.search(query); + searchPromise.then(function (response) { vm.movies = response.data.results; angular.forEach(vm.movies, function (each) { if (vm.topMovieNames.indexOf(each) === -1){ diff --git a/client/demo/expenses/expenses-controller.js b/client/demo/expenses/expenses-controller.js index db6b9a9..5bec622 100644 --- a/client/demo/expenses/expenses-controller.js +++ b/client/demo/expenses/expenses-controller.js @@ -19,12 +19,15 @@ vm.types = ["food","transportation","lodging","financial","other"]; vm.list = []; vm.listTotal = []; - vm.oldAmount = 0; + + vm.currentAmount = 0; + // Controller methods vm.add = add; vm.remove = remove; vm.edit = edit; + vm.save = save; vm.cancel = cancel; /* Adds an item to the todo list */ @@ -40,28 +43,33 @@ calculateTotals(); } + /* Save changes when we edit a item*/ + function save(indexList){ + vm.list[indexList].editing = false; + calculateTotals(); + } + + /* Edit a item from expenses list */ function edit(indexList) { + vm.currentAmount = vm.list[indexList].amount; - vm.oldAmount = vm.list[indexList].amount; - - var isEditing = vm.list[indexList].editing; - - if(isEditing){ - vm.list[indexList].editing = false; - calculateTotals(); - - }else{ - vm.list[indexList].editing = true; - } + disableAllEditingItem(); + vm.list[indexList].editing = true; } function cancel(indexList) { vm.list[indexList].editing = false; - vm.list[indexList].amount = vm.oldAmount; + vm.list[indexList].amount = vm.currentAmount; calculateTotals(); } - + + function disableAllEditingItem(){ + for(var i = 0, len = vm.list.length; i < len; i++){ + vm.list[i].editing = false; + } + } + /* Clean form test */ function cleanForm() { diff --git a/client/demo/expenses/index.html b/client/demo/expenses/index.html index b6676dc..edd7987 100644 --- a/client/demo/expenses/index.html +++ b/client/demo/expenses/index.html @@ -1,12 +1,14 @@ - + + - + - + + @@ -83,7 +85,7 @@

Items (#{{expVM.list.length}}):

- +
@@ -95,7 +97,7 @@

Totals:

- {{item.type}} : {{item.total}} + {{item.type}} : {{item.total | currency}}