-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ca5c77
commit 8ae2099
Showing
10 changed files
with
232 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Twill; | ||
|
||
use A17\Twill\Http\Controllers\Admin\ModuleController as BaseModuleController; | ||
use A17\Twill\Models\Contracts\TwillModelContract; | ||
use A17\Twill\Services\Forms\Fields\Input; | ||
use A17\Twill\Services\Forms\Fields\Select; | ||
use A17\Twill\Services\Forms\Fieldset; | ||
use A17\Twill\Services\Forms\Form; | ||
use A17\Twill\Services\Forms\Option; | ||
use A17\Twill\Services\Forms\Options; | ||
use A17\Twill\Services\Listings\TableColumns; | ||
use App\Http\Controllers\Twill\Columns\ApiRelation; | ||
use Illuminate\Support\Str; | ||
|
||
class StopController extends BaseModuleController | ||
{ | ||
protected $moduleName = 'stops'; | ||
|
||
protected function setUpController(): void | ||
{ | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Twill; | ||
|
||
use A17\Twill\Http\Requests\Admin\Request; | ||
|
||
class StopRequest extends Request | ||
{ | ||
public function rulesForCreate() | ||
{ | ||
return []; | ||
} | ||
|
||
public function rulesForUpdate() | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use A17\Twill\Models\Behaviors\HasPosition; | ||
use A17\Twill\Models\Behaviors\Sortable; | ||
use A17\Twill\Models\Model; | ||
use App\Models\Behaviors\HasApiRelations; | ||
|
||
class Stop extends Model implements Sortable | ||
{ | ||
use HasApiRelations; | ||
use HasPosition; | ||
|
||
protected $fillable = [ | ||
'title', | ||
'position', | ||
'artwork_id', | ||
'sound_id', | ||
]; | ||
|
||
public function audio() | ||
{ | ||
return $this->belongsToApi(\App\Models\Api\Sound::class, 'sound_id'); | ||
} | ||
|
||
public function object() | ||
{ | ||
return $this->belongsToApi(\App\Models\Api\Artwork::class, 'artwork_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Repositories; | ||
|
||
use A17\Twill\Repositories\ModuleRepository; | ||
use App\Models\Stop; | ||
|
||
class StopRepository extends ModuleRepository | ||
{ | ||
public function __construct(Stop $model) | ||
{ | ||
$this->model = $model; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
database/migrations/2023_08_16_151938_create_stops_tables.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateStopsTables extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('stops', function (Blueprint $table) { | ||
createDefaultTableFields($table); | ||
$table->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters