From 668a91c84792576ff9840a420efb229b38ab56d9 Mon Sep 17 00:00:00 2001 From: yzzy Date: Wed, 14 Feb 2018 16:16:01 +0500 Subject: [PATCH 1/8] Issue tags added to context menu --- app/helpers/tags_helper.rb | 15 ++++++++++----- app/views/issues/_tags_context_menu.html.erb | 10 ++++++++++ lib/redmine_tags/hooks/views_issues_hook.rb | 1 + .../patches/add_helpers_for_issue_tags_patch.rb | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 app/views/issues/_tags_context_menu.html.erb diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 7be6b1b..0b8692e 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -12,7 +12,8 @@ module TagsHelper # * open_only - Boolean. Whenever link to the filter with "open" issues # only limit. def render_tag_link(tag, options = {}) - use_colors = RedmineTags.settings[:issues_use_colors].to_i > 0 + use_colors = options[:use_colors] + use_colors = RedmineTags.settings[:issues_use_colors].to_i > 0 if use_colors.nil? if use_colors tag_bg_color = tag_color(tag) tag_fg_color = tag_fg_color(tag_bg_color) @@ -32,7 +33,7 @@ def render_tag_link(tag, options = {}) content << content_tag('span', "(#{ tag.count })", class: 'tag-count') end - style = if use_colors + style = if use_colors { class: 'tag-label-color', style: tag_style } else @@ -86,7 +87,7 @@ def render_tags_list(tags, options = {}) logger.warn "[redmine_tags] Unknown sorting option: <#{ sorting }>" tags.sort! {|a, b| a.name <=> b.name } end - if :list == style + if :list == style || :simple_list == style list_el, item_el = 'ul', 'li' elsif :simple_cloud == style list_el, item_el = 'div', 'span' @@ -104,8 +105,12 @@ def render_tags_list(tags, options = {}) style: (:simple_cloud == style ? 'font-size: 1em;' : '')) << ' '.html_safe end - content_tag list_el, content, class: 'tags', - style: (:simple_cloud == style ? 'text-align: left;' : '') + if :simple_list == style + content + else + content_tag list_el, content, class: 'tags', + style: (:simple_cloud == style ? 'text-align: left;' : '') + end end end diff --git a/app/views/issues/_tags_context_menu.html.erb b/app/views/issues/_tags_context_menu.html.erb new file mode 100644 index 0000000..622b425 --- /dev/null +++ b/app/views/issues/_tags_context_menu.html.erb @@ -0,0 +1,10 @@ +<% if @issue -%> +
  • + <%= l(:tags) %> + <% Rails.logger.info "Safe attributes: #{@safe_attrinutes}" %> + +
  • +<% end %> diff --git a/lib/redmine_tags/hooks/views_issues_hook.rb b/lib/redmine_tags/hooks/views_issues_hook.rb index 08dd916..d897bad 100755 --- a/lib/redmine_tags/hooks/views_issues_hook.rb +++ b/lib/redmine_tags/hooks/views_issues_hook.rb @@ -6,6 +6,7 @@ class ViewsIssuesHook < Redmine::Hook::ViewListener render_on :view_issues_sidebar_planning_bottom, partial: 'issues/tags_sidebar' render_on :view_issues_bulk_edit_details_bottom, partial: 'issues/bulk_edit_tags' render_on :view_layouts_base_html_head, partial: 'tags/header_assets' + render_on :view_issues_context_menu_end, partial: 'issues/tags_context_menu' end end end diff --git a/lib/redmine_tags/patches/add_helpers_for_issue_tags_patch.rb b/lib/redmine_tags/patches/add_helpers_for_issue_tags_patch.rb index 5fbed9f..9026d57 100644 --- a/lib/redmine_tags/patches/add_helpers_for_issue_tags_patch.rb +++ b/lib/redmine_tags/patches/add_helpers_for_issue_tags_patch.rb @@ -13,6 +13,7 @@ def self.included(base) bases = [ IssuesController, + ContextMenusController, CalendarsController, GanttsController, SettingsController From e661a528aecd45a9ae06e8fa19d46fa2c2b0bc16 Mon Sep 17 00:00:00 2001 From: yzzy Date: Fri, 16 Feb 2018 21:54:18 +0500 Subject: [PATCH 2/8] Ajax modal window for adding tags --- app/controllers/tags_controller.rb | 31 ++++++++++++++++++++ app/helpers/issues_tags_helper.rb | 8 +++++ app/views/issues/_tags_context_menu.html.erb | 3 +- app/views/tags/_tagging_issue.html.erb | 28 ++++++++++++++++++ app/views/tags/tagging_issue.js.erb | 3 ++ config/routes.rb | 2 ++ 6 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 app/views/tags/_tagging_issue.html.erb create mode 100644 app/views/tags/tagging_issue.js.erb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 86c650e..737a3f8 100755 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -54,6 +54,37 @@ def merge end end + def tagging_issue + Rails.logger.info "Tagging issue params: #{params}" + if params[:object_type] && params[:object_id] + klass = Object.const_get(params[:object_type].camelcase) rescue nil + return unless klass && klass.respond_to?('available_tags') + scope = klass.where(:id => Array.wrap(params[:object_id])) + if klass.reflect_on_association(:project) + scope = scope.preload(:project => :enabled_modules) + end + objects = scope.to_a + @issue = objects.first + @issue_tags = @issue.tags + @available_tags = klass.available_tags - @issue_tags + @project = @issue.project + case request.method_symbol + when :get + render layout: false + when :post + tag_ids = [] + if params[:tagged] + tag_ids << (params[:tagged][:tag_ids] || params[:tagged][:tag_id]) + else + tag_ids << params[:tag_id] + end + tags = ActsAsTaggableOn::Tag.where(id: tag_ids).all + @issue.tag_list << tags + @issue.save + end + end + end + private def bulk_find_tags diff --git a/app/helpers/issues_tags_helper.rb b/app/helpers/issues_tags_helper.rb index 98d7e9c..e0b792d 100644 --- a/app/helpers/issues_tags_helper.rb +++ b/app/helpers/issues_tags_helper.rb @@ -16,4 +16,12 @@ def render_sidebar_tags open_only: (RedmineTags.settings[:issues_open_only].to_i == 1), style: RedmineTags.settings[:issues_sidebar].to_sym } end + + def issue_tags_check_box_tags(name, issue_tags) + s = "" + issue_tags.each do |issue_tag| + s << "\n" + end + s.html_safe + end end diff --git a/app/views/issues/_tags_context_menu.html.erb b/app/views/issues/_tags_context_menu.html.erb index 622b425..b71484c 100644 --- a/app/views/issues/_tags_context_menu.html.erb +++ b/app/views/issues/_tags_context_menu.html.erb @@ -1,10 +1,9 @@ <% if @issue -%>
  • <%= l(:tags) %> - <% Rails.logger.info "Safe attributes: #{@safe_attrinutes}" %>
      <%= render_tags_list @issue.tags, :style => :simple_list, :use_colors => false %> -
    • <%= context_menu_link l(:button_add), new_watchers_path(:object_type => 'issue', :object_id => @issue.id), :remote => true, :class => 'icon-add' %>
    • +
    • <%= context_menu_link l(:button_add), tagging_issue_path(:object_type => 'issue', :object_id => @issue.id), :remote => true, :class => 'icon-add' %>
  • <% end %> diff --git a/app/views/tags/_tagging_issue.html.erb b/app/views/tags/_tagging_issue.html.erb new file mode 100644 index 0000000..dc491e9 --- /dev/null +++ b/app/views/tags/_tagging_issue.html.erb @@ -0,0 +1,28 @@ +

    <%= l(:issue_tags_manage_tags) %>

    + +<%= form_tag(tagging_issue_path, + :remote => true, + :method => :post, + :id => 'tagging-issue-form') do %> + + <% if issue.present? %> + <%= hidden_field_tag 'object_type', issue.class.name.underscore %> + <%= hidden_field_tag 'object_id[]', issue.id %> + <% end %> + <%= hidden_field_tag 'project_id', @project.id if @project %> + +

    <%= label_tag 'tag_search', l(:label_user_search) %><%= text_field_tag 'tag_search', nil %>

    + <%= javascript_tag "observeSearchfield('tag_search', 'issue_tags', '#{ escape_javascript auto_complete_issue_tags_path( + :object_type => (issue.present? ? issue.class.name.underscore : nil), + :object_id => (issue.present? ? issue.id : nil), + :project_id => @project) }')" %> + +
    + <%= issue_tags_check_box_tags('tagged[tag_ids][]', available_tags) %> +
    + +

    + <%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %> + <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %> +

    +<% end %> diff --git a/app/views/tags/tagging_issue.js.erb b/app/views/tags/tagging_issue.js.erb new file mode 100644 index 0000000..f9b9ad1 --- /dev/null +++ b/app/views/tags/tagging_issue.js.erb @@ -0,0 +1,3 @@ +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'tags/tagging_issue', :locals => {:issue => @issue, :issue_tags => @issue_tags, :available_tags => @available_tags, :project => @project}) %>'); +showModal('ajax-modal', '400px'); +$('#ajax-modal').addClass('new-watcher'); diff --git a/config/routes.rb b/config/routes.rb index bfae960..f8a8f38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,3 +12,5 @@ get :context_menu, :merge end end + +match '/tags/tagging_issue', to: 'tags#tagging_issue', as: 'tagging_issue', via: [:get, :post] From dbc13ba6fef32bf56763c1b012fb1bf8013c8406 Mon Sep 17 00:00:00 2001 From: yzzy Date: Wed, 28 Feb 2018 16:58:14 +0500 Subject: [PATCH 3/8] Marking tags for adding with checkboxes --- app/controllers/tags_controller.rb | 7 ++++--- app/helpers/issues_tags_helper.rb | 8 -------- app/helpers/tags_helper.rb | 12 ++++++++++++ .../_tag_list_with_checkboxes.html.erb | 1 + app/views/tags/_tagging_issue.html.erb | 19 ++++++++++--------- config/locales/en.yml | 1 + .../auto_completes_controller_patch.rb | 5 ++++- 7 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 app/views/auto_completes/_tag_list_with_checkboxes.html.erb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 737a3f8..24caeba 100755 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -55,7 +55,6 @@ def merge end def tagging_issue - Rails.logger.info "Tagging issue params: #{params}" if params[:object_type] && params[:object_id] klass = Object.const_get(params[:object_type].camelcase) rescue nil return unless klass && klass.respond_to?('available_tags') @@ -70,7 +69,9 @@ def tagging_issue @project = @issue.project case request.method_symbol when :get - render layout: false + respond_to do |format| + format.js { render layout: false } + end when :post tag_ids = [] if params[:tagged] @@ -78,7 +79,7 @@ def tagging_issue else tag_ids << params[:tag_id] end - tags = ActsAsTaggableOn::Tag.where(id: tag_ids).all + tags = ActsAsTaggableOn::Tag.where(id: tag_ids.flatten).all @issue.tag_list << tags @issue.save end diff --git a/app/helpers/issues_tags_helper.rb b/app/helpers/issues_tags_helper.rb index e0b792d..98d7e9c 100644 --- a/app/helpers/issues_tags_helper.rb +++ b/app/helpers/issues_tags_helper.rb @@ -16,12 +16,4 @@ def render_sidebar_tags open_only: (RedmineTags.settings[:issues_open_only].to_i == 1), style: RedmineTags.settings[:issues_sidebar].to_sym } end - - def issue_tags_check_box_tags(name, issue_tags) - s = "" - issue_tags.each do |issue_tag| - s << "\n" - end - s.html_safe - end end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 0b8692e..a5b5fd0 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -32,6 +32,10 @@ def render_tag_link(tag, options = {}) if options[:show_count] content << content_tag('span', "(#{ tag.count })", class: 'tag-count') end + if options[:show_checkbox] + id_name = options[:id_name] || tag.name + content = check_box_tag(id_name, tag.id, options[:checked] || false, id: nil) + content + end style = if use_colors { class: 'tag-label-color', @@ -114,6 +118,14 @@ def render_tags_list(tags, options = {}) end end + def render_tags_list_with_checkboxes(name, tags) + s = "" + tags.each do |tag| + s << content_tag('label', render_tag_link(tag, show_count: false, open_only: false, show_checkbox: true, checked: false, id_name: name)) + end + s.html_safe + end + private # make snowball. first tags comes in th middle. diff --git a/app/views/auto_completes/_tag_list_with_checkboxes.html.erb b/app/views/auto_completes/_tag_list_with_checkboxes.html.erb new file mode 100644 index 0000000..fc9d70b --- /dev/null +++ b/app/views/auto_completes/_tag_list_with_checkboxes.html.erb @@ -0,0 +1 @@ +<%= render_tags_list_with_checkboxes('tagged[tag_ids][]', tags) %> diff --git a/app/views/tags/_tagging_issue.html.erb b/app/views/tags/_tagging_issue.html.erb index dc491e9..4faf413 100644 --- a/app/views/tags/_tagging_issue.html.erb +++ b/app/views/tags/_tagging_issue.html.erb @@ -1,9 +1,6 @@

    <%= l(:issue_tags_manage_tags) %>

    -<%= form_tag(tagging_issue_path, - :remote => true, - :method => :post, - :id => 'tagging-issue-form') do %> +<%= form_tag(tagging_issue_path, remote: true, id: 'tagging-issue-form') do %> <% if issue.present? %> <%= hidden_field_tag 'object_type', issue.class.name.underscore %> @@ -11,14 +8,18 @@ <% end %> <%= hidden_field_tag 'project_id', @project.id if @project %> -

    <%= label_tag 'tag_search', l(:label_user_search) %><%= text_field_tag 'tag_search', nil %>

    - <%= javascript_tag "observeSearchfield('tag_search', 'issue_tags', '#{ escape_javascript auto_complete_issue_tags_path( +
    + <%= safe_join(issue.tag_counts.collect {|t| render_tag_link(t, show_count: false, open_only: false) }, RedmineTags.settings[:issues_use_colors].to_i > 0 ? ' ' : ', ') %> +
    +

    <%= label_tag 'tag_search', l(:issue_tags_label_search) %><%= text_field_tag 'tag_search', nil %>

    + <%= javascript_tag "observeSearchfield('tag_search', 'available_tags', '#{ escape_javascript auto_complete_issue_tags_path( :object_type => (issue.present? ? issue.class.name.underscore : nil), :object_id => (issue.present? ? issue.id : nil), - :project_id => @project) }')" %> + :project_id => @project, + :partial => :tag_list_with_checkboxes) }')" %> -
    - <%= issue_tags_check_box_tags('tagged[tag_ids][]', available_tags) %> +
    + <%= render partial: 'auto_completes/tag_list_with_checkboxes', locals: {tags: available_tags} %>

    diff --git a/config/locales/en.yml b/config/locales/en.yml index 2e3eace..ea4f4e3 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -26,3 +26,4 @@ en: issue_tags_tag: Tag issue_tags_button_merge: Merge issue_tags_label_merge: Merge selected tags + issue_tags_label_search: Search for tag diff --git a/lib/redmine_tags/patches/auto_completes_controller_patch.rb b/lib/redmine_tags/patches/auto_completes_controller_patch.rb index 3222030..e87002d 100644 --- a/lib/redmine_tags/patches/auto_completes_controller_patch.rb +++ b/lib/redmine_tags/patches/auto_completes_controller_patch.rb @@ -2,6 +2,9 @@ module RedmineTags module Patches module AutoCompletesControllerPatch def self.included(base) + base.class_eval do + helper TagsHelper + end base.send :include, InstanceMethods end @@ -9,7 +12,7 @@ module InstanceMethods def issue_tags @name = params[:q].to_s @tags = Issue.available_tags project: @project, name_like: @name - render layout: false, partial: 'tag_list' + render layout: false, partial: params[:partial] || 'tag_list', locals: {tags: @tags} end def wiki_tags From 39b8e6a4701106264914533897fec14d82fad1b8 Mon Sep 17 00:00:00 2001 From: yzzy Date: Thu, 1 Mar 2018 16:06:43 +0500 Subject: [PATCH 4/8] Closing ajax window after adding tags --- app/controllers/tags_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 24caeba..cda2b27 100755 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -82,6 +82,7 @@ def tagging_issue tags = ActsAsTaggableOn::Tag.where(id: tag_ids.flatten).all @issue.tag_list << tags @issue.save + render nothing: true, status: ok end end end From bf7115706b848577c2b4041d02f1ea46d0bc4349 Mon Sep 17 00:00:00 2001 From: yzzy Date: Fri, 2 Mar 2018 17:50:38 +0500 Subject: [PATCH 5/8] Writing changes to issue's journal --- app/controllers/tags_controller.rb | 23 +++++++++-------------- app/views/tags/_tagging_issue.html.erb | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index cda2b27..e50dd31 100755 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -55,17 +55,9 @@ def merge end def tagging_issue - if params[:object_type] && params[:object_id] - klass = Object.const_get(params[:object_type].camelcase) rescue nil - return unless klass && klass.respond_to?('available_tags') - scope = klass.where(:id => Array.wrap(params[:object_id])) - if klass.reflect_on_association(:project) - scope = scope.preload(:project => :enabled_modules) - end - objects = scope.to_a - @issue = objects.first + if params[:object_type] == 'issue' && params[:object_id] && @issue = Issue.find_by(id: params[:object_id]) @issue_tags = @issue.tags - @available_tags = klass.available_tags - @issue_tags + @available_tags = Issue.available_tags - @issue_tags @project = @issue.project case request.method_symbol when :get @@ -79,10 +71,13 @@ def tagging_issue else tag_ids << params[:tag_id] end - tags = ActsAsTaggableOn::Tag.where(id: tag_ids.flatten).all - @issue.tag_list << tags - @issue.save - render nothing: true, status: ok + tags = @issue.tag_list + ActsAsTaggableOn::Tag.where(id: tag_ids.flatten).all + tags_context = { issue: @issue, params: {} } + tags_context[:params].store :issue, { tag_list: tags } + @issue.init_journal(User.current) + RedmineTags::Hooks::ModelIssueHook.instance.save_tags_to_issue tags_context, true + @issue.current_journal.save + render nothing: true, status: :ok end end end diff --git a/app/views/tags/_tagging_issue.html.erb b/app/views/tags/_tagging_issue.html.erb index 4faf413..1b2ad6e 100644 --- a/app/views/tags/_tagging_issue.html.erb +++ b/app/views/tags/_tagging_issue.html.erb @@ -4,7 +4,7 @@ <% if issue.present? %> <%= hidden_field_tag 'object_type', issue.class.name.underscore %> - <%= hidden_field_tag 'object_id[]', issue.id %> + <%= hidden_field_tag 'object_id', issue.id %> <% end %> <%= hidden_field_tag 'project_id', @project.id if @project %> From 0eb5cae3247d85c489761bcb4e2ef4cd45933984 Mon Sep 17 00:00:00 2001 From: yzzy Date: Tue, 6 Mar 2018 14:08:35 +0500 Subject: [PATCH 6/8] Using delegate for save_tags_to_issue --- app/controllers/tags_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index e50dd31..9639d0a 100755 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -5,6 +5,8 @@ class TagsController < ApplicationController helper :issues_tags + delegate :save_tags_to_issue, to: "RedmineTags::Hooks::ModelIssueHook.instance" + def edit; end def destroy @@ -75,7 +77,7 @@ def tagging_issue tags_context = { issue: @issue, params: {} } tags_context[:params].store :issue, { tag_list: tags } @issue.init_journal(User.current) - RedmineTags::Hooks::ModelIssueHook.instance.save_tags_to_issue tags_context, true + save_tags_to_issue tags_context, true @issue.current_journal.save render nothing: true, status: :ok end From b41413062a76b4399572f0b9bc71ed2958fdf2f7 Mon Sep 17 00:00:00 2001 From: yzzy Date: Tue, 6 Mar 2018 15:52:14 +0500 Subject: [PATCH 7/8] Issue tags excluded from available set when filtering in modal window --- lib/redmine_tags/patches/auto_completes_controller_patch.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/redmine_tags/patches/auto_completes_controller_patch.rb b/lib/redmine_tags/patches/auto_completes_controller_patch.rb index e87002d..1b8f46c 100644 --- a/lib/redmine_tags/patches/auto_completes_controller_patch.rb +++ b/lib/redmine_tags/patches/auto_completes_controller_patch.rb @@ -12,6 +12,9 @@ module InstanceMethods def issue_tags @name = params[:q].to_s @tags = Issue.available_tags project: @project, name_like: @name + if params[:object_type] == 'issue' && params[:object_id] && issue = Issue.find_by(id: params[:object_id]) + @tags -= issue.tags + end render layout: false, partial: params[:partial] || 'tag_list', locals: {tags: @tags} end From 6785b9036ed574b44b26a7bf7ae5a6e9735bb10f Mon Sep 17 00:00:00 2001 From: yzzy Date: Sat, 24 Mar 2018 19:14:47 +0500 Subject: [PATCH 8/8] Full-scale modifying issue's tags --- app/controllers/tags_controller.rb | 3 ++- app/helpers/tags_helper.rb | 27 +++++++++---------- .../_tag_list_with_checkboxes.html.erb | 3 ++- app/views/issues/_tags_context_menu.html.erb | 3 +-- app/views/tags/_tagging_issue.html.erb | 4 +-- app/views/tags/tagging_issue.js.erb | 2 +- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 9639d0a..d0da263 100755 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -59,6 +59,7 @@ def merge def tagging_issue if params[:object_type] == 'issue' && params[:object_id] && @issue = Issue.find_by(id: params[:object_id]) @issue_tags = @issue.tags + @checked = {}; @issue_tags.each { |tag| @checked[tag.name] = true } @available_tags = Issue.available_tags - @issue_tags @project = @issue.project case request.method_symbol @@ -73,7 +74,7 @@ def tagging_issue else tag_ids << params[:tag_id] end - tags = @issue.tag_list + ActsAsTaggableOn::Tag.where(id: tag_ids.flatten).all + tags = ActsAsTaggableOn::Tag.where(id: tag_ids.flatten).all tags_context = { issue: @issue, params: {} } tags_context[:params].store :issue, { tag_list: tags } @issue.init_journal(User.current) diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index a5b5fd0..31958b3 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -11,6 +11,8 @@ module TagsHelper # * show_count - Boolean. Whenever show tag counts # * open_only - Boolean. Whenever link to the filter with "open" issues # only limit. + # * with_checkbox - Boolean. Renders tag as checkbox considering additional + # "checked" option def render_tag_link(tag, options = {}) use_colors = options[:use_colors] use_colors = RedmineTags.settings[:issues_use_colors].to_i > 0 if use_colors.nil? @@ -26,15 +28,15 @@ def render_tag_link(tag, options = {}) content = link_to tag, { controller: 'search', action: 'index', id: @project, q: tag.name, wiki_pages: true, issues: true, style: tag_style } + elsif options[:with_checkbox] + id_name = options[:id_name] || tag.name + with_tick = options[:checked] || {} + content = check_box_tag(id_name, tag.id, with_tick[tag.name] || false, id: nil, project_id: @project) + tag.name else content = link_to_filter tag.name, filters, project_id: @project end if options[:show_count] - content << content_tag('span', "(#{ tag.count })", class: 'tag-count') - end - if options[:show_checkbox] - id_name = options[:id_name] || tag.name - content = check_box_tag(id_name, tag.id, options[:checked] || false, id: nil) + content + content << content_tag('span', "(#{ tag.count })", class: 'tag-count', style: tag_style) end style = if use_colors @@ -70,7 +72,7 @@ def tag_fg_color(bg_color) # * show_count - Boolean. Whenever show tag counts # * open_only - Boolean. Whenever link to the filter with "open" issues # only limit. - # * style - list, cloud + # * style - list, cloud, simple_list, simple_cloud, with_checkbox def render_tags_list(tags, options = {}) unless tags.nil? or tags.empty? content, style = '', options.delete(:style) @@ -98,6 +100,9 @@ def render_tags_list(tags, options = {}) elsif :cloud == style list_el, item_el = 'div', 'span' tags = cloudify tags + elsif :with_checkbox == style + list_el, item_el = 'div', 'label' + options[:with_checkbox] = true else raise 'Unknown list style' end @@ -109,7 +114,7 @@ def render_tags_list(tags, options = {}) style: (:simple_cloud == style ? 'font-size: 1em;' : '')) << ' '.html_safe end - if :simple_list == style + if :simple_list == style || :with_checkbox == style content else content_tag list_el, content, class: 'tags', @@ -118,14 +123,6 @@ def render_tags_list(tags, options = {}) end end - def render_tags_list_with_checkboxes(name, tags) - s = "" - tags.each do |tag| - s << content_tag('label', render_tag_link(tag, show_count: false, open_only: false, show_checkbox: true, checked: false, id_name: name)) - end - s.html_safe - end - private # make snowball. first tags comes in th middle. diff --git a/app/views/auto_completes/_tag_list_with_checkboxes.html.erb b/app/views/auto_completes/_tag_list_with_checkboxes.html.erb index fc9d70b..55d10c9 100644 --- a/app/views/auto_completes/_tag_list_with_checkboxes.html.erb +++ b/app/views/auto_completes/_tag_list_with_checkboxes.html.erb @@ -1 +1,2 @@ -<%= render_tags_list_with_checkboxes('tagged[tag_ids][]', tags) %> +<% checked = local_assigns.fetch :checked, {} %> +<%= render_tags_list(tags, style: :with_checkbox, id_name: 'tagged[tag_ids][]', checked: checked) %> diff --git a/app/views/issues/_tags_context_menu.html.erb b/app/views/issues/_tags_context_menu.html.erb index b71484c..edce0b0 100644 --- a/app/views/issues/_tags_context_menu.html.erb +++ b/app/views/issues/_tags_context_menu.html.erb @@ -2,8 +2,7 @@

  • <%= l(:tags) %>
      - <%= render_tags_list @issue.tags, :style => :simple_list, :use_colors => false %> -
    • <%= context_menu_link l(:button_add), tagging_issue_path(:object_type => 'issue', :object_id => @issue.id), :remote => true, :class => 'icon-add' %>
    • +
    • <%= context_menu_link l(:button_edit), tagging_issue_path(:object_type => 'issue', :object_id => @issue.id), :remote => true, :class => 'icon-edit' %>
  • <% end %> diff --git a/app/views/tags/_tagging_issue.html.erb b/app/views/tags/_tagging_issue.html.erb index 1b2ad6e..6cb9b89 100644 --- a/app/views/tags/_tagging_issue.html.erb +++ b/app/views/tags/_tagging_issue.html.erb @@ -9,7 +9,7 @@ <%= hidden_field_tag 'project_id', @project.id if @project %>
    - <%= safe_join(issue.tag_counts.collect {|t| render_tag_link(t, show_count: false, open_only: false) }, RedmineTags.settings[:issues_use_colors].to_i > 0 ? ' ' : ', ') %> + <%= render partial: 'auto_completes/tag_list_with_checkboxes', locals: {tags: issue_tags, checked: checked} %>

    <%= label_tag 'tag_search', l(:issue_tags_label_search) %><%= text_field_tag 'tag_search', nil %>

    <%= javascript_tag "observeSearchfield('tag_search', 'available_tags', '#{ escape_javascript auto_complete_issue_tags_path( @@ -23,7 +23,7 @@

    - <%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %> + <%= submit_tag l(:button_change), :name => nil, :onclick => "hideModal(this);" %> <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>

    <% end %> diff --git a/app/views/tags/tagging_issue.js.erb b/app/views/tags/tagging_issue.js.erb index f9b9ad1..f95859a 100644 --- a/app/views/tags/tagging_issue.js.erb +++ b/app/views/tags/tagging_issue.js.erb @@ -1,3 +1,3 @@ -$('#ajax-modal').html('<%= escape_javascript(render :partial => 'tags/tagging_issue', :locals => {:issue => @issue, :issue_tags => @issue_tags, :available_tags => @available_tags, :project => @project}) %>'); +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'tags/tagging_issue', :locals => {:issue => @issue, :issue_tags => @issue_tags, :checked => @checked, :available_tags => @available_tags, :project => @project}) %>'); showModal('ajax-modal', '400px'); $('#ajax-modal').addClass('new-watcher');