-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
906 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
# redmine_diff_popup | ||
# Redmine Diff Popup | ||
|
||
This plugin provide on pop-up show feature of diff. | ||
|
||
* http://www.redmine.org/plugins/redmine_diff_popup | ||
|
||
## Features | ||
|
||
* Add pop-up show feature on issue's history diff. | ||
* Add switch of pop-up/default in user preferences. | ||
|
||
## Compatibility | ||
|
||
Redmine 3.3 or 3.4 stable | ||
|
||
Tested on: | ||
* 3.3.3 | ||
* 3.4.2 | ||
|
||
## Installation | ||
|
||
1. Follow the Redmine plugin installation steps at: http://www.redmine.org/wiki/redmine/Plugins | ||
2. Run the plugin migrations `rake redmine:plugins:migrate RAILS_ENV=production` | ||
3. Restart your Redmine web server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class DiffPopupController < ApplicationController | ||
unloadable | ||
before_action :find_journal, :only => [:journal_diff] | ||
|
||
layout false | ||
helper :issues | ||
helper :custom_fields | ||
|
||
def journal_diff | ||
@issue = @journal.issue | ||
if params[:detail_id].present? | ||
@detail = @journal.details.find_by_id(params[:detail_id]) | ||
else | ||
@detail = @journal.details.detect {|d| d.property == 'attr' && d.prop_key == 'description'} | ||
end | ||
unless @issue && @detail | ||
render_404 | ||
return false | ||
end | ||
if @detail.property == 'cf' | ||
unless @detail.custom_field && @detail.custom_field.visible_by?(@issue.project, User.current) | ||
raise ::Unauthorized | ||
end | ||
end | ||
@diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value) | ||
end | ||
|
||
private | ||
|
||
def find_journal | ||
@journal = Journal.visible.find(params[:id]) | ||
@project = @journal.journalized.project | ||
rescue ActiveRecord::RecordNotFound | ||
render_404 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<p><%= authoring @journal.created_on, @journal.user, :label => :label_updated_time_by %></p> | ||
<div style="text-align:right;"> | ||
<span class="diff_in"><%= l(:diff_popup_legend_add) %></span> <span class="diff_out"><%= l(:diff_popup_legend_remove) %></span> | ||
</div> | ||
<div class="text-diff"> | ||
<%= simple_format_without_paragraph @diff.to_html %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
app/views/issues/_issues_history_journal_bottom_partial.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<% if journal.details.any? && User.current.pref.enable_popup_journal_diff == '1' %> | ||
<% journal.visible_details.each do |detail| %> | ||
<% if is_show_diff_detail?(detail) %> | ||
<li><%= show_detail_diff_popup(detail, journal.indice) %></li> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
10 changes: 10 additions & 0 deletions
10
app/views/issues/_issues_show_details_bottom_partial.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% if User.current.pref.enable_popup_journal_diff == '1' %> | ||
<%= content_for :header_tags do | ||
javascript_include_tag("diff_popup", :plugin => "redmine_diff_popup") | ||
end %> | ||
<script> | ||
$(function () { | ||
replaceJournalDiff(); | ||
}); | ||
</script> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= labelled_fields_for :pref, @user.pref do |pref_fields| %> | ||
<p><%= pref_fields.check_box :enable_popup_journal_diff %></p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function replaceJournalDiff() | ||
{ | ||
$("#history div.journal ul > li > a").each(function(){ | ||
//find li | ||
var orgDiff = $(this).parent(); | ||
var popDiff = $(this).parents("div.journal:first").next("li"); | ||
|
||
//replace and set func | ||
popDiff.replaceAll(orgDiff).find("a").on("click", function(){ | ||
var diffUrl = $(this).attr("href"); | ||
var journalIndice = diffUrl.split("&indice=")[1]; | ||
var dlgName = "#diffpopup" + journalIndice; | ||
|
||
//on top dialog | ||
if ($(dlgName).size() == 1) | ||
{ | ||
$(dlgName).dialog("moveToTop"); | ||
return; | ||
} | ||
|
||
//show dialog | ||
$.get(diffUrl, function (data) { | ||
var journalIndice = decodeURIComponent(this.url.split("?")[1].split("&indice=")[1]); | ||
var popupId = "diffpopup" + journalIndice; | ||
$("#content").append("<div id='" + popupId + "'></div>"); | ||
$("#" + popupId).html(data).dialog({ | ||
title: "#" + journalIndice, | ||
width: window.innerWidth / 2 - 40, | ||
maxHeight: window.innerHeight - 160, | ||
position: { my: "center center", at: "right center", of: window }, | ||
create: function(event) { | ||
$(event.target).dialog("widget").css({ "position": "fixed" }); | ||
}, | ||
open: function() { | ||
$(this).find("a").blur(); | ||
}, | ||
close: function (event) { | ||
$(this).dialog("destroy"); | ||
$(event.target).remove(); | ||
} | ||
}).show(); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# English strings go here for Rails i18n | ||
en: | ||
diff_popup_legend_add: "Added" | ||
diff_popup_legend_remove: "Removed" | ||
field_enable_popup_journal_diff: "Enable popup show of issue's history diff" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Japanese strings go here for Rails i18n | ||
ja: | ||
diff_popup_legend_add: "追加" | ||
diff_popup_legend_remove: "削除" | ||
field_enable_popup_journal_diff: "チケット履歴の差分をポップアップ表示する" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Rails.application.routes.draw do | ||
get 'diff_popup/journal_diff', to: 'diff_popup#journal_diff' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require_dependency 'redmine_diff_popup/hooks/diff_popup_hook' | ||
require_dependency 'redmine_diff_popup/patches/issues_helper_patch' | ||
require_dependency 'redmine_diff_popup/patches/user_preference_patch' | ||
|
||
|
||
ActionDispatch::Callbacks.to_prepare do | ||
unless UserPreference.included_modules.include?(RedmineDiffPopup::Patches::UserPreferencePatch) | ||
UserPreference.send :prepend, RedmineDiffPopup::Patches::UserPreferencePatch | ||
end | ||
|
||
unless IssuesHelper.included_modules.include?(RedmineDiffPopup::Patches::IssuesHelperPatch) | ||
IssuesHelper.send :prepend, RedmineDiffPopup::Patches::IssuesHelperPatch | ||
end | ||
end | ||
|
||
|
||
Redmine::Plugin.register :redmine_diff_popup do | ||
name 'Redmine Diff Popup plugin' | ||
author 'Ryuta Tobita' | ||
description 'This plugin provide on pop-up show feature of diff.' | ||
version '1.0.0' | ||
url 'https://github.com/GEROMAX/redmine_diff_popup' | ||
author_url 'https://github.com/GEROMAX' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class DiffPopupHook < Redmine::Hook::ViewListener | ||
render_on :view_issues_history_journal_bottom, :partial => 'issues/issues_history_journal_bottom_partial' | ||
render_on :view_issues_show_details_bottom, :partial => 'issues/issues_show_details_bottom_partial' | ||
render_on :view_my_account_preferences, :partial => 'my/diff_popup_preferences' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require_dependency("issues_helper") | ||
|
||
module RedmineDiffPopup | ||
module Patches | ||
module IssuesHelperPatch | ||
extend ActiveSupport::Concern | ||
|
||
# add method to IssuesHelper | ||
def is_show_diff_detail?(detail) | ||
case detail.property | ||
when 'attr' | ||
return detail.prop_key == 'description' | ||
when 'cf' | ||
custom_field = detail.custom_field | ||
if custom_field | ||
if custom_field.format.class.change_as_diff | ||
return true | ||
end | ||
end | ||
end | ||
return false | ||
end | ||
|
||
def show_detail_diff_popup(detail, indice) | ||
label = detail.prop_key == 'description' ? l(:field_description) : detail.custom_field.name | ||
label = content_tag('strong', label) | ||
s = l(:text_journal_changed_no_detail, :label => label) | ||
diff_link = link_to 'diff', | ||
diff_popup_journal_diff_url(:id => detail.journal_id, :detail_id => detail.id, :indice => indice), | ||
:title => l(:label_view_diff), | ||
:onclick => 'return false;' | ||
s << " (#{ diff_link })" | ||
s.html_safe | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require_dependency 'user_preference' | ||
|
||
module RedmineDiffPopup | ||
module Patches | ||
module UserPreferencePatch | ||
|
||
def self.prepended(base) | ||
base.class_eval do | ||
if defined? safe_attributes | ||
safe_attributes :enable_popup_journal_diff | ||
end | ||
end | ||
end | ||
|
||
def enable_popup_journal_diff; self[:enable_popup_journal_diff] || '1'; end | ||
def enable_popup_journal_diff=(value); self[:enable_popup_journal_diff]=value; end | ||
|
||
end | ||
end | ||
end |