Skip to content

Commit bb0f30e

Browse files
committed
Merge branch 'development'
2 parents e79465c + 854fd21 commit bb0f30e

16 files changed

+172
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ This plugin provide on pop-up show feature of diff.
77
## Features
88

99
* Add pop-up show feature on issue's history diff.
10+
* Add pop-up show feature on wiki's history diff.
1011
* Add switch of pop-up/default in user preferences.
1112

1213
## Compatibility
1314

1415
Redmine 3.2 or 3.3 or 3.4 stable
1516

1617
Tested on:
18+
1719
* 3.2.2
18-
* 3.3.3
19-
* 3.4.2
20+
* 3.3.0
21+
* 3.4.3
2022

2123
## Installation
2224

app/controllers/diff_popup_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def journal_diff
2525
@diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
2626
end
2727

28-
private
28+
private
2929

3030
def find_journal
3131
@journal = Journal.visible.find(params[:id])
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class WikiPopupController < ApplicationController
2+
unloadable
3+
before_action :find_wiki, :authorize
4+
before_action :find_existing_page, :only => [:wiki_diff]
5+
6+
layout false
7+
8+
def wiki_diff
9+
@diff = @page.diff(params[:version], params[:version_from])
10+
render_404 unless @diff
11+
end
12+
13+
private
14+
15+
def find_wiki
16+
@project = Project.find(params[:project_id])
17+
@wiki = @project.wiki
18+
render_404 unless @wiki
19+
rescue ActiveRecord::RecordNotFound
20+
render_404
21+
end
22+
23+
# Finds the requested page and returns a 404 error if it doesn't exist
24+
def find_existing_page
25+
@page = @wiki.find_page(params[:id])
26+
if @page.nil?
27+
render_404
28+
return
29+
end
30+
if @wiki.page_found_with_redirect?
31+
redirect_to_page @page
32+
end
33+
end
34+
35+
def redirect_to_page(page)
36+
if page.project && page.project.visible?
37+
redirect_to :action => action_name, :project_id => page.project, :id => page.title
38+
else
39+
render_404
40+
end
41+
end
42+
43+
end

app/views/diff_popup/journal_diff.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
<p><%= authoring @journal.created_on, @journal.user, :label => :label_updated_time_by %></p>
2-
<div style="text-align:right;">
3-
<span class="diff_in"><%= l(:diff_popup_legend_add) %></span>&nbsp;<span class="diff_out"><%= l(:diff_popup_legend_remove) %></span>
1+
<div style="margin-top: 1em;margin-bottom: 1em;">
2+
<%= authoring @journal.created_on, @journal.user, :label => :label_updated_time_by %>
3+
<div style="float:right;">
4+
<span class="diff_in"><%= l(:diff_popup_legend_add) %></span>&nbsp;<span class="diff_out"><%= l(:diff_popup_legend_remove) %></span>
5+
</div>
46
</div>
57
<div class="text-diff">
68
<%= simple_format_without_paragraph @diff.to_html %>

