Skip to content

Commit 37abd92

Browse files
anuragawAnurag Awasthi
authored andcommitted
Support hiding columns through config file
We want users to be able to hide some columns in metrics tables that may not be necessary for their organizations. The current commit will start supporting metrics table and it can be extended to any table with similar logic Added all options to the config file for ease of use
1 parent 96cd9d9 commit 37abd92

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

ui/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,13 @@ cloudStackOptions = {
2727
"fr": "label.french.azerty.keyboard",
2828
"jp": "label.japanese.keyboard",
2929
"sc": "label.simplified.chinese.keyboard"
30+
},
31+
hiddenFields: {
32+
"metrics.zones":[], // Options - "name", "state", "clusters", "cpuused", "cpuallocated", "memused", "memallocated"
33+
"metrics.clusters": [], // Options - "name", "state", "hosts", "cpuused", "cpuallocated", "memused", "memallocated"
34+
"metrics.hosts": [], // Options - "name", "state", "powerstate", "instances", "cpuused", "memused", "network"
35+
"metrics.storagepool": [], // Options - "name", "property", "disk",
36+
"metrics.instances": [], // Options - "name", "state", "ipaddress", "zonename", "cpuused", "memused", "network", "disk"
37+
"metrics.volumes": [] // Options - "name", "state", "vmname", "sizegb", "physicalsize", "utilization", "storagetype", "storage"
3038
}
3139
};

ui/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,5 +1900,8 @@ <h3><translate key="label.set.up.zone.type"/></h3>
19001900
<script type="text/javascript" src="plugins/plugins.js"></script>
19011901
<script type="text/javascript" src="modules/modules.js"></script>
19021902
<script type="text/javascript" src="scripts/plugins.js"></script>
1903+
1904+
<!-- Load this script after all scripts have executed to populate data -->
1905+
<script type="text/javascript" src="scripts/postLoad.js"></script>
19031906
</body>
19041907
</html>

ui/scripts/postLoad.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
// Load this script after all scripts have executed to populate data
19+
(function(cloudStack) {
20+
21+
var loadListViewPreFilters = function(data, prefix) {
22+
$.each(Object.keys(data), function(idx, key) {
23+
if (key == "listView") {
24+
// Load config flags
25+
if (cloudStackOptions.hiddenFields[prefix]) {
26+
var oldPreFilter = data.listView.preFilter;
27+
data.listView.preFilter = function() {
28+
var hiddenFields = cloudStackOptions.hiddenFields[prefix];
29+
if (oldPreFilter) {
30+
return hiddenFields.concat(oldPreFilter());
31+
}
32+
return hiddenFields;
33+
}
34+
}
35+
} else if (data[key] && $.type(data[key]) == "object") {
36+
loadListViewPreFilters(data[key], (prefix != null && prefix.length > 0) ? prefix + "." + key : key);
37+
}
38+
});
39+
}
40+
41+
loadListViewPreFilters(cloudStack.sections, "");
42+
43+
})(cloudStack);

ui/scripts/ui/widgets/listView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@
860860
if (groupableColumns) {
861861
$tr.addClass('groupable-header-columns').addClass('groupable-header');
862862
$.each(fields, function(key) {
863+
if ($.inArray(key, hiddenFields) != -1)
864+
return true;
863865
var field = this;
864866
if (field.columns) {
865867
var colspan = Object.keys(field.columns).length;
@@ -1203,6 +1205,8 @@
12031205
var reducedFields = {};
12041206
var idx = 0;
12051207
$.each(fields, function(key) {
1208+
if ($.inArray(key, hiddenFields) != -1)
1209+
return true;
12061210
var field = this;
12071211
if (field.columns) {
12081212
$.each(field.columns, function(innerKey) {

0 commit comments

Comments
 (0)