Skip to content

Commit

Permalink
Link model title to edit/augment page from index [MA-112]
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgarwood committed Aug 11, 2023
1 parent c70c5b6 commit dee99b2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 26 deletions.
104 changes: 80 additions & 24 deletions app/Http/Controllers/Twill/BaseApiController.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<?php

/**
* WIP.
*
* TODO: Refactor this controller so we don't have dependencies to update
* When we are updating the CMS.
*
* Right now the relationship between model and modelApi, redefinition of forms, and it's harcoded nature
* doesn't scale in a maintenance window.
*
*/

namespace App\Http\Controllers\Twill;

use A17\Twill\Facades\TwillPermissions;
Expand All @@ -21,6 +10,11 @@
use A17\Twill\Services\Forms\Fieldset;
use A17\Twill\Services\Forms\Form;
use A17\Twill\Services\Listings\Columns\Boolean;
use A17\Twill\Services\Listings\Columns\FeaturedStatus;
use A17\Twill\Services\Listings\Columns\Image;
use A17\Twill\Services\Listings\Columns\Languages;
use A17\Twill\Services\Listings\Columns\PublishStatus;
use A17\Twill\Services\Listings\Columns\ScheduledStatus;
use A17\Twill\Services\Listings\Columns\Text;
use A17\Twill\Services\Listings\Filters\BasicFilter;
use A17\Twill\Services\Listings\Filters\QuickFilter;
Expand Down Expand Up @@ -53,7 +47,6 @@ protected function setUpController(): void
$this->disableBulkPublish();
$this->disableCreate();
$this->disableDelete();
$this->disableEdit();
$this->disablePermalink();
$this->disablePublish();
$this->disableRestore();
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/Models/Api/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Helpers\StringHelpers;
use App\Libraries\Api\Models\BaseApiModel;
use App\Presenters\Admin\GalleryPresenter;

class Gallery extends BaseApiModel
{
Expand Down
5 changes: 4 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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')
);
Expand Down

0 comments on commit dee99b2

Please sign in to comment.