diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index c35766e5..577dad22 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -23,12 +23,6 @@ class ApplicationController < ActionController::Base headers["Content-Type"] ||= "text/html; charset=UTF-8" end - # Reverses the urlize() method by substituting underscores for spaces - # - def deurlize(name) - name.to_s.gsub(/_/, " ") - end - def set_session_expiration # http://wiki.rubyonrails.com/rails/show/HowtoChangeSessionOptions unless session == nil diff --git a/tracks/app/controllers/context_controller.rb b/tracks/app/controllers/context_controller.rb index a565f963..2c5c0dad 100644 --- a/tracks/app/controllers/context_controller.rb +++ b/tracks/app/controllers/context_controller.rb @@ -46,7 +46,6 @@ class ContextController < ApplicationController @context.attributes = params['context'] || params['request']['context'] params_are_invalid = false end - @context.name = deurlize(@context.name) @saved = @context.save @context_not_done_counts = { @context.id => 0 } respond_to do |wants| @@ -73,7 +72,6 @@ class ContextController < ApplicationController params['context']['name'] = params['value'] end @context.attributes = params["context"] - @context.name = deurlize(@context.name) if @context.save if params['wants_render'] render @@ -113,10 +111,10 @@ class ContextController < ApplicationController protected def check_user_set_context - if params["name"] - @context = Context.find_by_name_and_user_id(deurlize(params["name"]), @user.id) + if params["url_friendly_name"] + @context = @user.contexts.find_by_url_friendly_name(params["url_friendly_name"]) elsif params['id'] - @context = Context.find_by_id_and_user_id(params["id"], @user.id) + @context = @user.contexts.find(params["id"]) else redirect_to(:controller => "context", :action => "list" ) end diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb index 01e64cf1..e70b74fb 100644 --- a/tracks/app/controllers/project_controller.rb +++ b/tracks/app/controllers/project_controller.rb @@ -70,7 +70,6 @@ class ProjectController < ApplicationController @project.attributes = params['project'] || params['request']['project'] params_are_invalid = false end - @project.name = deurlize(@project.name) @saved = @project.save @project_not_done_counts = { @project.id => 0 } respond_to do |wants| @@ -101,7 +100,6 @@ class ProjectController < ApplicationController params['project']['name'] = params['value'] end @project.attributes = params['project'] - @project.name = deurlize(@project.name) if @project.save if params['wants_render'] if (@project.hidden?) @@ -157,10 +155,10 @@ class ProjectController < ApplicationController protected def check_user_set_project - if params["name"] - @project = Project.find_by_name_and_user_id(deurlize(params["name"]), @user.id) + if params["url_friendly_name"] + @project = @user.projects.find_by_url_friendly_name(params["url_friendly_name"]) elsif params['id'] - @project = Project.find_by_id_and_user_id(params["id"], @user.id) + @project = @user.projects.find(params["id"]) else redirect_to(:controller => "project", :action => "list" ) end diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index e91f8e2d..400f1a4a 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -20,18 +20,6 @@ module ApplicationHelper def markdown(text) RedCloth.new(text).to_html end - - # Wraps object in HTML tags, tag - # - def tag_object(object, tag) - tagged = "<#{tag}>#{object}#{tag}>" - end - - # Converts names to URL-friendly format by substituting underscores for spaces - # - def urlize(name) - name.to_s.gsub(/ /, "_") - end # Replicates the link_to method but also checks request.request_uri to find # current page. If that matches the url, the link is marked @@ -132,16 +120,24 @@ module ApplicationHelper return count.to_s + " " + word end + def link_to_context(context, descriptor = sanitize(context.name)) + link_to( descriptor, { :controller => "context", :action => "show", :url_friendly_name => context.url_friendly_name }, :title => "View context: #{context.name}" ) + end + + def link_to_project(project, descriptor = sanitize(project.name)) + link_to( descriptor, { :controller => "project", :action => "show", :url_friendly_name => project.url_friendly_name }, :title => "View project: #{project.name}" ) + end + def item_link_to_context(item) descriptor = "[C]" descriptor = "[#{item.context.name}]" if (@user.preference.verbose_action_descriptors) - link_to( descriptor, { :controller => "context", :action => "show", :name => urlize(item.context.name) }, :title => "View context: #{item.context.name}" ) + link_to_context( item.context, descriptor ) end def item_link_to_project(item) descriptor = "[P]" descriptor = "[#{item.project.name}]" if (@user.preference.verbose_action_descriptors) - link_to( descriptor, { :controller => "project", :action => "show", :name => urlize(item.project.name) }, :title => "View project: #{item.project.name}" ) + link_to_project( item.project, descriptor ) end def render_flash diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb index 64ecf47b..d1be5a5e 100644 --- a/tracks/app/models/context.rb +++ b/tracks/app/models/context.rb @@ -6,6 +6,7 @@ class Context < ActiveRecord::Base acts_as_list :scope => :user extend NamePartFinder include Tracks::TodoList + include UrlFriendlyName attr_protected :user @@ -19,5 +20,5 @@ class Context < ActiveRecord::Base def hidden? self.hide == true end - + end diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb index 61627c94..5b68eefd 100644 --- a/tracks/app/models/project.rb +++ b/tracks/app/models/project.rb @@ -14,6 +14,7 @@ class Project < ActiveRecord::Base acts_as_state_machine :initial => :active, :column => 'state' extend NamePartFinder include Tracks::TodoList + include UrlFriendlyName state :active state :hidden, :enter => :hide_todos, :exit => :unhide_todos @@ -44,7 +45,7 @@ class Project < ActiveRecord::Base def linkurl_present? attribute_present?("linkurl") end - + def hide_todos todos.each do |t| t.hide! unless t.completed? diff --git a/tracks/app/views/context/_context.rhtml b/tracks/app/views/context/_context.rhtml index 96815cc1..f6851c56 100644 --- a/tracks/app/views/context/_context.rhtml +++ b/tracks/app/views/context/_context.rhtml @@ -7,7 +7,7 @@ <% if source_view_is :context %> <%= in_place_editor_field :context, :name, {}, { :url => url_for(:controller => 'context', :action => 'update', :id => context.id, :field => 'name', :wants_render => false) } %> <% else %> - <%= link_to( sanitize("#{context.name}"), { :controller => "context", :action => "show", :name => urlize(context.name) }, { :title => "Go to the #{context.name} context page" } ) %> + <%= link_to_context( context ) %> <% end %>
#{count_undone_todos(c)}. " context_description += "Context is #{c.hidden? ? 'Hidden' : 'Active'}. " diff --git a/tracks/app/views/feed/projects_rss.rxml b/tracks/app/views/feed/projects_rss.rxml index 5c176835..06de4788 100644 --- a/tracks/app/views/feed/projects_rss.rxml +++ b/tracks/app/views/feed/projects_rss.rxml @@ -7,7 +7,7 @@ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do @projects.each do |p| xml.item do xml.title(p.name) - xml.link(url_for(:only_path => false, :controller => 'project', :action => 'show', :name => urlize(p.name))) + xml.link(url_for(:only_path => false, :controller => 'project', :action => 'show', :url_friendly_name => p.url_friendly_name)) project_description = '' project_description += sanitize(markdown( p.description )) if p.description_present? project_description += "
#{count_undone_todos(p)}. " diff --git a/tracks/app/views/feed/rss.rxml b/tracks/app/views/feed/rss.rxml index e73cd78b..42ab94f5 100644 --- a/tracks/app/views/feed/rss.rxml +++ b/tracks/app/views/feed/rss.rxml @@ -6,15 +6,15 @@ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do @todos.each do |i| xml.item do xml.title(i.description) - xml.link(url_for(:only_path => false, :controller => 'context', :action => 'show', :name => urlize(i.context.name))) + xml.link(url_for(:only_path => false, :controller => 'context', :action => 'show', :url_friendly_name => i.context.url_friendly_name)) item_notes = sanitize(markdown( i.notes )) if i.notes? due = "