[issue #64] Added Wiki history, compare, revert.

This commit is contained in:
George Vinogradov 2012-01-20 03:04:11 +04:00
parent 54bc26d960
commit 364f2e40c0
15 changed files with 115 additions and 128 deletions

View File

@ -107,17 +107,37 @@ class WikiController < ApplicationController
if request.post?
@versions = params[:versions] || []
if @versions.size < 2
redirect_to history_project_wiki_path(@project, CGI.escape(@name))
if @name
redirect_to history_project_wiki_path(@project, CGI.escape(@name))
else
redirect_to history_project_wiki_index_path(@project)
end
else
redirect_to compare_versions_project_wiki_path(@project, CGI.escape(@name),
if @name
redirect_to compare_versions_project_wiki_path(@project, CGI.escape(@name),
sprintf('%s...%s', @versions.last, @versions.first))
else
redirect_to compare_versions_project_wiki_index_path(@project,
sprintf('%s...%s', @versions.last, @versions.first))
end
end
elsif request.get?
@versions = params[:versions].split(/\.{2,3}/)
@page = @wiki.page(@name)
diffs = @wiki.repo.diff(@versions.first, @versions.last, @page.path)
@diff = diffs.first
@helper = WikiHelper::CompareHelper.new(@diff, @versions)
if @versions.size < 2
if @name
redirect_to history_project_wiki_path(@project, CGI.escape(@name))
else
redirect_to history_project_wiki_index_path(@project)
return
end
end
if @name
page = @wiki.page(@name)
@diff = @wiki.repo.diff(@versions.first, @versions.last, page.path).first
@diffs = [@diff]
else
@diffs = @wiki.repo.diff(@versions.first, @versions.last)
end
render :compare
else
redirect_to project_wiki_path(@project, CGI.escape(@name))
@ -158,11 +178,14 @@ class WikiController < ApplicationController
end
def history
@name = params['id']
if @page = @wiki.page(@name)
@versions = @page.versions#(:page => params['page'], :per_page => 25)#.paginate :page => params[:page] #try to use will_paginate
if @name = params['id']
if @page = @wiki.page(@name)
@versions = @page.versions(:per_page => 1000000)#(:page => params['page'], :per_page => 25)#.paginate :page => params[:page] #try to use will_paginate
else
redirect_to :back
end
else
redirect_to :back
@versions = @wiki.log(:per_page => 100000)
end
end

View File

@ -1,89 +1,19 @@
module WikiHelper
class CompareHelper
def initialize(diff, versions)
@diff = diff
@versions = versions
def revert_path(project, first, second, name)
if name
revert_page_project_wiki_path(project, CGI.escape(name), first, second)
else
revert_page_project_wiki_index_path(project, first, second)
end
end
def before
@versions[0][0..6]
def compare_path(project, name)
if name
compare_project_wiki_path(@project, CGI.escape(name))
else
compare_project_wiki_index_path(@project)
end
def after
@versions[1][0..6]
end
def lines
lines = []
@diff.diff.split("\n")[2..-1].each do |line|
lines << { :line => line,
:class => line_class(line),
:ldln => left_diff_line_number(line),
:rdln => right_diff_line_number(line) }
end if @diff
lines
end
def show_revert
!@message
end
private
def line_class(line)
if line =~ /^@@/
'gc'
elsif line =~ /^\+/
'gi'
elsif line =~ /^\-/
'gd'
else
''
end
end
@left_diff_line_number = nil
def left_diff_line_number(line)
if line =~ /^@@/
m, li = *line.match(/\-(\d+)/)
@left_diff_line_number = li.to_i
@current_line_number = @left_diff_line_number
ret = '...'
elsif line[0] == ?-
ret = @left_diff_line_number.to_s
@left_diff_line_number += 1
@current_line_number = @left_diff_line_number - 1
elsif line[0] == ?+
ret = ' '
else
ret = @left_diff_line_number.to_s
@left_diff_line_number += 1
@current_line_number = @left_diff_line_number - 1
end
ret
end
@right_diff_line_number = nil
def right_diff_line_number(line)
if line =~ /^@@/
m, ri = *line.match(/\+(\d+)/)
@right_diff_line_number = ri.to_i
@current_line_number = @right_diff_line_number
ret = '...'
elsif line[0] == ?-
ret = ' '
elsif line[0] == ?+
ret = @right_diff_line_number.to_s
@right_diff_line_number += 1
@current_line_number = @right_diff_line_number - 1
else
ret = @right_diff_line_number.to_s
@right_diff_line_number += 1
@current_line_number = @right_diff_line_number - 1
end
ret
end
end
def gravatar_url(email)

View File

@ -2,19 +2,24 @@
- if action_name != 'revert'
%ul.actions
%li.minibutton
= form_tag revert_page_project_wiki_path(@project, escaped_name, @helper.before, @helper.after),
= form_tag revert_path(@project, @versions[0][0..6], @versions[1][0..6], @name),
:name => "gollum-revert", :id => "gollum-revert-form" do
= link_to t("layout.wiki.revert_changes"), '#', :class => "gollum-revert-button"
.data.highlight
%table{:cellpadding => "0", :cellspacing => "0"}
- @helper.lines.each do |line|
%tr
%td.line_numbers= line[:ldln]
%td.line_numbers= line[:rdln]
%td
%pre
%div{:class => line[:class]}= line[:line]
= render :partial => 'diff_data', :collection => @diffs, :as => :diff
.spacer
-# if @name
.data.highlight
%table{:cellpadding => "0", :cellspacing => "0"}
- @helper.lines.each do |line|
%tr
%td.line_numbers= line[:ldln]
%td.line_numbers= line[:rdln]
%td
%pre
%div{:class => line[:class]}= line[:line]
-# else
= debug @diffs
#gollum-footer
%ul.actions

View File

@ -0,0 +1,6 @@
.blob_header
.size= h(diff.a_path)
.clear
.diff_data.highlight
= render_diff(diff)

View File

@ -4,7 +4,7 @@
= link_to t("layout.wiki.compare_revisions"), "javascript:void(0);",
:class => "action-compare-revision"
= form_tag compare_project_wiki_path(@project, escaped_name), :name => "compare-versions", :id => "version-form" do
= form_tag compare_path(@project, @name), :name => "compare-versions", :id => "version-form" do
%fieldset
%table
%tbody
@ -20,7 +20,10 @@
%span.time-elapsed= "#{l v.committed_date.to_date, :format => :long}:"
&nbsp;
= v.message
= raw "[#{link_to v.id[0..6], versioned_project_wiki_path(@project, escaped_name, v.id), :title => t("layout.wiki.view_commit")}]"
- if @name
= raw "[#{link_to v.id[0..6], versioned_project_wiki_path(@project, escaped_name, v.id), :title => t("layout.wiki.view_commit")}]"
- else
= "[#{v.id[0..6]}]"
#gollum-footer
%ul.actions

View File

@ -7,18 +7,23 @@
%ul.wat-cf
%li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project)
%li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.wiki_history"), '#'
%li{:class => (!@name and action_name == 'compare') ? 'active' : ''}
= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.git_access"), '#'
.content
#wiki-wrapper.inner.compare
#head
%h1.title
= t("layout.wiki.history_for")
%strong= @name
- if @name
= t("layout.wiki.history_for")
%strong= @name
- else
= t("layout.wiki.wiki_history")
%ul.actions
%li.minibutton= link_to t("layout.wiki.back_to_history"), history_project_wiki_path(@project, escaped_name)
%li.minibutton= link_to t("layout.wiki.back_to_history"),
@name ? history_project_wiki_path(@project, escaped_name) : history_project_wiki_index_path(@project)
= render :partial => 'searchbar'
#wiki-content

View File

@ -7,7 +7,7 @@
%ul.wat-cf
%li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project)
%li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.wiki_history"), '#'
%li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.git_access"), '#'
.content

