Skip to content

Commit

Permalink
Create Tour model, revise TourStop and Sound models [MA-115]
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgarwood authored and nikhiltri committed Aug 23, 2023
1 parent 01d09dc commit f618f1a
Show file tree
Hide file tree
Showing 35 changed files with 859 additions and 214 deletions.
86 changes: 86 additions & 0 deletions app/Http/Controllers/Twill/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\Http\Controllers\Twill;

use A17\Twill\Http\Controllers\Admin\ModuleController;
use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Services\Forms\Fields\Input;
use A17\Twill\Services\Forms\Fieldset;
use A17\Twill\Services\Forms\Form;
use A17\Twill\Services\Listings\Columns\Text;
use A17\Twill\Services\Listings\TableColumns;

class BaseController extends ModuleController
{
protected function setUpController(): void
{
$this->disablePermalink();
$this->enableSkipCreateModal();
}

protected function getIndexTableColumns(): TableColumns
{
$columns = parent::getIndexTableColumns();
$after = $columns->splice(1);
$columns->push(
Text::make()
->field('updated_at')
->optional()
->hide()
);
return $columns->merge($after);
}

public function getForm(TwillModelContract $model): Form
{
$title = Input::make()
->name('title')
->required();
if (in_array(\A17\Twill\Models\Behaviors\HasTranslation::class, class_uses_recursive($model::class))) {
$title->translatable();
}
$content = Form::make()
->add($title)
->merge($this->additionalFormFields($model));
return parent::getForm($model)->addFieldset(
Fieldset::make()
->title('Content')
->id('content')
->fields($content->toArray())
);
}

protected function additionalFormFields(TwillModelContract $model): Form
{
return new Form();
}

public function getSideFieldSets(TwillModelContract $model): Form
{
return parent::getSideFieldSets($model)
// For some reason, the side form will not render unless there is a
// field in the default Content fieldset. 🤷
->add(
Input::make()
->name('id')
->disabled()
->note('readonly')
)
->addFieldset(
Fieldset::make()
->id('timestamps')
->title('Timestamps')
->closed()
->fields([
Input::make()
->name('created_at')
->disabled()
->note('readonly'),
Input::make()
->name('updated_at')
->disabled()
->note('readonly'),
])
);
}
}
132 changes: 0 additions & 132 deletions app/Http/Controllers/Twill/StopController.php

This file was deleted.

175 changes: 175 additions & 0 deletions app/Http/Controllers/Twill/TourController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php

namespace App\Http\Controllers\Twill;

use A17\Twill\Services\Forms\Fields\Input;
use A17\Twill\Services\Forms\Fields\Medias;
use A17\Twill\Services\Forms\Fields\Select;
use A17\Twill\Services\Forms\Form;
use A17\Twill\Services\Forms\Option;
use A17\Twill\Services\Forms\Options;
use A17\Twill\Services\Listings\Columns\NestedData;
use A17\Twill\Services\Listings\Columns\Text;
use A17\Twill\Services\Listings\TableColumns;
use App\Http\Controllers\Twill\Columns\ApiRelation;
use Illuminate\Support\Str;

class TourController extends BaseController
{
protected $moduleName = 'tours';

private $galleries = [];

protected function setUpController(): void
{
parent::setUpController();
$this->enableReorder();
$this->setModelName('Tour');
}

protected function additionalIndexTableColumns(): TableColumns
{
return parent::additionalIndexTableColumns()
->add(
Text::make()
->field('description')
->optional()
->hide()
)
->add(
ApiRelation::make()
->field('gallery_id')
->title('Gallery')
->relation('gallery')
)
->add(
Text::make()
->field('selector_number')
->optional()
->hide()
)
->add(
ApiRelation::make()
->field('Sound_id')
->title('Audio')
->relation('audio')
->optional()
->hide()
)
->add(
Text::make()
->field('duration_in_minutes')
->title('Duration')
->optional()
)
->add(
NestedData::make()
->field('stops')
->title('Stops')
);
}

public function additionalFormFields($model): Form
{
return parent::additionalFormFields($model)
->add(
Input::make()
->name('image_url')
->label('Image')
->disabled()
->note('Coming Soon!')
)
->add(
Input::make()
->name('description')
->type('textarea')
->required()
->translatable()
)
->add(
Select::make()
->name('gallery_id')
->label('Gallery')
->placeholder('Select Gallery')
->options(
Options::make(
[Option::make('', 'Unset Gallery')] +
$this->galleryOptions()
)
)
)
->add(
Input::make()
->name('gallery_id')
)
->add(
Input::make()
->name('selector_number')
->type('number')
->required()
)
// ->add(
// Select::make()
// ->name('sound_id')
// ->label('Audio')
// ->translatable()
// ->placeholder('Select Audio')
// ->note('100 most recent')
// ->options(
// Options::make(
// $this->audioOptions()
// )
// ),
// )
->add(
Input::make()
->name('sound_id')
->label('Audio Id')
->translatable()
->required()
->note('Datahub Sound Id')
)
->add(
Input::make()
->name('duration')
->type('number')
->min(1)
->default(1)
->required()
->note('in minutes')
);
}

private function galleryOptions(): array
{
$options = [];
if (!$this->galleries) {
$this->galleries = \App\Models\Api\Gallery::query()
->orderBy('title')
->limit(100)
->get()
->sortBy([
['floor', 'asc'],
['number', 'asc'],
['title', 'asc'],
]);
}
foreach ($this->galleries as $gallery) {
$options[] = Option::make($gallery->id, $gallery);
}
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;
}
}
Loading

0 comments on commit f618f1a

Please sign in to comment.