Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TM-1425] sort categories and add validation to missing slug #608

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions app/Helpers/RestorationByEcoregionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,16 @@ public static function getCategoryEcoRegion($value, ?bool $isExport = false)
$categoriesFromEcoRegion = [
'australasian' => [
'Southeast Australia temperate forests',
'Madeira-Tapajós moist forests',
'Tocantins/Pindare moist forests',
'Tapajós-Xingu moist forests',
'Mato Grosso seasonal forests',
'Mato Grosso seasonal forests, Xingu-Tocantins-Araguaia moist forests',
'Bahia coastal forests',
'Tonle Sap freshwater swamp forests',
'Southern Miombo woodlands',
'Palawan rain forests',
],
'afrotropical' => [
'Sinú Valley dry forests',
'Santa Marta montane forests',
'Atlantic mixed forests',
'Petén-Veracruz moist forests',
'Central American Atlantic moist forests',
'Petén-Veracruz moist forests, Central American Atlantic moist forests',
'Central American montane forests',
'Central American Atlantic moist forests, Central American montane forests',
'Northern Acacia-Commiphora bushlands and thickets',
'Southern Rift montane forest-grassland mosaic',
'Sierra Madre de Chiapas moist forests',
Expand All @@ -45,10 +38,46 @@ public static function getCategoryEcoRegion($value, ?bool $isExport = false)
'Central Zambezian Miombo woodlands',
'Ethiopian montane grasslands and woodlands',
'Central African mangroves',
'Southern Acacia-Commiphora bushlands and thickets',
'East African montane forests',
'Eastern Arc forests',
'Guinean mangroves',
'Eastern Zimbabwe montane forest-grassland mosaic',
'Somali Acacia-Commiphora bushlands and thickets',
'Ethiopian montane forests',
'Inner Niger Delta flooded savanna',
'Western Guinean lowland forests',
'Eastern Miombo woodlands',
'Ethiopian montane forests, Ethiopian montane grasslands and woodlands',
'Cross-Sanaga-Bioko coastal forests',
'Zambezian and Mopane woodlands',
'Madagascar lowland forests',
'Madagascar subhumid forests',
'Southern Congolian forest-savanna mosaic',
'East African montane forests',
'East African montane forests, Northern Acacia-Commiphora bushlands and thickets',
'Albertine Rift montane forests, Lake',
],
'paleartic' => [
'southern-zanzibar-inhambane-coastal-forest-mosaic',
'Southwest Iberian Mediterranean sclerophyllous and mixed forests',
'Narmada Valley dry deciduous forests',
'East African montane moorlands',
'Cameroonian Highlands forests',
'Celtic broadleaf forests',
'Atlantic Coast restingas',
],
'neotropical' => [
'Sinú Valley dry forests',
'Santa Marta montane forests',
'Petén-Veracruz moist forests',
'Central American Atlantic moist forests',
'Petén-Veracruz moist forests, Central American Atlantic moist forests',
'Central American montane forests',
'Central American Atlantic moist forests, Central American montane forests',
'Cross-Niger transition forests',
'Atlantic Coast restingas',
],

];
$formatedValue = [];
foreach ($categoriesFromEcoRegion as $category => $values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function __invoke(EntityModel $entity, string $slug)
'relation_name' => 'hectaresIndicator',
],
];
if (! isset($slugMappings[$slug])) {
return response()->json([]);
}

try {
return SitePolygon::whereHas($slugMappings[$slug]['relation_name'], function ($query) use ($slug) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function __invoke(EntityModel $entity, string $slug)
'indicator_title' => 'Hectares Under Restoration By WWF EcoRegion',
],
];
if (! isset($slugMappings[$slug])) {
return response()->json([]);
}

try {
$polygonUuids = SitePolygon::whereHas('site', function ($query) use ($entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class IndicatorEntitySlugExportController extends Controller
{
public function __invoke(EntityModel $entity, string $slug)
{
if (! isset($slugMappings[$slug])) {
return response()->json(['message' => 'Indicator not found'], 404);
}

return $this->exportCsv($entity, $slug);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function __invoke(Request $request, string $slug)
try {
$requestData = $request->all();
$binary_data = Redis::get('run:indicator|'.$slug.'|'.json_encode($requestData['uuids']));
Log::info($binary_data);
if (! $binary_data) {
$delayedJob = DelayedJob::create();
$job = new RunIndicatorAnalysisJob(
Expand Down
Loading