Skip to content

Commit 09b31a6

Browse files
author
Magnar Eivind Martinsen
committed
Updated dynamic landingpages with merging schema.org json-ld from laraf. Fixed other minor bugs in javascript files
1 parent 5e87e71 commit 09b31a6

File tree

6 files changed

+270
-83
lines changed

6 files changed

+270
-83
lines changed

metsis/metsis_lib/metsis_lib.routing.yml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ metsis_lib.dynamic_landing_pages_controller_getLandingPage:
2121
path: '/dataset/{id}'
2222
defaults:
2323
_controller: '\Drupal\metsis_lib\Controller\DynamicLandingPagesController::getLandingPage'
24-
_title: ''
2524
requirements:
2625
_custom_access: '\Drupal\metsis_lib\Controller\DynamicLandingPagesController::access'
2726
_permission: 'access content'

metsis/metsis_lib/src/Controller/DynamicLandingPagesController.php

+137-12
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ public function getLandingPage(string $id, Request $request) {
247247
$this->cache->set($cid, $renderArray, CacheBackendInterface::CACHE_PERMANENT, [$cid]);
248248
}
249249

250+
// Handle caching.
251+
$this->renderer->addCacheableDependency($renderArray, $main_config);
250252
return $renderArray;
251253

252254
}
@@ -378,15 +380,16 @@ protected function generateLandingPage($main_config, $host, $fullhost, $id, $id_
378380
}
379381

380382
// Add article prefix.
383+
$renderArray = [];
381384
$renderArray['#prefix'] = '<div class=dynamic-landing-page>';
382385
$renderArray['#suffix'] = '</div>';
383-
$renderArray = [];
384386

