AddWikiHierarchy.patch

Ron Monson, 2008-02-03 11:01

Download (10.9 KB)

View differences:

app/controllers/wiki_controller.rb (working copy)
58 58
    
59 59
    @content = @page.content_for_version(params[:version])
60 60
    @content.text = "h1. #{@page.pretty_title}" if @content.text.blank?
61
    @page.parent_id = params[:parent_id] if params[:parent_id]
62
    @content.parent_id = @page.parent_id
63
    @content.page = @page
61 64
    # don't keep previous comment
62 65
    @content.comments = nil
63 66
    if request.post?      
64
      if !@page.new_record? && @content.text == params[:content][:text]
65
        # don't save if text wasn't changed
67
      #if the parent id changes we'll need to save
68
      if @page.parent_id.to_s != params[:content][:parent_id]
69
        @page.parent_id = params[:content][:parent_id]
70
        @parent_changed = true
71
      end
72
      if !@page.new_record? && @content.text == params[:content][:text] && !@parent_changed
73
        # don't save if text or parent wasn't changed
66 74
        redirect_to :action => 'index', :id => @project, :page => @page.title
67 75
        return
68 76
      end
......
71 79
      @content.attributes = params[:content]
72 80
      @content.author = User.current
73 81
      # if page is new @page.save will also save content, but not if page isn't a new record
74
      if (@page.new_record? ? @page.save : @content.save)
82
      if (@page.new_record? || @parent_changed == true ? @page.save : @content.save)
75 83
        redirect_to :action => 'index', :id => @project, :page => @page.title
76 84
      end
77 85
    end
app/helpers/application_helper.rb (working copy)
194 194
    else
195 195
      format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
196 196
    end
197
    format_new_wiki_link = Proc.new {|project, title, parent_id| url_for :controller => 'wiki', :action => 'edit', :id => project, :page => title, :parent_id => parent_id}
197 198
    
198 199
    project = options[:project] || @project
199 200
    
......
219 220
      if link_project && link_project.wiki
220 221
        # check if page exists
221 222
        wiki_page = link_project.wiki.find_page(page)
222
        link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
223
                                 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
223
        if wiki_page
224
          link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page) + (wiki_page ? '' : '/edit/' + page_id)),
225
                                   :class => ('wiki-page' + (wiki_page ? '' : ' new')))
226
        else
227
          parent_id = options[:page].id.to_s if options[:page]
228
          link_to((title || page), format_new_wiki_link.call(link_project, Wiki.titleize(page), parent_id),
229
                                   :class => ('wiki-page' + (wiki_page ? '' : ' new')))
230
        end
224 231
      else
225 232
        # project or wiki doesn't exist
226 233
        title || page
......
248 255
      end
249 256
      leading + (link || "#{otype}#{oid}")
250 257
    end
258
  
259
  #convert {{child_pages}} tags into a table of links
260
  #this should really be a macro but not sure how to make :page visible to it
261
  text = text.gsub(/\{\{(&gt;|<)?child_pages\}\}/) do |m|
262
      if options[:page] && options[:page].children
263
        div_class = 'toc'
264
        div_class << ' right' if $1 == '&gt;'
265
        div_class << ' left' if $1 == '<'
266
        out = "<div class=\"#{div_class}\"><strong>" + l(:label_wiki_child_pages) + ":</strong>"
267
        for page in options[:page].children
268
          out << link_to(page.pretty_title, format_wiki_link.call(project, page.title))
269
        end
270
        out << '</div>'
271
        out
272
      else
273
        ""
274
      end
275
    end
251 276
    
252 277
    text
253 278
  end
app/helpers/wiki_helper.rb (working copy)
17 17

  
18 18
module WikiHelper
19 19

  
20
  def link_to_pages(pages, options = {})
21
    if pages.any?
22
      render :partial => 'wiki/links', :locals => {:pages => pages, :options => options}
23
    end
24
  end
25

  
20 26
  def html_diff(wdiff)
21 27
    words = wdiff.words.collect{|word| h(word)}
22 28
    words_add = 0
app/models/wiki_content.rb (working copy)
23 23
  belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
24 24
  validates_presence_of :text
25 25
  
26
  attr_accessor :parent_id
27
  
