Transform rename button to full edit functionality

- Replace rename modal with comprehensive edit modal supporting name, MAC, and IP changes
- Add edit_computer() method with full validation (MAC format, duplicates)
- Create new /api/edit endpoint accepting all computer attributes
- Update frontend JavaScript for multi-field editing with client-side validation
- Rename functions from openRenameModal/performRename to openEditModal/performEdit
- Pre-populate edit form with current values and validate MAC address format

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-07 00:10:21 +03:00
parent 86931a091e
commit 072553953e
3 changed files with 139 additions and 37 deletions

View File

@@ -198,6 +198,76 @@ class WOLManager:
return {'success': True, 'message': f'Computerul {deleted_name} a fost șters!'}
def edit_computer(self, old_name, new_name, new_mac, new_ip=None):
"""Editează un calculator existent - permite modificarea numelui, MAC-ului și IP-ului"""
if not new_name.strip():
return {'success': False, 'message': 'Numele nou nu poate fi gol!'}
if not new_mac.strip():
return {'success': False, 'message': 'Adresa MAC nu poate fi goală!'}
# Validează formatul MAC-ului (XX:XX:XX:XX:XX:XX)
import re
mac_pattern = r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
if not re.match(mac_pattern, new_mac):
return {'success': False, 'message': 'Formatul MAC-ului este invalid! Folosește formatul XX:XX:XX:XX:XX:XX'}
# Normalizează MAC-ul (lowercase și cu :)
new_mac = new_mac.lower().replace('-', ':')
computers = []
found = False
old_mac = None
# Citește toate computerele
if os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, 'r') as f:
for line in f:
line = line.strip()
if line and not line.startswith('#'):
parts = line.split('|')
if len(parts) >= 2:
if parts[0] == old_name:
old_mac = parts[1]
found = True
# Verifică dacă noul MAC este diferit și nu există deja
if new_mac != old_mac.lower():
# Verifică dacă noul MAC există deja la alt computer
for check_line in computers:
if not check_line.startswith('#') and check_line.strip():
check_parts = check_line.split('|')
if len(check_parts) >= 2 and check_parts[1].lower() == new_mac:
return {'success': False, 'message': f'Adresa MAC {new_mac} este deja folosită de alt computer!'}
# Actualizează computerul cu noile valori
new_ip_value = new_ip.strip() if new_ip else ''
computers.append(f"{new_name}|{new_mac}|{new_ip_value}")
else:
# Verifică dacă noul MAC este folosit de alt computer
if parts[1].lower() == new_mac and parts[0] != old_name:
return {'success': False, 'message': f'Adresa MAC {new_mac} este deja folosită de computerul "{parts[0]}"!'}
computers.append(line)
else:
computers.append(line)
if not found:
return {'success': False, 'message': f'Computerul "{old_name}" nu a fost găsit!'}
# Verifică dacă noul nume există deja (doar dacă s-a schimbat numele)
if new_name != old_name:
for computer_line in computers:
if not computer_line.startswith('#') and computer_line.strip():
parts = computer_line.split('|')
if len(parts) >= 2 and parts[0] == new_name and not computer_line.startswith(f"{new_name}|{new_mac}|"):
return {'success': False, 'message': f'Numele "{new_name}" este deja folosit de alt computer!'}
# Rescrie fișierul
with open(CONFIG_FILE, 'w') as f:
for computer_line in computers:
f.write(computer_line + '\n')
return {'success': True, 'message': f'Computerul a fost actualizat cu succes!'}
def scan_network(self, custom_network=None):
try:
# Încearcă să citească rezultatele scanului Windows mai întâi
@@ -398,6 +468,17 @@ def rename_computer():
)
return jsonify(result)
@app.route('/api/edit', methods=['POST'])
def edit_computer():
data = request.get_json()
result = wol_manager.edit_computer(
data.get('old_name'),
data.get('new_name'),
data.get('new_mac'),
data.get('new_ip')
)
return jsonify(result)
@app.route('/api/delete', methods=['POST'])
def delete_computer():
data = request.get_json()