diff options
author | Simon Rettberg | 2016-06-22 17:56:04 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-06-22 17:56:04 +0200 |
commit | a6a484ea37aeb91f848c11cb818e2d7d4351d391 (patch) | |
tree | 03cc7b9df8dabf61bdb1bc84137601ce187339ef /modules-available/locations | |
parent | [location] Support passing array of selected locs to getLocations() (diff) | |
download | slx-admin-a6a484ea37aeb91f848c11cb818e2d7d4351d391.tar.gz slx-admin-a6a484ea37aeb91f848c11cb818e2d7d4351d391.tar.xz slx-admin-a6a484ea37aeb91f848c11cb818e2d7d4351d391.zip |
[locations/sysconfig] Implement location specific sysconfig
Diffstat (limited to 'modules-available/locations')
-rw-r--r-- | modules-available/locations/inc/location.inc.php | 8 | ||||
-rw-r--r-- | modules-available/locations/page.inc.php | 54 | ||||
-rw-r--r-- | modules-available/locations/templates/locations.html | 35 |
3 files changed, 85 insertions, 12 deletions
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php index 788fc588..b1474279 100644 --- a/modules-available/locations/inc/location.inc.php +++ b/modules-available/locations/inc/location.inc.php @@ -64,7 +64,7 @@ class Location return $output; } - public static function getLocations($selected = 0, $excludeId = 0, $addNoParent = false) + public static function getLocations($selected = 0, $excludeId = 0, $addNoParent = false, $keepArrayKeys = false) { if (is_string($selected)) { settype($selected, 'int'); @@ -99,6 +99,8 @@ class Location 'selected' => $selected === 0 )); } + if ($keepArrayKeys) + return $rows; return array_values($rows); } @@ -129,14 +131,14 @@ class Location } $output = array(); foreach ($tree as $node) { - $output[] = array( + $output[(int)$node['locationid']] = array( 'locationid' => $node['locationid'], 'locationname' => $node['locationname'], 'locationpad' => str_repeat('--', $depth), 'depth' => $depth ); if (!empty($node['children'])) { - $output = array_merge($output, self::flattenTree($node['children'], $depth + 1)); + $output += self::flattenTree($node['children'], $depth + 1); } } return $output; diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 84bc11a9..de724350 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -166,7 +166,6 @@ class Page_Locations extends Page } } // Now actual updates - // TODO: Warn on mismatch/overlap (should lie entirely in parent's subnet, not overlap with others) $starts = Request::post('startaddr', false); $ends = Request::post('endaddr', false); if (!is_array($starts) || !is_array($ends)) { @@ -263,7 +262,8 @@ class Page_Locations extends Page { $overlapSelf = $overlapOther = true; $subnets = Location::getSubnetsByLocation($overlapSelf, $overlapOther); - $locs = Location::getLocations(); + $locs = Location::getLocations(0, 0, false, true); + // Statistics: Count machines for each subnet $unassigned = false; if (Module::get('statistics') !== false) { foreach ($locs as &$location) { @@ -289,15 +289,61 @@ class Page_Locations extends Page $unassigned = $res['cnt']; } unset($loc, $location); + // Show currently active sysconfig for each location + $defaultConfig = false; + if (Module::isAvailable('sysconfig')) { + $confs = SysConfig::getAll(); + foreach ($confs as $conf) { + $confLocs = explode(',', $conf['locs']); + foreach ($confLocs as $loc) { + settype($loc, 'int'); + if ($loc === 0) { + $defaultConfig = $conf['title']; + } + if (!isset($locs[$loc])) + continue; + $locs[$loc] += array('configName' => $conf['title'], 'configClass' => 'slx-bold'); + } + } + $depth = array(); + foreach ($locs as &$loc) { + $d = $loc['depth']; + if (!isset($loc['configName'])) { + // Has no explicit config assignment + if ($d === 0) { + $loc['configName'] = $defaultConfig; + } else { + $loc['configName'] = $depth[$d - 1]; + } + $loc['configClass'] = 'gray'; + } + $depth[$d] = $loc['configName']; + unset($depth[$d + 1]); + } + unset($loc); + } + // Count overridden config vars + if (Module::get('baseconfig') !== false) { + $res = Database::simpleQuery("SELECT locationid, Count(*) AS cnt FROM `setting_location` GROUP BY locationid"); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $lid = (int)$row['locationid']; + if (isset($locs[$lid])) { + $locs[$lid]['overriddenVars'] = $row['cnt']; + } + } + } + // Output Render::addTemplate('locations', array( - 'list' => $locs, + 'list' => array_values($locs), 'havestatistics' => Module::get('statistics') !== false, 'havebaseconfig' => Module::get('baseconfig') !== false, + 'havesysconfig' => Module::get('sysconfig') !== false, 'overlapSelf' => $overlapSelf, 'overlapOther' => $overlapOther, 'haveOverlapSelf' => !empty($overlapSelf), 'haveOverlapOther' => !empty($overlapOther), - 'unassignedCount' => $unassigned + 'unassignedCount' => $unassigned, + 'defaultConfig' => $defaultConfig, )); } diff --git a/modules-available/locations/templates/locations.html b/modules-available/locations/templates/locations.html index e8b5d707..11142ef8 100644 --- a/modules-available/locations/templates/locations.html +++ b/modules-available/locations/templates/locations.html @@ -6,34 +6,59 @@ <table class="table table-condensed" style="margin-bottom:0px"> <tr> <th width="100%">{{lang_locationName}}</th> - <th></th> + <th>{{#havestatistics}}{{lang_machineCount}}{{/havestatistics}}</th> + <th class="slx-nowrap">{{lang_editConfigVariables}}</th> + {{#havesysconfig}} + <th class="slx-nowrap"> + {{#havebaseconfig}}{{lang_sysConfig}}{{/havebaseconfig}} + </th> + {{/havesysconfig}} </tr> {{#list}} <tr> <td> <div style="display:inline-block;width:{{depth}}em"></div> - <a href="#" onclick="slxOpenLocation(this, {{locationid}})">{{locationname}}<b class="caret"></b></a> + <a href="#" onclick="slxOpenLocation(this, {{locationid}})">{{locationname}} <b class="caret"></b></a> </td> <td class="slx-nowrap" align="right"> {{#havestatistics}} {{clientCount}} <a class="btn btn-default btn-xs" href="?do=Statistics&filter=location&argument={{locationid}}"><span class="glyphicon glyphicon-eye-open"></span></a> {{/havestatistics}} + </td> + <td class="slx-nowrap"> {{#havebaseconfig}} - <a class="btn btn-success btn-xs" href="?do=baseconfig&module=locations&locationid={{locationid}}"><span class="glyphicon glyphicon-edit"></span> {{lang_editConfigVariables}}</a> + <div class="pull-right" style="z-index:-1"> + <a class="btn btn-default btn-xs" href="?do=baseconfig&module=locations&locationid={{locationid}}"><span class="glyphicon glyphicon-edit"></span></a> + </div> + {{#overriddenVars}} + {{lang_overrideCount}}: {{overriddenVars}} + {{/overriddenVars}} {{/havebaseconfig}} </td> + <td class="slx-nowrap"> + <div class="pull-right"> + <a class="btn btn-default btn-xs" href="?do=sysconfig&locationid={{locationid}}"><span class="glyphicon glyphicon-edit"></span></a> + </div> + <span class="{{configClass}}"> + {{configName}} + </span> + {{#havesysconfig}} + {{/havesysconfig}} + </td> </tr> {{/list}} {{#unassignedCount}} <tr> - <td></td> + <td>{{lang_unassignedMachines}}</td> <td class="slx-nowrap" align="right"> - {{lang_unassignedMachines}}: {{unassignedCount}} + {{unassignedCount}} <a class="btn btn-default btn-xs" href="?do=Statistics&filter=location&argument=0"> <span class="glyphicon glyphicon-eye-open"></span> </a> </td> + <td></td> + <td>{{defaultConfig}}</td> </tr> {{/unassignedCount}} </table> |