Skip to content

Commit

Permalink
Merge pull request #12 from OZ-United/canary
Browse files Browse the repository at this point in the history
0.1.0-rc.4
  • Loading branch information
janantala committed Nov 3, 2013
2 parents 4bd1557 + ba641e0 commit 8e6cb7b
Show file tree
Hide file tree
Showing 32 changed files with 458 additions and 50 deletions.
2 changes: 2 additions & 0 deletions admin/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<a href="#/books/" class="nav-link"><i class="icon-book"></i> Knihy</a>
<a href="#/users/" class="nav-link"><i class="icon-user"></i> Používatelia</a>
<a href="#/rents/" class="nav-link"><i class="icon-time"></i> Požičania</a>
<a href="#/reservations/" class="nav-link"><i class="icon-time"></i> Rezervácie</a>

<form name="searchBook" ng-submit="search(query)" class="nav-search">
<div class="input-append">
Expand Down Expand Up @@ -119,6 +120,7 @@ <h4 ng-hide="user.name">
<script src="scripts/directives/draganddrop.js"></script>
<script src="scripts/directives/infiniteScroll.js"></script>

<script src="scripts/controllers/reservations.js"></script>
<!-- endbuild -->
</body>
</html>
22 changes: 22 additions & 0 deletions admin/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ angular.module('adminApp', ['ngRoute', 'ngResource', 'ja.isbn', 'ui.bootstrap'])
templateUrl: 'views/auth.html',
controller: 'AuthCtrl'
})
.when('/reservations', {
templateUrl: 'views/reservations.html',
controller: 'ReservationsCtrl',
resolve: {
reservations: function($q, $route, Rents, Auth){
var deferred = $q.defer();
var query = {};
angular.extend(query, $route.current.params, {status: 'reserved'});
Rents.query(query,
function(reservations){
console.log(reservations);
deferred.resolve(reservations);
},
function(){
deferred.reject();
}
);

return deferred.promise;
}
}
})
.otherwise({
redirectTo: '/'
});
Expand Down
6 changes: 6 additions & 0 deletions admin/app/scripts/controllers/books/bookId.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ angular.module('adminApp')
'bookId': $scope.book.bookId,
'bookCopyId': bookCopy.bookCopyId
};

$scope.reservations = Rents.query({status: 'reserved', book: $scope.book.bookId});
};

$scope.clearRent = function(rent) {
rent.rentId = undefined;
};

$scope.closeRent = function () {
Expand Down
2 changes: 1 addition & 1 deletion admin/app/scripts/controllers/rents.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ angular.module('adminApp')
};

$scope.getStyle = function(rent){
if (new Date(rent.rent.endDate) < new Date() && !rent.rent.returnDate) {
if (rent.rent && (new Date(rent.rent.endDate) < new Date() && !rent.rent.returnDate)) {
return 'warning';
}
};
Expand Down
31 changes: 31 additions & 0 deletions admin/app/scripts/controllers/reservations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

angular.module('adminApp')
.controller('ReservationsCtrl', function ($scope, Rents, $location, $routeParams, Auth, reservations) {

$scope.reservations = reservations;

$scope.query = function(){
if (!$scope.mayQuery) {
return false;
}

var query = {page: $scope.page + 1};
query = angular.extend(query, $routeParams, {status: 'reserved'});
console.log(query);
Rents.query(query,
function(reservations){
if (!reservations.length) {
$scope.mayQuery = false;
}
$scope.reservations = $scope.reservations.concat(reservations);
$scope.page += 1;
},
function(error){

});
};

$scope.page = 1;
$scope.mayQuery = true;
});
21 changes: 18 additions & 3 deletions admin/app/views/books/bookId.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,30 @@ <h3>Požičať knihu</h3>
<form class="form-horizontal" ng-submit="save()" name="addBookForm">

<div class="control-group">
<label class="control-label" for="inputUserId">UserId</label>
<label class="control-label" for="inputUserId">UserId:</label>
<div class="controls">
<input type="text" ng-model="rentCopy.userId" id="inputUserId" class="input-field" required placeholder="UserId" typeahead="rentUser.userId as rentUser.name for rentUser in rentUsers | filter:$viewValue | limitTo:8">
<input type="text"
ng-model="rentCopy.userId" id="inputUserId" class="input-field" required placeholder="UserId"
ng-change="clearRent(rentCopy)"
typeahead="rentUser.userId as rentUser.name for rentUser in rentUsers | filter:$viewValue | limitTo:8"

>
<!-- <input type="text" ng-model="rentCopy.userId" id="inputUserId" class="input-field" required placeholder="UserId" typeahead="rentUser.userId as rentUser.name for rentUser in rentUsers | filter:$viewValue | limitTo:8"> -->
</div>
</div>

<div class="control-group" ng-show="reservations.length">
<label class="control-label">Rezervácie:</label>
<div class="controls">
<p ng-repeat="reservation in reservations"
ng-click="rentCopy.userId = reservation.user.userId; rentCopy.rentId = reservation.rentId;"
>
{{reservation.user.name}}</p>
</div>
</div>

<div class="control-group">
<label class="control-label" for="inputEndDate">Do kedy</label>
<label class="control-label" for="inputEndDate">Do kedy:</label>
<div class="controls">
<div ng-model="rentCopy.endDate" >
<datepicker min="minDate" show-weeks="false" starting-day="1" id="inputEndDate" ng-required="true"></datepicker>
Expand Down
29 changes: 29 additions & 0 deletions admin/app/views/reservations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<section>
<h4 class="content-header">Zoznam rezervácií</h4>
<table class="table">
<thead>
<tr>
<th>Obal</th>
<th>Názov</th>
<th>Autor</th>
<th>Používateľ</th>
<th>Od</th>
</tr>
</thead>
<tbody>

<tr ng-repeat="rent in reservations" ng-class="getStyle(rent)">
<td>
<a ng-href="#/books/{{rent.book.bookId}}" class="btn btn-link">
<img ng-src="{{rent.book.cover}}" alt="" style="height: 50px; width: auto; line-height: 50px;"></td>
</a>
<td style="line-height: 50px;"><a ng-href="#/books/{{rent.book.bookId}}">{{rent.book.title}}</a></td>
<td style="line-height: 50px;"><a ng-href="#/books?author={{rent.book.author}}">{{rent.book.author}}</a></td>
<td style="line-height: 50px;"><a ng-href="#/users/{{rent.user.userId}}">{{rent.user.name}}</a></td>
<td style="line-height: 50px;"><a ng-href="#/rents/{{rent.rentId}}">{{rent.reservation.reservationDate | date}}</a></td>
</tr>
</tbody>
</table>

<button class="btn btn-block" ng-click="query()" ng-show="mayQuery"><i class="icon-repeat"></i> Ďalšie</button>
</section>
22 changes: 22 additions & 0 deletions admin/test/spec/controllers/reservations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

describe('Controller: ReservationsCtrl', function () {

// load the controller's module
beforeEach(module('adminApp'));

var ReservationsCtrl,
scope;

// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
ReservationsCtrl = $controller('ReservationsCtrl', {
$scope: scope
});
}));

