158 lines
6.4 KiB
Python
158 lines
6.4 KiB
Python
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
|
|
from admin.fidelity_cards import FidelityCards
|
|
from admin.settings import Settings
|
|
from admin.inventory.inventory import Inventory
|
|
|
|
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.CARD_GIFTCARD_OUTLINED,
|
|
selected_icon=ft.Icon(ft.Icons.CARD_GIFTCARD),
|
|
label_content=ft.Text("Card de\nfidelitate"),
|
|
),
|
|
ft.NavigationRailDestination(
|
|
icon=ft.Icons.INVENTORY_2_OUTLINED,
|
|
selected_icon=ft.Icon(ft.Icons.INVENTORY_2),
|
|
label_content=ft.Text("Inventar"),
|
|
),
|
|
ft.NavigationRailDestination(
|
|
icon=ft.Icons.SETTINGS_APPLICATIONS_OUTLINED,
|
|
selected_icon=ft.Icon(ft.Icons.SETTINGS_APPLICATIONS),
|
|
label_content=ft.Text("Setari"),
|
|
),
|
|
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('https://tainagustului.ro')
|
|
case 5:
|
|
self.banner = Banner(self.page)
|
|
self.placeholder.content = self.banner.build()
|
|
self.placeholder.update()
|
|
case 6:
|
|
self.fidelity_cards = FidelityCards(self.page)
|
|
self.placeholder.content = self.fidelity_cards.build()
|
|
self.placeholder.update()
|
|
case 7:
|
|
self.inventory = Inventory(self.page, self)
|
|
self.placeholder.content = self.inventory.build()
|
|
self.placeholder.update()
|
|
case 8:
|
|
self.settings = Settings(self.page, self)
|
|
self.placeholder.content = self.settings.build()
|
|
self.placeholder.update()
|
|
case 9:
|
|
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
|
|
) |