Skip to content

Commit

Permalink
Simplify selectedmod/selectedres mechanism
Browse files Browse the repository at this point in the history
This also fixes module ordering/resource selection
  • Loading branch information
raphink committed Aug 7, 2017
1 parent 2312a79 commit 19577fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
24 changes: 12 additions & 12 deletions static/state.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ <h4><span class="glyphicon glyphicon-transfer" aria-hidden="true"></span> Compa
<div class="panel-heading">
<h3 class="panel-title">Modules</h3>
</div>
<ul id="nodeslist" class="list-group" ng-init="display.mod=0">
<ul id="nodeslist" class="list-group" ng-init="display.mod={}">
<li class="list-group-item form-group" ng-init="resFilter=''">
<input class="form-control" id="resFilter" ng-model="resFilter" placeholder="Filter resources..." />
</li>
<li class="list-group-item" ng-repeat="mod in details.modules | orderBy:'path' track by $index" ng-init="modname = mod.path" ng-class="{selected: mod == selectedmod}">
<div ng-click="display.mod = (display.mod != $index) ? $index : undefined" class="node-name">
<h4>{{modname}}</h4>
<span class="badge pull-right">{{resFilter == "" ? '' : filteredRes.length+'/'}}{{Utils.keys(details.modules[$index].resources).length}}</span>
<li class="list-group-item" ng-repeat="mod in details.modules | orderBy:'path'">
<div ng-click="display.mod = (display.mod != mod) ? mod : {}" class="node-name" ng-class="{selected: mod == selectedmod}">
<h4>{{mod.path}}</h4>
<span class="badge pull-right">{{resFilter == "" ? '' : filteredRes.length+'/'}}{{Utils.keys(mod.resources).length}}</span>
</div>
<ul ng-show="display.mod==$index" class="list-group" ng-init="indexmod=$index">
<li ng-repeat="r in details.modules[$index].resources | orderBy:'name' | filter:{name:resFilter} as filteredRes"
ng-class="{selected: $index == selectedres && indexmod == selectedmod}"
ng-click="setSelected(indexmod, $index)" class="list-group-item resource">
<ul ng-show="display.mod==mod" class="list-group">
<li ng-repeat="r in mod.resources | orderBy:'name' | filter:{name:resFilter} as filteredRes"
ng-class="{selected: r == selectedres && mod == selectedmod}"
ng-click="setSelected(mod, r)" class="list-group-item resource">
{{r.name}}
</li>
</ul>
Expand All @@ -70,8 +70,8 @@ <h4 class="panel-title">Details</h4>
<h1>{{path}}</h1>
</div>
<!-- Resource details view -->
<div class="row" ng-if="display.details && details.modules[selectedmod].resources[selectedres]">
<h2 class="node-title">{{(details.modules[selectedmod].path == 'root') ? "" : details.modules[selectedmod].path.replace('root/', '') + "."}}{{details.modules[selectedmod].resources[selectedres].name}}</h2>
<div class="row" ng-if="display.details && selectedres">
<h2 class="node-title">{{(selectedmod.path == 'root') ? "" : selectedmod.path.replace('root/', '') + "."}}{{selectedres.name}}</h2>
<div class="panel-group">
<div class="panel panel-info">
<div class="panel-heading">
Expand All @@ -80,7 +80,7 @@ <h4 class="panel-title">Attributes</h4>
<table class="table">
<thead><th>Attribute</th><th>Value</th></thead>
<tbody>
<tr ng-repeat="attr in details.modules[selectedmod].resources[selectedres].attributes | orderBy:'key'">
<tr ng-repeat="attr in selectedres.attributes | orderBy:'key'">
<td class="attr-key">{{attr.key}}</td>
<td class="attr-val">{{attr.value}}</td>
</tr>
Expand Down
20 changes: 8 additions & 12 deletions static/terraboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,13 @@ app.controller("tbStateCtrl",
}

// Init
$scope.selectedmod = 0;
$scope.selectedres = 0;
$scope.selectedmod = "";
$scope.selectedres = "";

$scope.setSelected = function(m, r) {
$scope.selectedmod = m;
$scope.selectedres = r;
var mod = $scope.details.modules[m];
var res = mod.resources[r];
var res_title = res.type+'.'+res.name;
var hash = (mod == 0) ? res_title : mod.path+'.'+res_title;
var hash = m.path+'.'+r.name;
$location.hash(hash);
};
});
Expand All @@ -329,21 +326,20 @@ app.controller("tbStateCtrl",

if ($location.hash() != "") {
// Default
$scope.selectedmod = 0;
$scope.selectedmod = {};

// Search for module in selected res
var targetRes = $location.hash();
for (i=0; i < mods.length; i++) {
if (targetRes.startsWith(mods[i].path+'.')) {
$scope.selectedmod = i;
$scope.selectedmod = mods[i];
}
}

targetRes = targetRes.replace(mods[$scope.selectedmod].path+'.', '');
var resources = mods[$scope.selectedmod].resources;
var resources = $scope.selectedmod.resources;
for (j=0; j < resources.length; j++) {
if (targetRes == resources[j].type+'.'+resources[j].name) {
$scope.selectedres = j;
if (targetRes == $scope.selectedmod.path+'.'+resources[j].name) {
$scope.selectedres = resources[j];
break;
}
}
Expand Down

0 comments on commit 19577fa

Please sign in to comment.