Skip to content

Commit 3adce04

Browse files
authoredApr 26, 2023
Merge pull request #52853 from pathmapper/pagesize
[server/OAPIF] Make pagesize configurable and other improvements for collection items HTML page
2 parents a9056f3 + 9935a3f commit 3adce04

11 files changed

+926
-60
lines changed
 

‎resources/server/api/ogc/templates/wfs3/getFeatures.html

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,49 @@
22
{% include "header.html" %}
33

44
<div class="row">
5+
<p>
6+
<b>Number of matching items:</b> {{ numberMatched }}
7+
&nbsp;
8+
<b>Number of returned items:</b> {{ numberReturned }}
9+
</p>
10+
</div>
11+
12+
<div class="row">
13+
{% if metadata.pagesize != [] %}
14+
<div class="dropdown">
15+
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
16+
Page size
17+
</button>
18+
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
19+
{% for pagesizeitem in metadata.pagesize %}
20+
{% if pagesizeitem == last(metadata.pagesize) %}
21+
<div class="dropdown-divider"></div>
22+
{% endif %}
23+
<a class="dropdown-item" href="{{ pagesizeitem.href }}">{{ pagesizeitem.title }}</a>
24+
{% endfor %}
25+
</div>
26+
</div>
27+
{% endif %}
28+
{% if metadata.pagination != [] %}
29+
&nbsp;
530
<nav aria-label="Page navigation">
6-
<ul class="pagination">
31+
<ul class="pagination" style="margin:0px">
732
{% for link in links_filter( links, "rel", "prev" ) %}
833
<li class="page-item"><a class="page-link" href="{{ link.href }}">{{ link.title }}</a></li>
934
{% endfor %}
1035
{% for pageitem in metadata.pagination %}
1136
<li class="{{ pageitem.class }}"><a class="page-link" {% if existsIn(pageitem, "href" ) %}
12-
href="{{ pageitem.href }}" {% endif %}>{{ pageitem.title }}</a>
37+
href="{{ pageitem.href }}"{% endif %}>{{ pageitem.title }}</a>
1338
</li>
1439
{% endfor %}
1540
{% for link in links_filter( links, "rel", "next" ) %}
1641
<li class="page-item"><a class="page-link" href="{{ link.href }}">{{ link.title }}</a></li>
1742
{% endfor %}
1843
</ul>
1944
</nav>
45+
{% endif %}
2046
</div>
21-
47+
<br>
2248
<div class="row">
2349
<div class="col-md-6">
2450
<h1>{{ metadata.pageTitle }}</h1>
@@ -38,4 +64,41 @@ <h2><a href="{{ path_append( feature.id ) }}">{{ metadata.layerTitle }} {{ featu
3864

3965
</div>
4066

67+
<div class="row">
68+
{% if metadata.pagesize != [] %}
69+
<div class="dropdown">
70+
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
71+
Page size
72+
</button>
73+
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
74+
{% for pagesizeitem in metadata.pagesize %}
75+
{% if pagesizeitem == last(metadata.pagesize) %}
76+
<div class="dropdown-divider"></div>
77+
{% endif %}
78+
<a class="dropdown-item" href="{{ pagesizeitem.href }}">{{ pagesizeitem.title }}</a>
79+
{% endfor %}
80+
</div>
81+
</div>
82+
{% endif %}
83+
{% if metadata.pagination != [] %}
84+
&nbsp;
85+
<nav aria-label="Page navigation">
86+
<ul class="pagination" style="margin:0px">
87+
{% for link in links_filter( links, "rel", "prev" ) %}
88+
<li class="page-item"><a class="page-link" href="{{ link.href }}">{{ link.title }}</a></li>
89+
{% endfor %}
90+
{% for pageitem in metadata.pagination %}
91+
<li class="{{ pageitem.class }}"><a class="page-link" {% if existsIn(pageitem, "href" ) %}
92+
href="{{ pageitem.href }}"{% endif %}>{{ pageitem.title }}</a>
93+
</li>
94+
{% endfor %}
95+
{% for link in links_filter( links, "rel", "next" ) %}
96+
<li class="page-item"><a class="page-link" href="{{ link.href }}">{{ link.title }}</a></li>
97+
{% endfor %}
98+
</ul>
99+
</nav>
100+
{% endif %}
101+
</div>
102+
<br>
103+
41104
{% include "footer.html" %}

‎src/server/services/wfs3/qgswfs3handlers.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,47 @@ void QgsWfs3CollectionsItemsHandler::handleRequest( const QgsServerApiContext &c
13881388
cleanedUrlAsString += '&';
13891389
}
13901390

1391+
// Pagesize metadata
1392+
json pagesize = json::array();
1393+
const qlonglong maxLimit { context.serverInterface()->serverSettings()->apiWfs3MaxLimit() };
1394+
if ( matchedFeaturesCount > 1 && maxLimit > 1 )
1395+
{
1396+
const std::string pageSizeOneLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=1" ).toStdString() };
1397+
pagesize.push_back( {{ "title", "1" }, { "href", pageSizeOneLink }} ) ;
1398+
if ( matchedFeaturesCount > 10 && maxLimit > 10 )
1399+
{
1400+
const std::string pageSizeTenLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=10" ).toStdString() };
1401+
pagesize.push_back( {{ "title", "10" }, { "href", pageSizeTenLink }} ) ;
1402+
}
1403+
if ( matchedFeaturesCount > 20 && maxLimit > 20 )
1404+
{
1405+
const std::string pageSizeTwentyLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=20" ).toStdString() };
1406+
pagesize.push_back( {{ "title", "20" }, { "href", pageSizeTwentyLink }} ) ;
1407+
}
1408+
if ( matchedFeaturesCount > 50 && maxLimit > 50 )
1409+
{
1410+
const std::string pageSizeFiftyLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=50" ).toStdString() };
1411+
pagesize.push_back( {{ "title", "50" }, { "href", pageSizeFiftyLink }} ) ;
1412+
}
1413+
if ( matchedFeaturesCount > 100 && maxLimit > 100 )
1414+
{
1415+
const std::string pageSizeHundredLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=100" ).toStdString() };
1416+
pagesize.push_back( {{ "title", "100" }, { "href", pageSizeHundredLink }} ) ;
1417+
}
1418+
if ( matchedFeaturesCount > 1000 && maxLimit > 1000 )
1419+
{
1420+
const std::string pageSizeThousandLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=1000" ).toStdString() };
1421+
pagesize.push_back( {{ "title", "1000" }, { "href", pageSizeThousandLink }} ) ;
1422+
}
1423+
std::string maxTitle = "All";
1424+
if ( maxLimit < matchedFeaturesCount )
1425+
{
1426+
maxTitle = "Maximum";
1427+
}
1428+
const std::string pageSizeMaxLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=%1" ).arg( maxLimit ).toStdString() };
1429+
pagesize.push_back( {{ "title", maxTitle }, { "href", pageSizeMaxLink }} ) ;
1430+
}
1431+
13911432
// Get the self link
13921433
json selfLink;
13931434
for ( const auto &l : data["links"] )
@@ -1502,6 +1543,7 @@ void QgsWfs3CollectionsItemsHandler::handleRequest( const QgsServerApiContext &c
15021543
"geojsonUrl", href( context, "/",
15031544
QgsServerOgcApi::contentTypeToExtension( QgsServerOgcApi::ContentType::GEOJSON ) )
15041545
},
1546+
{ "pagesize", pagesize },
15051547
{ "pagination", pagination },
15061548
{ "navigation", navigation }
15071549
};

‎tests/testdata/qgis_server/api/test_wfs3_collections_items_as_areas_short_name_1.html

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,67 @@
6565

6666

6767
<div class="row">
68+
<p>
69+
<b>Number of matching items:</b> 38
70+
&nbsp;
71+
<b>Number of returned items:</b> 6
72+
</p>
73+
</div>
74+
75+
<div class="row">
76+
77+
<div class="dropdown">
78+
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
79+
Page size
80+
</button>
81+
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
82+
83+
84+
<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=1">1</a>
85+
86+
87+
<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=10">10</a>
88+
89+
90+
<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=20">20</a>
91+
92+
93+
<div class="dropdown-divider"></div>
94+
95+
<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=10000">All</a>
96+
97+
</div>
98+
</div>
99+
100+
101+
&nbsp;
68102
<nav aria-label="Page navigation">
69-
<ul class="pagination">
103+
<ul class="pagination" style="margin:0px">
70104

71105

72106
<li class="page-item active"><a class="page-link"
73-
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=6" >1</a>
107+
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=6">1</a>
74108
</li>
75109

76110
<li class="page-item"><a class="page-link"
77-
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=6&limit=6" >2</a>
111+
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=6&limit=6">2</a>
78112
</li>
79113

80114
<li class="page-item disabled"><a class="page-link" ></a>
81115
</li>
82116

83117
<li class="page-item"><a class="page-link"
84-
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=36&limit=6" >7</a>
118+
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=36&limit=6">7</a>
85119
</li>
86120

87121

88122
<li class="page-item"><a class="page-link" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=6&limit=6">Next page</a></li>
89123

90124
</ul>
91125
</nav>
126+
92127
</div>
93-
128+
<br>
94129
<div class="row">
95130
<div class="col-md-6">
96131
<h1>Features in layer as_areas</h1>
@@ -555,6 +590,61 @@ <h2><a href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items/6
555590

556591
</div>
557592

593+
<div class="row">
594+
595+
<div class="dropdown">
596+
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
597+
Page size
598+
</button>
599+
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
600+
601+
602+
<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=1">1</a>
603+
604+
605+
<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=10">10</a>
606+
607+
608+
<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=20">20</a>
609+
610+
611+
<div class="dropdown-divider"></div>
612+
613+
<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=10000">All</a>
614+
615+
</div>
616+
</div>
617+
618+
619+
&nbsp;
620+
<nav aria-label="Page navigation">
621+
<ul class="pagination" style="margin:0px">
622+
623+
624+
<li class="page-item active"><a class="page-link"
625+
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=6">1</a>
626+
</li>
627+
628+
<li class="page-item"><a class="page-link"
629+
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=6&limit=6">2</a>
630+
</li>
631+
632+
<li class="page-item disabled"><a class="page-link" ></a>
633+
</li>
634+
635+
<li class="page-item"><a class="page-link"
636+
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=36&limit=6">7</a>
637+
</li>
638+
639+
640+
<li class="page-item"><a class="page-link" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=6&limit=6">Next page</a></li>
641+
642+
</ul>
643+
</nav>
644+
645+
</div>
646+
<br>
647+
558648
<!-- FOOTER TEMPLATE footer.html -->
559649
</div> <!-- //container -->
560650

0 commit comments

Comments
 (0)
Please sign in to comment.