Skip to content

Commit

Permalink
Merge pull request #103 from stats4sd/custom-indicators
Browse files Browse the repository at this point in the history
Custom indicators
  • Loading branch information
ciara-mc authored Dec 18, 2024
2 parents 51500e3 + c498b47 commit bc974ed
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 412 deletions.
64 changes: 0 additions & 64 deletions app/Imports/CustomIndicatorChoicesImport.php

This file was deleted.

89 changes: 0 additions & 89 deletions app/Imports/CustomIndicatorSurveyImport.php

This file was deleted.

36 changes: 0 additions & 36 deletions app/Imports/CustomIndicatorWorkbookImport.php

This file was deleted.

13 changes: 9 additions & 4 deletions app/Imports/XlsformTemplate/XlsformTemplateChoiceListImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ public function model(array $row): ChoiceList
{
$row = collect($row);

$localisable = match ($row['localisable']) {
'true', 'yes', 'TRUE', 'YES', 'Yes', 'True', '1', 1, true => true,
default => false,
};
if (isset($row['localisable'])) {
$localisable = match ($row['localisable']) {
'true', 'yes', 'TRUE', 'YES', 'Yes', 'True', '1', 1, true => true,
default => false,
};
}
else {
$localisable = false;
}

return new ChoiceList([
'template_id' => $this->xlsformTemplate->id,
Expand Down
68 changes: 29 additions & 39 deletions app/Livewire/CustomIndicators.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,6 @@ public function mount()
$this->team = Team::find(auth()->user()->latestTeam->id);
}

public function downloadHouseholdTemplate()
{
$hasHousehold = LocalIndicator::query()
->where('team_id', $this->team->id)
->where('is_custom', 1)
->where('survey', 'household')
->exists();

if (!$hasHousehold) {
$this->addError('validation', 'No confirmed custom indicators assigned to the Household survey.');
return;
}

$currentDate = Carbon::now()->format('Y-m-d');
$filename = "HOLPA - {$this->team->name} - Custom Indicator Household Template - {$currentDate}.xlsx";
return Excel::download(new CustomIndicatorExport($this->team, 'household'), $filename);
}

public function downloadFieldworkTemplate()
{
$hasFieldwork = LocalIndicator::query()
->where('team_id', $this->team->id)
->where('is_custom', 1)
->where('survey', 'fieldwork')
->exists();

if (!$hasFieldwork) {
$this->addError('validation', 'No confirmed custom indicators assigned to the Fieldwork survey.');
return;
}

$currentDate = Carbon::now()->format('Y-m-d');
$filename = "HOLPA - {$this->team->name} - Custom Indicator Fieldwork Template - {$currentDate}.xlsx";
return Excel::download(new CustomIndicatorExport($this->team, 'fieldwork'), $filename);
}

public function table(Table $table): Table
{
return $table
Expand All @@ -74,7 +38,7 @@ public function table(Table $table): Table
TextColumn::make('name')->label(''),
CheckboxColumn::make('is_custom')->label('Confirm and add'),
SelectColumn::make('survey')
->label('Survey')
->label('Select the survey')
->disabled(fn ($record) => $record->is_custom !== 1)
->options([
'household' => 'Household',
Expand All @@ -84,15 +48,41 @@ public function table(Table $table): Table
->paginated(false)
->emptyStateHeading('No custom indicators');
}



private function hasCustomIndicatorsWithSurvey(string $survey): bool
{
return LocalIndicator::query()
->where('team_id', $this->team->id)
->where('is_custom', 1)
->where('survey', $survey)
->exists();
}

private function hasUnassignedCustomIndicators(): bool
{
return $this->team->localIndicators()->where('is_custom', 1)->whereNull('survey')->exists();
}

public function resetIndicators()
{
// Reset the 'is_custom' flag to 0 for all local indicators belonging to this team
$this->team->localIndicators()->update(['is_custom' => 0]);
}

public function downloadHouseholdTemplate()
{
$currentDate = Carbon::now()->format('Y-m-d');
$filename = "HOLPA - {$this->team->name} - Custom Indicator Household Template - {$currentDate}.xlsx";
return Excel::download(new CustomIndicatorExport($this->team, 'household'), $filename);
}

public function downloadFieldworkTemplate()
{
$currentDate = Carbon::now()->format('Y-m-d');
$filename = "HOLPA - {$this->team->name} - Custom Indicator Fieldwork Template - {$currentDate}.xlsx";
return Excel::download(new CustomIndicatorExport($this->team, 'fieldwork'), $filename);
}

public function render()
{
return view('livewire.custom-indicators');
Expand Down
Loading

0 comments on commit bc974ed

Please sign in to comment.