8000 added support for nested module on the dashboard by zeezo887 · Pull Request #2547 · area17/twill · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

added support for nested module on the dashboard #2547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions src/Http/Controllers/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,17 @@ public function search(Request $request): Collection
$date = $item->created_at->toIso8601String();
}

$parentRelationship = $module['parentRelationship'] ?? null;
$parent = $item->$parentRelationship;

return [
'id' => $item->id,
'href' => moduleRoute($module['name'], $module['routePrefix'] ?? null, 'edit', $item->id),
'href' => moduleRoute(
$module['name'],
$module['routePrefix'] ?? null,
'edit',
array_merge($parentRelationship ? [$parent->id] : [], [$item->id])
),
'thumbnail' => method_exists($item, 'defaultCmsImage') ? $item->defaultCmsImage(['w' => 100, 'h' => 100]) : null,
'published' => $item->published,
'activity' => twillTrans('twill::lang.dashboard.search.last-edit'),
Expand Down Expand Up @@ -510,19 +518,21 @@ private function getShortcuts(Collection $modules): Collection
'singular' => $module['label_singular'] ?? Str::singular($module['name']),
];

$isNestedModule = Str::contains($module['name'], '.');

return [
'label' => ucfirst($moduleOptions['label']),
'singular' => ucfirst($moduleOptions['singular']),
'number' => $moduleOptions['count'] ? $repository->getCountByStatusSlug(
'all',
$module['countScope'] ?? []
) : null,
'url' => moduleRoute(
'url' => !$isNestedModule ? moduleRoute(
$module['name'],
$module['routePrefix'] ?? null,
'index'
),
'createUrl' => $moduleOptions['create'] ? moduleRoute(
) : null,
'createUrl' => ($moduleOptions['create'] && !$isNestedModule) ? moduleRoute(
$module['name'],
$module['routePrefix'] ?? null,
'index',
Expand All @@ -544,19 +554,40 @@ private function getDrafts(Collection $modules): Collection
if ($repository->hasBehavior('revisions')) {
$query->mine();
}
$parentRelationship = $module['parentRelationship'] ?? null;

return $query->get()->map(function ($draft) use ($module, $parentRelationship) {
$parent = $draft->$parentRelationship;

return $query->get()->map(function ($draft) use ($module) {
return [
'type' => ucfirst($module['label_singular'] ?? Str::singular($module['name'])),
'name' => $draft->titleInDashboard ?? $draft->title,
'url' => moduleRoute($module['name'], $module['routePrefix'] ?? null, 'edit', [$draft->id]),
'url' => moduleRoute(
$module['name'],
$module['routePrefix'] ?? null,
'edit',
array_merge($parentRelationship ? [$parent->id] : [], [$draft->id])
)
];
});
})->collapse()->values();
}

private function getRepository(string $module, string $forModule = null): ModuleRepository
{
return $this->app->make($forModule ?? $this->config->get('twill.namespace') . "\Repositories\\" . ucfirst(Str::singular($module)) . 'Repository');
$moduleName = '';

if (!$forModule) {
if (Str::contains($module, '.')) {
$parts = explode('.', $module);
foreach ($parts as $part) {
$moduleName .= ucfirst(Str::singular($part));
}
} else {
$moduleName = ucfirst(Str::singular($module));
}
}

return $this->app->make($forModule ?? $this->config->get('twill.namespace') . "\Repositories\\" . $moduleName . 'Repository');
}
}
0