# Default View Changes - File Manager

## Changes Made

### 1. All Folders Start Collapsed
- All folders now show `+` (collapsed) by default
- User must click `+` to expand and see children
- Cleaner initial view with less visual clutter

### 2. Default Filter Changed to "All Files"
- Previous default: "User Files" (only showed user context folders)
- New default: "All Files" (shows all folders you have permission to see)
- More intuitive starting point for admins

## Technical Implementation

### 1. Folders Start Collapsed

**JavaScript** (`public/js/file-manager.js` line 313):
```javascript
// Before:
const expandClass = level === 0 ? 'expand' : '';

// After:
// Start all folders collapsed (no expand class by default)
```

**PHP** (`views/file_manager/index.php` line 437):
```php
// Before:
$expandClass = $level === 0 ? 'expand' : '';

// After:
// Start all folders collapsed (no expand class by default)
```

Result: All folders render without the `.expand` class, so they show `+` instead of `-`

### 2. Default to "All Files"

**View** (`views/file_manager/index.php` line 109):
```html
<!-- Before -->
<option value="">All Files</option>
<option value="user" selected>User Files</option>

<!-- After -->
<option value="" selected>All Files</option>
<option value="user">User Files</option>
```

**Controller** (`controllers/FileManagerController.php` lines 24-25, 97-98):
```php
// Before:
$entityType = $_GET['context'] ?? 'system';

// After:
// Default to All Files (null) when no context provided
$entityType = isset($_GET['context']) && $_GET['context'] !== '' ? $_GET['context'] : null;
```

Result: When no `?context=` parameter is provided, `$entityType` is `null`, which tells the model to fetch ALL folders

## How It Works Now

### Initial Page Load
1. Navigate to `http://localhost:8080/files`
2. No `?context=` parameter → defaults to `null`
3. Dropdown shows "All Files" selected
4. Sidebar shows ALL folders (that you have permission to view)
5. All folders show `+` (collapsed)

### Selecting a Context Filter
1. Click dropdown and select "HR"
2. URL updates (optionally) or context passed to API
3. Sidebar reloads showing only HR folders
4. All folders show `+` (collapsed)
5. Main area resets to root

### Expanding Folders
1. Click `+` next to a folder name
2. `+` changes to `-`
3. Child folders appear indented below
4. Click `-` to collapse again

## User Experience Improvements

### Before:
```
- 📁 HR Files              ← expanded by default
    📁 Applications
    📁 NewHireForms
    📁 OfferDocs
- 📁 User Files            ← expanded by default
    📁 Battery Safety
📁 Accounting Files        ← collapsed
```
**Problems:**
- Top-level folders auto-expanded → visual clutter
- Defaulted to "User Files" filter → confusing for admins
- Had to scroll through many expanded folders

### After:
```
+ 📁 Accounting Files      ← all collapsed
+ 📁 CRM Files             ← all collapsed
+ 📁 Customer Files        ← all collapsed
+ 📁 HR Files              ← all collapsed
+ 📁 User Files            ← all collapsed
```
**Benefits:**
- ✅ Clean, organized initial view
- ✅ Shows all available folders at a glance
- ✅ User controls what to expand
- ✅ Less scrolling needed
- ✅ "All Files" is more intuitive default

## Context Filter Behavior

| Filter Selected | What You See | Default State |
|----------------|--------------|---------------|
| **All Files** | All folders across all contexts | All collapsed |
| **System** | Only System folders | All collapsed |
| **User Files** | Only User folders | All collapsed |
| **HR** | Only HR folders and children | All collapsed |
| **Accounting** | Only Accounting folders | All collapsed |
| etc. | ... | All collapsed |

## Permission Handling

- **Admin users**: See all folders when "All Files" is selected
- **Regular users**: See only folders for modules they have permission to access
- **Permission check**: Skipped when context is `null` (All Files mode)
- **Individual contexts**: Permission still enforced (e.g., can't see HR if no `hr.view` permission)

## Testing

### 1. Clear Browser Cache
```bash
# Hard refresh: Cmd+Shift+R (Mac) or Ctrl+Shift+R (Windows)
```

### 2. Test Default View
1. Navigate to http://localhost:8080/files
2. Verify:
   - ✅ Dropdown shows "All Files" selected
   - ✅ Sidebar shows all folders you have access to
   - ✅ All folders show `+` (none are expanded)

### 3. Test Expansion
1. Click `+` next to a folder with children (e.g., HR Files)
2. Verify:
   - ✅ `+` changes to `-`
   - ✅ Child folders appear
   - ✅ Click `-` collapses again

### 4. Test Filter Changes
1. Select "HR" from dropdown
2. Verify:
   - ✅ Sidebar shows only HR-related folders
   - ✅ All shown folders start collapsed (`+`)
3. Select "All Files" again
4. Verify:
   - ✅ All folders reappear
   - ✅ Reset to collapsed state

## Notes

- Collapse/expand state is **not persisted** across page reloads
- Each filter change resets all folders to collapsed
- Navigating to a specific folder will highlight it but won't auto-expand its parent
- Empty folders (no children) show invisible spacer for alignment
