diff --git a/app/application/app/Http/Controllers/Admin/Projects/DocumentationVersionController.php b/app/application/app/Http/Controllers/Admin/Projects/DocumentationVersionController.php index 36f1374..492435c 100644 --- a/app/application/app/Http/Controllers/Admin/Projects/DocumentationVersionController.php +++ b/app/application/app/Http/Controllers/Admin/Projects/DocumentationVersionController.php @@ -35,10 +35,10 @@ final class DocumentationVersionController extends Controller return view('admin/projects/documentation-versions/index', $result->getData()); } - public function show(int $projectId, int $id, Request $request): View + public function show(int $projectId, int $id, Request $request, ?int $category = null): View { $user = $request->user(); - $result = $this->documentationVersionService->show($projectId, $id, $user); + $result = $this->documentationVersionService->show($projectId, $id, $category, $user); if ($result->isError()) { $this->errors($result); } diff --git a/app/application/app/Services/Admin/Project/DocumentationVersionService.php b/app/application/app/Services/Admin/Project/DocumentationVersionService.php index 768bbc8..b208461 100644 --- a/app/application/app/Services/Admin/Project/DocumentationVersionService.php +++ b/app/application/app/Services/Admin/Project/DocumentationVersionService.php @@ -2,12 +2,17 @@ namespace App\Services\Admin\Project; +use App\Dto\Builder\Documentation as DocumentationBuilderDto; +use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto; use App\Dto\QuerySettingsDto; use App\Dto\Builder\DocumentationVersion as DocumentationVersionBuilderDto; use App\Dto\Service\Admin\Project\DocumentationVersion\StoreUpdate; use App\Enums\DocumentationVersionStatus; use App\Models\DocumentationVersion; +use App\Models\ProjectLanguage; use App\Models\User; +use App\Repositories\DocumentationCategoryRepository; +use App\Repositories\DocumentationRepository; use App\Repositories\DocumentationVersionRepository; use App\Repositories\ProjectRepository; use App\ServiceResults\ServiceResultArray; @@ -17,6 +22,8 @@ use App\ServiceResults\StoreUpdateResult; use App\Services\ClearCacheCommandHandler; use App\Services\DocumentationVersion\DocumentationVersionCommandHandler; use App\Services\Service; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Support\Facades\DB; final class DocumentationVersionService extends Service @@ -26,6 +33,9 @@ final class DocumentationVersionService extends Service private readonly DocumentationVersionRepository $documentationVersionRepository, private readonly DocumentationVersionCommandHandler $documentationVersionCommandHandler, private readonly ClearCacheCommandHandler $clearCacheCommandHandler, + + private readonly DocumentationCategoryRepository $documentationCategoryRepository, + private readonly DocumentationRepository $documentationRepository ) { } public function index(int $projectId, DocumentationVersionBuilderDto $documentationVersionBuilderDto, QuerySettingsDto $querySettingsDto, User $user): ServiceResultError | ServiceResultArray @@ -54,7 +64,7 @@ final class DocumentationVersionService extends Service ]); } - public function show(int $projectId, int $versionId, User $user): ServiceResultError | ServiceResultArray + public function show(int $projectId, int $versionId, ?int $categoryId, User $user): ServiceResultError | ServiceResultArray { $project = $this->projectRepository->getProjectById($projectId); if (\is_null($project)) { @@ -70,9 +80,48 @@ final class DocumentationVersionService extends Service return $this->errFobidden(__('Access is denied')); } + $category = null; + if (!\is_null($categoryId)) { + $category = $this->documentationCategoryRepository->getCategoryById($categoryId); + if (\is_null($category) || $category->version_id !== $version->id) { + return $this->errNotFound(__('Not Found')); + } + if ($user->cannot('view', $category)) { + return $this->errFobidden(__('Access is denied')); + } + } + + $defaultLanguage = $project->languages()->where('is_default', 1)->first(); + $with = [ + 'content' => function (HasOne $hasOne) use ($defaultLanguage) { + /** @var ?ProjectLanguage $defaultLanguage */ + $hasOne->when($defaultLanguage, function (Builder $query, ProjectLanguage $defaultLanguage) { + $query->where('language_id', $defaultLanguage->id); + }); + } + ]; + + $categoryDto = new DocumentationCategoryBuilderDto\Category($category->id ?? null); + $categories = $this->documentationCategoryRepository + ->getCategories( + $version->id, + new DocumentationCategoryBuilderDto(parentId: $categoryDto), + $with + )->all(); + $documents = $this->documentationRepository + ->getDocumentations( + $version->id, + new DocumentationBuilderDto(categoryId: $categoryDto), + $with + )->all(); + return $this->result([ 'version' => $version, 'project' => $project, + + 'category' => $category, + 'categories' => $categories, + 'documentations' => $documents, ]); } diff --git a/app/application/lang/en.json b/app/application/lang/en.json index d976cca..8ee4b02 100644 --- a/app/application/lang/en.json +++ b/app/application/lang/en.json @@ -38,6 +38,9 @@ "Connection Timed Out": "Connection Timed Out", "Continue": "Continue", "Create": "Create", + "Create documentation": "Create documentation", + "Create category": "Create category", + "Create version documentation": "Create a version of the documentation", "Create :name": "Create :name", "Created": "Created", "Delete": "Delete", diff --git a/app/application/lang/en/admin-sections.php b/app/application/lang/en/admin-sections.php index 69871f4..7309220 100644 --- a/app/application/lang/en/admin-sections.php +++ b/app/application/lang/en/admin-sections.php @@ -17,4 +17,6 @@ return [ 'Documentation' => 'Documentation', 'Categories' => 'Categories', 'Setting up automatic translation' => 'Setting up automatic translation', + 'Documentation not found' => 'Documentation not found', + 'No categories found' => 'No categories found', ]; diff --git a/app/application/lang/ru.json b/app/application/lang/ru.json index 0d55c4b..36c2e67 100644 --- a/app/application/lang/ru.json +++ b/app/application/lang/ru.json @@ -38,6 +38,9 @@ "Connection Timed Out": "Соединение не отвечает", "Continue": "Продолжай", "Create": "Создать", + "Create documentation": "Создать документацию", + "Create category": "Создать категорию", + "Create version documentation": "Создать версию документации", "Create :name": "Создать :name", "Created": "Создано", "Delete": "Удалить", diff --git a/app/application/lang/ru/admin-sections.php b/app/application/lang/ru/admin-sections.php index 09c6504..454ccd4 100644 --- a/app/application/lang/ru/admin-sections.php +++ b/app/application/lang/ru/admin-sections.php @@ -17,4 +17,6 @@ return [ 'Documentation' => 'Документация', 'Categories' => 'Категории', 'Setting up automatic translation' => 'Настройка автоматического перевода', + 'Documentation not found' => 'Документация не найдена', + 'No categories found' => 'Категории не найдены', ]; diff --git a/app/application/resources/views/admin/projects/documentation-versions/_top.blade.php b/app/application/resources/views/admin/projects/documentation-versions/_top.blade.php index 6010f38..d9d038b 100644 --- a/app/application/resources/views/admin/projects/documentation-versions/_top.blade.php +++ b/app/application/resources/views/admin/projects/documentation-versions/_top.blade.php @@ -1,18 +1,34 @@ - -
| {{ __('admin-sections.Sections') }} | +{{ __('admin-sections.Categories') }} |
+ ||||
|---|---|---|---|---|---|
| {{ __('validation.attributes.title') }} | +{{ __('validation.attributes.slug') }} | +{{ __('validation.attributes.is_public') }} | +|||
-
-
- {{ __('admin-sections.Documentation') }}
+ @forelse($categories as $category)
+ |
+ @can('view', $category)
+
+ {{ $category->content?->title }}
- |
-
-
- |
+
+ {{ $category->slug }}
+ |
+
+ @if($category->is_public)
+ {{ __('Yes') }}
+ @else
+ {{ __('No') }}
+ @endif
+ |
+
+ @can('update', $category)
+
+
- {{ __('admin-sections.Categories') }}
- |
- |
+
|
+
+ {{ __('admin-sections.No categories found') }}
+
+ |
+ |||||
{{ __('admin-sections.Documentation') }} |
+ |||||
| {{ __('validation.attributes.title') }} | +{{ __('validation.attributes.slug') }} | +{{ __('validation.attributes.is_public') }} | ++ | ||
| + {{ $documentation->content?->title }} + | ++ {{ $documentation->slug }} + | ++ @if($documentation->is_public) + {{ __('Yes') }} + @else + {{ __('No') }} + @endif + | ++ @can('update', $documentation) + + + + @endcan + @can('delete', $documentation) + + @endcan + | +||
|
+
+ {{ __('admin-sections.Documentation not found') }}
+
+ |
+ |||||