mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
small refactorings
This commit is contained in:
parent
7d0c716366
commit
82bb67f518
6 changed files with 61 additions and 130 deletions
|
|
@ -12,18 +12,15 @@ class IntegrationsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_quicksilver_applescript
|
def get_quicksilver_applescript
|
||||||
context = current_user.contexts.find params[:context_id]
|
get_applescript('quicksilver_applescript')
|
||||||
render :partial => 'quicksilver_applescript', :locals => { :context => context }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_applescript1
|
def get_applescript1
|
||||||
context = current_user.contexts.find params[:context_id]
|
get_applescript('applescript1')
|
||||||
render :partial => 'applescript1', :locals => { :context => context }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_applescript2
|
def get_applescript2
|
||||||
context = current_user.contexts.find params[:context_id]
|
get_applescript('applescript2')
|
||||||
render :partial => 'applescript2', :locals => { :context => context }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_plugin
|
def search_plugin
|
||||||
|
|
@ -46,38 +43,18 @@ class IntegrationsController < ApplicationController
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# parse message
|
if MessageGateway::receive(Mail.new(params[: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
|
|
||||||
else
|
|
||||||
body = message.body.to_s
|
|
||||||
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
|
render :text => 'success', :status => 200
|
||||||
|
else
|
||||||
|
render :text => "No user found or other error", :status => 404
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_applescript(partial_name)
|
||||||
|
context = current_user.contexts.find params[:context_id]
|
||||||
|
render :partial => partial_name, :locals => { :context => context }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,12 @@
|
||||||
# application.
|
# application.
|
||||||
module ApplicationHelper
|
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)
|
def navigation_link(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
||||||
link_to name, options, html_options
|
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\"" : ""
|
|
||||||
#
|
|
||||||
# "<a href=\"#{url}\"#{tag_options}#{id_tag}>#{name || url}</a>"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def days_from_today(date)
|
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
|
end
|
||||||
|
|
||||||
# Check due date in comparison to today's date Flag up date appropriately with
|
# Check due date in comparison to today's date Flag up date appropriately with
|
||||||
|
|
@ -123,8 +108,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_edit_note (note, descriptor = sanitize(note.id.to_s))
|
def link_to_edit_note (note, descriptor = sanitize(note.id.to_s))
|
||||||
link_to(descriptor,
|
link_to(descriptor, edit_notes_path(note),
|
||||||
url_for({:controller => 'notes', :action => 'edit', :id => note.id}),
|
|
||||||
{:id => "link_edit_#{dom_id(note)}", :class => "note_edit_settings"})
|
{:id => "link_edit_#{dom_id(note)}", :class => "note_edit_settings"})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -133,30 +117,30 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def item_link_to_context(item)
|
def item_link_to_context(item)
|
||||||
descriptor = "[C]"
|
link_to_context( item.context, prefs.verbose_action_descriptors ? "[#{item.context.name}]" : "[C]" )
|
||||||
descriptor = "[#{item.context.name}]" if prefs.verbose_action_descriptors
|
|
||||||
link_to_context( item.context, descriptor )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def item_link_to_project(item)
|
def item_link_to_project(item)
|
||||||
descriptor = "[P]"
|
link_to_project( item.project, prefs.verbose_action_descriptors ? "[#{item.project.name}]" : "[P]" )
|
||||||
descriptor = "[#{item.project.name}]" if prefs.verbose_action_descriptors
|
|
||||||
link_to_project( item.project, descriptor )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_flash
|
def render_flash
|
||||||
render :partial => 'shared/flash', :object => flash
|
render :partial => 'shared/flash', :object => flash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def time_span_text(date, i18n_text)
|
||||||
|
return (date ? "#{i18n_text} #{format_date(date)}" : "").html_safe
|
||||||
|
end
|
||||||
|
|
||||||
def recurrence_time_span(rt)
|
def recurrence_time_span(rt)
|
||||||
case rt.ends_on
|
case rt.ends_on
|
||||||
when "no_end_date"
|
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"
|
when "ends_on_number_of_times"
|
||||||
return I18n.t("todos.recurrence.pattern.times", :number => rt.number_of_occurences)
|
return I18n.t("todos.recurrence.pattern.times", :number => rt.number_of_occurences)
|
||||||
when "ends_on_end_date"
|
when "ends_on_end_date"
|
||||||
starts = rt.start_from.nil? ? "" : I18n.t("todos.recurrence.pattern.from") + " " + format_date(rt.start_from)
|
starts = time_span_text(rt.start_from, I18n.t("todos.recurrence.pattern.from"))
|
||||||
ends = rt.end_date.nil? ? "" : " " + I18n.t("todos.recurrence.pattern.until") + " " + format_date(rt.end_date)
|
ends = time_span_text(rt.end_date, I18n.t("todos.recurrence.pattern.until"))
|
||||||
return starts+ends
|
return starts+ends
|
||||||
else
|
else
|
||||||
raise Exception.new, "unknown recurrence time span selection (#{rt.ends_on})"
|
raise Exception.new, "unknown recurrence time span selection (#{rt.ends_on})"
|
||||||
|
|
@ -166,17 +150,15 @@ module ApplicationHelper
|
||||||
def recurrence_pattern_as_text(recurring_todo)
|
def recurrence_pattern_as_text(recurring_todo)
|
||||||
rt = recurring_todo.recurring_target_as_text
|
rt = recurring_todo.recurring_target_as_text
|
||||||
rp = recurring_todo.recurrence_pattern
|
rp = recurring_todo.recurrence_pattern
|
||||||
# only add space if recurrence_pattern has content
|
rp = " " + rp unless rp.nil?
|
||||||
rp = " " + rp if !rp.nil?
|
|
||||||
rts = recurrence_time_span(recurring_todo)
|
rts = recurrence_time_span(recurring_todo)
|
||||||
# only add space if recurrence_time_span has content
|
# only add space if recurrence_time_span has content
|
||||||
rts = " " + rts if !(rts == "")
|
rts = " " + rts unless rts == ""
|
||||||
return rt+rp+rts
|
return rt+rp+rts
|
||||||
end
|
end
|
||||||
|
|
||||||
def date_format_for_date_picker()
|
def date_format_for_date_picker()
|
||||||
standard_format = current_user.prefs.date_format
|
[
|
||||||
translations = [
|
|
||||||
['%m', 'mm'],
|
['%m', 'mm'],
|
||||||
['%b', 'M'],
|
['%b', 'M'],
|
||||||
['%B', 'MM'],
|
['%B', 'MM'],
|
||||||
|
|
@ -185,25 +167,24 @@ module ApplicationHelper
|
||||||
['%A', 'DD'],
|
['%A', 'DD'],
|
||||||
['%y', 'y'],
|
['%y', 'y'],
|
||||||
['%Y', 'yy']
|
['%Y', 'yy']
|
||||||
]
|
].inject(current_user.prefs.date_format) { |str, translation| str.gsub(*translation) }
|
||||||
translations.inject(standard_format) do |str, translation|
|
|
||||||
str.gsub(*translation)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def sidebar_html_for_titled_list (list, title)
|
def sidebar_html_for_titled_list (list, title)
|
||||||
return content_tag(:h3, title+" (#{list.size})") + content_tag(:ul, sidebar_html_for_list(list))
|
return content_tag(:h3, title+" (#{list.size})") + content_tag(:ul, sidebar_html_for_list(list))
|
||||||
end
|
end
|
||||||
|
|
||||||
def sidebar_html_for_list(list)
|
def link_to_sidebar_item(item)
|
||||||
if list.empty?
|
item.is_a?(Project) ? link_to_project( item ) : link_to_context( item )
|
||||||
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
|
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)
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def generate_i18n_strings
|
def generate_i18n_strings
|
||||||
|
|
@ -230,7 +211,7 @@ module ApplicationHelper
|
||||||
def javascript_tag_for_i18n_datepicker
|
def javascript_tag_for_i18n_datepicker
|
||||||
locale = I18n.locale
|
locale = I18n.locale
|
||||||
# do not include en as locale since this the available by default
|
# 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")
|
javascript_include_tag("i18n/jquery.ui.datepicker-#{locale}.js")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,5 @@
|
||||||
module ContextsHelper
|
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))
|
def link_to_delete_context(context, descriptor = sanitize(context.name))
|
||||||
link_to(descriptor,
|
link_to(descriptor,
|
||||||
context_path(context, :format => 'js'),
|
context_path(context, :format => 'js'),
|
||||||
|
|
@ -21,8 +12,7 @@ module ContextsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_edit_context (context, descriptor = sanitize(context.name))
|
def link_to_edit_context (context, descriptor = sanitize(context.name))
|
||||||
link_to(descriptor,
|
link_to(descriptor, edit_context_path(context),
|
||||||
url_for({:controller => 'contexts', :action => 'edit', :id => context.id}),
|
|
||||||
{
|
{
|
||||||
:id => "link_edit_#{dom_id(context)}",
|
:id => "link_edit_#{dom_id(context)}",
|
||||||
:class => "context_edit_settings icon"
|
:class => "context_edit_settings icon"
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,5 @@
|
||||||
module ProjectsHelper
|
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
|
def project_next_prev
|
||||||
html = ""
|
html = ""
|
||||||
if @previous_project
|
if @previous_project
|
||||||
|
|
@ -33,11 +16,11 @@ module ProjectsHelper
|
||||||
|
|
||||||
def project_next_prev_mobile
|
def project_next_prev_mobile
|
||||||
prev_project,next_project= "", ""
|
prev_project,next_project= "", ""
|
||||||
unless @previous_project.nil?
|
if @previous_project
|
||||||
project_name = truncate(@previous_project.name, :length => 40, :omission => "...")
|
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")
|
prev_project = content_tag(:li, link_to_project_mobile(@previous_project, "5", project_name), :class=>"prev")
|
||||||
end
|
end
|
||||||
unless @next_project.nil?
|
if @next_project
|
||||||
project_name = truncate(@next_project.name, :length => 40, :omission => "...")
|
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")
|
next_project = content_tag(:li, link_to_project_mobile(@next_project, "6", project_name), :class=>"next")
|
||||||
end
|
end
|
||||||
|
|
@ -58,8 +41,7 @@ module ProjectsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_edit_project (project, descriptor = sanitize(project.name))
|
def link_to_edit_project (project, descriptor = sanitize(project.name))
|
||||||
link_to(descriptor,
|
link_to(descriptor, edit_project_path(project),
|
||||||
url_for({:controller => 'projects', :action => 'edit', :id => project.id}),
|
|
||||||
{
|
{
|
||||||
:id => "link_edit_#{dom_id(project)}",
|
:id => "link_edit_#{dom_id(project)}",
|
||||||
:class => "project_edit_settings icon"
|
:class => "project_edit_settings icon"
|
||||||
|
|
@ -72,7 +54,6 @@ module ProjectsHelper
|
||||||
project_description += content_tag(:p,
|
project_description += content_tag(:p,
|
||||||
"#{count_undone_todos_phrase(p)}. #{t('projects.project_state', :state => project.state)}".html_safe
|
"#{count_undone_todos_phrase(p)}. #{t('projects.project_state', :state => project.state)}".html_safe
|
||||||
)
|
)
|
||||||
raw project_description
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def needsreview_class(item)
|
def needsreview_class(item)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ class MessageGateway < ActionMailer::Base
|
||||||
|
|
||||||
def receive(email)
|
def receive(email)
|
||||||
user = get_user_from_email_address(email)
|
user = get_user_from_email_address(email)
|
||||||
return if user.nil?
|
return false if user.nil?
|
||||||
|
|
||||||
context = user.prefs.sms_context
|
context = user.prefs.sms_context
|
||||||
description = nil
|
description = nil
|
||||||
|
|
|
||||||
|
|
@ -63,23 +63,25 @@ module IsTaggable
|
||||||
tags.delete(*(tags.select{|tag| outgoing.include? tag.name}))
|
tags.delete(*(tags.select{|tag| outgoing.include? tag.name}))
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_cast_to_string obj
|
def get_tag_name_from_item(item)
|
||||||
case obj
|
|
||||||
when Array
|
|
||||||
obj.map! do |item|
|
|
||||||
case item
|
case item
|
||||||
# removed next line as it prevents using numbers as tags
|
# 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 /^\d+$/, Fixnum then Tag.find(item).name # This will be slow if you use ids a lot.
|
||||||
when Tag then item.name
|
when Tag
|
||||||
when String then item
|
item.name
|
||||||
|
when String
|
||||||
|
item
|
||||||
else
|
else
|
||||||
raise "Invalid type"
|
raise "Invalid type"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_cast_to_string obj
|
||||||
|
case obj
|
||||||
|
when Array
|
||||||
|
obj.map! { |item| get_tag_name_from_item(item) }
|
||||||
when String
|
when String
|
||||||
obj = obj.split(Tag::DELIMITER).map do |tag_name|
|
obj.split(Tag::DELIMITER).map { |tag_name| tag_name.strip.squeeze(" ") }
|
||||||
tag_name.strip.squeeze(" ")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
raise "Invalid object of class #{obj.class} as tagging method parameter"
|
raise "Invalid object of class #{obj.class} as tagging method parameter"
|
||||||
end.flatten.compact.map(&:downcase).uniq
|
end.flatten.compact.map(&:downcase).uniq
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue