From df99d8f30801792560fc955ac36c2801e6aa5ff5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 20 Jan 2008 18:37:51 +0000 Subject: [PATCH] Unlimited and optional project description. The project list will show truncated descriptions only (the first fews lines). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1088 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/project.rb | 12 ++++++++++-- app/views/admin/projects.rhtml | 2 +- app/views/projects/_form.rhtml | 7 +++++-- app/views/projects/list.rhtml | 2 +- app/views/welcome/index.rhtml | 2 +- .../087_change_projects_description_to_text.rb | 8 ++++++++ 6 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 db/migrate/087_change_projects_description_to_text.rb diff --git a/app/models/project.rb b/app/models/project.rb index 0e7f8284c..42f2ddfd9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -52,12 +52,11 @@ class Project < ActiveRecord::Base attr_protected :status, :enabled_module_names - validates_presence_of :name, :description, :identifier + validates_presence_of :name, :identifier validates_uniqueness_of :name, :identifier validates_associated :custom_values, :on => :update validates_associated :repository, :wiki validates_length_of :name, :maximum => 30 - validates_length_of :description, :maximum => 255 validates_length_of :homepage, :maximum => 60 validates_length_of :identifier, :in => 3..20 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ @@ -184,6 +183,15 @@ class Project < ActiveRecord::Base name.downcase <=> project.name.downcase end + def to_s + name + end + + # Returns a short description of the projects (first lines) + def short_description(length = 255) + description.gsub(/^(.{#{length}}[^\n]*).*$/m, '\1').strip if description + end + def allows_to?(action) if action.is_a? Hash allowed_actions.include? "#{action[:controller]}/#{action[:action]}" diff --git a/app/views/admin/projects.rhtml b/app/views/admin/projects.rhtml index 3a759ecaa..d35c484b5 100644 --- a/app/views/admin/projects.rhtml +++ b/app/views/admin/projects.rhtml @@ -27,7 +27,7 @@ <% for project in @projects %> "> <%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %> - <%= textilizable project.description, :project => project %> + <%= textilizable project.short_description, :project => project %> <%= image_tag 'true.png' if project.is_public? %> <%= project.children.size %> <%= format_date(project.created_on) %> diff --git a/app/views/projects/_form.rhtml b/app/views/projects/_form.rhtml index e63c929cc..a810369d4 100644 --- a/app/views/projects/_form.rhtml +++ b/app/views/projects/_form.rhtml @@ -8,8 +8,11 @@

<%= f.select :parent_id, (@root_projects.collect {|p| [p.name, p.id]}), { :include_blank => true } %>

<% end %> -

<%= f.text_area :description, :required => true, :cols => 60, :rows => 5 %><%= l(:text_caracters_maximum, 255) %>

-

<%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %>
<%= l(:text_length_between, 3, 20) %> <%= l(:text_project_identifier_info) unless @project.identifier_frozen? %>

+

<%= f.text_area :description, :rows => 5, :class => 'wiki-edit' %>

+

<%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %> +<% unless @project.identifier_frozen? %> +
<%= l(:text_length_between, 3, 20) %> <%= l(:text_project_identifier_info) %> +<% end %>

<%= f.text_field :homepage, :size => 40 %>

<%= f.check_box :is_public %>

<%= wikitoolbar_for 'project_description' %> diff --git a/app/views/projects/list.rhtml b/app/views/projects/list.rhtml index a18f63e43..15ea06483 100644 --- a/app/views/projects/list.rhtml +++ b/app/views/projects/list.rhtml @@ -2,7 +2,7 @@ <% @project_tree.keys.sort.each do |project| %>

<%= link_to h(project.name), {:action => 'show', :id => project}, :class => (User.current.member_of?(project) ? "icon icon-fav" : "") %>

-<%= textilizable(project.description, :project => project) %> +<%= textilizable(project.short_description, :project => project) %> <% if @project_tree[project].any? %>

<%= l(:label_subproject_plural) %>: diff --git a/app/views/welcome/index.rhtml b/app/views/welcome/index.rhtml index 2e7ec2c06..d618fa6e1 100644 --- a/app/views/welcome/index.rhtml +++ b/app/views/welcome/index.rhtml @@ -18,7 +18,7 @@ <% for project in @projects %>

  • <%= link_to project.name, :controller => 'projects', :action => 'show', :id => project %> (<%= format_time(project.created_on) %>) - <%= textilizable project.description, :project => project %> + <%= textilizable project.short_description, :project => project %>
  • <% end %> diff --git a/db/migrate/087_change_projects_description_to_text.rb b/db/migrate/087_change_projects_description_to_text.rb new file mode 100644 index 000000000..d215840aa --- /dev/null +++ b/db/migrate/087_change_projects_description_to_text.rb @@ -0,0 +1,8 @@ +class ChangeProjectsDescriptionToText < ActiveRecord::Migration + def self.up + change_column :projects, :description, :text, :default => '' + end + + def self.down + end +end -- 2.39.5