26 28
  acts_as_versioned
27 29
  class Version
28 30
    belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'
app/models/wiki_page.rb (working copy)
21 21
class WikiPage < ActiveRecord::Base
22 22
  belongs_to :wiki
23 23
  has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
24
  has_one :parent, :class_name => 'WikiPage', :foreign_key => 'page_id'
24 25
  has_many :attachments, :as => :container, :dependent => :destroy
25 26

  
26 27
  acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"},
......
32 33
                     :include => [:wiki, :content],
33 34
                     :project_key => "#{Wiki.table_name}.project_id"
34 35

  
36
  acts_as_tree :order => "id" 
37
  
35 38
  attr_accessor :redirect_existing_links
36 39
  
37 40
  validates_presence_of :title
......
105 108
  def text
106 109
    content.text if content
107 110
  end
111
  
112
  def parents
113
    @parents = []
114
    @parent = parent
115
    while @parent
116
      logger.info(@parent.title)
117
      @parents = [parent] + @parents
118
      @parent = @parent.parent
119
    end
120
    @parents
121
  end
108 122
end
109 123

  
110 124
class WikiDiff
app/views/wiki/_content.rhtml (working copy)
1 1
<div class="wiki">
2
  <%= textilizable content, :text, :attachments => content.page.attachments %>
2
  <%= textilizable content, :text, :attachments => content.page.attachments, :page => @page %>
3 3
</div>
app/views/wiki/_links.rhtml (revision 0)
1
<% 
2
@first = true
3
for page in pages %>
4
  <%=" > " if !@first%><%= link_to page.pretty_title, {:controller => 'wiki', :action => 'index', :page => page.title} %> 
5
<% 
6
  @first = false
7
end %>
8
&nbsp;&nbsp;&nbsp;&nbsp;
app/views/wiki/edit.rhtml (working copy)
4 4
<%= f.hidden_field :version %>
5 5
<%= error_messages_for 'content' %>
6 6
<div class="contextual">
7
<%= l(:label_wiki_parent_page) %>: <%= f.select :parent_id, (@page.wiki.pages.collect {|p| [p.pretty_title, p.id]}).sort, :include_blank => true %>
8
&nbsp;&nbsp;&nbsp;&nbsp;
7 9
<%= l(:setting_text_formatting) %>:
8 10
<%= link_to l(:label_help), '/help/wiki_syntax.html',
9 11
                            :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)
1
<p class="breadcrumbs">
2
<%= link_to_pages @page.parents,  nil if @page.parent%>
3
</p>
1 4
<div class="contextual">
2
<%= 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 %>
5
<%= 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 %>
3 6
<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :page => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %>
4 7
<%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :page => @page.title}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
5 8
<%= 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)
9 9
  map.home '', :controller => 'welcome'
10 10

  
11 11
  map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
12
  map.connect 'wiki/:id/:page/:action/:parent_id', :controller => 'wiki', :page => nil
12 13
  map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
13 14
  map.connect 'help/:ctrl/:page', :controller => 'help'
14 15
  #map.connect ':controller/:action/:id/:sort_key/:sort_order'
db/migrate/1001_wiki_hierarchy.rb (revision 0)
1
class WikiHierarchy < ActiveRecord::Migration
2
  def self.up
3
    add_column(:wiki_pages, :parent_id, :integer)
4
  end
5

  
6
  def self.down
7
    remove_column :wiki_pages, :parent_id
8
  end
9
end
lang/en.yml (working copy)
378 378
label_wiki_edit_plural: Wiki edits
379 379
label_wiki_page: Wiki page
380 380
label_wiki_page_plural: Wiki pages
381
label_wiki_parent_page: Parent Page
382
label_wiki_child_pages: Child Pages
381 383
label_index_by_title: Index by title
382 384
label_index_by_date: Index by date
383 385
label_current_version: Current version
public/stylesheets/application.css (working copy)
109 109
 overflow: hidden;
110 110
 width: .6em; height: .6em;
111 111
}
112

  
112
.breadcrumbs {white-space: nowrap; line-height:0.2em;margin-top:5px;font-size:0.9em;}
113 113
.contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px;font-size:0.9em;}
114 114
.contextual input {font-size:0.9em;}
115 115