[Koha-patches] [PATCH 2/2] Bug 12780 [ENH] Addition of plugins-menu.inc for a nav menu for Koha Plugins

Indranil Das Gupta indradg at gmail.com
Fri Aug 22 05:08:15 CEST 2014


Koha plugins system (http://manual.koha-community.org/3.16/en/pluginsystem.html)
does not provide a ready method to show an auto-populated nav menu for the
plugins installed in the system. This patch adds that capability and allows
plugin authors to add this .inc file in the plugin's template file

Test Plan:

1) Apply this patch

2) Upload a copy of "Kitchen Sink Example" plugin from ByWater Solutions's
website http://git.bywatersolutions.com/koha-plugins.git/snapshot/tags/kitchen_sink_v1.01

3) Edit
"<pluginsdir>/Koha/Plugin/Com/ByWaterSolutions/KitchenSink/tool-step1.tt"
   Replace the line "<div id="doc3">" with :

    <div id="doc3" class="yui-t2">
      <div id="bd">
        <div id="yui-main">
          <div class="yui-b">

  Also, just before the line "[% INCLUDE 'intranet-bottom.inc' %]" at the end
  of the file, insert the following lines :

        </div>
      </div>
      <div class="yui-b noprint">
        [% INCLUDE 'plugins-menu.inc' %]
      </div>
    </div>
   </div>

   Note: <pluginsdir> as defined in your koha-conf.xml

4) Edit "<pluginsdir>/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm" by adding:

      use Koha::Plugins;

   after the line : use base qw(Koha::Plugins::Base);

   Also, just after the line :

      my $template = $self->get_template({ file => 'tool-step1.tt' });

   Insert the following :

      my @reports = Koha::Plugins->new()->GetPlugins("report");
      $template->param( reports => \@reports, );
      my @tools = Koha::Plugins->new()->GetPlugins("tool");
      $template->param( tools => \@tools, );

5) Go to http://<intranet_hostname>/cgi-bin/koha/plugins/plugins-home.pl
   and click on "Run tool" link.

6) The page should now show the menu on the left, with the KitchenSink plugin
   under the "Plugin Tools" sub-menu being highlighted.
---
 .../prog/en/includes/plugins-menu.inc              | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/plugins-menu.inc

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/plugins-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/plugins-menu.inc
new file mode 100644
index 0000000..2d36107
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/plugins-menu.inc
@@ -0,0 +1,68 @@
+<script type="text/javascript">//<![CDATA[
+    $(document).ready(function() {
+        var path = location.pathname.substring(1);
+        var url = window.location.toString();
+        var params = '';
+        if ( url.match(/\?(.+)$/) ) {
+            params = RegExp.$1;
+
+	   console.log(params);
+            
+            var outstring = "?";
+            
+            var qstr = params.split("&");
+            
+            for (i=0; i < qstr.length; i++) {
+	      var qstrkey = qstr[i].split("=");
+	      for (j=0; j < qstrkey.length; j++) {
+		if (qstrkey[j] == "class" || qstrkey[j] == "method" ) {
+		  if (i > 0) {
+		    outstring = outstring + "&" + qstrkey[0] + "=" + qstrkey[1];
+		  } else {
+		    outstring = outstring + qstrkey[0] + "=" + qstrkey[1];
+		  }
+		}
+	      }
+            }            
+        }
+        $('#navmenulist a[href$="/' + path + outstring + '"]').css('font-weight','bold');
+	console.log("/" + path + outstring);
+    });
+//]]>
+</script>
+<div id="navmenu">
+<div id="navmenulist">
+<h5>Koha Plug-ins
+</h5>
+<ul>
+    <li><a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins home</a></li>
+    <li><a href="/cgi-bin/koha/plugins/plugins-upload.pl">Upload plugins</a></li>
+</ul>
+
+[% IF ( reports ) %]
+  <h5>Plugin Reports</h5>
+  [% FOREACH report IN reports %]
+  <ul>
+    [% IF ( CAN_user_plugins_report ) %]
+      [% IF report.can('report') %]
+	<li><a href="/cgi-bin/koha/plugins/run.pl?class=[% report.class %]&method=report">[% report.metadata.name %]</a></li>
+      [% END %]
+    [% END %]
+  </ul>
+  [% END %]
+[% END %]
+
+[% IF ( tools ) %]
+  <h5>Plugin Tools</h5>
+  [% FOREACH tool IN tools %]
+  <ul>
+    [% IF ( CAN_user_plugins_report ) %]
+      [% IF tool.can('tool') %]
+	<li><a href="/cgi-bin/koha/plugins/run.pl?class=[% tool.class %]&method=tool">[% tool.metadata.name %]</a></li>
+      [% END %]
+    [% END %]
+  </ul>
+  [% END %]
+[% END %]
+
+</div></div>
-- 
1.8.1.2



More information about the Koha-patches mailing list