Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgarwood committed Jan 30, 2025
1 parent 40ff015 commit 5fedd3f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 111 deletions.
120 changes: 34 additions & 86 deletions app/Http/Controllers/Twill/ExperienceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,99 +2,47 @@

namespace App\Http\Controllers\Twill;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use A17\Twill\Services\Listings\Columns\NestedData;
use A17\Twill\Services\Listings\Columns\Presenter;
use A17\Twill\Services\Listings\Columns\Relation;
use A17\Twill\Services\Listings\TableColumns;
use App\Models\Experience;
use App\Models\InteractiveFeature;
use App\Models\Article;
use App\Repositories\CategoryRepository;

class ExperienceController extends \App\Http\Controllers\Twill\ModuleController
class ExperienceController extends BaseController
{
protected $moduleName = 'experiences';
protected $modelName = 'Experience';
protected $previewView = 'site.experienceDetail';

protected $indexOptions = [
'reorder' => true,
];

protected $indexColumns = [
'image' => [
'thumb' => true,
'variant' => [
'role' => 'image',
'crop' => 'default',
],
],
'isWebPublished' => [
'title' => 'Is web published?',
'field' => 'isWebPublished',
'present' => true,
],
'title' => [
'title' => 'Title',
'field' => 'title',
],
'interactiveFeatureTitle' => [ // Relation column
'title' => 'Grouping',
'relationship' => 'interactiveFeature',
'field' => 'title'
],
'experiences' => [
'title' => 'Slides',
'nested' => 'slides',
],
];

/**
* Intend to override the lines:
* thumbnail
* $value .= moduleRoute("experiences.slides", $this->routePrefix, 'index', [$item->id]);
*/
protected function getItemColumnData($item, $column)
protected function setUpController(): void
{
if (isset($column['thumb']) && $column['thumb']) {
if (isset($column['present']) && $column['present']) {
return [
'thumbnail' => $item->presentAdmin()->{$column['presenter']},
];
}
$variant = isset($column['variant']);
$params = $variant && isset($column['variant']['params'])
? $column['variant']['params']
: ['w' => 80, 'h' => 80, 'fit' => 'crop'];

$thumbnail_image = $item->defaultCmsImage($params);

return [
'thumbnail' => $thumbnail_image,
];
}

if (isset($column['nested']) && $column['nested']) {
$field = $column['nested'];
$nestedCount = $item->{$column['nested']}->count();
$value = '<a href="';
$value .= moduleRoute('experiences.slides', $this->routePrefix, 'index', [$item->id]);
$value .= '">' . $nestedCount . ' ' . (strtolower($nestedCount > 1
? Str::plural($column['title'])
: Str::singular($column['title']))) . '</a>';
} else {
$field = $column['field'];
$value = $item->{$field};
}

if (isset($column['relationship'])) {
$field = $column['relationship'] . ucfirst($column['field']);
$value = Arr::get($item, "{$column['relationship']}.{$column['field']}");
} elseif (isset($column['present']) && $column['present']) {
$value = $item->presentAdmin()->{$column['field']};
}
parent::setUpController();
$this->enableReorder();
$this->enableShowImage();
$this->setModelName('Experience');
$this->setModuleName('experiences');
$this->setPreviewView('site.experienceDetail');
}

return [
$field => $value,
];
protected function additionalIndexTableColumns(): TableColumns
{
$columns = TableColumns::make();
$columns->add(
Presenter::make()
->field('isWebPublished')
->title('Is web published?')
);
$columns->add(
Relation::make()
->relation('interactiveFeature')
->field('title')
->title('Grouping')
);
$columns->add(
NestedData::make()
->field('slides')
);

return $columns;
}

protected function getIndexTableMainFilters($items, $scopes = [])
Expand Down Expand Up @@ -155,7 +103,7 @@ protected function formData($request)
protected function indexData($request)
{
return [
'groupingsList' => InteractiveFeature::all()->pluck('title', 'id')
'groupingsList' => [], // InteractiveFeature::all()->pluck('title', 'id')
];
}

Expand Down
45 changes: 21 additions & 24 deletions app/Http/Controllers/Twill/InteractiveFeatureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,30 @@

namespace App\Http\Controllers\Twill;

use A17\Twill\Services\Listings\Columns\Presenter;
use A17\Twill\Services\Listings\TableColumns;
use App\Models\InteractiveFeature;

class InteractiveFeatureController extends \App\Http\Controllers\Twill\ModuleController
class InteractiveFeatureController extends BaseController
{
protected $moduleName = 'interactiveFeatures';

protected $indexColumns = [
'title' => [
'title' => 'Title',
'field' => 'title',
'sort' => true,
],
'updated_at' => [
'title' => 'Updated At',
'field' => 'updatedDate',
'present' => true,
],
];

protected $formWith = ['revisions'];

protected $defaultOrders = ['title' => 'desc'];

protected $indexOptions = [
'permalink' => false,
];
protected $filters = [];
protected function setUpController(): void
{
parent::setUpController();
$this->eagerLoadFormRelationCounts(['revisions']);
$this->setModuleName('interactiveFeatures');
}

protected function additionalIndexTableColumns(): TableColumns
{
$columns = TableColumns::make();
$columns->add(
Presenter::make()
->field('updatedDate')
->title('Updated At')
);

return $columns;
}

protected function getIndexTableMainFilters($items, $scopes = [])
{
Expand Down
11 changes: 10 additions & 1 deletion app/Repositories/InteractiveFeatureRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use A17\Twill\Repositories\Behaviors\HandleMedias;
use A17\Twill\Repositories\Behaviors\HandleRevisions;
use A17\Twill\Repositories\Behaviors\HandleSlugs;
use App\Models\InteractiveFeature;
use App\Models\Experience;
use App\Models\InteractiveFeature;
use Illuminate\Database\Eloquent\Builder;

class InteractiveFeatureRepository extends ModuleRepository
{
Expand All @@ -21,6 +22,14 @@ public function __construct(InteractiveFeature $model)
$this->model = $model;
}

public function order(Builder $query, array $orders = []): Builder
{
// Default sort by publish_start_date instead of created_at.
$orders['title'] ??= 'desc';
unset($orders['created_at']);
return parent::order($query, $orders);
}

public function getCountByStatusSlug(string $slug, array $scope = []): int
{
$scope = $scope + ['archived' => false];
Expand Down

0 comments on commit 5fedd3f

Please sign in to comment.