From fd75577042f71049976243cf0e6a976c52b6efda Mon Sep 17 00:00:00 2001 From: Daniel Prado Date: Tue, 1 Dec 2015 13:32:33 -0200 Subject: [PATCH 1/4] cash machine --- .gitignore | 2 + testes/cash-machine/app/controllers/main.js | 52 ++++++++++++++++++ testes/cash-machine/app/module.js | 6 +++ testes/cash-machine/css/custom.css | 21 ++++++++ testes/cash-machine/index.html | 59 +++++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 .gitignore create mode 100644 testes/cash-machine/app/controllers/main.js create mode 100644 testes/cash-machine/app/module.js create mode 100644 testes/cash-machine/css/custom.css create mode 100644 testes/cash-machine/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..1e501e3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bower_components +node_modules \ No newline at end of file diff --git a/testes/cash-machine/app/controllers/main.js b/testes/cash-machine/app/controllers/main.js new file mode 100644 index 00000000..ef76debc --- /dev/null +++ b/testes/cash-machine/app/controllers/main.js @@ -0,0 +1,52 @@ +(function(angular, $) { + "use strict"; + + angular.module("cashMachineApp") + .controller("mainController", ["$scope", function($scope) { + var notes = [100, 50, 20, 10]; + var minimunNote = notes[notes.length - 1]; + + console.log(notes, minimunNote); + + $scope.submit = function(e) { + e.preventDefault(); + $scope.errorMessage = ""; + $scope.result = []; + + var value = $scope.value; + + if (!$.isNumeric(value)) { + $scope.errorMessage = "Not a number"; + return; + } + + if (value < minimunNote) { + $scope.errorMessage = "Must be greater than " + minimunNote; + return; + } + + if (value % minimunNote != 0) { + $scope.errorMessage = "Unavailable Note"; + return; + } + + notes.forEach(function(note) { + var rest = Math.floor(value / note); + + if (rest == 0) { + return; + } + + for (var x = 0; x < rest; x++) { + $scope.result.push(note); + } + + value -= note * rest; + }); + }; + + }]); + + + +})(angular, jQuery); \ No newline at end of file diff --git a/testes/cash-machine/app/module.js b/testes/cash-machine/app/module.js new file mode 100644 index 00000000..d63e2b43 --- /dev/null +++ b/testes/cash-machine/app/module.js @@ -0,0 +1,6 @@ +(function(angular){ + "use strict"; + + angular.module("cashMachineApp", []); + +})(angular); diff --git a/testes/cash-machine/css/custom.css b/testes/cash-machine/css/custom.css new file mode 100644 index 00000000..d3cf672e --- /dev/null +++ b/testes/cash-machine/css/custom.css @@ -0,0 +1,21 @@ +h1{ + text-align: center; +} + +.notes{ + text-align: center; +} + +.notes > div { + display: inline-block; + font-size: 20px; + padding: 20px; + color: green; +} +.notes > div i { + font-size: 30px; + margin-bottom: 5px; +} +.notes > div p { + margin: 0; +} diff --git a/testes/cash-machine/index.html b/testes/cash-machine/index.html new file mode 100644 index 00000000..dc9d50d9 --- /dev/null +++ b/testes/cash-machine/index.html @@ -0,0 +1,59 @@ + + + + Cash Machine + + + + + + + + + + +
+ +

Cash Machine

+ + +
+ +
+
+ +
+ + +
+
{{errorMessage}}
+ + +
+ +
+ +
+
+ + +
+ +
+
+ +

{{note | currency}}

