Phase 6: Backend Integration
Historical design/implementation plan. It is retained as background, not a statement that every proposed feature is available. Use the current component/project guides and the deployed editor before following its recipes.
Estimated Effort: 4-5 hours Dependencies: Phase 5 complete Jira: EZ-2206
Overview
Integrate the configuration form with backend endpoints to handle app installation. This includes updating the ProjectPageController store method, implementing helper methods for dependency creation, portal navigation, shortcuts, and dashboard tiles.
Objectives
- Update StoreProjectPageRequest validation rules
- Implement ProjectPageController store method enhancements
- Create helper methods for dependency processing
- Implement auto-creation of dependencies with preferred values
- Add portal navigation creation logic
- Add shortcuts creation logic
- Add dashboard tiles creation logic
- Handle form submission in AppStoreModal
- Test complete end-to-end flow
Implementation Steps
Step 1: Update Form Request Validation
File: app/Http/Requests/StoreProjectPageRequest.php
(Create if doesn't exist)
docker compose exec app php artisan make:request Admin/Project/StoreProjectPageRequest
Update rules:
<?php
namespace App\Http\Requests\Admin\Project;
use Illuminate\Foundation\Http\FormRequest;
class StoreProjectPageRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'plugin_page_id' => 'required|exists:plugin_pages,id',
'name' => 'required|string|max:255',
'dependencies' => 'nullable|array',
'dependencies.*' => 'nullable', // Can be ID or 'create_new'
'add_to_portal_nav' => 'boolean',
'portal_page_title' => 'required_if:add_to_portal_nav,true|string|max:255',
'portal_page_path' => 'required_if:add_to_portal_nav,true|string|max:255',
'add_to_shortcuts' => 'boolean',
'target_dashboard' => 'nullable|string',
'new_dashboard_name' => 'required_if:target_dashboard,new|string|max:255',
'selected_tiles' => 'nullable|array',
'selected_tiles.*' => 'exists:plugin_tiles,id'
];
}
public function messages()
{
return [
'name.required' => 'Please provide a name for this app.',
'portal_page_title.required_if' => 'Page title is required when adding to portal navigation.',
'portal_page_path.required_if' => 'Page path is required when adding to portal navigation.',
'new_dashboard_name.required_if' => 'Dashboard name is required when creating a new dashboard.',
];
}
}
Step 2: Update ProjectPageController
File: app/Http/Controllers/Admin/Project/ProjectPageController.php
Update store method:
use App\Http\Requests\Admin\Project\StoreProjectPageRequest;
use Illuminate\Support\Facades\DB;
public function store(StoreProjectPageRequest $request, Project $project)
{
$validated = $request->validated();
DB::beginTransaction();
try {
// Create the page
$page = $project->pages()->create([
'name' => $validated['name'],
'plugin_page_id' => $validated['plugin_page_id'],
// Add other fields as needed
]);
// Handle dependencies
if (isset($validated['dependencies']) && !empty($validated['dependencies'])) {
$this->processDependencies($page, $validated['dependencies'], $project);
}
// Handle portal navigation
if ($validated['add_to_portal_nav'] ?? false) {
$this->addToPortalNavigation($page, $project, $validated);
}
// Handle shortcuts
if ($validated['add_to_shortcuts'] ?? false) {
$this->addToShortcuts($page, $project);
}
// Handle dashboard tiles
if (!empty($validated['selected_tiles'])) {
$this->addDashboardTiles(
$page,
$project,
$validated['selected_tiles'],
$validated['target_dashboard'],
$validated['new_dashboard_name'] ?? null
);
}
DB::commit();
return redirect()->route('dashboard.project.pages.show', [
'project' => $project->slug,
'page' => $page->slug
])->with('success', 'App added successfully!');
} catch (\Exception $e) {
DB::rollBack();
\Log::error('Failed to create project page', [
'error' => $e->getMessage(),
'project_id' => $project->id,
'plugin_page_id' => $validated['plugin_page_id']
]);
throw $e;
}
}
Add helper methods:
protected function processDependencies($page, $dependencies, $project)
{
$pluginVersion = $page->pluginPage->currentVersion;
$dependencyDefinitions = $pluginVersion->dependencies ?? [];
foreach ($dependencies as $identifier => $value) {
if (empty($value)) {
continue;
}
$definition = collect($dependencyDefinitions)
->firstWhere('identifier', $identifier);
if (!$definition) {
continue;
}
if ($value === 'create_new') {
// Auto-create dependency with preferred values
$value = $this->createDependency(
$definition['model'],
$project,
$page->name,
$definition['preferred'] ?? []
);
}
// Attach dependency to page
$page->dependencies()->create([
'identifier' => $identifier,
'model' => $definition['model'],
'model_id' => $value
]);
}
}
protected function createDependency($model, $project, $baseName, $preferred = [])
{
$modelClass = "App\\Models\\{$model}";
if (!class_exists($modelClass)) {
throw new \Exception("Model {$modelClass} does not exist");
}
$data = array_merge([
'name' => $baseName,
'project_id' => $project->id
], $preferred);
$instance = $modelClass::create($data);
return $instance->id;
}
protected function addToPortalNavigation($page, $project, $validated)
{
$portal = $project->portals()->where('is_default', true)->first();
if (!$portal) {
\Log::warning('No default portal found for project', [
'project_id' => $project->id
]);
return;
}
$portal->navigationItems()->create([
'label' => $validated['portal_page_title'],
'path' => $validated['portal_page_path'],
'page_id' => $page->id,
'icon' => $page->pluginPage->icon,
'order' => $portal->navigationItems()->max('order') + 1
]);
}
protected function addToShortcuts($page, $project)
{
$project->navigationShortcuts()->create([
'label' => $page->name,
'page_id' => $page->id,
'icon' => $page->pluginPage->icon,
'color' => $page->pluginPage->background_color,
'is_top_level' => true,
'order' => $project->navigationShortcuts()->max('order') + 1
]);
}
protected function addDashboardTiles($page, $project, $tileIds, $targetDashboard, $newDashboardName)
{
if ($targetDashboard === 'new') {
$dashboard = $project->dashboards()->create([
'name' => $newDashboardName ?: $page->name,
'is_default' => false
]);
$dashboardId = $dashboard->id;
} else {
$dashboardId = $targetDashboard;
}
$dashboard = $project->dashboards()->find($dashboardId);
if (!$dashboard) {
\Log::warning('Dashboard not found', [
'dashboard_id' => $dashboardId,
'project_id' => $project->id
]);
return;
}
foreach ($tileIds as $tileId) {
$pluginTile = \App\Models\PluginTile::find($tileId);
if (!$pluginTile) {
continue;
}
$dashboard->tiles()->create([
'plugin_tile_id' => $tileId,
'page_id' => $page->id,
'title' => $pluginTile->name,
'config' => $pluginTile->default_config ?? [],
'order' => $dashboard->tiles()->max('order') + 1
]);
}
}
Step 3: Update AppStoreModal Form Submission
File: resources/js/Components/Mod/AppStoreModal/AppStoreModal.vue
Update handleConfigSubmit method:
const handleConfigSubmit = async (formData) => {
loading.value = true
try {
router.post(
route('dashboard.project.pages.store', { project: props.project.slug }),
{
plugin_page_id: formData.plugin_page_id,
name: formData.name,
dependencies: formData.dependencies,
add_to_portal_nav: formData.addToPortalNav,
portal_page_title: formData.portalPageTitle,
portal_page_path: formData.portalPagePath,
add_to_shortcuts: formData.addToShortcuts,
target_dashboard: formData.targetDashboard,
new_dashboard_name: formData.newDashboardName,
selected_tiles: formData.selectedTiles
},
{
onSuccess: () => {
// Redirect is handled by backend
closeModal()
},
onError: (errors) => {
// Pass errors back to config form
toast.error('Please fix the errors and try again')
loading.value = false
// You may want to emit errors back to AppStoreConfig
}
}
)
} catch (err) {
toast.error('Failed to add app to project')
console.error(err)
loading.value = false
}
}
Step 4: Add Async Selectors for Dependencies
File: resources/js/Components/Mod/AppStoreModal/AppStoreConfig.vue
Update dependency selectors to use async data:
Replace the dependency select sections with:
<div
v-for="dep in dependencies"
:key="dep.identifier"
class="mb-3"
>
<label class="form-label">
{{ formatLabel(dep.model) }}
<span v-if="dep.required" class="text-danger">*</span>
</label>
<AsyncSelect
v-model="formData.dependencies[dep.identifier]"
:route="getDependencyRoute(dep.model)"
:route-params="{ project: project.slug }"
:allow-create="true"
create-label="Create new"
:class="{ 'is-invalid': errors[`dependencies.${dep.identifier}`] }"
@create="() => handleCreateDependency(dep)"
/>
<div v-if="errors[`dependencies.${dep.identifier}`]" class="invalid-feedback d-block">
{{ errors[`dependencies.${dep.identifier}`] }}
</div>
</div>
Add methods:
import AsyncSelect from '@/Components/Selectors/AsyncSelect.vue'
// Model to route mapping
const modelRouteMap = {
'ProjectForm': 'dashboard.project.forms.index',
'AccessGroup': 'dashboard.project.access-groups.index',
'ProjectPortal': 'dashboard.project.portals.index',
// Add other mappings as needed
}
function getDependencyRoute(model) {
return modelRouteMap[model] || null
}
function handleCreateDependency(dep) {
// Set to create_new flag
formData.value.dependencies[dep.identifier] = 'create_new'
}
Step 5: Write Feature Test
File: tests/Feature/PluginPage/AppStoreInstallationTest.php
<?php
namespace Tests\Feature\PluginPage;
use App\Models\Admin;
use App\Models\PluginPage;
use App\Models\PluginPageVersion;
use App\Models\PluginTile;
use App\Models\Project;
use App\Models\Team;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AppStoreInstallationTest extends TestCase
{
use RefreshDatabase;
protected $admin;
protected $team;
protected $project;
protected function setUp(): void
{
parent::setUp();
$this->team = Team::factory()->create();
$this->admin = Admin::factory()->create();
$this->admin->teams()->attach($this->team);
$this->project = Project::factory()->create(['team_id' => $this->team->id]);
}
public function test_can_install_app_with_basic_config()
{
$pluginPage = PluginPage::factory()->create([
'icon' => 'users',
'background_color' => '#3490dc'
]);
$version = PluginPageVersion::factory()->create([
'plugin_page_id' => $pluginPage->id,
'dependencies' => []
]);
$pluginPage->update(['current_version_id' => $version->id]);
$response = $this->actingAs($this->admin)->post(
route('dashboard.project.pages.store', ['project' => $this->project->slug]),
[
'plugin_page_id' => $pluginPage->id,
'name' => 'Test App',
'add_to_portal_nav' => false,
'add_to_shortcuts' => false
]
);
$response->assertRedirect();
$this->assertDatabaseHas('project_pages', [
'project_id' => $this->project->id,
'name' => 'Test App',
'plugin_page_id' => $pluginPage->id
]);
}
public function test_can_install_app_with_shortcuts()
{
$pluginPage = PluginPage::factory()->create([
'icon' => 'users',
'background_color' => '#3490dc'
]);
$version = PluginPageVersion::factory()->create([
'plugin_page_id' => $pluginPage->id
]);
$pluginPage->update(['current_version_id' => $version->id]);
$response = $this->actingAs($this->admin)->post(
route('dashboard.project.pages.store', ['project' => $this->project->slug]),
[
'plugin_page_id' => $pluginPage->id,
'name' => 'Test App',
'add_to_shortcuts' => true
]
);
$response->assertRedirect();
$this->assertDatabaseHas('project_navigation_shortcuts', [
'project_id' => $this->project->id,
'label' => 'Test App',
'is_top_level' => true
]);
}
public function test_can_install_app_with_dashboard_tiles()
{
$pluginPage = PluginPage::factory()->create();
$version = PluginPageVersion::factory()->create(['plugin_page_id' => $pluginPage->id]);
$pluginPage->update(['current_version_id' => $version->id]);
$tile = PluginTile::factory()->create();
$response = $this->actingAs($this->admin)->post(
route('dashboard.project.pages.store', ['project' => $this->project->slug]),
[
'plugin_page_id' => $pluginPage->id,
'name' => 'Test App',
'target_dashboard' => 'new',
'new_dashboard_name' => 'Test Dashboard',
'selected_tiles' => [$tile->id]
]
);
$response->assertRedirect();
$dashboard = $this->project->dashboards()->where('name', 'Test Dashboard')->first();
$this->assertNotNull($dashboard);
$this->assertDatabaseHas('dashboard_tiles', [
'dashboard_id' => $dashboard->id,
'plugin_tile_id' => $tile->id
]);
}
public function test_validation_fails_without_required_fields()
{
$response = $this->actingAs($this->admin)->post(
route('dashboard.project.pages.store', ['project' => $this->project->slug]),
[]
);
$response->assertSessionHasErrors(['plugin_page_id', 'name']);
}
}
Run tests:
docker compose exec app ./vendor/bin/phpunit tests/Feature/PluginPage/AppStoreInstallationTest.php
Step 6: Manual End-to-End Testing
- Open app store modal
- Browse and select an app
- Click "Add"
- Fill out configuration form:
- Name
- Dependencies (test both selecting existing and "create new")
- Portal navigation
- Shortcuts
- Dashboard tiles
- Submit form
- Verify redirect to new page
- Check that all options were applied:
- Page created
- Dependencies attached
- Portal navigation item created (if selected)
- Shortcut created (if selected)
- Dashboard and tiles created (if selected)
Acceptance Criteria
- Form validation rules work on backend
- Page creation succeeds with all data
- Dependencies are processed correctly
- "Create new" dependencies are auto-created with preferred values
- Portal navigation items are created when selected
- Shortcuts are created when selected
- Dashboard tiles are added to new or existing dashboard
- Transaction rollback works on errors
- Redirect happens after successful creation
- Success message displays
- All feature tests pass
Files Created
app/Http/Requests/Admin/Project/StoreProjectPageRequest.phptests/Feature/PluginPage/AppStoreInstallationTest.php
Files Modified
app/Http/Controllers/Admin/Project/ProjectPageController.phpresources/js/Components/Mod/AppStoreModal/AppStoreModal.vueresources/js/Components/Mod/AppStoreModal/AppStoreConfig.vue
Next Phase
After this phase is complete and all tests pass, proceed to Phase 7: Testing & Polish.