From c3be582c061c039993817d8a932684175f53e15f Mon Sep 17 00:00:00 2001 From: Orestis Moresis Date: Fri, 17 Mar 2023 13:13:06 +0200 Subject: [PATCH] improve wfd external data --- public/js/extras.js | 5 +++- public/js/more-info.js | 2 +- public/js/sidebar.js | 2 +- src/Controllers/DataController.php | 18 +++++++++--- src/Data/request_external_data.php | 44 ------------------------------ src/Services/WfdAPI.php | 3 +- 6 files changed, 21 insertions(+), 53 deletions(-) delete mode 100644 src/Data/request_external_data.php diff --git a/public/js/extras.js b/public/js/extras.js index 4499e15..1da1af7 100644 --- a/public/js/extras.js +++ b/public/js/extras.js @@ -242,6 +242,7 @@ function getHabitat(layerCode) { function moreInfoPopup(props) { let title; + if (props.hasOwnProperty('code')) { title = `${props.code} — ${props.name}`; } else { @@ -253,8 +254,10 @@ function moreInfoPopup(props) { props.entity_group = 'POSEIDON'; } - if (typeof props.ctStationCode !== 'undefined') + if (typeof props.ctStationCode !== 'undefined') { title = `WFD — ${props.ctStationCode}`; + props.category = 'coastal_wfd'; + } Alpine.store('entity', props); getPagePartial('more-info').then(content => { diff --git a/public/js/more-info.js b/public/js/more-info.js index 84cdfff..80481ba 100644 --- a/public/js/more-info.js +++ b/public/js/more-info.js @@ -28,7 +28,7 @@ function moreInfo() { search() { this.drawDataChart(); // check if entity has an external source - if (this.$store.entity.hasOwnProperty('ctStationCode')) { + if (this.$store.entity.category === 'coastal_wfd') { requestExternalData(this.did, this.cid, this.date.from, this.date.to, this.entityGroup, this.entityId); } else { requestEntityData(this.did, this.cid, this.date.from, this.date.to, this.entityGroup, this.entityId); diff --git a/public/js/sidebar.js b/public/js/sidebar.js index 6ca75f8..a6b75a7 100644 --- a/public/js/sidebar.js +++ b/public/js/sidebar.js @@ -223,7 +223,7 @@ function requestEntityData(desc, crit, from, to, entityGroup, entityId) { */ function requestExternalData(desc, crit, from, to, entityGroup, entityId) { console.debug('requesting external data'); - const url = BASE_URL + `/src/data/request_external_data.php?entityGroup=${entityGroup}&entityId=${entityId}&dateFrom=${from}&dateTo=${to}&critId=${crit}`; + const url = BASE_URL + `/data/external/${entityGroup}/${entityId}`; fetch(url) .then(res => { return res.blob(); diff --git a/src/Controllers/DataController.php b/src/Controllers/DataController.php index cef3261..53bb35f 100644 --- a/src/Controllers/DataController.php +++ b/src/Controllers/DataController.php @@ -1,6 +1,7 @@ getToken(); - $stations = $p->getStations(); + // $stations = $p->getStations(); + $samples = $p->getStationSamples($platform); + $sampleIds = []; + + foreach ($samples as $sample) { + $sampleIds[] = $sample->id; + } + + $data = $p->getData($sampleIds); + /* print_r($data); */ + /* $json = json_encode($stations); */ + echo json_encode($data, JSON_PRETTY_PRINT); - $json = json_encode($stations); - echo convertToGeoJSON($json, 'ctStationDecimalLongitude', 'ctStationDecimalLatitude'); break; default: - /* header($_SERVER['SERVER_PROTOCOL'].'404 Not Found'); */ + header($_SERVER['SERVER_PROTOCOL'].'400 Bad Request'); break; } diff --git a/src/Data/request_external_data.php b/src/Data/request_external_data.php deleted file mode 100644 index 7134b73..0000000 --- a/src/Data/request_external_data.php +++ /dev/null @@ -1,44 +0,0 @@ -getToken(); -$stations = $p->getStations(); -$samples = $p->getStationSamples(); -$sampleIds = []; -foreach ($samples as $sample) { - $sampleIds[] = $sample->id; -} - -$data = $p->getData($sampleIds); -/* print_r($data); */ -/* $json = json_encode($stations); */ -echo json_encode($data); -/* echo convertToGeoJSON($json, 'ctStationDecimalLongitude', 'ctStationDecimalLatitude'); */ -/* $request = new DataRequest($_GET, $user_id); */ -/* echo $request->insert_to_db(); */ -/* */ -?> diff --git a/src/Services/WfdAPI.php b/src/Services/WfdAPI.php index c0d5d22..a841450 100644 --- a/src/Services/WfdAPI.php +++ b/src/Services/WfdAPI.php @@ -54,9 +54,8 @@ class WfdAPI extends API { } - public function getStationSamples() { + public function getStationSamples($station_id) { $endpoint = "/coastal-trans-samples"; - $station_id = 16; $data = array( "coastalTransStationId.equals" => $station_id );