it('should attach a list of awesomeThings to the scope', function () {
expect(scope.awesomeThings.length).toBe(3);
});
});
10 changes: 6 additions & 4 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function(app, auth) {
// users
var users = require('../routes/users');
app.get('/users', users.hasAuthorization, users.isAdmin, users.query);
app.post('/users', users.hasAuthorization, users.isAdmin, users.create, emails.registerUser);
app.post('/users', users.create, emails.registerUser);
app.get('/users/me', users.hasAuthorization, users.me);
app.get('/users/:userId', users.hasAuthorization, users.isAdmin, users.get);
app.put('/users/:userId', users.hasAuthorization, users.isAdmin, users.update);
Expand All @@ -50,10 +50,12 @@ module.exports = function(app, auth) {

// rents
var rents = require('../routes/rents');
app.get('/rents', users.hasAuthorization, users.isAdmin, rents.query);
app.get('/rents/:rentId', users.hasAuthorization, users.isAdmin, rents.get);
app.get('/rents', users.hasAuthorization, users.isMe, rents.query);
app.get('/rents/:rentId', users.hasAuthorization, users.isMe, rents.get);
app.post('/rents', users.hasAuthorization, users.isAdmin, rents.create, emails.rentBook);
app.put('/rents/:rentId/', users.hasAuthorization, users.isAdmin, rents.update);
app.post('/rents/reserveBook', users.hasAuthorization,rents.reserveBook, emails.reserveBook);
app.post('/rents/:rentId', users.hasAuthorization, users.isAdmin, rents.create, emails.rentBook);
app.put('/rents/:rentId', users.hasAuthorization, users.isAdmin, rents.update);
app.del('/rents/:rentId', users.hasAuthorization, users.isAdmin, rents.remove);
app.post('/rents/:rentId/returnBook', users.hasAuthorization, users.isAdmin, rents.returnBook, emails.returnBook);

Expand Down
3 changes: 3 additions & 0 deletions dashboard/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<a href="#/books/" class="nav-link"><i class="icon-book"></i> Knihy</a>
<a href="#/profile/" class="nav-link" ng-show="user.name"><i class="icon-user"></i> Môj účet</a>
<a href="#/rents/" class="nav-link" ng-show="user.name"><i class="icon-time"></i> Požičania</a>
<a href="#/reservations/" class="nav-link" ng-show="user.name"><i class="icon-time"></i> Rezervácie</a>

<form name="searchBook" ng-submit="search(query)" class="nav-search">
<div class="input-append">
Expand Down Expand Up @@ -112,6 +113,8 @@ <h4 ng-hide="user.name">
<script src="scripts/services/Users.js"></script>
<script src="scripts/controllers/books/bookId.js"></script>
<script src="scripts/controllers/rents/rentId.js"></script>
<script src="scripts/controllers/register.js"></script>
<script src="scripts/controllers/reservations.js"></script>
<!-- endbuild -->
</body>
</html>
51 changes: 39 additions & 12 deletions dashboard/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ angular.module('dashboardApp', ['ngRoute', 'ngResource'])
resolve: {
user: function($q, $route, Users, Auth){
var deferred = $q.defer();
Users.get({'userId': Auth.getUser().userId},
Users.me({'userId': 'me'},
function(user){
console.log(user);
deferred.resolve(user);
Expand All @@ -33,7 +33,9 @@ angular.module('dashboardApp', ['ngRoute', 'ngResource'])
resolve: {
rents: function($q, $route, Rents, Auth){
var deferred = $q.defer();
Rents.query({user: Auth.getUser().userId},
var query = {};
angular.extend(query, $route.current.params, {user: Auth.getUser().userId});
Rents.query(query,
function(rents){
console.log(rents);
deferred.resolve(rents);
Expand Down Expand Up @@ -131,6 +133,32 @@ angular.module('dashboardApp', ['ngRoute', 'ngResource'])
}
}
})
.when('/register', {
templateUrl: 'views/register.html',
controller: 'RegisterCtrl'
})
.when('/reservations', {
templateUrl: 'views/reservations.html',
controller: 'ReservationsCtrl',
resolve: {
reservations: function($q, $route, Rents, Auth){
var deferred = $q.defer();
var query = {};
angular.extend(query, $route.current.params, {user: Auth.getUser().userId, status: 'reserved'});
Rents.query(query,
function(reservations){
console.log(reservations);
deferred.resolve(reservations);
},
function(){
deferred.reject();
}
);

return deferred.promise;
}
}
})
.otherwise({
redirectTo: '/'
});
Expand All @@ -153,15 +181,14 @@ angular.module('dashboardApp', ['ngRoute', 'ngResource'])
$rootScope.$on('$routeChangeStart', function(event, next, current) {
console.log(next.templateUrl);
console.log(Auth.isLoggedIn());
// if ( !Auth.isLoggedIn() ) {
// if ( next.templateUrl !== 'views/auth.html' ) {
// $location.path( '/auth' );
// }
// }
// else {
// if ( next.templateUrl === 'views/auth.html' ) {
// $location.path( '/' );
// }
// }
if ( Auth.isLoggedIn() ) {
if ( next.templateUrl === 'views/auth.html' ) {
$location.path( '/' );
}

if ( next.templateUrl === 'views/register.html' ) {
$location.path( '/' );
}
}
});
});
3 changes: 2 additions & 1 deletion dashboard/app/scripts/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

angular.module('dashboardApp')
.controller('AuthCtrl', function ($scope, Auth, $location) {

$scope.auth = function(user) {
Auth.login(user).then(function(user){
console.log(user);
$location.path('/');
},
function(){
$scope.error = true;
$scope.error = 'Nepodarilo sa prihlásiť';
});
};
});
14 changes: 13 additions & 1 deletion dashboard/app/scripts/controllers/books/bookId.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('dashboardApp')
.controller('BooksBookidCtrl', function ($scope, Rents, $routeParams, $location, book) {
.controller('BooksBookidCtrl', function ($scope, Rents, $routeParams, $location, book, Auth) {
$scope.book = book;

$scope.returnBook = function(bookCopy) {
Expand All @@ -11,4 +11,16 @@ angular.module('dashboardApp')
});
};

$scope.reserveBook = function() {
console.log($routeParams);
console.log(Auth.getUser());
var payload = {
'bookId': $routeParams.bookId,
'userId': Auth.getUser().userId
};
Rents.reserveBook(payload, function(){
$location.path('/rents');
});
};

});
15 changes: 15 additions & 0 deletions dashboard/app/scripts/controllers/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

angular.module('dashboardApp')
.controller('RegisterCtrl', function ($scope, Auth, $location) {

$scope.auth = function(user) {
Auth.register(user).then(function(user){
console.log(user);
$location.path('/');
},
function(){
$scope.error = 'Nepodarilo sa zaregistrovať';
});
};
});
6 changes: 3 additions & 3 deletions dashboard/app/scripts/controllers/rents.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('dashboardApp')
.controller('RentsCtrl', function ($scope, Rents, $location, $routeParams, rents) {
.controller('RentsCtrl', function ($scope, Rents, $location, $routeParams, Auth, rents) {
$scope.rents = rents;

$scope.returnBook = function(rent){
Expand All @@ -13,7 +13,7 @@ angular.module('dashboardApp')
};

$scope.getStyle = function(rent){
if (new Date(rent.rent.endDate) < new Date() && !rent.rent.returnDate) {
if (rent.rent && (new Date(rent.rent.endDate) < new Date() && !rent.rent.returnDate)) {
return 'warning';
}
};
Expand All @@ -24,7 +24,7 @@ angular.module('dashboardApp')
}

var query = {page: $scope.page + 1};
query = angular.extend(query, $routeParams);
query = angular.extend(query, $routeParams, {user: Auth.getUser().userId});
console.log(query);
Rents.query(query,
function(rents){
Expand Down
Loading

0 comments on commit 8e6cb7b

Please sign in to comment.