##// END OF EJS Templates
Unlimited and optional project description. The project list will show truncated descriptions only (the first fews lines)....
Jean-Philippe Lang -
r1074:df99d8f30801
parent child
Show More
@@ -0,0 +1,8
1 class ChangeProjectsDescriptionToText < ActiveRecord::Migration
2 def self.up
3 change_column :projects, :description, :text, :default => ''
4 end
5
6 def self.down
7 end
8 end
@@ -1,225 +1,233
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Project < ActiveRecord::Base
19 19 # Project statuses
20 20 STATUS_ACTIVE = 1
21 21 STATUS_ARCHIVED = 9
22 22
23 23 has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
24 24 has_many :users, :through => :members
25 25 has_many :custom_values, :dependent => :delete_all, :as => :customized
26 26 has_many :enabled_modules, :dependent => :delete_all
27 27 has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
28 28 has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
29 29 has_many :issue_changes, :through => :issues, :source => :journals
30 30 has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
31 31 has_many :time_entries, :dependent => :delete_all
32 32 has_many :queries, :dependent => :delete_all
33 33 has_many :documents, :dependent => :destroy
34 34 has_many :news, :dependent => :delete_all, :include => :author
35 35 has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
36 36 has_many :boards, :order => "position ASC"
37 37 has_one :repository, :dependent => :destroy
38 38 has_many :changesets, :through => :repository
39 39 has_one :wiki, :dependent => :destroy
40 40 # Custom field for the project issues
41 41 has_and_belongs_to_many :custom_fields,
42 42 :class_name => 'IssueCustomField',
43 43 :order => "#{CustomField.table_name}.position",
44 44 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
45 45 :association_foreign_key => 'custom_field_id'
46 46
47 47 acts_as_tree :order => "name", :counter_cache => true
48 48
49 49 acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
50 50 acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
51 51 :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}}
52 52
53 53 attr_protected :status, :enabled_module_names
54 54
55 validates_presence_of :name, :description, :identifier
55 validates_presence_of :name, :identifier
56 56 validates_uniqueness_of :name, :identifier
57 57 validates_associated :custom_values, :on => :update
58 58 validates_associated :repository, :wiki
59 59 validates_length_of :name, :maximum => 30
60 validates_length_of :description, :maximum => 255
61 60 validates_length_of :homepage, :maximum => 60
62 61 validates_length_of :identifier, :in => 3..20
63 62 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
64 63
65 64 before_destroy :delete_all_members
66 65
67 66 def identifier=(identifier)
68 67 super unless identifier_frozen?
69 68 end
70 69
71 70 def identifier_frozen?
72 71 errors[:identifier].nil? && !(new_record? || identifier.blank?)
73 72 end
74 73
75 74 def issues_with_subprojects(include_subprojects=false)
76 75 conditions = nil
77 76 if include_subprojects && !active_children.empty?
78 77 ids = [id] + active_children.collect {|c| c.id}
79 78 conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"]
80 79 end
81 80 conditions ||= ["#{Issue.table_name}.project_id = ?", id]
82 81 # Quick and dirty fix for Rails 2 compatibility
83 82 Issue.send(:with_scope, :find => { :conditions => conditions }) do
84 83 yield
85 84 end
86 85 end
87 86
88 87 # Return all issues status changes for the project between the 2 given dates
89 88 def issues_status_changes(from, to)
90 89 Journal.find(:all, :include => [:issue, :details, :user],
91 90 :conditions => ["#{Journal.table_name}.journalized_type = 'Issue'" +
92 91 " AND #{Issue.table_name}.project_id = ?" +
93 92 " AND #{JournalDetail.table_name}.prop_key = 'status_id'" +
94 93 " AND #{Journal.table_name}.created_on BETWEEN ? AND ?",
95 94 id, from, to+1])
96 95 end
97 96
98 97 # returns latest created projects
99 98 # non public projects will be returned only if user is a member of those
100 99 def self.latest(user=nil, count=5)
101 100 find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
102 101 end
103 102
104 103 def self.visible_by(user=nil)
105 104 if user && user.admin?
106 105 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
107 106 elsif user && user.memberships.any?
108 107 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
109 108 else
110 109 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}"
111 110 end
112 111 end
113 112
114 113 def self.find(*args)
115 114 if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
116 115 project = find_by_identifier(*args)
117 116 raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil?
118 117 project
119 118 else
120 119 super
121 120 end
122 121 end
123 122
124 123 def to_param
125 124 identifier
126 125 end
127 126
128 127 def active?
129 128 self.status == STATUS_ACTIVE
130 129 end
131 130
132 131 def archive
133 132 # Archive subprojects if any
134 133 children.each do |subproject|
135 134 subproject.archive
136 135 end
137 136 update_attribute :status, STATUS_ARCHIVED
138 137 end
139 138
140 139 def unarchive
141 140 return false if parent && !parent.active?
142 141 update_attribute :status, STATUS_ACTIVE
143 142 end
144 143
145 144 def active_children
146 145 children.select {|child| child.active?}
147 146 end
148 147
149 148 # Returns an array of the trackers used by the project and its sub projects
150 149 def rolled_up_trackers
151 150 @rolled_up_trackers ||=
152 151 Tracker.find(:all, :include => :projects,
153 152 :select => "DISTINCT #{Tracker.table_name}.*",
154 153 :conditions => ["#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?", id, id],
155 154 :order => "#{Tracker.table_name}.position")
156 155 end
157 156
158 157 # Deletes all project's members
159 158 def delete_all_members
160 159 Member.delete_all(['project_id = ?', id])
161 160 end
162 161
163 162 # Users issues can be assigned to
164 163 def assignable_users
165 164 members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort
166 165 end
167 166
168 167 # Returns the mail adresses of users that should be always notified on project events
169 168 def recipients
170 169 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
171 170 end
172 171
173 172 # Returns an array of all custom fields enabled for project issues
174 173 # (explictly associated custom fields and custom fields enabled for all projects)
175 174 def custom_fields_for_issues(tracker)
176 175 all_custom_fields.select {|c| tracker.custom_fields.include? c }
177 176 end
178 177
179 178 def all_custom_fields
180 179 @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq
181 180 end
182 181
183 182 def <=>(project)
184 183 name.downcase <=> project.name.downcase
185 184 end
186 185
186 def to_s
187 name
188 end
189
190 # Returns a short description of the projects (first lines)
191 def short_description(length = 255)
192 description.gsub(/^(.{#{length}}[^\n]*).*$/m, '\1').strip if description
193 end
194
187 195 def allows_to?(action)
188 196 if action.is_a? Hash
189 197 allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
190 198 else
191 199 allowed_permissions.include? action
192 200 end
193 201 end
194 202
195 203 def module_enabled?(module_name)
196 204 module_name = module_name.to_s
197 205 enabled_modules.detect {|m| m.name == module_name}
198 206 end
199 207
200 208 def enabled_module_names=(module_names)
201 209 enabled_modules.clear
202 210 module_names = [] unless module_names && module_names.is_a?(Array)
203 211 module_names.each do |name|
204 212 enabled_modules << EnabledModule.new(:name => name.to_s)
205 213 end
206 214 end
207 215
208 216 protected
209 217 def validate
210 218 errors.add(parent_id, " must be a root project") if parent and parent.parent
211 219 errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0
212 220 end
213 221
214 222 private
215 223 def allowed_permissions
216 224 @allowed_permissions ||= begin
217 225 module_names = enabled_modules.collect {|m| m.name}
218 226 Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
219 227 end
220 228 end
221 229
222 230 def allowed_actions
223 231 @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
224 232 end
225 233 end
@@ -1,50 +1,50
1 1 <div class="contextual">
2 2 <%= link_to l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add' %>
3 3 </div>
4 4
5 5 <h2><%=l(:label_project_plural)%></h2>
6 6
7 7 <% form_tag() do %>
8 8 <fieldset><legend><%= l(:label_filter_plural) %></legend>
9 9 <label><%= l(:field_status) %> :</label>
10 10 <%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
11 11 <%= submit_tag l(:button_apply), :class => "small" %>
12 12 </fieldset>
13 13 <% end %>
14 14 &nbsp;
15 15
16 16 <table class="list">
17 17 <thead><tr>
18 18 <%= sort_header_tag('name', :caption => l(:label_project)) %>
19 19 <th><%=l(:field_description)%></th>
20 20 <th><%=l(:field_is_public)%></th>
21 21 <th><%=l(:label_subproject_plural)%></th>
22 22 <%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
23 23 <th></th>
24 24 <th></th>
25 25 </tr></thead>
26 26 <tbody>
27 27 <% for project in @projects %>
28 28 <tr class="<%= cycle("odd", "even") %>">
29 29 <td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %>
30 <td><%= textilizable project.description, :project => project %>
30 <td><%= textilizable project.short_description, :project => project %>
31 31 <td align="center"><%= image_tag 'true.png' if project.is_public? %>
32 32 <td align="center"><%= project.children.size %>
33 33 <td align="center"><%= format_date(project.created_on) %>
34 34 <td align="center" style="width:10%">
35 35 <small>
36 36 <%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project }, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-lock') if project.active? %>
37 37 <%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project }, :method => :post, :class => 'icon icon-unlock') if !project.active? && (project.parent.nil? || project.parent.active?) %>
38 38 </small>
39 39 </td>
40 40 <td align="center" style="width:10%">
41 41 <small><%= link_to(l(:button_delete), { :controller => 'projects', :action => 'destroy', :id => project }, :class => 'icon icon-del') %></small>
42 42 </td>
43 43 </tr>
44 44 <% end %>
45 45 </tbody>
46 46 </table>
47 47
48 48 <p class="pagination"><%= pagination_links_full @project_pages, @project_count %></p>
49 49
50 50 <% html_title(l(:label_project_plural)) -%>
@@ -1,53 +1,56
1 1 <%= error_messages_for 'project' %>
2 2
3 3 <div class="box">
4 4 <!--[form:project]-->
5 5 <p><%= f.text_field :name, :required => true %><br /><em><%= l(:text_caracters_maximum, 30) %></em></p>
6 6
7 7 <% if User.current.admin? and !@root_projects.empty? %>
8 8 <p><%= f.select :parent_id, (@root_projects.collect {|p| [p.name, p.id]}), { :include_blank => true } %></p>
9 9 <% end %>
10 10
11 <p><%= f.text_area :description, :required => true, :cols => 60, :rows => 5 %><em><%= l(:text_caracters_maximum, 255) %></em></p>
12 <p><%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %><br /><em><%= l(:text_length_between, 3, 20) %> <%= l(:text_project_identifier_info) unless @project.identifier_frozen? %></em></p>
11 <p><%= f.text_area :description, :rows => 5, :class => 'wiki-edit' %></p>
12 <p><%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %>
13 <% unless @project.identifier_frozen? %>
14 <br /><em><%= l(:text_length_between, 3, 20) %> <%= l(:text_project_identifier_info) %></em>
15 <% end %></p>
13 16 <p><%= f.text_field :homepage, :size => 40 %></p>
14 17 <p><%= f.check_box :is_public %></p>
15 18 <%= wikitoolbar_for 'project_description' %>
16 19
17 20 <% for @custom_value in @custom_values %>
18 21 <p><%= custom_field_tag_with_label @custom_value %></p>
19 22 <% end %>
20 23 </div>
21 24
22 25 <% unless @trackers.empty? %>
23 26 <fieldset class="box"><legend><%=l(:label_tracker_plural)%></legend>
24 27 <% @trackers.each do |tracker| %>
25 28 <label class="floating">
26 29 <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %>
27 30 <%= tracker %>
28 31 </label>
29 32 <% end %>
30 33 <%= hidden_field_tag 'project[tracker_ids][]', '' %>
31 34 </fieldset>
32 35 <% end %>
33 36
34 37 <% unless @custom_fields.empty? %>
35 38 <fieldset class="box"><legend><%=l(:label_custom_field_plural)%></legend>
36 39 <% for custom_field in @custom_fields %>
37 40 <label class="floating">
38 41 <%= check_box_tag 'project[custom_field_ids][]', custom_field.id, ((@project.custom_fields.include? custom_field) or custom_field.is_for_all?), (custom_field.is_for_all? ? {:disabled => "disabled"} : {}) %>
39 42 <%= custom_field.name %>
40 43 </label>
41 44 <% end %>
42 45 <%= hidden_field_tag 'project[custom_field_ids][]', '' %>
43 46 </fieldset>
44 47 <% end %>
45 48 <!--[eoform:project]-->
46 49
47 50
48 51 <% content_for :header_tags do %>
49 52 <%= javascript_include_tag 'calendar/calendar' %>
50 53 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
51 54 <%= javascript_include_tag 'calendar/calendar-setup' %>
52 55 <%= stylesheet_link_tag 'calendar' %>
53 56 <% end %>
@@ -1,20 +1,20
1 1 <h2><%=l(:label_project_plural)%></h2>
2 2
3 3 <% @project_tree.keys.sort.each do |project| %>
4 4 <h3><%= link_to h(project.name), {:action => 'show', :id => project}, :class => (User.current.member_of?(project) ? "icon icon-fav" : "") %></h3>
5 <%= textilizable(project.description, :project => project) %>
5 <%= textilizable(project.short_description, :project => project) %>
6 6
7 7 <% if @project_tree[project].any? %>
8 8 <p><%= l(:label_subproject_plural) %>:
9 9 <%= @project_tree[project].sort.collect {|subproject|
10 10 link_to(h(subproject.name), {:action => 'show', :id => subproject}, :class => (User.current.member_of?(subproject) ? "icon icon-fav" : ""))}.join(', ') %></p>
11 11 <% end %>
12 12 <% end %>
13 13
14 14 <% if User.current.logged? %>
15 15 <div class="contextual">
16 16 <span class="icon icon-fav"><%= l(:label_my_projects) %></span>
17 17 </div>
18 18 <% end %>
19 19
20 20 <% html_title(l(:label_project_plural)) -%>
@@ -1,30 +1,30
1 1 <h2><%= l(:label_home) %></h2>
2 2
3 3 <div class="splitcontentleft">
4 4 <%= textilizable Setting.welcome_text %>
5 5 <% if @news.any? %>
6 6 <div class="box">
7 7 <h3><%=l(:label_news_latest)%></h3>
8 8 <%= render :partial => 'news/news', :collection => @news %>
9 9 <%= link_to l(:label_news_view_all), :controller => 'news' %>
10 10 </div>
11 11 <% end %>
12 12 </div>
13 13
14 14 <div class="splitcontentright">
15 15 <div class="box">
16 16 <h3 class="icon22 icon22-projects"><%=l(:label_project_latest)%></h3>
17 17 <ul>
18 18 <% for project in @projects %>
19 19 <li>
20 20 <%= link_to project.name, :controller => 'projects', :action => 'show', :id => project %> (<%= format_time(project.created_on) %>)
21 <%= textilizable project.description, :project => project %>
21 <%= textilizable project.short_description, :project => project %>
22 22 </li>
23 23 <% end %>
24 24 </ul>
25 25 </div>
26 26 </div>
27 27
28 28 <% content_for :header_tags do %>
29 29 <%= auto_discovery_link_tag(:atom, {:controller => 'news', :action => 'index', :key => User.current.rss_key, :format => 'atom'}, {:title => l(:label_news_latest)}) %>
30 30 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now