Skip to content

Commit

Permalink
Merge pull request #9 from OZ-United/canary
Browse files Browse the repository at this point in the history
0.1.0-rc.1
  • Loading branch information
janantala committed Oct 6, 2013
2 parents d6a3e20 + c3133bd commit c2de3da
Show file tree
Hide file tree
Showing 33 changed files with 549 additions and 195 deletions.
Binary file added admin/app/images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added admin/app/images/logoSmall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 24 additions & 15 deletions admin/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<title>United knižnica</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

<!-- build:css({.tmp,app}) styles/main.css -->
Expand All @@ -28,19 +28,27 @@
<![endif]-->

<!-- Add your site or application content here -->
<header>
<nav>
<a href="#/books/">Knihy</a>
<a href="#/users/">Používatelia</a>
<a href="#/rents/">Požičania</a>
</nav>
<div>
<form name="searchBook" ng-submit="search(query)">
<input type="text" class="input-field" ng-model="query">
<button type="submit" class="btn" ng-click="search(query)">Search</button>
</form>
</div>
</header>
<nav class="nav">
<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>

<form name="searchBook" ng-submit="search(query)" class="nav-search">
<div class="input-append">
<input type="search" class="input-field input-search" ng-model="query">
<button type="submit" class="btn" ng-click="search(query)"><i class="icon-search"></i></button>
</div>
</form>

<h4 ng-show="user.name" ng-click="signout()">
<i class="icon-signout"></i>
<a href="#"><span ng-bind="user.name"></span></a>
</h4>

<a href="http://www.spolocenstvounited.sk" class="nav-logo"></a>

</nav>

<div class="container" ng-view=""></div>

