Skip to content

Commit

Permalink
[server/OAPIF] Make pagesize configurable for collection items HTML page
Browse files Browse the repository at this point in the history
  • Loading branch information
pathmapper committed Apr 23, 2023
1 parent bc114fb commit 29b5c6e
Show file tree
Hide file tree
Showing 11 changed files with 973 additions and 56 deletions.
73 changes: 70 additions & 3 deletions resources/server/api/ogc/templates/wfs3/getFeatures.html
Expand Up @@ -2,23 +2,51 @@
{% include "header.html" %}

<div class="row">
<p>
<b>Number of matching items:</b> {{ numberMatched }}
&nbsp;
<b>Number of returned items:</b> {{ numberReturned }}
</p>
</div>

<div class="row">
{% if metadata.pagesize != [] %}
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Page size
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
{% for pagesizeitem in metadata.pagesize %}
{% if pagesizeitem == last(metadata.pagesize) %}
<div class="dropdown-divider"></div>
{% endif %}
<a class="dropdown-item" href="{{ pagesizeitem.href }}">{{ pagesizeitem.title }}</a>
{% endfor %}
</div>
</div>
{% endif %}
{% if metadata.pagination != [] %}
&nbsp;
<nav aria-label="Page navigation">
<ul class="pagination">
<ul class="pagination" style="margin:0px">
{% endif %}
{% for link in links_filter( links, "rel", "prev" ) %}
<li class="page-item"><a class="page-link" href="{{ link.href }}">{{ link.title }}</a></li>
{% endfor %}
{% for pageitem in metadata.pagination %}
<li class="{{ pageitem.class }}"><a class="page-link" {% if existsIn(pageitem, "href" ) %}
href="{{ pageitem.href }}" {% endif %}>{{ pageitem.title }}</a>
href="{{ pageitem.href }}"{% endif %}>{{ pageitem.title }}</a>
</li>
{% endfor %}
{% for link in links_filter( links, "rel", "next" ) %}
<li class="page-item"><a class="page-link" href="{{ link.href }}">{{ link.title }}</a></li>
{% endfor %}
{% if metadata.pagination != [] %}
</ul>
</nav>
{% endif %}
</div>

