From rodrigo.trujillo at linux.vnet.ibm.com Mon Aug 25 18:41:39 2014 Content-Type: multipart/mixed; boundary="===============2164293513982758914==" MIME-Version: 1.0 From: Rodrigo Trujillo To: kimchi-devel at ovirt.org Subject: Re: [Kimchi-devel] [PATCH] Detect and enable help page from plugins tabs Date: Mon, 25 Aug 2014 19:41:30 -0300 Message-ID: <53FBBB9A.9020806@linux.vnet.ibm.com> In-Reply-To: 1409005867-21264-1-git-send-email-rodrigo.trujillo@linux.vnet.ibm.com --===============2164293513982758914== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Hi, You can test this patch with sample plugin, running "sudo autogen.sh = --enable-sample". You should be able to open the plugin help page, in en_US language. Then plugin, remove element of plugins/sample/ui/config/tab-ext.xml Run make again. The 'Help' will be disabled. Rodrigo Trujillo 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/ " path > - plugin should add following lines to .conf: > * [/help] > * tools.staticdir.on =3D True > * tools.nocache.on =3D True > - plugins should add a 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 > --- > 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 =3D ['POST', 'PUT'] > [/circles] > tools.kimchiauth.on =3D True > tools.kimchiauth.admin_methods =3D ['POST', 'PUT'] > + > +[/help] > +tools.staticdir.on =3D True > +tools.nocache.on =3D True > diff --git a/plugins/sample/ui/config/tab-ext.xml b/plugins/sample/ui/con= fig/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 @@ > > SampleTab > plugins/sample/tab.html > + tab > > > 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 =3D self.add_prefix(os.path.join(self.plugin_dir, '= ui')) > self.mo_dir =3D self.add_prefix(os.path.join(self.plugin_dir, '= mo')) > self.conf_file =3D os.path.join(self.conf_dir, '%s.conf' % name) > + self.help_dir =3D 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 =3D PluginPaths(name).conf_file > + plugin_paths =3D PluginPaths(name) > + plugin_conf =3D 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 =3D 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'] =3D \ > + 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 =3D function() { > var path =3D tab['path']; > var mode =3D tab['mode']; > if (mode !=3D 'none') { > + var disableHelp =3D ""; > + if (/^plugins/.test(path)) { > + if (!tab['pluginTabHelp']) { > + disableHelp =3D " disableHelp"; > + } > + } > tabsHtml.push( > '
  • ', > - '', > + '', > title, > '', > '
  • ' > @@ -53,6 +59,7 @@ kimchi.main =3D function() { > var titleKey =3D $tab.find('title').text(); > var title =3D i18n[titleKey] ? i18n[titleKey] : titleKey; > var path =3D $tab.find('path').text(); > + var pluginTabHelp =3D $tab.find('help').text(); > var roles =3D kimchi.cookie.get('roles'); > if (roles) { > var role =3D JSON.parse(roles)[titleKey.toLowerCase()]; > @@ -61,7 +68,8 @@ kimchi.main =3D function() { > tabs.push({ > title: title, > path: path, > - mode: mode > + mode: mode, > + pluginTabHelp: pluginTabHelp > }); > } else { > document.location.href =3D 'login.html'; > @@ -158,6 +166,15 @@ kimchi.main =3D 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 =3D function(e) { > url =3D url.replace("#tabs", "/help/" + lang); > if (url =3D=3D "/help" + lang) > url =3D url + "/index.html" > + else if (/^#plugin/.test(url)) { > + var plugin =3D url.split("/").pop(); > + url =3D url.replace("#", ""); > + url =3D url.replace(plugin, "help/" + lang + "/" + plugin + = ".html"); > + } > else > url =3D url + ".html"; > --===============2164293513982758914==--