LinkDesk/backend/docs/default-asset-tasks-impleme...

6.8 KiB

Default Asset Task Creation Implementation

Overview

This document describes the implementation of automatic default task creation for assets based on their category (Task 5.3).

Requirements Implemented

  • 17.1: Automatic task generation when assets are created based on asset category
  • 17.2: Default task templates for each asset category (modeling, surfacing, rigging)
  • 17.3: Customizable task creation options for coordinators
  • 17.4: Default task naming conventions
  • 17.5: API endpoint for retrieving default tasks by asset category
  • 17.6: Proper task naming
  • 17.7: Unassigned task creation

Backend Implementation

Default Task Templates

Located in backend/routers/assets.py:

DEFAULT_ASSET_TASKS = {
    AssetCategory.CHARACTERS: ["modeling", "surfacing", "rigging"],
    AssetCategory.PROPS: ["modeling", "surfacing"],
    AssetCategory.SETS: ["modeling", "surfacing"],
    AssetCategory.VEHICLES: ["modeling", "surfacing", "rigging"]
}

Key Functions

get_default_asset_task_types(category: AssetCategory) -> List[str]

Returns the default task types for a given asset category.

get_all_asset_task_types(project_id: int, db: Session) -> List[str]

Returns all task types (standard + custom) for assets in a project.

create_default_tasks_for_asset(asset: Asset, task_types: List[str], db: Session) -> List[Task]

Creates default tasks for an asset with proper naming conventions:

  • Task name format: {asset_name} - {task_type.title()}
  • Tasks are created with status NOT_STARTED
  • Tasks are left unassigned (assigned_user_id = None)

API Endpoints

GET /assets/default-tasks/{category}

Returns default task types for an asset category.

Query Parameters:

  • project_id (optional): Include custom task types for the project

Response:

["modeling", "surfacing", "rigging"]

POST /assets/?project_id={project_id}

Creates a new asset with optional default tasks.

Request Body:

{
  "name": "Hero Character",
  "category": "characters",
  "description": "Main character asset",
  "status": "not_started",
  "create_default_tasks": true,
  "selected_task_types": ["modeling", "surfacing", "rigging"]
}

Fields:

  • create_default_tasks (boolean): Whether to create default tasks (default: true)
  • selected_task_types (array, optional): Specific task types to create. If not provided, uses category defaults.

Response:

{
  "id": 1,
  "name": "Hero Character",
  "category": "characters",
  "status": "not_started",
  "project_id": 1,
  "task_count": 3,
  "created_at": "2024-01-01T00:00:00Z",
  "updated_at": "2024-01-01T00:00:00Z"
}

Frontend Implementation

AssetForm Component

Located in frontend/src/components/asset/AssetForm.vue

Features:

  1. Default Tasks Toggle: Checkbox to enable/disable default task creation
  2. Task Preview: Shows which tasks will be created based on category
  3. Custom Task Selection: Allows coordinators to select specific tasks to create
  4. Confirmation Dialog: Shows preview of tasks before creation

Key Sections:

<!-- Default Tasks Section -->
<div v-if="!isEdit" class="space-y-4 border-t pt-4">
  <div class="flex items-center space-x-2">
    <Checkbox 
      id="create-default-tasks"
      v-model:checked="formData.create_default_tasks"
    />
    <Label>Create default tasks for this asset</Label>
  </div>
  
  <!-- Task Selection -->
  <div v-if="formData.create_default_tasks && formData.category">
    <div v-for="taskType in defaultTasks" :key="taskType">
      <Checkbox 
        :checked="selectedTaskTypes.includes(taskType)"
        @update:checked="toggleTaskType(taskType)"
      />
      <Label>{{ formatTaskType(taskType) }}</Label>
    </div>
  </div>
</div>

Asset Service

Located in frontend/src/services/asset.ts

Methods:

async getDefaultTasksForCategory(
  category: AssetCategory, 
  projectId?: number
): Promise<string[]>

async createAsset(
  projectId: number, 
  data: AssetCreate
): Promise<Asset>

Task Naming Convention

Tasks are automatically named using the format:

{Asset Name} - {Task Type}

Examples:

  • "Hero Character - Modeling"
  • "Hero Character - Surfacing"
  • "Hero Character - Rigging"
  • "Sword Prop - Modeling"
  • "Sword Prop - Surfacing"

Task Assignment

All default tasks are created unassigned (assigned_user_id = null). Coordinators must manually assign tasks to artists after creation.

Category-Specific Defaults

Category Default Tasks
Characters Modeling, Surfacing, Rigging
Props Modeling, Surfacing
Sets Modeling, Surfacing
Vehicles Modeling, Surfacing, Rigging

Custom Task Types

The system supports custom task types per project. When a project has custom asset task types defined, they are included in the available task types for selection during asset creation.

Testing

Backend Test

Run backend/test_default_asset_tasks.py to verify:

  • Default task templates for each category
  • Asset creation with default tasks
  • Task naming conventions
  • Custom task selection
  • Unassigned task creation

Frontend Test

Open frontend/test-default-asset-tasks.html to test:

  • Default task retrieval
  • Asset creation with task selection
  • Task verification

Usage Example

Creating an Asset with Default Tasks

  1. Navigate to Assets section in a project
  2. Click "Create Asset"
  3. Fill in asset details (name, category, description)
  4. Ensure "Create default tasks" is checked
  5. Review the task preview
  6. Optionally customize which tasks to create
  7. Click "Create Asset"
  8. Confirm task creation in the dialog

Creating an Asset without Default Tasks

  1. Follow steps 1-3 above
  2. Uncheck "Create default tasks"
  3. Click "Create Asset"
  4. Asset is created with no tasks

Custom Task Selection

  1. Follow steps 1-4 above
  2. Uncheck specific tasks you don't want to create
  3. Click "Create Asset"
  4. Only selected tasks will be created

Integration with Custom Task Types

When custom task types are defined for a project (via Task 19), they are automatically included in the available task types for asset creation. The default task templates remain the same, but coordinators can select custom task types during asset creation.

Error Handling

  • Validates that selected task types are valid (standard or custom)
  • Prevents duplicate asset names within a project
  • Returns appropriate error messages for invalid requests
  • Handles missing project or category gracefully

Performance Considerations

  • Tasks are created in a single database transaction
  • Bulk task creation is efficient using SQLAlchemy's bulk operations
  • Task count is returned immediately after creation without additional queries