Skip to content

Commit 9f07633

Browse files
committed
improve: a page with collection info now shows the series with images.
Fix #511
1 parent e807a57 commit 9f07633

File tree

7 files changed

+101
-35
lines changed

7 files changed

+101
-35
lines changed

NEWS.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- (feature) admin can add a price in Michel, Scott, Yvert, Gibbons, Solovyov, and Zagorski catalogs
88
- (feature) admin can add numbers in Michel, Scott, Yvert, Gibbons, Solovyov, and Zagorski catalogs
99
- (improvement) on a country info page show the series with an image
10+
- (improvement) on a collection info page show the series with an image
1011
- (feature) add a condition (MNH/MNHOG/MVLH/CTO/cancelled) to a series sale
1112

1213
0.4.3

src/main/java/ru/mystamps/web/feature/collection/RowMappers.java

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ private RowMappers() {
4848
Integer releaseYear = JdbcUtils.getInteger(rs, "release_year");
4949
Integer quantity = rs.getInt("quantity");
5050
Boolean perforated = rs.getBoolean("perforated");
51+
Integer previewId = JdbcUtils.getInteger(rs, "preview_id");
5152
Integer numberOfStamps = rs.getInt("number_of_stamps");
5253

5354
return new SeriesInCollectionDto(
@@ -57,6 +58,7 @@ private RowMappers() {
5758
releaseYear,
5859
perforated,
5960
quantity,
61+
previewId,
6062
numberOfStamps
6163
);
6264
}

src/main/java/ru/mystamps/web/feature/collection/SeriesInCollectionDto.java

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class SeriesInCollectionDto {
2929
private final Integer releaseYear;
3030
private final Boolean perforated;
3131
private final Integer quantity;
32+
private final Integer previewId;
3233
// quantity holds number of stamps in a series, while user may
3334
// have less stamps in his collection
3435
private final Integer numberOfStamps;

src/main/resources/sql/collection_dao_queries.properties

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ collection.find_series_by_collection_id = \
1818
, s.quantity \
1919
, s.perforated \
2020
, cs.number_of_stamps \
21+
, ( \
22+
SELECT si.image_id \
23+
FROM series_images si \
24+
WHERE si.series_id = s.id \
25+
AND si.hidden = FALSE \
26+
ORDER BY si.image_id \
27+
LIMIT 1 \
28+
) AS preview_id \
2129
FROM collections_series cs \
2230
JOIN series s \
2331
ON s.id = cs.series_id \

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

+75-27
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ <h3 class="text-center" th:text="#{t_collection_of(${ownerName})}">
8888
/*/-->
8989

9090
<div class="row">
91-
<div class="col-sm-2 col-md-push-4">
91+
<div class="col-sm-2 col-sm-offset-2">
9292
<div class="panel panel-default" th:if="${not #lists.isEmpty(seriesOfCollection)}">
9393
<div class="panel-heading">
9494
<h4 class="panel-title" th:text="#{t_in_collection}">In this collection</h4>
@@ -110,48 +110,96 @@ <h4 class="panel-title" th:text="#{t_in_collection}">In this collection</h4>
110110
</div>
111111
</div>
112112
</div>
113-
<div class="col-sm-3 col-md-push-4">
113+
<div class="col-sm-3">
114114
<div class="panel panel-default" th:if="${not #lists.isEmpty(seriesOfCollection)}">
115115
<div class="panel-heading">
116116
<h4 class="panel-title" th:text="#{t_stamps_by_countries}">Stamps by countries</h4>
117117
</div>
118118
<div id="countries-chart" class="panel-body no-padding"></div>
119119
</div>
120120
</div>
121-
<div class="col-sm-3 col-md-push-4">
121+
<div class="col-sm-3">
122122
<div class="panel panel-default" th:if="${not #lists.isEmpty(seriesOfCollection)}">
123123
<div class="panel-heading">
124124
<h4 class="panel-title" th:text="#{t_stamps_by_categories}">Stamps by categories</h4>
125125
</div>
126126
<div id="categories-chart" class="panel-body no-padding"></div>
127127
</div>
128128
</div>
129-
<div class="col-sm-4 col-md-pull-8">
130-
<ul th:if="${not #lists.isEmpty(seriesOfCollection)}" th:remove="all-but-first">
131-
<li th:each="series : ${seriesOfCollection}">
129+
</div>
130+
131+
<div class="row" th:if="${not #lists.isEmpty(seriesOfCollection)}">
132+
<div class="col-sm-12">
133+
134+
<div class="image-gallery" th:remove="all-but-first">
135+
136+
<figure th:each="series : ${seriesOfCollection}"
137+
th:with="desc=|${series.category}, ${series.country != null ? series.country + ', ' : ''}${series.releaseYear != null ? series.releaseYear + ', ' : ''}${series.quantity}&nbsp;${series.quantity != 1 ? '__#{t_stamps}__' : '__#{t_stamp}__'}${not series.perforated ? ' (__#{t_wo_perforation_short}__)' : ''}|">
138+
132139
<a href="../series/info.html" th:href="@{${INFO_SERIES_PAGE}(id=${series.id})}">
133-
<span th:remove="tag" th:text="|${series.category}, |">Animals, </span>
134-
<span th:remove="tag" th:if="${series.country != null}" th:text="|${series.country}, |">Italy, </span>
135-
<span th:remove="tag" th:if="${series.releaseYear != null}" th:text="|${series.releaseYear}, |">1999, </span>
136-
<span th:remove="tag" th:text="|${series.quantity}&nbsp;${series.quantity != 1 ? '__#{t_stamps}__' : '__#{t_stamp}__'}|">7&nbsp;stamps</span>
137-
<span th:remove="tag" th:if="${not series.perforated}" th:text="|(#{t_wo_perforation_short})|">(imperf.)</span>
140+
<img src="http://via.placeholder.com/250"
141+
alt="Prehistoric animals, Italy, 1999, 7&nbsp;stamps (imperf.)"
142+
title="Prehistoric animals, Italy, 1999, 7&nbsp;stamps (imperf.)"
143+
th:alt="${desc}"
144+
th:title="${desc}"
145+
th:src="@{${GET_IMAGE_PREVIEW_PAGE}(id=${series.previewId})}" />
146+
</a>
147+
<figcaption>
148+
<a href="../series/info.html" th:href="@{${INFO_SERIES_PAGE}(id=${series.id})}" th:text="${desc}">
149+
Prehistoric animals, Italy, 1999, 7&nbsp;stamps (imperf.)
150+
</a>
151+
<!--/*/
152+
<span class="label label-default"
153+
th:if="${series.quantity != series.numberOfStamps}"
154+
th:text="#{t_m_out_of_n(${series.numberOfStamps}, ${series.quantity})}"></span>
155+
/*/-->
156+
<span th:if="${justAddedSeriesId != null and justAddedSeriesId == series.id and justAddedNumberOfStamps == series.NumberOfStamps}" class="label label-success">New</span>
157+
<!--/* @todo #1123 /collection/{slug}: show "New" badge only once */-->
158+
<!--/* @todo #511 /collection/{slug}: wrap a long caption */-->
159+
</figcaption>
160+
</figure>
161+
<figure>
162+
<a href="../series/info.html">
163+
<img src="http://via.placeholder.com/250" alt="Prehistoric animals, Italy, 22&nbsp;stamps" title="Prehistoric animals, Italy, 22&nbsp;stamps" />
164+
</a>
165+
<figcaption><a href="../series/info.html">Prehistoric animals, Italy, 22&nbsp;stamps</a></figcaption>
166+
</figure>
167+
<figure>
168+
<a href="../series/info.html">
169+
<img src="http://via.placeholder.com/250" alt="Cartoons, Italy, 2005, 5&nbsp;stamps" title="Cartoons, Italy, 2005, 5&nbsp;stamps" />
138170
</a>
139-
<!--/*/
140-
<span class="label label-default"
141-
th:if="${series.quantity != series.numberOfStamps}"
142-
th:text="#{t_m_out_of_n(${series.numberOfStamps}, ${series.quantity})}"></span>
143-
/*/-->
144-
<span th:if="${justAddedSeriesId != null and justAddedSeriesId == series.id and justAddedNumberOfStamps == series.NumberOfStamps}" class="label label-success">New</span>
145-
<!--/* @todo #1123 /collection/{slug}: show "New" badge only once */-->
146-
</li>
147-
<li>
148-
<a href="../series/info.html">Animals, Italy, 22&nbsp;stamps</a>
149-
<span class="label label-default">20 out of 22</span>
150-
</li>
151-
<li>
152-
<a href="../series/info.html">Animals, Italy, 1983, 5&nbsp;stamps</a>
153-
</li>
154-
</ul>
171+
<figcaption><a href="../series/info.html">Cartoons, Italy, 2005, 5&nbsp;stamps</a></figcaption>
172+
</figure>
173+
<figure>
174+
<a href="../series/info.html">
175+
<img src="http://via.placeholder.com/250" alt="Prehistoric animals, Italy, 22&nbsp;stamps" title="Prehistoric animals, Italy, 22&nbsp;stamps" />
176+
</a>
177+
<figcaption>
178+
<a href="../series/info.html">Prehistoric animals, Italy, 22&nbsp;stamps</a>
179+
<span class="label label-default">20 out of 22</span>
180+
</figcaption>
181+
</figure>
182+
<figure>
183+
<a href="../series/info.html">
184+
<img src="http://via.placeholder.com/250" alt="Prehistoric animals, Italy, 1983, 5&nbsp;stamps" title="Prehistoric animals, Italy, 1983, 5&nbsp;stamps" />
185+
</a>
186+
<figcaption><a href="../series/info.html">Prehistoric animals, Italy, 1983, 5&nbsp;stamps</a></figcaption>
187+
</figure>
188+
<figure>
189+
<a href="../series/info.html">
190+
<img src="http://via.placeholder.com/250" alt="Famous People, Italy, 2003, 4&nbsp;stamps" title="Famous People, Italy, 2003, 4&nbsp;stamps" />
191+
</a>
192+
<figcaption><a href="../series/info.html">Famous People, Italy, 2003, 4&nbsp;stamps</a></figcaption>
193+
</figure>
194+
<figure>
195+
<a href="../series/info.html">
196+
<img src="http://via.placeholder.com/250" alt="Sport, Italy, 1996, 1&nbsp;stamp" title="Sport, Italy, 1996, 1&nbsp;stamp" />
197+
</a>
198+
<figcaption><a href="../series/info.html">Sport, Italy, 1996, 1&nbsp;stamp</a></figcaption>
199+
</figure>
200+
201+
</div>
202+
155203
</div>
156204
</div>
157205
</div>

src/test/robotframework/collection/add-series/logic.robot

+12-6
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@ Add a series to user's collection (all stamps)
1212
Element Text Should Be id:series-status-msg You don't have this series. Add one instance:
1313
Element Text Should Be id:number-of-stamps-block I have 2 out of 2 stamps
1414
Submit Form id:add-series-form
15-
Page Should Contain Link css:[href="/series/2"]
15+
Page Should Contain Link css:.image-gallery figcaption [href="/series/2"]
1616
# See https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator
17-
Element Text Should Be css:[href="/series/2"] ~ .label-success New
17+
Element Text Should Be css:.image-gallery figcaption [href="/series/2"] ~ .label-success New
1818

1919
Add the same series to user's collection again (incomplete series)
2020
Go To ${SITE_URL}/series/2
2121
Element Text Should Be id:series-status-msg You already have this series. Add another one instance:
2222
Input Text id:number-of-stamps 1
2323
Submit Form id:add-series-form
24-
Xpath Should Match X Times xpath://a[@href="/series/2"] 2
25-
Xpath Should Match X Times xpath://a[@href="/series/2"]/following-sibling::*[contains(concat(" ", normalize-space(@class), " "), " label-success ")] 1
26-
Element Text Should Be css:[href="/series/2"] ~ .label-success New
24+
# See https://stackoverflow.com/questions/1604471/how-can-i-find-an-element-by-css-class-with-xpath
25+
${linkXpath}= Catenate SEPARATOR=
26+
... //*[contains(concat(" ", normalize-space(@class), " "), " image-gallery ")]
27+
... //figcaption
28+
... //a[@href="/series/2"]
29+
${successLabelElem}= Set Variable *[contains(concat(" ", normalize-space(@class), " "), " label-success ")]
30+
Xpath Should Match X Times xpath:${linkXpath} expectedXpathCount=2
31+
Xpath Should Match X Times xpath:${linkXpath}/following-sibling::${successLabelElem} expectedXpathCount=1
32+
Element Text Should Be css:.image-gallery figcaption [href="/series/2"] ~ .label-success New
2733
# See https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator
28-
Element Text Should Be css:[href="/series/2"] ~ .label-default 1 out of 2
34+
Element Text Should Be css:.image-gallery figcaption [href="/series/2"] ~ .label-default 1 out of 2
2935

3036
*** Keywords ***
3137
Before Test Suite

src/test/robotframework/collection/remove-series/logic.robot

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Remove the first instance of a series from user's collection
1212
Xpath Should Match X Times xpath://input[@value="Remove from collection"] 2
1313
# Submit the first form
1414
Submit Form css:.remove-series-form
15-
Page Should Contain Link css:[href="/series/3"]
15+
Page Should Contain Link css:.image-gallery figcaption [href="/series/3"]
1616
# See https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator
17-
Element Text Should Be css:[href="/series/3"] ~ .label-default 2 out of 3
17+
Element Text Should Be css:.image-gallery figcaption [href="/series/3"] ~ .label-default 2 out of 3
1818

1919
Remove the last instance of a series from user's collection
2020
Go To ${SITE_URL}/series/3

0 commit comments

Comments
 (0)