intrgrating suggestions after betta 1
This commit is contained in:
@@ -58,6 +58,11 @@ class ArchiveInPage:
|
||||
self.selected_delete_order = order
|
||||
self.page.open(self.delete_dialog)
|
||||
|
||||
def download_order_file(self, order):
|
||||
file = order['file']
|
||||
url=f"{API_BASE_URL}/orders_in/files/{file}"
|
||||
self.page.launch_url(url)
|
||||
|
||||
def load_orders(self):
|
||||
try:
|
||||
token = self.page.client_storage.get("token")
|
||||
@@ -90,6 +95,11 @@ class ArchiveInPage:
|
||||
self.orders_list.controls.clear()
|
||||
for order in self.orders:
|
||||
client = self.get_client(order['client_id'])
|
||||
buttons = []
|
||||
if order.get("file"):
|
||||
buttons.append(ft.Button("Download", icon=ft.Icons.DOWNLOAD, on_click=lambda e, o=order: self.download_order_file(o)))
|
||||
buttons.append(ft.Button("View", icon=ft.Icons.PICTURE_AS_PDF, on_click=lambda e, o=order: self.view_order(o)))
|
||||
buttons.append(ft.Button("Delete", icon=ft.Icons.CANCEL, on_click=lambda e, o=order: self.cancel_order(o)))
|
||||
self.orders_list.controls.append(
|
||||
ft.Container(
|
||||
content=ft.Row([
|
||||
@@ -97,8 +107,7 @@ class ArchiveInPage:
|
||||
ft.Text(f"{client}", size=16, weight=ft.FontWeight.BOLD),
|
||||
ft.Text(f"Order Number: {order['order_number']}", size=14),
|
||||
], expand=True),
|
||||
ft.Button("View",icon=ft.Icons.PICTURE_AS_PDF, on_click=lambda e, o=order: self.view_order(o)),
|
||||
ft.Button("Delete", icon=ft.Icons.CANCEL, on_click=lambda e, o=order: self.cancel_order(o))
|
||||
*buttons
|
||||
]),
|
||||
padding=10,
|
||||
border=ft.border.all(1, ft.Colors.GREY_300),
|
||||
@@ -108,6 +117,18 @@ class ArchiveInPage:
|
||||
)
|
||||
self.page.update()
|
||||
|
||||
def get_client_access(self):
|
||||
token = self.page.client_storage.get("token")
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
response = requests.get(f"{API_BASE_URL}/profile/", headers=headers, timeout=10)
|
||||
user = response.json()
|
||||
if user['user_role'] == 'user':
|
||||
return True
|
||||
else:
|
||||
id = self.page.session.get("user_id")
|
||||
response = requests.get(f"{API_BASE_URL}/company_user/access/{id}", headers=headers)
|
||||
return True if response.json()['orders_in'] == 1 else False
|
||||
|
||||
def build(self):
|
||||
self.refresh()
|
||||
return ft.Container(
|
||||
@@ -115,7 +136,7 @@ class ArchiveInPage:
|
||||
[
|
||||
ft.Row(
|
||||
[
|
||||
ft.Text("Archive", size=24, weight=ft.FontWeight.BOLD),
|
||||
ft.Text("Archive Orders In", size=24, weight=ft.FontWeight.BOLD),
|
||||
ft.Button("Back", icon=ft.Icons.ARROW_BACK_IOS_NEW, on_click=self.on_go_back_btn_click)
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
|
||||
@@ -123,4 +144,30 @@ class ArchiveInPage:
|
||||
self.orders_list
|
||||
]
|
||||
)
|
||||
) if self.get_client_access() else ft.Container(
|
||||
content=ft.Column(
|
||||
[
|
||||
ft.Row(
|
||||
[
|
||||
ft.Text("Archive Orders In", size=24, weight=ft.FontWeight.BOLD),
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
|
||||
),
|
||||
ft.Row(
|
||||
[
|
||||
ft.Text(
|
||||
"You do not have access to this page content",
|
||||
size=24,
|
||||
weight=ft.FontWeight.BOLD,
|
||||
color=ft.Colors.RED
|
||||
)
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.CENTER
|
||||
),
|
||||
ft.Text("")
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
||||
expand=True
|
||||
),
|
||||
expand=True
|
||||
)
|
||||
Reference in New Issue
Block a user