add V2
This commit is contained in:
128
UI_V2/admin/dashboard.py
Normal file
128
UI_V2/admin/dashboard.py
Normal file
@@ -0,0 +1,128 @@
|
||||
import flet as ft
|
||||
from admin.category import Category
|
||||
from admin.products import ProductsPage
|
||||
from admin.banner import Banner
|
||||
from admin.orders import OrdersPage
|
||||
from admin.clients import Clients
|
||||
|
||||
class Dashboard:
|
||||
def __init__(self, page: ft.Page):
|
||||
self.page = page
|
||||
self.category = Category(self.page)
|
||||
self.placeholder = ft.Container(
|
||||
content=self.category.build(),
|
||||
padding=10,
|
||||
expand=True
|
||||
)
|
||||
self.rail = ft.NavigationRail(
|
||||
selected_index=0,
|
||||
label_type=ft.NavigationRailLabelType.ALL,
|
||||
min_width=100,
|
||||
#min_extended_width=400,
|
||||
leading=ft.Image('images/tainagustului.png', width=80),
|
||||
group_alignment=-0.9,
|
||||
destinations=[
|
||||
ft.NavigationRailDestination(
|
||||
icon=ft.Icons.CATEGORY_OUTLINED,
|
||||
selected_icon=ft.Icons.CATEGORY_ROUNDED,
|
||||
label="Categori",
|
||||
),
|
||||
ft.NavigationRailDestination(
|
||||
icon=ft.Icons.ADD_BOX_OUTLINED,
|
||||
selected_icon=ft.Icons.ADD_BOX_ROUNDED,
|
||||
label="Produse",
|
||||
),
|
||||
ft.NavigationRailDestination(
|
||||
icon=ft.Icon(ft.Icons.MANAGE_ACCOUNTS_OUTLINED),
|
||||
selected_icon=ft.Icon(ft.Icons.MANAGE_ACCOUNTS_ROUNDED),
|
||||
label="Clienti",
|
||||
),
|
||||
ft.NavigationRailDestination(
|
||||
icon=ft.Icons.SHOPPING_CART_OUTLINED,
|
||||
selected_icon=ft.Icon(ft.Icons.SHOPPING_CART_ROUNDED),
|
||||
label_content=ft.Text("Comenzi"),
|
||||
),
|
||||
ft.NavigationRailDestination(
|
||||
icon=ft.Icons.SHOPIFY_OUTLINED,
|
||||
selected_icon=ft.Icon(ft.Icons.SHOPIFY_ROUNDED),
|
||||
label_content=ft.Text("Magazin"),
|
||||
),
|
||||
ft.NavigationRailDestination(
|
||||
icon=ft.Icons.IMAGE_OUTLINED,
|
||||
selected_icon=ft.Icon(ft.Icons.IMAGE_ROUNDED),
|
||||
label_content=ft.Text("Banner"),
|
||||
),
|
||||
ft.NavigationRailDestination(
|
||||
icon=ft.Icons.LOGOUT_OUTLINED,
|
||||
selected_icon=ft.Icon(ft.Icons.LOGOUT_ROUNDED),
|
||||
label_content=ft.Text("Logout"),
|
||||
),
|
||||
],
|
||||
on_change=lambda e: self.navigate_to(e),
|
||||
)
|
||||
|
||||
def navigate_to(self, e):
|
||||
index = e.control.selected_index
|
||||
match index:
|
||||
case 0:
|
||||
self.category = Category(self.page)
|
||||
self.placeholder.content = self.category.build()
|
||||
self.placeholder.update()
|
||||
case 1:
|
||||
self.products = ProductsPage(self.page)
|
||||
self.placeholder.content = self.products.build()
|
||||
self.placeholder.update()
|
||||
case 2:
|
||||
self.clients = Clients(self.page)
|
||||
self.placeholder.content = self.clients.build()
|
||||
self.placeholder.update()
|
||||
case 3:
|
||||
self.orders = OrdersPage(self.page)
|
||||
self.placeholder.content = self.orders.build()
|
||||
self.placeholder.update()
|
||||
case 4:
|
||||
self.page.launch_url('http://0.0.0.0:5555/')
|
||||
case 5:
|
||||
self.banner = Banner(self.page)
|
||||
self.placeholder.content = self.banner.build()
|
||||
self.placeholder.update()
|
||||
case 6:
|
||||
self.page.client_storage.clear()
|
||||
self.page.session.clear()
|
||||
self.page.go('/')
|
||||
|
||||
def build(self):
|
||||
if self.page.session.get("user") is None or self.page.session.get("user")['role'] != 'admin':
|
||||
return ft.Container(
|
||||
content=ft.Column(
|
||||
[
|
||||
ft.Text(
|
||||
"Nu aveti drepturi sa accesati pagina de admin!",
|
||||
size=20,
|
||||
weight=ft.FontWeight.BOLD,
|
||||
text_align=ft.TextAlign.CENTER
|
||||
),
|
||||
ft.Text("Va rugam sa va autentificati cu un rol de admin",text_align=ft.TextAlign.CENTER)
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.CENTER,
|
||||
horizontal_alignment=ft.CrossAxisAlignment.CENTER
|
||||
)
|
||||
)
|
||||
else:
|
||||
return ft.Container(
|
||||
content=ft.Column(
|
||||
[
|
||||
ft.Row(
|
||||
[
|
||||
self.rail,
|
||||
ft.VerticalDivider(width=1),
|
||||
self.placeholder
|
||||
],
|
||||
expand=True
|
||||
),
|
||||
#self.shop_page
|
||||
],
|
||||
expand=True
|
||||
),
|
||||
expand=True
|
||||
)
|
||||
Reference in New Issue
Block a user