# Project Settings Interface Implementation

## Overview

This document describes the implementation of the comprehensive project settings interface with tabbed navigation for managing episodes, task templates, and upload locations.

## Features Implemented

### 1. Tabbed Interface

The project settings page now includes a tabbed interface with six sections:

- **General**: Basic project information (name, code, client, type, status, dates)
- **Episodes**: Episode management for organizing shots
- **Team**: Project member management with department roles
- **Technical**: Technical specifications (frame rate, storage paths, delivery specs)
- **Tasks**: Default task templates for assets and shots
- **Storage**: Upload location configuration

### 2. Episode Management Section

**Location**: `frontend/src/components/settings/EpisodeManagementSection.vue`

**Features**:
- View all episodes in a table format with episode number, name, status, shot count, and description
- Create new episodes with name, episode number, description, and status
- Edit existing episodes
- Delete episodes (with protection for episodes containing shots)
- Sort episodes by episode number
- Visual status indicators with color-coded badges
- Inline actions for edit and delete

**Episode Statuses**:
- Planning (secondary badge)
- In Progress (default badge)
- On Hold (outline badge)
- Completed (success badge)
- Cancelled (destructive badge)

**Validation**:
- Cannot delete episodes that contain shots
- Episode number must be unique within the project
- All fields validated before submission

### 3. Default Task Templates Editor

**Location**: `frontend/src/components/settings/DefaultTaskTemplatesEditor.vue`

**Features**:
- Configure default tasks for each asset category:
  - **Characters**: modeling, surfacing, rigging
  - **Props**: modeling, surfacing
  - **Sets**: modeling, surfacing
  - **Vehicles**: modeling, surfacing, rigging
- Configure default tasks for shots:
  - Layout, Animation, Simulation, Lighting, Compositing
- Enable/disable individual tasks per category
- Preview section showing how templates will be applied
- Reset to defaults button
- Save/cancel actions

**Default Templates**:
```javascript
{
  assetTemplates: {
    characters: ['modeling', 'surfacing', 'rigging'],
    props: ['modeling', 'surfacing'],
    sets: ['modeling', 'surfacing'],
    vehicles: ['modeling', 'surfacing', 'rigging']
  },
  shotTemplates: ['layout', 'animation', 'simulation', 'lighting', 'compositing']
}
```

### 4. Upload Location Configuration

**Location**: `frontend/src/components/settings/UploadLocationConfig.vue`

**Features**:
- Configure custom upload data location for the project
- File path input with validation
- Clear button to reset to default
- Example paths for Windows, Linux/Mac, and Network locations
- Info box explaining the configuration
- Save/cancel actions

**Example Paths**:
- Windows: `D:\Projects\ProjectName\Uploads`
- Linux/Mac: `/mnt/storage/projects/project-name/uploads`
- Network: `\\server\projects\project-name\uploads`

## Backend Implementation

### Database Schema Changes

Added new columns to the `projects` table:

```sql
ALTER TABLE projects ADD COLUMN upload_data_location TEXT;
ALTER TABLE projects ADD COLUMN asset_task_templates TEXT;
ALTER TABLE projects ADD COLUMN shot_task_templates TEXT;
ALTER TABLE projects ADD COLUMN enabled_asset_tasks TEXT;
ALTER TABLE projects ADD COLUMN enabled_shot_tasks TEXT;
```

**Migration Script**: `backend/migrate_project_settings.py`

### API Endpoints

#### Get Project Settings
```
GET /projects/{project_id}/settings
```

**Response**:
```json
{
  "upload_data_location": "/mnt/projects/project-name/uploads",
  "asset_task_templates": {
    "characters": ["modeling", "surfacing", "rigging"],
    "props": ["modeling", "surfacing"],
    "sets": ["modeling", "surfacing"],
    "vehicles": ["modeling", "surfacing", "rigging"]
  },
  "shot_task_templates": ["layout", "animation", "simulation", "lighting", "compositing"],
  "enabled_asset_tasks": {},
  "enabled_shot_tasks": []
}
```

#### Update Project Settings
```
PUT /projects/{project_id}/settings
```

**Request Body**:
```json
{
  "upload_data_location": "/mnt/projects/project-name/uploads",
  "asset_task_templates": {
    "characters": ["modeling", "surfacing", "rigging"]
  },
  "shot_task_templates": ["layout", "animation", "lighting"]
}
```

**Response**: Same as GET response

### Authorization

- **Coordinators** and **Admins** can modify project settings
- **Artists** and **Directors** can view project settings (read-only)
- Artists can only access settings for projects they are members of

