Browse Source

improve wfd external data

master
o.moresis 2 years ago
parent
commit
c3be582c06
  1. 5
      public/js/extras.js
  2. 2
      public/js/more-info.js
  3. 2
      public/js/sidebar.js
  4. 18
      src/Controllers/DataController.php
  5. 44
      src/Data/request_external_data.php
  6. 3
      src/Services/WfdAPI.php

5
public/js/extras.js

@ -242,6 +242,7 @@ function getHabitat(layerCode) { @@ -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) { @@ -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 => {

2
public/js/more-info.js

@ -28,7 +28,7 @@ function moreInfo() { @@ -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);

2
public/js/sidebar.js

@ -223,7 +223,7 @@ function requestEntityData(desc, crit, from, to, entityGroup, entityId) { @@ -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();

18
src/Controllers/DataController.php

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
<?php
namespace MSFD\Controllers;
use MSFD\Services\PoseidonAPI;
use MSFD\Services\WfdAPI;
class DataController {
@ -32,13 +33,22 @@ class DataController { @@ -32,13 +33,22 @@ class DataController {
require __DIR__.'/../Services/WfdAPI.php';
$p = new WfdAPI();
$p->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;
}

44
src/Data/request_external_data.php

@ -1,44 +0,0 @@ @@ -1,44 +0,0 @@
<?php
/**
* Requests external data from other APIs such as Poseidon or WfdAPI
*
*/
session_start();
$user_groups = implode(",", $_SESSION['usergroups']);
if ($user_groups < 4) {
header('HTTP/1.0 401 Unauthorized');
exit();
}
/* require_once(__DIR__ . '/data_request.php'); */
require_once(__DIR__ . '/../wfd_api.php');
//require_once(__DIR__ . '/../lib/common.php');
// Process all of the get values
// TODO: Clean below variables
/* $bodyId = $_GET['bodyId']; */
/* $entity_type = $_GET['entityGroup']; */
/* $entity_id = $_GET['entityId']; */
/* $criterias = $_GET['critId']; */
/* $dateFrom = $_GET['dateFrom']; */
/* $dateTo = $_GET['dateTo']; */
/* $user_id = $_SESSION['userid']; */
/* $user_groups = implode(",", $_SESSION['usergroups']); */
/* $files_list = array(); */
/* $downloadable = array(); */
$p = new WfdAPI();
$p->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(); */
/* */
?>

3
src/Services/WfdAPI.php

@ -54,9 +54,8 @@ class WfdAPI extends API { @@ -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
);

Loading…
Cancel
Save