View File

@ -7,23 +7,31 @@
%ul.wat-cf
%li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project)
%li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.wiki_history"), '#'
%li{:class => (!@name and action_name == 'history') ? 'active' : ''}
= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.git_access"), '#'
.content
#wiki-wrapper.inner.history
#head
%h1.title
= t("layout.wiki.history_for")
%strong= @name
- if @name
= t("layout.wiki.history_for")
%strong= @name
- else
= t("layout.wiki.wiki_history")
%ul.actions
%li.minibutton
= link_to t("layout.wiki.view_page"), view_path(@project, escaped_name),
:class => 'action-view-page'
%li.minibutton
= link_to t("layout.wiki.edit_page"), edit_project_wiki_path(@project, escaped_name),
:class => 'aciton-edit-page'
- if @name
%li.minibutton
= link_to t("layout.wiki.view_page"), view_path(@project, escaped_name),
:class => 'action-view-page'
%li.minibutton
= link_to t("layout.wiki.edit_page"), edit_project_wiki_path(@project, escaped_name),
:class => 'aciton-edit-page'
- else
%li.minibutton
= link_to t("layout.wiki.view_page"), project_wiki_index_path(@project)
= render :partial => 'searchbar'
#wiki-content

View File

@ -7,7 +7,7 @@
%ul.wat-cf
%li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project)
%li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.wiki_history"), '#'
%li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.git_access"), '#'
.content

