[PATCH 0/3] Update default tab from "Host" to "Guests"

Crístian Viana (3): Refactor code to trim file extension Define the default tab more clearly Change the default tab to "Guests" ui/js/src/kimchi.main.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- 1.9.0

In some parts of the code, it is necessary to remove the file extension from a string. Currently, the last 5 characters are removed from the text. Remove the file extension by searching for the last '.' inside the string. This approach works for other file extension lengths - even though we will probably use only .html - and is more clear than having a magic number ("5") inside the code. Also, add a comment explaining what the substring method does in that case. Signed-off-by: Crístian Viana <vianac@linux.vnet.ibm.com> --- ui/js/src/kimchi.main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index 018f5e7..2999aa2 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -76,8 +76,9 @@ kimchi.main = function() { }); var firstTabPath = tabs[0] && tabs[0]['path']; + // Remove file extension from 'firstTabPath' DEFAULT_HASH = firstTabPath && - firstTabPath.substring(0, firstTabPath.length - 5); + firstTabPath.substring(0, firstTabPath.lastIndexOf('.')) $('#nav-menu').append(genTabs(tabs)); @@ -183,7 +184,8 @@ kimchi.main = function() { */ $('#nav-menu').on('click', 'a.item', function(event) { var href = $(this).attr('href'); - location.hash = href.substring(0,href.length -5); + // Remove file extension from 'href' + location.hash = href.substring(0,href.lastIndexOf('.')) /* * We use the HTML file name for hash, like: guests for guests.html * and templates for templates.html. -- 1.9.0

In order to define the default tab, the developer needs to update the code in more than one place. Also, the corresponding variable name does not reflect what it actually means. Define the default tab in a single variable and make all the other values dependent on it. Also, rename the variable from "firstTab" to "defaultTab". Signed-off-by: Crístian Viana <vianac@linux.vnet.ibm.com> --- ui/js/src/kimchi.main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index 2999aa2..a016bee 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -75,10 +75,12 @@ kimchi.main = function() { tabs.push.apply(tabs, retrieveTabs(url)); }); - var firstTabPath = tabs[0] && tabs[0]['path']; - // Remove file extension from 'firstTabPath' - DEFAULT_HASH = firstTabPath && - firstTabPath.substring(0, firstTabPath.lastIndexOf('.')) + var defaultTab = tabs[0] + + var defaultTabPath = defaultTab && defaultTab['path'] + // Remove file extension from 'defaultTabPath' + DEFAULT_HASH = defaultTabPath && + defaultTabPath.substring(0, defaultTabPath.lastIndexOf('.')) $('#nav-menu').append(genTabs(tabs)); -- 1.9.0

When Kimchi is launched, it opens the tab "Host" by default. As Kimchi is a virtual machine manager, it makes more sense to use the default tab "Guests". Update the default tab from "Host" to "Guests". Signed-off-by: Crístian Viana <vianac@linux.vnet.ibm.com> --- ui/js/src/kimchi.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index a016bee..86fed5b 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -75,7 +75,7 @@ kimchi.main = function() { tabs.push.apply(tabs, retrieveTabs(url)); }); - var defaultTab = tabs[0] + var defaultTab = tabs[1] var defaultTabPath = defaultTab && defaultTab['path'] // Remove file extension from 'defaultTabPath' -- 1.9.0

Applied. Thanks. Regards, Aline Manera
participants (2)
-
Aline Manera
-
Crístian Viana