Skip to content

Commit 3bf4e5c

Browse files
anuragawyadvr
authored andcommitted
ui: configurable branding, keyboard list and hide-able columns through a new config.js file (#3258)
We want to support hiding table columns, specifically in metrics table, through config file so that users can make the relevant bits hidden as per their organization. Current work will support the metrics table but can be extended to any table with minimal work in future. Config file will take the key of the metrics column from metrics.js file for the sake of minimal changes and simplicity of development. Problem: The keyboard list in the UI is not consistent across views such as in the instance wizard and in the register template form. There is also no way to custom about url/text and doc title and help URL in the UI. Root Cause: The list is hardcoded in the UI allowing no centralised configuration. Solution: Introduce a new config.js file installed at the /usr/share/cloudstackmanagement/webapp/config.js location. The config.js allows configurable keyboard list, about url/text, doc title, and help URL. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 0f4b1f5 commit 3bf4e5c

8 files changed

Lines changed: 108 additions & 29 deletions

File tree

ui/config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
// Define custom options configurable by admins for UI
19+
cloudStackOptions = {
20+
aboutText: "label.app.name", // This is the text shown in the 'About' box
21+
aboutTitle: "label.about.app", // This is the Application 'Title' shown in the 'About' box
22+
docTitle: "label.app.name", // This is the Application 'Title' shown on browser tab.
23+
24+
helpURL: "http://docs.cloudstack.apache.org/", // This is the URL that opens when users click Help
25+
keyboardOptions: {
26+
"us": "label.standard.us.keyboard",
27+
"uk": "label.uk.keyboard",
28+
"fr": "label.french.azerty.keyboard",
29+
"jp": "label.japanese.keyboard",
30+
"sc": "label.simplified.chinese.keyboard"
31+
},
32+
hiddenFields: {
33+
"metrics.zones":[], // Options - "name", "state", "clusters", "cpuused", "cpuallocated", "memused", "memallocated"
34+
"metrics.clusters": [], // Options - "name", "state", "hosts", "cpuused", "cpuallocated", "memused", "memallocated"
35+
"metrics.hosts": [], // Options - "name", "state", "powerstate", "instances", "cpuused", "memused", "network"
36+
"metrics.storagepool": [], // Options - "name", "property", "disk",
37+
"metrics.instances": [], // Options - "name", "state", "ipaddress", "zonename", "cpuused", "memused", "network", "disk"
38+
"metrics.volumes": [] // Options - "name", "state", "vmname", "sizegb", "physicalsize", "utilization", "storagetype", "storage"
39+
}
40+
};

ui/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,7 @@ <h3><translate key="label.set.up.zone.type"/></h3>
17621762
<script src="lib/jquery.cookies.js" type="text/javascript"></script>
17631763
<script src="lib/jquery.md5.js" type="text/javascript" ></script>
17641764
<script src="lib/require.js" type="text/javascript"></script>
1765+
<script type="text/javascript" src="config.js"></script>
17651766

17661767
<!-- localized messages -->
17671768
<script type="text/javascript">
@@ -1824,10 +1825,9 @@ <h3><translate key="label.set.up.zone.type"/></h3>
18241825

18251826
// Inject translated keyboard options
18261827
var keyboardDropdown = $($.find('#keyboard-options'));
1827-
keyboardDropdown.append($('<option>', {value: 'us', text: 'Standard (US) keyboard'}));
1828-
keyboardDropdown.append($('<option>', {value: 'uk', text: 'UK keyboard'}));
1829-
keyboardDropdown.append($('<option>', {value: 'jp', text: '日本語キーボード'}));
1830-
keyboardDropdown.append($('<option>', {value: 'sc', text: '简体中文键盘'}));
1828+
for (var key in cloudStackOptions.keyboardOptions) {
1829+
keyboardDropdown.append($('<option>', {value: key, text: translate(cloudStackOptions.keyboardOptions[key])}));
1830+
}
18311831
</script>
18321832

18331833
<script src="lib/excanvas.js" type="text/javascript"></script>
@@ -1920,5 +1920,8 @@ <h3><translate key="label.set.up.zone.type"/></h3>
19201920
<script type="text/javascript" src="plugins/plugins.js"></script>
19211921
<script type="text/javascript" src="modules/modules.js"></script>
19221922
<script type="text/javascript" src="scripts/plugins.js"></script>
1923+
1924+
<!-- Load this script after all scripts have executed to populate data -->
1925+
<script type="text/javascript" src="scripts/postLoad.js"></script>
19231926
</body>
19241927
</html>

ui/l10n/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ var dictionary = {
789789
"label.format":"Format",
790790
"label.format.lower":"format",
791791
"label.friday":"Friday",
792+
"label.french.azerty.keyboard":"French AZERTY keyboard",
792793
"label.full":"Full",
793794
"label.full.path":"Full path",
794795
"label.gateway":"Gateway",

ui/scripts/cloudStack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,6 @@
482482

483483
cloudStack.uiCustom.login(loginArgs);
484484

485-
document.title = _l('label.app.name');
485+
document.title = _l(cloudStackOptions.docTitle);
486486
});
487487
})(cloudStack, jQuery);

