From e76a60c6007037f8af7c0a15be648797fe30afd4 Mon Sep 17 00:00:00 2001 From: fsociety Date: Sun, 29 Sep 2024 16:51:35 +0200 Subject: [PATCH] close election --- app/Models/Election.php | 7 ++ ..._add_end_time_field_to_elections_table.php | 27 ++++++++ .../election/[Election:year].blade.php | 65 +++++++++++++------ 3 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 database/migrations/2024_09_29_143100_add_end_time_field_to_elections_table.php diff --git a/app/Models/Election.php b/app/Models/Election.php index d5c6b9d..e266986 100644 --- a/app/Models/Election.php +++ b/app/Models/Election.php @@ -7,4 +7,11 @@ use Illuminate\Database\Eloquent\Model; class Election extends Model { protected $guarded = []; + + protected function casts(): array + { + return [ + 'end_time' => 'datetime', + ]; + } } diff --git a/database/migrations/2024_09_29_143100_add_end_time_field_to_elections_table.php b/database/migrations/2024_09_29_143100_add_end_time_field_to_elections_table.php new file mode 100644 index 0000000..910a554 --- /dev/null +++ b/database/migrations/2024_09_29_143100_add_end_time_field_to_elections_table.php @@ -0,0 +1,27 @@ +timestamp('end_time')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('elections', function (Blueprint $table) { + // + }); + } +}; diff --git a/resources/views/pages/association/election/[Election:year].blade.php b/resources/views/pages/association/election/[Election:year].blade.php index 9dba1e0..6f50556 100644 --- a/resources/views/pages/association/election/[Election:year].blade.php +++ b/resources/views/pages/association/election/[Election:year].blade.php @@ -30,6 +30,7 @@ state(['election' => fn() => $election]); state(['plebs' => []]); state(['search' => '']); state(['signThisEvent' => '']); +state(['isNotClosed' => true]); mount(function () { $this->plebs = \App\Models\EinundzwanzigPleb::query() @@ -41,6 +42,9 @@ mount(function () { ->get() ->toArray(); $this->loadEvents(); + if ($this->election->end_time->isPast()) { + $this->isNotClosed = false; + } }); on([ @@ -49,9 +53,11 @@ on([ }, ]); -on(['echo:votes,.newVote' => function () { - $this->loadEvents(); -}]); +on([ + 'echo:votes,.newVote' => function () { + $this->loadEvents(); + } +]); updated([ 'search' => function ($value) { @@ -101,12 +107,22 @@ $loadEvents = function () { }; $vote = function ($pubkey, $type) { + if ($this->election->end_time->isPast()) { + $this->isNotClosed = false; + return; + } $note = new NostrEvent(); $note->setContent($pubkey . ',' . $type); $note->setKind(2121); $this->signThisEvent = $note->toJson(); }; +$checkElection = function () { + if ($this->election->end_time->isPast()) { + $this->isNotClosed = false; + } +}; + $signEvent = function ($event) { $note = new NostrEvent(); $note->setId($event['id']); @@ -131,7 +147,7 @@ $signEvent = function ($event) { @volt -
+
@php $positions = [ @@ -347,10 +363,17 @@ $signEvent = function ($event) { class="flex items-center justify-between before:absolute before:inset-0 before:backdrop-blur-md before:bg-gray-50/90 dark:before:bg-[#1B1B1B]/90 before:-z-10 border-b border-gray-200 dark:border-gray-700/60 px-4 sm:px-6 md:px-5 h-16">
- + @if($isNotClosed) + + @else + + @endif
- +
@@ -389,7 +412,8 @@ $signEvent = function ($event) {
-
+

{{ $position['title'] }}

@@ -405,18 +429,20 @@ $signEvent = function ($event) {
- @foreach($electionConfig->firstWhere('type', $type)['candidates'] as $c) -
-
- {{ $c['name'] }} - {{ $c['name'] }} + @foreach($electionConfig->firstWhere('type', $type)['candidates'] as $c) +
+
+ {{ $c['name'] }} + {{ $c['name'] }} +
-
- @endforeach + @endforeach
@@ -471,7 +497,8 @@ $signEvent = function ($event) { @foreach($loadedEvents as $event) -
{{ \Illuminate\Support\Str::limit($event['id'], 10) }}
+
{{ \Illuminate\Support\Str::limit($event['id'], 10) }}
{{ $event['kind'] }}