Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Juan.cook/assignment4 #10

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
topRatedMovies: topRatedMovies,
configuration: configuration,
search: search,
movieInfo: movieInfo
movieInfo: movieInfo,
reviewAdd: reviewAdd
};

function topRatedMovies() {
Expand All @@ -44,6 +45,10 @@
});
}

function reviewAdd(data){
return $http.post('/api/movies/review/', data)
}

return service;

}
Expand Down
38 changes: 37 additions & 1 deletion client/app/pages/movie/movie-page.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
};

}
})();
1 change: 1 addition & 0 deletions client/app/pages/movie/movie-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ <h2>{{movieVm.movie.title}}</h2>
<a ui-sref="movie-page.similar"><label class="btn btn-primary" ng-model="radioModel" uib-btn-radio="'Similar'">Similar</label></a>
<a ui-sref="movie-page.debug"><label class="btn btn-primary" ng-model="radioModel" uib-btn-radio="'Middle'">Debug</label></a>
<a ui-sref="movie-page.edit"><label class="btn btn-primary" ng-model="radioModel" uib-btn-radio="'Edit'">Edit</label></a>
<a ui-sref="movie-page.review"><label class="btn btn-primary" ng-model="radioModel" uib-btn-radio="'Review'">Review</label></a>
</div>
<ui-view>
</ui-view>
Expand Down
35 changes: 35 additions & 0 deletions client/app/pages/movie/movie-page.review.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<h2>Review</h2>
<div class="well well-sm alert-info" ng-if="movieVm.msg">
<div>{{ movieVm.msg }}</div>
<div>
<button class="btn btn-default" ng-click="movieVm.back()">Back</button>
</div>
</div>
<div class="row" ng-if="!movieVm.msg">
<div class="col-sm-6 well">
<form name="reviewForm" novalidate>
<div class="form-group" ng-class="{ 'has-error' : reviewForm.name.$invalid && !reviewForm.name.$pristine && movieVm.submitted }">
<input type="text" name="name" class="form-control" ng-model="movieVm.user.name" placeholder="Name" ng-minlength="3" required/>
<p ng-show="reviewForm.name.$invalid && !reviewForm.name.$pristine && movieVm.submitted" class="help-block">You name is required.</p>
</div>
<div class="form-group">
<input type="text" name="lastname" class="form-control" ng-model="movieVm.user.lastname" placeholder="Lastname" ng-minlength="3" required/>
<p ng-show="reviewForm.lastname.$invalid && !reviewForm.lastname.$pristine && movieVm.submitted" class="help-block">You lastname is required.</p>
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" ng-model="movieVm.user.email" placeholder="Email" ng-minlength="3" required/>
<p ng-show="reviewForm.email.$invalid && !reviewForm.email.$pristine && movieVm.submitted" class="help-block">Enter a valid email.</p>
</div>
<div class="form-group">
<textarea name="comment" class="form-control" ng-model="movieVm.review.comment" placeholder="Comment" ng-minlength="10" required></textarea>
<p ng-show="reviewForm.comment.$invalid && !reviewForm.comment.$pristine && movieVm.submitted" class="help-block">You comment is required.</p>
</div>
<div class="form-group">
<label>Rating</label>
<uib-rating name="rate" ng-model="movieVm.review.rate" max="10" required></uib-rating>
<p ng-show="reviewForm.rate.$invalid && !reviewForm.rate.$pristine && movieVm.submitted" class="help-block">You rate is required.</p>
</div>
<button type="submit" class="btn btn-primary pull-right" ng-click="movieVm.addReview(reviewForm.$valid)">Create Review</button>
</form>
</div>
</div>
20 changes: 20 additions & 0 deletions client/app/pages/movie/movie-page.review.route.js
Original file line number Diff line number Diff line change
@@ -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'
});
}
})();
117 changes: 117 additions & 0 deletions client/demo/ex/assignment1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<html ng-app>
<head>
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css">
<title>Expense App Assignment1</title>
</head>
<body>
<div class="container"
ng-init="
expenses = [];
types= ['food', 'transportation', 'lodging', 'financial', 'sales', 'other.'];
isEditing = false;
index = -1;">
<h1>Expenses</h1>
<div class="create_expense">
<!-- <form name="expenseForm" ng-init="expense = {};"> -->
<form ng-init="expense = {};">
<h4>Create Expense</h4>
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="text" hidden ng-model="expense.id" />
<div class="form-group">
<input type="date" class="form-control" placeholder="Date" ng-model="expense.date" />
</div>
<div class="form-group">
<select id="type" name="type" class="form-control" ng-model="expense.type" ng-options="option for option in types track by option">
<option value="">-- Select type --</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Description" ng-model="expense.description" />
</div>
<div class="form-group">
<input type="number" class="form-control" placeholder="Amount" ng-model="expense.amount" />
</div>
<div>
<input type="button" id="create-button" value="Create" class="btn btn-primary"
ng-click="expense.id = (expenses.length)+1;
expenses.push(expense);
expense = {};"
ng-hide="isEditing">
<input type="button" id="update-button" value="Update" class="btn btn-primary"
ng-click="expenses[index] = expense;;
expense = {};
isEditing = false;"
ng-show="isEditing">
<input type="button" id="cancel-button" value="Cancel" class="btn btn-primary"
ng-click="expense = {};
isEditing = false;"
ng-show="isEditing">
</div>
</div>
</div>
</form>
</div>
<div class="display_expenses">
<table class="table">
<thead>
<th>Date</th>
<th>Type</th>
<th>Description</th>
<th>Amount</th>
</thead>
<tbody>
<tr ng-repeat="exp in expenses track by exp.id">
<td>{{ exp.date | date: 'dd/MM/yy'}}</td>
<td>{{ exp.type }}</td>
<td>{{ exp.description }}</td>
<td>{{ exp.amount }}</td>
<td>
<button class="btn btn-default"
ng-click="$parent.expense = exp;
$parent.isEditing = true;
$parent.index = expenses.indexOf(exp);">
<i class="glyphicon glyphicon-pencil"></i>
</button>
<button class="btn btn-default"
ng-click="expenses.splice(expenses.indexOf(exp),1)">
<i class="glyphicon glyphicon-trash"></i>
</button>
</td>
</tr>
</tbody>
</table>
<hr>
<div class="row">
<h3>Totals by Type</h3>
<div class="col-sm-6 col-sm-offset-3">
<table class="table" id="totals_table">
<thead>
<th>Type</th>
<th>Total</th>
</thead>
<tbody>
<tr ng-repeat="type in types">
<td>{{type}}</td>
<td ng-init="total=0;"
ng-repeat="exp in expenses | filter: type">{{ exp.amount + total }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3>Total All Types</h3>
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<p ng-init="total=0;" ng-repeat="exp in expenses">{{ exp.amount + total}}</p>
</div>
</div>
</div>
</div>
</body>
</html>
118 changes: 118 additions & 0 deletions client/demo/ex/assignment1/index2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<html ng-app >
<head>
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css">
<script src="/demo/todo-list-controller/todo-list.controller.js"></script>
</head>
<body ng-init="list=[];
isEditing=false;
index=-1;
itemTypes=['food', 'transportation', 'lodging', 'financial', 'sales', 'other'];">
<div class="container">
<div class="row">
<h2>Todo List #{{list.length}}</h2>
</div>

<div class="row">
<div class="col-md-1 text-right">
Date:
</div>
<div class="col-md-11">
<input id="date" type="text" ng-model="date">
</div>
<div class="col-md-1 text-right">
Type:
</div>
<div class="col-md-11">
<select id="type" ng-model="type">
<option ng-repeat="type in itemTypes" value="{{type}}">{{type}}</option>
</select>
</div>
<div class="col-md-1 text-right">
Description:
</div>
<div class="col-md-11">
<input id="description" type="text" ng-model="description">
</div>
<div class="col-md-1 text-right">
Amount:
</div>
<div class="col-md-11">
<input id="amount" type="number" ng-model="amount">
</div>
<div class="col-md-1 text-right">
</div>
<div class="col-md-11">
<input id="add-button" class="btn btn-default" type="button" value="Add"
ng-click="item={date:date, type: type, description: description, amount: amount};
date=''; type=''; description=''; amount='';
list.push(item);"
ng-hide="isEditing">

<input id="cancel-button" class="btn btn-default" type="button" value="Cancel"
ng-click="addBtnDisplay='inline'; updBtnDisplay='none';
date=''; type=''; description=''; amount='';
isEditing=false;"
ng-show="isEditing">

<input id="update-button" class="btn btn-default" type="button" value="Update"
ng-click="list[index]={date:date, type: type, description: description, amount: amount};
date=''; type=''; description=''; amount='';
isEditing=false;"
ng-show="isEditing">
</div>
</div>
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Type</th>
<th>Description</th>
<th>Amount</th>
<th>Action</th>
</tr>
</thead>
<tbody id="items-list">
<tr ng-repeat="item in list">
<td>{{item.date}}</td>
<td>{{item.type}}</td>
<td>{{item.description}}</td>
<td>{{item.amount}}</td>
<td>
<input class="btn btn-default btn-xs" type="button" value="X" id="delete-{{$index}}"
ng-click="list.splice(list.indexOf(item), 1)">

<input class="btn btn-xs" type="button" value="E" id="edit-{{$index}}"
ng-click="$parent.description=item.description;
$parent.date=item.date;
$parent.type=item.type;
$parent.amount=item.amount;
$parent.index=list.indexOf(item);
$parent.isEditing=true;">
</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Type</th>
<th>Total</th>
</tr>
</thead>
<tbody id="totals-list">
<tr ng-repeat="type in itemTypes">
<td>{{type}}</td>
<td ng-init="total=0;" ng-repeat="item in list | filter: type">{{total + item.amout * 1}}</td>
</tr>
<tbody>
</table>

<div>
</div>
</div>
</body>
</html>
2 changes: 2 additions & 0 deletions client/demo/ex/assignment2/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
angular
.module('expensesApp', []);
Loading