ui/scripts/postLoad.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
// Hide config specified fields only for users.
29+
var hiddenFields = isUser() ? cloudStackOptions.hiddenFields[prefix] : [];
30+
if (oldPreFilter) {
31+
return hiddenFields.concat(oldPreFilter());
32+
}
33+
return hiddenFields;
34+
}
35+
}
36+
} else if (data[key] && $.type(data[key]) == "object") {
37+
loadListViewPreFilters(data[key], (prefix != null && prefix.length > 0) ? prefix + "." + key : key);
38+
}
39+
});
40+
}
41+
42+
loadListViewPreFilters(cloudStack.sections, "");
43+
44+
})(cloudStack);

ui/scripts/templates.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -449,22 +449,12 @@
449449
id: "",
450450
description: ""
451451
});
452-
items.push({
453-
id: "us",
454-
description: "US Keboard"
455-
});
456-
items.push({
457-
id: "uk",
458-
description: "UK Keyboard"
459-
});
460-
items.push({
461-
id: "jp",
462-
description: "Japanese Keyboard"
463-
});
464-
items.push({
465-
id: "sc",
466-
description: "Simplified Chinese"
467-
});
452+
for (var key in cloudStackOptions.keyboardOptions) {
453+
items.push({
454+
id: key,
455+
description: _l(cloudStackOptions.keyboardOptions[key])
456+
});
457+
}
468458
args.response.success({
469459
data: items
470460
});

ui/scripts/ui/core.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,20 @@
317317

318318
if (this == 'label.help') {
319319
$link.addClass('help').click(function() {
320-
var helpURL = 'http://cloudstack.apache.org/';
321-
322-
window.open(helpURL, '_blank');
323-
320+
window.open(cloudStackOptions.helpURL, '_blank');
324321
return false;
325322
});
326323
}
327324
if (this == 'label.about') {
328325
$link.addClass('about').click(function() {
329-
var $logo = $('<div>').addClass('logo').text(_l('label.app.name')),
330-
$version = $('<div>').addClass('version').text(g_cloudstackversion),
326+
var $logo = $('<div>').addClass('logo').text(_l(cloudStackOptions.aboutText)),
327+
$version = $('<div>').addClass('version').text(_l(g_cloudstackversion)),
331328
$about = $('<div>').addClass('about').append($logo).append($version);
332-
329+
333330
var $aboutDialog = $about.dialog({
334331
modal: true,
335332
width: 300,
336-
title: _l('label.about.app'),
333+
title: _l(cloudStackOptions.aboutTitle),
337334
closeOnEscape: false,
338335
dialogClass: 'dialog-about',
339336
buttons: {

ui/scripts/ui/widgets/listView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,8 @@
862862
if (groupableColumns) {
863863
$tr.addClass('groupable-header-columns').addClass('groupable-header');
864864
$.each(fields, function(key) {
865+
if ($.inArray(key, hiddenFields) != -1)
866+
return true;
865867
var field = this;
866868
if (field.columns) {
867869
var colspan = Object.keys(field.columns).length;
@@ -1205,6 +1207,8 @@
12051207
var reducedFields = {};
12061208
var idx = 0;
12071209
$.each(fields, function(key) {
1210+
if ($.inArray(key, hiddenFields) != -1)
1211+
return true;
12081212
var field = this;
12091213
if (field.columns) {
12101214
$.each(field.columns, function(innerKey) {

0 commit comments

Comments
 (0)