<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="moz-cite-prefix">On 09/22/2014 03:04 PM, Rodrigo
      Trujillo wrote:<br>
    </div>
    <blockquote cite="mid:542064B8.5000604@linux.vnet.ibm.com"
      type="cite">On 08/28/2014 01:25 PM, Aline Manera wrote:
      <br>
      <blockquote type="cite">
        <br>
        On 08/27/2014 07:18 PM, Rodrigo Trujillo wrote:
        <br>
        <blockquote type="cite">Kimchi is currently not able to
          configure and open help pages of any
          <br>
          plugin tab. This patch fixes this problem and removes the HELP
          button
          <br>
          if any plugin tab or tab do not have a help configured
          properly for
          <br>
          the language being used.
          <br>
          (eg.
          plugins/&lt;tab_html&gt;/help/&lt;lang&gt;/&lt;tab_html&gt;.html
          does not exist).
          <br>
          <br>
          Help pages for a plugin tab follow same Kimchi system:
          <br>
              - html help file should have the same name of plugin html
          tab file
          <br>
              - html files should be in plugin's "
          ui/pages/help/&lt;LANG&gt; " path
          <br>
              - plugin should add following lines to
          &lt;PLUGIN_NAME&gt;.conf:
          <br>
                   * [/help]
          <br>
                   * tools.staticdir.on = True
          <br>
                   * tools.nocache.on = True
          <br>
          <br>
          Signed-off-by: Rodrigo Trujillo
          <a class="moz-txt-link-rfc2396E" href="mailto:rodrigo.trujillo@linux.vnet.ibm.com">&lt;rodrigo.trujillo@linux.vnet.ibm.com&gt;</a>
          <br>
          ---
          <br>
            plugins/sample/sample.conf.in               |  4 ++++
          <br>
            plugins/sample/ui/pages/help/en_US/tab.html |  1 +
          <br>
            src/kimchi/config.py.in                     |  1 +
          <br>
            src/kimchi/utils.py                         |  9 ++++++--
          <br>
            ui/js/src/kimchi.main.js                    | 36
          ++++++++++++++++++++++++++++-
          <br>
            5 files changed, 48 insertions(+), 3 deletions(-)
          <br>
            create mode 100644
          plugins/sample/ui/pages/help/en_US/tab.html
          <br>
          <br>
          diff --git a/plugins/sample/sample.conf.in
          b/plugins/sample/sample.conf.in
          <br>
          index 6e0908b..181616d 100644
          <br>
          --- a/plugins/sample/sample.conf.in
          <br>
          +++ b/plugins/sample/sample.conf.in
          <br>
          @@ -22,3 +22,7 @@ tools.kimchiauth.admin_methods = ['POST',
          'PUT']
          <br>
            [/circles]
          <br>
            tools.kimchiauth.on = True
          <br>
            tools.kimchiauth.admin_methods = ['POST', 'PUT']
          <br>
          +
          <br>
          +[/help]
          <br>
          +tools.staticdir.on = True
          <br>
          +tools.nocache.on = True
          <br>
          diff --git a/plugins/sample/ui/pages/help/en_US/tab.html
          b/plugins/sample/ui/pages/help/en_US/tab.html
          <br>
          new file mode 100644
          <br>
          index 0000000..cd32b47
          <br>
          --- /dev/null
          <br>
          +++ b/plugins/sample/ui/pages/help/en_US/tab.html
          <br>
          @@ -0,0 +1 @@
          <br>
          +Help page for Kimchi's Sample plugin.
          <br>
          diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in
          <br>
          index fca32ee..e10f1f6 100644
          <br>
          --- a/src/kimchi/config.py.in
          <br>
          +++ b/src/kimchi/config.py.in
          <br>
          @@ -145,6 +145,7 @@ class PluginPaths(Paths):
          <br>
                    self.ui_dir =
          self.add_prefix(os.path.join(self.plugin_dir, 'ui'))
          <br>
                    self.mo_dir =
          self.add_prefix(os.path.join(self.plugin_dir, 'mo'))
          <br>
                    self.conf_file = os.path.join(self.conf_dir,
          '%s.conf' % name)
          <br>
          +        self.help_dir = os.path.join(self.ui_dir +
          '/pages/help')
          <br>
          <br>
          <br>
            class UIConfig(dict):
          <br>
          diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
          <br>
          index 0977b9f..9e80e06 100644
          <br>
          --- a/src/kimchi/utils.py
          <br>
          +++ b/src/kimchi/utils.py
          <br>
          @@ -82,13 +82,18 @@ def is_digit(value):
          <br>
          <br>
          <br>
            def _load_plugin_conf(name):
          <br>
          -    plugin_conf = PluginPaths(name).conf_file
          <br>
          +    plugin_paths = PluginPaths(name)
          <br>
          +    plugin_conf = plugin_paths.conf_file
          <br>
                if not os.path.exists(plugin_conf):
          <br>
                    cherrypy.log.error_log.error("Plugin configuration
          file %s"
          <br>
                                                 " doesn't exist." %
          plugin_conf)
          <br>
                    return
          <br>
                try:
          <br>
        </blockquote>
      </blockquote>
    </blockquote>
    <br>
    <blockquote cite="mid:542064B8.5000604@linux.vnet.ibm.com"
      type="cite">
      <blockquote type="cite">
        <blockquote type="cite">-        return
          Parser().dict_from_file(plugin_conf)
          <br>
          +        plugin_dict = Parser().dict_from_file(plugin_conf)
          <br>
          +        if (os.path.exists(plugin_paths.help_dir) and '/help'
          in plugin_dict):
          <br>
          +            plugin_dict['/help']['tools.staticdir.dir'] = \
          <br>
          +                plugin_paths.help_dir
          <br>
          +        return plugin_dict
          <br>
        </blockquote>
      </blockquote>
    </blockquote>
    <br>
    Just stopped to check the patch again and the above code should be
    removed.<br>
    It needs to go to plugin config file in [/help] section<br>
    <br>
    <blockquote cite="mid:542064B8.5000604@linux.vnet.ibm.com"
      type="cite">
      <blockquote type="cite">
        <blockquote type="cite">      except ValueError as e:
          <br>
                    cherrypy.log.error_log.error("Failed to load plugin
          "
          <br>
                                                 "conf from %s: %s" %
          <br>
          diff --git a/ui/js/src/kimchi.main.js
          b/ui/js/src/kimchi.main.js
          <br>
          index ba54b26..f7931da 100644
          <br>
          --- a/ui/js/src/kimchi.main.js
          <br>
          +++ b/ui/js/src/kimchi.main.js
          <br>
          @@ -34,9 +34,10 @@ kimchi.main = function() {
          <br>
                        var path = tab['path'];
          <br>
                        var mode = tab['mode'];
          <br>
                        if (mode != 'none') {
          <br>
          +                var disableHelp = checkHelpFile(path);
          <br>
                            tabsHtml.push(
          <br>
                                '&lt;li&gt;',
          <br>
          -                        '&lt;a class="item" href="', path,
          '"&gt;',
          <br>
          +                        '&lt;a class="item', disableHelp,'"
          href="', path, '"&gt;',
          <br>
                                        title,
          <br>
                                    '&lt;/a&gt;',
          <br>
                                '&lt;/li&gt;'
          <br>
          @@ -46,6 +47,25 @@ kimchi.main = function() {
          <br>
                    return tabsHtml.join('');
          <br>
                };
          <br>
        </blockquote>
        <br>
        <br>
        <blockquote type="cite">+    var checkHelpFile = function(path)
          {
          <br>
          +        var returnClass;
          <br>
          +        var lang = kimchi.lang.get();
          <br>
          +        url = path.replace("tabs", "/help/" + lang);
          <br>
          +        if (url == "/help" + lang)
          <br>
          +            url = url + "/index.html"
          <br>
          +        else if (/^plugin/.test(url)) {
          <br>
        </blockquote>
        <br>
        It should be "plugins", right?
        <br>
      </blockquote>
      <br>
      Not actually, because it does not matter.  The only difference is
      that plugin*S* would be more accurate. Not problem to change.
      <br>
    </blockquote>
    <br>
    Please, do! Otherwise if we create a URL /plugin it will have an
    unexpected result.<br>
    The /plugins is reserved for plugins<br>
    <br>
    <blockquote cite="mid:542064B8.5000604@linux.vnet.ibm.com"
      type="cite">
      <br>
      The 'path' argument comes as:
      <br>
      <br>
          * tabs/host.html        -&gt;    url = /help/en_US/host.html
      <br>
      * plugins/sample/tab.html       -&gt; url =
      plugins/sample/help/en_US/tab.html
      <br>
      <br>
      <blockquote type="cite">
        <br>
        <blockquote type="cite">+            var plugin =
          url.split("/").pop();
          <br>
          +            url = url.replace(plugin, "help/" + lang + "/" +
          plugin);
          <br>
        </blockquote>
        <br>
        url = url.replace(plugin, "help/" + lang + "/" + plugin*+
        ".html"*);
        <br>
      </blockquote>
      <br>
      No, as explained above.
      <br>
    </blockquote>
    <br>
    OK.<br>
    <br>
    <blockquote cite="mid:542064B8.5000604@linux.vnet.ibm.com"
      type="cite">
      <br>
      <blockquote type="cite">
        <br>
        <br>
        <blockquote type="cite">+        }
          <br>
        </blockquote>
        <br>
        This whole block is the same on kimchi.getHelp() function.
        <br>
        <br>
        Let's create a getHelpURL() and reuse it when needed.
        <br>
      </blockquote>
      <br>
      No sure, they look like similar, but are different:
      <br>
      * checkHelpFile runs in very first kimchi html load time
      <br>
      * checkHelpFile receives the complete tab html path (such as
      "/tabs/host.html" )
      <br>
      * checkHelpFile modifies the path to find the html help file
      <br>
      <br>
      ** getHelp is used when use clicks in the help button, "runs
      on-the-fly"
      <br>
      ** getHelp is receives uses the window path (such as
      "/#tabs/host")
      <br>
      ** getHelp open the help page
      <br>
    </blockquote>
    <br>
    From your patch I have:<br>
    <br>
    <pre wrap="">+    var checkHelpFile = function(path) {
+        var returnClass;
+        var lang = kimchi.lang.get();
+        url = path.replace("tabs", "<i class="moz-txt-slash"><span class="moz-txt-tag">/</span>help<span class="moz-txt-tag">/</span></i>" + lang);
+        if (url == "/help" + lang)
+            url = url + "/index.html"
+        else if (/^plugin/.test(url)) {
+            var plugin = url.split("/").pop();
+            url = url.replace(plugin, "help/" + lang + "/" + plugin);
+        }</pre>
    <br>
    And on getHelp() I have (include current code + your changes)<br>
    <br>
            var lang =
    kimchi.lang.get();                                           <br>
            url = url.replace("#tabs", "/help/" +
    lang);                            <br>
            if (url == "/help" +
    lang)                                              <br>
                url = url + "/index.html"<br>
    <pre wrap="">+        else if (/^#plugin/.test(url)) {
+            var plugin = url.split("/").pop();
+            url = url.replace("#", "");
+            url = url.replace(plugin, "help/" + lang + "/" + plugin + ".html");
+        }</pre>
                                               <br>
           
    else                                                                   
    <br>
                url = url + ".html";<br>
    <br>
    <br>
    Seems to me the code are the same but duplicated in 2 different
    functions =)<br>
    <br>
    <blockquote cite="mid:542064B8.5000604@linux.vnet.ibm.com"
      type="cite">
      <br>
      I thought to merge functions at first time but would have to use
      lots of 'ifs' and 'elses'
      <br>
      creating a dirty function. Its feasible, but we will have a dirty
      function that do 2 different
      <br>
      things. What do you think ?
      <br>
      <br>
      <blockquote type="cite">
        <blockquote type="cite">+        $.ajax({
          <br>
          +            url: url,
          <br>
          +            async: false,
          <br>
          +            error: function() { returnClass = " disableHelp";
          },
          <br>
          +            success: function() { returnClass = ""; }
          <br>
          +        });
          <br>
          +        return returnClass;
          <br>
          +    };
          <br>
          +
          <br>
                var parseTabs = function(xmlData) {
          <br>
                    var tabs = [];
          <br>
                    $(xmlData).find('tab').each(function() {
          <br>
          @@ -158,6 +178,15 @@ kimchi.main = function() {
          <br>
                    $(tab).addClass('current');
          <br>
                    $(tab).focus();
          <br>
        </blockquote>
        <br>
        <blockquote type="cite">+        if
          ($(tab).hasClass("disableHelp")) {
          <br>
          +            $('#btn-help').prop('disabled', true);
          <br>
          +            $('#btn-help').hide();
          <br>
          +        }
          <br>
          +        else {
          <br>
          +            $('#btn-help').prop('disabled', false);
          <br>
          +            $('#btn-help').show();
          <br>
          +        }
          <br>
          +
          <br>
        </blockquote>
        <br>
        Is the "else" statement really needed? Because it is the default
        button behavior
        <br>
      </blockquote>
      <br>
      Yes, it is, because the button is static and the tabs are loaded
      and change the button dynamically.
      <br>
      Without the "else", if you move to a  tab without Help and back to
      a tab with Help, the button will
      <br>
      never be showed again.
      <br>
    </blockquote>
    <br>
    OK.<br>
    <br>
    <blockquote cite="mid:542064B8.5000604@linux.vnet.ibm.com"
      type="cite">
      <br>
      <blockquote type="cite">
        <br>
        <br>
        <blockquote type="cite">          // Load page content.
          <br>
                    loadPage(url);
          <br>
                };
          <br>
          @@ -297,6 +326,11 @@ kimchi.getHelp = function(e) {
          <br>
                    url = url.replace("#tabs", "/help/" + lang);
          <br>
                    if (url == "/help" + lang)
          <br>
                        url = url + "/index.html"
          <br>
          +        else if (/^#plugin/.test(url)) {
          <br>
          +            var plugin = url.split("/").pop();
          <br>
          +            url = url.replace("#", "");
          <br>
          +            url = url.replace(plugin, "help/" + lang + "/" +
          plugin + ".html");
          <br>
          +        }
          <br>
                    else
          <br>
                        url = url + ".html";
          <br>
          <br>
        </blockquote>
        <br>
        <br>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>