|
| 1 | +import flet as ft |
| 2 | +import logging |
| 3 | +import os |
| 4 | +from pathlib import Path |
| 5 | +from switchcraft.gui_modern.utils.view_utils import ViewMixin |
| 6 | +from switchcraft.utils.i18n import i18n |
| 7 | +from switchcraft.services.sap_service import SapService |
| 8 | + |
| 9 | +logger = logging.getLogger(__name__) |
| 10 | + |
| 11 | +class SapWizardView(ft.Column, ViewMixin): |
| 12 | + """ |
| 13 | + Wizard-style UI for SAP Installation Server management. |
| 14 | + Handles merging updates, customization, and packaging. |
| 15 | + """ |
| 16 | + |
| 17 | + def __init__(self, page: ft.Page): |
| 18 | + super().__init__(expand=True, scroll=ft.ScrollMode.AUTO) |
| 19 | + self.app_page = page |
| 20 | + self.sap_service = SapService() |
| 21 | + |
| 22 | + # State |
| 23 | + self.server_path = "" |
| 24 | + self.update_files = [] |
| 25 | + self.logo_path = "" |
| 26 | + self.use_webview2 = True |
| 27 | + |
| 28 | + self.current_step = 1 |
| 29 | + self.content_area = ft.Container(expand=True) |
| 30 | + self.controls = [ |
| 31 | + ft.Text(i18n.get("sap_wizard_title") or "SAP Management Wizard", size=24, weight=ft.FontWeight.BOLD), |
| 32 | + ft.Divider(), |
| 33 | + self.content_area, |
| 34 | + self._build_nav_buttons() |
| 35 | + ] |
| 36 | + |
| 37 | + self._show_step(1) |
| 38 | + |
| 39 | + def _show_step(self, step_num): |
| 40 | + self.current_step = step_num |
| 41 | + if step_num == 1: |
| 42 | + self.content_area.content = self._build_step_1() |
| 43 | + elif step_num == 2: |
| 44 | + self.content_area.content = self._build_step_2() |
| 45 | + elif step_num == 3: |
| 46 | + self.content_area.content = self._build_step_3() |
| 47 | + elif step_num == 4: |
| 48 | + self.content_area.content = self._build_step_4() |
| 49 | + self.update() |
| 50 | + |
| 51 | + def _build_step_1(self): |
| 52 | + """Step 1: Select SAP Installation Server path.""" |
| 53 | + def on_pick_server(e: ft.FilePickerResultEvent): |
| 54 | + if e.path: |
| 55 | + self.server_path = e.path |
| 56 | + path_text.value = e.path |
| 57 | + self.update() |
| 58 | + |
| 59 | + path_text = ft.Text(self.server_path or "No path selected", italic=True) |
| 60 | + fp = ft.FilePicker() |
| 61 | + fp.on_result = on_pick_server |
| 62 | + self.app_page.overlay.append(fp) |
| 63 | + |
| 64 | + return ft.Column([ |
| 65 | + ft.Text(i18n.get("sap_step1_title") or "1. Select SAP Installation Server", size=18, weight=ft.FontWeight.BOLD), |
| 66 | + ft.Text(i18n.get("sap_step1_desc") or "Point to the root folder of your SAP nwsetupadmin server."), |
| 67 | + ft.Row([ |
| 68 | + ft.ElevatedButton(i18n.get("btn_browse_folder") or "Browse Server Folder", icon=ft.Icons.FOLDER_OPEN, on_click=lambda _: fp.get_directory_path()), |
| 69 | + path_text |
| 70 | + ]) |
| 71 | + ]) |
| 72 | + |
| 73 | + def _build_step_2(self): |
| 74 | + """Step 2: Add Updates/Add-ons.""" |
| 75 | + return ft.Column([ |
| 76 | + ft.Text(i18n.get("sap_step2_title") or "2. Add Updates & Add-ons (Optional)", size=18, weight=ft.FontWeight.BOLD), |
| 77 | + ft.Text(i18n.get("sap_step2_desc") or "Select .exe files to merge into the installation server."), |
| 78 | + ft.ElevatedButton(i18n.get("btn_add_update") or "Add Update EXE", icon=ft.Icons.ADD, on_click=lambda _: self._show_snack("Not implemented in stub")), |
| 79 | + ft.ListView(expand=True, height=100) # Placeholder for file list |
| 80 | + ]) |
| 81 | + |
| 82 | + def _build_step_3(self): |
| 83 | + """Step 3: Customization.""" |
| 84 | + return ft.Column([ |
| 85 | + ft.Text(i18n.get("sap_step3_title") or "3. Customization", size=18, weight=ft.FontWeight.BOLD), |
| 86 | + ft.Checkbox(label=i18n.get("sap_use_webview2") or "Default to Edge WebView2 (Recommended)", value=self.use_webview2, on_change=lambda e: setattr(self, 'use_webview2', e.control.value)), |
| 87 | + ft.Row([ |
| 88 | + ft.ElevatedButton(i18n.get("btn_select_logo") or "Select Custom Logo", icon=ft.Icons.IMAGE), |
| 89 | + ft.Text(i18n.get("no_logo_selected") or "No logo selected", italic=True) |
| 90 | + ]) |
| 91 | + ]) |
| 92 | + |
| 93 | + def _build_step_4(self): |
| 94 | + """Step 4: Summary & Packaging.""" |
| 95 | + return ft.Column([ |
| 96 | + ft.Text(i18n.get("sap_step4_title") or "4. Summary & Packaging", size=18, weight=ft.FontWeight.BOLD), |
| 97 | + ft.Text(f"{i18n.get('label_server') or 'Server'}: {self.server_path}"), |
| 98 | + ft.Text(f"{i18n.get('label_custom_logo') or 'Custom Logo'}: {'Yes' if self.logo_path else 'No'}"), |
| 99 | + ft.Text(f"{i18n.get('label_webview2') or 'Edge WebView2'}: {'Enabled' if self.use_webview2 else 'Disabled'}"), |
| 100 | + ft.Divider(), |
| 101 | + ft.ElevatedButton(i18n.get("btn_apply_build") or "Apply & Build Packaging", icon=ft.Icons.BUILD_CIRCLE, bgcolor="PRIMARY", color="WHITE", on_click=self._on_finalize) |
| 102 | + ]) |
| 103 | + |
| 104 | + def _build_nav_buttons(self): |
| 105 | + return ft.Row([ |
| 106 | + ft.TextButton(i18n.get("btn_back") or "Back", on_click=lambda _: self._show_step(self.current_step - 1) if self.current_step > 1 else None), |
| 107 | + ft.ElevatedButton(i18n.get("btn_next") or "Next", on_click=lambda _: self._show_step(self.current_step + 1) if self.current_step < 4 else None) |
| 108 | + ], alignment=ft.MainAxisAlignment.END) |
| 109 | + |
| 110 | + def _on_finalize(self, _): |
| 111 | + if not self.server_path: |
| 112 | + self._show_snack("Please select a server path first.", color="RED") |
| 113 | + return |
| 114 | + |
| 115 | + try: |
| 116 | + self.sap_service.customize_server(self.server_path, self.logo_path, self.use_webview2) |
| 117 | + self._show_snack("SAP Server customized successfully!", color="GREEN") |
| 118 | + # In a real app, we would now trigger the packaging process |
| 119 | + except Exception as e: |
| 120 | + self._show_snack(f"Error: {e}", color="RED") |
0 commit comments