Project

General

Profile

Patch #243 ยป AddWikiHierarchy.patch

Ron Monson, 2008-02-03 11:01

View differences:

app/controllers/wiki_controller.rb (working copy)
@content = @page.content_for_version(params[:version])
@content.text = "h1. #{@page.pretty_title}" if @content.text.blank?
@page.parent_id = params[:parent_id] if params[:parent_id]
@content.parent_id = @page.parent_id
@content.page = @page
# don't keep previous comment
@content.comments = nil
if request.post?
if !@page.new_record? && @content.text == params[:content][:text]
# don't save if text wasn't changed
#if the parent id changes we'll need to save
if @page.parent_id.to_s != params[:content][:parent_id]
@page.parent_id = params[:content][:parent_id]
@parent_changed = true
end
if !@page.new_record? && @content.text == params[:content][:text] && !@parent_changed
# don't save if text or parent wasn't changed
redirect_to :action => 'index', :id => @project, :page => @page.title
return
end
......
@content.attributes = params[:content]
@content.author = User.current
# if page is new @page.save will also save content, but not if page isn't a new record
if (@page.new_record? ? @page.save : @content.save)
if (@page.new_record? || @parent_changed == true ? @page.save : @content.save)
redirect_to :action => 'index', :id => @project, :page => @page.title
end
end
app/helpers/application_helper.rb (working copy)
else
format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
end
format_new_wiki_link = Proc.new {|project, title, parent_id| url_for :controller => 'wiki', :action => 'edit', :id => project, :page => title, :parent_id => parent_id}
project = options[:project] || @project
......
if link_project && link_project.wiki
# check if page exists
wiki_page = link_project.wiki.find_page(page)
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
:class => ('wiki-page' + (wiki_page ? '' : ' new')))
if wiki_page
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page) + (wiki_page ? '' : '/edit/' + page_id)),
:class => ('wiki-page' + (wiki_page ? '' : ' new')))
else
parent_id = options[:page].id.to_s if options[:page]
link_to((title || page), format_new_wiki_link.call(link_project, Wiki.titleize(page), parent_id),
:class => ('wiki-page' + (wiki_page ? '' : ' new')))
end
else
# project or wiki doesn't exist
title || page
......
end
leading + (link || "#{otype}#{oid}")
end
#convert {{child_pages}} tags into a table of links
#this should really be a macro but not sure how to make :page visible to it
text = text.gsub(/\{\{(&gt;|<)?child_pages\}\}/) do |m|
if options[:page] && options[:page].children
div_class = 'toc'
div_class << ' right' if $1 == '&gt;'
div_class << ' left' if $1 == '<'
out = "<div class=\"#{div_class}\"><strong>" + l(:label_wiki_child_pages) + ":</strong>"
for page in options[:page].children
out << link_to(page.pretty_title, format_wiki_link.call(project, page.title))
end
out << '</div>'
out
else
""
end
end
text
end
app/helpers/wiki_helper.rb (working copy)
module WikiHelper
def link_to_pages(pages, options = {})
if pages.any?
render :partial => 'wiki/links', :locals => {:pages => pages, :options => options}
end
end
def html_diff(wdiff)
words = wdiff.words.collect{|word| h(word)}
words_add = 0
app/models/wiki_content.rb (working copy)
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
validates_presence_of :text
attr_accessor :parent_id
acts_as_versioned
class Version
belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'
app/models/wiki_page.rb (working copy)
class WikiPage < ActiveRecord::Base
belongs_to :wiki
has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
has_one :parent, :class_name => 'WikiPage', :foreign_key => 'page_id'
has_many :attachments, :as => :container, :dependent => :destroy
acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"},
......
:include => [:wiki, :content],
:project_key => "#{Wiki.table_name}.project_id"
acts_as_tree :order => "id"
attr_accessor :redirect_existing_links
validates_presence_of :title
......
def text
content.text if content
end
def parents
@parents = []
@parent = parent
while @parent
logger.info(@parent.title)
@parents = [parent] + @parents
@parent = @parent.parent
end
@parents
end
end
class WikiDiff
app/views/wiki/_content.rhtml (working copy)
<div class="wiki">
<%= textilizable content, :text, :attachments => content.page.attachments %>
<%= textilizable content, :text, :attachments => content.page.attachments, :page => @page %>
</div>
app/views/wiki/_links.rhtml (revision 0)
<%
@first = true
for page in pages %>
<%=" > " if !@first%><%= link_to page.pretty_title, {:controller => 'wiki', :action => 'index', :page => page.title} %>
<%
@first = false
end %>
&nbsp;&nbsp;&nbsp;&nbsp;
app/views/wiki/edit.rhtml (working copy)
<%= f.hidden_field :version %>
<%= error_messages_for 'content' %>
<div class="contextual">
<%= l(:label_wiki_parent_page) %>: <%= f.select :parent_id, (@page.wiki.pages.collect {|p| [p.pretty_title, p.id]}).sort, :include_blank => true %>
&nbsp;&nbsp;&nbsp;&nbsp;
<%= l(:setting_text_formatting) %>:
<%= link_to l(:label_help), '/help/wiki_syntax.html',
:onclick => "window.open('#{ url_for '/help/wiki_syntax.html' }', '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes'); return false;" %>
app/views/wiki/show.rhtml (working copy)
<p class="breadcrumbs">
<%= link_to_pages @page.parents, nil if @page.parent%>
</p>
<div class="contextual">
<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :page => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %>
<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :page => @page.title, :parent_id => @page.parent_id}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %>
<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :page => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %>
<%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :page => @page.title}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :page => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %>
config/routes.rb (working copy)
map.home '', :controller => 'welcome'
map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
map.connect 'wiki/:id/:page/:action/:parent_id', :controller => 'wiki', :page => nil
map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
map.connect 'help/:ctrl/:page', :controller => 'help'
#map.connect ':controller/:action/:id/:sort_key/:sort_order'
db/migrate/1001_wiki_hierarchy.rb (revision 0)
class WikiHierarchy < ActiveRecord::Migration
def self.up
add_column(:wiki_pages, :parent_id, :integer)
end
def self.down
remove_column :wiki_pages, :parent_id
end
end
lang/en.yml (working copy)
label_wiki_edit_plural: Wiki edits
label_wiki_page: Wiki page
label_wiki_page_plural: Wiki pages
label_wiki_parent_page: Parent Page
label_wiki_child_pages: Child Pages
label_index_by_title: Index by title
label_index_by_date: Index by date
label_current_version: Current version
public/stylesheets/application.css (working copy)
overflow: hidden;
width: .6em; height: .6em;
}
.breadcrumbs {white-space: nowrap; line-height:0.2em;margin-top:5px;font-size:0.9em;}
.contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px;font-size:0.9em;}
.contextual input {font-size:0.9em;}
    (1-1/1)