385387
$renderArray['timestamp'] = [
386388
'#type' => 'value',
387389
'#value' => strtotime($fields['timestamp']),
388390
];
389-
391+
// Add page title.
392+
$renderArray['#title'] = $fields['title'][0];
390393
// Render the title.
391394
$renderArray['title'] = [
392395
'#type' => 'markup',
@@ -989,7 +992,8 @@ protected function generateLandingPage($main_config, $host, $fullhost, $id, $id_
989992
$renderArray['#attached']['library'][] = 'metsis_lib/landing_page';
990993
$renderArray['#attached']['library'][] = 'metsis_lib/fa_academia';
991994
$renderArray['#cache'] = [
992-
'contexts' => ['url'],
995+
'contexts' => ['url.path'],
996+
'bin' => 'dynamic_landingpages',
993997
'tags' => ['dataset:' . $dataset_id],
994998
'max-age' => Cache::PERMANENT,
995999
];
@@ -1069,28 +1073,149 @@ public function getJsonld($fields, $host, $id_prefix) {
10691073
if (isset($fields['temporal_extent_end_date'])) {
10701074
$end_date = $fields['temporal_extent_end_date'][0];
10711075
}
1076+
else {
1077+
$end_date = '..';
1078+
}
10721079
$mid = $fields['metadata_identifier'];
10731080
if ($id_prefix === 'no-met-nbs') {
10741081
$mid = explode(':', $fields['metadata_identifier'])[1];
10751082
}
1083+
$keywords = [];
1084+
if (isset($fields['keywords_gcmd'])) {
1085+
foreach ($fields['keywords_gcmd'] as $gcmd) {
1086+
$keywords[] = [
1087+
'@type' => 'DefinedTerm',
1088+
'name' => $gcmd,
1089+
'inDefinedTermSet' => 'https://gcmd.earthdata.nasa.gov/kms/concepts/concept_scheme/sciencekeywords'
1090+
];
1091+
}
1092+
}
1093+
if (isset($fields['keywords_cfstdn'])) {
1094+
foreach ($fields['keywords_cfstdn'] as $cfstdn) {
1095+
$keywords[] = [
1096+
'@type' => 'DefinedTerm',
1097+
'name' => $cfstdn,
1098+
'inDefinedTermSet' => 'https://vocab.nerc.ac.uk/standard_name/',
1099+
'url' => 'https://vocab.nerc.ac.uk/standard_name/' . $cfstdn
1100+
];
1101+
}
1102+
}
1103+
if (isset($fields['project_long_name'])) {
1104+
$projects = [];
1105+
foreach ($fields['project_long_name'] as $projectln) {
1106+
$projects[] = [
1107+
'@type' => 'MonetaryGrant',
1108+
'name' => $projectln
1109+
];
1110+
}
1111+
}
1112+
if (isset($fields['personnel_investigator_name'])) {
1113+
$creators = [];
1114+
foreach ($fields['personnel_investigator_name'] as $creator) {
1115+
$creators[] = [
1116+
'@type' => 'Person',
1117+
'name' => $creator
1118+
];
1119+
}
1120+
}
1121+
if (isset($fields['personnel_investigator_organisation'])) {
1122+
$providers = [];
1123+
foreach ($fields['personnel_investigator_organisation'] as $provider) {
1124+
$providers[] = [
1125+
'@type' => 'Organization',
1126+
'name' => $provider
1127+
];
1128+
}
1129+
}
1130+
if (isset($fields['personnel_technical_name']) or isset($fields['personnel_metadata_author_name'])) {
1131+
$contributors = [];
1132+
if (isset($fields['personnel_technical_name'])) {
1133+
foreach ($fields['personnel_investigator_name'] as $contributor) {
1134+
$contributors[] = [
1135+
'@type' => 'Person',
1136+
'name' => $contributor,
1137+
];
1138+
}
1139+
}
1140+
if (isset($fields['personnel_metadata_author_name'])) {
1141+
foreach ($fields['personnel_metadata_author_name'] as $contributor) {
1142+
$contributors[] = [
1143+
'@type' => 'Person',
1144+
'name' => $contributor
1145+
];
1146+
}
1147+
}
1148+
}
1149+
if (isset($fields['data_access_url_http'])) {
1150+
$datadownloads = [];
1151+
foreach ($fields['data_access_url_http'] as $datadownload) {
1152+
$datadownloads[] = [
1153+
'@type' => 'DataDownload',
1154+
'description' => 'Direct dowload',
1155+
'contentUrl' => $datadownload
1156+
];
1157+
}
1158+
}
1159+
if (isset($fields['geographic_extent_rectangle_north'])) {
1160+
$spatialcoverage = [
1161+
'@type' => 'Place',
1162+
'geo' => [
1163+
'@type' => 'GeoShape',
1164+
'box' => implode(" ", [$fields['geographic_extent_rectangle_south'],
1165+
$fields['geographic_extent_rectangle_west'],
1166+
$fields['geographic_extent_rectangle_north'],
1167+
$fields['geographic_extent_rectangle_east'],
1168+
]),
1169+
],
1170+
'additionalProperty' => [
1171+
'@type' => 'PropertyValue',
1172+
'propertyID' => 'http://inspire.ec.europa.eu/glossary/SpatialReferenceSystem',
1173+
'value' => 'http://www.opengis.net/def/crs/EPSG/0/'
1174+
. $fields['geographic_extent_rectangle_srsName'],
1175+
],
1176+
];
1177+
}
1178+
if (in_array("Created", $fields['last_metadata_update_type'])) {
1179+
$i = 0;
1180+
foreach ($fields['last_metadata_update_type'] as $mdupdatedt) {
1181+
if ($mdupdatedt == 'Created') {
1182+
$datecreated = $fields['last_metadata_update_datetime'][$i];
1183+
}
1184+
$i++;
1185+
}
1186+
}
10761187
$json = [
1077-
'@context' => 'https://schema.org/',
1188+
'@context' => ['@vocab' => 'https://schema.org/'],
10781189
'@type' => 'Dataset',
1079-
'@id' => $fields['related_url_landing_page'][0] ?? '',
1190+
'@id' => $fields['metadata_identifier'],
1191+
'identifier' => [
1192+
'@type' => 'PropertyValue',
1193+
'@id' => $fields['related_url_landing_page'][0] ?? '',
1194+
'url' => $fields['related_url_landing_page'][0] ?? '',
1195+
'value' => $mid,
1196+
],
10801197
'name' => $fields['title'][0],
10811198
'description' => $fields['abstract'][0],
10821199
'url' => $fields['related_url_landing_page'][0] ?? '',
1083-
'identifier' => [
1084-
$mid,
1085-
],
1086-
'keywords' => $fields['keywords_keyword'],
1087-
'license' => $fields['use_constraint_resource'] ?? "",
1200+
'dateCreated' => $datecreated ?? '',
1201+
'license' => $fields['use_constraint_resource'] ?? '',
1202+
'keywords' => $keywords,
10881203
'includedInDataCatalog' => [
10891204
'@type' => 'DataCatalog',
10901205
'name:' => $host,
10911206
],
1092-
'temporalCoverage' => $start_date . '/' . $end_date ?? '',
1093-
1207+
'temporalCoverage' => $start_date . '/' . $end_date ,
1208+
'spatialCoverage' => $spatialcoverage,
1209+
'conditionsOfAccess' => $fields['access_constraint'] ?? '',
1210+
'creator' => $creators ?? '',
1211+
'contributor' => $contributors ?? '',
1212+
'provider' => $providers ?? '',
1213+
'publisher' => [
1214+
'@type' => 'Organization',
1215+
'name' => $fields['data_center_long_name'][0] ?? '',
1216+
'url' => $fields['data_center_url'][0] ?? '',
1217+
],
1218+
'funding' => $projects ?? '',
10941219
];
10951220
return $json;
10961221
}

metsis/metsis_search/js/metsis_res_map.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ console.log("Start of metsis search map script:");
662662
baseLayer: false,
663663
visible: false,
664664
source: new ol.source.TileWMS({
665-
url: 'https://openwms.statkart.no/skwms1/wms.vegnett2?',
665+
url: 'https://wms.geonorge.no/skwms1/wms.vegnett2',
666666
params: {
667667
'LAYERS': 'europaveg',
668668
'TRANSPARENT': 'true',
@@ -679,7 +679,7 @@ console.log("Start of metsis search map script:");
679679
baseLayer: false,
680680
visible: false,
681681
source: new ol.source.TileWMS({
682-
url: 'https://openwms.statkart.no/skwms1/wms.vegnett2?',
682+
url: 'https://wms.geonorge.no/skwms1/wms.vegnett2',
683683
params: {
684684
'LAYERS': 'riksveg',
685685
'TRANSPARENT': 'true',
@@ -697,7 +697,7 @@ console.log("Start of metsis search map script:");
697697
baseLayer: false,
698698
visible: false,
699699
source: new ol.source.TileWMS({
700-
url: 'https://openwms.statkart.no/skwms1/wms.vegnett2?',
700+
url: 'https://wms.geonorge.no/skwms1/wms.vegnett2',
701701
params: {
702702
'LAYERS': 'fylkesveg',
703703
'TRANSPARENT': 'true',
@@ -3306,7 +3306,7 @@ console.log("Start of metsis search map script:");
33063306
featureLayers['europaveg'] = new ol.layer.Tile({
33073307
title: 'europaveg',
33083308
source: new ol.source.TileWMS({
3309-
url: 'https://openwms.statkart.no/skwms1/wms.vegnett?',
3309+
url: 'https://wms.geonorge.no/skwms1/wms.vegnett2?',
33103310
params: {
33113311
'LAYERS': 'europaveg',
33123312
'TRANSPARENT': 'true',
@@ -3322,7 +3322,7 @@ console.log("Start of metsis search map script:");
33223322
title: 'riksveg',
33233323
displayInLayerSwitcher: true,
33243324
source: new ol.source.TileWMS({
3325-
url: 'https://openwms.statkart.no/skwms1/wms.vegnett?',
3325+
url: 'https://wms.geonorge.no/skwms1/wms.vegnett2?',
33263326
params: {
33273327
'LAYERS': 'riksveg',
33283328
'TRANSPARENT': 'true',
@@ -3337,7 +3337,7 @@ console.log("Start of metsis search map script:");
33373337
featureLayers['fylkesveg'] = new ol.layer.Tile({
33383338
title: 'fylkesveg',
33393339
source: new ol.source.TileWMS({
3340-
url: 'https://openwms.statkart.no/skwms1/wms.vegnett?',
3340+
url: 'https://wms.geonorge.no/skwms1/wms.vegnett2?',
33413341
params: {
33423342
'LAYERS': 'fylkesveg',
33433343
'TRANSPARENT': 'true',

0 commit comments

Comments
 (0)