diff --git a/assets/src/legacy/attributeTable.js b/assets/src/legacy/attributeTable.js index 9eeec98494..b2fcc8866e 100644 --- a/assets/src/legacy/attributeTable.js +++ b/assets/src/legacy/attributeTable.js @@ -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; @@ -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]; diff --git a/lizmap/composer.json b/lizmap/composer.json index 0d877093b2..2c05b7a671 100644 --- a/lizmap/composer.json +++ b/lizmap/composer.json @@ -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" diff --git a/lizmap/modules/lizmap/lib/Project/Project.php b/lizmap/modules/lizmap/lib/Project/Project.php index fbda20aee8..fa3412f31e 100644 --- a/lizmap/modules/lizmap/lib/Project/Project.php +++ b/lizmap/modules/lizmap/lib/Project/Project.php @@ -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' diff --git a/lizmap/modules/lizmap/lib/Request/RemoteStorageRequest.php b/lizmap/modules/lizmap/lib/Request/RemoteStorageRequest.php index a6e848be04..c0c59ef3f2 100644 --- a/lizmap/modules/lizmap/lib/Request/RemoteStorageRequest.php +++ b/lizmap/modules/lizmap/lib/Request/RemoteStorageRequest.php @@ -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; diff --git a/lizmap/modules/lizmap/lib/Request/WFSRequest.php b/lizmap/modules/lizmap/lib/Request/WFSRequest.php index 58844e26cc..d53d8e4128 100644 --- a/lizmap/modules/lizmap/lib/Request/WFSRequest.php +++ b/lizmap/modules/lizmap/lib/Request/WFSRequest.php @@ -12,9 +12,6 @@ namespace Lizmap\Request; -use GuzzleHttp\Psr7; -use JsonMachine; - /** * @see https://en.wikipedia.org/wiki/Web_Feature_Service. */ @@ -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); } /** @@ -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 = ','; } @@ -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. * diff --git a/lizmap/modules/view/controllers/lizMap.classic.php b/lizmap/modules/view/controllers/lizMap.classic.php index 110d47953b..f73e6ba015 100644 --- a/lizmap/modules/view/controllers/lizMap.classic.php +++ b/lizmap/modules/view/controllers/lizMap.classic.php @@ -1,4 +1,7 @@ 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'), @@ -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().';');