Warning, file /swf-monitor/src/monitor_app/cell_fmt.py was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 """HTML cell-formatting helpers for DataTables ajax responses.
0002
0003 Shared across view modules so any table can emit state-colored cells
0004 without duplicating the wrapping convention.
0005 """
0006
0007 from .state_descriptions import state_description
0008
0009
0010 def fill_cell(content, state, url=None):
0011 """Wrap content so the enclosing <td> fills with the BigMon state color.
0012
0013 The content is wrapped in ``<span data-fill="<state>_fill">…</span>``.
0014 The DataTables `createdCell` hook in _datatable_base.html /
0015 _datatable_dynamic_base.html reads td.innerHTML, extracts the
0016 data-fill value, and promotes it as a class on the <td> itself so
0017 the whole cell fills with the state color (see
0018 src/monitor_app/static/css/state-colors.css).
0019
0020 When the state has a known description (see state_descriptions.py), a
0021 ``title=`` attribute is added so hovering the cell reveals what the
0022 state means. Unknown states omit the tooltip silently.
0023
0024 ``state`` can be any short label that resolves to a ``<label>_fill``
0025 CSS class (e.g. a PanDA status, a log level, an agent status).
0026 Empty/falsy state returns the content unwrapped (no fill). The class
0027 is lowercased to match the BigMon CSS convention.
0028 """
0029 if content is None:
0030 content = ''
0031 if not state:
0032 return str(content)
0033 fill = f'{str(state).lower()}_fill'
0034 title_attr = ''
0035 desc = state_description(state)
0036 if desc:
0037
0038
0039 safe_desc = str(desc).replace('"', '"')
0040 title_attr = f' title="{safe_desc}"'
0041 wrapper = f'<span data-fill="{fill}"{title_attr}>{content}</span>'
0042 if url:
0043 return f'<a href="{url}" style="text-decoration:none;color:inherit;">{wrapper}</a>'
0044 return wrapper