From 6b93e332d4900d701af4693fd33d7f1fa4ed917f Mon Sep 17 00:00:00 2001 From: Namezero Date: Thu, 25 Sep 2014 20:26:22 +0000 Subject: [PATCH 1/2] Merged features from redmine_archive_issue_categories Merged features from redmine_archive_issue_categories (https://github.com/tofi86/redmine_archive_issue_categories) --- .../issue_category_helper.rb | 60 +++++- app/views/issues/bulk_edit.html.erb | 198 ++++++++++++++++++ .../settings/_issue_categories.html.erb | 2 + assets/stylesheets/styles.css | 6 + config/locales/de.yml | 12 ++ config/locales/en.yml | 4 + config/locales/ru.yml | 4 + config/routes.rb | 9 + db/migrate/003_change_issue_categories.rb | 12 ++ init.rb | 2 +- .../issue_categories_controller_patch.rb | 54 +++++ .../patches/issues_controller_patch.rb | 3 + 12 files changed, 358 insertions(+), 8 deletions(-) create mode 100644 app/views/issues/bulk_edit.html.erb create mode 100644 assets/stylesheets/styles.css create mode 100644 config/locales/de.yml create mode 100644 db/migrate/003_change_issue_categories.rb diff --git a/app/views/helpers/redmine_category_tree/issue_category_helper.rb b/app/views/helpers/redmine_category_tree/issue_category_helper.rb index c0cc69a..a5c5736 100644 --- a/app/views/helpers/redmine_category_tree/issue_category_helper.rb +++ b/app/views/helpers/redmine_category_tree/issue_category_helper.rb @@ -2,7 +2,7 @@ module RedmineCategoryTree module IssueCategoryHelper def issue_category_tree_options_for_select(issue_categories, options={}) s = '' - issue_category_tree(issue_categories) do |category, level| + issue_category_tree(issue_categories, true) do |category, level| if category.nil? || category.id.nil? next end @@ -22,15 +22,61 @@ def issue_category_tree_options_for_select(issue_categories, options={}) if !options[:current].nil? && options[:current].id == category.id tag_options[:disabled] = 'disabled' end - - tag_options.merge!(yield(category)) if block_given? + + tag_options.merge!(yield(category)) if block_given? s << content_tag('option', name_prefix + h(category), tag_options) + end s.html_safe end - def issue_category_tree(issue_categories, &block) - IssueCategory.issue_category_tree(issue_categories, &block) + def issue_category_tree(issue_categories, ignore_disabled = false, &block) + + if ignore_disabled + + cats = [] + levels = [] + + cur_disabled_levels = [] + IssueCategory.issue_category_tree(issue_categories) do |category, level| + + # Child levels no longer matter if we moved up + while !cur_disabled_levels.empty? && cur_disabled_levels.last >= level + cur_disabled_levels.pop + end + + has_disabled_parent_cat = !cur_disabled_levels.empty? && cur_disabled_levels.min < level + disabled_at_current_level = !cur_disabled_levels.empty? && cur_disabled_levels.last == level + current_cat_disabled = category.archived || has_disabled_parent_cat + + # If archived here, current disabled level + if category.archived + cur_disabled_levels.push level + # Pop current level if reached again, but honor setting from parent for this one + elsif disabled_at_current_level + while !cur_disabled_levels.empty? && cur_disabled_levels.last == level + cur_disabled_levels.pop + end + end + + if !current_cat_disabled + cats.push category + levels.push level + end + + end + + if !cats.nil? + # How to make a normal for loop?? => for(int i = 0; i < cats.size(); ++i) { ... } ??? + len = cats.size - 1 + (0..len).each do |i| + yield cats[i], levels[i] + end + end + return cats + else + IssueCategory.issue_category_tree(issue_categories, &block) + end end def render_issue_category_tree_list(categories, includeOuterUL=false, &block) @@ -67,14 +113,14 @@ def render_issue_category_tree_list(categories, includeOuterUL=false, &block) end def render_issue_category_tree_context_menu_list(categories, includeOuterUL=false, &block) - categories = issue_category_tree(categories) { |cat, level| nil } + categories = issue_category_tree(categories, true) { |cat, level| nil } return '' if categories.size == 0 output = '' output << '