Coverage for src/lexigram/admin/ui/views.py: 0%
50 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 13:43 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 13:43 +0800
1"""
2Concrete View classes for declarative Resource configuration.
3Wraps LayoutConfig for a more user-friendly API.
4"""
6from __future__ import annotations
8from dataclasses import dataclass
9from typing import TYPE_CHECKING, Any
11from lexigram.admin.layout.layout_manager import LayoutConfig, LayoutType
13if TYPE_CHECKING:
14 from collections.abc import Callable
16 from htpy import Element
19class View:
20 """Base class for all Views."""
22 type: LayoutType
23 label: str
24 icon: str
25 enabled: bool = True
27 def to_config(self) -> LayoutConfig:
28 """Convert to LayoutConfig."""
29 raise NotImplementedError
32@dataclass
33class ListView(View):
34 """Standard list/table view."""
36 type: LayoutType = LayoutType.LIST
37 label: str = "List"
38 icon: str = "list"
39 enabled: bool = True
41 def to_config(self) -> LayoutConfig:
42 return LayoutConfig(
43 type=self.type,
44 label=self.label,
45 icon=self.icon,
46 enabled=self.enabled,
47 )
50@dataclass
51class GridView(View):
52 """Grid view with cards."""
54 type: LayoutType = LayoutType.GRID
55 label: str = "Grid"
56 icon: str = "grid"
57 enabled: bool = True
58 columns: int = 3
59 card_template: Callable[[dict[str, Any]], Element] | None = None
61 def to_config(self) -> LayoutConfig:
62 return LayoutConfig(
63 type=self.type,
64 label=self.label,
65 icon=self.icon,
66 enabled=self.enabled,
67 columns=self.columns,
68 card_template=self.card_template,
69 )
72@dataclass
73class CalendarView(View):
74 """Calendar view for date-based data."""
76 type: LayoutType = LayoutType.CALENDAR
77 label: str = "Calendar"
78 icon: str = "calendar"
79 enabled: bool = True
80 date_field: str = "created_at"
81 title_field: str = "title"
83 def to_config(self) -> LayoutConfig:
84 return LayoutConfig(
85 type=self.type,
86 label=self.label,
87 icon=self.icon,
88 enabled=self.enabled,
89 date_field=self.date_field,
90 title_field=self.title_field,
91 )
94@dataclass
95class MapView(View):
96 """Map view for location data."""
98 type: LayoutType = LayoutType.MAP
99 label: str = "Map"
100 icon: str = "map"
101 enabled: bool = True
102 latitude_field: str = "latitude"
103 longitude_field: str = "longitude"
104 marker_template: Callable[[dict[str, Any]], Element] | None = None
106 def to_config(self) -> LayoutConfig:
107 return LayoutConfig( # type: ignore[call-arg]
108 type=self.type,
109 label=self.label,
110 icon=self.icon,
111 enabled=self.enabled,
112 latitude_field=self.latitude_field,
113 longitude_field=self.longitude_field,
114 marker_template=self.marker_template,
115 )