implemented step 12 by Gemini
- Task actions
This commit is contained in:
@ -64,6 +64,7 @@ try {
|
||||
|
||||
// Router
|
||||
$projectActions = new \App\Actions\ProjectActions();
|
||||
$taskActions = new \App\Actions\TaskActions();
|
||||
$consentService = new \App\Services\ConsentService();
|
||||
|
||||
switch ($action) {
|
||||
@ -130,6 +131,14 @@ try {
|
||||
sendResponse(true, $result);
|
||||
break;
|
||||
|
||||
case 'generateWebsite':
|
||||
$projectId = $data['project_id'] ?? null;
|
||||
if (!$projectId) {
|
||||
sendResponse(false, ['code' => 'MISSING_PROJECT_ID', 'message' => 'Project ID is required.'], 400);
|
||||
}
|
||||
sendResponse(true, $taskActions->generateWebsite($userId, $projectId));
|
||||
break;
|
||||
|
||||
default:
|
||||
sendResponse(false, ['code' => 'UNKNOWN_ACTION', 'message' => "Action '$action' is not defined."], 404);
|
||||
break;
|
||||
|
||||
@ -482,6 +482,33 @@ textarea:focus, input[type="text"]:focus, input[type="email"]:focus, input[type=
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* Generation Loader */
|
||||
.generation-loader {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1.5rem;
|
||||
padding: 3rem 0;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
border: 4px solid var(--border-color);
|
||||
border-top-color: var(--primary-color);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
#generation-status {
|
||||
font-weight: 500;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
|
||||
@ -307,9 +307,11 @@
|
||||
<!-- Step 6: Generovanie -->
|
||||
<div class="step" data-step="6">
|
||||
<h2>Generovanie obsahu</h2>
|
||||
<p class="step-description">Naša AI teraz pripravuje váš textový obsah.</p>
|
||||
<div class="form-placeholder">
|
||||
<p>Obsah pre krok 6...</p>
|
||||
<p class="step-description">Naša AI teraz pripravuje váš textový obsah a štruktúru webu. Môže to trvať niekoľko desiatok sekúnd.</p>
|
||||
|
||||
<div class="generation-loader">
|
||||
<div class="spinner"></div>
|
||||
<p id="generation-status">Čakám na zaradenie do fronty...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -50,6 +50,13 @@ const App = {
|
||||
this.state.currentStep = this.state.project.current_step || 1;
|
||||
console.log('Loaded existing project:', this.state.project.project_id);
|
||||
this.syncSelectionWithProject();
|
||||
|
||||
// Resume polling if generating
|
||||
const pollingStatuses = ['queued', 'generating', 'rendering'];
|
||||
if (pollingStatuses.includes(this.state.project.status)) {
|
||||
this.state.currentStep = 6;
|
||||
this.startPolling();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await this.createProject();
|
||||
@ -708,9 +715,66 @@ const App = {
|
||||
|
||||
if (this.state.currentStep < this.state.totalSteps) {
|
||||
this.showStep(this.state.currentStep + 1);
|
||||
|
||||
// Trigger generation if entering step 6
|
||||
if (this.state.currentStep === 6) {
|
||||
this.startWebsiteGeneration();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async startWebsiteGeneration() {
|
||||
try {
|
||||
const result = await this.apiCall('generateWebsite');
|
||||
if (result.success) {
|
||||
console.log('Generation started:', result.data.task_id);
|
||||
this.startPolling();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to start generation:', error);
|
||||
document.getElementById('generation-status').textContent = 'Chyba: ' + error.message;
|
||||
}
|
||||
},
|
||||
|
||||
startPolling() {
|
||||
if (this.pollingInterval) clearInterval(this.pollingInterval);
|
||||
|
||||
this.pollingInterval = setInterval(async () => {
|
||||
try {
|
||||
const response = await this.apiCall('getProjectStatus');
|
||||
if (response.success) {
|
||||
const project = response.data;
|
||||
this.state.project = project;
|
||||
this.updateGenerationStatus(project.status);
|
||||
|
||||
if (project.status === 'ready' || project.status === 'failed') {
|
||||
clearInterval(this.pollingInterval);
|
||||
if (project.status === 'ready') {
|
||||
// Move to preview step
|
||||
this.showStep(7);
|
||||
} else {
|
||||
document.getElementById('generation-status').textContent = 'Generovanie zlyhalo. Skúste to neskôr.';
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Polling error:', error);
|
||||
}
|
||||
}, 3000);
|
||||
},
|
||||
|
||||
updateGenerationStatus(status) {
|
||||
const statusEl = document.getElementById('generation-status');
|
||||
const messages = {
|
||||
'queued': 'Zaradené do fronty, čakám na AI...',
|
||||
'generating': 'AI práve píše texty pre váš web...',
|
||||
'rendering': 'Skladáme výslednú stránku...',
|
||||
'ready': 'Hotovo! Pripravujem náhľad...',
|
||||
'failed': 'Nastal problém pri generovaní.'
|
||||
};
|
||||
statusEl.textContent = messages[status] || 'Spracovávam...';
|
||||
},
|
||||
|
||||
prevStep() {
|
||||
if (this.state.currentStep > 1) {
|
||||
this.showStep(this.state.currentStep - 1);
|
||||
@ -749,6 +813,9 @@ const App = {
|
||||
|
||||
btnNext.disabled = nextDisabled;
|
||||
|
||||
// Hide footer in generating step
|
||||
document.querySelector('.wizard-footer').classList.toggle('hidden', this.state.currentStep === 6);
|
||||
|
||||
if (this.state.currentStep === this.state.totalSteps) {
|
||||
btnNext.textContent = 'Dokončiť';
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user