[Kimchi-devel] [PATCH] Detect and enable help page from plugins tabs

Aline Manera alinefm at linux.vnet.ibm.com
Tue Aug 26 13:46:50 UTC 2014


On 08/25/2014 07:31 PM, Rodrigo Trujillo wrote:
> Kimchi is currently not able to configure and open help pages of any
> plugin tab. This patch fixes this problem and removes the HELP button
> if the plugin does not have a help configured properly.
>
> Help pages for a plugin tab follow same Kimchi system:
>     - html help file should have the same name of plugin html tab file
>     - html files should be in plugin's " ui/pages/help/<LANG> " path
>     - plugin should add following lines to <PLUGIN_NAME>.conf:
>          * [/help]
>          * tools.staticdir.on = True
>          * tools.nocache.on = True
>     - plugins should add a <help> element with tab help html name in
>       "ui/config/tab-ext.xml", for each configured tab. If this
>       element does not exist, 'Help' will be disabled
>
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
> ---
>   plugins/sample/sample.conf.in               |  4 ++++
>   plugins/sample/ui/config/tab-ext.xml        |  1 +
>   plugins/sample/ui/pages/help/en_US/tab.html |  1 +
>   src/kimchi/config.py.in                     |  1 +
>   src/kimchi/utils.py                         |  9 +++++++--
>   ui/js/src/kimchi.main.js                    | 26 ++++++++++++++++++++++++--
>   6 files changed, 38 insertions(+), 4 deletions(-)
>   create mode 100644 plugins/sample/ui/pages/help/en_US/tab.html
>
> diff --git a/plugins/sample/sample.conf.in b/plugins/sample/sample.conf.in
> index 6e0908b..181616d 100644
> --- a/plugins/sample/sample.conf.in
> +++ b/plugins/sample/sample.conf.in
> @@ -22,3 +22,7 @@ tools.kimchiauth.admin_methods = ['POST', 'PUT']
>   [/circles]
>   tools.kimchiauth.on = True
>   tools.kimchiauth.admin_methods = ['POST', 'PUT']
> +
> +[/help]
> +tools.staticdir.on = True
> +tools.nocache.on = True
> diff --git a/plugins/sample/ui/config/tab-ext.xml b/plugins/sample/ui/config/tab-ext.xml
> index a1fb1c2..5ca6e6b 100644
> --- a/plugins/sample/ui/config/tab-ext.xml
> +++ b/plugins/sample/ui/config/tab-ext.xml
> @@ -6,5 +6,6 @@
>
>           <title>SampleTab</title>
>           <path>plugins/sample/tab.html</path>

> +        <help>tab</help>

Why is it needed?
The help page should be the /help/<lang>/<plugin-name>.html by default.

>       </tab>
>   </tabs-ext>
> diff --git a/plugins/sample/ui/pages/help/en_US/tab.html b/plugins/sample/ui/pages/help/en_US/tab.html
> new file mode 100644
> index 0000000..cd32b47
> --- /dev/null
> +++ b/plugins/sample/ui/pages/help/en_US/tab.html
> @@ -0,0 +1 @@
> +Help page for Kimchi's Sample plugin.
> diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in
> index fca32ee..e10f1f6 100644
> --- a/src/kimchi/config.py.in
> +++ b/src/kimchi/config.py.in
> @@ -145,6 +145,7 @@ class PluginPaths(Paths):
>           self.ui_dir = self.add_prefix(os.path.join(self.plugin_dir, 'ui'))
>           self.mo_dir = self.add_prefix(os.path.join(self.plugin_dir, 'mo'))
>           self.conf_file = os.path.join(self.conf_dir, '%s.conf' % name)
> +        self.help_dir = os.path.join(self.ui_dir + '/pages/help')
>
>
>   class UIConfig(dict):
> diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
> index 0977b9f..9e80e06 100644
> --- a/src/kimchi/utils.py
> +++ b/src/kimchi/utils.py
> @@ -82,13 +82,18 @@ def is_digit(value):
>
>
>   def _load_plugin_conf(name):
> -    plugin_conf = PluginPaths(name).conf_file
> +    plugin_paths = PluginPaths(name)
> +    plugin_conf = plugin_paths.conf_file
>       if not os.path.exists(plugin_conf):
>           cherrypy.log.error_log.error("Plugin configuration file %s"
>                                        " doesn't exist." % plugin_conf)
>           return
>       try:
> -        return Parser().dict_from_file(plugin_conf)
> +        plugin_dict = Parser().dict_from_file(plugin_conf)
> +        if (os.path.exists(plugin_paths.help_dir) and '/help' in plugin_dict):
> +            plugin_dict['/help']['tools.staticdir.dir'] = \
> +                plugin_paths.help_dir
> +        return plugin_dict
>       except ValueError as e:
>           cherrypy.log.error_log.error("Failed to load plugin "
>                                        "conf from %s: %s" %
> diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
> index ba54b26..71a8280 100644
> --- a/ui/js/src/kimchi.main.js
> +++ b/ui/js/src/kimchi.main.js
> @@ -34,9 +34,15 @@ kimchi.main = function() {
>               var path = tab['path'];
>               var mode = tab['mode'];
>               if (mode != 'none') {
> +                var disableHelp = "";
> +                if (/^plugins/.test(path)) {
> +                    if (!tab['pluginTabHelp']) {
> +                        disableHelp = " disableHelp";
> +                    }
> +                }
>                   tabsHtml.push(
>                       '<li>',
> -                        '<a class="item" href="', path, '">',
> +                        '<a class="item', disableHelp,'" href="', path, '">',
>                               title,
>                           '</a>',
>                       '</li>'
> @@ -53,6 +59,7 @@ kimchi.main = function() {
>               var titleKey = $tab.find('title').text();
>               var title = i18n[titleKey] ? i18n[titleKey] : titleKey;
>               var path = $tab.find('path').text();
> +            var pluginTabHelp = $tab.find('help').text();
>               var roles = kimchi.cookie.get('roles');
>               if (roles) {
>                   var role = JSON.parse(roles)[titleKey.toLowerCase()];
> @@ -61,7 +68,8 @@ kimchi.main = function() {
>                   tabs.push({
>                       title: title,
>                       path: path,
> -                    mode: mode
> +                    mode: mode,
> +                    pluginTabHelp: pluginTabHelp
>                   });
>               } else {
>                   document.location.href = 'login.html';
> @@ -158,6 +166,15 @@ kimchi.main = function() {
>           $(tab).addClass('current');
>           $(tab).focus();
>
> +        if ($(tab).hasClass("disableHelp")) {
> +            $('#btn-help').prop('disabled', true);
> +            $('#btn-help').hide();
> +        }
> +        else {
> +            $('#btn-help').prop('disabled', false);
> +            $('#btn-help').show();
> +        }
> +
>           // Load page content.
>           loadPage(url);
>       };
> @@ -297,6 +314,11 @@ kimchi.getHelp = function(e) {
>           url = url.replace("#tabs", "/help/" + lang);
>           if (url == "/help" + lang)
>               url = url + "/index.html"
> +        else if (/^#plugin/.test(url)) {
> +            var plugin = url.split("/").pop();
> +            url = url.replace("#", "");
> +            url = url.replace(plugin, "help/" + lang + "/" + plugin + ".html");
> +        }
>           else
>               url = url + ".html";
>




More information about the Kimchi-devel mailing list