Skip to content

Commit

Permalink
[TM-1625] Add cohort filter to dashboard (#645)
Browse files Browse the repository at this point in the history
* [TM-1620] add cohort field in v2 project table

* [TM-1625] add cohort filter to dashboard controllers

* [TM-1625] add command

* [TM-1625] change cohort values

---------

Co-authored-by: JORGE <[email protected]>
  • Loading branch information
cesarLima1 and egrojMonroy authored Jan 13, 2025
1 parent d38b053 commit 2d33e8f
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 8 deletions.
45 changes: 45 additions & 0 deletions app/Console/Commands/replicate_framework_cohort_command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Console\Commands;

use App\Models\V2\Projects\Project;
use Illuminate\Console\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;

class replicate_framework_cohort_command extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'replicate_framework_cohort_command';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command to copy framework_key to cohort';

/**
* Execute the console command.
*/
public function handle()
{
$projects = Project::all();
$output = new ConsoleOutput();
$progressBar = new ProgressBar($output, count($projects));
$progressBar->setFormat('Processing: %current% [%bar%] %percent:3s%%');
$progressBar->start();

foreach ($projects as $project) {
$framework_key = $project->framework_key;
$project->cohort = $framework_key;
$project->save();
$progressBar->advance();
}
$progressBar->finish();
}
}
8 changes: 7 additions & 1 deletion app/Helpers/TerrafundDashboardQueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public static function buildQueryFromRequest(Request $request)
$query->when(data_get($filters, 'filter.programmes'), function ($query, $programmes) {
$query->whereIn('v2_projects.framework_key', $programmes);
}, function ($query) {
$query->whereIn('v2_projects.framework_key', ['terrafund', 'terrafund-landscapes']);
$query->whereIn('v2_projects.framework_key', ['terrafund', 'terrafund-landscapes', 'enterprises']);
});

$query->when(data_get($filters, 'filter.cohort'), function ($query, $cohort) {
$query->where('v2_projects.cohort', $cohort);
}, function ($query) {
$query->whereIn('v2_projects.cohort', ['terrafund', 'terrafund-landscapes', 'enterprises']);
});

$query->when(data_get($filters, 'filter.landscapes'), function ($query, $landscapes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$delayedJob = DelayedJob::create();
Expand All @@ -35,6 +36,7 @@ public function __invoke(Request $request)
$landscapes,
$organisations,
$country,
$cohort,
$uuid,
$cacheParameter
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$delayedJob = DelayedJob::create();
Expand All @@ -35,6 +36,7 @@ public function __invoke(Request $request)
$landscapes,
$organisations,
$country,
$cohort,
$uuid,
$cacheParameter
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$delayedJob = DelayedJob::create();
Expand All @@ -35,6 +36,7 @@ public function __invoke(Request $request)
$landscapes,
$organisations,
$country,
$cohort,
$uuid,
$cacheParameter
);
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/V2/Dashboard/GetProjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$request = new Request([
Expand All @@ -33,6 +34,7 @@ public function __invoke(Request $request)
'landscapes' => $landscapes,
'organisationType' => $organisations,
'projectUuid' => $uuid,
'cohort' => $cohort,
],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$delayedJob = DelayedJob::create();
Expand All @@ -35,6 +36,7 @@ public function __invoke(Request $request)
$landscapes,
$organisations,
$country,
$cohort,
$uuid,
$cacheParameter
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$delayedJob = DelayedJob::create();
Expand All @@ -41,6 +42,7 @@ public function __invoke(Request $request)
$landscapes,
$organisations,
$country,
$cohort,
$uuid,
$cacheParameter
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$delayedJob = DelayedJob::create();
Expand All @@ -35,6 +36,7 @@ public function __invoke(Request $request)
$landscapes,
$organisations,
$country,
$cohort,
$uuid,
$cacheParameter
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$delayedJob = DelayedJob::create();
Expand All @@ -35,6 +36,7 @@ public function __invoke(Request $request)
$landscapes,
$organisations,
$country,
$cohort,
$uuid,
$cacheParameter
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(Request $request)
$landscapes = data_get($request, 'filter.landscapes', []);
$organisations = data_get($request, 'filter.organisationType', []);
$country = data_get($request, 'filter.country', '');
$cohort = data_get($request, 'filter.cohort', '');
$uuid = data_get($request, 'filter.projectUuid', '');

$delayedJob = DelayedJob::create();
Expand All @@ -35,6 +36,7 @@ public function __invoke(Request $request)
$landscapes,
$organisations,
$country,
$cohort,
$uuid,
$cacheParameter
);
Expand Down
5 changes: 5 additions & 0 deletions app/Jobs/Dashboard/RunActiveCountriesTableJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class RunActiveCountriesTableJob implements ShouldQueue

protected $country;

protected $cohort;

protected $uuid;

protected $cacheParameter;
Expand All @@ -44,6 +46,7 @@ public function __construct(
array $landscapes,
array $organisations,
string $country,
string $cohort,
string $uuid,
string $cacheParameter
) {
Expand All @@ -52,6 +55,7 @@ public function __construct(
$this->landscapes = $landscapes;
$this->organisations = $organisations;
$this->country = $country;
$this->cohort = $cohort;
$this->uuid = $uuid;
$this->cacheParameter = $cacheParameter;
}
Expand All @@ -68,6 +72,7 @@ public function handle(RunActiveCountriesTableService $runActiveCountriesTableSe
'landscapes' => $this->landscapes,
'organisationType' => $this->organisations,
'projectUuid' => $this->uuid,
'cohort' => $this->cohort,
],
]);

