Skip to content

Commit 883a7a7

Browse files
committed
Angular js support for Book CRUD
- I18n as well for the model
1 parent 8b1898c commit 883a7a7

File tree

12 files changed

+440
-0
lines changed

12 files changed

+440
-0
lines changed

src/main/webapp/i18n/en/book.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"bookstoreApp": {
3+
"book" : {
4+
"home": {
5+
"title": "Books",
6+
"createLabel": "Create a new Book",
7+
"createOrEditLabel": "Create or edit a Book"
8+
},
9+
"delete": {
10+
"question": "Are you sure you want to delete Book {{ id }}?"
11+
},
12+
"detail": {
13+
"title": "Book"
14+
},
15+
"title": "Title",
16+
"description": "Description",
17+
"publicationDate": "PublicationDate",
18+
"price": "Price",
19+
"author": "author"
20+
}
21+
}
22+
}

src/main/webapp/i18n/en/global.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"entities": {
88
"main": "Entities",
99
"author": "Author",
10+
"book": "Book",
1011
"additionalEntity": "JHipster will add additional entities here (do not translate!)"
1112
},
1213
"account": {

src/main/webapp/i18n/fr/book.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"bookstoreApp": {
3+
"book" : {
4+
"home": {
5+
"title": "Books",
6+
"createLabel": "Créer un nouveau Book",
7+
"createOrEditLabel": "Créer ou éditer un Book"
8+
},
9+
"delete": {
10+
"question": "Etes-vous certain de vouloir supprimer le Book {{ id }} ?"
11+
},
12+
"detail": {
13+
"title": "Book"
14+
},
15+
"title": "Title",
16+
"description": "Description",
17+
"publicationDate": "PublicationDate",
18+
"price": "Price",
19+
"author": "author"
20+
}
21+
}
22+
}
23+

