Skip to content

Commit

Permalink
Merge pull request #139 from stats4sd/post-demo-fixes
Browse files Browse the repository at this point in the history
Post demo fixes
  • Loading branch information
ciara-mc authored Jan 7, 2025
2 parents 91554d6 + e973c45 commit 68aafae
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public static function getNavigationItems(): array

$baseRoute = static::getUrl('index');

$navItems = LocationLevel::all()
$navItems = LocationLevel::query()
->orderBy('parent_id')
->get()
->map(function ($level) use ($baseRoute) {
return NavigationItem::make(Str::plural($level->name))
->url($baseRoute . '/' . $level->slug)
Expand Down Expand Up @@ -96,6 +98,7 @@ public static function table(Table $table): Table
->boolean()
->sortable(),
])
->defaultSort('parent_id', 'asc')
->filters([
//
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace App\Filament\App\Clusters\LocationLevels\Resources\LocationLevelResource\RelationManagers;

use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Filament\Resources\RelationManagers\RelationManager;

class LocationsRelationManager extends RelationManager
{
Expand All @@ -22,18 +22,30 @@ public static function getTitle(Model $ownerRecord, string $pageClass): string

public function isReadOnly(): bool
{
return true;
return false;
}

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('parent_id')
->label(fn () => $this->getOwnerRecord()->parent->name)
->relationship('parent', 'name', function ($query) {
$parent_location_level_id = $this->getOwnerRecord()->parent->id;
$query->where('location_level_id', $parent_location_level_id); })
->required()
->searchable()
->preload()
->visible(fn () => $this->getOwnerRecord()->parent !== null),
Forms\Components\TextInput::make('name')
->hintIcon('heroicon-o-information-circle')
->required()
->maxLength(255),
]);
Forms\Components\TextInput::make('code')
->required()
->maxLength(255),
])
->columns(1);
}

public function table(Table $table): Table
Expand All @@ -44,6 +56,7 @@ public function table(Table $table): Table
if ($this->getOwnerRecord()->parent) {
$columns[] = Tables\Columns\TextColumn::make('parent.name')->label(fn () => $this->getOwnerRecord()->parent->name)->sortable();
$filters[] = Tables\Filters\SelectFilter::make('parent')
->label(fn () => $this->getOwnerRecord()->parent->name)
->relationship('parent', 'name', fn (Builder $query) => $query->where('location_level_id', $this->getOwnerRecord()->parent->id));
}

