diff --git a/application/views/scripts/config/module.phtml b/application/views/scripts/config/module.phtml index 6cadd8a90..3608e953c 100644 --- a/application/views/scripts/config/module.phtml +++ b/application/views/scripts/config/module.phtml @@ -6,7 +6,8 @@ translate('There is no such module installed.') ?> getRequiredModules(); + $requiredMods = array_diff_key($module->getRequiredModules(), $module->getOptionalModules()); + $optionalMods = $module->getOptionalModules(); $requiredLibs = $module->getRequiredLibraries(); $restrictions = $module->getProvidedRestrictions(); $permissions = $module->getProvidedPermissions(); @@ -50,7 +51,7 @@ escape($this->translate('Dependencies')) ?> - + translate('This module has no dependencies') ?> @@ -78,28 +79,63 @@ - + - $versionString): ?> - - - - - -
translate('Modules') ?>
escape($moduleName) ?> - has($moduleName, $versionString === true ? null : $versionString)): ?> - escape($versionString) ?> - - escape($versionString) ?> - hasInstalled($moduleName)): ?> - (translate('not installed') ?>) - - (getModule($moduleName, false)->getVersion() ?>hasEnabled($moduleName) ? '' : ', ' . $this->translate('disabled') ?>) - - -
- + + $versionString): ?> + + escape($moduleName) ?> + + has($moduleName, $versionString === true ? null : $versionString)): ?> + escape($versionString) ?> + + escape($versionString) ?> + hasInstalled($moduleName)): ?> + (translate('not installed') ?>) + + (getModule($moduleName, false)->getVersion() ?>hasEnabled($moduleName) ? '' : ', ' . $this->translate('disabled') ?>) + + + + + + + + + hasAny($modules); + ?> + + $versionString): ?> + 0): ?> + translate('or') ?> + + + escape($moduleName) ?> + + has($moduleName, $versionString === true ? null : $versionString)): ?> + escape($versionString) ?> + + > + escape($versionString) ?> + + hasInstalled($moduleName)): ?> + (translate('not installed') ?>) + + (getModule($moduleName, false)->getVersion() ?>hasEnabled($moduleName) ? '' : ', ' . $this->translate('disabled') ?>) + + + + + + + + + + + diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index f137c196e..39aa1d1f3 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -474,6 +474,24 @@ class Manager return version_compare($modVersion, $version, $operator); } + /** + * Check if any module in the given array is enabled + * + * @param array $modules + * + * @return bool + */ + public function hasAny($modules) + { + foreach ($modules as $name => $version) { + if ($this->has($name, $version)) { + return true; + } + } + + return false; + } + /** * Get the currently loaded modules * @@ -558,7 +576,14 @@ class Manager { $module = $this->getModule($name, false); - $requiredMods = $module->getRequiredModules(); + $optionalMods = $module->getOptionalModules(); + foreach ($optionalMods as $modules) { + if (! $this->hasAny($modules)) { + return true; + } + } + + $requiredMods = array_diff_key($module->getRequiredModules(), $optionalMods); foreach ($requiredMods as $moduleName => $moduleVersion) { if (! $this->has($moduleName, $moduleVersion)) { return true; diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 5d742b7cd..12a8e3f67 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -897,6 +897,25 @@ class Module return $requiredModules; } + /** + * Get optional modules + * + * Modules that have an or operator + * + * @return array + */ + public function getOptionalModules() + { + $modulesWithOrOperator = []; + foreach ($this->getRequiredModules() as $key => $val) { + if (strpos($key, '|') !== false) { + $modulesWithOrOperator[$key] = $val; + } + } + + return $modulesWithOrOperator; + } + /** * Fetch module metadata * @@ -983,8 +1002,15 @@ class Module } $parts = preg_split('/,\s+/', $val); - foreach ($parts as $part) { - if (preg_match('/^([\w\-\/]+)\s+\((.+)\)$/', $part, $m)) { + foreach ($parts as $i => $part) { + if (strpos($part, '|') !== false) { + $orParts = array_map('trim', explode('|', $part)); + foreach ($orParts as $orPart) { + if (preg_match('/^([\w\-\/]+)\s+\((.+)\)$/', $orPart, $m)) { + $metadata->{$key}['|' . $i][$m[1]] = $m[2]; + } + } + } elseif (preg_match('/^([\w\-\/]+)\s+\((.+)\)$/', $part, $m)) { $metadata->{$key}[$m[1]] = $m[2]; } else { // TODO: FAIL? diff --git a/public/css/icinga/main.less b/public/css/icinga/main.less index 74ecf419d..b8fa6e9f3 100644 --- a/public/css/icinga/main.less +++ b/public/css/icinga/main.less @@ -440,5 +440,10 @@ a:hover > .icon-cancel { .var(color, color-critical); font-weight: bold; } + + .or-separator { + position: relative; + transform: translate(70%, 0); + } } }