Permalink
Browse files

Merge branch 'redmine-1.4' into redmine-2.1

Conflicts:
	lib/tagging_plugin/tagging_hooks.rb
  • Loading branch information...
nettsundere committed Dec 19, 2012
2 parents 9d999f9 + bd22280 commit 8d4bc72e4fea3430ba03032829ca33f4fd286916
@@ -21,6 +21,10 @@ def link_to_project_tag_filter(project, tag, options = {}, html_options = {})
end
end
def tag_without_sharp(tag)
tag[1..-1]
end
def tag_cloud_in_project(project, &each_tag)
tags = {}
@@ -0,0 +1,13 @@
<a id="cloud_trigger"><b><%= t(:tags_in_project) %></b></a>
<span id="cloud_content"> &mdash;
<%
tag_cloud_in_project(@project) do |tag, factor|
style = "font-size: #{10 * factor + 9}pt"
%>
<a class="tag_item"
data-tag="<%= tag_without_sharp(tag) %>"
style="<%= style %>">
<%= tag %>
</a>
<% end %>
</span>
@@ -0,0 +1,107 @@
// IE compatibility
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
"use strict"
if (this == null) {
throw new TypeError()
}
var t = Object(this)
var len = t.length >>> 0
if (len === 0) {
return -1
}
var n = 0
if (arguments.length > 1) {
n = Number(arguments[1]);
if (n != n) { // shortcut for verifying if it's NaN
n = 0
} else if (n != 0 && n != Infinity && n != -Infinity) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
if (n >= len) {
return -1
}
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
for (; k < len; k++) {
if (k in t && t[k] === searchElement) {
return k
}
}
return -1
}
}
(function ($) {
$.fn.toggleCloudViaFor = function(cloud_trigger, tag_container) {
var tag_cloud = $(this)
cloud_trigger.click(function(e) {
tag_cloud.toggle()
e.preventDefault()
})
var tag_items = tag_cloud.children()
$(tag_items).click(function(e) {
var tag_value = $(this).attr("data-tag")
$(this).toggleTagFor(tag_value, tag_container)
show_selected_tags_from(tag_container, tag_cloud)
e.preventDefault()
})
$(this).toggle()
show_selected_tags_from(tag_container, tag_cloud)
tag_container.keyup(function(e) {
show_selected_tags_from(tag_container, tag_cloud)
})
tag_container.change(function(e) {
show_selected_tags_from(tag_container, tag_cloud)
})
}
function show_selected_tags_from(tag_container, tag_cloud) {
var current_tags = tags_to_array(tag_container.attr("value"))
update_selected_tags(current_tags, tag_cloud)
}
function update_selected_tags(selected_tags, tag_cloud) {
tag_cloud.children().each(function(index, tag_child) {
var tag_value = $(tag_child).attr("data-tag")
if(selected_tags.indexOf(tag_value.toLowerCase()) == -1)
$(tag_child).removeClass("selected")
else {
$(tag_child).addClass("selected")
}
})
}
$.fn.toggleTagFor = function(tag_name, tag_container) {
var content_tags = tags_to_array(tag_container.attr("value"))
var this_tag_index = content_tags.indexOf(tag_name.toLowerCase())
if(this_tag_index == -1) {
content_tags.push(tag_name)
} else {
content_tags.splice(this_tag_index, 1)
}
tag_container.attr("value", content_tags.join(" "))
}
function tags_to_array(tags) {
dirty_items = tags.split(/[,#\s]+/)
dirty_items = $.map(dirty_items, function(val, i){
return val.toLowerCase()
})
return $.grep(dirty_items, function(val, i){
return (val.length > 0)
})
}
})(jQuery)
@@ -0,0 +1,31 @@
span.tagMatches {
margin-left: 10px;
}
span.tagMatches span {
padding: 2px;
margin-right: 4px;
background-color: #0000AB;
color: #fff;
cursor: pointer;
}
#cloud_trigger, #cloud_content a {
cursor: pointer;
text-decoration: none;
border-bottom: 1px dashed;
}
#cloud_trigger {
font-weight: bold;
}
#cloud_content a {
margin: 0.1em;
}
#cloud_content .selected {
background: #0000AB;
color: #fff;
}
@@ -12,4 +12,5 @@ en:
tags: "Tags"
append_tags: "Append tags instead of rewrite"
detach: "Detach"
detach: "Detach"
tags_in_project: "Project tags"
@@ -4,4 +4,5 @@ ru:
tagging_wiki_pages_inline: "Использовать теги из текста страниц вики"
tagging_issues_inline: "Использовать теги из описаний задач"
detach: "Отделить"
notice_successful_detached: "Тег успешно отвязан от всех тикетов проекта"
notice_successful_detached: "Тег успешно отвязан от всех тикетов проекта"
tags_in_project: "Теги в проекте"
@@ -1,64 +1,58 @@
module TaggingPlugin
module Hooks
class LayoutHook < Redmine::Hook::ViewListener
def view_issues_sidebar_planning_bottom(context={ })
def view_issues_sidebar_planning_bottom(context={})
return '' if Setting.plugin_redmine_tagging[:sidebar_tagcloud] != "1"
return context[:controller].send(:render_to_string, {
:partial => 'tagging/tagcloud',
:locals => context
})
})
end
def view_wiki_sidebar_bottom(context={ })
def view_wiki_sidebar_bottom(context={})
return '' if Setting.plugin_redmine_tagging[:sidebar_tagcloud] != "1"
return context[:controller].send(:render_to_string, {
:partial => 'tagging/tagcloud_search',
:locals => context
})
})
end
def view_layouts_base_html_head(context = {})
if Setting.plugin_redmine_tagging[:sidebar_tagcloud] == "1" \
&& context[:controller].is_a?(WikiController)
def view_layouts_base_html_head(context={})
tagging_stylesheet = stylesheet_link_tag 'tagging', :plugin => 'redmine_tagging'
unless ((Setting.plugin_redmine_tagging[:sidebar_tagcloud] == "1" &&
context[:controller].is_a?(WikiController)) ||
(context[:controller].is_a?(IssuesController) &&
context[:controller].action_name == 'bulk_edit'))
return tagging_stylesheet
end
if Setting.plugin_redmine_tagging[:sidebar_tagcloud] == "1"
tag_cloud = context[:controller].send(:render_to_string, {
:partial => 'tagging/tagcloud_search',
:locals => context
})
result = <<-TAGS
<script type="text/javascript">
$(function() {
$('#sidebar').append("#{escape_javascript(tag_cloud)}")
})
</script>
TAGS
sidebar_tags = "$('#sidebar').append(\"#{escape_javascript(tag_cloud)}\")"
else
result = ''
sidebar_tags = ''
end
<<-TAGCLOUD
#{result}
<style>
span.tagMatches {
margin-left: 10px;
}
span.tagMatches span {
padding: 2px;
margin-right: 4px;
background-color: #0000AB;
color: #fff;
cursor: pointer;
}
</style>
TAGCLOUD
<<-TAGS
#{tagging_stylesheet}
#{javascript_include_tag 'toggle_tags', :plugin => 'redmine_tagging'}
<script type="text/javascript">
$(function() {
#{sidebar_tags}
$('#cloud_content').toggleCloudViaFor($('#cloud_trigger'), $('#issue_tags'))
})
</script>
TAGS
end
def view_issues_show_details_bottom(context={ })
def view_issues_show_details_bottom(context={})
return '' if Setting.plugin_redmine_tagging[:issues_inline] == "1"
issue = context[:issue]
@@ -72,7 +66,7 @@ def view_issues_show_details_bottom(context={ })
})
end
def view_issues_form_details_bottom(context={ })
def view_issues_form_details_bottom(context={})
return '' if Setting.plugin_redmine_tagging[:issues_inline] == "1"
issue = Issue.visible.find_by_id(context[:issue].id) || context[:issue]
@@ -82,8 +76,13 @@ def view_issues_form_details_bottom(context={ })
tags = issue.tag_list_on(tag_context).sort.collect{|tag| tag.gsub(/^#/, '')}.join(' ')
tags = '<p>' + context[:form].text_field(:tags, :value => tags) + '</p>'
tags += javascript_include_tag 'jquery_loader', :plugin => 'redmine_tagging'
tags += javascript_include_tag 'tag', :plugin => 'redmine_tagging'
tags += javascript_include_tag 'toggle_tags', :plugin => 'redmine_tagging'
cloud = context[:controller].send(:render_to_string, {
:partial => 'tagging/issue_tagcloud',
:locals => context
})
ac = ActsAsTaggableOn::Tag.find(:all,
:conditions => ["id in (select tag_id from taggings
@@ -93,14 +92,18 @@ def view_issues_form_details_bottom(context={ })
<script type="text/javascript">
$(document).ready(function() {
$('#issue_tags').tagSuggest({ tags: [#{ac}] })
var tags_container = $('#issue_tags').parent()
var cloud = $("<div>#{escape_javascript(cloud)}</div>")
$(tags_container).append(cloud)
$('#cloud_content').toggleCloudViaFor($('#cloud_trigger'), $('#issue_tags'))
})
</script>
generatedscript
return tags
end
def controller_issues_bulk_edit_before_save(context = {})
def controller_issues_bulk_edit_before_save(context={})
return if Setting.plugin_redmine_tagging[:issues_inline] == "1"
return unless context[:params] && context[:params]['issue']
return unless context[:params]['issue']['tags']
@@ -125,7 +128,7 @@ def controller_issues_bulk_edit_before_save(context = {})
issue.tags_to_update = tags
end
def controller_issues_edit_before_save(context = {})
def controller_issues_edit_before_save(context={})
return if Setting.plugin_redmine_tagging[:issues_inline] == "1"
return unless context[:params] && context[:params]['issue']
@@ -139,7 +142,7 @@ def controller_issues_edit_before_save(context = {})
alias_method :controller_issues_new_before_save, :controller_issues_edit_before_save
# wikis have no view hooks
def view_layouts_base_content(context = {})
def view_layouts_base_content(context={})
return '' if Setting.plugin_redmine_tagging[:wiki_pages_inline] == "1"
return '' unless context[:controller].is_a?(WikiController)
@@ -196,17 +199,23 @@ def view_layouts_base_content(context = {})
return tags
end
def view_issues_bulk_edit_details_bottom(context = {})
def view_issues_bulk_edit_details_bottom(context={})
cloud = context[:controller].send(:render_to_string, {
:partial => 'tagging/issue_tagcloud',
:locals => context
})
field = "<p>
<label>#{ l(:field_tags) }</label>
#{ text_field_tag 'issue[tags]', '', :size => 18 }<br>
<input type=\"checkbox\" name=\"append_tags\" checked=\"checked\">
#{ l(:append_tags) }<br>
</p>"
return field
return field + "<p>" + cloud + "</p>"
end
def view_reports_issue_report_split_content_right(context = {})
def view_reports_issue_report_split_content_right(context={})
project_context = ContextHelper.context_for(context[:project])
@tags = ActsAsTaggableOn::Tagging \
.find_all_by_context(project_context) \
@@ -222,7 +231,6 @@ def view_reports_issue_report_split_content_right(context = {})
report += "<br/>"
return report
end
end
end
end

0 comments on commit 8d4bc72

Please sign in to comment.