Skip to content

Commit 4baa1cc

Browse files
committed
Separate columns with or without table view
Change-Id: Ia4c04c544402aa2780448b24eddbe7fe8c89a441
1 parent 18fcc22 commit 4baa1cc

8 files changed

Lines changed: 465 additions & 410 deletions

File tree

cmk/gui/views/inventory/__init__.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
from ._display_hints import (
3030
inv_display_hints,
3131
NodeDisplayHint,
32+
OrderedColumnDisplayHintsOfView,
3233
PAINT_FUNCTION_NAME_PREFIX,
3334
register_display_hints,
35+
TableWithView,
3436
)
3537
from ._painters import (
3638
attribute_painter_from_hint,
@@ -50,9 +52,11 @@
5052
)
5153

5254
__all__ = [
53-
"inv_display_hints",
5455
"InventoryHintSpec",
5556
"NodeDisplayHint",
57+
"OrderedColumnDisplayHintsOfView",
58+
"TableWithView",
59+
"inv_display_hints",
5660
]
5761

5862

@@ -105,20 +109,23 @@ def _register_sorter(ident: str, spec: SorterFromHint) -> None:
105109

106110

107111
def _register_views(
108-
hint: NodeDisplayHint,
112+
node_hint: NodeDisplayHint,
109113
painters: Sequence[ColumnSpec],
110114
filters: Iterable[FilterName],
111115
) -> None:
112116
"""Declare two views: one for searching globally. And one for the items of one host"""
117+
if not isinstance(node_hint.table, TableWithView):
118+
return
119+
113120
context: VisualContext = {f: {} for f in filters}
114121

115122
# View for searching for items
116-
search_view_name = hint.table_view_name + "_search"
123+
search_view_name = node_hint.table.name + "_search"
117124
multisite_builtin_views[search_view_name] = {
118125
# General options
119-
"title": _l("Search %s") % hint.title.lower(),
126+
"title": _l("Search %s") % node_hint.title.lower(),
120127
"description": (
121-
_l("A view for searching in the inventory data for %s") % hint.title.lower()
128+
_l("A view for searching in the inventory data for %s") % node_hint.title.lower()
122129
),
123130
"hidden": False,
124131
"hidebutton": False,
@@ -153,7 +160,7 @@ def _register_views(
153160
"link_from": {},
154161
"icon": None,
155162
"single_infos": [],
156-
"datasource": hint.table_view_name,
163+
"datasource": node_hint.table.name,
157164
"topic": "inventory",
158165
"sort_index": 30,
159166
"public": True,
@@ -167,34 +174,34 @@ def _register_views(
167174
"mobile": False,
168175
"group_painters": [],
169176
"sorters": [],
170-
"is_show_more": hint.table_is_show_more,
177+
"is_show_more": node_hint.table.is_show_more,
171178
"owner": UserId.builtin(),
172179
"add_context_to_title": True,
173180
"packaged": False,
174181
"main_menu_search_terms": [],
175182
}
176183

177184
# View for the items of one host
178-
host_view_name = make_table_view_name_of_host(hint.table_view_name)
185+
host_view_name = make_table_view_name_of_host(node_hint.table.name)
179186
multisite_builtin_views[host_view_name] = {
180187
# General options
181-
"title": hint.title,
182-
"description": _l("A view for the %s of one host") % hint.title,
188+
"title": node_hint.title,
189+
"description": _l("A view for the %s of one host") % node_hint.title,
183190
"hidden": True,
184191
"hidebutton": False,
185192
"mustsearch": False,
186193
"link_from": {
187194
"single_infos": ["host"],
188-
"has_inventory_tree": hint.path,
195+
"has_inventory_tree": node_hint.path,
189196
},
190197
# Columns
191198
"painters": painters,
192199
# Filters
193200
"context": context,
194-
"icon": hint.icon,
201+
"icon": node_hint.icon,
195202
"name": host_view_name,
196203
"single_infos": ["host"],
197-
"datasource": hint.table_view_name,
204+
"datasource": node_hint.table.name,
198205
"topic": "inventory",
199206
"sort_index": 30,
200207
"public": True,
@@ -208,7 +215,7 @@ def _register_views(
208215
"mobile": False,
209216
"group_painters": [],
210217
"sorters": [],
211-
"is_show_more": hint.table_is_show_more,
218+
"is_show_more": node_hint.table.is_show_more,
212219
"owner": UserId.builtin(),
213220
"add_context_to_title": True,
214221
"packaged": False,
@@ -217,16 +224,16 @@ def _register_views(
217224

218225

219226
def _register_table_view(node_hint: NodeDisplayHint) -> None:
220-
if not node_hint.table_view_name:
227+
if not isinstance(node_hint.table, TableWithView):
221228
return
222229

223230
# Declare the "info" (like a database table)
224231
visual_info_registry.register(
225232
type(
226-
"VisualInfo%s" % node_hint.table_view_name.title(),
233+
"VisualInfo%s" % node_hint.table.name.title(),
227234
(VisualInfo,),
228235
{
229-
"_ident": node_hint.table_view_name,
236+
"_ident": node_hint.table.name,
230237
"ident": property(lambda self: self._ident),
231238
"_title": node_hint.title,
232239
"title": property(lambda self: self._title),
@@ -240,15 +247,15 @@ def _register_table_view(node_hint: NodeDisplayHint) -> None:
240247
# Create the datasource (like a database view)
241248
data_source_registry.register(
242249
type(
243-
"DataSourceInventory%s" % node_hint.table_view_name.title(),
250+
"DataSourceInventory%s" % node_hint.table.name.title(),
244251
(ABCDataSourceInventory,),
245252
{
246-
"_ident": node_hint.table_view_name,
253+
"_ident": node_hint.table.name,
247254
"_inventory_path": inventory.InventoryPath(
248255
path=node_hint.path, source=inventory.TreeSource.table
249256
),
250257
"_title": node_hint.long_inventory_table_title,
251-
"_infos": ["host", node_hint.table_view_name],
258+
"_infos": ["host", node_hint.table.name],
252259
"ident": property(lambda s: s._ident),
253260
"title": property(lambda s: s._title),
254261
"table": property(lambda s: RowTableInventory(s._ident, s._inventory_path)),
@@ -263,14 +270,12 @@ def _register_table_view(node_hint: NodeDisplayHint) -> None:
263270

264271
painters: list[ColumnSpec] = []
265272
filters = []
266-
for col_hint in node_hint.columns.values():
273+
for col_hint in node_hint.table.columns.values():
267274
_register_painter(col_hint.ident, column_painter_from_hint(col_hint.ident, col_hint))
268275
_register_sorter(col_hint.ident, column_sorter_from_hint(col_hint.ident, col_hint))
269276
painters.append(ColumnSpec(col_hint.ident))
270-
271-
if col_hint.filter is not None:
272-
filter_registry.register(col_hint.filter)
273-
filters.append(col_hint.ident)
277+
filter_registry.register(col_hint.filter)
278+
filters.append(col_hint.ident)
274279

275280
_register_views(node_hint, painters, filters)
276281

0 commit comments

Comments
 (0)