diff --git a/app/Http/Controllers/Twill/Columns/ApiRelation.php b/app/Http/Controllers/Twill/Columns/ApiRelation.php index 66169e98..59eea955 100644 --- a/app/Http/Controllers/Twill/Columns/ApiRelation.php +++ b/app/Http/Controllers/Twill/Columns/ApiRelation.php @@ -21,7 +21,7 @@ protected function getRenderValue(TwillModelContract $model): string if (null === $this->relation) { throw new ColumnMissingPropertyException('Relation column missing relation value: ' . $this->field); } - if ($augmentedModel = $model->getAugmentedModel()) { + if (method_exists($model, 'getAugmentedModel') && $augmentedModel = $model->getAugmentedModel()) { if ($relation = $augmentedModel->{$this->relation}()) { return $relation; } diff --git a/app/Http/Controllers/Twill/StopController.php b/app/Http/Controllers/Twill/StopController.php new file mode 100644 index 00000000..5bd2c8a0 --- /dev/null +++ b/app/Http/Controllers/Twill/StopController.php @@ -0,0 +1,132 @@ +disablePermalink(); + $this->enableReorder(); + } + + protected function additionalIndexTableColumns(): TableColumns + { + $table = parent::additionalIndexTableColumns(); + + $table->add( + ApiRelation::make() + ->field('artwork_id') + ->title('Object') + ->relation('object') + ); + $table->add( + ApiRelation::make() + ->field('sound_id') + ->title('Audio') + ->relation('audio') + ); + + return $table; + } + + public function getForm(TwillModelContract $stop): Form + { + $form = parent::getForm($stop); + $form->add( + Input::make() + ->name('title') + ); + $form->add( + Input::make() + ->name('artwork_id') + ->note('Datahub Id') + ); + $form->add( + Input::make() + ->name('sound_id') + ->note('Datahub Id') + ); + + return $form; + } + + public function getSideFieldSets(TwillModelContract $stop): Form + { + return parent::getSideFieldSets($stop) + // For some reason, the side form will not render unless there is a + // field in the default Content fieldset. + ->add( + Input::make() + ->name('title') + ->disabled() + ) + ->addFieldset( + Fieldset::make() + ->id('api_relations') + ->title('API Relations') + ->fields([ + Select::make() + ->name('artwork_id') + ->label('Object') + ->placeholder('Select Object') + ->note('100 most recent') + ->options( + Options::make( + $this->objectOptions() + ) + ), + Select::make() + ->name('sound_id') + ->label('Audio') + ->placeholder('Select Audio') + ->note('100 most recent') + ->options( + Options::make( + $this->audioOptions() + ) + ), + ]) + ); + } + + private function objectOptions(): array + { + $options = []; + $objects = \App\Models\Api\Artwork::query() + ->limit(100) + ->get() + ->sortBy('source_updated_at'); + foreach ($objects as $object) { + $options[] = Option::make($object->id, Str::words($object->title, 5)); + } + return $options; + } + + private function audioOptions(): array + { + $options = []; + $audios = \App\Models\Api\Sound::query() + ->limit(100) + ->get() + ->sortByDesc('source_updated_at'); + foreach ($audios as $audio) { + $options[] = Option::make($audio->id, Str::words($audio->title, 5)); + } + return $options; + } +} diff --git a/app/Http/Requests/Twill/StopRequest.php b/app/Http/Requests/Twill/StopRequest.php new file mode 100644 index 00000000..ef86181e --- /dev/null +++ b/app/Http/Requests/Twill/StopRequest.php @@ -0,0 +1,18 @@ +title - $this->artist_display"; + } } diff --git a/app/Models/Api/Sound.php b/app/Models/Api/Sound.php index c3f93c3b..c55733e2 100644 --- a/app/Models/Api/Sound.php +++ b/app/Models/Api/Sound.php @@ -20,8 +20,8 @@ public function getTypeAttribute() return 'sound'; } - public function getTitleSlugAttribute() + public function __toString(): string { - return StringHelpers::getUtf8Slug($this->title); + return $this->title; } } diff --git a/app/Models/Stop.php b/app/Models/Stop.php new file mode 100644 index 00000000..c68599da --- /dev/null +++ b/app/Models/Stop.php @@ -0,0 +1,31 @@ +belongsToApi(\App\Models\Api\Sound::class, 'sound_id'); + } + + public function object() + { + return $this->belongsToApi(\App\Models\Api\Artwork::class, 'artwork_id'); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index c465ea2f..95d09313 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -46,5 +46,8 @@ public function boot(): void TwillNavigation::addLink( NavigationLink::make()->title('Objects')->forModule('artworks') ); + TwillNavigation::addLink( + NavigationLink::make()->forModule('stops') + ); } } diff --git a/app/Repositories/StopRepository.php b/app/Repositories/StopRepository.php new file mode 100644 index 00000000..1f3c0bb6 --- /dev/null +++ b/app/Repositories/StopRepository.php @@ -0,0 +1,14 @@ +model = $model; + } +} diff --git a/database/migrations/2023_08_16_151938_create_stops_tables.php b/database/migrations/2023_08_16_151938_create_stops_tables.php new file mode 100644 index 00000000..5d8e7229 --- /dev/null +++ b/database/migrations/2023_08_16_151938_create_stops_tables.php @@ -0,0 +1,24 @@ +string('title')->nullable(); + $table->integer('position')->unsigned()->nullable(); + $table->string('artwork_id')->nullable()->comment('Datahub foreign key'); + $table->string('sound_id')->nullable()->comment('Datahub foreign key'); + }); + } + + public function down() + { + Schema::dropIfExists('stops'); + } +} diff --git a/routes/twill.php b/routes/twill.php index b457e808..153e6300 100644 --- a/routes/twill.php +++ b/routes/twill.php @@ -14,3 +14,5 @@ TwillRoutes::module('sounds'); Route::get('sounds/augment/{datahub_id}', [SoundController::class, 'augment'])->name('sounds.augment'); + +TwillRoutes::module('stops');