Expand All @@ -58,7 +71,8 @@ public function table(Table $table): Table
->columns($columns)
->filters($filters)
->headerActions([
Tables\Actions\CreateAction::make(),
Tables\Actions\CreateAction::make()
->label(fn () => 'Add new ' . $this->getOwnerRecord()->name),
])
->actions([
Tables\Actions\EditAction::make(),
Expand Down
12 changes: 6 additions & 6 deletions app/Filament/App/Pages/LISP.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function markCompleteAction(): Action
->label('MARK AS COMPLETE')
->extraAttributes(['class' => 'buttona mx-4 inline-block'])
->action(function () {
$team = Team::find(auth()->user()->latestTeam->id);
$team->lisp_progress = 'complete';
$team->save();
Team::find(auth()->user()->latestTeam->id)->update([
'lisp_complete' => 1,
]);

$this->dispatch('refreshPage');
});
Expand All @@ -49,9 +49,9 @@ public function markIncompleteAction(): Action
->label('MARK AS INCOMPLETE')
->extraAttributes(['class' => 'buttona mx-4 inline-block'])
->action(function () {
$team = Team::find(auth()->user()->latestTeam->id);
$team->lisp_progress = 'not_started';
$team->save();
Team::find(auth()->user()->latestTeam->id)->update([
'lisp_complete' => 0,
]);

$this->dispatch('refreshPage');
});
Expand Down
12 changes: 6 additions & 6 deletions app/Filament/App/Pages/PlaceAdaptations.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function markCompleteAction(): Action
->label('MARK AS COMPLETE')
->extraAttributes(['class' => 'buttona mx-4 inline-block'])
->action(function () {
$team = Team::find(auth()->user()->latestTeam->id);
$team->pba_progress = 'complete';
$team->save();
Team::find(auth()->user()->latestTeam->id)->update([
'pba_complete' => 1,
]);

$this->dispatch('refreshPage');
});
Expand All @@ -50,9 +50,9 @@ public function markIncompleteAction(): Action
->label('MARK AS INCOMPLETE')
->extraAttributes(['class' => 'buttona mx-4 inline-block'])
->action(function () {
$team = Team::find(auth()->user()->latestTeam->id);
$team->pba_progress = 'not_started';
$team->save();
Team::find(auth()->user()->latestTeam->id)->update([
'pba_complete' => 0,
]);

$this->dispatch('refreshPage');
});
Expand Down
12 changes: 6 additions & 6 deletions app/Filament/App/Pages/Sampling.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function markCompleteAction(): Action
->label('MARK AS COMPLETE')
->extraAttributes(['class' => 'buttona mx-4 inline-block'])
->action(function () {
$team = Team::find(auth()->user()->latestTeam->id);
$team->sampling_progress = 'complete';
$team->save();
Team::find(auth()->user()->latestTeam->id)->update([
'sampling_complete' => 1,
]);

$this->dispatch('refreshPage');
});
Expand All @@ -50,9 +50,9 @@ public function markIncompleteAction(): Action
->label('MARK AS INCOMPLETE')
->extraAttributes(['class' => 'buttona mx-4 inline-block'])
->action(function () {
$team = Team::find(auth()->user()->latestTeam->id);
$team->sampling_progress = 'not_started';
$team->save();
Team::find(auth()->user()->latestTeam->id)->update([
'sampling_complete' => 0,
]);

$this->dispatch('refreshPage');
});
Expand Down
1 change: 0 additions & 1 deletion app/Filament/App/Pages/SurveyDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class SurveyDashboard extends Page
public function mount(): void
{
$this->team = Team::find(auth()->user()->latestTeam->id);
ray($this->team->sampling_progress);
}

public function getMaxContentWidth(): MaxWidth
Expand Down
12 changes: 6 additions & 6 deletions app/Filament/App/Pages/SurveyLanguages.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function markCompleteAction(): Action
->label('MARK AS COMPLETE')
->extraAttributes(['class' => 'buttona mx-4 inline-block'])
->action(function () {
$team = Team::find(auth()->user()->latestTeam->id);
$team->languages_progress = 'complete';
$team->save();
Team::find(auth()->user()->latestTeam->id)->update([
'languages_complete' => 1,
]);

$this->dispatch('refreshPage');
});
Expand All @@ -50,9 +50,9 @@ public function markIncompleteAction(): Action
->label('MARK AS INCOMPLETE')
->extraAttributes(['class' => 'buttona mx-4 inline-block'])
->action(function () {
$team = Team::find(auth()->user()->latestTeam->id);
$team->languages_progress = 'not_started';
$team->save();
Team::find(auth()->user()->latestTeam->id)->update([
'languages_complete' => 0,
]);

$this->dispatch('refreshPage');
});
Expand Down
58 changes: 57 additions & 1 deletion app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Models\Language;
use App\Models\Holpa\LocalIndicator;
use App\Models\SampleFrame\Farm;
use App\Models\SampleFrame\Location;
Expand All @@ -10,13 +11,16 @@
use App\Models\Xlsforms\ChoiceList;
use App\Models\Xlsforms\ChoiceListEntry;
use App\Models\Xlsforms\Xlsform;
use App\Models\XlsformTemplates\ChoiceList;
use App\Models\XlsformTemplates\ChoiceListEntry;
use App\Models\XlsformTemplates\XlsformTemplate;
use App\Models\Xlsforms\XlsformModule;
use App\Models\Xlsforms\XlsformModuleVersion;
use App\Models\Xlsforms\XlsformTemplate;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
Expand Down Expand Up @@ -186,4 +190,56 @@ public function getXlsformFwModuleVersionAttribute()
}
return null;
}

public function getLispProgressAttribute()
{
if ($this->lisp_complete === 1) {
return 'complete';
}

return $this->localIndicators()->exists() ? 'in_progress' : 'not_started';
}

