Skip to content

Commit

Permalink
rollback webdav url replacement in WFS requests, remove jsonmachine d…
Browse files Browse the repository at this point in the history
…ependency, webdav url replacement on web client side
  • Loading branch information
mind84 committed Nov 21, 2023
1 parent b25b869 commit ff28eeb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 102 deletions.
9 changes: 8 additions & 1 deletion assets/src/legacy/attributeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,6 @@ var lizAttributeTable = function() {
function createDatatableColumns(aName, atFeatures, hiddenFields, cAliases, cTypes, allColumnsKeyValues){
const columns = [];
let firstDisplayedColIndex = 0;

// Column with selected status
columns.push( {"data": "lizSelected", "width": "25px", "searchable": false, "sortable": true, "visible": false} );
firstDisplayedColIndex+=1;
Expand Down Expand Up @@ -1511,10 +1510,18 @@ var lizAttributeTable = function() {
}
} else {
// Check if we need to replace url or media by link
let davConf = lizUrls['webDavUrl'] && config.layers[aName]?.webDavFields && Array.isArray(config.layers[aName].webDavFields) && config.layers[aName].webDavFields.includes(columnName) || false;
colConf['render'] = function (data, type, row, meta) {
// Replace media and URL with links
if (!data || !(typeof data === 'string'))
return data;
if (davConf) {
// replace the root of the url
if(data.startsWith(lizUrls['webDavUrl'])){
data = data.replace(lizUrls['webDavUrl'],'dav/')
}
}

if (data.substring(0, 6) == 'media/' || data.substring(0, 7) == '/media/' || data.substring(0, 9) == '../media/') {
var rdata = data;
var colMeta = meta.settings.aoColumns[meta.col];
Expand Down
3 changes: 1 addition & 2 deletions lizmap/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"jelix/ldapdao-module": "~2.2.4",
"proj4php/proj4php": "~2.0.0",
"violet/streaming-json-encoder": "^1.1.5",
"guzzlehttp/guzzle": "^7.7.0",
"halaxa/json-machine": "^1.1"
"guzzlehttp/guzzle": "^7.7.0"
},
"require-dev": {
"gettext/gettext": "^4.6.1"
Expand Down
4 changes: 4 additions & 0 deletions lizmap/modules/lizmap/lib/Project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,10 @@ public function getUpdatedConfig()
$layerDef = $this->getLayerDefinition($obj->id);
// Add layer type
$obj->layerType = $layerDef['type'];
// add webDav fields as layer property
if ($layerDef && array_key_exists('webDavFields', $layerDef)) {
$obj->webDavFields = $layerDef['webDavFields'];
}
// Extract layer datasource parameters only for raster/wms
if ($layerDef['type'] == 'raster' && $layerDef['provider'] == 'wms') {
// source xyz: $layerDatasource['type'] == 'xyz'
Expand Down
6 changes: 3 additions & 3 deletions lizmap/modules/lizmap/lib/Request/RemoteStorageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ public static function getProfile($storageType, $profileName = 'default')
$profile = null;

try {
$profile = $context->getProfile($storageType, $profileName, true);
if ($profile && is_array($profile) && array_key_exists('enabled', $profile) && $profile['enabled'] == 1 && array_key_exists('baseUri', $profile)) {
return $profile;
$webDavProfile = $context->getProfile($storageType, $profileName, true);
if ($webDavProfile && is_array($webDavProfile) && array_key_exists('enabled', $webDavProfile) && $webDavProfile['enabled'] == 1 && array_key_exists('baseUri', $webDavProfile)) {
$profile = $webDavProfile;
}
} catch (\Exception $e) {
$profile = null;
Expand Down
97 changes: 1 addition & 96 deletions lizmap/modules/lizmap/lib/Request/WFSRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

namespace Lizmap\Request;

use GuzzleHttp\Psr7;
use JsonMachine;

/**
* @see https://en.wikipedia.org/wiki/Web_Feature_Service.
*/
Expand Down Expand Up @@ -387,59 +384,7 @@ protected function getfeatureQgis()

// Else pass query to QGIS Server
// Get remote data
$wfsResult = $this->request(true, true);
if ($wfsResult->code >= 400) {
return $wfsResult;
}
if ($wfsResult->mime != 'application/vnd.geo+json; charset=utf-8') {
return $wfsResult;
}
// check for webdav fields
$webDavConfiguration = $this->getWebDavConf();
if (!array_key_exists('webDavFields', $webDavConfiguration) || count($webDavConfiguration['webDavFields']) == 0) {
return $wfsResult;
}

$featureStream = Psr7\StreamWrapper::getResource($wfsResult->getBodyAsStream());
$features = JsonMachine\Items::fromStream($featureStream, array('pointer' => '/features'));

return new OGCResponse(200, 'application/vnd.geo+json; charset=utf-8', (function () use ($features, $webDavConfiguration) {
yield '{"type": "FeatureCollection", "features": [';
$virg = '';
foreach ($features as $feat) {
if (property_exists($feat, 'properties')) {
$feat->properties = $this->processFeatureGeoJSON($feat->properties, $webDavConfiguration);
}

yield $virg.json_encode($feat);
$virg = ',';
}

yield ']}';
})());
}

/**
* return the configuration for webdav fields for current layer.
*
* @return array the configuration
*/
protected function getWebDavConf()
{
if ($this->qgisLayer) {
$davProfile = RemoteStorageRequest::getProfile('webdav');
$baseUri = '';
if ($davProfile) {
$baseUri = $davProfile['baseUri'];
}

return array(
'baseUri' => $baseUri,
'webDavFields' => $this->qgisLayer->getWebDavFieldConfiguration(),
);
}

return array();
return $this->request(true, true);
}

/**
Expand Down Expand Up @@ -904,17 +849,7 @@ protected function getfeaturePostgres()
return new OGCResponse(200, 'application/vnd.geo+json; charset=utf-8', (function () use ($q) {
yield '{"type": "FeatureCollection", "features": [';
$virg = '';
// check for webdav configuration
$webDavConfiguration = $this->getWebDavConf();
foreach ($q as $d) {
if (count($webDavConfiguration['webDavFields']) > 0) {
$geoJson = json_decode($d->geojson);
if (property_exists($geoJson, 'properties')) {
$geoJson->properties = $this->processFeatureGeoJSON($geoJson->properties, $webDavConfiguration);
$d->geojson = json_encode($geoJson);
}
}

yield $virg.$d->geojson;
$virg = ',';
}
Expand All @@ -923,36 +858,6 @@ protected function getfeaturePostgres()
})());
}

/**
* parse geoJSON response properties.
*
* @param object $properties record properties array
* @param array $webDavConf list of webdav fields
*
* @return object
*/
protected function processFeatureGeoJSON($properties, $webDavConf)
{
foreach ($webDavConf['webDavFields'] as $field => $url) {
if ($properties->{$field}) {
// if the base path starts with base URI, replace it with a genric path
if ($webDavConf['baseUri'] && strpos($properties->{$field}, $webDavConf['baseUri']) === 0) {
$properties->{$field} = str_replace($webDavConf['baseUri'], 'dav/', $properties->{$field});
} else {
// set filename as value
$pathInfo = pathinfo($properties->{$field});
if ($pathInfo['filename'] !== '') {
$properties->{$field} = $pathInfo['filename'].'.'.$pathInfo['extension'];
} else {
$properties->{$field} = $pathInfo['basename'];
}
}
}
}

return $properties;
}

/**
* Validate an expression filter.
*
Expand Down
9 changes: 9 additions & 0 deletions lizmap/modules/view/controllers/lizMap.classic.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use Lizmap\Request\RemoteStorageRequest;

/**
* Displays a full featured map based on one Qgis project.
*
Expand Down Expand Up @@ -190,6 +193,7 @@ public function index()
$lizUrls = array(
'params' => array('repository' => $repository, 'project' => $project),
'config' => jUrl::get('lizmap~service:getProjectConfig'),
'remoteStorageConfig' => jUrl::get('lizmap~service:getRemoteStorageConfig'),
'keyValueConfig' => jUrl::get('lizmap~service:getKeyValueConfig'),
'wms' => jUrl::get('lizmap~service:index'),
'media' => jUrl::get('view~media:getMedia'),
Expand Down Expand Up @@ -219,6 +223,11 @@ function f($x)
$lizUrls['removeCache'] = jUrl::get('admin~maps:removeLayerCache');
}

$webDavProfile = RemoteStorageRequest::getProfile('webdav');
if ($webDavProfile) {
$lizUrls['webDavUrl'] = $webDavProfile['baseUri'];
}

$rep->addJSCode('var lizUrls = '.json_encode($lizUrls).';');
$rep->addJSCode('var lizProj4 = '.json_encode($lproj->getAllProj4()).';');
$rep->addStyle('#map', 'background-color:'.$lproj->getCanvasColor().';');
Expand Down

0 comments on commit ff28eeb

Please sign in to comment.