<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
Expand Down Expand Up @@ -97,6 +105,7 @@
<script src="scripts/directives/infiniteScroll.js"></script>
<script src="scripts/controllers/search.js"></script>
<script src="scripts/services/Search.js"></script>
<script src="scripts/services/Auth.js"></script>
<!-- endbuild -->
</body>
</html>
140 changes: 132 additions & 8 deletions admin/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,117 @@ angular.module('adminApp', ['ngResource', 'ja.isbn', 'ui.bootstrap'])
})
.when('/users', {
templateUrl: 'views/users.html',
controller: 'UsersCtrl'
controller: 'UsersCtrl',
resolve: {
users: function($q, $route, Users, Auth){
var deferred = $q.defer();
if (!Auth.isLoggedIn()) { return deferred.reject(); }

Users.query($route.current.params,
function(users){
console.log(users);
deferred.resolve(users);
},
function(){
deferred.reject();
}
);

return deferred.promise;
}
}
})
.when('/books', {
templateUrl: 'views/books.html',
controller: 'BooksCtrl'
controller: 'BooksCtrl',
resolve: {
books: function($q, $route, Books, Auth){
var deferred = $q.defer();
if (!Auth.isLoggedIn()) { return deferred.reject(); }
Books.query($route.current.params,
function(books){
console.log(books);
deferred.resolve(books);
},
function(){
deferred.reject();
}
);

return deferred.promise;
}
}
})
.when('/rents', {
templateUrl: 'views/rents.html',
controller: 'RentsCtrl'
controller: 'RentsCtrl',
resolve: {
rents: function($q, $route, Rents, Auth){
var deferred = $q.defer();
if (!Auth.isLoggedIn()) { return deferred.reject(); }
Rents.query($route.current.params,
function(rents){
console.log(rents);
deferred.resolve(rents);
},
function(){
deferred.reject();
}
);

return deferred.promise;
}
}
})
.when('/books/:bookId', {
templateUrl: 'views/books/bookId.html',
controller: 'BooksBookidCtrl'
controller: 'BooksBookidCtrl',
resolve: {
book: function($q, $route, Books, Auth){
var deferred = $q.defer();
if (!Auth.isLoggedIn()) { return deferred.reject(); }
Books.get({'bookId': $route.current.params.bookId},
function(book){
console.log(book);
deferred.resolve(book);
},
function(){
deferred.reject();
}
);

return deferred.promise;
}
}
})
.when('/users/:userId', {
templateUrl: 'views/users/userId.html',
controller: 'UsersUseridCtrl'
controller: 'UsersUseridCtrl',
resolve: {
user: function($q, $route, Users, Auth){
var deferred = $q.defer();
if (!Auth.isLoggedIn()) { return deferred.reject(); }
Users.get({'userId': $route.current.params.userId},
function(user){
console.log(user);
deferred.resolve(user);
},
function(){
deferred.reject();
}
);

return deferred.promise;
}
}
})
.when('/rents/:rentId', {
templateUrl: 'views/rents/rentId.html',
controller: 'RentsRentidCtrl',
resolve: {
rent: function($q, $route, Rents){
rent: function($q, $route, Rents, Auth){
var deferred = $q.defer();
if (!Auth.isLoggedIn()) { return deferred.reject(); }
Rents.get({'rentId': $route.current.params.rentId},
function(rent){
console.log(rent);
Expand All @@ -49,13 +136,30 @@ angular.module('adminApp', ['ngResource', 'ja.isbn', 'ui.bootstrap'])
})
.when('/search', {
templateUrl: 'views/search.html',
controller: 'SearchCtrl'
controller: 'SearchCtrl',
resolve: {
books: function($q, $route, Search, Auth){
var deferred = $q.defer();
if (!Auth.isLoggedIn()) { return deferred.reject(); }
Search.query($route.current.params,
function(books){
console.log(books);
deferred.resolve(books);
},
function(){
deferred.reject();
}
);

return deferred.promise;
}
}
})
.otherwise({
redirectTo: '/'
});
})
.run(function($rootScope, $location){
.run(function($rootScope, $location, Auth){
$rootScope.modalOpts = {
backdropFade: true,
dialogFade: true
Expand All @@ -64,4 +168,24 @@ angular.module('adminApp', ['ngResource', 'ja.isbn', 'ui.bootstrap'])
$rootScope.search = function(query) {
$location.url('search?q=' + query);
};

$rootScope.signout = function() {
Auth.logout();
$location.path( '/' );
};

$rootScope.$on('$routeChangeStart', function(event, next, current) {
console.log(next.templateUrl);
console.log(Auth.isLoggedIn());
if ( !Auth.isLoggedIn() ) {
if ( next.templateUrl !== 'views/main.html' ) {
$location.path( '/' );
}
}
else {
if ( next.templateUrl === 'views/main.html' ) {
$location.path( '/books' );
}
}
});
});
7 changes: 3 additions & 4 deletions admin/app/scripts/controllers/books.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

angular.module('adminApp')
.controller('BooksCtrl', function ($scope, Books, $routeParams) {
.controller('BooksCtrl', function ($scope, Books, $routeParams, books) {

$scope.book = {};
$scope.books = [];
$scope.books = books;

$scope.addBook = function(){
if ($scope.addBookForm.$valid) {
Expand Down Expand Up @@ -51,7 +51,6 @@ angular.module('adminApp')
});
};

$scope.page = 0;
$scope.page = 1;
$scope.mayQuery = true;
$scope.query();
});
4 changes: 2 additions & 2 deletions admin/app/scripts/controllers/books/bookId.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('adminApp')
.controller('BooksBookidCtrl', function ($scope, Books, Users, Rents, $routeParams, $location) {
$scope.book = Books.get({'bookId': $routeParams.bookId});
.controller('BooksBookidCtrl', function ($scope, Users, Rents, $routeParams, $location, book) {
$scope.book = book;

$scope.openRent = function (bookCopy) {
$scope.rentBook = true;
Expand Down
15 changes: 8 additions & 7 deletions admin/app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

angular.module('adminApp')
.controller('MainCtrl', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
});
.controller('MainCtrl', function ($scope, Auth, $location) {
$scope.auth = function(user) {
Auth.login(user).then(function(user){
console.log(user);
$location.path('/books');
});
};
});
7 changes: 3 additions & 4 deletions admin/app/scripts/controllers/rents.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('adminApp')
.controller('RentsCtrl', function ($scope, Rents, $location, $routeParams) {
$scope.rents = [];
.controller('RentsCtrl', function ($scope, Rents, $location, $routeParams, rents) {
$scope.rents = rents;

$scope.returnBook = function(rent){
Rents.returnBook({'rentId': rent.rentId}, function(res){
Expand Down Expand Up @@ -39,7 +39,6 @@ angular.module('adminApp')
});
};

$scope.page = 0;
$scope.page = 1;
$scope.mayQuery = true;
$scope.query();
});
6 changes: 4 additions & 2 deletions admin/app/scripts/controllers/search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

angular.module('adminApp')
.controller('SearchCtrl', function ($scope, $routeParams, Search) {
$scope.books = Search.query($routeParams);
.controller('SearchCtrl', function ($scope, $routeParams, $rootScope, books) {
$scope.books = books;

$rootScope.query = '';
});
7 changes: 3 additions & 4 deletions admin/app/scripts/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('adminApp')
.controller('UsersCtrl', function ($scope, Users, $routeParams) {
$scope.users = [];
.controller('UsersCtrl', function ($scope, Users, $routeParams, users) {
$scope.users = users;

$scope.addUser = function(){
if ($scope.addUserForm.$valid) {
Expand Down Expand Up @@ -43,7 +43,6 @@ angular.module('adminApp')
});
};

$scope.page = 0;
$scope.page = 1;
$scope.mayQuery = true;
$scope.query();
});
6 changes: 2 additions & 4 deletions admin/app/scripts/controllers/users/userId.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';

angular.module('adminApp')
.controller('UsersUseridCtrl', function ($scope, Users, $routeParams, $location) {
$scope.user = Users.get($routeParams, function(){
$scope.user.password = undefined;
});
.controller('UsersUseridCtrl', function ($scope, Users, $routeParams, $location, user) {
$scope.user = user;

$scope.updateUser = function(user){
if ($scope.updateUserForm.$valid) {
Expand Down
36 changes: 36 additions & 0 deletions admin/app/scripts/services/Auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

angular.module('adminApp')
.factory('Auth', function ($q, $http, $rootScope) {
var STORAGE_ID = 'united-library';
$rootScope.user = JSON.parse(localStorage.getItem(STORAGE_ID) || '{}');

return {
login: function (user) {
var deferred = $q.defer();

$http.post((window.host || '') + '/auth', user)
.success(function(res){
$rootScope.user = res;
localStorage.setItem(STORAGE_ID, JSON.stringify(res));
deferred.resolve(res);
})
.error(function(){
deferred.reject();
});

return deferred.promise;
},
getUser: function() {
return $rootScope.user;
},
isLoggedIn: function() {
return ($rootScope.user.hash && $rootScope.user.hash.length) ? true : false;
},
logout: function() {
$rootScope.user = {};
localStorage.setItem(STORAGE_ID, JSON.stringify('{}'));
return true;
}
};
});
Loading

0 comments on commit c2de3da

Please sign in to comment.