# High Settings Screen — Full Actions Documentation

## Overview
The High Settings screen is a complete developer operations panel for administrators. It covers Laravel maintenance, Git operations, environment configuration, server diagnostics, and performance optimization. The screen follows Keen theme 3.5 design patterns and uses an OOP JavaScript IIFE module (`KTHighSettings`) with `KTUtil.onDOMContentLoaded` initialization.

---

## Available Actions

### 1. Server Information *(auto-loads on page open)*
- **Card**: Full-width, auto-populated on `init()`
- **Route**: `GET /admin/high-settings/server-info`
- **Controller**: `HighSettingsController@serverInfo`
- **Displays**: PHP version, Laravel version, App environment, Debug mode (ON/OFF), Disk usage progress bar (used / total / free)
- **Refresh Button**: Re-calls `KTHighSettings.refreshServerInfo()`

---

### 2. Git Status *(auto-loads on page open)*
- **Card**: 8-column width, auto-populated on `init()`
- **Route**: `GET /admin/high-settings/git-status`
- **Controller**: `HighSettingsController@gitStatus`
- **Displays**: Current branch badge, staged/modified/untracked file lists, recent 5 commits
- **Refresh Button**: Re-calls `KTHighSettings.refreshGitStatus()`
- **Side Effect**: Also called automatically after pull, commit, stash, stash-pop

---

### 3. Git Diff
- **Button**: "Show Diff" (light-warning)
- **Route**: `GET /admin/high-settings/git-diff`
- **Controller**: `HighSettingsController@gitDiff`
- **Runs**: `git diff --stat`
- **Output**: Rendered in scrollable `<pre>` with Copy button

---

### 4. Cache Management
- **Button**: "Clear All Cache" (red) — requires SweetAlert2 confirmation
- **Route**: `POST /admin/high-settings/clear-cache`
- **Controller**: `HighSettingsController@clearCache`
- **Runs**: `cache:clear`, `config:clear`, `route:clear`, `view:clear` via `Artisan::call()`

---

### 5. Database Migrations
- **Button**: "Run Migrations" (blue) — requires SweetAlert2 confirmation
- **Route**: `POST /admin/high-settings/run-migrate`
- **Controller**: `HighSettingsController@runMigrate`
- **Runs**: `php artisan migrate --force`

---

### 6. Optimize Application
- **Button**: "Optimize All" (green)
- **Route**: `POST /admin/high-settings/optimize`
- **Controller**: `HighSettingsController@optimizeApp`
- **Runs**: `config:cache`, `route:cache`, `view:cache`
- **Use Case**: Maximize performance before production deployment

---

### 7. Storage Link
- **Button**: "Create Storage Link" (info/teal)
- **Route**: `POST /admin/high-settings/storage-link`
- **Controller**: `HighSettingsController@storageLink`
- **Runs**: `php artisan storage:link`
- **Use Case**: Create `public/storage` symlink after fresh install or deployment

---

### 8. Git Configuration
- **Form**: User Name + User Email (with FormValidation plugin validation)
- **Route**: `POST /admin/high-settings/set-git-config`
- **Controller**: `HighSettingsController@setGitConfig`
- **Runs**: `git config --global user.name`, `git config --global user.email`
- **Validation**: `required|string` for name, `required|email` for email (backend + FormValidation frontend)

---

### 9. Git Repository

#### Initialize Repository
- **Button**: "Initialize Repository" (dark)
- **Route**: `POST /admin/high-settings/git-init`
- **Controller**: `HighSettingsController@gitInit`
- **Runs**: `git init`

#### Configure Remote
- **Input**: Remote URL field
- **Button**: "Update Remote" (secondary)
- **Route**: `POST /admin/high-settings/git-remote`
- **Controller**: `HighSettingsController@setGitRemote`
- **Runs**: `git remote add origin <url>` or `git remote set-url origin <url>`

#### Stash Changes
- **Button**: "Stash Changes" (light-warning) — requires SweetAlert2 confirmation
- **Route**: `POST /admin/high-settings/git-stash`
- **Controller**: `HighSettingsController@gitStash`
- **Runs**: `git stash`
- **Side Effect**: Refreshes Git Status card

#### Pop Stash
- **Button**: "Pop Stash" (light-primary) — requires SweetAlert2 confirmation
- **Route**: `POST /admin/high-settings/git-stash-pop`
- **Controller**: `HighSettingsController@gitStashPop`
- **Runs**: `git stash pop`
- **Side Effect**: Refreshes Git Status card

---

### 10. GitHub Operations

#### Pull from GitHub
- **Button**: "Pull from GitHub" (green)
- **Route**: `POST /admin/high-settings/git-pull`
- **Controller**: `HighSettingsController@gitPull`
- **Runs**: `git pull`
- **Side Effect**: Refreshes Git Status card on success

#### Commit Changes
- **Button**: "Commit Changes" (info) — opens commit modal
- **Modal**: Bootstrap modal with required commit message textarea
- **Route**: `POST /admin/high-settings/git-commit`
- **Controller**: `HighSettingsController@gitCommit`
- **Runs**: `git add .` + `git commit -m <message>`
- **Side Effect**: Refreshes Git Status card on success

#### Push to GitHub
- **Button**: "Push to GitHub" (warning) — requires SweetAlert2 confirmation
- **Route**: `POST /admin/high-settings/git-push`
- **Controller**: `HighSettingsController@gitPush`
- **Runs**: `git push origin <current-branch>` (or `GIT_REPO_URL` if set in `.env`)

---

