|
1 | 1 | import subprocess |
2 | | -from enum import Enum |
3 | 2 |
|
4 | 3 | import flet as ft |
5 | 4 |
|
6 | 5 | from components.dialogs.DownloadDialog import DownloadDialog |
7 | 6 | from components.dialogs.ErrorDialog import ErrorDialog |
| 7 | +from components.dialogs.SuccessDialog import SuccessDialog |
8 | 8 | from helper.PageState import PageState |
9 | 9 | from helper.RevisionHelper import RevisionHelper |
10 | 10 | from helper.SystemHelper import SystemHelper |
|
13 | 13 | revision_helper = RevisionHelper() |
14 | 14 |
|
15 | 15 |
|
16 | | -class RevisionType(Enum): |
17 | | - BRANCH = "BRANCH" |
18 | | - TAG = "TAG" |
19 | | - |
20 | | - |
21 | 16 | class SettingsUpdateDialog(ft.AlertDialog): |
22 | 17 | branches_list = ft.ListView() |
23 | 18 | tags_list = ft.ListView() |
24 | 19 |
|
| 20 | + curr_revision_span = ft.TextSpan("", style=ft.TextStyle(weight=ft.FontWeight.BOLD)) |
| 21 | + |
25 | 22 | def __init__(self): |
26 | 23 | super().__init__() |
27 | 24 | self.download_dialog = DownloadDialog() |
28 | 25 | self.error_dialog = ErrorDialog() |
| 26 | + self.success_dialog = SuccessDialog() |
29 | 27 |
|
30 | 28 | PageState.page.add(self.download_dialog) |
31 | 29 | PageState.page.add(self.error_dialog) |
| 30 | + PageState.page.add(self.success_dialog) |
32 | 31 |
|
33 | 32 | self.title = ft.Text( |
34 | 33 | spans=[ |
35 | 34 | ft.TextSpan("Aktueller Stand: "), |
36 | | - ft.TextSpan(self.get_current_revision(), style=ft.TextStyle(weight=ft.FontWeight.BOLD)), |
| 35 | + self.curr_revision_span, |
37 | 36 | ] |
38 | 37 | ) |
39 | 38 | self.content = ft.Column( |
@@ -62,56 +61,58 @@ def __init__(self): |
62 | 61 | def open_dialog(self): |
63 | 62 | self.fill_branches_list() |
64 | 63 | self.fill_tags_list() |
| 64 | + self.curr_revision_span.text = self._get_current_revision() |
| 65 | + self.curr_revision_span.update() |
65 | 66 | self.open = True |
66 | 67 | self.update() |
67 | 68 |
|
68 | 69 | def fill_branches_list(self): |
69 | 70 | branches = revision_helper.get_branches() |
70 | 71 |
|
71 | 72 | self.branches_list.controls.clear() |
72 | | - self.branches_list.controls = self._get_items(branches, RevisionType.BRANCH) |
| 73 | + self.branches_list.controls = self._get_items(branches) |
73 | 74 | self.branches_list.update() |
74 | 75 |
|
75 | 76 | def fill_tags_list(self): |
76 | 77 | tags = revision_helper.get_tags() |
77 | 78 |
|
78 | 79 | self.tags_list.controls.clear() |
79 | | - self.tags_list.controls = self._get_items(tags, RevisionType.TAG) |
| 80 | + self.tags_list.controls = self._get_items(tags) |
80 | 81 | self.tags_list.update() |
81 | 82 |
|
82 | | - def _get_items(self, revisions: list[str], revision_type: RevisionType): |
| 83 | + def _get_items(self, revisions: list[str]): |
83 | 84 | return [ |
84 | 85 | ft.TextButton( |
85 | 86 | content=ft.Container( |
86 | 87 | content=ft.Row( |
87 | 88 | [ |
88 | | - ft.Icon(ft.icons.DONE, visible=(r == self.get_current_revision())), |
| 89 | + ft.Icon( |
| 90 | + ft.icons.DONE, |
| 91 | + visible=(r == self._get_current_revision()), |
| 92 | + ), |
89 | 93 | ft.Text(r, size=18), |
90 | 94 | ], |
91 | 95 | ), |
92 | 96 | ), |
93 | | - on_click=lambda e, revision=r: self.on_revision_click(revision, revision_type), |
| 97 | + on_click=lambda e, revision=r: self.on_revision_click(revision), |
94 | 98 | ) |
95 | 99 | for r in revisions |
96 | 100 | ] |
97 | 101 |
|
98 | | - def on_revision_click(self, revision, revision_type): |
| 102 | + def on_revision_click(self, revision): |
99 | 103 | self.download_dialog.open_dialog(revision) |
100 | 104 | try: |
101 | | - result = subprocess.run( |
102 | | - ["bash", "scripts/update_project.sh", revision], |
103 | | - capture_output=True, |
104 | | - text=True, |
105 | | - check=True, |
| 105 | + system_helper.change_revision(revision) |
| 106 | + self.success_dialog.open_dialog( |
| 107 | + "Updates", f'Updates für "{revision}" erfolgreich heruntergeladen!', show_icon=True |
106 | 108 | ) |
107 | | - print("✅ Script output:\n", result.stdout) |
108 | 109 | except subprocess.CalledProcessError as e: |
109 | 110 | print("Script failed!") |
110 | 111 | print("Exit code:", e.returncode) |
111 | 112 | print("STDOUT:\n", e.stdout) |
112 | 113 | print("STDERR:\n", e.stderr) |
113 | | - self.error_dialog.open_dialog(e.stderr) |
| 114 | + self.error_dialog.open_dialog(e.stderr, show_icon=True) |
114 | 115 | self.download_dialog.close_dialog() |
115 | 116 |
|
116 | | - def get_current_revision(self): |
| 117 | + def _get_current_revision(self): |
117 | 118 | return revision_helper.get_current_revision() |
0 commit comments