From dee99b20cfa2297bdf2a4b64d855c9fff188164c Mon Sep 17 00:00:00 2001 From: Zach Garwood Date: Fri, 11 Aug 2023 12:25:06 -0500 Subject: [PATCH] Link model title to edit/augment page from index [MA-112] --- .../Controllers/Twill/BaseApiController.php | 104 ++++++++++++++---- app/Models/Api/Gallery.php | 1 - app/Providers/AppServiceProvider.php | 5 +- 3 files changed, 84 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/Twill/BaseApiController.php b/app/Http/Controllers/Twill/BaseApiController.php index 268673d3..281fa1f7 100644 --- a/app/Http/Controllers/Twill/BaseApiController.php +++ b/app/Http/Controllers/Twill/BaseApiController.php @@ -1,16 +1,5 @@ disableBulkPublish(); $this->disableCreate(); $this->disableDelete(); - $this->disableEdit(); $this->disablePermalink(); $this->disablePublish(); $this->disableRestore(); @@ -149,27 +142,90 @@ public function getApiData($scopes = [], $forcePagination = false, $appliedFilte protected function getIndexTableColumns(): TableColumns { - $table = parent::getIndexTableColumns(); - $after = $table->splice(0); - return $table - ->push(Boolean::make() + $columns = TableColumns::make(); + + if ($this->getIndexOption('publish')) { + $columns->add( + PublishStatus::make() + ->title(twillTrans('twill::lang.listing.columns.published')) + ->sortable() + ->optional() + ); + } + + if ($this->getIndexOption('showImage')) { + $columns->add( + Image::make() + ->field('thumbnail') + ->title(twillTrans('Image')) + ); + } + + if ($this->getIndexOption('feature') && $this->repository->isFillable('featured')) { + $columns->add( + FeaturedStatus::make() + ->title(twillTrans('twill::lang.listing.columns.featured')) + ); + } + + $columns->add( + Boolean::make() ->field('is_augmented') ->optional() - ->hide()) - ->push(Text::make() + ->hide() + ); + $columns->add( + Text::make() ->field('id') ->title('Datahub Id') ->optional() - ->hide()) - ->push(Text::make() + ->hide() + ); + $columns->add( + Text::make() ->field('source_updated_at') ->optional() - ->hide()) - ->push(Text::make() + ->hide() + ); + $columns->add( + Text::make() ->field('updated_at') ->optional() - ->hide()) - ->merge($after); + ->hide() + ); + $columns->add( + Text::make() + ->field($this->titleColumnKey) + ->linkCell(function (TwillModelContract $model) { + if ($model->is_augmented) { + $action = 'edit'; + $id = $model->getAugmentedModel()->id; + } else { + $action = 'augment'; + $id = $model->id; + } + return moduleRoute($this->moduleName, $this->routePrefix, $action, [$id]); + }) + ); + $columns = $columns->merge($this->additionalIndexTableColumns()); + + if ($this->getIndexOption('includeScheduledInList') && $this->repository->isFillable('publish_start_date')) { + $columns->add( + ScheduledStatus::make() + ->title(twillTrans('twill::lang.listing.columns.published')) + ->optional() + ); + } + + if ($this->moduleHas('translations') && count(getLocales()) > 1) { + $columns->add( + Languages::make() + ->title(twillTrans('twill::lang.listing.languages')) + ->optional() + ); + } + + return $columns; } public function getForm(TwillModelContract $model): Form diff --git a/app/Models/Api/Gallery.php b/app/Models/Api/Gallery.php index 1e719e91..12e3de85 100644 --- a/app/Models/Api/Gallery.php +++ b/app/Models/Api/Gallery.php @@ -4,7 +4,6 @@ use App\Helpers\StringHelpers; use App\Libraries\Api\Models\BaseApiModel; -use App\Presenters\Admin\GalleryPresenter; class Gallery extends BaseApiModel { diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 4f3b0d54..ecbb025c 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -6,6 +6,7 @@ use A17\Twill\View\Components\Navigation\NavigationLink; use App\Libraries\Api\Consumers\GuzzleApiConsumer; use App\Libraries\DamsImageService; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\URL; use Illuminate\Support\ServiceProvider; @@ -33,7 +34,9 @@ public function register(): void */ public function boot(): void { - URL::forceScheme('https'); + if (App::environment(['testing', 'production'])) { + URL::forceScheme('https'); + } TwillNavigation::addLink( NavigationLink::make()->forModule('exhibitions') );