public function getSamplingProgressAttribute()
{
if ($this->sampling_complete === 1) {
return 'complete';
}

return $this->locationLevels()->exists() ? 'in_progress' : 'not_started';
}

public function getLanguagesProgressAttribute()
{
if ($this->languages_complete === 1) {
return 'complete';
}

// teams have English as a locale as default, check for others
$english_language_id = Language::where('name', 'English')->value('id');

$hasAddedLocales = $this->locales()
->where('language_id', '!=', $english_language_id)
->exists();

return $hasAddedLocales ? 'in_progress' : 'not_started';
}

public function getPbaProgressAttribute()
{
if ($this->pba_complete === 1) {
return 'complete';
}

if (
$this->time_frame !== null ||
$this->diet_diversity_module_version_id !== null ||
$this->choiceListEntries()->exists()
) {
return 'in_progress';
}

return 'not_started';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
DB::table('teams')->update([
'lisp_progress' => DB::raw("IF(lisp_progress = 'complete', 1, 0)"),
'sampling_progress' => DB::raw("IF(sampling_progress = 'complete', 1, 0)"),
'languages_progress' => DB::raw("IF(languages_progress = 'complete', 1, 0)"),
'pba_progress' => DB::raw("IF(pba_progress = 'complete', 1, 0)"),
]);

Schema::table('teams', function (Blueprint $table) {
$table->renameColumn('lisp_progress', 'lisp_complete');
$table->renameColumn('sampling_progress', 'sampling_complete');
$table->renameColumn('languages_progress', 'languages_complete');
$table->renameColumn('pba_progress', 'pba_complete');
});

Schema::table('teams', function (Blueprint $table) {
$table->boolean('lisp_complete')->default(false)->change();
$table->boolean('sampling_complete')->default(false)->change();
$table->boolean('languages_complete')->default(false)->change();
$table->boolean('pba_complete')->default(false)->change();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};
2 changes: 1 addition & 1 deletion resources/views/filament/app/pages/lisp.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<!-- Footer -->
<div class="completebar">
@if(auth()->user()->latestTeam->lisp_progress === 'complete')
@if(auth()->user()->latestTeam->lisp_complete === 1)
<div class="mb-6 mx-auto md:mr-24 md:ml-0 md:inline-block block text-green ">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 inline " fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<!-- Footer -->
<div class="completebar">
@if(auth()->user()->latestTeam->pba_progress === 'complete')
@if(auth()->user()->latestTeam->pba_complete === 1)
<div class="mb-6 mx-auto md:mr-24 md:ml-0 md:inline-block block text-green ">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 inline " fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filament/app/pages/sampling.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<!-- Footer -->
<div class="completebar">
@if(auth()->user()->latestTeam->sampling_progress === 'complete')
@if(auth()->user()->latestTeam->sampling_complete === 1)
<div class="mb-6 mx-auto md:mr-24 md:ml-0 md:inline-block block text-green ">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 inline " fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<!-- Footer -->
<div class="completebar">
@if(auth()->user()->latestTeam->languages_progress === 'complete')
@if(auth()->user()->latestTeam->languages_complete === 1)
<div class="mb-6 mx-auto md:mr-24 md:ml-0 md:inline-block block text-green ">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 inline " fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/cover-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="flex flex-col lg:flex-row space-y-6 lg:space-y-0 lg:space-x-8 w-full items-center lg:items-stretch mt-10 lg:mt-16 pb-8">
<div class="flex-grow max-w-3xl">
<h2 class="text-white text-5xl mb-2 lg:mb-4 font-extralight" style="letter-spacing: 0.3em;">HOLPA</h3>
<h1 class="text-hyellow text-2xl sm:text-3xl lg:text-5xl mb-2 lg:mb-4">Holistic Localised Performance Assessment</h1>
<h1 class="text-hyellow text-2xl sm:text-3xl lg:text-5xl mb-2 lg:mb-4">Holistic Localised Performance Assessment for Agroecology</h1>
</div>


Expand Down

0 comments on commit 68aafae

Please sign in to comment.