Expand Down
6 changes: 5 additions & 1 deletion app/Jobs/Dashboard/RunActiveProjectsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ class RunActiveProjectsJob implements ShouldQueue

protected $country;

protected $cohort;

protected $cacheParameter;

public function __construct(string $delayed_job_id, array $frameworks, array $landscapes, array $organisations, string $country, string $uuid, string $cacheParameter)
public function __construct(string $delayed_job_id, array $frameworks, array $landscapes, array $organisations, string $country, string $cohort, string $uuid, string $cacheParameter)
{
$this->delayed_job_id = $delayed_job_id;
$this->frameworks = $frameworks;
$this->landscapes = $landscapes;
$this->organisations = $organisations;
$this->country = $country;
$this->cohort = $cohort;
$this->uuid = $uuid;
$this->cacheParameter = $cacheParameter;
}
Expand All @@ -62,6 +65,7 @@ public function handle(RunActiveProjectsService $runActiveProjectsService)
'landscapes' => $this->landscapes,
'organisationType' => $this->organisations,
'projectUuid' => $this->uuid,
'cohort' => $this->cohort,
],
]
);
Expand Down
6 changes: 5 additions & 1 deletion app/Jobs/Dashboard/RunHectaresRestoredJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ class RunHectaresRestoredJob implements ShouldQueue

protected $country;

protected $cohort;

protected $cacheParameter;

public function __construct(string $delayed_job_id, array $frameworks, array $landscapes, array $organisations, string $country, string $uuid, string $cacheParameter)
public function __construct(string $delayed_job_id, array $frameworks, array $landscapes, array $organisations, string $country, string $cohort, string $uuid, string $cacheParameter)
{
$this->delayed_job_id = $delayed_job_id;
$this->frameworks = $frameworks;
$this->landscapes = $landscapes;
$this->organisations = $organisations;
$this->country = $country;
$this->cohort = $cohort;
$this->uuid = $uuid;
$this->cacheParameter = $cacheParameter;
}
Expand All @@ -62,6 +65,7 @@ public function handle(RunHectaresRestoredService $runHectaresRestoredService)
'landscapes' => $this->landscapes,
'organisationsType' => $this->organisations,
'projectUuid' => $this->uuid,
'cohort' => $this->cohort,
],
]
);
Expand Down
5 changes: 5 additions & 0 deletions app/Jobs/Dashboard/RunJobsCreatedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class RunJobsCreatedJob implements ShouldQueue

protected $country;

protected $cohort;

protected $uuid;

protected $cacheParameter;
Expand All @@ -44,6 +46,7 @@ public function __construct(
array $landscapes,
array $organisations,
string $country,
string $cohort,
string $uuid,
string $cacheParameter
) {
Expand All @@ -52,6 +55,7 @@ public function __construct(
$this->landscapes = $landscapes;
$this->organisations = $organisations;
$this->country = $country;
$this->cohort = $cohort;
$this->uuid = $uuid;
$this->cacheParameter = $cacheParameter;
}
Expand All @@ -68,6 +72,7 @@ public function handle(JobsCreatedService $jobsCreatedService)
'landscapes' => $this->landscapes,
'organisationType' => $this->organisations,
'projectUuid' => $this->uuid,
'cohort' => $this->cohort,
],
]);

Expand Down
6 changes: 5 additions & 1 deletion app/Jobs/Dashboard/RunTopTreesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ class RunTopTreesJob implements ShouldQueue

protected $country;

protected $cohort;

protected $cacheParameter;

public function __construct(string $delayed_job_id, array $frameworks, array $landscapes, array $organisations, string $country, string $uuid, string $cacheParameter)
public function __construct(string $delayed_job_id, array $frameworks, array $landscapes, array $organisations, string $country, string $cohort, string $uuid, string $cacheParameter)
{
$this->delayed_job_id = $delayed_job_id;
$this->frameworks = $frameworks;
$this->landscapes = $landscapes;
$this->organisations = $organisations;
$this->country = $country;
$this->cohort = $cohort;
$this->uuid = $uuid;
$this->cacheParameter = $cacheParameter;
}
Expand All @@ -62,6 +65,7 @@ public function handle(RunTopTreesService $runTopTreesService)
'landscapes' => $this->landscapes,
'organisationType' => $this->organisations,
'projectUuid' => $this->uuid,
'cohort' => $this->cohort,
],
]
);
Expand Down
6 changes: 5 additions & 1 deletion app/Jobs/Dashboard/RunTotalHeaderJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ class RunTotalHeaderJob implements ShouldQueue

protected $country;

protected $cohort;

protected $cacheParameter;

public function __construct(string $delayed_job_id, array $frameworks, array $landscapes, array $organisations, string $country, string $uuid, string $cacheParameter)
public function __construct(string $delayed_job_id, array $frameworks, array $landscapes, array $organisations, string $country, string $cohort, string $uuid, string $cacheParameter)
{
$this->delayed_job_id = $delayed_job_id;
$this->frameworks = $frameworks;
$this->landscapes = $landscapes;
$this->organisations = $organisations;
$this->country = $country;
$this->cohort = $cohort;
$this->uuid = $uuid;
$this->cacheParameter = $cacheParameter;
}
Expand All @@ -62,6 +65,7 @@ public function handle(RunTotalHeaderService $runTotalHeaderService)
'landscapes' => $this->landscapes,
'organisationType' => $this->organisations,
'projectUuid' => $this->uuid,
'cohort' => $this->cohort,
],
]
);
Expand Down
Loading

0 comments on commit 2d33e8f

Please sign in to comment.