To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / plugins / redmine_tags / lib / redmine_tags / patches / project_patch.rb @ 739:b7ac21913927

History | View | Annotate | Download (2.89 KB)

1 727:e3e958595e07 luis
# C4DM
2
3
require_dependency 'project'
4
5
module RedmineTags
6
  module Patches
7
    module ProjectPatch
8 729:291c4d7dc0b6 luis
      def self.included(base) # :nodoc:
9 727:e3e958595e07 luis
        base.extend(ClassMethods)
10 730:4a9bb3b8d5cd luis
        base.send(:include, InstanceMethods)
11 727:e3e958595e07 luis
12
        base.class_eval do
13
          unloadable
14 730:4a9bb3b8d5cd luis
15
          attr_accessor :tag_list
16
17 727:e3e958595e07 luis
          acts_as_taggable
18 730:4a9bb3b8d5cd luis
19 727:e3e958595e07 luis
        end
20
      end
21
22 730:4a9bb3b8d5cd luis
      def before_save_with_save_tags()
23
#        debugger
24
        logger.error { "GONNA SAVE TAG LIST" }
25 729:291c4d7dc0b6 luis
26 730:4a9bb3b8d5cd luis
27
#        params[:tag_list]
28
29
30
        # logger.error { @project.name }
31 729:291c4d7dc0b6 luis
32
    #    if params && params[:project] && !params[:project][:tag_list].nil?
33
    #      old_tags = context[:project].tag_list.to_s
34
    #      context[:project].tag_list = params[:project][:tag_list]
35
    #      new_tags = context[:project].tag_list.to_s
36
    #
37
    #      unless (old_tags == new_tags || context[:project].current_journal.blank?)
38
    #        context[:project].current_journal.details << JournalDetail.new(:property => 'attr',
39
    #                                                                     :prop_key => 'tag_list',
40
    #                                                                     :old_value => old_tags,
41
    #                                                                     :value => new_tags)
42
    #      end
43
    #    end
44
      end
45
46 730:4a9bb3b8d5cd luis
      module InstanceMethods
47
48
      end
49 729:291c4d7dc0b6 luis
50 727:e3e958595e07 luis
      module ClassMethods
51 739:b7ac21913927 luis
52
53
        def search_by_question(question)
54
          if question.length > 1
55
            search(RedmineProjectFiltering.calculate_tokens(question), nil, :all_words => true).first.sort_by(&:lft)
56
          else
57
            all(:order => 'lft')
58
          end
59
        end
60
61
62 727:e3e958595e07 luis
        # Returns available issue tags
63
        # === Parameters
64
        # * <i>options</i> = (optional) Options hash of
65
        #   * project   - Project to search in.
66
        #   * open_only - Boolean. Whenever search within open issues only.
67
        #   * name_like - String. Substring to filter found tags.
68
        def available_tags(options = {})
69
          project   = options[:project]
70
          open_only = options[:open_only]
71
          name_like = options[:name_like]
72
          options   = {}
73
          visible   = ARCondition.new
74
75
          if project
76
            project = project.id if project.is_a? Project
77
            visible << ["#{Issue.table_name}.project_id = ?", project]
78
          end
79
80
          if open_only
81 729:291c4d7dc0b6 luis
            visible << ["#{Project.table_name}.status_id IN " +
82 727:e3e958595e07 luis
                        "( SELECT issue_status.id " +
83
                        "    FROM #{IssueStatus.table_name} issue_status " +
84
                        "   WHERE issue_status.is_closed = ? )", false]
85
          end
86
87
          if name_like
88
            visible << ["#{ActsAsTaggableOn::Tag.table_name}.name LIKE ?", "%#{name_like.downcase}%"]
89
          end
90
91
          options[:conditions] = visible.conditions
92
          self.all_tag_counts(options)
93
        end
94
      end
95
    end
96
  end
97
end