View File

@ -8,7 +8,7 @@
%li.first{:class => "#{(@name == 'Home') ? 'active' : ''}" }
= link_to t("layout.wiki.home"), project_wiki_index_path(@project)
%li.active= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.wiki_history"), '#'
%li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.git_access"), '#'
.content

View File

@ -7,7 +7,7 @@
%ul.wat-cf
%li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project)
%li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.wiki_history"), '#'
%li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.git_access"), '#'
.content

View File

@ -8,7 +8,7 @@
%li.first{:class => "#{(@name == 'Home') ? 'active' : ''}" }
= link_to t("layout.wiki.home"), project_wiki_index_path(@project)
%li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.wiki_history"), '#'
%li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project)
%li= link_to t("layout.wiki.git_access"), '#'
.content

View File

@ -81,12 +81,14 @@ Rosa::Application.routes.draw do
resources :projects do
resources :wiki do
collection do
# Uncomment if gollum can revert page without name
# match 'revert/:sha1/:sha2' => 'wiki#revert', :as => :revert, :via => :get, :constrains => {:sha1 => /[0-9a-f]{40}/, :sha2 => /[0-9a-f]{40}/}
match '_history' => 'wiki#history', :as => :history, :via => :get
match '_access' => 'wiki#git', :as => :git, :via => :get
match '_revert/:sha1/:sha2' => 'wiki#revert', :as => :revert_page, :via => [:get, :post]
match '_compare' => 'wiki#compare', :as => :compare, :via => :post
post :preview
get :search
get :pages
match '_compare/*versions' => 'wiki#compare', :as => :compare_versions, :via => :get
end
member do
get :history

View File

@ -111,6 +111,7 @@ table.blob td.blob pre {
background-color: #EAEAEA;
border-bottom: 1px solid #DDDDDD;
font-family: Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
font-size: 1.2em;
padding: 5px;
margin-top: 20px;
}
@ -143,6 +144,7 @@ table.commit_stats tr {
table.diff {
line-height: 1.4em;
font-size: 1.2em;
font-family: 'Bitstream Vera Sans Mono','Courier',monospace;
border-top: 1px solid #EAEAEA;
border-bottom: 1px solid #EAEAEA;
@ -153,8 +155,7 @@ table.diff tr td.line_numbers {
background-color: #ECECEC;
border-right: 1px solid #DDDDDD;
color: #AAAAAA;
padding-left: 10px;
padding-right: 10px;
padding: 0 0.5em;
text-align: right;
}

View File

@ -449,6 +449,10 @@
width: 1%;
}
#compare-content .spacer {
height: 20px;
}
.compare #compare-content ul.actions li,
.compare #footer ul.actions li {
margin-left: 0;