Skip to content

Commit 924e4da

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 924e4da

4 files changed

Lines changed: 68 additions & 8 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: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@
8888

8989
// Make sure the master checkbox is unselected
9090
if (multiSelect) {
91-
$instanceRow.closest('.list-view').find('input.multiSelectMasterCheckbox').attr('checked', false);
91+
var $listView = $instanceRow.closest('.list-view');
92+
$listView.find('input.multiSelectMasterCheckbox').prop('checked', false);
93+
toggleMultiSelectActions($listView, false);
9294
}
9395

9496
var externalLinkAction = action.externalLink;
@@ -860,6 +862,8 @@
860862
if (groupableColumns) {
861863
$tr.addClass('groupable-header-columns').addClass('groupable-header');
862864
$.each(fields, function(key) {
865+
if ($.inArray(key, hiddenFields) != -1)
866+
return true;
863867
var field = this;
864868
if (field.columns) {
865869
var colspan = Object.keys(field.columns).length;
@@ -882,15 +886,15 @@
882886

883887
if (multiSelect) {
884888
var $th = $('<th>').addClass('multiselect').appendTo($tr);
885-
var content = $('<input>')
889+
var $multiSelectMaster = $('<input>')
886890
.attr('type', 'checkbox')
887-
.addClass('multiSelectMasterCheckbox')
888-
.appendTo($th);
891+
.addClass('multiSelectMasterCheckbox');
892+
$multiSelectMaster.appendTo($th);
889893

890-
content.click(function() {
891-
var checked = $(this).is(':checked');
892-
$('.multiSelectCheckbox').attr('checked', checked);
893-
toggleMultiSelectActions($table.closest('.list-view'), checked);
894+
$multiSelectMaster.click(function() {
895+
var isMasterChecked = $(this).prop('checked');
896+
$('.multiSelectCheckbox').prop('checked', isMasterChecked);
897+
toggleMultiSelectActions($table.closest('.list-view'), isMasterChecked);
894898
});
895899
}
896900

@@ -1203,6 +1207,8 @@
12031207
var reducedFields = {};
12041208
var idx = 0;
12051209
$.each(fields, function(key) {
1210+
if ($.inArray(key, hiddenFields) != -1)
1211+
return true;
12061212
var field = this;
12071213
if (field.columns) {
12081214
$.each(field.columns, function(innerKey) {

0 commit comments

Comments
 (0)