diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/__pycache__/__init__.cpython-310.pyc b/backend/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..07d5af7 Binary files /dev/null and b/backend/__pycache__/__init__.cpython-310.pyc differ diff --git a/backend/app.py b/backend/app.py index c295683..20bc044 100644 --- a/backend/app.py +++ b/backend/app.py @@ -3,8 +3,8 @@ import os import sys from pathlib import Path -# Add the backend directory to Python path -backend_dir = Path(__file__).parent +# Add the parent directory to Python path +backend_dir = Path(__file__).parent.parent # Sube un nivel más para incluir la carpeta raíz if str(backend_dir) not in sys.path: sys.path.append(str(backend_dir)) @@ -56,11 +56,14 @@ def create_profile(): @app.route('/api/profiles/', methods=['PUT']) def update_profile(profile_id): """Update existing profile""" - profile_data = request.json try: + profile_data = request.json + print(f"Received update request for profile {profile_id}: {profile_data}") # Debug profile = profile_manager.update_profile(profile_id, profile_data) + print(f"Profile updated: {profile}") # Debug return jsonify(profile) except Exception as e: + print(f"Error updating profile: {e}") # Debug return jsonify({"error": str(e)}), 400 @app.route('/api/profiles/', methods=['DELETE']) @@ -72,11 +75,33 @@ def delete_profile(profile_id): except Exception as e: return jsonify({"error": str(e)}), 400 +@app.route('/api/script-groups', methods=['GET']) +def get_script_groups(): + """Get all available script groups""" + try: + groups = script_manager.get_available_groups() + return jsonify(groups) + except Exception as e: + return jsonify({"error": str(e)}), 500 + +@app.route('/api/script-groups//scripts', methods=['GET']) +def get_group_scripts(group_id): + """Get scripts for a specific group""" + try: + scripts = script_manager.get_group_scripts(group_id) + return jsonify(scripts) + except ValueError as e: + return jsonify({"error": str(e)}), 404 + except Exception as e: + return jsonify({"error": str(e)}), 500 + # Directory handling endpoints @app.route('/api/select-directory', methods=['GET']) def handle_select_directory(): """Handle directory selection""" + print("Handling directory selection request") # Debug result = select_directory() + print(f"Directory selection result: {result}") # Debug if "error" in result: return jsonify(result), 400 return jsonify(result) diff --git a/backend/core/__pycache__/directory_handler.cpython-310.pyc b/backend/core/__pycache__/directory_handler.cpython-310.pyc index 1bd90e3..8f1efa0 100644 Binary files a/backend/core/__pycache__/directory_handler.cpython-310.pyc and b/backend/core/__pycache__/directory_handler.cpython-310.pyc differ diff --git a/backend/core/__pycache__/profile_manager.cpython-310.pyc b/backend/core/__pycache__/profile_manager.cpython-310.pyc index a11e478..bfba5bc 100644 Binary files a/backend/core/__pycache__/profile_manager.cpython-310.pyc and b/backend/core/__pycache__/profile_manager.cpython-310.pyc differ diff --git a/backend/core/__pycache__/script_manager.cpython-310.pyc b/backend/core/__pycache__/script_manager.cpython-310.pyc index 3962c1f..97eb113 100644 Binary files a/backend/core/__pycache__/script_manager.cpython-310.pyc and b/backend/core/__pycache__/script_manager.cpython-310.pyc differ diff --git a/backend/core/directory_handler.py b/backend/core/directory_handler.py index ef81c63..ea44391 100644 --- a/backend/core/directory_handler.py +++ b/backend/core/directory_handler.py @@ -13,12 +13,17 @@ def select_directory(): root.withdraw() # Hide the main window try: + print("Opening directory dialog...") # Debug directory = filedialog.askdirectory( title="Select Work Directory", initialdir=os.path.expanduser("~") ) - return {"path": directory} if directory else {"error": "No directory selected"} + print(f"Selected directory: {directory}") # Debug + result = {"path": directory} if directory else {"error": "No directory selected"} + print(f"Returning result: {result}") # Debug + return result except Exception as e: + print(f"Error in select_directory: {str(e)}") # Debug return {"error": str(e)} finally: root.destroy() \ No newline at end of file diff --git a/backend/core/profile_manager.py b/backend/core/profile_manager.py index 341b5ec..8b0037b 100644 --- a/backend/core/profile_manager.py +++ b/backend/core/profile_manager.py @@ -58,8 +58,14 @@ class ProfileManager: """Save profiles to file""" if profiles is None: profiles = self.profiles - with open(self.profiles_file, 'w', encoding='utf-8') as f: - json.dump(profiles, f, indent=4) + try: + print(f"Saving profiles to: {self.profiles_file}") # Agregar debug + with open(self.profiles_file, 'w', encoding='utf-8') as f: + json.dump(profiles, f, indent=4) + print("Profiles saved successfully") # Agregar debug + except Exception as e: + print(f"Error saving profiles: {e}") # Agregar debug + raise # Re-lanzar la excepción para que se maneje arriba def get_all_profiles(self) -> List[Dict[str, Any]]: """Get all profiles""" @@ -94,19 +100,28 @@ class ProfileManager: def update_profile(self, profile_id: str, profile_data: Dict[str, Any]) -> Dict[str, Any]: """Update existing profile""" - if profile_id not in self.profiles: - raise ValueError(f"Profile {profile_id} not found") + try: + print(f"Updating profile {profile_id} with data: {profile_data}") + if profile_id not in self.profiles: + raise ValueError(f"Profile {profile_id} not found") + + if profile_id == "default" and "id" in profile_data: + raise ValueError("Cannot change id of default profile") - if profile_id == "default" and "id" in profile_data: - raise ValueError("Cannot change id of default profile") - - # Update timestamp - profile_data["updated_at"] = datetime.now().isoformat() - - # Update profile - self.profiles[profile_id].update(profile_data) - self._save_profiles() - return self.profiles[profile_id] + # Update timestamp + profile_data["updated_at"] = datetime.now().isoformat() + + # Update profile + current_profile = self.profiles[profile_id].copy() # Hacer una copia + current_profile.update(profile_data) # Actualizar la copia + self.profiles[profile_id] = current_profile # Asignar la copia actualizada + + print(f"Updated profile: {self.profiles[profile_id]}") + self._save_profiles() + return self.profiles[profile_id] + except Exception as e: + print(f"Error in update_profile: {e}") # Agregar debug + raise def delete_profile(self, profile_id: str): """Delete profile""" diff --git a/backend/core/script_manager.py b/backend/core/script_manager.py index cf6f0fa..72609a1 100644 --- a/backend/core/script_manager.py +++ b/backend/core/script_manager.py @@ -6,6 +6,34 @@ from typing import Dict, List, Any, Optional import json class ScriptManager: + def get_available_groups(self) -> List[Dict[str, Any]]: + """Get list of available script groups""" + groups = [] + + for group_dir in self.script_groups_dir.iterdir(): + if group_dir.is_dir() and not group_dir.name.startswith('_'): + groups.append({ + "id": group_dir.name, + "name": group_dir.name.replace('_', ' ').title(), + "path": str(group_dir) + }) + + return groups + + def get_group_scripts(self, group_id: str) -> List[Dict[str, Any]]: + """Get scripts for a specific group""" + group_dir = self.script_groups_dir / group_id + + if not group_dir.exists() or not group_dir.is_dir(): + raise ValueError(f"Script group '{group_id}' not found") + + scripts = [] + for script_file in group_dir.glob('x[0-9].py'): + script_info = self._analyze_script(script_file) + if script_info: + scripts.append(script_info) + + return sorted(scripts, key=lambda x: x['id']) """Manages script discovery and execution""" def __init__(self, script_groups_dir: Path): diff --git a/backend/script_groups/__pycache__/__init__.cpython-310.pyc b/backend/script_groups/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..97b55df Binary files /dev/null and b/backend/script_groups/__pycache__/__init__.cpython-310.pyc differ diff --git a/backend/script_groups/__pycache__/base_script.cpython-310.pyc b/backend/script_groups/__pycache__/base_script.cpython-310.pyc new file mode 100644 index 0000000..61187d6 Binary files /dev/null and b/backend/script_groups/__pycache__/base_script.cpython-310.pyc differ diff --git a/backend/script_groups/example_group/__pycache__/x1.cpython-310.pyc b/backend/script_groups/example_group/__pycache__/x1.cpython-310.pyc index c1e701b..ce249e2 100644 Binary files a/backend/script_groups/example_group/__pycache__/x1.cpython-310.pyc and b/backend/script_groups/example_group/__pycache__/x1.cpython-310.pyc differ diff --git a/backend/script_groups/example_group/__pycache__/x2.cpython-310.pyc b/backend/script_groups/example_group/__pycache__/x2.cpython-310.pyc index 8a20ed3..e02ef0f 100644 Binary files a/backend/script_groups/example_group/__pycache__/x2.cpython-310.pyc and b/backend/script_groups/example_group/__pycache__/x2.cpython-310.pyc differ diff --git a/backend/script_groups/example_group/x1.py b/backend/script_groups/example_group/x1.py index 3dc0f84..f5ba050 100644 --- a/backend/script_groups/example_group/x1.py +++ b/backend/script_groups/example_group/x1.py @@ -1,5 +1,5 @@ # backend/script_groups/example_group/x1.py -from ..base_script import BaseScript +from backend.script_groups.base_script import BaseScript import os from pathlib import Path diff --git a/backend/script_groups/example_group/x2.py b/backend/script_groups/example_group/x2.py index f2dfbef..917c107 100644 --- a/backend/script_groups/example_group/x2.py +++ b/backend/script_groups/example_group/x2.py @@ -1,5 +1,5 @@ # backend/script_groups/example_group/x2.py -from ..base_script import BaseScript +from backend.script_groups.base_script import BaseScript import psutil import json from datetime import datetime diff --git a/data/profiles.json b/data/profiles.json index ea2b923..3b68f75 100644 --- a/data/profiles.json +++ b/data/profiles.json @@ -14,13 +14,13 @@ "1": { "id": "1", "name": "Base", - "work_dir": "D:/Proyectos/AutoCAD", + "work_dir": "C:/Estudio", "llm_settings": { "api_key": "333333333333", "model": "gpt-4", "temperature": 0.7 }, "created_at": "2025-02-07T13:00:43.541932", - "updated_at": "2025-02-07T13:01:40.473406" + "updated_at": "2025-02-07T23:34:43.039269" } } \ No newline at end of file diff --git a/files.txt b/files.txt index dd78c0b..8b81891 100644 Binary files a/files.txt and b/files.txt differ diff --git a/frontend/static/css/style.css b/frontend/static/css/style.css index bc6f798..60220d9 100644 --- a/frontend/static/css/style.css +++ b/frontend/static/css/style.css @@ -160,4 +160,33 @@ margin-top: 0.5rem; white-space: pre-wrap; font-size: 0.9rem; +} + +/* frontend/static/css/style.css */ + +.script-group-selector { + margin-bottom: 20px; + padding: 1rem; + background: white; + border-radius: 8px; + box-shadow: 0 2px 4px rgba(0,0,0,0.1); +} + +.script-group-selector label { + display: block; + margin-bottom: 0.5rem; + font-weight: 500; +} + +.script-group-selector select { + width: 100%; + padding: 0.5rem; + border: 1px solid var(--border-color); + border-radius: 4px; + background: white; +} + +#scriptList { + display: none; + margin-top: 1rem; } \ No newline at end of file diff --git a/frontend/static/js/main.js b/frontend/static/js/main.js index 1b2c923..3ca3e02 100644 --- a/frontend/static/js/main.js +++ b/frontend/static/js/main.js @@ -93,19 +93,26 @@ function updateWorkDirDisplay() { async function selectWorkDir() { try { + console.log('Requesting directory selection...'); // Debug const response = await apiRequest('/select-directory'); + console.log('Directory selection response:', response); // Debug + if (response.path) { - await apiRequest(`/profiles/${currentProfile.id}`, { + console.log('Updating profile with new work_dir:', response.path); // Debug + const updateResponse = await apiRequest(`/profiles/${currentProfile.id}`, { method: 'PUT', body: JSON.stringify({ ...currentProfile, work_dir: response.path }) }); + console.log('Profile update response:', updateResponse); // Debug + await selectProfile(currentProfile.id); showSuccess('Work directory updated successfully'); } } catch (error) { + console.error('Error in selectWorkDir:', error); // Debug showError('Failed to update work directory'); } } diff --git a/frontend/static/js/scripts.js b/frontend/static/js/scripts.js index 1b61ff0..6450434 100644 --- a/frontend/static/js/scripts.js +++ b/frontend/static/js/scripts.js @@ -8,16 +8,60 @@ document.addEventListener('DOMContentLoaded', async () => { await loadScriptGroups(); }); -// Load script groups from API +// Load script groups when page loads +document.addEventListener('DOMContentLoaded', async () => { + await loadScriptGroups(); +}); + +// Load available script groups async function loadScriptGroups() { try { - scriptGroups = await apiRequest('/scripts'); - updateScriptGroupsDisplay(); + const groups = await apiRequest('/script-groups'); + const select = document.getElementById('groupSelect'); + + select.innerHTML = ` + + ${groups.map(group => ` + + `).join('')} + `; } catch (error) { showError('Failed to load script groups'); } } +// Load scripts for selected group +async function loadGroupScripts(groupId) { + const scriptList = document.getElementById('scriptList'); + + if (!groupId) { + scriptList.style.display = 'none'; + return; + } + + try { + const scripts = await apiRequest(`/script-groups/${groupId}/scripts`); + + scriptList.innerHTML = scripts.map(script => ` +
+
+

${script.name}

+

${script.description || 'No description available'}

+
+
+ +
+
+ `).join(''); + + scriptList.style.display = 'block'; + } catch (error) { + showError('Failed to load scripts for group'); + } +} + // Update script groups display function updateScriptGroupsDisplay() { const container = document.getElementById('scriptGroups'); diff --git a/frontend/templates/index.html b/frontend/templates/index.html index 89a43a4..d7ea1cd 100644 --- a/frontend/templates/index.html +++ b/frontend/templates/index.html @@ -32,9 +32,16 @@
-

Available Scripts

-
- +

Scripts

+
+ + +
+