[issue #64] Added revisions comparsion.
This commit is contained in:
parent
552aa0a58a
commit
0c527af291
|
@ -117,6 +117,7 @@ class WikiController < ApplicationController
|
|||
@page = @wiki.page(@name)
|
||||
diffs = @wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||
@diff = diffs.first
|
||||
@helper = WikiHelper::CompareHelper.new(@diff, @versions)
|
||||
render :compare
|
||||
else
|
||||
redirect_to project_wiki_path(@project, CGI.escape(@name))
|
||||
|
@ -137,6 +138,7 @@ class WikiController < ApplicationController
|
|||
@versions = [sha1, sha2]
|
||||
diffs = @wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||
@diff = diffs.first
|
||||
@helper = WikiHelper::CompareHelper.new(@diff, @versions)
|
||||
flash[:error] = t("flash.wiki.patch_does_not_apply")
|
||||
render :compare
|
||||
end
|
||||
|
@ -158,7 +160,7 @@ class WikiController < ApplicationController
|
|||
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
|
||||
@versions = @page.versions#(:page => params['page'], :per_page => 25)#.paginate :page => params[:page] #try to use will_paginate
|
||||
else
|
||||
redirect_to :back
|
||||
end
|
||||
|
|
|
@ -1,4 +1,90 @@
|
|||
module WikiHelper
|
||||
class CompareHelper
|
||||
|
||||
def initialize(diff, versions)
|
||||
@diff = diff
|
||||
@versions = versions
|
||||
end
|
||||
|
||||
def before
|
||||
@versions[0][0..6]
|
||||
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)
|
||||
"http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.downcase)}?s=16&r=pg"
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#compare-content
|
||||
- if action_name != 'revert'
|
||||
%ul.actions
|
||||
%li.minibutton
|
||||
= form_tag revert_page_project_wiki_path(@project, escaped_name, @helper.before, @helper.after),
|
||||
: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]
|
||||
|
||||
#gollum-footer
|
||||
%ul.actions
|
||||
- if action_name != 'revert'
|
||||
%li.minibutton
|
||||
= link_to t("layout.wiki.revert_changes"), '#', :class => "gollum-revert-button"
|
||||
%li.minibutton= link_to t("layout.wiki.back_to_top"), '#wiki'
|
|
@ -0,0 +1,29 @@
|
|||
= render :partial => 'gollum_includes'
|
||||
= render :partial => 'project_short'
|
||||
|
||||
%a{ :name => "wiki"}
|
||||
.block
|
||||
.secondary-navigation
|
||||
%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.git_access"), '#'
|
||||
|
||||
.content
|
||||
#wiki-wrapper.inner.compare
|
||||
#head
|
||||
%h1
|
||||
= t("layout.wiki.history_for")
|
||||
%strong= @name
|
||||
|
||||
%ul.actions
|
||||
%li.minibutton= link_to t("layout.wiki.back_to_history"), history_project_wiki_path(@project, escaped_name)
|
||||
= render :partial => 'searchbar'
|
||||
|
||||
#wiki-content
|
||||
= render :partial => "compare"
|
||||
|
||||
- content_for :sidebar do
|
||||
- render :partial => 'projects/sidebar'
|
||||
|
|
@ -187,6 +187,9 @@ ru:
|
|||
no_pages_in: В %{ref} нет страниц для отображения.
|
||||
no_results_for_search: По запросу %{query} ничего не найдено.
|
||||
matches: Совпадений
|
||||
back_to_history: Назад к истории
|
||||
history_for: История для
|
||||
revert_changes: Откатить изменения
|
||||
|
||||
roles:
|
||||
confirm_delete: Вы уверены, что хотите удалить эту роль?
|
||||
|
|
|
@ -91,7 +91,7 @@ Rosa::Application.routes.draw do
|
|||
member do
|
||||
get :history
|
||||
get :edit
|
||||
match 'revert/:sha1/:sha2' => 'wiki#revert', :as => :revert_page, :via => :get
|
||||
match 'revert/:sha1/:sha2' => 'wiki#revert', :as => :revert_page, :via => [:get, :post]
|
||||
match ':ref' => 'wiki#show', :as => :versioned, :via => :get
|
||||
|
||||
post :compare
|
||||
|
|
|
@ -274,6 +274,7 @@
|
|||
#wiki-history table tr td.checkbox {
|
||||
min-width: 2em;
|
||||
padding: 0.3em;
|
||||
width: 24px;
|
||||
}
|
||||
|
||||
#wiki-history table tr td.checkbox input {
|
||||
|
@ -415,9 +416,14 @@
|
|||
.compare .data {
|
||||
border: 1px solid #ddd;
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.compare .data table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.compare .data pre {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
@ -440,6 +446,7 @@
|
|||
border-right: 1px solid #999;
|
||||
color: #999;
|
||||
padding: 0 0 0 0.5em;
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
.compare #compare-content ul.actions li,
|
||||
|
|
Loading…
Reference in New Issue