Skip to content

Commit

Permalink
New issue, issue edit, bulk issue edit tagcloud. New UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nettsundere committed Dec 5, 2012
1 parent c5a1a54 commit 529787d
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 68 deletions.
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -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 = {}

Expand Down
10 changes: 7 additions & 3 deletions app/views/tagging/_issue_tagcloud.erb
@@ -1,9 +1,13 @@
<a id="cloud_trigger"><%= t(:tags_in_project) %></a>
<a id="cloud_trigger"><b><%= t(:tags_in_project) %></b></a>
<span id="cloud_content"> &mdash;
<%
tag_cloud_in_project(@project) do |tag, factor|
options = {:style => "font-size: #{10 * factor + 9}pt" }
style = "font-size: #{10 * factor + 9}pt"
%>
<%= link_to_project_tag_filter(@project, tag, {}, options) %>
<a class="tag_item"
data-tag="<%= tag_without_sharp(tag) %>"
style="<%= style %>">
<%= tag %>
</a>
<% end %>
</span>
103 changes: 103 additions & 0 deletions assets/javascripts/toggle_tags.js
@@ -0,0 +1,103 @@
// 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) == -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)

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]+/)
return $.grep(dirty_items, function(val, i){
return (val.length > 0)
})
}
})(jQuery)
17 changes: 0 additions & 17 deletions assets/javascripts/toggle_visibility.js

This file was deleted.

31 changes: 31 additions & 0 deletions assets/stylesheets/tagging.css
@@ -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;
}
72 changes: 24 additions & 48 deletions lib/tagging_plugin/tagging_hooks.rb
@@ -1,38 +1,13 @@
module TaggingPlugin
module Hooks
class LayoutHook < Redmine::Hook::ViewListener
def view_issues_new_top(context={})
return '' if Setting.plugin_redmine_tagging[:sidebar_tagcloud] != "1"

cloud = context[:controller].send(:render_to_string, {
:partial => 'tagging/issue_tagcloud',
:locals => context
})

result = <<-TAGS
#{javascript_include_tag 'jquery_loader', :plugin => 'redmine_tagging'}
#{javascript_include_tag 'toggle_visibility', :plugin => 'redmine_tagging'}
<script type="text/javascript">
var $j = jQuery.noConflict()
$j(function() {
var tags_container = $j('#issue_tags').parent()
var cloud = $j("<div>#{escape_javascript(cloud)}</div>")
$j(tags_container).append(cloud)
$j('#cloud_content').toggleVisibilityVia($j('#cloud_trigger'))
})
</script>
TAGS

return result
end

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={})
Expand All @@ -41,11 +16,18 @@ def view_wiki_sidebar_bottom(context={})
return context[:controller].send(:render_to_string, {
:partial => 'tagging/tagcloud_search',
:locals => context
})
})
end

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, {
Expand All @@ -58,34 +40,18 @@ def view_layouts_base_html_head(context={})
sidebar_tags = ''
end

result = <<-TAGS
<<-TAGS
#{tagging_stylesheet}
#{javascript_include_tag 'jquery_loader', :plugin => 'redmine_tagging'}
#{javascript_include_tag 'toggle_visibility', :plugin => 'redmine_tagging'}
#{javascript_include_tag 'toggle_tags', :plugin => 'redmine_tagging'}
<script type="text/javascript">
var $j = jQuery.noConflict()
$j(function() {
#{sidebar_tags}
$j('#cloud_content').toggleVisibilityVia($j('#cloud_trigger'))
$j('#cloud_content').toggleCloudViaFor($j('#cloud_trigger'), $j('#issue_tags'))
})
</script>
TAGS

<<-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
end

def view_issues_show_details_bottom(context={})
Expand Down Expand Up @@ -114,6 +80,12 @@ def view_issues_form_details_bottom(context={})
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
Expand All @@ -124,6 +96,11 @@ def view_issues_form_details_bottom(context={})
var $j = jQuery.noConflict()
$j(document).ready(function() {
$j('#issue_tags').tagSuggest({ tags: [#{ac}] })
var tags_container = $j('#issue_tags').parent()
var cloud = $j("<div>#{escape_javascript(cloud)}</div>")
$j(tags_container).append(cloud)
$j('#cloud_content').toggleCloudViaFor($j('#cloud_trigger'), $j('#issue_tags'))
})
</script>
generatedscript
Expand Down Expand Up @@ -260,7 +237,6 @@ def view_reports_issue_report_split_content_right(context={})
report += "<br/>"
return report
end

end
end
end

0 comments on commit 529787d

Please sign in to comment.