"""Shared semantic HTML for the MinerOps Internal Alpha shell."""
from html import escape
from typing import Callable
NAVIGATION = (
("dashboard", "Dashboard", "/dashboard", "dashboard.view"),
("map", "Mine Map", "/monitoring/map", "locations.view"),
("repairs", "Repair Center", "/operations/repairs", "repairs.view"),
("miners", "Miners", "/assets/miners", "miners.view"),
)
PAGE_DETAILS = {
"dashboard": (
"Operational overview",
"Dashboard",
"A concise starting point for operational state and recent activity.",
),
"map": (
"Monitoring / Spatial operations",
"Mine Map",
"Inspect where miners and operational conditions are concentrated.",
),
"repairs": (
"Operations",
"Repair Center",
"Review miners currently represented in the backend repair queue.",
),
"miners": (
"Assets",
"Miners",
"Search durable miner inventory and inspect current identity and state.",
),
}
def _dashboard_content(
can_view_miners: bool,
can_view_repairs: bool,
can_view_locations: bool,
) -> str:
fleet = """
Total miners
-
Runtime
- Online
- -
- Offline
- -
- Unknown
- -
Lifecycle
- In repair
- -
- Spare
- -
- Retired
- -
Runtime and lifecycle are separate dimensions and may overlap.
""" if can_view_miners else ""
repairs = """
""" if can_view_repairs else ""
mapped_metrics = """
Mapped miners-
Unmapped miners-
""" if can_view_miners else ""
locations = f"""
- Sites
- -
- Rooms
- -
- Positions
- -
- Occupied
- -
- Empty
- -
{mapped_metrics}
""" if can_view_locations else ""
available = sum((can_view_miners, can_view_repairs, can_view_locations))
partial = (
'This overview includes only the '
'operational areas available to your account.
'
if 0 < available < 3 else ""
)
return f"""
Loading operational overview
Requesting current fleet, repair, and location summaries.
Dashboard unavailable
The operational overview could not be loaded.
No operational sections available
Your account can open Dashboard but has no additional overview permissions.
Waiting for current summaries
{partial}
{fleet}{repairs}{locations}
"""
def _map_content(can_manage_locations: bool = False) -> str:
manage_link = (
'Manage locations'
if can_manage_locations
else ""
)
return f"""
Map context
Select a site and room.
{manage_link}
Filters
Map unavailable
The map could not be loaded.
Loading Mine Map
Requesting the current physical layout and operational observations.
Miner details require inventory access. Layout and occupancy remain visible.
Unscoped legacy positions
Stored positions without a durable room relationship. They are not assigned to the selected site or room.
Unplaced and operational areas
Miner records without a configured rack position.
"""
def _state_messages(noun: str) -> str:
return f"""
Loading {noun}
Requesting current information from MinerOps.
No {noun} found
There is no information to show in this view.
Access unavailable
Your account cannot view this information.
Could not load {noun}
Retry after checking the MinerOps connection.
"""
def _repairs_content(can_view_locations: bool, can_view_miners: bool) -> str:
location_filters = """
""" if can_view_locations else ""
search_placeholder = (
"Miner, model, status, reason, or context"
if can_view_miners else "Repair status, reason, or context"
)
model_filter = """
""" if can_view_miners else ""
return f"""
Repair Center
Active work and historical modular repairs, with legacy queue records clearly identified.
Loading repair work
Total results-
Active-
Historical-
{_state_messages("repair records")}
| Miner | Repair state | Reported problem |
Latest context | Location | Opened / age |
Parts | Actions |
"""
def _miners_content(can_view_locations: bool) -> str:
location_filters = """
""" if can_view_locations else ""
return f"""
Fleet
Current miner identity, operating state, telemetry, and repair context.
Loading current fleet
{_state_messages("miners")}
| Miner | Operational | Model / Serial |
Network | Location | Hashrate | Power |
Max chip temp | Lifecycle / Repair | Actions |
"""
def render_app_page(
view: str,
current_user: dict,
has_permission: Callable[[str], bool],
) -> str:
context, title, summary = PAGE_DETAILS[view]
display_name = escape(
str(
current_user.get("display_name")
or current_user.get("username")
or "MinerOps user"
)
)
role = escape(str(current_user.get("role") or "Authenticated user"))
can_view_miners = has_permission("miners.view")
navigation = "".join(
(
f'{escape(label)}'
if key == view
else f'{escape(label)}'
)
for key, label, href, permission in NAVIGATION
if has_permission(permission)
)
global_search = (
''
if can_view_miners
else ''
)
content = (
_map_content(has_permission("locations.manage"))
if view == "map"
else _miners_content(has_permission("locations.view"))
if view == "miners"
else _repairs_content(
has_permission("locations.view"), has_permission("miners.view")
)
if view == "repairs"
else _dashboard_content(
has_permission("miners.view"),
has_permission("repairs.view"),
has_permission("locations.view"),
)
)
page_script = (
''
if view == "map"
else ''
if view == "miners"
else ''
if view == "repairs"
else ''
if view == "dashboard"
else ""
)
return f"""
{escape(title)} | MinerOps
Skip to main content
{escape(context)}
{escape(title)}
{escape(summary)}
Current view: {escape(title)}
{content}
{page_script}
"""