Skip to content

Commit 4b05621

Browse files
author
Jhonny Cohen
committed
Inital Commit
0 parents  commit 4b05621

11 files changed

+568
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
.idea/
3+
bower_components/
4+

bower.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "boilerplate_angular_client",
3+
"version": "0.1.0",
4+
"description": "Angular JS client for the Laravel API Boilerplate example project.",
5+
"authors": [
6+
"Francesco Malatesta"
7+
],
8+
"license": "MIT",
9+
"ignore": [
10+
"**/.*",
11+
"node_modules",
12+
"bower_components",
13+
"test",
14+
"tests"
15+
],
16+
"dependencies": {
17+
"angular-route": "~1.4.6",
18+
"angular-local-storage": "~0.2.2",
19+
"angular": "~1.4.6",
20+
"bootstrap": "~3.3.5",
21+
"restangular": "~1.5.1"
22+
}
23+
}

favicon.ico

Whitespace-only changes.

index.html

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html lang="en" ng-app="bookWishlistApp">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
8+
<title>Book Wishlist Application</title>
9+
10+
<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
11+
12+
<script src="bower_components/angular/angular.min.js"></script>
13+
<script src="bower_components/lodash/dist/lodash.min.js"></script>
14+
<script src="bower_components/angular-route/angular-route.min.js"></script>
15+
<script src="bower_components/angular-local-storage/dist/angular-local-storage.min.js"></script>
16+
<script src="bower_components/restangular/dist/restangular.min.js"></script>
17+
18+
<script src="js/app.js"></script>
19+
<script src="js/controllers.js"></script>
20+
<script src="js/services.js"></script>
21+
22+
<style>
23+
24+
li {
25+
padding-bottom: 8px;
26+
}
27+
28+
</style>
29+
</head>
30+
31+
<body>
32+
<div class="container">
33+
<div class="row">
34+
<div class="col-md-12">
35+
<h1>Book Wishlist Application</h1>
36+
</div>
37+
</div>
38+
39+
<div ng-view></div>
40+
</div>
41+
42+
<script src="bower_components/jquery/dist/jquery.min.js"></script>
43+
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
44+
</body>
45+
</html>

js/app.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var bookWishlistApp = angular.module('bookWishlistApp', [
2+
'ngRoute',
3+
'bookWishlistAppControllers'
4+
]);
5+
6+
bookWishlistApp.config(function (localStorageServiceProvider) {
7+
localStorageServiceProvider
8+
.setPrefix('bookWishlistApp')
9+
.setStorageType('localStorage');
10+
});
11+
12+
bookWishlistApp.constant('urls', {
13+
// BASE: 'http://devtestco.nfcs.co.il/'
14+
// BASE: 'http://localhost:8000/'
15+
BASE: 'http://admin.dev/'
16+
17+
18+
});
19+
20+
bookWishlistApp.config(['$routeProvider', function($routeProvider) {
21+
22+
$routeProvider.
23+
when('/login', {
24+
templateUrl: 'partials/login.html',
25+
controller: 'LoginController'
26+
}).
27+
when('/signup', {
28+
templateUrl: 'partials/signup.html',
29+
controller: 'SignupController'
30+
}).
31+
when('/', {
32+
templateUrl: 'partials/index.html',
33+
controller: 'MainController'
34+
}).
35+
otherwise({
36+
redirectTo: '/'
37+
});
38+
39+
}]);
40+
41+
bookWishlistApp.config(function(RestangularProvider) {
42+
// RestangularProvider.setBaseUrl('http://devtestco.nfcs.co.il/');
43+
// RestangularProvider.setBaseUrl('http://localhost:8000/');
44+
RestangularProvider.setBaseUrl('http://admin.dev/');
45+
46+
// RestangularProvider.setResponseExtractor(function(response, operation) {
47+
// return response.data;
48+
// });
49+
50+
});

