Make projects depend on templates

This commit is contained in:
2026-09-08 10:25:52 +00:00
committed by Twyco
parent 40f9b473fc
commit fef82cb88f
19 changed files with 281 additions and 14 deletions
+5 -1
View File
@@ -54,7 +54,11 @@ class ProjectController extends Controller
403,
);
$sourceTemplates = ProjectTemplate::query()->with('sourceProject')->orderBy('name')->get();
$sourceTemplates = ProjectTemplate::query()
->published()
->with('sourceProject')
->orderBy('name')
->get();
$selectedTemplateId = $request->integer('template');
return Inertia::render('projects/Create', [
@@ -26,6 +26,7 @@ class ProjectTemplateController extends Controller
'status' => session('status'),
'templates' => ProjectTemplateResource::collection(
ProjectTemplate::query()
->published()
->with('sourceProject')
->orderBy('name')
->get(),
@@ -51,6 +52,8 @@ class ProjectTemplateController extends Controller
public function destroy(ProjectTemplate $projectTemplate): RedirectResponse
{
abort_if(! $projectTemplate->is_published, 404);
$templateName = $projectTemplate->name;
$projectTemplate->delete();
+1 -1
View File
@@ -85,7 +85,7 @@ class StoreProjectRequest extends FormRequest
Rule::requiredIf(fn (): bool => $this->input('creation_mode') === 'template'),
'nullable',
'integer',
Rule::exists('project_templates', 'id'),
Rule::exists('project_templates', 'id')->where(fn ($query) => $query->where('is_published', true)),
],
'copy_areas' => ['nullable', 'array'],
'copy_areas.*' => [
+1
View File
@@ -18,6 +18,7 @@ class ProjectResource extends JsonResource
'id' => $this->id,
'name' => $this->name,
'key' => $this->key,
'project_template_id' => $this->project_template_id,
'show_author' => $this->show_author,
'show_story_points' => $this->show_story_points,
'created_at' => $this->created_at?->toISOString(),
@@ -19,12 +19,14 @@ class ProjectTemplateResource extends JsonResource
if ($this->resource instanceof ProjectTemplate) {
return [
'id' => $this->id,
'project_id' => $this->project_id,
'source_project_id' => $this->source_project_id,
'source_project' => $this->relationLoaded('sourceProject') && $this->sourceProject !== null
? ProjectResource::make($this->sourceProject)->resolve()
: null,
'name' => $this->name,
'slug' => $this->slug,
'is_published' => $this->is_published,
'copy_areas' => $this->copy_areas ?? [],
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
@@ -33,10 +35,12 @@ class ProjectTemplateResource extends JsonResource
return [
'id' => Arr::get($this->resource, 'id'),
'project_id' => Arr::get($this->resource, 'project_id'),
'source_project_id' => Arr::get($this->resource, 'source_project_id'),
'source_project' => Arr::get($this->resource, 'source_project'),
'name' => Arr::get($this->resource, 'name'),
'slug' => Arr::get($this->resource, 'slug'),
'is_published' => Arr::get($this->resource, 'is_published', true),
'copy_areas' => Arr::get($this->resource, 'copy_areas', []),
'created_at' => Arr::get($this->resource, 'created_at'),
'updated_at' => Arr::get($this->resource, 'updated_at'),