summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Étienne Deparis 2017-02-11 01:13:49 +0100
committerGravatar Étienne Deparis 2017-02-11 01:13:49 +0100
commit6cd78826aedcefebe4161c32827b8b9eb6b9cad9 (patch)
tree48d855d256e5bef994b4b849e9d53ad2cb0b3924
downloadcgit_menus-6cd78826aedcefebe4161c32827b8b9eb6b9cad9.tar.gz
cgit_menus-6cd78826aedcefebe4161c32827b8b9eb6b9cad9.tar.xz
cgit_menus-6cd78826aedcefebe4161c32827b8b9eb6b9cad9.zip
Initial import
-rw-r--r--app/views/settings/_cgit_menus_settings.html.erb5
-rw-r--r--init.rb11
-rw-r--r--lib/cgit_menus_hook_listener.rb11
3 files changed, 27 insertions, 0 deletions
diff --git a/app/views/settings/_cgit_menus_settings.html.erb b/app/views/settings/_cgit_menus_settings.html.erb
new file mode 100644
index 0000000..3673e30
--- /dev/null
+++ b/app/views/settings/_cgit_menus_settings.html.erb
@@ -0,0 +1,5 @@
+<p>
+ <label for="cgit_url_field">URL of your cgit instance</label>
+ <input type="text" name="settings[cgit_url]"
+ value="<%= @settings['cgit_url'] %>" id="cgit_url_field">
+</p>
diff --git a/init.rb b/init.rb
new file mode 100644
index 0000000..9fa8f8f
--- /dev/null
+++ b/init.rb
@@ -0,0 +1,11 @@
+require_dependency 'cgit_menus_hook_listener'
+
+Redmine::Plugin.register :cgit_menus do
+ name 'cgit menus'
+ author 'Étienne Deparis'
+ description 'Add link to your cgit instance at various places'
+ version '0.0.1'
+ #menu :top_menu, 'Git repos', Setting.plugin_cgit_menus['cgit_url'], :after => :home
+ #menu :project_menu, 'Git', "#{@settings['cgit_url']}/#{@project.identifier}", :if => Proc.new { @project.present? }, :last => true
+ settings :default => { 'cgit_url' => '' }, :partial => 'settings/cgit_menus_settings'
+end
diff --git a/lib/cgit_menus_hook_listener.rb b/lib/cgit_menus_hook_listener.rb
new file mode 100644
index 0000000..1a76480
--- /dev/null
+++ b/lib/cgit_menus_hook_listener.rb
@@ -0,0 +1,11 @@
+class CgitMenusHookListener < Redmine::Hook::ViewListener
+ def view_layouts_base_body_top(context = {})
+ unless Redmine::MenuManager.map(:top_menu).exists?('Git repos'.to_sym)
+ Redmine::MenuManager.map(:top_menu).push('Git repos', Setting.plugin_cgit_menus['cgit_url'], :after => :home)
+ end
+ return '' unless context[:project]
+ Redmine::MenuManager.map(:project_menu).delete(:git)
+ Redmine::MenuManager.map(:project_menu).push(:git, "#{Setting.plugin_cgit_menus['cgit_url']}/#{context[:project].identifier}", :last => true)
+ '' # Deactivate ugly output
+ end
+end