add article and pubications

This commit is contained in:
2026-06-25 10:30:24 +03:00
parent 7fa8a9b7fc
commit 7206a0a0c5
25 changed files with 1180 additions and 86 deletions

View File

@@ -73,6 +73,13 @@ class Documents:
disabled=True, # Will be enabled based on status
visible=False # Initially hidden
)
self.download_button = ft.FilledButton(
"Descarcă Document Final",
icon=ft.Icons.DOWNLOAD,
on_click=self._on_download_button_click,
disabled=True, # Will be enabled based on status and document_id
visible=False # Initially hidden
)
self.comment_text_field = ft.TextField(
label="Adauga un comentariu",
multiline=True,
@@ -96,11 +103,13 @@ class Documents:
ft.Text("Pret:", weight=ft.FontWeight.BOLD),
self.request_price_text,
self.pay_button,
self.download_button,
ft.Divider(),
ft.Text("Adauga Comentariu:", weight=ft.FontWeight.BOLD),
ft.Row([self.comment_text_field, self.add_comment_button]),
],
expand=True,
scroll=ft.ScrollMode.ADAPTIVE,
visible=False # Initially hidden
)
@@ -186,6 +195,14 @@ class Documents:
self.pay_button.visible = False
self.pay_button.disabled = True
# Handle Download button visibility and state
if request_data.get('status') == DocumentsStatus.COMPLETED and request_data.get('document_id'):
self.download_button.visible = True
self.download_button.disabled = False
else:
self.download_button.visible = False
self.download_button.disabled = True
# Enable comment section
self.add_comment_button.disabled = False
self.comment_text_field.disabled = False
@@ -308,6 +325,36 @@ class Documents:
))
self.page.update()
async def _on_download_button_click(self, e):
"""Handles the download of the final document."""
if not self.current_selected_request or not self.current_selected_request.get('document_id'):
self.page.show_dialog(ft.SnackBar(ft.Text("Nu există un document final asociat acestei solicitări."), open=True))
self.page.update()
return
document_id = self.current_selected_request['document_id']
try:
# Fetch document details to get the path
response = requests.get(
f"{self.base_url}/documents/customs/{document_id}",
headers={'Authorization': f'Bearer {self.token}'}
)
if response.status_code == 200:
document_data = response.json()
document_path = document_data.get('path')
if document_path:
download_url = f"{self.base_url}/documents/download?path={document_path}&token={self.token}"
await self.page.launch_url(download_url)
else:
self.page.show_dialog(ft.SnackBar(ft.Text("Calea documentului nu a putut fi găsită."), open=True))
else:
self.page.show_dialog(ft.SnackBar(ft.Text(f"Eroare la preluarea detaliilor documentului: {response.status_code}"), open=True))
except requests.exceptions.RequestException as err:
self.page.show_dialog(ft.SnackBar(ft.Text(f"Eroare de rețea la descărcarea documentului: {err}"), open=True))
except Exception as ex:
self.page.show_dialog(ft.SnackBar(ft.Text(f"A apărut o eroare neașteptată: {ex}"), open=True))
self.page.update()
def _close_dialog(self, e):
self.page.pop_dialog()
self.page.update()