1313use Icinga \Module \Icingadb \Redis \VolatileStateResults ;
1414use Icinga \Module \Icingadb \Util \FeatureStatus ;
1515use Icinga \Module \Icingadb \Web \Control \SearchBar \ObjectSuggestions ;
16+ use Icinga \Module \Icingadb \Web \Control \TabularViewModeSwitcher ;
1617use Icinga \Module \Icingadb \Web \Controller ;
1718use Icinga \Module \Icingadb \Widget \Detail \MultiselectQuickActions ;
1819use Icinga \Module \Icingadb \Widget \Detail \ObjectsDetail ;
@@ -61,8 +62,18 @@ public function indexAction()
6162 ],
6263 ['host.state.severity DESC ' , 'host.state.last_state_change DESC ' ]
6364 );
64- $ viewModeSwitcher = $ this ->createViewModeSwitcher ($ paginationControl , $ limitControl );
65- $ columns = $ this ->createColumnControl ($ hosts , $ viewModeSwitcher );
65+ $ viewModeSwitcher = $ this ->createViewModeSwitcher (
66+ $ paginationControl ,
67+ $ limitControl ,
68+ viewModeSwitcherClass: TabularViewModeSwitcher::class
69+ );
70+ $ columns = $ this ->createColumnControl (
71+ $ hosts ,
72+ Url::fromPath ('icingadb/hosts/suggestColumns ' ),
73+ ['host.name ' , 'host.state.output ' ],
74+ Url::fromPath ('icingadb/hosts ' )
75+ )
76+ ->getColumns ();
6677
6778 $ searchBar = $ this ->createSearchBar ($ hosts , [
6879 $ limitControl ->getLimitParam (),
@@ -104,7 +115,8 @@ public function indexAction()
104115 $ continueWith = $ this ->createContinueWith (Links::hostsDetails (), $ searchBar , $ results ->hasResult ());
105116 if ($ viewModeSwitcher ->getViewMode () === 'tabular ' ) {
106117 $ hostList = (new HostItemTable ($ results , HostItemTable::applyColumnMetaData ($ hosts , $ columns )))
107- ->setSort ($ sortControl ->getSort ());
118+ ->setSort ($ sortControl ->getSort ())
119+ ->setColumnChooserUrl (Url::fromPath ('icingadb/hosts/columnControl ' ));
108120 } else {
109121 $ hostList = (new ObjectList ($ results ))
110122 ->setViewMode ($ viewModeSwitcher ->getViewMode ());
@@ -198,6 +210,14 @@ public function completeAction()
198210 $ this ->getDocument ()->add ($ suggestions );
199211 }
200212
213+ public function suggestColumnsAction ()
214+ {
215+ $ this ->suggestColumns (Host::class, [
216+ 'host ' => t ('Host %s ' , '..<customvar-name> ' ),
217+ 'service ' => t ('Service %s ' , '..<customvar-name> ' )
218+ ]);
219+ }
220+
201221 public function searchEditorAction ()
202222 {
203223 $ editor = $ this ->createSearchEditor (Host::on ($ this ->getDb ()), [
@@ -211,6 +231,18 @@ public function searchEditorAction()
211231 $ this ->setTitle (t ('Adjust Filter ' ));
212232 }
213233
234+ public function columnControlAction ()
235+ {
236+ $ this ->setTitle ($ this ->translate ('Select Columns ' ));
237+ $ columnChooser = $ this ->createColumnControl (
238+ Host::on ($ this ->getDb ()),
239+ Url::fromPath ('icingadb/hosts/suggestColumns ' ),
240+ ['host.name ' , 'host.state.output ' ],
241+ Url::fromPath ('icingadb/hosts ' )
242+ )->handleRequest ($ this ->getServerRequest ());
243+ $ this ->addContent ($ columnChooser );
244+ }
245+
214246 protected function fetchCommandTargets (): Query
215247 {
216248 $ db = $ this ->getDb ();
0 commit comments