js/controllers.js

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
var bookWishlistAppControllers = angular.module('bookWishlistAppControllers', [
2+
'bookWishlistAppServices'
3+
]);
4+
5+
bookWishlistAppControllers.controller('LoginController', ['$scope', '$location', 'userService', function ($scope, $location, userService) {
6+
7+
$scope.login = function() {
8+
userService.login(
9+
$scope.email, $scope.password,
10+
function(response){
11+
$location.path('/');
12+
},
13+
function(response){
14+
alert('Something went wrong with the login process. Try again later!');
15+
}
16+
);
17+
}
18+
19+
$scope.email = '';
20+
$scope.password = '';
21+
22+
if(userService.checkIfLoggedIn())
23+
$location.path('/');
24+
25+
}]);
26+
27+
bookWishlistAppControllers.controller('SignupController', ['$scope', '$location', 'userService', function ($scope, $location, userService) {
28+
29+
$scope.signup = function() {
30+
userService.signup(
31+
$scope.name, $scope.email, $scope.password,
32+
function(response){
33+
alert('Great! You are now signed in! Welcome, ' + $scope.name + '!');
34+
$location.path('/');
35+
},
36+
function(response){
37+
alert('Something went wrong with the signup process. Try again later.');
38+
}
39+
);
40+
}
41+
42+
$scope.name = '';
43+
$scope.email = '';
44+
$scope.password = '';
45+
46+
if(userService.checkIfLoggedIn())
47+
$location.path('/');
48+
49+
}]);
50+
51+
bookWishlistAppControllers.controller('MainController', ['$scope', '$location', 'userService', 'bookService', function ($scope, $location, userService, bookService) {
52+
53+
$scope.logout = function(){
54+
userService.logout();
55+
$location.path('/login');
56+
}
57+
58+
$scope.create = function(){
59+
60+
bookService.create({
61+
title: $scope.currentBookTitle,
62+
author_name: $scope.currentBookAuthorName,
63+
pages_count: $scope.currentBookPagesCount
64+
}, function(){
65+
66+
$('#addBookModal').modal('toggle');
67+
$scope.currentBookReset();
68+
$scope.refresh();
69+
70+
}, function(){
71+
72+
alert('Some errors occurred while communicating with the service. Try again later.');
73+
74+
});
75+
76+
}
77+
78+
$scope.refresh = function(){
79+
80+
bookService.getAll(function(response){
81+
82+
$scope.books = response;
83+
console.log($scope.books);
84+
85+
86+
}, function(){
87+
88+
alert('Some errors occurred while communicating with the service. Try again later.');
89+
90+
});
91+
92+
}
93+
94+
$scope.load = function(bookId){
95+
96+
bookService.getById(bookId, function(response){
97+
98+
$scope.currentBookId = response.book.id;
99+
$scope.currentBookTitle = response.book.title;
100+
$scope.currentBookAuthorName = response.book.author_name;
101+
$scope.currentBookPagesCount = response.book.pages_count;
102+
103+
$('#updateBookModal').modal('toggle');
104+
105+
}, function(){
106+
107+
alert('Some errors occurred while communicating with the service. Try again later.');
108+
109+
});
110+
111+
}
112+
113+
$scope.update = function(){
114+
115+
bookService.update(
116+
$scope.currentBookId,
117+
{
118+
title: $scope.currentBookTitle,
119+
author_name: $scope.currentBookAuthorName,
120+
pages_count: $scope.currentBookPagesCount
121+
},
122+
function(response){
123+
124+
$('#updateBookModal').modal('toggle');
125+
$scope.currentBookReset();
126+
$scope.refresh();
127+
128+
}, function(response){
129+
alert('Some errors occurred while communicating with the service. Try again later.');
130+
}
131+
);
132+
133+
}
134+
135+
$scope.remove = function(bookId){
136+
137+
if(confirm('Are you sure to remove this book from your wishlist?')){
138+
bookService.remove(bookId, function(){
139+
140+
alert('Book removed successfully.');
141+
142+
}, function(){
143+
144+
alert('Some errors occurred while communicating with the service. Try again later.');
145+
146+
});
147+
}
148+
149+
}
150+
151+
$scope.currentBookReset = function(){
152+
$scope.currentBookTitle = '';
153+
$scope.currentBookAuthorName = '';
154+
$scope.currentBookPagesCount = '';
155+
$scope.currentBookId = '';
156+
}
157+
158+
if(!userService.checkIfLoggedIn())
159+
$location.path('/login');
160+
161+
$scope.books = [];
162+
163+
$scope.currentBookReset();
164+
$scope.refresh();
165+
166+
}]);

0 commit comments

Comments
 (0)