From 41612c4481111969367d1a228ad4875d781558a2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 30 Nov 2021 15:27:59 +0100 Subject: [locations] Modularize additional column handling Additional columns are now added through a hook, moving specialized code where it belongs. --- .../baseconfig/hooks/locations-column.inc.php | 76 ++++++++++++++++++++++ modules-available/baseconfig/lang/de/module.json | 3 + modules-available/baseconfig/lang/en/module.json | 3 + 3 files changed, 82 insertions(+) create mode 100644 modules-available/baseconfig/hooks/locations-column.inc.php (limited to 'modules-available/baseconfig') diff --git a/modules-available/baseconfig/hooks/locations-column.inc.php b/modules-available/baseconfig/hooks/locations-column.inc.php new file mode 100644 index 00000000..ca30d56e --- /dev/null +++ b/modules-available/baseconfig/hooks/locations-column.inc.php @@ -0,0 +1,76 @@ +byLoc = Database::queryKeyValueList("SELECT locationid, Count(*) AS cnt + FROM `setting_location` + WHERE locationid IN (:allowedLocationIds) + GROUP BY locationid", compact('allowedLocationIds')); + // Confusing because the count might be inaccurate within a branch + //$this->propagateFields($locationList, '', 'overriddenVars', 'overriddenClass'); + // Count machines with overriden var(s) + $this->byMachine = Database::queryKeyValueList("SELECT IFNULL(m.locationid, 0), Count(DISTINCT sm.machineuuid) AS cnt + FROM setting_machine sm + INNER JOIN machine m USING (machineuuid) + WHERE (m.locationid IN (:allowedLocationIds) $extra) + GROUP BY m.locationid", compact('allowedLocationIds')); + // There WHERE statement drops clients without location - but this cannot be displayed by the locations + // table anyways as of now - maybe implement some day? Or just encourage everyone to have a root location + } + + public function getColumnHtml(int $locationId): string + { + $ret = ''; + if ($this->byLoc[$locationId] ?? 0) { + $title = htmlspecialchars(Dictionary::translateFileModule('baseconfig', 'module', 'overriden-vars-for-location')); + $ret .= << + {$this->byLoc[$locationId]} + +EOF; + } + if ($this->byMachine[$locationId] ?? 0) { + $title = htmlspecialchars(Dictionary::translateFileModule('baseconfig', 'module', 'overriden-vars-machines')); + $ret .= << + {$this->byMachine[$locationId]} + +EOF; + } + return $ret; + } + + public function getEditUrl(int $locationId): string + { + if (!User::hasPermission('.baseconfig.edit', $locationId)) + return ''; + return '?do=baseconfig&module=locations&locationid=' . $locationId; + } + + public function header(): string + { + return Dictionary::translateFileModule('baseconfig', 'module', 'location-column-header'); + } + + public function priority(): int + { + return 1000; + } +} + +return new BaseconfigLocationColumn($allowedLocationIds); \ No newline at end of file diff --git a/modules-available/baseconfig/lang/de/module.json b/modules-available/baseconfig/lang/de/module.json index f7dbf53a..a9c2c6bf 100644 --- a/modules-available/baseconfig/lang/de/module.json +++ b/modules-available/baseconfig/lang/de/module.json @@ -1,5 +1,8 @@ { + "location-column-header": "Konfig.-Variablen", "module_name": "Konfigurationsvariablen", + "overriden-vars-for-location": "F\u00fcr diesen Ort \u00fcberschriebene Variablen", + "overriden-vars-machines": "Rechner an diesem Ort, die \u00fcberschriebene Variablen haben", "source-default": "Auslieferungszustand", "source-global": "Global" } \ No newline at end of file diff --git a/modules-available/baseconfig/lang/en/module.json b/modules-available/baseconfig/lang/en/module.json index 97e19f92..5a25bcff 100644 --- a/modules-available/baseconfig/lang/en/module.json +++ b/modules-available/baseconfig/lang/en/module.json @@ -1,5 +1,8 @@ { + "location-column-header": "Config. Vars", "module_name": "Config Variables", + "overriden-vars-for-location": "Number of variables overridden at this location", + "overriden-vars-machines": "Machines at this location that have overridden variables", "source-default": "Factory default", "source-global": "Global" } \ No newline at end of file -- cgit v1.2.3-55-g7522