<br>
<div class="row">
<div class="col-md-6">
<h1>{{ metadata.pageTitle }}</h1>
Expand All @@ -38,4 +66,43 @@ <h2><a href="{{ path_append( feature.id ) }}">{{ metadata.layerTitle }} {{ featu

</div>

<div class="row">
{% if metadata.pagesize != [] %}
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Page size
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
{% for pagesizeitem in metadata.pagesize %}
{% if pagesizeitem == last(metadata.pagesize) %}
<div class="dropdown-divider"></div>
{% endif %}
<a class="dropdown-item" href="{{ pagesizeitem.href }}">{{ pagesizeitem.title }}</a>
{% endfor %}
</div>
</div>
{% endif %}
{% if metadata.pagination != [] %}
&nbsp;
<nav aria-label="Page navigation">
<ul class="pagination" style="margin:0px">
{% endif %}
{% for link in links_filter( links, "rel", "prev" ) %}
<li class="page-item"><a class="page-link" href="{{ link.href }}">{{ link.title }}</a></li>
{% endfor %}
{% for pageitem in metadata.pagination %}
<li class="{{ pageitem.class }}"><a class="page-link" {% if existsIn(pageitem, "href" ) %}
href="{{ pageitem.href }}"{% endif %}>{{ pageitem.title }}</a>
</li>
{% endfor %}
{% for link in links_filter( links, "rel", "next" ) %}
<li class="page-item"><a class="page-link" href="{{ link.href }}">{{ link.title }}</a></li>
{% endfor %}
{% if metadata.pagination != [] %}
</ul>
</nav>
{% endif %}
</div>
<br>

{% include "footer.html" %}
45 changes: 45 additions & 0 deletions src/server/services/wfs3/qgswfs3handlers.cpp
Expand Up @@ -1388,6 +1388,50 @@ void QgsWfs3CollectionsItemsHandler::handleRequest( const QgsServerApiContext &c
cleanedUrlAsString += '&';
}

// Pagesize metadata
json pagesize = json::array();
const qlonglong maxLimit { context.serverInterface()->serverSettings()->apiWfs3MaxLimit() };
if ( matchedFeaturesCount > 1 && maxLimit > 1 )
{
const std::string pageSizeOneLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=1" ).toStdString() };
pagesize.push_back( {{ "title", "1" }, { "href", pageSizeOneLink }} ) ;
}
if ( matchedFeaturesCount > 10 && maxLimit > 10 )
{
const std::string pageSizeTenLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=10" ).toStdString() };
pagesize.push_back( {{ "title", "10" }, { "href", pageSizeTenLink }} ) ;
}
if ( matchedFeaturesCount > 20 && maxLimit > 20 )
{
const std::string pageSizeTwentyLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=20" ).toStdString() };
pagesize.push_back( {{ "title", "20" }, { "href", pageSizeTwentyLink }} ) ;
}
if ( matchedFeaturesCount > 50 && maxLimit > 50 )
{
const std::string pageSizeFiftyLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=50" ).toStdString() };
pagesize.push_back( {{ "title", "50" }, { "href", pageSizeFiftyLink }} ) ;
}
if ( matchedFeaturesCount > 100 && maxLimit > 100 )
{
const std::string pageSizeHundredLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=100" ).toStdString() };
pagesize.push_back( {{ "title", "100" }, { "href", pageSizeHundredLink }} ) ;
}
if ( matchedFeaturesCount > 1000 && maxLimit > 1000 )
{
const std::string pageSizeThousandLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=1000" ).toStdString() };
pagesize.push_back( {{ "title", "1000" }, { "href", pageSizeThousandLink }} ) ;
}
if ( matchedFeaturesCount > 1 && maxLimit > 1 )
{
std::string maxTitle = "All";
if ( maxLimit < matchedFeaturesCount )
{
maxTitle = "Maximum";
}
const std::string pageSizeMaxLink { cleanedUrlAsString.toStdString() + QStringLiteral( "offset=0&limit=%1" ).arg( maxLimit ).toStdString() };
pagesize.push_back( {{ "title", maxTitle }, { "href", pageSizeMaxLink }} ) ;
}

// Get the self link
json selfLink;
for ( const auto &l : data["links"] )
Expand Down Expand Up @@ -1502,6 +1546,7 @@ void QgsWfs3CollectionsItemsHandler::handleRequest( const QgsServerApiContext &c
"geojsonUrl", href( context, "/",
QgsServerOgcApi::contentTypeToExtension( QgsServerOgcApi::ContentType::GEOJSON ) )
},
{ "pagesize", pagesize },
{ "pagination", pagination },
{ "navigation", navigation }
};
Expand Down
Expand Up @@ -65,32 +65,69 @@


<div class="row">
<p>
<b>Number of matching items:</b> 38
&nbsp;
<b>Number of returned items:</b> 6
</p>
</div>

<div class="row">

<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Page size
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">


<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=1">1</a>


<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=10">10</a>


<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=20">20</a>


<div class="dropdown-divider"></div>

<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=10000">All</a>

</div>
</div>


&nbsp;
<nav aria-label="Page navigation">
<ul class="pagination">
<ul class="pagination" style="margin:0px">



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

<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" >2</a>
href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=6&limit=6">2</a>
</li>

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

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


<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>


</ul>
</nav>

</div>

<br>
<div class="row">
<div class="col-md-6">
<h1>Features in layer as_areas</h1>
Expand Down Expand Up @@ -555,6 +592,63 @@ <h2><a href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items/6

</div>

<div class="row">

<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Page size
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">


<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=1">1</a>


<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=10">10</a>


<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=20">20</a>


<div class="dropdown-divider"></div>

<a class="dropdown-item" href="http://server.qgis.org/wfs3/collections/as-areas-short-name/items.html?offset=0&limit=10000">All</a>

</div>
</div>


&nbsp;
<nav aria-label="Page navigation">
<ul class="pagination" style="margin:0px">



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

<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">2</a>
</li>

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

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


<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>


</ul>
</nav>

</div>
<br>

<!-- FOOTER TEMPLATE footer.html -->
</div> <!-- //container -->

Expand Down

0 comments on commit 29b5c6e

Please sign in to comment.