### Install Flowforge Package (Composer) Source: https://relaticle.github.io/flowforge/getting-started/installation Installs the Flowforge package using Composer. This is the first step in the setup process. ```bash composer require relaticle/flowforge ``` -------------------------------- ### Generate Flowforge Task Board (Artisan) Source: https://relaticle.github.io/flowforge/getting-started/installation Creates a new Kanban board for your specified model. This command generates the necessary page and configuration for your board. ```bash php artisan flowforge:make-board TaskBoard --model=Task ``` -------------------------------- ### Install BCMath PHP Extension on Ubuntu/Debian Source: https://relaticle.github.io/flowforge/getting-started/upgrading This command installs the BCMath PHP extension, which is a requirement for Flowforge v3.x and v4.x due to changes in how positions are stored. This is specific to Ubuntu/Debian-based systems. ```bash sudo apt-get install php-bcmath ``` -------------------------------- ### Install Flowforge v4.x using Composer Source: https://relaticle.github.io/flowforge/getting-started/upgrading This command installs the latest v4.x version of the Flowforge package using Composer. Ensure you are running a compatible version of PHP and Laravel as per the upgrade requirements. ```bash composer require relaticle/flowforge:^4.0 ``` -------------------------------- ### Real-World CardFlex Layout Example (PHP) Source: https://relaticle.github.io/flowforge/essentials/customization A practical example of using CardFlex within a card schema, combining text entries for title, description, and multiple styled entries for priority, due date, and assigned user. It showcases wrapping and justification. ```php ->cardSchema(fn (Schema $schema) => $schema->components([ TextEntry::make('title') ->weight('bold') ->size('lg'), TextEntry::make('description') ->limit(100) ->color('gray'), CardFlex::make([ TextEntry::make('priority') ->badge() ->icon('heroicon-o-flag'), TextEntry::make('due_date') ->badge() ->date() ->icon('heroicon-o-calendar'), TextEntry::make('assignedTo.name') ->badge() ->icon('heroicon-o-user'), ])->wrap()->justify('start'), ])) ``` -------------------------------- ### Optimize Board Query for Performance Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Provides an example of an optimized Eloquent query for the board, including eager loading relationships and selecting only necessary fields. This helps improve board loading performance with many cards. ```php // Optimized query example ->query( Task::query() ->with(['assignee', 'priority']) // Eager load relationships ->select(['id', 'title', 'status', 'position']) // Select only needed fields ) ``` -------------------------------- ### Register Task Board Page in Filament Source: https://relaticle.github.io/flowforge/getting-started/installation Registers the generated TaskBoard page within your Filament admin panel configuration, making it accessible in the navigation. ```php ->pages([ App\Filament\Pages\TaskBoard::class, ]) ``` -------------------------------- ### Flowforge Optional Commands Source: https://relaticle.github.io/flowforge/getting-started/installation Provides optional commands for Flowforge maintenance, such as repairing corrupted or missing position data. ```bash php artisan flowforge:repair-positions ``` -------------------------------- ### Enable Drag-Drop with Pagination Disabled Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Demonstrates how to programmatically load all items in a column to enable drag-and-drop functionality when pagination is active. It shows checking and loading columns. ```php // Check if column is fully loaded $this->isColumnFullyLoaded('todo'); // Returns false with pagination // Load all cards programmatically $this->loadAllItems('todo'); // Now drag-drop is enabled $this->isColumnFullyLoaded('todo'); // Returns true ``` -------------------------------- ### Include Flowforge CSS Assets (Filament Theme) Source: https://relaticle.github.io/flowforge/getting-started/installation Adds Flowforge CSS styles to your custom Filament theme. Requires a pre-existing custom Filament theme. ```css @source "../../../../vendor/relaticle/flowforge/resources/views/**/*.blade.php"; ``` -------------------------------- ### Configure Board with Position Identifier Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Ensures cards are draggable by adding the necessary `positionIdentifier` to the board configuration. This is crucial for the drag-and-drop functionality to work correctly. ```php public function board(Board $board): Board { return $board ->query(Task::query()) ->columnIdentifier('status') ->positionIdentifier('position') // Required for drag-drop ->columns([...]); } ``` -------------------------------- ### Update Flowforge Position Service Usage (v2.x to v3.x) Source: https://relaticle.github.io/flowforge/getting-started/upgrading This code illustrates the changes in Flowforge's position service between v2.x and v3.x. It shows how to obtain a new position, transitioning from the `Rank` service to the `DecimalPosition` service. ```php // Before (v2.x) use Relaticle\Flowforge\Services\Rank; $position = Rank::forEmptySequence()->get(); $position = Rank::after($lastRank)->get(); // After (v3.x) use Relaticle\Flowforge\Services\DecimalPosition; $position = DecimalPosition::forEmptyColumn(); $position = DecimalPosition::after($lastPosition); ``` -------------------------------- ### Create Migration for Position Column (Artisan) Source: https://relaticle.github.io/flowforge/getting-started/installation Generates a new migration file to add the 'position' column to your database table, which is essential for Flowforge's drag-and-drop functionality. ```bash php artisan make:migration add_position_to_tasks_table ``` -------------------------------- ### Flowforge Diagnostic and Rebalancing Commands Source: https://relaticle.github.io/flowforge/getting-started/upgrading Flowforge v3.x introduces new Artisan commands for managing item positions. `diagnose-positions` checks for inconsistencies, while `rebalance-positions` redistributes positions to ensure proper ordering. ```bash php artisan flowforge:diagnose-positions # Check for issues php artisan flowforge:rebalance-positions # Redistribute positions ``` -------------------------------- ### Update Flowforge Position Service Usage (v2.x to v4.x) Source: https://relaticle.github.io/flowforge/getting-started/upgrading This code shows the refactoring required when migrating from Flowforge v2.x to v4.x. It demonstrates the change in how to obtain a position value, moving from the `Rank` service to the `DecimalPosition` service. ```php // Before (v2.x) use Relaticle\Flowforge\Services\Rank; $position = Rank::forEmptySequence()->get(); // After (v4.x) use Relaticle\Flowforge\Services\DecimalPosition; $position = DecimalPosition::forEmptyColumn(); ``` -------------------------------- ### Verify Database Schema with PHP Artisan Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Checks the status of database migrations using the `php artisan migrate:status` command. This helps in understanding which migrations have been applied and which are pending. ```bash php artisan migrate:status ``` -------------------------------- ### Debug Empty Board by Dumping Data Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Temporarily adds a `dd()` call to the board method to inspect the data being retrieved by the Eloquent query. This helps verify if data exists and is being fetched correctly. ```php // Add to board method temporarily dd($this->getEloquentQuery()->get()); ``` -------------------------------- ### Add Position Column to Database Table (PHP) Source: https://relaticle.github.io/flowforge/getting-started/installation Applies the 'position' column to your database table using the generated migration. This column is automatically handled for database-specific collations. ```php Schema::table('tasks', function (Blueprint $table) { $table->flowforgePositionColumn('position'); // Handles database-specific collations automatically }); ``` -------------------------------- ### Add Flowforge Position Column to Existing Table (PHP) Source: https://relaticle.github.io/flowforge/essentials/database-schema Provides an example migration to add a `flowforgePositionColumn` to an existing 'tasks' table, including an optional unique constraint for concurrent safety. ```php flowforgePositionColumn('position'); // Recommended: Add unique constraint for concurrent safety $table->unique(['status', 'position'], 'unique_position_per_column'); }); } public function down(): void { Schema::table('tasks', function (Blueprint $table) { $table->dropUnique('unique_position_per_column'); $table->dropColumn('position'); }); } }; ``` -------------------------------- ### Test Livewire Drag and Drop Functionality in PHP Source: https://relaticle.github.io/flowforge/essentials/troubleshooting A temporary Livewire component method for testing drag and drop functionality. It moves a task to 'in_progress' status and uses `dd()` to display the updated status. ```php // Add to board component temporarily public function testDragDrop() { $task = Task::first(); $this->moveCard($task->id, 'in_progress'); dd($task->fresh()->status); } ``` -------------------------------- ### Implement Required Traits for Actions Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Ensures that the component uses the `InteractsWithActions` and `InteractsWithForms` traits, which are necessary for card and column actions to function properly within Flowforge. ```php class TaskBoard extends BoardPage { use InteractsWithActions; // Required use InteractsWithForms; // Required public function board(Board $board): Board { return $board ->cardActions([ EditAction::make()->model(Task::class), // Model required ]); } } ``` -------------------------------- ### Pagination Control - Livewire Source: https://relaticle.github.io/flowforge/essentials/api-reference Offers Livewire methods for managing card pagination within columns. This includes loading more cards, loading all cards to enable reordering, checking if all cards are loaded, and getting the position for new cards. ```php // Load more cards for pagination $this->loadMoreItems(string $columnId, ?int $count = null) // Load all cards to enable reordering $this->loadAllItems(string $columnId) // Check if all cards are loaded $this->isColumnFullyLoaded(string $columnId): bool // Get position for new card in column $this->getBoardPositionInColumn(string $columnId): string ``` -------------------------------- ### Run Flowforge Position Repair Command Source: https://relaticle.github.io/flowforge/getting-started/upgrading After performing database schema changes related to the position column, this Artisan command should be run. It helps repair and re-index positions, especially after a quick upgrade or if using the 'regenerate' strategy. ```bash php artisan flowforge:repair-positions ``` -------------------------------- ### Ensure Query Returns Records for Board Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Checks for potential issues like global scopes or soft deletes that might prevent the query from returning records for the board. It suggests using `withoutGlobalScopes()` to bypass these. ```php // Check for global scopes, soft deletes, etc. ->query(Task::withoutGlobalScopes()->get()) ``` -------------------------------- ### Clear View Cache with PHP Artisan Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Clears the application's view cache using the `php artisan view:clear` command. This is useful when changes to Blade views are not reflecting correctly. ```bash php artisan view:clear ``` -------------------------------- ### Include Flowforge Views in Theme CSS Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Specifies the CSS import rule required in your theme's CSS file to ensure Flowforge components are correctly styled. This prevents styling issues and broken layouts. ```css /* Required in your theme CSS file */ @source "../../../../vendor/relaticle/flowforge/resources/views/**/*.blade.php"; ``` -------------------------------- ### Include Filament Assets in Layout Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Ensures that Filament's CSS and JavaScript assets are included in your application's layout. This is necessary for Flowforge's Alpine components and action modals to function correctly. ```html {{-- Required in your layout --}}
@filamentStyles {{ $slot }} @filamentScripts ``` -------------------------------- ### Upgrade Position Column (Preserve Order) Source: https://relaticle.github.io/flowforge/getting-started/upgrading This PHP code snippet provides a method to upgrade the 'position' column while preserving the existing order of items. It involves adding a temporary new column, copying data, swapping columns, and then running a repair command. ```php public function up(): void { // Add temporary column Schema::table('tasks', function (Blueprint $table) { $table->decimal('position_new', 20, 10)->nullable(); }); // Copy order (positions will be regenerated by repair command) DB::statement('UPDATE tasks SET position_new = CAST(position AS DECIMAL(20,10))'); // Swap columns Schema::table('tasks', function (Blueprint $table) { $table->dropColumn('position'); }); Schema::table('tasks', function (Blueprint $table) { $table->renameColumn('position_new', 'position'); }); } ``` -------------------------------- ### Upgrade Position Column (Quick - Resets Order) Source: https://relaticle.github.io/flowforge/getting-started/upgrading This PHP code snippet demonstrates a quick method to upgrade the 'position' column in your database schema to support Flowforge v3.x/v4.x. This approach drops the existing column and adds a new one using the `flowforgePositionColumn()` macro, which resets the order of items. ```php public function up(): void { Schema::table('tasks', function (Blueprint $table) { $table->dropColumn('position'); }); Schema::table('tasks', function (Blueprint $table) { $table->flowforgePositionColumn(); }); } ``` -------------------------------- ### Add Position Generation in Create Action Source: https://relaticle.github.io/flowforge/essentials/troubleshooting Modifies the form data during creation to include the correct status and position for new cards, especially when created via column actions. This prevents cards from appearing in random positions. ```php CreateAction::make() ->mutateFormDataUsing(function (array $data, array $arguments): array { if (isset($arguments['column'])) { $data['status'] = $arguments['column']; $data['position'] = $this->getBoardPositionInColumn($arguments['column']); } return $data; }) ``` -------------------------------- ### Configure Board Essentials - PHP Source: https://relaticle.github.io/flowforge/essentials/api-reference Sets up the essential configuration for a Flowforge board, including the data source, column identifier, position identifier, and defining the board's columns. This is a required step for basic board functionality. ```php public function board(Board $board): Board { return $board ->query(Task::query()) // Required: Data source ->columnIdentifier('status') // Required: Column field ->positionIdentifier('position') // Required: Position field ->columns([ Column::make('todo')->label('To Do')->color('gray'), Column::make('done')->label('Done')->color('green'), ]); } ``` -------------------------------- ### Integrate Kanban Board with Filament Resource Source: https://relaticle.github.io/flowforge/essentials/integration-patterns This snippet shows how to create a Kanban board view for a Filament resource, specifically for campaign tasks. It defines the board's columns, query logic to fetch tasks for the current campaign and user's team, and registers the new board page within the resource's routes. Dependencies include the Filament framework and Flowforge components. ```php query( // Get tasks for this specific campaign and current user's team $this->getRecord() ->tasks() ->whereHas('team', fn($q) => $q->where('id', auth()->user()->current_team_id)) ->getQuery() ) ->columnIdentifier('status') ->positionIdentifier('position') ->columns([ Column::make('backlog')->label('Backlog')->color('gray'), Column::make('in_progress')->label('In Progress')->color('blue'), Column::make('review')->label('Review')->color('amber'), Column::make('completed')->label('Completed')->color('green'), ]); } } // Register in your CampaignResource public static function getPages(): array { return [ 'index' => Pages\ListCampaigns::route('/'), 'create' => Pages\CreateCampaign::route('/create'), 'edit' => Pages\EditCampaign::route('/{record}/edit'), 'tasks' => Pages\CampaignTaskBoard::route('/{record}/tasks'), // Add this line ]; } ``` -------------------------------- ### Implement Search and Filtering for Kanban Boards (PHP) Source: https://relaticle.github.io/flowforge/essentials/customization Enables search and filtering capabilities for Kanban boards. It includes searching by title, description, and assignee name, and provides filters for priority (multi-select) and assigned user (relationship-based), plus an 'overdue' toggle filter. ```php use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Filters\Filter; public function board(Board $board): Board { return $board ->searchable(['title', 'description', 'assignee.name']) ->filters([ SelectFilter::make('priority') ->options(['low' => 'Low', 'medium' => 'Medium', 'high' => 'High']) ->multiple(), SelectFilter::make('assigned_to') ->relationship('assignee', 'name') ->searchable() ->preload(), Filter::make('overdue') ->label('Overdue') ->query(fn (Builder $query) => $query->where('due_date', '<', now())) ->toggle(), ]); } ``` -------------------------------- ### Configure Column Appearance with Colors (PHP) Source: https://relaticle.github.io/flowforge/essentials/customization Demonstrates how to configure a column's appearance, specifically setting its color using various supported formats. This includes using string-based Tailwind CSS color names, Filament Color constants, semantic color names, and custom hex color codes. ```php use Filament\Support\Colors\Color; Column::make('todo') ->label('To Do') ->color('gray') // Supports multiple color formats ->icon('heroicon-o-queue-list') ``` ```php use Filament\Support\Colors\Color; Column::make('todo')->color(Color::Gray) Column::make('in_progress')->color(Color::Blue) Column::make('done')->color(Color::Green) ``` ```php Column::make('todo')->color('gray') Column::make('in_progress')->color('blue') Column::make('done')->color('green') ``` ```php Column::make('urgent')->color('#ff0000') Column::make('normal')->color('#3b82f6') Column::make('completed')->color('#22c55e') ``` ```php use Filament\Support\Colors\Color; ->columns([ Column::make('todo') ->color('gray'), // Tailwind color name Column::make('in_progress') ->color(Color::Blue), // Color constant Column::make('review') ->color('primary'), // Semantic color Column::make('done') ->color('#22c55e'), // Custom hex ]) ``` -------------------------------- ### Arrange Card Elements with CardFlex Layout (PHP) Source: https://relaticle.github.io/flowforge/essentials/customization Demonstrates using the CardFlex component to arrange multiple elements within a card in a flexible row that wraps on smaller screens. It allows for justification and alignment of elements. ```php use Filament\Infolists\Components\TextEntry; use Filament\Infolists\Components\ImageEntry; use Relaticle\Flowforge\Components\CardFlex; ->cardSchema(fn (Schema $schema) => $schema->components([ TextEntry::make('title')->weight('bold'), CardFlex::make([ TextEntry::make('priority')->badge(), TextEntry::make('due_date')->icon('heroicon-o-calendar'), ImageEntry::make('assignee.avatar_url')->circular()->size(24), ]) ->wrap() // Enable wrapping on small screens ->justify('between') // Horizontal: 'start', 'end', 'between', 'center' ->align('center'), // Vertical: 'start', 'end', 'center' ])) ``` -------------------------------- ### PHP Livewire Event Listeners for Kanban Source: https://relaticle.github.io/flowforge/essentials/api-reference Listen to Kanban events like 'kanban-card-moved' and 'kanban-items-loaded' using Livewire's #[On] attribute. These methods allow custom logic execution based on specific Kanban interactions, such as updating analytics or tracking loading progress. ```php use Livewire\Attributes\On; #[On('kanban-card-moved')] public function onCardMoved(string $cardId, string $columnId, string $position): void { // Custom logic when a card moves (e.g., send notification, update analytics) } #[On('kanban-items-loaded')] public function onItemsLoaded(string $columnId, int $loadedCount, int $totalCount, bool $isFullyLoaded): void { // Track loading progress } ``` -------------------------------- ### Add Column Actions for Card Creation (PHP) Source: https://relaticle.github.io/flowforge/essentials/customization Implements column actions for Kanban boards, specifically a 'CreateAction' to add new tasks. It configures the action with a form including text input for title and a select input for priority, with data mutation for status and position. ```php use Filament\Actions\CreateAction; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Select; public function board(Board $board): Board { return $board ->columnActions([ CreateAction::make() ->label('Add Task') ->model(Task::class) ->form([ TextInput::make('title')->required(), Select::make('priority') ->options(['low' => 'Low', 'medium' => 'Medium', 'high' => 'High']) ->default('medium'), ]) ->mutateFormDataUsing(function (array $data, array $arguments): array { if (isset($arguments['column'])) { $data['status'] = $arguments['column']; $data['position'] = $this->getBoardPositionInColumn($arguments['column']); } return $data; }), ]); } ``` -------------------------------- ### Configure Board Content - PHP Source: https://relaticle.github.io/flowforge/essentials/api-reference Enhances board configuration by defining the attribute used for card titles and setting up rich card content using a schema. This allows for more detailed and structured information to be displayed on each card. ```php ->recordTitleAttribute('title') // Card title field ->cardSchema(fn(Schema $schema) => $schema // Rich card content ->components([ TextEntry::make('description'), TextEntry::make('due_date')->date(), ]) ) ``` -------------------------------- ### Generate Task Positions with Factory (PHP) Source: https://relaticle.github.io/flowforge/essentials/database-schema Illustrates how to integrate Flowforge's `DecimalPosition` service into a Laravel factory to generate correct position values for tasks, ensuring proper ordering. ```php use Relaticle\Flowforge\Services\DecimalPosition; class TaskFactory extends Factory { /** @var array