diff --git a/app/controllers/wiki_menu_items_controller.rb b/app/controllers/wiki_menu_items_controller.rb index 3ae6e5a376..c43b8760d4 100644 --- a/app/controllers/wiki_menu_items_controller.rb +++ b/app/controllers/wiki_menu_items_controller.rb @@ -18,8 +18,20 @@ class WikiMenuItemsController < ApplicationController if wiki_menu_setting == 'sub_item' @wiki_menu_item.parent_id = parent_wiki_menu_item - else + elsif wiki_menu_setting == 'main_item' @wiki_menu_item.parent_id = nil + + if params[:wiki_menu_item][:new_wiki_page] == "1" + @wiki_menu_item.new_wiki_page = true + elsif params[:wiki_menu_item][:new_wiki_page] == "0" + @wiki_menu_item.new_wiki_page = false + end + + if params[:wiki_menu_item][:index_page] == "1" + @wiki_menu_item.index_page = true + elsif params[:wiki_menu_item][:index_page] == "0" + @wiki_menu_item.index_page = false + end end end diff --git a/app/models/wiki.rb b/app/models/wiki.rb index db3f81748a..ab7c8c416e 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -16,10 +16,18 @@ class Wiki < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project has_many :pages, :class_name => 'WikiPage', :dependent => :destroy, :order => 'title' + has_many :wiki_menu_items, :class_name => 'WikiMenuItem', :dependent => :delete_all, :order => 'name' has_many :redirects, :class_name => 'WikiRedirect', :dependent => :delete_all + acts_as_watchable + accepts_nested_attributes_for :wiki_menu_items, + :allow_destroy => true, + :reject_if => proc { |attr| attr['name'].blank? && attr['title'].blank? } + + safe_attributes 'wiki_menu_items_attributes' + attr_protected :project_id validates_presence_of :start_page diff --git a/app/models/wiki_menu_item.rb b/app/models/wiki_menu_item.rb index 6d678ee80d..a6b59b9d51 100644 --- a/app/models/wiki_menu_item.rb +++ b/app/models/wiki_menu_item.rb @@ -3,6 +3,8 @@ class WikiMenuItem < ActiveRecord::Base belongs_to :parent, :class_name => 'WikiMenuItem' has_many :children, :class_name => 'WikiMenuItem', :dependent => :destroy, :foreign_key => :parent_id + serialize :options, Hash + named_scope :main_items, lambda { |wiki_id| {:conditions => {:wiki_id => wiki_id, :parent_id => nil}} } @@ -16,6 +18,10 @@ class WikiMenuItem < ActiveRecord::Base validates_presence_of :name + def after_initialize + self.options ||= Hash.new + end + def validate_if_at_least_one_item_exists if self.is_main_item? and not new_record? and WikiMenuItem.main_items(wiki_id).size <= 1 errors.add_to_base(:wiki_cannot_delete_last_item) @@ -34,9 +40,19 @@ class WikiMenuItem < ActiveRecord::Base end def new_wiki_page + !!options[:new_wiki_page] + end + + def new_wiki_page=(value) + options[:new_wiki_page] = value end def index_page + !!options[:index_page] + end + + def index_page=(value) + options[:index_page] = value end def is_main_item? diff --git a/app/views/wiki/new.html.erb b/app/views/wiki/new.html.erb index 510a6ec056..698db09195 100644 --- a/app/views/wiki/new.html.erb +++ b/app/views/wiki/new.html.erb @@ -1,8 +1,8 @@

<% if @page.parent %> - <%= l("wiki_tabs.create_child_page_for", :title => @page.parent.pretty_title) %> + <%= l("create_child_page_for", :title => @page.parent.pretty_title) %> <% else %> - <%= l("wiki_tabs.create_new_page") %> + <%= l("create_new_page") %> <% end %>