+
+
+ +
+ + + + + + + + + + \ No newline at end of file From 48b73d9cde12bead046a783d36fdae40ed8ccdf8 Mon Sep 17 00:00:00 2001 From: Daniel Prado Date: Tue, 1 Dec 2015 13:34:04 -0200 Subject: [PATCH 2/4] remove console --- testes/cash-machine/app/controllers/main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/testes/cash-machine/app/controllers/main.js b/testes/cash-machine/app/controllers/main.js index ef76debc..a318870a 100644 --- a/testes/cash-machine/app/controllers/main.js +++ b/testes/cash-machine/app/controllers/main.js @@ -6,8 +6,6 @@ var notes = [100, 50, 20, 10]; var minimunNote = notes[notes.length - 1]; - console.log(notes, minimunNote); - $scope.submit = function(e) { e.preventDefault(); $scope.errorMessage = ""; From e4111815aaf5f013b1d481bd85819ddefa756cab Mon Sep 17 00:00:00 2001 From: Daniel Prado Date: Tue, 1 Dec 2015 13:41:49 -0200 Subject: [PATCH 3/4] resolve angular ngRepeat bug --- testes/cash-machine/app/controllers/main.js | 8 +++++++- testes/cash-machine/app/module.js | 8 ++++---- testes/cash-machine/css/custom.css | 6 ++++++ testes/cash-machine/index.html | 9 +++++---- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/testes/cash-machine/app/controllers/main.js b/testes/cash-machine/app/controllers/main.js index a318870a..fcfbc3d4 100644 --- a/testes/cash-machine/app/controllers/main.js +++ b/testes/cash-machine/app/controllers/main.js @@ -13,6 +13,10 @@ var value = $scope.value; + if (!value) { + return; + } + if (!$.isNumeric(value)) { $scope.errorMessage = "Not a number"; return; @@ -36,7 +40,9 @@ } for (var x = 0; x < rest; x++) { - $scope.result.push(note); + $scope.result.push({ + value: note + }); } value -= note * rest; diff --git a/testes/cash-machine/app/module.js b/testes/cash-machine/app/module.js index d63e2b43..d37648c4 100644 --- a/testes/cash-machine/app/module.js +++ b/testes/cash-machine/app/module.js @@ -1,6 +1,6 @@ -(function(angular){ - "use strict"; +(function(angular) { + "use strict"; - angular.module("cashMachineApp", []); + angular.module("cashMachineApp", ['angular.filter']); -})(angular); +})(angular); \ No newline at end of file diff --git a/testes/cash-machine/css/custom.css b/testes/cash-machine/css/custom.css index d3cf672e..1360ad27 100644 --- a/testes/cash-machine/css/custom.css +++ b/testes/cash-machine/css/custom.css @@ -15,7 +15,13 @@ h1{ .notes > div i { font-size: 30px; margin-bottom: 5px; + margin-left: 5px; } + +.notes > div i:last-child { + margin-left: 0; +} + .notes > div p { margin: 0; } diff --git a/testes/cash-machine/index.html b/testes/cash-machine/index.html index dc9d50d9..441b0b8f 100644 --- a/testes/cash-machine/index.html +++ b/testes/cash-machine/index.html @@ -24,7 +24,7 @@

Cash Machine

- +
{{errorMessage}}
@@ -40,9 +40,9 @@

Cash Machine

-
- -

{{note | currency}}

+
+ +

{{note.length}} x {{note[0].value | currency}}

@@ -51,6 +51,7 @@

Cash Machine

+ From 103de52aa4ceccd2f46dae389327107e46e2ce7f Mon Sep 17 00:00:00 2001 From: Daniel Prado Date: Tue, 1 Dec 2015 14:07:23 -0200 Subject: [PATCH 4/4] word rank --- testes/word-rank/app/controllers/main.js | 43 +++++++++++++++++++++++ testes/word-rank/app/module.js | 6 ++++ testes/word-rank/css/custom.css | 27 +++++++++++++++ testes/word-rank/index.html | 44 ++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 testes/word-rank/app/controllers/main.js create mode 100644 testes/word-rank/app/module.js create mode 100644 testes/word-rank/css/custom.css create mode 100644 testes/word-rank/index.html diff --git a/testes/word-rank/app/controllers/main.js b/testes/word-rank/app/controllers/main.js new file mode 100644 index 00000000..953f0733 --- /dev/null +++ b/testes/word-rank/app/controllers/main.js @@ -0,0 +1,43 @@ +(function(angular, $) { + "use strict"; + + angular.module("wordRankApp") + .controller("mainController", ["$scope", "$http", "$filter", function($scope, $http, $filter) { + var resolve = function(fullText) { + var parts = fullText.match(/([A-z]+)/g); + var wordsCount = countWords(parts); + + var result = $filter("orderBy")(wordsCount, ['-qty', 'word']); + $scope.words = result.splice(0, 20); + } + + var countWords = function(parts) { + var words = {}; + + parts.forEach(function(word) { + if (words[word]) { + words[word].qty++; + return; + } + + words[word] = { + word: word, + qty: 1 + }; + }); + + return $.map(words, function(word) { + return word; + }); + } + + $http.get("/texto.txt").then(function(response) { + resolve(response.data); + }); + + + }]); + + + +})(angular, jQuery); \ No newline at end of file diff --git a/testes/word-rank/app/module.js b/testes/word-rank/app/module.js new file mode 100644 index 00000000..84686236 --- /dev/null +++ b/testes/word-rank/app/module.js @@ -0,0 +1,6 @@ +(function(angular) { + "use strict"; + + angular.module("wordRankApp", ['angular.filter']); + +})(angular); \ No newline at end of file diff --git a/testes/word-rank/css/custom.css b/testes/word-rank/css/custom.css new file mode 100644 index 00000000..1360ad27 --- /dev/null +++ b/testes/word-rank/css/custom.css @@ -0,0 +1,27 @@ +h1{ + text-align: center; +} + +.notes{ + text-align: center; +} + +.notes > div { + display: inline-block; + font-size: 20px; + padding: 20px; + color: green; +} +.notes > div i { + font-size: 30px; + margin-bottom: 5px; + margin-left: 5px; +} + +.notes > div i:last-child { + margin-left: 0; +} + +.notes > div p { + margin: 0; +} diff --git a/testes/word-rank/index.html b/testes/word-rank/index.html new file mode 100644 index 00000000..e9a0c98b --- /dev/null +++ b/testes/word-rank/index.html @@ -0,0 +1,44 @@ + + + + Word Rank + + + + + + + + + + +
+ +

Word Rank

+ + + + + + + + + + + + +
WordQty
{{word.word}}{{word.qty}}
+ + +
+ + + + + + + + + + + \ No newline at end of file