[Kimchi-devel] [PATCH] Make guests template handling more robust like host template handling

Paulo Ricardo Paz Vital pvital at linux.vnet.ibm.com
Wed Jan 29 14:12:00 UTC 2014


-- 
Reviewed-by: Paulo Vital <pvital at linux.vnet.ibm.com>


On Tue, 2014-01-28 at 22:52 -0500, Adam King wrote:
> Change guest tab loading from an ajax request to an inline element
> processed by Cheetah at guests.html.tmpl load time. This will eliminate
> the potential for error when fetching the guest template, as well as improve
> the performance of the flow. Also updated kimchi-ui.html to eliminate
> potential race condition as I integrated the new guests load into the main
> flow.
> 
> Signed-off-by: Adam King <rak at linux.vnet.ibm.com>
> ---
>  ui/js/src/kimchi.guest_main.js | 20 ++------------------
>  ui/pages/kimchi-ui.html.tmpl   | 28 +++++++++++++---------------
>  ui/pages/tabs/guests.html.tmpl | 18 ++++++++++--------
>  3 files changed, 25 insertions(+), 41 deletions(-)
> 
> diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js
> index 9c45cf5..8467f3f 100644
> --- a/ui/js/src/kimchi.guest_main.js
> +++ b/ui/js/src/kimchi.guest_main.js
> @@ -228,27 +228,11 @@ kimchi.guest_main = function() {
>      $("#vm-add").on("click", function(event) {
>          kimchi.window.open('guest-add.html');
>      });
> -
> -    $.ajax({
> -        headers : {
> -            Accept : "text/html"
> -        },
> -        url : 'guest.html',
> -        type : 'GET',
> -        dataType : 'html',
> -        accepts : 'text/html',
> -        success : function(response) {
> -            kimchi.guestTemplate = response;
> -            kimchi.listVmsAuto()
> -        },
> -        error : function() {
> -            console.error('Could not get guest.html');
> -        },
> -    });
> -
> +    kimchi.guestTemplate = $('#guest-tmpl').html();
>      $('#guests-root-container').on('remove', function() {
>          kimchi.vmTimeout && clearTimeout(kimchi.vmTimeout);
>      });
> +    kimchi.listVmsAuto()
>  };
> 
>  kimchi.editTemplate = function(guestTemplate, oldPopStat) {
> diff --git a/ui/pages/kimchi-ui.html.tmpl b/ui/pages/kimchi-ui.html.tmpl
> index 8e234e2..eebe886 100644
> --- a/ui/pages/kimchi-ui.html.tmpl
> +++ b/ui/pages/kimchi-ui.html.tmpl
> @@ -32,9 +32,14 @@
>  <title>Kimchi</title>
>  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
>  <link rel="shortcut icon" href="images/logo.ico">
> -<link rel="stylesheet" href="$href("libs/themes/base/jquery-ui.min.css")">
> -<link rel="stylesheet" href="$href("css/theme-default.min.css")">
> -<script src="$href("libs/modernizr.custom.76777.js")"></script>
> +<link rel="stylesheet" href="$href('libs/themes/base/jquery-ui.min.css')">
> +<link rel="stylesheet" href="$href('css/theme-default.min.css')">
> +
> +<script src="$href('libs/modernizr.custom.76777.js')"></script>
> +<script src="$href('libs/jquery-1.10.0.min.js')"></script>
> +<script src="$href('libs/jquery-ui.min.js')"></script>
> +<script src="$href('libs/jquery-ui-i18n.min.js')"></script>
> +<script src="$href('js/kimchi.min.js')"></script>
> 
>  <!-- This is used for detecting if the UI needs to be built -->
>  <style type="text/css">
> @@ -62,7 +67,7 @@
>  }
>  </style>
>  </head>
> -<body>
> +<body onload="kimchi.main()">
>  <div class="container">
>  <header class="topbar">
>      <h1 id="logo"><img alt="Project Kimchi" src="images/theme-default/logo-white.png"></h1>
> @@ -89,19 +94,12 @@
>      </div>
>  </div>
>  </div>
> -<script src="$href("libs/jquery-1.10.0.min.js")"></script>
> -<script src="$href("libs/jquery-ui.min.js")"></script>
> -<script src="$href("libs/jquery-ui-i18n.min.js")"></script>
> -<script src="$href("js/kimchi.min.js")"></script>
> 
>  <div id="buildme">
> -<div>Oops!  It looks like I am running from a source tree and you forgot to build!
> -Please run the following command and reload this page:
> -<p><code>python setup.py build</code></p>
> -</div>
> +    <div><p>Oops!  It looks like I am running from a source tree and you forgot to build!
> +    Please run the following command from the kimchi directory and reload this page:</p>
> +    <p><code>make</code></p>
> +    </div>
>  </div>
> -<script>
> -kimchi.main();
> -</script>
>  </body>
>  </html>
> diff --git a/ui/pages/tabs/guests.html.tmpl b/ui/pages/tabs/guests.html.tmpl
> index d73eb39..e2ab173 100644
> --- a/ui/pages/tabs/guests.html.tmpl
> +++ b/ui/pages/tabs/guests.html.tmpl
> @@ -22,13 +22,14 @@
> 
>  #unicode UTF-8
>  #import gettext
> +#from Cheetah.Template import Template
>  #from kimchi.cachebust import href
>  #silent t = gettext.translation($lang.domain, $lang.localedir, languages=$lang.lang)
>  #silent _ = t.gettext
>  #silent _t = t.gettext
> -<!DOCTYPE html>
> -<html>
> -<body>
> +
> +#silent ht = Template
> +
>  <div id="guests-root-container">
>      <div class="toolbar">
>          <div class="tools">
> @@ -50,9 +51,10 @@
>      <div id="noGuests" class="list-no-result" style="display: none;">
>          $_("No guests found.")
>      </div>
> +    <script id="guest-tmpl" type="kimchi/template">
> +    $ht(file="ui/pages/guest.html.tmpl",searchList=[self,{'lang':$lang}])
> +    </script>
> +    <script type="text/javascript">
> +        kimchi.guest_main();
> +    </script>
>  </div>
> -<script>
> -    kimchi.guest_main();
> -</script>
> -</body>
> -</html>




More information about the Kimchi-devel mailing list