"""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": (
"Fleet 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() -> str:
metrics = (
("Site health", "--", "Live health summary not yet connected"),
("Total miners", "--", "Inventory summary not yet connected"),
("Miners in repair", "--", "Repair summary not yet connected"),
("Current hashrate", "-- TH/s", "Telemetry not yet connected"),
("Current power", "-- kW", "Telemetry not yet connected"),
)
metric_html = "".join(
""
f"{escape(label)}"
f"{escape(value)}"
f"{escape(state)}"
""
for label, value, state in metrics
)
return f"""
Recent activity
Operational events will appear here when
the dashboard activity feed is connected.
No activity feed connected
No events are fabricated for this placeholder.
"""
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 |
"""
CONTENT = {
"dashboard": _dashboard_content,
"map": _map_content,
"repairs": _repairs_content,
"miners": _miners_content,
}
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 CONTENT[view]()
)
page_script = (
''
if view == "map"
else ''
if view == "miners"
else ''
if view == "repairs"
else ""
)
return f"""
{escape(title)} | MinerOps
Skip to main content
{escape(context)}
{escape(title)}
{escape(summary)}
Current view: {escape(title)}
{content}
{page_script}
"""