"""Shared semantic HTML for the MinerOps Internal Alpha shell."""
from html import escape
from typing import Callable
from app.frontend.miner_detail_view import miner_detail_content
from app.frontend.monitoring_trends_view import monitoring_trends_content
from app.frontend.system_health_view import system_health_content
from app.frontend.agent_management_view import agent_management_content
NAVIGATION = (
("dashboard", "Dashboard", "/dashboard", "dashboard.view"),
("map", "Mine Map", "/monitoring/map", "locations.view"),
("analytics", "Trends", "/monitoring/analytics", "miners.view"),
("repairs", "Repair Center", "/operations/repairs", "repairs.view"),
("miners", "Miners", "/assets/miners", "miners.view"),
("system_health", "System Health", "/system-health", "system_health.view"),
("agent_management", "Agents", "/agent/management", "agents.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.",
),
"analytics": (
"Monitoring / Analytics",
"Trends",
"Review bounded historical hashrate and power observations.",
),
"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.",
),
"miner_detail": (
"Assets / Miners",
"Miner Detail",
"Current identity, operating facts, location, and authorized history.",
),
"system_health": (
"Administration / Diagnostics",
"System Health",
"Inspect application services, operational data, and maintenance facts.",
),
"agent_management": (
"Administration / Agents",
"Agent Management",
"Inspect Agent identities, routing boundaries, and secure enrollment.",
),
}
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],
*,
miner_id: str | None = None,
return_to: str | None = None,
) -> 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")
active_navigation = "miners" if view == "miner_detail" else view
navigation = "".join(
(
f'{escape(label)}'
if key == active_navigation
else f'{escape(label)}'
)
for key, label, href, permission in NAVIGATION
if has_permission(permission)
)
global_search = (
''
if can_view_miners
else ''
)
content = (
agent_management_content(has_permission("agents.manage"))
if view == "agent_management"
else system_health_content()
if view == "system_health"
else miner_detail_content()
if view == "miner_detail"
else monitoring_trends_content(has_permission("locations.view"))
if view == "analytics"
else _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 == "system_health"
else ''
if view == "miner_detail"
else ''
if view == "analytics"
else ''
if view == "map"
else ''
if view == "miners"
else ''
if view == "repairs"
else ''
if view == "dashboard"
else ""
)
page_style = (
''
if view == "system_health"
else ''
if view == "analytics" else ""
)
object_attributes = ""
if miner_id is not None:
object_attributes += f' data-miner-id="{escape(miner_id)}"'
if return_to is not None:
object_attributes += f' data-return-to="{escape(return_to)}"'
return f"""
{escape(title)} | MinerOps
{page_style}
Skip to main content
{escape(context)}
{escape(title)}
{escape(summary)}
Current view: {escape(title)}
{content}
{page_script}
"""