diff --git a/app/views/wiki/show.rhtml b/app/views/wiki/show.rhtml index ab404c4912..76e3fbda48 100644 --- a/app/views/wiki/show.rhtml +++ b/app/views/wiki/show.rhtml @@ -19,6 +19,8 @@ <%= li_unless_nil(link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel')) if @content.version < @page.content.version %> <% end %> <%= li_unless_nil(link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history')) %> + <%= li_unless_nil(link_to_if_authorized(l(:button_wiki_menu_entry), {:controller => 'wiki_menu_items', :action => 'edit', :project_id => @project.identifier, :id => @page.title}, :class => 'icon icon-edit')) %> + <% end %> <% breadcrumb_paths(*@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:id => parent.title, :project_id => parent.project}}) %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 512b3ab6e2..26024fcb1f 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -114,6 +114,10 @@ de: activerecord: errors: template: + models: + wiki_menu_item: + wiki_cannot_delete_last_item: "Es muss mindestens ein Menüpunkt für das Wiki vorhanden sein. + Wenn Sie wirklich alle Wiki Menüpunkte entfernen wollen, deaktivieren Sie 'Wiki' in der Projektkonfiguration." header: one: "Dieses %{model}-Objekt konnte nicht gespeichert werden: %{count} Fehler." other: "Dieses %{model}-Objekt konnte nicht gespeichert werden: %{count} Fehler." @@ -700,8 +704,21 @@ de: label_wiki_edit_plural: Wiki-Bearbeitungen label_wiki_page: Wiki-Seite label_wiki_page_plural: Wiki-Seiten + + wiki_menu_item: "Menüpunkt" + wiki_menu_item_for: "Menüpunkt für die Wikiseite \"%{title}\"" + label_wiki_dont_show_menu_item: Wikiseite nicht in der Projektnavigation anzeigen + label_wiki_show_menu_item: als Menüpunkt in der Projektnavigation anzeigen + label_wiki_show_submenu_item: "als Untermenüpunkt anzeigen von " + label_menu_item_name: Name des Menüpunktes + wiki_menu_item_setting: Sichtbarkeit + label_wiki_show_new_page_link: "'Neue Seite anlegen' Link als Untermenüpunkt anzeigen" + label_wiki_show_index_page_link: "'Inhaltsverzeichnis' Link als Untermenüpunkt anzeigen" + create_child_page: Neue Unterseite anlegen create_child_page_for: "Neue Unterseite anlegen: \"%{title}\"" + create_new_page: Neue Seite anlegen + label_index_by_title: Seiten nach Titel label_index_by_date: Seiten nach Datum label_current_version: Gegenwärtige Version @@ -893,6 +910,7 @@ de: button_duplicate: Duplizieren button_show: Anzeigen button_remove_widget: Infobox löschen + button_wiki_menu_entry: Menüpunkt verwalten status_active: aktiv status_registered: angemeldet diff --git a/config/locales/en.yml b/config/locales/en.yml index aea6ff0f3a..cd5ea00d30 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -98,6 +98,10 @@ en: activerecord: errors: + models: + wiki_menu_item: + wiki_cannot_delete_last_item: "There needs to be at least one wiki item. + If you really want to remove all wiki menu items you have to deactivate the modul 'wiki' in project settings." template: header: one: "1 error prohibited this %{model} from being saved" @@ -699,8 +703,20 @@ en: label_wiki_edit_plural: Wiki edits label_wiki_page: Wiki page label_wiki_page_plural: Wiki pages + wiki_menu_item: "Menu item" + wiki_menu_item_for: "Menu item for wikipage \"%{title}\"" + label_wiki_dont_show_menu_item: Do not show this wikipage in project navigation + label_wiki_show_menu_item: Show in project navigation + label_wiki_show_submenu_item: "Show as a submenu item of " + label_menu_item_name: Name of menu item + wiki_menu_item_setting: Visibility + label_wiki_show_new_page_link: "Show submenu item 'Create new page'" + label_wiki_show_index_page_link: "Show submenu item 'Index page'" + wiki_create_child_page: Create new child page wiki_create_child_page_for: "Create new child page: \"%{title}\"" + wiki_create_new_page: Create new page + label_index_by_title: Index by title label_index_by_date: Index by date label_current_version: Current version @@ -910,6 +926,7 @@ en: button_duplicate: Duplicate button_show: Show button_remove_widget: Remove widget + button_wiki_menu_entry: Configure menu item status_active: active status_registered: registered diff --git a/config/routes.rb b/config/routes.rb index 03a950ccf3..ea851853fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,6 +38,7 @@ ActionController::Routing::Routes.draw do |map| end map.resources :time_entries, :controller => 'timelog' + map.resource :wiki_menu_item, :path_prefix => "projects/:project_id/wiki/:id", :only => [:edit, :update] map.wiki_new 'projects/:project_id/wiki/new', :controller => 'wiki', :action => 'new', :conditions => { :method => :get } map.wiki_create 'projects/:project_id/wiki/new', :controller => 'wiki', :action => 'create', :conditions => { :method => :post } diff --git a/db/migrate/20120731135140_create_wiki_menu_items.rb b/db/migrate/20120731135140_create_wiki_menu_items.rb new file mode 100644 index 0000000000..9de1986470 --- /dev/null +++ b/db/migrate/20120731135140_create_wiki_menu_items.rb @@ -0,0 +1,16 @@ +class CreateWikiMenuItems < ActiveRecord::Migration + def self.up + create_table :wiki_menu_items do |t| + t.column :name, :string + t.column :title, :string + t.column :parent_id, :integer + t.column :options, :text + + t.belongs_to :wiki + end + end + + def self.down + puts "You cannot safely undo this migration!" + end +end diff --git a/lib/redmine/menu_manager/menu_helper.rb b/lib/redmine/menu_manager/menu_helper.rb index c92ae2c176..698d776837 100644 --- a/lib/redmine/menu_manager/menu_helper.rb +++ b/lib/redmine/menu_manager/menu_helper.rb @@ -22,9 +22,31 @@ module Redmine::MenuManager::MenuHelper # Renders the application main menu def render_main_menu(project) + build_wiki_menus(project) if project render_menu((project && !project.new_record?) ? :project_menu : :application_menu, project) end + def build_wiki_menus(project) + project_wiki = project.wiki + + WikiMenuItem.main_items(project_wiki).each do |main_item| + Redmine::MenuManager.loose :project_menu do |menu| + menu.push "#{main_item.title}".to_sym, + { :controller => 'wiki', :action => 'show', :id => h(main_item.title) }, + :param => :project_id, :caption => main_item.name + + menu.push :wiki_create_new_page, {:action=>"new_child", :controller=>"wiki", :id => h(main_item.title) }, :param => :project_id, :caption => :create_new_page, :parent => "#{main_item.title}".to_sym if main_item.new_wiki_page + menu.push :table_of_contents, {:action => 'index', :controller => 'wiki'}, :param => :project_id, :caption => :label_table_of_contents, :parent => "#{main_item.title}".to_sym if main_item.index_page + + main_item.children.each do |child| + menu.push "#{child.title}".to_sym, + { :controller => 'wiki', :action => 'show', :id => h(child.title) }, + :param => :project_id, :caption => child.name, :parent => "#{main_item.title}".to_sym + end + end + end + end + def display_main_menu?(project) menu_name = project && !project.new_record? ? :project_menu : :application_menu Redmine::MenuManager.items(menu_name).size > 1 # 1 element is the root diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index d2a3dfb5bb..aa5e1f0540 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -499,7 +499,7 @@ a.atom { background: url(../images/feed.png) no-repeat 1px 50%; padding: 2px 0px div#tab-content-members .splitcontentleft, div#tab-content-memberships .splitcontentleft, div#tab-content-users .splitcontentleft { width: 64% } div#tab-content-members .splitcontentright, div#tab-content-memberships .splitcontentright, div#tab-content-users .splitcontentright { width: 34% } div#tab-content-members fieldset, div#tab-content-memberships fieldset, div#tab-content-users fieldset { padding:1em; margin-bottom: 1em; } -div#tab-content-info fieldset legend, div#tab-content-members fieldset legend, div#tab-content-memberships fieldset legend, div#tab-content-users fieldset legend { font-weight: bold; } +div#tab-content-info fieldset legend, div#tab-content-members fieldset legend, div#tab-content-memberships fieldset legend, div#tab-content-users fieldset legend, fieldset#wiki_menu_item_setting { font-weight: bold; } div#tab-content-members fieldset label, div#tab-content-memberships fieldset label, div#tab-content-users fieldset label { display: block; } div#tab-content-members fieldset div, div#tab-content-users fieldset div { max-height: 400px; overflow:auto; } div#tab-content-members .user.status_registered, div#tab-content-members label.status_registered { filter: alpha(opacity=80); -khtml-opacity: 0.8; opacity: 0.8; -moz-opacity: 0.8; } @@ -2952,3 +2952,40 @@ strong.related-issues-heading { div.indent { padding-left: 10px; } +form.wiki_menu_item_form p { + padding-left: 0px; +} +form.wiki_menu_item_form label { + display: block; + margin-bottom: 10px; + margin-left: 0px; + width: auto; + font-weight: bold; +} +form.wiki_menu_item_form label#name_of_item { + float: left; + padding-left: 3px; +} +form.wiki_menu_item_form label#with-select { + float: left; + margin-left: 0px; +} +form.wiki_menu_item_form select#parent_wiki_menu_item_wiki_page { + margin-bottom: 10px; +} +form.wiki_menu_item_form p input { + float: left; +} +form.wiki_menu_item_form fieldset#wiki_menu_item_setting { + margin-top: 10px; +} +form.wiki_menu_item_form p.name_of_item { + padding-top: 10px; +} +form.wiki_menu_item_form p.main_item { + padding-bottom: 0px; +} +form.wiki_menu_item_form p.wiki_menu_item_optional_links { + margin-left: 10px; + padding-top: 0px; +}