### 11. Git History
- **Button**: "Load History" (light-dark, in card toolbar)
- **Route**: `GET /admin/high-settings/git-log`
- **Controller**: `HighSettingsController@gitLog`
- **Runs**: `git log --pretty=format:"%h|%s|%an|%ar" -15`
- **Displays**: Table — Hash (monospace badge) | Message | Author | Relative date

---

### 12. Laravel Logs
- **Button**: "Load Recent Logs" (light-danger, in card toolbar)
- **Route**: `GET /admin/high-settings/view-logs`
- **Controller**: `HighSettingsController@viewLogs`
- **Reads**: Last 100 lines of `storage/logs/laravel.log`
- **Output**: Scrollable `<pre>` (max-height 400px) with Copy button

---

### 13. Environment Configuration
- **Control**: Dropdown selector (local / development / testing / staging / production)
- **Route**: `POST /admin/high-settings/set-environment`
- **Controller**: `HighSettingsController@setEnvironment`
- **Runs**: Updates `APP_ENV` in `.env` + `config:clear`

---

### 14. Debug Mode
- **Control**: Toggle switch
- **Route**: `POST /admin/high-settings/set-debug-mode`
- **Controller**: `HighSettingsController@setDebugMode`
- **Runs**: Updates `APP_DEBUG` in `.env` + `config:clear`

---

### 15. Generate Thumbnails
- **Button**: "Generate Thumbnails" (blue)
- **Route**: `POST /admin/high-settings/generate-thumbnails`
- **Controller**: `HighSettingsController@generateThumbnails`
- **Runs**: `php artisan images:generate-thumbnails`
- **Covers**: Cities, Countries, Categories, Banners, Blog Images, Bouquet Images (sizes 256×144 and 426×240)

---

## Technical Implementation

### JavaScript Architecture
- **Class**: `KTHighSettings`
- **Pattern**: IIFE module — `var KTHighSettings = function () { ... }();`
- **Private functions**: Arrow functions (`const name = () => {}`)
- **Initialization**: `KTUtil.onDOMContentLoaded(() => { KTHighSettings.init(); })`
- **CSRF**: All requests include `X-CSRF-TOKEN` and `X-Requested-With` headers
- **HTTP**: `fetch()` via `_post()` (POST with JSON/FormData) and `_get()` (GET)

### UX Patterns
- **Loading states**: `data-kt-indicator="on"/"off"` on all action buttons
- **Confirmations**: `Swal.fire()` (SweetAlert2) before destructive/network actions
- **Output display**: `_showResult()` renders success/danger alert + scrollable `<pre>` + Copy button
- **Copy-to-clipboard**: `navigator.clipboard.writeText()` on all output blocks
- **Form validation**: `FormValidation.formValidation()` on git config form
- **Auto-load**: Server info + Git status populate automatically on page load

### Backend Helpers
- `runProcess(array $command)` — Symfony Process, 120s timeout, returns `{ success, output }`
- `updateEnvValue(string $key, string $value)` — regex replace in `.env` file
- `formatBytes(int $bytes)` — converts bytes to human-readable KB/MB/GB

### Security
- `auth:admin` middleware on all routes
- CSRF protection on all POST routes
- Input validation on every controller method
- Git commands run through Symfony Process (no `shell_exec`)

---

## Route Summary

| Method | URI | Name | Action |
|--------|-----|------|--------|
| GET | `/admin/high-settings` | `admin.high-settings.index` | `index` |
| GET | `/admin/high-settings/server-info` | `admin.high-settings.server-info` | `serverInfo` |
| GET | `/admin/high-settings/git-status` | `admin.high-settings.git-status` | `gitStatus` |
| GET | `/admin/high-settings/git-log` | `admin.high-settings.git-log` | `gitLog` |
| GET | `/admin/high-settings/git-diff` | `admin.high-settings.git-diff` | `gitDiff` |
| GET | `/admin/high-settings/view-logs` | `admin.high-settings.view-logs` | `viewLogs` |
| POST | `/admin/high-settings/clear-cache` | `admin.high-settings.clear-cache` | `clearCache` |
| POST | `/admin/high-settings/run-migrate` | `admin.high-settings.run-migrate` | `runMigrate` |
| POST | `/admin/high-settings/optimize` | `admin.high-settings.optimize` | `optimizeApp` |
| POST | `/admin/high-settings/storage-link` | `admin.high-settings.storage-link` | `storageLink` |
| POST | `/admin/high-settings/set-git-config` | `admin.high-settings.set-git-config` | `setGitConfig` |
| POST | `/admin/high-settings/git-init` | `admin.high-settings.git-init` | `gitInit` |
| POST | `/admin/high-settings/git-remote` | `admin.high-settings.git-remote` | `setGitRemote` |
| POST | `/admin/high-settings/git-stash` | `admin.high-settings.git-stash` | `gitStash` |
| POST | `/admin/high-settings/git-stash-pop` | `admin.high-settings.git-stash-pop` | `gitStashPop` |
| POST | `/admin/high-settings/git-pull` | `admin.high-settings.git-pull` | `gitPull` |
| POST | `/admin/high-settings/git-commit` | `admin.high-settings.git-commit` | `gitCommit` |
| POST | `/admin/high-settings/git-push` | `admin.high-settings.git-push` | `gitPush` |
| POST | `/admin/high-settings/set-environment` | `admin.high-settings.set-environment` | `setEnvironment` |
| POST | `/admin/high-settings/set-debug-mode` | `admin.high-settings.set-debug-mode` | `setDebugMode` |
| POST | `/admin/high-settings/generate-thumbnails` | `admin.high-settings.generate-thumbnails` | `generateThumbnails` |
