diff --git a/app/controllers/integrations_controller.rb b/app/controllers/integrations_controller.rb index 219068f5..dcc86187 100644 --- a/app/controllers/integrations_controller.rb +++ b/app/controllers/integrations_controller.rb @@ -10,20 +10,17 @@ class IntegrationsController < ApplicationController def rest_api @page_title = 'TRACKS::REST API Documentation' end - + def get_quicksilver_applescript - context = current_user.contexts.find params[:context_id] - render :partial => 'quicksilver_applescript', :locals => { :context => context } + get_applescript('quicksilver_applescript') end def get_applescript1 - context = current_user.contexts.find params[:context_id] - render :partial => 'applescript1', :locals => { :context => context } + get_applescript('applescript1') end def get_applescript2 - context = current_user.contexts.find params[:context_id] - render :partial => 'applescript2', :locals => { :context => context } + get_applescript('applescript2') end def search_plugin @@ -46,38 +43,18 @@ class IntegrationsController < ApplicationController return false end - # parse message - message = Mail.new(params[:message]) - - # find user - user = User.where("preferences.sms_email = ?", message.from).includes(:preference).first - if user.nil? - render :text => "No user found", :status => 404 - return false - end - - # load user settings - context = user.prefs.sms_context - - # prepare body - if message.body.multipart? - body = message.body.preamble + if MessageGateway::receive(Mail.new(params[:message])) + render :text => 'success', :status => 200 else - body = message.body.to_s + render :text => "No user found or other error", :status => 404 end - - # parse mail - if message.subject.to_s.empty? - description = body - notes = nil - else - description = message.subject.to_s - notes = body - end - - # create todo - todo = Todo.from_rich_message(user, context.id, description, notes) - todo.save! - render :text => 'success', :status => 200 end + + private + + def get_applescript(partial_name) + context = current_user.contexts.find params[:context_id] + render :partial => partial_name, :locals => { :context => context } + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b03d773e..ea28e310 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,27 +2,12 @@ # application. module ApplicationHelper - # Replicates the link_to method but also checks request.request_uri to find - # current page. If that matches the url, the link is marked id = "current" - # def navigation_link(name, options = {}, html_options = nil, *parameters_for_method_reference) link_to name, options, html_options - # TODO: check if this needs to be converted - # if html_options - # html_options = html_options.stringify_keys - # convert_options_to_javascript!(html_options) - # tag_options = tag_options(html_options) - # else - # tag_options = nil - # end - # url = options.is_a?(String) ? options : self.url_for(options, *parameters_for_method_reference) - # id_tag = (request.request_uri == url) ? " id=\"current\"" : "" - # - # "#{name || url}" end def days_from_today(date) - Integer (date.in_time_zone.to_date - current_user.time.to_date) + (date.in_time_zone.to_date - current_user.time.to_date).to_i end # Check due date in comparison to today's date Flag up date appropriately with @@ -123,8 +108,7 @@ module ApplicationHelper end def link_to_edit_note (note, descriptor = sanitize(note.id.to_s)) - link_to(descriptor, - url_for({:controller => 'notes', :action => 'edit', :id => note.id}), + link_to(descriptor, edit_notes_path(note), {:id => "link_edit_#{dom_id(note)}", :class => "note_edit_settings"}) end @@ -133,30 +117,30 @@ module ApplicationHelper end def item_link_to_context(item) - descriptor = "[C]" - descriptor = "[#{item.context.name}]" if prefs.verbose_action_descriptors - link_to_context( item.context, descriptor ) + link_to_context( item.context, prefs.verbose_action_descriptors ? "[#{item.context.name}]" : "[C]" ) end def item_link_to_project(item) - descriptor = "[P]" - descriptor = "[#{item.project.name}]" if prefs.verbose_action_descriptors - link_to_project( item.project, descriptor ) + link_to_project( item.project, prefs.verbose_action_descriptors ? "[#{item.project.name}]" : "[P]" ) end def render_flash render :partial => 'shared/flash', :object => flash end + def time_span_text(date, i18n_text) + return (date ? "#{i18n_text} #{format_date(date)}" : "").html_safe + end + def recurrence_time_span(rt) case rt.ends_on when "no_end_date" - return rt.start_from.nil? ? "" : I18n.t("todos.recurrence.pattern.from") + " " + format_date(rt.start_from) + return time_span_text(rt.start_from, I18n.t("todos.recurrence.pattern.from")) when "ends_on_number_of_times" return I18n.t("todos.recurrence.pattern.times", :number => rt.number_of_occurences) when "ends_on_end_date" - starts = rt.start_from.nil? ? "" : I18n.t("todos.recurrence.pattern.from") + " " + format_date(rt.start_from) - ends = rt.end_date.nil? ? "" : " " + I18n.t("todos.recurrence.pattern.until") + " " + format_date(rt.end_date) + starts = time_span_text(rt.start_from, I18n.t("todos.recurrence.pattern.from")) + ends = time_span_text(rt.end_date, I18n.t("todos.recurrence.pattern.until")) return starts+ends else raise Exception.new, "unknown recurrence time span selection (#{rt.ends_on})" @@ -166,17 +150,15 @@ module ApplicationHelper def recurrence_pattern_as_text(recurring_todo) rt = recurring_todo.recurring_target_as_text rp = recurring_todo.recurrence_pattern - # only add space if recurrence_pattern has content - rp = " " + rp if !rp.nil? + rp = " " + rp unless rp.nil? rts = recurrence_time_span(recurring_todo) # only add space if recurrence_time_span has content - rts = " " + rts if !(rts == "") + rts = " " + rts unless rts == "" return rt+rp+rts end def date_format_for_date_picker() - standard_format = current_user.prefs.date_format - translations = [ + [ ['%m', 'mm'], ['%b', 'M'], ['%B', 'MM'], @@ -185,25 +167,24 @@ module ApplicationHelper ['%A', 'DD'], ['%y', 'y'], ['%Y', 'yy'] - ] - translations.inject(standard_format) do |str, translation| - str.gsub(*translation) - end + ].inject(current_user.prefs.date_format) { |str, translation| str.gsub(*translation) } end def sidebar_html_for_titled_list (list, title) return content_tag(:h3, title+" (#{list.size})") + content_tag(:ul, sidebar_html_for_list(list)) end + def link_to_sidebar_item(item) + item.is_a?(Project) ? link_to_project( item ) : link_to_context( item ) + end + + def sidebar_html_for_item(item) + content_tag(:li, link_to_sidebar_item(item) + " (" + count_undone_todos_phrase(item)+")") + end + def sidebar_html_for_list(list) - if list.empty? - return content_tag(:li, t('sidebar.list_empty')).html_safe - else - return list.inject("") do |html, item| - link = item.is_a?(Project) ? link_to_project( item ) : link_to_context(item) - html << content_tag(:li, link + " (" + count_undone_todos_phrase(item)+")") - end.html_safe - end + return content_tag(:li, t('sidebar.list_empty')).html_safe if list.empty? + return list.inject("") { |html, item| html << sidebar_html_for_item(item) }.html_safe end def generate_i18n_strings @@ -230,7 +211,7 @@ module ApplicationHelper def javascript_tag_for_i18n_datepicker locale = I18n.locale # do not include en as locale since this the available by default - if locale and locale != :en + if locale && locale != :en javascript_include_tag("i18n/jquery.ui.datepicker-#{locale}.js") end end diff --git a/app/helpers/contexts_helper.rb b/app/helpers/contexts_helper.rb index 423d18ad..0ec1793a 100644 --- a/app/helpers/contexts_helper.rb +++ b/app/helpers/contexts_helper.rb @@ -1,14 +1,5 @@ module ContextsHelper - def get_listing_sortable_options - { - :tag => 'div', - :handle => 'handle', - :complete => visual_effect(:highlight, 'list-contexts'), - :url => order_contexts_path - } - end - def link_to_delete_context(context, descriptor = sanitize(context.name)) link_to(descriptor, context_path(context, :format => 'js'), @@ -21,8 +12,7 @@ module ContextsHelper end def link_to_edit_context (context, descriptor = sanitize(context.name)) - link_to(descriptor, - url_for({:controller => 'contexts', :action => 'edit', :id => context.id}), + link_to(descriptor, edit_context_path(context), { :id => "link_edit_#{dom_id(context)}", :class => "context_edit_settings icon" diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 44b7609c..15364485 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -1,22 +1,5 @@ module ProjectsHelper - def get_listing_sortable_options(list_container_id) - { - :tag => 'div', - :handle => 'handle', - :complete => visual_effect(:highlight, list_container_id), - :url => order_projects_path - } - end - - def set_element_visible(id,test) - if (test) - page.show id - else - page.hide id - end - end - def project_next_prev html = "" if @previous_project @@ -33,11 +16,11 @@ module ProjectsHelper def project_next_prev_mobile prev_project,next_project= "", "" - unless @previous_project.nil? + if @previous_project project_name = truncate(@previous_project.name, :length => 40, :omission => "...") prev_project = content_tag(:li, link_to_project_mobile(@previous_project, "5", project_name), :class=>"prev") end - unless @next_project.nil? + if @next_project project_name = truncate(@next_project.name, :length => 40, :omission => "...") next_project = content_tag(:li, link_to_project_mobile(@next_project, "6", project_name), :class=>"next") end @@ -58,8 +41,7 @@ module ProjectsHelper end def link_to_edit_project (project, descriptor = sanitize(project.name)) - link_to(descriptor, - url_for({:controller => 'projects', :action => 'edit', :id => project.id}), + link_to(descriptor, edit_project_path(project), { :id => "link_edit_#{dom_id(project)}", :class => "project_edit_settings icon" @@ -72,7 +54,6 @@ module ProjectsHelper project_description += content_tag(:p, "#{count_undone_todos_phrase(p)}. #{t('projects.project_state', :state => project.state)}".html_safe ) - raw project_description end def needsreview_class(item) diff --git a/app/models/message_gateway.rb b/app/models/message_gateway.rb index eaea3818..43248afc 100644 --- a/app/models/message_gateway.rb +++ b/app/models/message_gateway.rb @@ -4,7 +4,7 @@ class MessageGateway < ActionMailer::Base def receive(email) user = get_user_from_email_address(email) - return if user.nil? + return false if user.nil? context = user.prefs.sms_context description = nil diff --git a/lib/is_taggable.rb b/lib/is_taggable.rb index 2308a0b6..73caf339 100644 --- a/lib/is_taggable.rb +++ b/lib/is_taggable.rb @@ -62,24 +62,26 @@ module IsTaggable outgoing = tag_cast_to_string(outgoing) tags.delete(*(tags.select{|tag| outgoing.include? tag.name})) end + + def get_tag_name_from_item(item) + case item + # removed next line as it prevents using numbers as tags + # when /^\d+$/, Fixnum then Tag.find(item).name # This will be slow if you use ids a lot. + when Tag + item.name + when String + item + else + raise "Invalid type" + end + end def tag_cast_to_string obj case obj when Array - obj.map! do |item| - case item - # removed next line as it prevents using numbers as tags - # when /^\d+$/, Fixnum then Tag.find(item).name # This will be slow if you use ids a lot. - when Tag then item.name - when String then item - else - raise "Invalid type" - end - end + obj.map! { |item| get_tag_name_from_item(item) } when String - obj = obj.split(Tag::DELIMITER).map do |tag_name| - tag_name.strip.squeeze(" ") - end + obj.split(Tag::DELIMITER).map { |tag_name| tag_name.strip.squeeze(" ") } else raise "Invalid object of class #{obj.class} as tagging method parameter" end.flatten.compact.map(&:downcase).uniq