## Frontend Service Layer

### Project Service Updates

**Location**: `frontend/src/services/project.ts`

Added new methods:

```typescript
async getProjectSettings(projectId: number): Promise<ProjectSettings>
async updateProjectSettings(projectId: number, settings: ProjectSettings): Promise<ProjectSettings>
```

**Types**:
```typescript
interface AssetTaskTemplates {
  characters: string[]
  props: string[]
  sets: string[]
  vehicles: string[]
}

interface ProjectSettings {
  upload_data_location?: string
  asset_task_templates?: AssetTaskTemplates
  shot_task_templates?: string[]
  enabled_asset_tasks?: Record<string, string[]>
  enabled_shot_tasks?: string[]
}
```

## User Experience

### Navigation Flow

1. User navigates to Project Settings from the project detail page
2. Settings page loads with tabbed interface
3. User can switch between tabs to manage different aspects
4. Changes are saved per section with immediate feedback
5. Toast notifications confirm successful saves

### Episode Management Flow

1. User clicks "Episodes" tab
2. View list of existing episodes sorted by episode number
3. Click "New Episode" to create a new episode
4. Fill in episode details (number, name, description, status)
5. Click "Create Episode" to save
6. Episode appears in the list immediately
7. Edit or delete episodes using action buttons
8. Cannot delete episodes with shots (protection)

### Task Templates Flow

1. User clicks "Tasks" tab
2. View current task templates for assets and shots
3. Check/uncheck tasks to enable/disable them
4. Preview section shows how templates will be applied
5. Click "Reset to Defaults" to restore default templates
6. Click "Save Templates" to apply changes
7. Toast notification confirms save

### Upload Location Flow

1. User clicks "Storage" tab
2. View current upload location (if set)
3. Enter new file path or clear existing path
4. View example paths for reference
5. Click "Save Configuration" to apply
6. Toast notification confirms save

## Requirements Satisfied

This implementation satisfies the following requirements from the spec:

### Requirement 3 (Episode Management in Settings)
- ✅ 3.1: Episode management within project settings page
- ✅ 3.2: Episodes management section in project settings
- ✅ 3.3: Create new episodes with name, number, and status
- ✅ 3.4: Edit existing episode details
- ✅ 3.5: Delete episodes with no associated shots
- ✅ 3.6: Prevent deletion of episodes with shots
- ✅ 3.7: Display episode list with status and shot count
- ✅ 3.8: Support episode statuses (planning, in_progress, on_hold, completed, cancelled)
- ✅ 3.9: Sort episodes by episode number

### Requirement 19 (Project Settings)
- ✅ 19.1: Configure upload data storage locations per project
- ✅ 19.2: Define custom default task templates for assets per project
- ✅ 19.3: Define custom default task templates for shots per project
- ✅ 19.4: Support different task templates for different asset categories
- ✅ 19.5: Support different task templates for different shot types
- ✅ 19.6: Enable or disable specific default tasks per project
- ✅ 19.7: Apply project-specific upload locations to all file uploads
- ✅ 19.8: Use project-specific default task templates when creating assets and shots
- ✅ 19.9: Provide project settings interface for coordinators

## Testing

### Manual Testing Checklist

- [ ] Navigate to project settings page
- [ ] Switch between all tabs
- [ ] Create a new episode
- [ ] Edit an existing episode
- [ ] Try to delete an episode with shots (should fail)
- [ ] Delete an episode without shots (should succeed)
- [ ] Modify asset task templates
- [ ] Modify shot task templates
- [ ] Reset templates to defaults
- [ ] Save task templates
- [ ] Configure upload location
- [ ] Clear upload location
- [ ] Save upload location
- [ ] Verify all changes persist after page reload

### API Testing

Run the test script:
```bash
cd backend
python test_project_settings.py
```

## Future Enhancements

1. **Task Template Presets**: Save and load custom template presets
2. **Bulk Episode Operations**: Create multiple episodes at once
3. **Episode Templates**: Define episode templates with default shots
4. **Storage Validation**: Validate that storage paths exist and are writable
5. **Task Dependencies**: Define task dependencies in templates
6. **Custom Task Types**: Allow creation of custom task types per project
7. **Template Inheritance**: Inherit templates from parent projects or global defaults

## Notes

- Episode management is now centralized in project settings instead of a separate page
- This provides a better user experience with all project configuration in one place
- The tabbed interface makes it easy to navigate between different settings sections
- All changes are saved immediately with visual feedback
- The implementation follows the existing patterns in the codebase