app/views/issues/_issues_show_details_bottom_partial.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<% if User.current.pref.enable_popup_journal_diff == '1' %>
22
<%= content_for :header_tags do
3-
javascript_include_tag("diff_popup", :plugin => "redmine_diff_popup")
3+
javascript_include_tag('diff_popup', :plugin => 'redmine_diff_popup')
44
end %>
55
<script>
66
$(function () {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<% if User.current.pref.enable_popup_wiki_diff == '1' %>
2+
<%= hidden_field_tag 'project_id', @project.id %>
3+
<%= hidden_field_tag 'id', @page.title %>
4+
<%= button_tag l(:label_view_diff), :type => 'button', :class => 'small wiki-popup', :style => 'display:none;', :url => Redmine::Utils.relative_url_root + '/wiki_popup/wiki_diff?' %>
5+
<script>
6+
$(function () {
7+
replaceWikiSubmitButton();
8+
});
9+
</script>
10+
<% end %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% if User.current.pref.enable_popup_wiki_diff == '1' %>
2+
<%= javascript_include_tag('wiki_popup', :plugin => 'redmine_diff_popup') %>
3+
<% end %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<%= labelled_fields_for :pref, @user.pref do |pref_fields| %>
22
<p><%= pref_fields.check_box :enable_popup_journal_diff %></p>
3+
<p><%= pref_fields.check_box :enable_popup_wiki_diff %></p>
34
<% end %>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<p class="wiki-popup-title" style="display:none;"><%= l(:label_history) %> <%= @diff.content_from.version %> - <%= @diff.content_to.version %></p>
2+
<div style="margin-top: 1em;margin-bottom: 1em;">
3+
<%= l(:label_version) %> <%= link_to @diff.content_from.version, :controller => "wiki", :action => 'show', :id => @page.title, :project_id => @page.project, :version => @diff.content_from.version %>
4+
<em>(<%= @diff.content_from.author ?
5+
@diff.content_from.author.name : l(:label_user_anonymous)
6+
%>, <%= format_time(@diff.content_from.updated_on) %>)</em>
7+
&#8594;
8+
<%= l(:label_version) %> <%= link_to @diff.content_to.version, :controller => "wiki", :action => 'show',
9+
:id => @page.title, :project_id => @page.project,
10+
:version => @diff.content_to.version
11+
%>/<%= @page.content.version %>
12+
<em>(<%= @diff.content_to.author ?
13+
link_to_user(@diff.content_to.author.name) : l(:label_user_anonymous)
14+
%>, <%= format_time(@diff.content_to.updated_on) %>)</em>
15+
<div style="float:right;">
16+
<span class="diff_in"><%= l(:diff_popup_legend_add) %></span>&nbsp;<span class="diff_out"><%= l(:diff_popup_legend_remove) %></span>
17+
</div>
18+
</div>
19+
<div class="text-diff">
20+
<%= simple_format_without_paragraph @diff.to_html %>
21+
</div>

assets/javascripts/wiki_popup.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function replaceWikiSubmitButton()
2+
{
3+
$("button.wiki-popup, #project_id, #id").replaceAll($("#content > form > input.small")).filter("button.wiki-popup").show().on("click", function(){
4+
//on top dialog
5+
var dlgName = "#diffpopup" + $("input[name='version_from']:checked").val() + "_" + $("input[name='version']:checked").val();
6+
if ($(dlgName).size() == 1)
7+
{
8+
$(dlgName).dialog("moveToTop");
9+
return false;
10+
}
11+
12+
//show dialog
13+
var diffUrl = $(this).attr("url") + $(this).parent("form").serialize();
14+
$.get(diffUrl, function (data) {
15+
var params = q_to_hash(decodeURIComponent(this.url).split("?")[1].split("&"));
16+
var popupId = "diffpopup" + params["version_from"] + "_" + params["version"];
17+
$("#content").append("<div id='" + popupId + "'></div>");
18+
$("#" + popupId).html(data).dialog({
19+
title: $("#" + popupId).find("p.wiki-popup-title").text(),
20+
width: window.innerWidth / 2 - 40,
21+
maxHeight: window.innerHeight - 160,
22+
position: { my: "center center", at: "right center", of: window },
23+
create: function(event) {
24+
$(event.target).dialog("widget").css({ "position": "fixed" });
25+
},
26+
open: function() {
27+
$(this).find("a").blur();
28+
},
29+
resizeStart: function(event) {
30+
$(event.target).dialog("option", "maxHeight", "");
31+
},
32+
close: function (event) {
33+
$(this).dialog("destroy");
34+
$(event.target).remove();
35+
}
36+
}).show();
37+
});
38+
39+
return false;
40+
});
41+
}
42+
43+
function q_to_hash(param){
44+
var hs = new Object;
45+
for(var i=0;i < param.length;i++) {
46+
var kv = param[i].split("=");
47+
hs[kv[0]]=kv[1];
48+
}
49+
return hs;
50+
}

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ en:
33
diff_popup_legend_add: "Added"
44
diff_popup_legend_remove: "Removed"
55
field_enable_popup_journal_diff: "Enable popup show of issue's history diff"
6+
field_enable_popup_wiki_diff: "Enable popup show of wiki's history diff"

config/locales/ja.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ ja:
33
diff_popup_legend_add: "追加"
44
diff_popup_legend_remove: "削除"
55
field_enable_popup_journal_diff: "チケット履歴の差分をポップアップ表示する"
6+
field_enable_popup_wiki_diff: "Wiki履歴の差分をポップアップ表示する"

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Rails.application.routes.draw do
22
get 'diff_popup/journal_diff', to: 'diff_popup#journal_diff'
3+
match 'wiki_popup/:action', :controller => 'wiki_popup', :via => [:get]
34
end

init.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
name 'Redmine Diff Popup plugin'
1919
author 'Ryuta Tobita'
2020
description 'This plugin provide on pop-up show feature of diff.'
21-
version '1.0.1'
21+
version '2.0.0'
2222
url 'https://github.com/GEROMAX/redmine_diff_popup'
2323
author_url 'https://github.com/GEROMAX'
24+
permission :wiki_popup, {:wiki_popup => [:wiki_diff]}, :public => true
2425
end

lib/redmine_diff_popup/hooks/diff_popup_hook.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,28 @@ class DiffPopupHook < Redmine::Hook::ViewListener
22
render_on :view_issues_history_journal_bottom, :partial => 'issues/issues_history_journal_bottom_partial'
33
render_on :view_issues_show_details_bottom, :partial => 'issues/issues_show_details_bottom_partial'
44
render_on :view_my_account_preferences, :partial => 'my/diff_popup_preferences'
5+
6+
def view_layouts_base_html_head(context={})
7+
if is_wiki_history?(context[:request])
8+
context[:controller].send(:render_to_string, {
9+
:partial => 'layouts/wiki_popup_html_head_partial',
10+
:locals => context
11+
})
12+
end
13+
end
14+
15+
def view_layouts_base_content(context={})
16+
if is_wiki_history?(context[:request])
17+
context[:controller].send(:render_to_string, {
18+
:partial => 'layouts/wiki_popup_content_partial',
19+
:locals => context
20+
})
21+
end
22+
end
23+
24+
private
25+
def is_wiki_history?(request)
26+
request.original_url =~ Regexp.new('/projects/\S+/wiki/\S+/history')
27+
end
28+
529
end

lib/redmine_diff_popup/patches/user_preference_patch.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ def self.prepended(base)
88
base.class_eval do
99
if defined? safe_attributes
1010
safe_attributes :enable_popup_journal_diff
11+
safe_attributes :enable_popup_wiki_diff
1112
end
1213
end
1314
end
1415

1516
def enable_popup_journal_diff; self[:enable_popup_journal_diff] || '1'; end
1617
def enable_popup_journal_diff=(value); self[:enable_popup_journal_diff]=value; end
1718

19+
def enable_popup_wiki_diff; self[:enable_popup_wiki_diff] || '1'; end
20+
def enable_popup_wiki_diff=(value); self[:enable_popup_wiki_diff]=value; end
21+
1822
end
1923
end
2024
end

0 commit comments

Comments
 (0)