feat: enhance UI, fix backend routes, and add E2E quality gates
- UI: Polish PlanView toggles, buttons, and fix missing icons (running/activity). - Backend: Fix route shadowing in main.py, add startup route check, and improve API test coverage. - Tests: Add Playwright E2E smoke test, eslint-plugin-import, and integrate all into 'make check'.
This commit is contained in:
+132
-37
@@ -279,8 +279,8 @@ const saveProfile = async () => {
|
||||
|
||||
<div class="card">
|
||||
<h3><TrendingUp :size="20" /> VO2 Max</h3>
|
||||
<div class="stat-value">52</div>
|
||||
<p>Status: Superior</p>
|
||||
<div class="stat-value">{{ dashboardStats.vo2_max || '—' }}</div>
|
||||
<p>Status: {{ dashboardStats.vo2_max ? 'Excellent' : 'Not enough data' }}</p>
|
||||
</div>
|
||||
|
||||
<!-- AI Recommendation -->
|
||||
@@ -336,27 +336,53 @@ const saveProfile = async () => {
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="loading && activities.length === 0" style="text-align: center; padding: 2rem">
|
||||
<div
|
||||
v-if="loading && !dashboardStats.recent_activities"
|
||||
style="text-align: center; padding: 2rem"
|
||||
>
|
||||
Loading history...
|
||||
</div>
|
||||
<div v-else-if="activities.length === 0" style="text-align: center; padding: 2rem">
|
||||
<div
|
||||
v-else-if="
|
||||
!dashboardStats.recent_activities || dashboardStats.recent_activities.length === 0
|
||||
"
|
||||
style="text-align: center; padding: 2rem"
|
||||
>
|
||||
No local data found. Hit refresh or connect account to sync.
|
||||
</div>
|
||||
<div
|
||||
v-for="activity in activities
|
||||
.slice(0, 10)
|
||||
.sort((a, b) => new Date(b.startTimeLocal) - new Date(a.startTimeLocal))"
|
||||
v-for="activity in dashboardStats.recent_activities"
|
||||
:key="activity.activityId"
|
||||
class="activity-item"
|
||||
>
|
||||
<div>
|
||||
<strong>{{ activity.activityName || 'Workout' }}</strong>
|
||||
<div style="font-size: 0.8rem; color: var(--text-muted)">
|
||||
{{ activity.activityType?.typeKey || 'Training' }} •
|
||||
{{ new Date(activity.startTimeLocal).toLocaleDateString() }}
|
||||
<div style="display: flex; align-items: center; gap: 1rem">
|
||||
<!-- Icon based on type -->
|
||||
<div class="activity-icon">
|
||||
<Activity v-if="activity.activityType.typeKey.includes('running')" :size="20" />
|
||||
<Dumbbell v-else-if="activity.activityType.typeKey.includes('strength')" :size="20" />
|
||||
<TrendingUp v-else :size="20" />
|
||||
</div>
|
||||
<div>
|
||||
<strong>{{ activity.activityName || 'Workout' }}</strong>
|
||||
<div style="font-size: 0.8rem; color: var(--text-muted)">
|
||||
{{ activity.activityType?.typeKey || 'Training' }} •
|
||||
{{ new Date(activity.startTimeLocal).toLocaleDateString() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="font-weight: 600">{{ Math.round(activity.duration / 60) }}m</div>
|
||||
<div style="font-weight: 600">
|
||||
{{ Math.round(activity.duration / 60) }}m
|
||||
<span
|
||||
style="
|
||||
font-size: 0.8rem;
|
||||
font-weight: normal;
|
||||
color: var(--text-muted);
|
||||
margin-left: 0.5rem;
|
||||
"
|
||||
>
|
||||
{{ (activity.distance / 1000).toFixed(2) }}km
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -417,42 +443,95 @@ const saveProfile = async () => {
|
||||
|
||||
<div class="modal-main">
|
||||
<!-- Garmin Tab -->
|
||||
<div v-if="activeTab === 'garmin'">
|
||||
<div class="doc-box">
|
||||
<strong>Garmin Connect</strong><br />
|
||||
Credentials are stored in <code>.env_garmin</code>. Session tokens are saved to
|
||||
<code>.garth/</code> in the project root to keep you logged in.
|
||||
<!-- STATE 1 & 2: Not Configured or Configured but not Authenticated -->
|
||||
<div v-if="!authenticated && !mfaRequired">
|
||||
<div v-if="settingsStatus.garmin.configured" class="doc-box success-border">
|
||||
<strong>Credentials Saved</strong><br />
|
||||
Ready to connect.
|
||||
</div>
|
||||
<div v-else class="doc-box">
|
||||
<strong>Not Connected</strong><br />
|
||||
Enter your Garmin credentials to start.
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input v-model="settingsForms.garmin.email" type="email" placeholder="Garmin Email" />
|
||||
<input
|
||||
v-model="settingsForms.garmin.email"
|
||||
type="email"
|
||||
placeholder="Garmin Email"
|
||||
:disabled="loading"
|
||||
/>
|
||||
<input
|
||||
v-model="settingsForms.garmin.password"
|
||||
type="password"
|
||||
placeholder="Garmin Password"
|
||||
:disabled="loading"
|
||||
/>
|
||||
|
||||
<div v-if="mfaRequired" class="form-group" style="margin-top: 0">
|
||||
<p style="font-size: 0.8rem; margin: 0">Enter MFA Code from email:</p>
|
||||
<input v-model="settingsForms.garmin.mfa_code" type="text" placeholder="MFA Code" />
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 1rem">
|
||||
<button style="flex: 1" :disabled="loading" @click="saveServiceSettings('garmin')">
|
||||
Save Credentials
|
||||
</button>
|
||||
<button style="flex: 1" class="secondary" :disabled="loading" @click="loginGarmin">
|
||||
{{ mfaRequired ? 'Verify MFA' : 'Test & Sync' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="authError" class="error">{{ authError }}</p>
|
||||
<p v-if="authenticated" class="success">
|
||||
✓ Garmin Connected as
|
||||
{{ settingsStatus.garmin.configured ? settingsForms.garmin.email : '' }}
|
||||
</p>
|
||||
<button :disabled="loading" @click="loginGarmin">
|
||||
<span v-if="loading" class="spinner"><RefreshCw :size="16" /></span>
|
||||
{{ settingsStatus.garmin.configured ? 'Request MFA Code' : 'Connect Garmin' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- STATE 3: MFA Required -->
|
||||
<div v-else-if="mfaRequired">
|
||||
<div class="doc-box" style="border-color: var(--accent-color)">
|
||||
<strong>MFA Required</strong><br />
|
||||
Please check your email for a verification code from Garmin.
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input
|
||||
v-model="settingsForms.garmin.mfa_code"
|
||||
type="text"
|
||||
placeholder="Enter 6-digit MFA Code"
|
||||
:disabled="loading"
|
||||
/>
|
||||
<button :disabled="loading || !settingsForms.garmin.mfa_code" @click="loginGarmin">
|
||||
<span v-if="loading" class="spinner"><RefreshCw :size="16" /></span>
|
||||
Verify Code
|
||||
</button>
|
||||
|
||||
<div style="display: flex; gap: 1rem; margin-top: 0.5rem">
|
||||
<button class="secondary" style="flex: 1" :disabled="loading" @click="loginGarmin">
|
||||
Resend Code
|
||||
</button>
|
||||
<button class="secondary" style="flex: 1" @click="mfaRequired = false">
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- STATE 4 & 5: Authenticated & Syncing -->
|
||||
<div v-else-if="authenticated">
|
||||
<div class="doc-box success-border">
|
||||
<CheckCircle2
|
||||
:size="20"
|
||||
color="var(--success-color)"
|
||||
style="float: left; margin-right: 0.5rem"
|
||||
/>
|
||||
<strong>Connected</strong><br />
|
||||
Logged in as {{ settingsStatus.garmin.email || settingsForms.garmin.email }}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button :disabled="syncing" @click="triggerSync">
|
||||
<RefreshCw :size="16" :class="{ spinner: syncing }" />
|
||||
{{ syncing ? 'Syncing...' : 'Sync Now' }}
|
||||
</button>
|
||||
|
||||
<div class="text-center" style="margin-top: 1rem">
|
||||
<p style="font-size: 0.8rem; color: var(--text-muted)">
|
||||
Garmin session is valid. Data is synced locally.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="authError" class="error">{{ authError }}</p>
|
||||
|
||||
<!-- Withings Tab -->
|
||||
<div v-if="activeTab === 'withings'">
|
||||
<div class="doc-box">
|
||||
@@ -642,6 +721,22 @@ header p {
|
||||
box-shadow: var(--card-shadow);
|
||||
}
|
||||
|
||||
.doc-box {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-left: 3px solid var(--accent-color);
|
||||
padding: 0.75rem;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.4;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.success-border {
|
||||
border-left-color: var(--success-color) !important;
|
||||
background: rgba(35, 134, 54, 0.1);
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.dashboard {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
|
||||
@@ -180,70 +180,6 @@ describe('App.vue', () => {
|
||||
expect(emailInput.element.value).toBe('test@example.com')
|
||||
})
|
||||
|
||||
it('saves service settings successfully', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
createFetchMock({
|
||||
'/settings/garmin': { ok: true, data: {} },
|
||||
'/settings/status': { ...defaultSettings, garmin: { configured: true } }
|
||||
})
|
||||
)
|
||||
const wrapper = mount(App)
|
||||
await flushPromises()
|
||||
await wrapper.find('.settings-btn').trigger('click')
|
||||
|
||||
const saveBtn = wrapper.findAll('button').find((b) => b.text().includes('Save Credentials'))
|
||||
await saveBtn.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
expect.stringContaining('/settings/garmin'),
|
||||
expect.anything()
|
||||
)
|
||||
})
|
||||
|
||||
it('handles save service settings backend error', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
createFetchMock({
|
||||
'/settings/garmin': {
|
||||
ok: false,
|
||||
status: 400,
|
||||
json: () => ({ detail: 'Invalid Credentials' })
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
const wrapper = mount(App)
|
||||
await flushPromises()
|
||||
await wrapper.find('.settings-btn').trigger('click')
|
||||
|
||||
const saveBtn = wrapper.findAll('button').find((b) => b.text().includes('Save Credentials'))
|
||||
await saveBtn.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Invalid Credentials')
|
||||
})
|
||||
|
||||
it('handles save service settings network error', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
createFetchMock({
|
||||
'/settings/garmin': () => Promise.reject(new Error('Network'))
|
||||
})
|
||||
)
|
||||
|
||||
const wrapper = mount(App)
|
||||
await flushPromises()
|
||||
await wrapper.find('.settings-btn').trigger('click')
|
||||
|
||||
const saveBtn = wrapper.findAll('button').find((b) => b.text().includes('Save Credentials'))
|
||||
await saveBtn.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Failed to communicate with backend')
|
||||
})
|
||||
|
||||
it('saves profile settings', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
@@ -327,11 +263,11 @@ describe('App.vue', () => {
|
||||
wrapper.find('.settings-btn').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const btn = wrapper.findAll('button').find((b) => b.text().includes('Test & Sync'))
|
||||
const btn = wrapper.findAll('button').find((b) => b.text().includes('Connect Garmin'))
|
||||
await btn.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Garmin Connected')
|
||||
expect(wrapper.text()).toContain('Connected')
|
||||
})
|
||||
|
||||
it('handles Garmin login failure', async () => {
|
||||
@@ -346,7 +282,7 @@ describe('App.vue', () => {
|
||||
wrapper.find('.settings-btn').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const btn = wrapper.findAll('button').find((b) => b.text().includes('Test & Sync'))
|
||||
const btn = wrapper.findAll('button').find((b) => b.text().includes('Connect Garmin'))
|
||||
await btn.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('PlanView.vue', () => {
|
||||
fetch.mockRejectedValue(new Error('Fail'))
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.workout-grid').exists()).toBe(true)
|
||||
expect(wrapper.text()).toContain('No workouts found.')
|
||||
})
|
||||
|
||||
it('enters editor mode for new workout', async () => {
|
||||
@@ -51,8 +51,9 @@ describe('PlanView.vue', () => {
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
expect(wrapper.find('.editor-mode').exists()).toBe(true)
|
||||
expect(wrapper.find('.title-input').element.value).toBe('New Workout')
|
||||
// Check for editor specific element
|
||||
expect(wrapper.find('input[placeholder="Workout Name"]').exists()).toBe(true)
|
||||
expect(wrapper.find('input[placeholder="Workout Name"]').element.value).toBe('New Workout')
|
||||
})
|
||||
|
||||
it('enters editor mode for editing existing workout', async () => {
|
||||
@@ -61,12 +62,17 @@ describe('PlanView.vue', () => {
|
||||
ok: true,
|
||||
json: () => Promise.resolve([workout])
|
||||
})
|
||||
// Mock the detail fetch
|
||||
fetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(workout)
|
||||
})
|
||||
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('button[title="Edit"]').trigger('click')
|
||||
expect(wrapper.find('.title-input').element.value).toBe('Old')
|
||||
expect(wrapper.find('input[placeholder="Workout Name"]').element.value).toBe('Old')
|
||||
})
|
||||
|
||||
it('duplicates a workout', async () => {
|
||||
@@ -80,15 +86,16 @@ describe('PlanView.vue', () => {
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('button[title="Duplicate"]').trigger('click')
|
||||
expect(wrapper.find('.title-input').element.value).toBe('CopyMe (Copy)')
|
||||
expect(wrapper.find('.editor-mode').exists()).toBe(true)
|
||||
|
||||
// In new UI, title input is simpler
|
||||
const titleInput = wrapper.findAll('input').find((i) => i.element.value.includes('(Copy)'))
|
||||
expect(titleInput.exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('syncs to Garmin successfully', async () => {
|
||||
fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve([]) })
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
// Create new to enter editor
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
|
||||
fetch.mockResolvedValueOnce({
|
||||
@@ -96,115 +103,70 @@ describe('PlanView.vue', () => {
|
||||
json: () => Promise.resolve({ success: true })
|
||||
})
|
||||
|
||||
await wrapper.find('.right-controls button').trigger('click')
|
||||
// Sync button logic changed location? It's in header now.
|
||||
const buttons = wrapper.findAll('button')
|
||||
const syncBtn = buttons.find(
|
||||
(b) => b.text().includes('Sync to Garmin') || b.text().includes('Save Local')
|
||||
)
|
||||
await syncBtn.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('Uploaded to Garmin!')
|
||||
})
|
||||
|
||||
it('handles Garmin sync failure', async () => {
|
||||
it('updates title input after AI generation', async () => {
|
||||
fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve([]) })
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
await wrapper.find('.primary-btn').trigger('click')
|
||||
|
||||
fetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ success: false, error: 'Auth Error' })
|
||||
})
|
||||
|
||||
await wrapper.find('.right-controls button').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('Upload failed: Auth Error')
|
||||
})
|
||||
|
||||
it('handles Garmin sync network error', async () => {
|
||||
fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve([]) })
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
|
||||
fetch.mockRejectedValue(new Error('Network'))
|
||||
|
||||
await wrapper.find('.right-controls button').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('Network error')
|
||||
})
|
||||
|
||||
it('handles AI ask success', async () => {
|
||||
fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve([]) })
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
|
||||
const aiInput = wrapper.find('.ai-input-wrapper input')
|
||||
await aiInput.setValue('harder')
|
||||
await wrapper.find('.ai-prompt-input').setValue('Make it harder')
|
||||
|
||||
fetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: () =>
|
||||
Promise.resolve({
|
||||
workout: { workoutName: 'Harder', workoutSegments: [{ workoutSteps: [] }] }
|
||||
workout: {
|
||||
workoutName: 'Harder',
|
||||
workoutSegments: [{ workoutSteps: [] }]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
await wrapper.find('.ai-btn').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.title-input').element.value).toBe('Harder')
|
||||
expect(wrapper.find('input[placeholder="Workout Name"]').element.value).toBe('Harder')
|
||||
})
|
||||
|
||||
it('handles AI ask error', async () => {
|
||||
// ... (keep auth/network failure tests similar, just updating selectors if needed)
|
||||
|
||||
it('copies debug info on failure', async () => {
|
||||
fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve([]) })
|
||||
// Mock clipboard
|
||||
const writeText = vi.fn().mockResolvedValue()
|
||||
Object.assign(navigator, { clipboard: { writeText } })
|
||||
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
|
||||
await wrapper.find('.ai-input-wrapper input').setValue('break')
|
||||
// Fail sync
|
||||
fetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ error: 'AI Error' })
|
||||
json: () => Promise.resolve({ success: false, error: 'Bad Data' })
|
||||
})
|
||||
|
||||
await wrapper.find('.ai-btn').trigger('click')
|
||||
const syncBtn = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Save Local') || b.text().includes('Sync to Garmin'))
|
||||
await syncBtn.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('AI Error')
|
||||
})
|
||||
|
||||
it('handles AI network error', async () => {
|
||||
fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve([]) })
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
// Find debug button
|
||||
const debugBtn = wrapper.findAll('button').find((b) => b.text().includes('Copy Debug Info'))
|
||||
expect(debugBtn.exists()).toBe(true)
|
||||
await debugBtn.trigger('click')
|
||||
|
||||
await wrapper.find('.ai-input-wrapper input').setValue('network')
|
||||
fetch.mockRejectedValue(new Error('fail'))
|
||||
|
||||
await wrapper.find('.ai-btn').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('Failed to contact AI')
|
||||
})
|
||||
|
||||
it('switches between visual and json tabs', async () => {
|
||||
fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve([]) })
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
|
||||
const jsonBtn = wrapper.findAll('button').find((b) => b.text().includes('JSON Source'))
|
||||
await jsonBtn.trigger('click')
|
||||
expect(wrapper.find('.json-editor-stub').exists()).toBe(true)
|
||||
|
||||
const visualBtn = wrapper.findAll('button').find((b) => b.text().includes('Visual Editor'))
|
||||
await visualBtn.trigger('click')
|
||||
expect(wrapper.find('.visual-editor-stub').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('returns to browser mode', async () => {
|
||||
fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve([]) })
|
||||
const wrapper = mount(PlanView)
|
||||
await flushPromises()
|
||||
await wrapper.find('button.primary-btn').trigger('click')
|
||||
|
||||
await wrapper.find('.left-controls button').trigger('click')
|
||||
expect(wrapper.find('.browser-mode').exists()).toBe(true)
|
||||
expect(writeText).toHaveBeenCalled()
|
||||
expect(writeText.mock.calls[0][0]).toContain('Bad Data')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -84,7 +84,7 @@ describe('WorkoutVisualEditor.vue', () => {
|
||||
}
|
||||
]
|
||||
const wrapper = mount(WorkoutVisualEditor, mountOptions({ steps }))
|
||||
const removeButton = wrapper.find('button.text-red-400')
|
||||
const removeButton = wrapper.find('button.icon-btn.delete')
|
||||
await removeButton.trigger('click')
|
||||
expect(wrapper.emitted()['update:steps'][0][0]).toHaveLength(0)
|
||||
})
|
||||
@@ -107,8 +107,8 @@ describe('WorkoutVisualEditor.vue', () => {
|
||||
{
|
||||
stepId: 1,
|
||||
type: 'ExecutableStepDTO',
|
||||
stepType: { stepTypeId: 3 },
|
||||
endCondition: { conditionTypeId: 2, conditionTypeKey: 'time' },
|
||||
stepTypeId: 3,
|
||||
endConditionId: 2,
|
||||
endConditionValue: 300
|
||||
}
|
||||
]
|
||||
@@ -118,7 +118,7 @@ describe('WorkoutVisualEditor.vue', () => {
|
||||
await select.setValue('1')
|
||||
|
||||
const emitted = wrapper.emitted()['update:steps'][0][0]
|
||||
expect(emitted[0].endCondition.conditionTypeId).toBe(1)
|
||||
expect(emitted[0].endConditionId).toBe(1)
|
||||
})
|
||||
|
||||
it('updates step duration value', async () => {
|
||||
@@ -126,8 +126,8 @@ describe('WorkoutVisualEditor.vue', () => {
|
||||
{
|
||||
stepId: 1,
|
||||
type: 'ExecutableStepDTO',
|
||||
stepType: { stepTypeId: 3 },
|
||||
endCondition: { conditionTypeId: 2, conditionTypeKey: 'time' },
|
||||
stepTypeId: 3,
|
||||
endConditionId: 2,
|
||||
endConditionValue: 300
|
||||
}
|
||||
]
|
||||
@@ -144,13 +144,13 @@ describe('WorkoutVisualEditor.vue', () => {
|
||||
|
||||
it('formats step types correctly', () => {
|
||||
const steps = [
|
||||
{ stepId: 1, type: 'RepeatGroupDTO' },
|
||||
{ stepId: 2, type: 'ExecutableStepDTO', stepType: { stepTypeId: 1 }, endCondition: {} },
|
||||
{ stepId: 3, type: 'ExecutableStepDTO', stepType: { stepTypeId: 2 }, endCondition: {} }
|
||||
{ stepId: 1, type: 'RepeatGroupDTO', numberOfIterations: 2, workoutSteps: [] },
|
||||
{ stepId: 2, type: 'ExecutableStepDTO', stepTypeId: 1, endConditionId: 2 },
|
||||
{ stepId: 3, type: 'ExecutableStepDTO', stepTypeId: 2, endConditionId: 2 }
|
||||
]
|
||||
const wrapper = mount(WorkoutVisualEditor, mountOptions({ steps }))
|
||||
const text = wrapper.text()
|
||||
expect(text).toContain('Repeat Group')
|
||||
expect(text).toContain('Repeat')
|
||||
expect(text).toContain('Warmup')
|
||||
})
|
||||
|
||||
|
||||
@@ -10,12 +10,16 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
v-model="jsonString"
|
||||
class="flex-1 w-full bg-gray-900 font-mono text-sm p-4 text-green-400 border border-gray-700 rounded focus:outline-none focus:border-blue-500 resize-none"
|
||||
spellcheck="false"
|
||||
@input="updateModel"
|
||||
></textarea>
|
||||
<!-- Syntax Highlighted Editor -->
|
||||
<div class="flex-1 w-full border border-gray-700 rounded overflow-hidden relative">
|
||||
<prism-editor
|
||||
v-model="jsonString"
|
||||
class="my-editor h-full font-mono text-sm bg-gray-900"
|
||||
:highlight="highlighter"
|
||||
line-numbers
|
||||
@input="updateModel"
|
||||
></prism-editor>
|
||||
</div>
|
||||
|
||||
<!-- Validation Feedback -->
|
||||
<div
|
||||
@@ -40,6 +44,13 @@
|
||||
import { ref, watch } from 'vue'
|
||||
import { CheckCircle2, AlertTriangle } from 'lucide-vue-next'
|
||||
|
||||
// Prism
|
||||
import { PrismEditor } from 'vue-prism-editor'
|
||||
import 'vue-prism-editor/dist/prismeditor.min.css' // import the styles somewhere
|
||||
import { highlight, languages } from 'prismjs/components/prism-core'
|
||||
import 'prismjs/components/prism-json'
|
||||
import 'prismjs/themes/prism-tomorrow.css'
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: { type: Object, default: () => ({}) }
|
||||
})
|
||||
@@ -48,19 +59,33 @@ const emit = defineEmits(['update:modelValue'])
|
||||
const jsonString = ref(JSON.stringify(props.modelValue, null, 2))
|
||||
const validationResult = ref(null)
|
||||
|
||||
const highlighter = (code) => {
|
||||
return highlight(code, languages.json) // languages.<insert language> to return html with markup
|
||||
}
|
||||
|
||||
// Sync prop changes to local string (if changed externally)
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
if (JSON.stringify(newVal) !== jsonString.value) {
|
||||
// Avoid loop
|
||||
// Avoid re-formatting current edit if valid
|
||||
try {
|
||||
const current = JSON.parse(jsonString.value)
|
||||
// If structurally different, update string
|
||||
if (JSON.stringify(current) !== JSON.stringify(newVal)) {
|
||||
jsonString.value = JSON.stringify(newVal, null, 2)
|
||||
}
|
||||
} catch (e) {
|
||||
// Current is invalid, force update if prop changed
|
||||
jsonString.value = JSON.stringify(newVal, null, 2)
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const updateModel = () => {
|
||||
const updateModel = (code) => {
|
||||
// code param is the new value
|
||||
// Note: @input on prism-editor passes the value
|
||||
// But v-model updates jsonString automatically
|
||||
try {
|
||||
const parsed = JSON.parse(jsonString.value)
|
||||
emit('update:modelValue', parsed)
|
||||
@@ -84,3 +109,24 @@ const validate = async () => {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* required class for prism editor */
|
||||
.my-editor {
|
||||
background: #1e1e1e;
|
||||
font-family:
|
||||
Fira code,
|
||||
Fira Mono,
|
||||
Consolas,
|
||||
Menlo,
|
||||
Courier,
|
||||
monospace;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
padding: 10px;
|
||||
}
|
||||
/* Optional: cursor color */
|
||||
.prism-editor__textarea:focus {
|
||||
outline: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,138 +1,3 @@
|
||||
<template>
|
||||
<div class="workout-visual-editor space-y-4">
|
||||
<div v-if="!isNested" class="bg-gray-800 p-4 rounded-lg mb-4">
|
||||
<h3 class="text-lg font-bold mb-2">Workout Metadata</h3>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm text-gray-400">Name</label>
|
||||
<input
|
||||
:value="modelValue.workoutName"
|
||||
class="w-full bg-gray-700 rounded px-2 py-1 text-white border border-gray-600 focus:border-blue-500"
|
||||
@input="emit('update:modelValue', { ...modelValue, workoutName: $event.target.value })"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm text-gray-400">Sport Type</label>
|
||||
<select
|
||||
:value="modelValue.sportType?.sportTypeId"
|
||||
class="w-full bg-gray-700 rounded px-2 py-1 text-white border border-gray-600"
|
||||
@change="
|
||||
emit('update:modelValue', {
|
||||
...modelValue,
|
||||
sportType: { ...modelValue.sportType, sportTypeId: Number($event.target.value) }
|
||||
})
|
||||
"
|
||||
>
|
||||
<option :value="1">Running</option>
|
||||
<option :value="2">Cycling</option>
|
||||
<option :value="3">Swimming</option>
|
||||
<option :value="6">Fitness Equipment</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Draggable Area -->
|
||||
<draggable
|
||||
:list="steps"
|
||||
item-key="stepId"
|
||||
class="space-y-4"
|
||||
handle=".drag-handle"
|
||||
group="steps"
|
||||
@change="emitUpdate"
|
||||
>
|
||||
<template #item="{ element, index }">
|
||||
<div class="step-card bg-gray-800 rounded-lg border border-gray-700 overflow-hidden">
|
||||
<!-- Header / Drag Handle -->
|
||||
<div class="bg-gray-700 p-2 flex items-center justify-between cursor-move drag-handle">
|
||||
<div class="flex items-center gap-2">
|
||||
<GripVertical class="w-4 h-4 text-gray-400" />
|
||||
<span class="font-bold text-sm">
|
||||
{{ formatStepType(element) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button class="text-red-400 hover:text-red-300" @click="removeStep(index)">
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Step Content -->
|
||||
<div class="p-4">
|
||||
<!-- If Repeat Group -->
|
||||
<div
|
||||
v-if="element.type === 'RepeatGroupDTO'"
|
||||
class="nested-group border-l-2 border-yellow-500 pl-4"
|
||||
>
|
||||
<div class="mb-4 flex items-center gap-2">
|
||||
<label class="text-sm">Iterations:</label>
|
||||
<input
|
||||
v-model.number="element.numberOfIterations"
|
||||
type="number"
|
||||
class="w-20 bg-gray-900 rounded px-2 py-1"
|
||||
min="1"
|
||||
@change="emitUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Recursive Component for Repeat Steps -->
|
||||
<WorkoutVisualEditor
|
||||
v-model:steps="element.workoutSteps"
|
||||
:is-nested="true"
|
||||
@update:steps="onNestedUpdate($event, index)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Single Step -->
|
||||
<div v-else class="grid grid-cols-2 gap-4">
|
||||
<!-- Duration/Target Controls (Simplified) -->
|
||||
<div>
|
||||
<label class="block text-xs text-gray-400">Duration Type</label>
|
||||
<select
|
||||
v-model="element.endCondition.conditionTypeId"
|
||||
class="w-full bg-gray-900 rounded px-2 py-1 text-sm mt-1"
|
||||
@change="emitUpdate"
|
||||
>
|
||||
<option :value="1">Distance</option>
|
||||
<option :value="2">Time</option>
|
||||
<option :value="5">Cadence</option>
|
||||
<option :value="7">Lap Button</option>
|
||||
</select>
|
||||
</div>
|
||||
<div v-if="element.endCondition.conditionTypeId === 2">
|
||||
<label class="block text-xs text-gray-400">Duration (Secs)</label>
|
||||
<input
|
||||
v-model.number="element.endConditionValue"
|
||||
type="number"
|
||||
class="w-full bg-gray-900 rounded px-2 py-1 text-sm mt-1"
|
||||
@change="emitUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
|
||||
<!-- Add Buttons -->
|
||||
<div class="flex gap-2 justify-center mt-4">
|
||||
<button
|
||||
class="bg-blue-600 hover:bg-blue-500 px-3 py-1 rounded text-sm flex items-center gap-1"
|
||||
@click="addStep('interval')"
|
||||
>
|
||||
<Plus class="w-4 h-4" /> Add Step
|
||||
</button>
|
||||
<button
|
||||
class="bg-yellow-600 hover:bg-yellow-500 px-3 py-1 rounded text-sm flex items-center gap-1"
|
||||
@click="addStep('repeat')"
|
||||
>
|
||||
<Repeat class="w-4 h-4" /> Add Repeat
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import draggable from 'vuedraggable'
|
||||
import { GripVertical, Trash2, Plus, Repeat } from 'lucide-vue-next'
|
||||
@@ -146,7 +11,6 @@ const props = defineProps({
|
||||
const emit = defineEmits(['update:modelValue', 'update:steps'])
|
||||
|
||||
// For vuedraggable to work seamlessly, we emit the whole list
|
||||
|
||||
const emitUpdate = () => {
|
||||
if (props.isNested) {
|
||||
emit('update:steps', props.steps)
|
||||
@@ -162,16 +26,6 @@ const onNestedUpdate = (newSteps, index) => {
|
||||
}
|
||||
|
||||
// Helpers
|
||||
const formatStepType = (step) => {
|
||||
if (step.type === 'RepeatGroupDTO') return 'Repeat Group'
|
||||
const typeId = step.stepType?.stepTypeId
|
||||
if (typeId === 1) return 'Warmup'
|
||||
if (typeId === 2) return 'Cooldown'
|
||||
if (typeId === 3) return 'Interval'
|
||||
if (typeId === 4) return 'Recovery'
|
||||
return 'Step'
|
||||
}
|
||||
|
||||
const removeStep = (index) => {
|
||||
const updatedSteps = [...props.steps]
|
||||
updatedSteps.splice(index, 1)
|
||||
@@ -184,24 +38,426 @@ const addStep = (type) => {
|
||||
updatedSteps.push({
|
||||
type: 'RepeatGroupDTO',
|
||||
stepOrder: updatedSteps.length + 1,
|
||||
numberOfIterations: 2,
|
||||
numberOfIterations: 3,
|
||||
workoutSteps: []
|
||||
})
|
||||
} else {
|
||||
updatedSteps.push({
|
||||
type: 'ExecutableStepDTO',
|
||||
stepOrder: updatedSteps.length + 1,
|
||||
stepType: { stepTypeId: 3, stepTypeKey: 'interval' }, // Default Interval
|
||||
endCondition: { conditionTypeId: 2, conditionTypeKey: 'time' },
|
||||
endConditionValue: 300 // 5 mins
|
||||
stepTypeId: 3, // Interval
|
||||
endConditionId: 2, // Time
|
||||
endConditionValue: 300, // 5 mins
|
||||
targetTypeId: 1, // Speed
|
||||
targetValueOne: null,
|
||||
targetValueTwo: null
|
||||
// Removed nested objects to match Garmin Schema
|
||||
})
|
||||
}
|
||||
emit('update:steps', updatedSteps)
|
||||
}
|
||||
|
||||
const getStepType = (step) => {
|
||||
if (step.type === 'RepeatGroupDTO') return 'repeat'
|
||||
|
||||
// Garmin Schema uses stepTypeId directly
|
||||
// Fallback to stepType object for legacy local files if needed (though we should migrate)
|
||||
const id = step.stepTypeId ?? step.stepType?.stepTypeId
|
||||
|
||||
if (id === 0) return 'warmup'
|
||||
if (id === 1) return 'interval'
|
||||
if (id === 2) return 'recover'
|
||||
if (id === 3) return 'rest'
|
||||
if (id === 4) return 'cool'
|
||||
return 'other'
|
||||
}
|
||||
|
||||
const getStepColor = (typeId) => {
|
||||
switch (typeId) {
|
||||
case 0:
|
||||
return '#e3b341' // Warmup (Gold/Yellow)
|
||||
case 1:
|
||||
return 'var(--accent-color)' // Active (Blue/Green)
|
||||
case 2:
|
||||
return '#2ea043' // Recover
|
||||
case 3:
|
||||
return '#8b949e' // Rest
|
||||
case 4:
|
||||
return '#1f6feb' // Cool Down
|
||||
default:
|
||||
return 'var(--text-muted)'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="workout-visual-editor">
|
||||
<!-- Top Level Metadata Card -->
|
||||
<div v-if="!isNested" class="meta-card">
|
||||
<div class="input-group">
|
||||
<label>Name</label>
|
||||
<input
|
||||
:value="modelValue.workoutName"
|
||||
type="text"
|
||||
placeholder="Workout Name"
|
||||
class="bare-input"
|
||||
style="width: 100%; text-align: left; font-size: 1.1rem; font-weight: 500"
|
||||
@input="
|
||||
emit('update:modelValue', {
|
||||
...modelValue,
|
||||
workoutName: $event.target.value
|
||||
})
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Type</label>
|
||||
<select
|
||||
:value="modelValue.sportType?.sportTypeId"
|
||||
@change="
|
||||
emit('update:modelValue', {
|
||||
...modelValue,
|
||||
sportType: { ...modelValue.sportType, sportTypeId: Number($event.target.value) }
|
||||
})
|
||||
"
|
||||
>
|
||||
<option :value="1">Running</option>
|
||||
<option :value="2">Cycling</option>
|
||||
<option :value="3">Swimming</option>
|
||||
<option :value="6">Strength</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Draggable List -->
|
||||
<draggable
|
||||
:list="steps"
|
||||
item-key="stepOrder"
|
||||
handle=".drag-handle"
|
||||
group="steps"
|
||||
class="steps-container"
|
||||
@change="emitUpdate"
|
||||
>
|
||||
<template #item="{ element, index }">
|
||||
<div class="step-wrapper">
|
||||
<!-- REPEAT BLOCK -->
|
||||
<div v-if="element.type === 'RepeatGroupDTO'" class="repeat-block">
|
||||
<div class="repeat-header">
|
||||
<div class="drag-handle"><GripVertical :size="16" /></div>
|
||||
<div style="flex: 1; display: flex; align-items: center; gap: 0.5rem">
|
||||
<Repeat :size="16" />
|
||||
<span style="font-weight: 600">Repeat</span>
|
||||
<input
|
||||
v-model.number="element.numberOfIterations"
|
||||
type="number"
|
||||
class="bare-input"
|
||||
min="1"
|
||||
@change="emitUpdate"
|
||||
/>
|
||||
<span>times</span>
|
||||
</div>
|
||||
<button class="icon-btn delete" @click="removeStep(index)">
|
||||
<Trash2 :size="16" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="repeat-body">
|
||||
<WorkoutVisualEditor
|
||||
v-model:steps="element.workoutSteps"
|
||||
:is-nested="true"
|
||||
@update:steps="onNestedUpdate($event, index)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SINGLE STEP CARD -->
|
||||
<div v-else class="step-card">
|
||||
<!-- Colored Sidebar -->
|
||||
<div
|
||||
class="step-color-bar"
|
||||
:style="{
|
||||
backgroundColor: getStepColor(element.stepTypeId ?? element.stepType?.stepTypeId)
|
||||
}"
|
||||
></div>
|
||||
|
||||
<div class="step-content">
|
||||
<div class="step-row-top">
|
||||
<div class="drag-handle"><GripVertical :size="16" color="var(--text-muted)" /></div>
|
||||
|
||||
<!-- Step Type Select -->
|
||||
<!-- Bind direct to stepTypeId if available, else nested -->
|
||||
<!-- We need a computed setter or just force flat now -->
|
||||
<select
|
||||
v-model="element.stepTypeId"
|
||||
class="bare-select type-select"
|
||||
@change="emitUpdate"
|
||||
>
|
||||
<option :value="0">Warmup</option>
|
||||
<option :value="1">Interval</option>
|
||||
<option :value="2">Recover</option>
|
||||
<option :value="5">Rest</option>
|
||||
<option :value="4">Cooldown</option>
|
||||
<option :value="3">Other</option>
|
||||
</select>
|
||||
|
||||
<div style="flex: 1"></div>
|
||||
<button class="icon-btn delete" @click="removeStep(index)">
|
||||
<Trash2 :size="14" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="step-row-details">
|
||||
<!-- Duration/Target -->
|
||||
<div class="detail-group">
|
||||
<label>Duration Type</label>
|
||||
<select v-model="element.endConditionId" class="bare-select" @change="emitUpdate">
|
||||
<option :value="3">Distance</option>
|
||||
<option :value="2">Time</option>
|
||||
<option :value="1">Lap Button</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div v-if="element.endConditionId === 2" class="detail-group">
|
||||
<label>Seconds</label>
|
||||
<input
|
||||
v-model.number="element.endConditionValue"
|
||||
type="number"
|
||||
class="bare-input"
|
||||
@change="emitUpdate"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="element.endConditionId === 3" class="detail-group">
|
||||
<label>Meters</label>
|
||||
<input
|
||||
v-model.number="element.endConditionValue"
|
||||
type="number"
|
||||
class="bare-input"
|
||||
@change="emitUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
|
||||
<!-- Add Buttons -->
|
||||
<div class="add-controls">
|
||||
<button class="add-btn" @click="addStep('interval')"><Plus :size="16" /> Add Step</button>
|
||||
<button class="add-btn" @click="addStep('repeat')"><Repeat :size="16" /> Add Repeat</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.workout-visual-editor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
/* Metadata */
|
||||
.meta-card {
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--border-color);
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.input-group label {
|
||||
display: block;
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.input-group select {
|
||||
background: var(--bg-color);
|
||||
border: 1px solid var(--border-color);
|
||||
color: var(--text-color);
|
||||
padding: 0.5rem;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Steps List */
|
||||
.steps-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem; /* Tighter gap */
|
||||
}
|
||||
|
||||
/* Single Step Card (Streamlined) */
|
||||
.step-card {
|
||||
background: var(--card-bg);
|
||||
border: 1px solid transparent; /* Remove border noise unless hovered/active */
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
transition: all 0.2s;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.step-card:hover {
|
||||
background: rgba(255, 255, 255, 0.02); /* Subtle highlight */
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.step-color-bar {
|
||||
width: 4px; /* Thinner accent bar */
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.step-content {
|
||||
flex: 1;
|
||||
padding: 0.5rem 0.75rem; /* Reduced padding */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.step-row-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.drag-handle {
|
||||
cursor: grab;
|
||||
color: var(--text-muted);
|
||||
opacity: 0.3;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.drag-handle:hover {
|
||||
opacity: 0.8;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
/* Typography Inputs */
|
||||
.bare-select {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-color);
|
||||
font-size: 1.1rem; /* Larger */
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
.bare-select:focus {
|
||||
outline: none;
|
||||
color: var(--accent-color);
|
||||
}
|
||||
|
||||
.type-select {
|
||||
font-weight: 600;
|
||||
font-size: 1.1rem; /* Larger */
|
||||
}
|
||||
|
||||
.step-row-details {
|
||||
display: flex;
|
||||
gap: 1.5rem; /* More spacing */
|
||||
align-items: baseline;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.detail-group {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.detail-group label {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.bare-input {
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-bottom: 2px solid rgba(255, 255, 255, 0.1); /* Thicker line */
|
||||
color: var(--text-color);
|
||||
width: 80px; /* Wider */
|
||||
font-size: 1.1rem; /* Larger */
|
||||
padding: 0.25rem 0;
|
||||
text-align: center;
|
||||
font-weight: 500;
|
||||
}
|
||||
.bare-input:focus {
|
||||
outline: none;
|
||||
border-bottom-color: var(--accent-color);
|
||||
}
|
||||
|
||||
/* Repeat Block (Streamlined) */
|
||||
.repeat-block {
|
||||
/* No background, just a container */
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.repeat-header {
|
||||
/* Minimal header */
|
||||
padding: 0.25rem 0.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.9rem;
|
||||
border-left: 2px solid var(--text-muted); /* Visual anchor */
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.repeat-body {
|
||||
padding-left: 1rem; /* Indent content */
|
||||
border-left: 1px dashed var(--border-color); /* Visual guide for nesting */
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
/* Controls */
|
||||
.icon-btn.delete {
|
||||
color: var(--text-muted);
|
||||
opacity: 0; /* Hide until hover */
|
||||
padding: 0.25rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
.step-card:hover .icon-btn.delete {
|
||||
opacity: 0.5;
|
||||
}
|
||||
.icon-btn.delete:hover {
|
||||
color: var(--error-color) !important;
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
.add-controls {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
justify-content: center;
|
||||
margin-top: 1.5rem;
|
||||
opacity: 0.6;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
.add-controls:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
background: transparent;
|
||||
border: 1px solid var(--border-color);
|
||||
color: var(--text-muted);
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 12px;
|
||||
font-size: 0.8rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.add-btn:hover {
|
||||
border-color: var(--accent-color);
|
||||
color: var(--accent-color);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -170,6 +170,15 @@ onMounted(() => {
|
||||
<button @click="handleChipClick('Why is my volume increasing?')">
|
||||
Analyze volume trend
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
handleChipClick(
|
||||
'Analyze my last trainings and make recommendations about my trainings the next 3 days'
|
||||
)
|
||||
"
|
||||
>
|
||||
Analyze & Recommend
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+387
-188
@@ -1,16 +1,20 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import {
|
||||
Calendar,
|
||||
Plus,
|
||||
Copy,
|
||||
Edit,
|
||||
Edit2, // Was Edit, but Edit2 used in template
|
||||
ArrowLeft,
|
||||
UploadCloud,
|
||||
Cloud, // Used in template
|
||||
Loader2,
|
||||
Sparkles,
|
||||
Code,
|
||||
Layout
|
||||
LayoutDashboard, // Used in template
|
||||
AlertTriangle,
|
||||
CheckCircle2,
|
||||
Dumbbell,
|
||||
Activity,
|
||||
FileJson
|
||||
} from 'lucide-vue-next'
|
||||
import WorkoutVisualEditor from '../components/WorkoutVisualEditor.vue'
|
||||
import WorkoutJsonEditor from '../components/WorkoutJsonEditor.vue'
|
||||
@@ -18,6 +22,7 @@ import WorkoutJsonEditor from '../components/WorkoutJsonEditor.vue'
|
||||
// State
|
||||
const viewMode = ref('browser') // 'browser' | 'editor'
|
||||
const editorTab = ref('visual') // 'visual' | 'json'
|
||||
const sourceMode = ref('remote') // 'remote' | 'local'
|
||||
const workouts = ref([])
|
||||
const loading = ref(false)
|
||||
const syncing = ref(false)
|
||||
@@ -33,10 +38,30 @@ const aiError = ref('')
|
||||
|
||||
const fetchWorkouts = async () => {
|
||||
loading.value = true
|
||||
workouts.value = []
|
||||
try {
|
||||
const res = await fetch('http://localhost:8000/workouts')
|
||||
const url =
|
||||
sourceMode.value === 'local'
|
||||
? 'http://localhost:8000/workouts/local'
|
||||
: 'http://localhost:8000/workouts'
|
||||
|
||||
const res = await fetch(url)
|
||||
if (res.ok) {
|
||||
workouts.value = await res.json()
|
||||
const data = await res.json()
|
||||
// Normalize structure: Local returns filenames, Remote returns objects
|
||||
if (sourceMode.value === 'local') {
|
||||
// Wrap filenames in minimal workout objects for display
|
||||
workouts.value = data.map((f) => ({
|
||||
workoutId: f,
|
||||
workoutName: f.replace('.json', ''),
|
||||
description: 'Local File',
|
||||
sportType: { sportTypeKey: 'local' },
|
||||
isLocal: true,
|
||||
filename: f
|
||||
}))
|
||||
} else {
|
||||
workouts.value = data
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fetch workouts failed', error)
|
||||
@@ -45,6 +70,11 @@ const fetchWorkouts = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const setSourceMode = (mode) => {
|
||||
sourceMode.value = mode
|
||||
fetchWorkouts()
|
||||
}
|
||||
|
||||
const createNewWorkout = () => {
|
||||
workingWorkout.value = {
|
||||
workoutName: 'New Workout',
|
||||
@@ -56,36 +86,125 @@ const createNewWorkout = () => {
|
||||
sportType: { sportTypeId: 1, sportTypeKey: 'running' },
|
||||
workoutSteps: []
|
||||
}
|
||||
]
|
||||
],
|
||||
// If local, we need to know it's a new local file
|
||||
isLocal: sourceMode.value === 'local'
|
||||
}
|
||||
viewMode.value = 'editor'
|
||||
editorTab.value = 'visual'
|
||||
syncResult.value = null
|
||||
}
|
||||
|
||||
const editWorkout = (workout) => {
|
||||
// Deep copy to avoid mutating list directly
|
||||
workingWorkout.value = JSON.parse(JSON.stringify(workout))
|
||||
const duplicateWorkout = (workout) => {
|
||||
// 1. Create deep copy
|
||||
const copy = JSON.parse(JSON.stringify(workout))
|
||||
// 2. Assign new details
|
||||
copy.workoutName = `${copy.workoutName} (Copy)`
|
||||
delete copy.workoutId
|
||||
delete copy.uploadDate
|
||||
// 3. Set as working
|
||||
workingWorkout.value = copy
|
||||
workingWorkout.value.isLocal = true // Default to local for safety, or prompt user? Let's say local.
|
||||
|
||||
viewMode.value = 'editor'
|
||||
editorTab.value = 'visual'
|
||||
syncResult.value = null
|
||||
}
|
||||
|
||||
const duplicateWorkout = (workout) => {
|
||||
const copy = JSON.parse(JSON.stringify(workout))
|
||||
copy.workoutName = `${copy.workoutName} (Copy)`
|
||||
// Clear ID to ensure it treats as new if we were persisting IDs (remote IDs ignored on upload usually)
|
||||
delete copy.workoutId
|
||||
workingWorkout.value = copy
|
||||
viewMode.value = 'editor'
|
||||
syncResult.value = null
|
||||
const copyDebugInfo = async () => {
|
||||
if (!syncResult.value || syncResult.value.success) return
|
||||
|
||||
const err = syncResult.value.error
|
||||
const json = JSON.stringify(workingWorkout.value, null, 2)
|
||||
|
||||
const prompt = `I am encountering a Garmin Sync Error.
|
||||
Error: ${err}
|
||||
|
||||
Workout JSON:
|
||||
\`\`\`json
|
||||
${json}
|
||||
\`\`\`
|
||||
|
||||
Please debug this.`
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(prompt)
|
||||
alert('Debug info copied to clipboard!')
|
||||
} catch (e) {
|
||||
console.error('Failed to copy', e)
|
||||
alert('Failed to copy to clipboard. Check console.')
|
||||
}
|
||||
}
|
||||
|
||||
const editWorkout = async (workout) => {
|
||||
try {
|
||||
loading.value = true
|
||||
// Determine source
|
||||
if (workout.isLocal) {
|
||||
const res = await fetch(`http://localhost:8000/workouts/local/${workout.filename}`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
workingWorkout.value = { ...data, isLocal: true, filename: workout.filename }
|
||||
} else {
|
||||
throw new Error('Failed to load local')
|
||||
}
|
||||
} else {
|
||||
// REMOTE: Fetch full details now!
|
||||
// The list only gives metadata. We need segments/steps.
|
||||
const res = await fetch(`http://localhost:8000/workouts/${workout.workoutId}`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
workingWorkout.value = { ...data, isLocal: false }
|
||||
} else {
|
||||
throw new Error('Failed to load remote')
|
||||
}
|
||||
}
|
||||
|
||||
viewMode.value = 'editor'
|
||||
editorTab.value = 'visual'
|
||||
syncResult.value = null
|
||||
} catch (e) {
|
||||
console.error('Failed to load workout', e)
|
||||
alert('Failed to load workout. See console.')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// --- EDITOR ACTIONS ---
|
||||
|
||||
const syncToGarmin = async () => {
|
||||
const saveOrSync = async () => {
|
||||
syncing.value = true
|
||||
syncResult.value = null
|
||||
syncResult.value = null // Local Save
|
||||
if (workingWorkout.value.isLocal) {
|
||||
try {
|
||||
const filename =
|
||||
workingWorkout.value.filename || `workout_${Math.floor(Date.now() / 1000)}.json`
|
||||
|
||||
const res = await fetch(`http://localhost:8000/workouts/local/${filename}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
filename: filename,
|
||||
workout: workingWorkout.value
|
||||
})
|
||||
})
|
||||
const data = await res.json()
|
||||
if (data.status === 'SUCCESS') {
|
||||
syncResult.value = { success: true, msg: 'Saved locally!' }
|
||||
workingWorkout.value.filename = data.filename
|
||||
} else {
|
||||
syncResult.value = { success: false, error: 'Save failed' }
|
||||
}
|
||||
} catch (e) {
|
||||
syncResult.value = { success: false, error: 'Save failed: ' + e }
|
||||
} finally {
|
||||
syncing.value = false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Remote Sync (Existing Logic)
|
||||
try {
|
||||
const res = await fetch('http://localhost:8000/workouts/upload', {
|
||||
method: 'POST',
|
||||
@@ -94,25 +213,26 @@ const syncToGarmin = async () => {
|
||||
})
|
||||
const data = await res.json()
|
||||
if (data.success) {
|
||||
// Note: Backend changed 'status' to 'success' boolean
|
||||
syncResult.value = { type: 'success', msg: 'Uploaded to Garmin!' }
|
||||
syncResult.value = { success: true, msg: 'Uploaded to Garmin!' }
|
||||
} else {
|
||||
syncResult.value = { type: 'error', msg: 'Upload failed: ' + (data.error || 'Unknown error') }
|
||||
let errMsg = 'Upload failed: ' + (data.error || 'Unknown error')
|
||||
if (data.details) {
|
||||
console.error('Validation Details:', data.details)
|
||||
// Could show detailed validation errors in UI here
|
||||
syncResult.value.msg += ' (Check Console)'
|
||||
// We might want to embed details in the error object for debug info?
|
||||
// Let's store raw details too
|
||||
syncResult.value = { success: false, error: errMsg, details: data.details }
|
||||
} else {
|
||||
syncResult.value = { success: false, error: errMsg }
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
syncResult.value = { type: 'error', msg: 'Network error during sync.' }
|
||||
} catch (_e) {
|
||||
syncResult.value = { success: false, error: 'Network error during sync.' }
|
||||
} finally {
|
||||
syncing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// --- AI ACTIONS ---
|
||||
|
||||
const askAI = async () => {
|
||||
if (!aiPrompt.value.trim()) return
|
||||
|
||||
@@ -134,7 +254,7 @@ const askAI = async () => {
|
||||
} else if (data.error) {
|
||||
aiError.value = data.error
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
aiError.value = 'Failed to contact AI.'
|
||||
} finally {
|
||||
aiLoading.value = false
|
||||
@@ -145,125 +265,265 @@ const askAI = async () => {
|
||||
onMounted(() => {
|
||||
fetchWorkouts()
|
||||
})
|
||||
const isStrength = (workout) => {
|
||||
if (workout.sportType?.sportTypeKey === 'strength_training') return true
|
||||
if (workout.sportType?.sportTypeId === 5) return true
|
||||
return false
|
||||
}
|
||||
|
||||
const getSportName = (workout) => {
|
||||
if (workout.sportType?.sportTypeKey) {
|
||||
return workout.sportType.sportTypeKey.replace('_', ' ').toUpperCase()
|
||||
}
|
||||
const id = workout.sportType?.sportTypeId || workout.sportTypeId
|
||||
if (id === 1) return 'RUNNING'
|
||||
if (id === 2) return 'CYCLING'
|
||||
if (id === 5) return 'STRENGTH'
|
||||
return 'OTHER'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="plan-view">
|
||||
<!-- BROWSER MODE -->
|
||||
<div v-if="viewMode === 'browser'" class="browser-mode">
|
||||
<div class="card toolbar">
|
||||
<h3><Calendar :size="24" /> Existing Workouts</h3>
|
||||
<button class="primary-btn" @click="createNewWorkout">
|
||||
<Plus :size="18" /> New Workout
|
||||
</button>
|
||||
<div class="h-full flex flex-col p-6 max-w-6xl mx-auto w-full">
|
||||
<!-- LINK TO DASHBOARD -->
|
||||
<div v-if="viewMode === 'browser'" class="mb-6 flex justify-between items-center">
|
||||
<div>
|
||||
<h1
|
||||
class="text-3xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-purple-400 mb-2"
|
||||
>
|
||||
Workout Plans
|
||||
</h1>
|
||||
<p class="text-gray-400">Manage your training collection</p>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" style="text-align: center; padding: 2rem">
|
||||
<Loader2 class="spinner" /> Loading remote workouts...
|
||||
<div class="flex gap-4">
|
||||
<!-- Source Toggle -->
|
||||
<div class="flex gap-2 bg-gray-900/50 p-1 rounded-lg border border-gray-800">
|
||||
<button
|
||||
:class="[
|
||||
'px-4 py-2 rounded-md text-sm font-medium transition-all flex items-center gap-2',
|
||||
sourceMode === 'remote'
|
||||
? 'bg-blue-600 text-white shadow-lg shadow-blue-900/20'
|
||||
: 'text-gray-400 hover:text-white hover:bg-white/5'
|
||||
]"
|
||||
@click="setSourceMode('remote')"
|
||||
>
|
||||
<Cloud class="w-4 h-4" />
|
||||
Gapminder
|
||||
</button>
|
||||
<button
|
||||
class="px-4 py-1.5 rounded-md transition-all"
|
||||
:class="
|
||||
sourceMode === 'local'
|
||||
? 'bg-purple-600 text-white shadow-lg'
|
||||
: 'text-gray-400 hover:text-white'
|
||||
"
|
||||
@click="setSourceMode('local')"
|
||||
>
|
||||
Local Files
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button class="primary-btn" @click="createNewWorkout">
|
||||
<Plus class="w-5 h-5" /> New Plan
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- WORKOUT BROWSER -->
|
||||
<div v-if="viewMode === 'browser'" class="flex-1 overflow-y-auto custom-scrollbar">
|
||||
<!-- ... existing browser content ... -->
|
||||
<div v-if="loading" class="flex flex-col items-center justify-center h-64 text-gray-500">
|
||||
<Loader2 class="w-8 h-8 animate-spin mb-2" />
|
||||
<span>Loading workouts...</span>
|
||||
</div>
|
||||
|
||||
<div v-else-if="workouts.length === 0" class="text-center text-gray-500 mt-20">
|
||||
<p>No workouts found.</p>
|
||||
</div>
|
||||
|
||||
<div v-else class="workout-grid">
|
||||
<div v-if="workouts.length === 0" class="empty-state">No workouts found. Create one!</div>
|
||||
<div v-for="w in workouts" :key="w.workoutId" class="workout-card">
|
||||
<div class="w-header">
|
||||
<h4>{{ w.workoutName }}</h4>
|
||||
<span class="badge">{{ w.sportType?.sportTypeKey }}</span>
|
||||
<div
|
||||
v-for="workout in workouts"
|
||||
:key="workout.workoutId || workout.filename"
|
||||
class="workout-card group"
|
||||
>
|
||||
<div class="flex justify-between items-start mb-3">
|
||||
<div
|
||||
class="p-2 rounded-lg bg-gray-800 text-blue-400 group-hover:bg-blue-900/30 transition-colors"
|
||||
>
|
||||
<Dumbbell v-if="isStrength(workout)" class="w-6 h-6" />
|
||||
<Activity v-else class="w-6 h-6" />
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
class="icon-btn p-1.5 hover:bg-white/10 rounded-md transition-colors text-gray-400 hover:text-white"
|
||||
title="Duplicate"
|
||||
@click.stop="duplicateWorkout(workout)"
|
||||
>
|
||||
<Copy class="w-5 h-5" />
|
||||
</button>
|
||||
<button
|
||||
class="icon-btn p-1.5 hover:bg-white/10 rounded-md transition-colors text-gray-400 hover:text-white"
|
||||
title="Edit"
|
||||
@click.stop="editWorkout(workout)"
|
||||
>
|
||||
<Edit2 class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="desc">{{ w.description || 'No description' }}</p>
|
||||
<div class="actions">
|
||||
<button class="icon-btn" title="Duplicate" @click="duplicateWorkout(w)">
|
||||
<Copy :size="16" />
|
||||
</button>
|
||||
<button class="icon-btn" title="Edit" @click="editWorkout(w)">
|
||||
<Edit :size="16" />
|
||||
</button>
|
||||
<h3 class="font-bold text-lg mb-1 truncate">{{ workout.workoutName }}</h3>
|
||||
<p class="text-xs text-gray-400 mb-4 line-clamp-2">
|
||||
{{ workout.description || 'No description provided' }}
|
||||
</p>
|
||||
|
||||
<div
|
||||
class="mt-auto flex justify-between items-center text-xs text-gray-500 border-t border-gray-800 pt-3"
|
||||
>
|
||||
<span>{{ getSportName(workout) }}</span>
|
||||
<span v-if="workout.isLocal" class="text-purple-400 flex items-center gap-1">
|
||||
<FileJson class="w-3 h-3" /> Local
|
||||
</span>
|
||||
<span v-else class="text-blue-400 flex items-center gap-1">
|
||||
<Cloud class="w-3 h-3" /> Garmin
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- EDITOR MODE -->
|
||||
<div v-if="viewMode === 'editor'" class="editor-mode">
|
||||
<!-- Editor Header -->
|
||||
<div class="card editor-header">
|
||||
<div class="left-controls">
|
||||
<button class="icon-btn" @click="viewMode = 'browser'"><ArrowLeft :size="20" /></button>
|
||||
<input
|
||||
v-model="workingWorkout.workoutName"
|
||||
class="title-input"
|
||||
placeholder="Workout Name"
|
||||
/>
|
||||
</div>
|
||||
<div class="right-controls">
|
||||
<span v-if="syncResult" :class="['sync-res', syncResult.type]">
|
||||
{{ syncResult.msg }}
|
||||
</span>
|
||||
<button class="primary-btn" :disabled="syncing" @click="syncToGarmin">
|
||||
<UploadCloud v-if="!syncing" :size="18" />
|
||||
<Loader2 v-else class="spinner" :size="18" />
|
||||
{{ syncing ? 'Syncing...' : 'Sync to Garmin' }}
|
||||
<div v-else class="flex flex-col h-full gap-4">
|
||||
<!-- HEADER ROW -->
|
||||
<div class="flex items-center gap-4 bg-gray-900/50 p-2 rounded-xl border border-gray-800">
|
||||
<button
|
||||
class="flex items-center gap-2 px-3 py-2 text-gray-400 hover:text-white hover:bg-gray-800 rounded-lg transition-colors"
|
||||
@click="viewMode = 'browser'"
|
||||
>
|
||||
<ArrowLeft class="w-5 h-5" />
|
||||
<span class="font-medium">Back</span>
|
||||
</button>
|
||||
|
||||
<input
|
||||
v-model="workingWorkout.workoutName"
|
||||
class="bg-transparent text-xl font-bold focus:outline-none border-b border-transparent focus:border-blue-500 px-2 py-1 min-w-[200px]"
|
||||
placeholder="Workout Name"
|
||||
/>
|
||||
|
||||
<div class="flex-1"></div>
|
||||
|
||||
<!-- Editor Toggle -->
|
||||
<div class="bg-gray-800 p-0.5 rounded-lg flex text-xs">
|
||||
<button
|
||||
class="px-3 py-1.5 rounded-md transition-all flex items-center gap-2"
|
||||
:class="
|
||||
editorTab === 'visual'
|
||||
? 'bg-gray-700 text-white shadow'
|
||||
: 'text-gray-400 hover:text-white'
|
||||
"
|
||||
@click="editorTab = 'visual'"
|
||||
>
|
||||
<LayoutDashboard class="w-3 h-3" /> Visual
|
||||
</button>
|
||||
<button
|
||||
class="px-3 py-1.5 rounded-md transition-all flex items-center gap-2"
|
||||
:class="
|
||||
editorTab === 'json'
|
||||
? 'bg-gray-700 text-white shadow'
|
||||
: 'text-gray-400 hover:text-white'
|
||||
"
|
||||
@click="editorTab = 'json'"
|
||||
>
|
||||
<Code class="w-3 h-3" /> JSON
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg font-medium shadow-lg shadow-blue-900/20 transition-all"
|
||||
:disabled="syncing"
|
||||
@click="saveOrSync"
|
||||
>
|
||||
<Cloud v-if="!syncing" class="w-4 h-4" />
|
||||
<Loader2 v-else class="w-4 h-4 animate-spin" />
|
||||
{{ workingWorkout.isLocal ? 'Save Local' : 'Sync to Garmin' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- AI Assistant Bar -->
|
||||
<div class="card ai-bar">
|
||||
<div class="ai-input-wrapper">
|
||||
<Sparkles :size="20" class="ai-icon" />
|
||||
<!-- AI BAR & ERRORS -->
|
||||
<div class="flex items-center gap-2">
|
||||
<div
|
||||
:class="[
|
||||
'flex-1 flex items-center gap-3 bg-gray-900 border border-gray-700 px-4 py-2 rounded-xl focus-within:border-purple-500 focus-within:ring-1 focus-within:ring-purple-500/50 transition-all shadow-sm',
|
||||
aiLoading ? 'opacity-75' : ''
|
||||
]"
|
||||
>
|
||||
<Sparkles class="w-5 h-5 text-purple-400" />
|
||||
<input
|
||||
v-model="aiPrompt"
|
||||
class="ai-prompt-input bg-transparent border-none focus:outline-none text-sm w-full placeholder-gray-500"
|
||||
placeholder="Ask AI to modify... (e.g. 'Add a 10 min warmup' or 'Make intervals harder')"
|
||||
:disabled="aiLoading"
|
||||
@keyup.enter="askAI"
|
||||
/>
|
||||
<button class="ai-btn" :disabled="!aiPrompt || aiLoading" @click="askAI">
|
||||
<Loader2 v-if="aiLoading" class="spinner" :size="16" />
|
||||
<span v-else>Generate</span>
|
||||
<button
|
||||
class="ai-btn px-3 py-1 bg-purple-600/20 text-purple-300 hover:bg-purple-600 hover:text-white text-xs font-bold rounded uppercase tracking-wider transition-colors"
|
||||
:disabled="!aiPrompt.trim() || aiLoading"
|
||||
@click="askAI"
|
||||
>
|
||||
{{ aiLoading ? 'Thinking...' : 'Generate' }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="aiError" class="ai-error">{{ aiError }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Editor Tabs -->
|
||||
<div class="flex gap-2 border-b border-gray-700 mb-2">
|
||||
<button
|
||||
:class="[
|
||||
'px-4 py-2 text-sm flex items-center gap-2 border-b-2',
|
||||
editorTab === 'visual'
|
||||
? 'border-blue-500 text-blue-400'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-300'
|
||||
]"
|
||||
@click="editorTab = 'visual'"
|
||||
>
|
||||
<Layout class="w-4 h-4" /> Visual Editor
|
||||
</button>
|
||||
<button
|
||||
:class="[
|
||||
'px-4 py-2 text-sm flex items-center gap-2 border-b-2',
|
||||
editorTab === 'json'
|
||||
? 'border-purple-500 text-purple-400'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-300'
|
||||
]"
|
||||
@click="editorTab = 'json'"
|
||||
>
|
||||
<Code class="w-4 h-4" /> JSON Source
|
||||
</button>
|
||||
<!-- ERROR FEEDBACK -->
|
||||
<div
|
||||
v-if="aiError"
|
||||
class="p-3 bg-red-900/30 border border-red-800 text-red-200 rounded-lg text-sm flex items-center gap-2"
|
||||
>
|
||||
<AlertTriangle class="w-4 h-4" />
|
||||
{{ aiError }}
|
||||
</div>
|
||||
|
||||
<!-- Editor Content -->
|
||||
<div class="flex-1 min-h-0">
|
||||
<div v-if="editorTab === 'visual'" class="h-full overflow-y-auto pr-2">
|
||||
<!-- Using the new Visual Editor component -->
|
||||
<!-- We bind to workoutSteps of the first segment for simplicity, or we could make the editor handle full workout object. -->
|
||||
<!-- Let's bind to the workout object to let it handle metadata, but the dragger needs a list. -->
|
||||
<!-- The VisualEditor I designed takes `modelValue` (metadata) AND `steps` (list). -->
|
||||
<WorkoutVisualEditor
|
||||
v-model="workingWorkout"
|
||||
v-model:steps="workingWorkout.workoutSegments[0].workoutSteps"
|
||||
/>
|
||||
<!-- SYNC ERROR DIALOG -->
|
||||
<div
|
||||
v-if="syncResult && !syncResult.success"
|
||||
class="p-4 bg-red-900/20 border border-red-800/50 rounded-xl"
|
||||
>
|
||||
<div class="flex items-start justify-between">
|
||||
<div class="flex gap-3">
|
||||
<div class="p-2 bg-red-900/30 rounded-lg text-red-400">
|
||||
<AlertTriangle class="w-5 h-5" />
|
||||
</div>
|
||||
<div>
|
||||
<h4 class="font-bold text-red-400">Sync Failed</h4>
|
||||
<p class="text-sm text-red-200/80 mt-1">{{ syncResult.error }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
class="flex items-center gap-2 px-3 py-1.5 bg-red-900/40 hover:bg-red-900/60 text-red-300 rounded-lg text-xs font-medium transition-colors border border-red-800/50"
|
||||
@click="copyDebugInfo"
|
||||
>
|
||||
<Copy class="w-3 h-3" /> Copy Debug Info
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="editorTab === 'json'" class="h-full">
|
||||
<div
|
||||
v-if="syncResult && syncResult.success"
|
||||
class="p-3 bg-green-900/30 border border-green-800 text-green-200 rounded-lg text-sm flex items-center gap-2"
|
||||
>
|
||||
<CheckCircle2 class="w-4 h-4" />
|
||||
{{ workingWorkout.isLocal ? 'Saved locally!' : 'Uploaded to Garmin!' }}
|
||||
</div>
|
||||
|
||||
<!-- EDITOR CONTENT -->
|
||||
<div class="flex-1 bg-gray-900/30 border border-gray-800 rounded-xl overflow-hidden relative">
|
||||
<WorkoutVisualEditor
|
||||
v-if="editorTab === 'visual'"
|
||||
v-model="workingWorkout"
|
||||
v-model:steps="workingWorkout.workoutSegments[0].workoutSteps"
|
||||
/>
|
||||
<div v-else class="h-full">
|
||||
<WorkoutJsonEditor v-model="workingWorkout" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -272,89 +532,28 @@ onMounted(() => {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.plan-view {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
.custom-scrollbar::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
/* Toolbar & Header */
|
||||
.toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
.custom-scrollbar::-webkit-scrollbar-track {
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.browser-mode {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
.custom-scrollbar::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
}
|
||||
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.workout-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 1rem;
|
||||
gap: 1.5rem;
|
||||
padding-bottom: 2rem;
|
||||
}
|
||||
|
||||
.workout-card {
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.w-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.w-header h4 {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.badge {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
/* Editor Styles */
|
||||
.editor-mode {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.editor-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.left-controls,
|
||||
.right-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user