src/main/webapp/i18n/fr/global.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"entities": {
88
"main": "Entités",
99
"author": "Author",
10+
"book": "Book",
1011
"additionalEntity": "JHipster will add additional entities here (do not translate!)"
1112
},
1213
"account": {

src/main/webapp/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
<script src="scripts/app/entities/author/author.controller.js"></script>
128128
<script src="scripts/app/entities/author/author-detail.controller.js"></script>
129129
<script src="scripts/components/entities/author/author.service.js"></script>
130+
<script src="scripts/app/entities/book/book.js"></script>
131+
<script src="scripts/app/entities/book/book.controller.js"></script>
132+
<script src="scripts/app/entities/book/book-detail.controller.js"></script>
133+
<script src="scripts/components/entities/book/book.service.js"></script>
130134
<!-- endbuild -->
131135
</body>
132136
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
angular.module('bookstoreApp')
4+
.controller('BookDetailController', function ($scope, $stateParams, Book, Author) {
5+
$scope.book = {};
6+
$scope.load = function (id) {
7+
Book.get({id: id}, function(result) {
8+
$scope.book = result;
9+
});
10+
};
11+
$scope.load($stateParams.id);
12+
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
<div>
3+
<h2><span translate="bookstoreApp.book.detail.title">Book</span> {{book.id}}</h2>
4+
<div class="table-responsive">
5+
<table class="table table-striped">
6+
<thead>
7+
<tr>
8+
<th translate="entity.detail.field">Field</th>
9+
<th translate="entity.detail.value">Value</th>
10+
</tr>
11+
</thead>
12+
<tbody>
13+
<tr>
14+
<td>
15+
<span translate="bookstoreApp.book.title">Title</span>
16+
</td>
17+
<td>
18+
<input type="text" class="input-sm form-control" value="{{book.title}}" readonly>
19+
</td>
20+
</tr>
21+
<tr>
22+
<td>
23+
<span translate="bookstoreApp.book.description">Description</span>
24+
</td>
25+
<td>
26+
<input type="text" class="input-sm form-control" value="{{book.description}}" readonly>
27+
</td>
28+
</tr>
29+
<tr>
30+
<td>
31+
<span translate="bookstoreApp.book.publicationDate">PublicationDate</span>
32+
</td>
33+
<td>
34+
<input type="text" class="input-sm form-control" value="{{book.publicationDate}}" readonly>
35+
</td>
36+
</tr>
37+
<tr>
38+
<td>
39+
<span translate="bookstoreApp.book.price">Price</span>
40+
</td>
41+
<td>
42+
<input type="text" class="input-sm form-control" value="{{book.price}}" readonly>
43+
</td>
44+
</tr>
45+
<tr>
46+
<td>
47+
<span translate="bookstoreApp.book.author">author</span>
48+
</td>
49+
<td>
50+
<input type="text" class="input-sm form-control" value="{{book.author.name}}" readonly>
51+
</td>
52+
</tr>
53+
</tbody>
54+
</table>
55+
</div>
56+
57+
<button type="submit"
58+
ui-sref="book"
59+
class="btn btn-info">
60+
<span class="glyphicon glyphicon-arrow-left"></span>&nbsp;<span translate="entity.action.back"> Back</span>
61+
</button>
62+
</div>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
3+
angular.module('bookstoreApp')
4+
.controller('BookController', function ($scope, Book, Author, ParseLinks) {
5+
$scope.books = [];
6+
$scope.authors = Author.query();
7+
$scope.page = 1;
8+
$scope.loadAll = function() {
9+
Book.query({page: $scope.page, per_page: 20}, function(result, headers) {
10+
$scope.links = ParseLinks.parse(headers('link'));
11+
$scope.books = result;
12+
});
13+
};
14+
$scope.loadPage = function(page) {
15+
$scope.page = page;
16+
$scope.loadAll();
17+
};
18+
$scope.loadAll();
19+
20+
$scope.showUpdate = function (id) {
21+
Book.get({id: id}, function(result) {
22+
$scope.book = result;
23+
$('#saveBookModal').modal('show');
24+
});
25+
};
26+
27+
$scope.save = function () {
28+
if ($scope.book.id != null) {
29+
Book.update($scope.book,
30+
function () {
31+
$scope.refresh();
32+
});
33+
} else {
34+
Book.save($scope.book,
35+
function () {
36+
$scope.refresh();
37+
});
38+
}
39+
};
40+
41+
$scope.delete = function (id) {
42+
Book.get({id: id}, function(result) {
43+
$scope.book = result;
44+
$('#deleteBookConfirmation').modal('show');
45+
});
46+
};
47+
48+
$scope.confirmDelete = function (id) {
49+
Book.delete({id: id},
50+
function () {
51+
$scope.loadAll();
52+
$('#deleteBookConfirmation').modal('hide');
53+
$scope.clear();
54+
});
55+
};
56+
57+
$scope.refresh = function () {
58+
$scope.loadAll();
59+
$('#saveBookModal').modal('hide');
60+
$scope.clear();
61+
};
62+
63+
$scope.clear = function () {
64+
$scope.book = {title: null, description: null, publicationDate: null, price: null, id: null};
65+
$scope.editForm.$setPristine();
66+
$scope.editForm.$setUntouched();
67+
};
68+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
angular.module('bookstoreApp')
4+
.config(function ($stateProvider) {
5+
$stateProvider
6+
.state('book', {
7+
parent: 'entity',
8+
url: '/book',
9+
data: {
10+
roles: ['ROLE_USER'],
11+
pageTitle: 'bookstoreApp.book.home.title'
12+
},
13+
views: {
14+
'content@': {
15+
templateUrl: 'scripts/app/entities/book/books.html',
16+
controller: 'BookController'
17+
}
18+
},
19+
resolve: {
20+
translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
21+
$translatePartialLoader.addPart('book');
22+
return $translate.refresh();
23+
}]
24+
}
25+
})
26+
.state('bookDetail', {
27+
parent: 'entity',
28+
url: '/book/:id',
29+
data: {
30+
roles: ['ROLE_USER'],
31+
pageTitle: 'bookstoreApp.book.detail.title'
32+
},
33+
views: {
34+
'content@': {
35+
templateUrl: 'scripts/app/entities/book/book-detail.html',
36+
controller: 'BookDetailController'
37+
}
38+
},
39+
resolve: {
40+
translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
41+
$translatePartialLoader.addPart('book');
42+
return $translate.refresh();
43+
}]
44+
}
45+
});
46+
});

0 commit comments

Comments
 (0)