diff --git a/client/app/components/movies-connector/moviesConnector.factory.js b/client/app/components/movies-connector/moviesConnector.factory.js index 5cd3886..f5daafb 100644 --- a/client/app/components/movies-connector/moviesConnector.factory.js +++ b/client/app/components/movies-connector/moviesConnector.factory.js @@ -21,7 +21,8 @@ topRatedMovies: topRatedMovies, configuration: configuration, search: search, - movieInfo: movieInfo + movieInfo: movieInfo, + reviewAdd: reviewAdd }; function topRatedMovies() { @@ -44,6 +45,10 @@ }); } + function reviewAdd(data){ + return $http.post('/api/movies/review/', data) + } + return service; } diff --git a/client/app/pages/movie/movie-page.controller.js b/client/app/pages/movie/movie-page.controller.js index d37511e..e05bf9d 100644 --- a/client/app/pages/movie/movie-page.controller.js +++ b/client/app/pages/movie/movie-page.controller.js @@ -11,10 +11,46 @@ ]; /* @ngInject */ - function MoviePageController(movie, topMovies, moviesConnector){ + function MoviePageController(movie, moviesConnector){ var vm = this; vm.movie = movie; + vm.user = {}; + vm.review = {}; + vm.msg = null; + + vm.addReview = function(isValid){ + + vm.submitted = true; + + if (isValid) { + + var data = {}; + data.user = vm.user; + data.movieId = vm.movie.id; + data.rating = vm.review.rate; + data.comment = vm.review.comment; + + console.debug(data); + + moviesConnector.reviewAdd(data) + .then(function () { + vm.msg = 'Your review has been saved successfully'; + console.debug('success'); + }) + .catch(function (response) { + vm.msg = 'There was an error submiting your review'; + console.debug('error'); + }); + } + }; + + vm.back = function(){ + vm.msg = null; + vm.user = {}; + vm.review = {}; + vm.review = {}; + }; } })(); diff --git a/client/app/pages/movie/movie-page.html b/client/app/pages/movie/movie-page.html index c8642da..aaf718b 100644 --- a/client/app/pages/movie/movie-page.html +++ b/client/app/pages/movie/movie-page.html @@ -14,6 +14,7 @@

{{movieVm.movie.title}}

+ diff --git a/client/app/pages/movie/movie-page.review.html b/client/app/pages/movie/movie-page.review.html new file mode 100644 index 0000000..7c7f7d9 --- /dev/null +++ b/client/app/pages/movie/movie-page.review.html @@ -0,0 +1,35 @@ +

Review

+
+
{{ movieVm.msg }}
+
+ +
+
+
+
+
+
+ +

You name is required.

+
+
+ +

You lastname is required.

+
+
+ +

Enter a valid email.

+
+
+ +

You comment is required.

+
+
+ + +

You rate is required.

+
+ +
+
+
\ No newline at end of file diff --git a/client/app/pages/movie/movie-page.review.route.js b/client/app/pages/movie/movie-page.review.route.js new file mode 100644 index 0000000..a8a004b --- /dev/null +++ b/client/app/pages/movie/movie-page.review.route.js @@ -0,0 +1,20 @@ +(function () { + 'use strict'; + + angular + .module('moviesApp') + .config(configRouteMovieReview); + + configRouteMovieReview.$inject = [ + '$stateProvider' + ]; + + function configRouteMovieReview($stateProvider) { + + $stateProvider + .state('movie-page.review', { + url: '/review', + templateUrl: 'app/pages/movie/movie-page.review.html' + }); + } +})(); diff --git a/client/demo/ex/assignment1/index.html b/client/demo/ex/assignment1/index.html new file mode 100644 index 0000000..ed960e4 --- /dev/null +++ b/client/demo/ex/assignment1/index.html @@ -0,0 +1,117 @@ + + + + + + + + Expense App Assignment1 + + +
+

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}}

+
+
+
+
+ + 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 new file mode 100644 index 0000000..954b27e --- /dev/null +++ b/client/demo/ex/assignment2/app.js @@ -0,0 +1,2 @@ +angular + .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..b474c08 --- /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(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/expensesController.spec.js b/client/demo/ex/assignment2/expensesController.spec.js new file mode 100644 index 0000000..539eaf8 --- /dev/null +++ b/client/demo/ex/assignment2/expensesController.spec.js @@ -0,0 +1,44 @@ +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(0); + }); + + 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); + }); + +}); diff --git a/client/demo/ex/assignment2/index.html b/client/demo/ex/assignment2/index.html new file mode 100644 index 0000000..7a49fc6 --- /dev/null +++ b/client/demo/ex/assignment2/index.html @@ -0,0 +1,112 @@ + + + + + + + + + + + + + Expense App Assignment2 + + +
+

Expenses

+
+
+

Create Expense

+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + +
DateTypeDescriptionAmount
{{ expen.date | date: 'MM/dd/yy'}}{{ expen.type }}{{ expen.description }}{{ expen.amount }} + + +
+
+
+
+
+ Totals by Type +
+
+
+ + + + + + + + + + + +
TypeTotal
{{ type }}{{ exp.getTotalByType(type) }}
+
+
+
+
+
+
+
+ Total All Types +
+
+
+

Total: {{ exp.getTotal() }}

+
+
+
+
+
+
+ + diff --git a/client/index.html b/client/index.html index 2f82e12..a64f1e1 100644 --- a/client/index.html +++ b/client/index.html @@ -88,6 +88,7 @@ + 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); + }); + +});