Skip to content

Commit 71ec4fc

Browse files
AleksSPbphp-coder
authored andcommitted
Limit number of images that can be added to the series.
Fix #108
1 parent a07d56b commit 71ec4fc

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/main/java/ru/mystamps/web/controller/SeriesController.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ public String showInfo(
198198
: collectionService.isSeriesInCollection(currentUser.getId(), series.getId())
199199
);
200200

201+
model.addAttribute(
202+
"allowAddingImages",
203+
isAllowedToAddingImages(series)
204+
);
205+
206+
model.addAttribute("maxQuantityOfImagesExceeded", false);
207+
201208
return "series/info";
202209
}
203210

@@ -227,7 +234,15 @@ public String processImage(
227234
collectionService.isSeriesInCollection(currentUser.getId(), series.getId())
228235
);
229236

230-
if (result.hasErrors()) {
237+
model.addAttribute(
238+
"allowAddingImages",
239+
isAllowedToAddingImages(series)
240+
);
241+
242+
boolean maxQuantityOfImagesExceeded = !isAllowedToAddingImages(series);
243+
model.addAttribute("maxQuantityOfImagesExceeded", maxQuantityOfImagesExceeded);
244+
245+
if (result.hasErrors() || maxQuantityOfImagesExceeded) {
231246
// don't try to re-display file upload field
232247
form.setImage(null);
233248
return "series/info";
@@ -369,6 +384,10 @@ public String findSeriesByGibbons(
369384
return redirectTo(Url.INFO_SERIES_PAGE, seriesId.get());
370385
}
371386

387+
private static boolean isAllowedToAddingImages(Series series) {
388+
return series.getImages().size() <= series.getQuantity();
389+
}
390+
372391
private static String redirectTo(String url, Object... args) {
373392
String dstUrl = UriComponentsBuilder.fromUriString(url)
374393
.buildAndExpand(args)

src/main/resources/ru/mystamps/i18n/Messages.properties

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ t_remove_from_collection = Remove from collection
111111
t_need_authentication_to_add_series_to_collection = \
112112
In order to add this series to your collection you should <a href="{0}">register</a> or <a href="{1}">pass authentication</a>.
113113
t_add_image = Add image
114+
t_add_image_error = This series has enough images. Please, contact with admin if you want to add more images
114115

115116
# category/add.html
116117

src/main/resources/ru/mystamps/i18n/Messages_ru.properties

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ t_remove_from_collection = Убрать из коллекции
111111
t_need_authentication_to_add_series_to_collection = \
112112
Для того, чтобы добавить эту серию в свою коллекцию вы должны <a href="{0}">зарегистрироваться</a> или <a href="{1}">пройти идентификацию</a>.
113113
t_add_image = Добавить изображение
114+
t_add_image_error = Эта серия содержит все необходимые изображения. Пожалуйста, свяжитесь с администратором, если вы хотите добавить больше изображений
114115

115116
# category/add.html
116117

src/main/webapp/WEB-INF/views/series/info.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@
8787
<div class="row" id="content">
8888
<div class="col-sm-12">
8989

90+
<!--/*/
91+
<div class="row" th:if="${maxQuantityOfImagesExceeded}">
92+
<div class="alert alert-danger text-center col-sm-8 col-sm-offset-2" th:text="#{t_add_image_error}">
93+
This series has enough images. Please, contact with admin if you want to add more images
94+
</div>
95+
</div>
96+
/*/-->
97+
9098
<div class="row">
9199

92100
<div class="col-sm-4">
@@ -287,7 +295,7 @@
287295

288296
</div>
289297

290-
<div class="row" togglz:active="ADD_ADDITIONAL_IMAGES_TO_SERIES" sec:authorize="hasAuthority('ADD_IMAGES_TO_SERIES')">
298+
<div class="row" th:if="${allowAddingImages}" togglz:active="ADD_ADDITIONAL_IMAGES_TO_SERIES" sec:authorize="hasAuthority('ADD_IMAGES_TO_SERIES')">
291299
<div class="col-sm-4">
292300
<div class="row">
293301
<div class="col-sm-6 col-sm-offset-3">

0 commit comments

Comments
 (0)