mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-21 21:40:48 +02:00
Merge pull request #2503 from TracksApp/codeclimate_fixes
More code climate style fixes
This commit is contained in:
commit
318e4a22e4
28 changed files with 157 additions and 172 deletions
|
@ -219,14 +219,14 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def init_not_done_counts(parents=['project', 'context'])
|
||||
def init_not_done_counts(parents = ['project', 'context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_not_done_counts ||= current_user.todos.active.count_by_group('#{parent}_id')", binding, __FILE__, __LINE__)
|
||||
eval("@#{parent}_deferred_counts ||= current_user.todos.deferred.count_by_group('#{parent}_id')", binding, __FILE__, __LINE__)
|
||||
end
|
||||
end
|
||||
|
||||
def init_hidden_todo_counts(parents=['project', 'context'])
|
||||
def init_hidden_todo_counts(parents = ['project', 'context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_hidden_todo_counts ||= current_user.todos.active_or_hidden.count_by_group('#{parent}_id')", binding, __FILE__, __LINE__)
|
||||
end
|
||||
|
|
|
@ -758,7 +758,7 @@ class TodosController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def get_not_completed_for_predecessor(relation, todo_id=nil)
|
||||
def get_not_completed_for_predecessor(relation, todo_id = nil)
|
||||
items = relation.todos.not_completed
|
||||
.where('(LOWER(todos.description) ' + Common.like_operator + '?)', "%#{params[:term].downcase}%")
|
||||
items = items.where("AND NOT(todos.id=?)", todo_id) unless todo_id.nil?
|
||||
|
@ -984,7 +984,7 @@ end
|
|||
return todos_in_container, todos_in_target_container
|
||||
end
|
||||
|
||||
def determine_remaining_in_container_count(todo=@todo)
|
||||
def determine_remaining_in_container_count(todo = @todo)
|
||||
source_view do |from|
|
||||
from.deferred {
|
||||
todos_in_container, todos_in_target_container = find_todos_in_container_and_target_container(todo, @todo)
|
||||
|
@ -1282,22 +1282,22 @@ end
|
|||
end
|
||||
|
||||
# all completed todos [today@00:00, today@now]
|
||||
def get_done_today(completed_todos, includes={ :include => Todo::DEFAULT_INCLUDES })
|
||||
def get_done_today(completed_todos, includes = { :include => Todo::DEFAULT_INCLUDES })
|
||||
start_of_this_day = Time.zone.now.beginning_of_day
|
||||
completed_todos.completed_after(start_of_this_day).includes(includes[:include])
|
||||
end
|
||||
|
||||
def get_done_in_period(completed_todos, before, after, includes={ :include => Todo::DEFAULT_INCLUDES })
|
||||
def get_done_in_period(completed_todos, before, after, includes = { :include => Todo::DEFAULT_INCLUDES })
|
||||
completed_todos.completed_before(before).completed_after(after).includes(includes[:include])
|
||||
end
|
||||
|
||||
# all completed todos [begin_of_week, start_of_today]
|
||||
def get_done_rest_of_week(completed_todos, includes={ :include => Todo::DEFAULT_INCLUDES })
|
||||
def get_done_rest_of_week(completed_todos, includes = { :include => Todo::DEFAULT_INCLUDES })
|
||||
get_done_in_period(completed_todos, Time.zone.now.beginning_of_day, Time.zone.now.beginning_of_week)
|
||||
end
|
||||
|
||||
# all completed todos [begin_of_month, begin_of_week]
|
||||
def get_done_rest_of_month(completed_todos, includes={ :include => Todo::DEFAULT_INCLUDES })
|
||||
def get_done_rest_of_month(completed_todos, includes = { :include => Todo::DEFAULT_INCLUDES })
|
||||
get_done_in_period(completed_todos, Time.zone.now.beginning_of_week, Time.zone.now.beginning_of_month)
|
||||
end
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ module ApplicationHelper
|
|||
link_to(descriptor, project, :title => "View project: #{project.name}")
|
||||
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, edit_note_path(note),
|
||||
{ :id => "link_edit_#{dom_id(note)}", :class => "note_edit_settings" })
|
||||
end
|
||||
|
@ -207,7 +207,7 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
def link_to_delete(type, object, descriptor=sanitize(object.name))
|
||||
def link_to_delete(type, object, descriptor = sanitize(object.name))
|
||||
link_to(descriptor, self.send("#{type}_path", object, :format => 'js'),
|
||||
{
|
||||
:id => "delete_#{type}_#{object.id}",
|
||||
|
@ -228,7 +228,7 @@ module ApplicationHelper
|
|||
|
||||
def source_view_key
|
||||
# uses @project.id or @context.id depending on source_view
|
||||
source_view_is_one_of(:project, :context) ? "#{@source_view}-#{eval("@#{@source_view}.id")}" : @source_view
|
||||
source_view_is_one_of(:project, :context) ? "#{@source_view}-#{eval("@#{@source_view}.id", binding, __FILE__, __LINE__)}" : @source_view
|
||||
end
|
||||
|
||||
# create a unique object name which can be used in ajax calls returning js
|
||||
|
@ -237,7 +237,7 @@ module ApplicationHelper
|
|||
"#{name}_#{SecureRandom.hex(5)}"
|
||||
end
|
||||
|
||||
def js_render(partial, locals={}, object=nil)
|
||||
def js_render(partial, locals = {}, object = nil)
|
||||
if object
|
||||
escape_javascript(render(partial: partial, locals: locals, object: object))
|
||||
else
|
||||
|
|
|
@ -13,7 +13,7 @@ module FeedlistHelper
|
|||
end
|
||||
|
||||
def ical_formatted_link(options = {})
|
||||
link_to(content_tag(:span, 'iCal', { :class=>"feed", :title => "iCal feed" }), linkoptions('ics', options))
|
||||
link_to(content_tag(:span, 'iCal', { :class => "feed", :title => "iCal feed" }), linkoptions('ics', options))
|
||||
end
|
||||
|
||||
def feed_links(feeds, link_options, title)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module IconHelper
|
||||
include FontAwesome::Sass::Rails::ViewHelpers
|
||||
|
||||
def icon_fw(style, name, text=nil, html_options={})
|
||||
def icon_fw(style, name, text = nil, html_options = {})
|
||||
text, html_options = nil, text if text.is_a?(Hash)
|
||||
|
||||
if html_options.key?(:class)
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'staleness'
|
|||
|
||||
module TodosHelper
|
||||
# === helpers for rendering container
|
||||
def empty_message_holder(container_name, show, title_param=nil)
|
||||
def empty_message_holder(container_name, show, title_param = nil)
|
||||
content_tag(:div, :id => "no_todos_in_view", :class => "container #{container_name}", :style => "display:" + (show ? "block" : "none") ) do
|
||||
content_tag(:h2) { t("todos.no_actions.title", :param=>title_param) } +
|
||||
content_tag(:div, :class => "message") do
|
||||
|
@ -41,7 +41,7 @@ module TodosHelper
|
|||
}
|
||||
end
|
||||
|
||||
def show_done_todos(done_todos, settings={})
|
||||
def show_done_todos(done_todos, settings = {})
|
||||
settings[:container_name] = "completed"
|
||||
settings[:link_in_header] = link_to(t('common.show_all'), determine_done_path)
|
||||
|
||||
|
@ -63,7 +63,7 @@ module TodosHelper
|
|||
:locals => { :settings => settings }
|
||||
end
|
||||
|
||||
def show_hidden_todos(hidden_todos, settings={})
|
||||
def show_hidden_todos(hidden_todos, settings = {})
|
||||
settings[:container_name] = "hidden"
|
||||
|
||||
render :partial => 'todos/collection',
|
||||
|
@ -71,7 +71,7 @@ module TodosHelper
|
|||
:locals => { :settings => settings.reverse_merge!(default_collection_settings) }
|
||||
end
|
||||
|
||||
def show_deferred_pending_todos(deferred_todos, pending_todos, settings={})
|
||||
def show_deferred_pending_todos(deferred_todos, pending_todos, settings = {})
|
||||
settings[:pending] = pending_todos
|
||||
settings[:container_name]="deferred_pending"
|
||||
|
||||
|
@ -91,7 +91,7 @@ module TodosHelper
|
|||
}
|
||||
end
|
||||
|
||||
def todos_container(settings={})
|
||||
def todos_container(settings = {})
|
||||
settings.reverse_merge!({
|
||||
:id => "#{settings[:container_name]}_container",
|
||||
:class => "container #{settings[:container_name]}",
|
||||
|
@ -109,7 +109,7 @@ module TodosHelper
|
|||
end
|
||||
end
|
||||
|
||||
def todos_container_header(settings={})
|
||||
def todos_container_header(settings = {})
|
||||
settings.reverse_merge!({
|
||||
:title => t("todos.actions.#{settings[:parent_container_type]}_#{settings[:container_name]}", :param => settings[:title_param])
|
||||
})
|
||||
|
@ -122,7 +122,7 @@ module TodosHelper
|
|||
header.html_safe
|
||||
end
|
||||
|
||||
def todos_container_items(collection, settings={})
|
||||
def todos_container_items(collection, settings = {})
|
||||
settings.reverse_merge!({:id => "#{settings[:container_name]}"})
|
||||
# do not pass :class to partial locals
|
||||
settings.delete(:class)
|
||||
|
@ -146,13 +146,13 @@ module TodosHelper
|
|||
|
||||
# === helpers for rendering a todo
|
||||
|
||||
def remote_star_icon(todo=@todo)
|
||||
def remote_star_icon(todo = @todo)
|
||||
link_to(image_tag_for_star(todo),
|
||||
toggle_star_todo_path(todo),
|
||||
:class => "icon star_item", :title => t('todos.star_action_with_description', :description => todo.description))
|
||||
end
|
||||
|
||||
def remote_edit_button(todo=@todo)
|
||||
def remote_edit_button(todo = @todo)
|
||||
link_to(
|
||||
image_tag("blank.png", :alt => t('todos.edit'), :align => "absmiddle", :id => dom_id(todo, "edit_icon"), :class => 'edit_item'),
|
||||
edit_todo_path(todo),
|
||||
|
@ -244,18 +244,18 @@ module TodosHelper
|
|||
image_tag("blank.png", :title => t('todos.star_action'), :class => "todo_star" + (todo.starred? ? " starred" : ""), :id => "star_img_" + todo.id.to_s)
|
||||
end
|
||||
|
||||
def remote_toggle_checkbox(todo=@todo)
|
||||
def remote_toggle_checkbox(todo = @todo)
|
||||
check_box_tag("mark_complete_#{todo.id}", toggle_check_todo_path(todo), todo.completed?, :class => 'item-checkbox',
|
||||
:title => todo.pending? ? t('todos.blocked_by', :predecessors => todo.uncompleted_predecessors.to_a.map(&:description).join(', ')) : "", :readonly => todo.pending?)
|
||||
end
|
||||
|
||||
def remote_mobile_checkbox(todo=@todo)
|
||||
def remote_mobile_checkbox(todo = @todo)
|
||||
form_tag toggle_check_todo_path(@todo, :format => 'm'), :method => :put, :class => "mobile-done", :name => "mobile_complete_#{@todo.id}" do
|
||||
check_box_tag('_source_view', 'todo', @todo && @todo.completed?, "onClick" => "document.mobile_complete_#{@todo.id}.submit()")
|
||||
end
|
||||
end
|
||||
|
||||
def date_span(todo=@todo)
|
||||
def date_span(todo = @todo)
|
||||
if todo.completed?
|
||||
content_tag(:span, { :class => :grey }) { format_date( todo.completed_at ) }
|
||||
elsif todo.pending?
|
||||
|
@ -268,7 +268,7 @@ module TodosHelper
|
|||
end
|
||||
end
|
||||
|
||||
def successors_span(todo=@todo)
|
||||
def successors_span(todo = @todo)
|
||||
unless todo.pending_successors.empty?
|
||||
pending_count = todo.pending_successors.count
|
||||
title = "#{t('todos.has_x_pending', :count => pending_count)}: #{todo.pending_successors.to_a.map(&:description).join(', ')}"
|
||||
|
@ -276,7 +276,7 @@ module TodosHelper
|
|||
end
|
||||
end
|
||||
|
||||
def grip_span(todo=@todo)
|
||||
def grip_span(todo = @todo)
|
||||
unless todo.completed?
|
||||
image_tag('grip.png', :width => '7', :height => '16', :border => '0',
|
||||
:title => t('todos.drag_action_title'),
|
||||
|
@ -284,23 +284,23 @@ module TodosHelper
|
|||
end
|
||||
end
|
||||
|
||||
def tag_list_text(todo=@todo)
|
||||
def tag_list_text(todo = @todo)
|
||||
todo.tags.to_a.join(', ')
|
||||
end
|
||||
|
||||
def tag_span(tag, mobile=false)
|
||||
def tag_span(tag, mobile = false)
|
||||
content_tag(:span, :class => "tag #{tag.label}") { link_to(tag.name, tag_path(tag.name, :format => mobile ? :m : nil)) }
|
||||
end
|
||||
|
||||
def tag_list(todo=@todo, mobile=false)
|
||||
def tag_list(todo=@todo, mobile = false)
|
||||
content_tag(:span, :class => 'tags') { todo.tags.all_except_starred.collect{ |tag| tag_span(tag, mobile) }.join('').html_safe }
|
||||
end
|
||||
|
||||
def tag_list_mobile(todo=@todo)
|
||||
def tag_list_mobile(todo = @todo)
|
||||
todo.tags.all_except_starred.empty? ? "" : tag_list(todo, true)
|
||||
end
|
||||
|
||||
def deferred_due_date(todo=@todo)
|
||||
def deferred_due_date(todo = @todo)
|
||||
t('todos.action_due_on', :date => format_date(todo.due)) if todo.deferred? && todo.due
|
||||
end
|
||||
|
||||
|
@ -417,7 +417,7 @@ module TodosHelper
|
|||
# animation steps.
|
||||
# if the animation needs to be run inside the namespace of an object, set the
|
||||
# object_name to the name of the object and this name will be prepended to each step
|
||||
def render_animation(animation, object_name=nil)
|
||||
def render_animation(animation, object_name = nil)
|
||||
object_name += "." unless object_name.nil? # add dot if object_name is given
|
||||
|
||||
# concatenate all steps into functions that call functions
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class Dependency < ApplicationRecord
|
||||
# touch to make sure todo caches for predecessor and successor are invalidated
|
||||
belongs_to :predecessor, :foreign_key => 'predecessor_id', :class_name => 'Todo', :touch => true
|
||||
belongs_to :successor, :foreign_key => 'successor_id', :class_name => 'Todo', :touch => true
|
||||
belongs_to :successor, :foreign_key => 'successor_id', :class_name => 'Todo', :touch => true
|
||||
|
||||
validate :check_circular_dependencies
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class MessageGateway < ActionMailer::Base
|
|||
attachment = todo.attachments.build
|
||||
|
||||
# create temp file
|
||||
tmp = Tempfile.new(['attachment', '.eml'], {universal_newline: true})
|
||||
tmp = Tempfile.new(['attachment', '.eml'], { universal_newline: true })
|
||||
tmp.write email.raw_source.gsub(/\r/, "")
|
||||
|
||||
# add temp file to attachment. paperclip will copy the file to the right location
|
||||
|
@ -74,13 +74,13 @@ class MessageGateway < ActionMailer::Base
|
|||
end
|
||||
|
||||
def get_receiving_user_from_mail_header(email)
|
||||
user = get_receiving_user_from_sms_email( get_address(email) )
|
||||
user = get_receiving_user_from_sms_email(get_address(email))
|
||||
Rails.logger.info(user.nil? ? "User unknown": "Email belongs to #{user.login}")
|
||||
return user
|
||||
end
|
||||
|
||||
def get_address(email)
|
||||
return SITE_CONFIG['email_dispatch'] == 'to' ? email.to[0] : email.from[0]
|
||||
return SITE_CONFIG['email_dispatch'] == 'to' ? email.to[0] : email.from[0]
|
||||
end
|
||||
|
||||
def get_receiving_user_from_sms_email(address)
|
||||
|
@ -91,7 +91,7 @@ class MessageGateway < ActionMailer::Base
|
|||
end
|
||||
|
||||
def check_sender_is_in_mailmap(user, email)
|
||||
if user.present? and !sender_is_in_mailmap?(user,email)
|
||||
if user.present? && !sender_is_in_mailmap?(user, email)
|
||||
Rails.logger.warn "#{email.from[0]} not found in mailmap for #{user.login}"
|
||||
return false
|
||||
end
|
||||
|
@ -122,7 +122,7 @@ class MessageGateway < ActionMailer::Base
|
|||
parts = get_all_parts(email.parts)
|
||||
|
||||
# remove all parts that are not text/plain
|
||||
parts.reject{|part| !part.content_type.start_with?("text/plain") }
|
||||
parts.reject { |part| !part.content_type.start_with?("text/plain") }
|
||||
|
||||
return parts.count > 0 ? parts[0].decoded.strip : ""
|
||||
end
|
||||
|
|
|
@ -49,7 +49,7 @@ class Project < ApplicationRecord
|
|||
end
|
||||
|
||||
def set_last_reviewed_now
|
||||
self.last_reviewed = Time.now
|
||||
self.last_reviewed = Time.zone.now
|
||||
end
|
||||
|
||||
def set_completed_at_date
|
||||
|
@ -105,7 +105,7 @@ class Project < ApplicationRecord
|
|||
return !self.todos.deferred_or_blocked.exists? && !self.todos.active.exists?
|
||||
end
|
||||
|
||||
def shortened_name(length=40)
|
||||
def shortened_name(length = 40)
|
||||
name.truncate(length, :omission => "...").html_safe
|
||||
end
|
||||
|
||||
|
|
|
@ -44,9 +44,13 @@ module RecurringTodos
|
|||
|
||||
def xth(x)
|
||||
xth_day = [
|
||||
I18n.t('todos.recurrence.pattern.first'),I18n.t('todos.recurrence.pattern.second'),I18n.t('todos.recurrence.pattern.third'),
|
||||
I18n.t('todos.recurrence.pattern.fourth'),I18n.t('todos.recurrence.pattern.last')]
|
||||
x.nil? ? '??' : xth_day[x-1]
|
||||
I18n.t('todos.recurrence.pattern.first'),
|
||||
I18n.t('todos.recurrence.pattern.second'),
|
||||
I18n.t('todos.recurrence.pattern.third'),
|
||||
I18n.t('todos.recurrence.pattern.fourth'),
|
||||
I18n.t('todos.recurrence.pattern.last'),
|
||||
]
|
||||
x.nil? ? '??' : xth_day[x - 1]
|
||||
end
|
||||
|
||||
def day_of_week_as_text(day)
|
||||
|
@ -170,7 +174,7 @@ module RecurringTodos
|
|||
# takes start_from and previous into account.
|
||||
# offset needs to be 1.day for daily patterns or the start will be the
|
||||
# same day as the previous
|
||||
def determine_start(previous, offset=0.day)
|
||||
def determine_start(previous, offset = 0.day)
|
||||
start = self.start_from || NullTime.new
|
||||
if previous
|
||||
# check if the start_from date is later than previous. If so, use
|
||||
|
|
|
@ -32,7 +32,7 @@ module RecurringTodos
|
|||
get(:recurrence_selector) == 1 ? get(:every_other2) : 1
|
||||
end
|
||||
|
||||
def every_xth_day(default=nil)
|
||||
def every_xth_day(default = nil)
|
||||
get(:every_other3) || default
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ module RecurringTodos
|
|||
class RecurringTodosBuilder
|
||||
attr_reader :builder, :project, :context, :tag_list, :user
|
||||
|
||||
def initialize (user, attributes)
|
||||
def initialize(user, attributes)
|
||||
@user = user
|
||||
@attributes = Tracks::AttributeHandler.new(@user, attributes)
|
||||
|
||||
|
@ -60,7 +60,7 @@ module RecurringTodos
|
|||
end
|
||||
|
||||
def parse_dates
|
||||
%w{end_date start_from}.each {|date| @attributes.parse_date date }
|
||||
%w{end_date start_from}.each { |date| @attributes.parse_date date }
|
||||
end
|
||||
|
||||
def parse_project
|
||||
|
|
|
@ -41,7 +41,7 @@ module RecurringTodos
|
|||
|
||||
# we did not find anything this week, so check the nth next, starting from
|
||||
# sunday
|
||||
start = start + self.every_x_week.week - (start.wday()).days
|
||||
start = start + self.every_x_week.week - (start.wday).days
|
||||
|
||||
start = find_first_day_in_this_week(start)
|
||||
return start unless start == -1
|
||||
|
@ -56,7 +56,7 @@ module RecurringTodos
|
|||
return self.start_from || Time.zone.now
|
||||
else
|
||||
start = previous + 1.day
|
||||
if start.wday() == 0
|
||||
if start.wday == 0
|
||||
# we went to a new week, go to the nth next week and find first match
|
||||
# that week. Note that we already went into the next week, so -1
|
||||
start += (every_x_week - 1).week
|
||||
|
@ -72,8 +72,8 @@ module RecurringTodos
|
|||
|
||||
def find_first_day_in_this_week(start)
|
||||
# check if there are any days left this week for the next todo
|
||||
start.wday().upto 6 do |i|
|
||||
return start + (i - start.wday()).days if on_xday(i)
|
||||
start.wday.upto 6 do |i|
|
||||
return start + (i - start.wday).days if on_xday(i)
|
||||
end
|
||||
-1
|
||||
end
|
||||
|
|
|
@ -81,7 +81,7 @@ module RecurringTodos
|
|||
if start.month > month || (start.month == month && start.day >= every_x_day)
|
||||
# if there is no next month n and day m in this year, search in next
|
||||
# year
|
||||
start = Time.zone.local(start.year+1, month, 1)
|
||||
start = Time.zone.local(start.year + 1, month, 1)
|
||||
else
|
||||
# if there is a next month n, stay in this year
|
||||
start = Time.zone.local(start.year, month, 1)
|
||||
|
@ -91,14 +91,14 @@ module RecurringTodos
|
|||
|
||||
def get_relative_weekday_of_month(start, month)
|
||||
# if there is no next month n in this year, search in next year
|
||||
the_next = start.month > month ? Time.zone.local(start.year+1, month, 1) : start
|
||||
the_next = start.month > month ? Time.zone.local(start.year + 1, month, 1) : start
|
||||
|
||||
# get the xth day of the month
|
||||
the_next = get_xth_day_of_month(self.every_xth_day, day_of_week, month, the_next.year)
|
||||
|
||||
# if the_next is before previous, we went back into the past, so try next
|
||||
# year
|
||||
the_next = get_xth_day_of_month(self.every_xth_day, day_of_week, month, start.year+1) if the_next <= start
|
||||
the_next = get_xth_day_of_month(self.every_xth_day, day_of_week, month, start.year + 1) if the_next <= start
|
||||
|
||||
the_next
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ module RecurringTodos
|
|||
end
|
||||
|
||||
def get_recurrence_selector
|
||||
@selector=='yearly_every_x_day' ? 0 : 1
|
||||
@selector == 'yearly_every_x_day' ? 0 : 1
|
||||
end
|
||||
|
||||
def get_every_other2
|
||||
|
|
|
@ -89,7 +89,7 @@ module Stats
|
|||
created_count_array = Array.new(30) { |i| @actions_created_last30days.size / 30.0 }
|
||||
done_count_array = Array.new(30) { |i| @actions_done_last30days.size / 30.0 }
|
||||
# TODO: make the strftime i18n proof
|
||||
time_labels = Array.new(30) { |i| I18n.l(Time.zone.now-i.days, :format => :stats) }
|
||||
time_labels = Array.new(30) { |i| I18n.l(Time.zone.now - i.days, :format => :stats) }
|
||||
|
||||
return {
|
||||
datasets: [
|
||||
|
@ -103,11 +103,11 @@ module Stats
|
|||
end
|
||||
|
||||
def completion_time_data
|
||||
@actions_completion_time = @user.todos.completed.select("completed_at, created_at").reorder("completed_at DESC" )
|
||||
@actions_completion_time = @user.todos.completed.select("completed_at, created_at").reorder("completed_at DESC")
|
||||
|
||||
# convert to array and fill in non-existing weeks with 0
|
||||
@max_weeks = @actions_completion_time.last ? difference_in_weeks(@today, @actions_completion_time.last.completed_at) : 1
|
||||
@actions_completed_per_week_array = convert_to_weeks_running_array(@actions_completion_time, @max_weeks+1)
|
||||
@actions_completed_per_week_array = convert_to_weeks_running_array(@actions_completion_time, @max_weeks + 1)
|
||||
|
||||
# stop the chart after 10 weeks
|
||||
@count = [10, @max_weeks].min
|
||||
|
@ -119,7 +119,7 @@ module Stats
|
|||
# get percentage done cumulative
|
||||
@cum_percent_done = convert_to_cumulative_array(@actions_completion_time_array, @actions_completion_time.count(:all))
|
||||
|
||||
time_labels = Array.new(@count) { |i| "#{i}-#{i+1}" }
|
||||
time_labels = Array.new(@count) { |i| "#{i}-#{i + 1}" }
|
||||
time_labels[0] = I18n.t('stats.within_one')
|
||||
time_labels[@count] = "> #{@count}"
|
||||
|
||||
|
@ -137,7 +137,7 @@ module Stats
|
|||
|
||||
# convert to array and fill in non-existing weeks with 0
|
||||
@max_weeks = difference_in_weeks(@today, @actions_running_time.last.created_at)
|
||||
@actions_running_per_week_array = convert_to_weeks_from_today_array(@actions_running_time, @max_weeks+1, :created_at)
|
||||
@actions_running_per_week_array = convert_to_weeks_from_today_array(@actions_running_time, @max_weeks + 1, :created_at)
|
||||
|
||||
# cut off chart at 52 weeks = one year
|
||||
@count = [52, @max_weeks].min
|
||||
|
@ -147,9 +147,9 @@ module Stats
|
|||
@max_actions = @actions_running_time_array.max
|
||||
|
||||
# get percentage done cumulative
|
||||
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count )
|
||||
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count)
|
||||
|
||||
time_labels = Array.new(@count) { |i| "#{i}-#{i+1}" }
|
||||
time_labels = Array.new(@count) { |i| "#{i}-#{i + 1}" }
|
||||
time_labels[0] = "< 1"
|
||||
time_labels[@count] = "> #{@count}"
|
||||
|
||||
|
@ -186,9 +186,9 @@ module Stats
|
|||
@max_actions = @actions_running_time_array.max
|
||||
|
||||
# get percentage done cumulative
|
||||
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count )
|
||||
@cum_percent_done = convert_to_cumulative_array(@actions_running_time_array, @actions_running_time.count)
|
||||
|
||||
time_labels = Array.new(@count) { |i| "#{i}-#{i+1}" }
|
||||
time_labels = Array.new(@count) { |i| "#{i}-#{i + 1}" }
|
||||
time_labels[0] = "< 1"
|
||||
time_labels[@count] = "> #{@count}"
|
||||
|
||||
|
@ -211,10 +211,10 @@ module Stats
|
|||
# cut off chart at 52 weeks = one year
|
||||
@count = [52, @max_weeks].min
|
||||
|
||||
@actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks+1)
|
||||
@actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks + 1)
|
||||
@actions_open_per_week_array = cut_off_array(@actions_open_per_week_array, @count)
|
||||
|
||||
time_labels = Array.new(@count+1) { |i| "#{i}-#{i+1}" }
|
||||
time_labels = Array.new(@count + 1) { |i| "#{i}-#{i + 1}" }
|
||||
time_labels[0] = "< 1"
|
||||
|
||||
return {
|
||||
|
@ -252,7 +252,7 @@ module Stats
|
|||
@actions_completion_day = @user.todos.completed_after(@cut_off_month).select("completed_at")
|
||||
|
||||
# convert to hash to be able to fill in non-existing days
|
||||
@max=0
|
||||
@max = 0
|
||||
@actions_creation_day_array = Array.new(7) { |i| 0 }
|
||||
@actions_creation_day.each { |r| @actions_creation_day_array[r.created_at.wday] += 1 }
|
||||
|
||||
|
@ -275,11 +275,11 @@ module Stats
|
|||
|
||||
# convert to hash to be able to fill in non-existing days
|
||||
@actions_creation_hour_array = Array.new(24) { |i| 0 }
|
||||
@actions_creation_hour.each{|r| @actions_creation_hour_array[r.created_at.hour] += 1 }
|
||||
@actions_creation_hour.each { |r| @actions_creation_hour_array[r.created_at.hour] += 1 }
|
||||
|
||||
# convert to hash to be able to fill in non-existing days
|
||||
@actions_completion_hour_array = Array.new(24) { |i| 0 }
|
||||
@actions_completion_hour.each{|r| @actions_completion_hour_array[r.completed_at.hour] += 1 }
|
||||
@actions_completion_hour.each { |r| @actions_completion_hour_array[r.completed_at.hour] += 1 }
|
||||
|
||||
return {
|
||||
datasets: [
|
||||
|
@ -296,11 +296,11 @@ module Stats
|
|||
|
||||
# convert to hash to be able to fill in non-existing days
|
||||
@actions_creation_hour_array = Array.new(24) { |i| 0 }
|
||||
@actions_creation_hour.each{|r| @actions_creation_hour_array[r.created_at.hour] += 1 }
|
||||
@actions_creation_hour.each { |r| @actions_creation_hour_array[r.created_at.hour] += 1 }
|
||||
|
||||
# convert to hash to be able to fill in non-existing days
|
||||
@actions_completion_hour_array = Array.new(24) { |i| 0 }
|
||||
@actions_completion_hour.each{|r| @actions_completion_hour_array[r.completed_at.hour] += 1 }
|
||||
@actions_completion_hour.each { |r| @actions_completion_hour_array[r.completed_at.hour] += 1 }
|
||||
|
||||
return {
|
||||
datasets: [
|
||||
|
@ -393,7 +393,7 @@ module Stats
|
|||
# calculate fractions
|
||||
a = Array.new(array.size) {|i| array[i] * 100.0 / max}
|
||||
# make cumulative
|
||||
1.upto(array.size-1) { |i| a[i] += a[i - 1] }
|
||||
1.upto(array.size - 1) { |i| a[i] += a[i - 1] }
|
||||
return a
|
||||
end
|
||||
|
||||
|
@ -412,7 +412,7 @@ module Stats
|
|||
end
|
||||
|
||||
def three_month_avg(set, i)
|
||||
(set.fetch(i) { 0 } + set.fetch(i+1) { 0 } + set.fetch(i + 2) { 0 }) / 3.0
|
||||
(set.fetch(i) { 0 } + set.fetch(i + 1) { 0 } + set.fetch(i + 2) { 0 }) / 3.0
|
||||
end
|
||||
|
||||
def set_three_month_avg(set, upper_bound)
|
||||
|
@ -421,14 +421,14 @@ module Stats
|
|||
|
||||
def compute_running_avg_array(set, upper_bound)
|
||||
result = set_three_month_avg(set, upper_bound)
|
||||
result[upper_bound - 1] = result[upper_bound-1] * 3 if upper_bound == set.length
|
||||
result[upper_bound - 2] = result[upper_bound-2] * 3 / 2 if upper_bound > 1 and upper_bound == set.length
|
||||
result[upper_bound - 1] = result[upper_bound - 1] * 3 if upper_bound == set.length
|
||||
result[upper_bound - 2] = result[upper_bound - 2] * 3 / 2 if upper_bound > 1 and upper_bound == set.length
|
||||
result[0] = "null"
|
||||
result
|
||||
end # unsolved, not triggered, edge case for set.length == upper_bound + 1
|
||||
|
||||
def month_label(i)
|
||||
I18n.t('date.month_names')[(Time.zone.now.mon - i -1 ) % 12 + 1]
|
||||
I18n.t('date.month_names')[(Time.zone.now.mon - i - 1) % 12 + 1]
|
||||
end
|
||||
|
||||
def array_of_month_labels(count)
|
||||
|
|
|
@ -32,7 +32,7 @@ module Stats
|
|||
end
|
||||
|
||||
def counts
|
||||
@counts ||= tags.map { |t| t.count }
|
||||
@counts ||= tags.map(&:count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,8 +64,8 @@ class Todo < ApplicationRecord
|
|||
where('todos.due > ? AND todos.due <= ?', start_date, end_date)
|
||||
end
|
||||
|
||||
STARRED_TAG_NAME = "starred"
|
||||
DEFAULT_INCLUDES = [:project, :context, :tags, :taggings, :pending_successors, :uncompleted_predecessors, :recurring_todo]
|
||||
STARRED_TAG_NAME = "starred".freeze
|
||||
DEFAULT_INCLUDES = [:project, :context, :tags, :taggings, :pending_successors, :uncompleted_predecessors, :recurring_todo].freeze
|
||||
|
||||
# state machine
|
||||
include AASM
|
||||
|
@ -149,7 +149,7 @@ class Todo < ApplicationRecord
|
|||
end
|
||||
|
||||
def save_predecessors
|
||||
unless @predecessor_array.nil? # Only save predecessors if they changed
|
||||
unless @predecessor_array.nil? # Only save predecessors if they changed
|
||||
current_array = self.predecessors
|
||||
remove_array = current_array - @predecessor_array
|
||||
add_array = @predecessor_array - current_array
|
||||
|
@ -245,7 +245,7 @@ class Todo < ApplicationRecord
|
|||
end
|
||||
|
||||
def toggle_star!
|
||||
self.starred= !starred?
|
||||
self.starred = !starred?
|
||||
end
|
||||
|
||||
def starred=(starred)
|
||||
|
@ -313,7 +313,7 @@ class Todo < ApplicationRecord
|
|||
alias_method :original_context=, :context=
|
||||
def context=(value)
|
||||
if value.is_a? Context
|
||||
self.original_context=(value)
|
||||
self.original_context = (value)
|
||||
else
|
||||
c = Context.where(:name => value[:name]).first
|
||||
c = Context.create(value) if c.nil?
|
||||
|
|
|
@ -14,8 +14,8 @@ module Todos
|
|||
not_done_todos = current_user.todos.active.not_hidden
|
||||
end
|
||||
|
||||
not_done_todos = not_done_todos.
|
||||
reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
|
||||
not_done_todos = not_done_todos
|
||||
.reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
|
||||
not_done_todos = not_done_todos.limit(sanitize(params[:limit])) if params[:limit]
|
||||
|
|
|
@ -13,60 +13,69 @@ class User < ApplicationRecord
|
|||
def find_by_params(params)
|
||||
find(params['id'] || params['context_id']) || nil
|
||||
end
|
||||
|
||||
def update_positions(context_ids)
|
||||
context_ids.each_with_index {|id, position|
|
||||
context = self.detect { |c| c.id == id.to_i }
|
||||
raise I18n.t('models.user.error_context_not_associated', :context => id, :user => @user.id) if context.nil?
|
||||
context.update_attribute(:position, position + 1)
|
||||
}
|
||||
end
|
||||
context_ids.each_with_index { |id, position|
|
||||
context = self.detect { |c| c.id == id.to_i }
|
||||
raise I18n.t('models.user.error_context_not_associated', :context => id, :user => @user.id) if context.nil?
|
||||
context.update_attribute(:position, position + 1)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
has_many(:projects, -> { order 'projects.position ASC' }, dependent: :delete_all) do
|
||||
def find_by_params(params)
|
||||
find(params['id'] || params['project_id'])
|
||||
end
|
||||
|
||||
def update_positions(project_ids)
|
||||
project_ids.each_with_index {|id, position|
|
||||
project_ids.each_with_index { |id, position|
|
||||
project = self.find_by(id: id.to_i)
|
||||
raise I18n.t('models.user.error_project_not_associated', :project => id, :user => @user.id) if project.nil?
|
||||
project.update_attribute(:position, position + 1)
|
||||
}
|
||||
end
|
||||
|
||||
def projects_in_state_by_position(state)
|
||||
self.select{ |p| p.state == state }.sort_by{ |p| p.position }
|
||||
self.select { |p| p.state == state }.sort_by { |p| p.position }
|
||||
end
|
||||
|
||||
def next_from(project)
|
||||
self.offset_from(project, 1)
|
||||
end
|
||||
|
||||
def previous_from(project)
|
||||
self.offset_from(project, -1)
|
||||
end
|
||||
|
||||
def offset_from(project, offset)
|
||||
projects = self.projects_in_state_by_position(project.state)
|
||||
position = projects.index(project)
|
||||
return nil if position == 0 && offset < 0
|
||||
projects.at(position + offset)
|
||||
end
|
||||
|
||||
def cache_note_counts
|
||||
project_note_counts = Note.group(:project_id).count
|
||||
self.each do |project|
|
||||
project.cached_note_count = project_note_counts[project.id] || 0
|
||||
end
|
||||
end
|
||||
|
||||
def alphabetize(scope_conditions = {})
|
||||
projects = where(scope_conditions)
|
||||
projects = projects.sort_by { |project| project.name.downcase }
|
||||
self.update_positions(projects.map{ |p| p.id })
|
||||
self.update_positions(projects.map(&:id))
|
||||
return projects
|
||||
end
|
||||
|
||||
def actionize(scope_conditions = {})
|
||||
todos_in_project = where(scope_conditions).includes(:todos)
|
||||
todos_in_project = todos_in_project.sort_by { |x| [-x.todos.active.count, -x.id] }
|
||||
todos_in_project.reject{ |p| p.todos.active.count > 0 }
|
||||
sorted_project_ids = todos_in_project.map { |p| p.id }
|
||||
todos_in_project.reject { |p| p.todos.active.count > 0 }
|
||||
sorted_project_ids = todos_in_project.map(&:id)
|
||||
|
||||
all_project_ids = self.map { |p| p.id }
|
||||
all_project_ids = self.map(&:id)
|
||||
other_project_ids = all_project_ids - sorted_project_ids
|
||||
|
||||
update_positions(sorted_project_ids + other_project_ids)
|
||||
|
@ -76,9 +85,9 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
has_many(:todos, -> { order 'todos.completed_at DESC, todos.created_at DESC' }, dependent: :delete_all) do
|
||||
def count_by_group(g)
|
||||
except(:order).group(g).count
|
||||
end
|
||||
def count_by_group(g)
|
||||
except(:order).group(g).count
|
||||
end
|
||||
end
|
||||
|
||||
has_many :recurring_todos,
|
||||
|
@ -89,9 +98,9 @@ class User < ApplicationRecord
|
|||
-> { where('state = ?', 'deferred')
|
||||
.order('show_from ASC, todos.created_at DESC') },
|
||||
:class_name => 'Todo') do
|
||||
def find_and_activate_ready
|
||||
where('show_from <= ?', Time.current).collect { |t| t.activate! }
|
||||
end
|
||||
def find_and_activate_ready
|
||||
where('show_from <= ?', Time.current).collect { |t| t.activate! }
|
||||
end
|
||||
end
|
||||
|
||||
has_many :tags, dependent: :delete_all
|
||||
|
@ -157,7 +166,7 @@ class User < ApplicationRecord
|
|||
"#{first_name} #{last_name}"
|
||||
end
|
||||
|
||||
def change_password(pass,pass_confirm)
|
||||
def change_password(pass, pass_confirm)
|
||||
self.password = pass
|
||||
self.password_confirmation = pass_confirm
|
||||
save!
|
||||
|
|
|
@ -8,7 +8,7 @@ module Common
|
|||
end
|
||||
|
||||
def self.like_operator
|
||||
# This is something of a hack to use the correct operator for Pg
|
||||
# HACK: This is something of a hack to use the correct operator for Pg
|
||||
if ActiveRecord::Base.connection.adapter_name.downcase.to_sym == :postgresql
|
||||
like = 'ILIKE'
|
||||
else
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
class DoneTodos
|
||||
|
||||
|
||||
def self.done_todos_for_container(todos)
|
||||
completed_todos = todos.completed
|
||||
return done_today(completed_todos), done_rest_of_week(completed_todos), done_rest_of_month(completed_todos)
|
||||
end
|
||||
|
||||
def self.done_today(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
def self.done_today(todos, includes={ :include => Todo::DEFAULT_INCLUDES })
|
||||
# TODO: refactor to remove outer hash from includes param
|
||||
todos.completed_after(beginning_of_day).includes(includes[:include])
|
||||
end
|
||||
|
||||
def self.done_rest_of_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
def self.done_rest_of_week(todos, includes={ :include => Todo::DEFAULT_INCLUDES })
|
||||
done_between(todos, includes, beginning_of_day, beginning_of_week)
|
||||
end
|
||||
|
||||
def self.done_rest_of_month(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
def self.done_rest_of_month(todos, includes={ :include => Todo::DEFAULT_INCLUDES })
|
||||
done_between(todos, includes, beginning_of_week, beginning_of_month)
|
||||
end
|
||||
|
||||
def self.completed_period(date)
|
||||
return nil if date.nil?
|
||||
return nil if date.nil?
|
||||
|
||||
return "today" if date >= end_of_day # treat todos with completed_at in future as done today (happens in tests)
|
||||
return "today" if date.between?(beginning_of_day, end_of_day)
|
||||
|
@ -57,5 +55,4 @@ class DoneTodos
|
|||
def self.beginning_of_month
|
||||
Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
# These methods are adapted from has_many_polymorphs' tagging_extensions
|
||||
|
||||
module IsTaggable
|
||||
|
||||
def self.included(klass)
|
||||
klass.class_eval do
|
||||
|
||||
# Add tags associations
|
||||
has_many :taggings, :as => :taggable
|
||||
has_many :tags, :through => :taggings do
|
||||
def to_s
|
||||
self.to_a.map(&:name).sort.join(Tag::JOIN_DELIMITER)
|
||||
end
|
||||
|
||||
def all_except_starred
|
||||
self.to_a.reject{|tag| tag.name == Todo::STARRED_TAG_NAME}
|
||||
self.to_a.reject { |tag| tag.name == Todo::STARRED_TAG_NAME }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require_dependency "user"
|
||||
|
||||
module LoginSystem
|
||||
|
||||
def current_user
|
||||
get_current_user
|
||||
end
|
||||
|
@ -97,7 +96,6 @@ module LoginSystem
|
|||
# def authorize?(user)
|
||||
#
|
||||
def login_required
|
||||
|
||||
if not protect?(action_name)
|
||||
return true
|
||||
end
|
||||
|
@ -125,7 +123,6 @@ module LoginSystem
|
|||
end
|
||||
|
||||
def login_optional
|
||||
|
||||
login_from_cookie
|
||||
|
||||
if session['user_id'] and authorize?(get_current_user)
|
||||
|
@ -189,7 +186,6 @@ module LoginSystem
|
|||
|
||||
# HTTP Basic auth code adapted from Coda Hale's simple_http_auth plugin. Thanks, Coda!
|
||||
def get_basic_auth_data
|
||||
|
||||
auth_locations = ['REDIRECT_REDIRECT_X_HTTP_AUTHORIZATION',
|
||||
'REDIRECT_X_HTTP_AUTHORIZATION',
|
||||
'X-HTTP_AUTHORIZATION', 'HTTP_AUTHORIZATION']
|
||||
|
@ -216,7 +212,7 @@ module LoginSystem
|
|||
render :body => t('login.unsuccessful'), :status => 401
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
# Redirect the user to the login page.
|
||||
def redirect_to_login
|
||||
|
@ -226,5 +222,4 @@ private
|
|||
format.m { redirect_to login_path(:format => 'm') }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'active_support/all'
|
|||
require 'user_time'
|
||||
|
||||
class Staleness
|
||||
SECONDS_PER_DAY = 86400
|
||||
SECONDS_PER_DAY = 86_400
|
||||
|
||||
def self.days_stale(item, current_user)
|
||||
return 0 if cannot_be_stale(item, current_user)
|
||||
|
@ -15,4 +15,3 @@ class Staleness
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
module Tracks
|
||||
|
||||
class AttributeHandler
|
||||
attr_reader :attributes
|
||||
|
||||
|
@ -10,7 +9,7 @@ module Tracks
|
|||
end
|
||||
|
||||
def get(attribute)
|
||||
@attributes[attribute.to_sym]
|
||||
@attributes[attribute.to_sym]
|
||||
end
|
||||
|
||||
def [](attribute)
|
||||
|
@ -37,7 +36,7 @@ module Tracks
|
|||
@attributes.key?(key.to_sym)
|
||||
end
|
||||
|
||||
def selector_key_present?(key)
|
||||
def selector_key_present?(key)
|
||||
key?(key)
|
||||
end
|
||||
|
||||
|
@ -78,9 +77,9 @@ module Tracks
|
|||
object = relation.build(:name => name)
|
||||
new_object_created = true
|
||||
end
|
||||
|
||||
|
||||
return object, new_object_created
|
||||
end
|
||||
end
|
||||
|
||||
def specified_by_name?(object_type)
|
||||
self.send("#{object_type}_specified_by_name?")
|
||||
|
@ -115,25 +114,23 @@ module Tracks
|
|||
ActionController::Parameters.new(attributes).permit(
|
||||
:context, :project,
|
||||
# model attributes
|
||||
:context_id, :project_id, :description, :notes, :state, :start_from,
|
||||
:context_id, :project_id, :description, :notes, :state, :start_from,
|
||||
:ends_on, :end_date, :number_of_occurrences, :occurrences_count, :target,
|
||||
:show_from_delta, :recurring_period, :recurrence_selector, :every_other1,
|
||||
:every_other2, :every_other3, :every_day, :only_work_days, :every_count,
|
||||
:show_from_delta, :recurring_period, :recurrence_selector, :every_other1,
|
||||
:every_other2, :every_other3, :every_day, :only_work_days, :every_count,
|
||||
:weekday, :show_always, :context_name, :project_name, :tag_list,
|
||||
# form attributes
|
||||
:recurring_period, :daily_selector, :monthly_selector, :yearly_selector,
|
||||
:recurring_target, :daily_every_x_days, :monthly_day_of_week,
|
||||
:monthly_every_x_day, :monthly_every_x_month2, :monthly_every_x_month,
|
||||
:monthly_every_xth_day, :recurring_show_days_before,
|
||||
:recurring_period, :daily_selector, :monthly_selector, :yearly_selector,
|
||||
:recurring_target, :daily_every_x_days, :monthly_day_of_week,
|
||||
:monthly_every_x_day, :monthly_every_x_month2, :monthly_every_x_month,
|
||||
:monthly_every_xth_day, :recurring_show_days_before,
|
||||
:recurring_show_always, :weekly_every_x_week, :weekly_return_monday,
|
||||
:yearly_day_of_week, :yearly_every_x_day, :yearly_every_xth_day,
|
||||
:yearly_day_of_week, :yearly_every_x_day, :yearly_every_xth_day,
|
||||
:yearly_month_of_year2, :yearly_month_of_year,
|
||||
# derived attributes
|
||||
:weekly_return_monday, :weekly_return_tuesday, :weekly_return_wednesday,
|
||||
:weekly_return_monday, :weekly_return_tuesday, :weekly_return_wednesday,
|
||||
:weekly_return_thursday, :weekly_return_friday, :weekly_return_saturday, :weekly_return_sunday
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
module Tracks
|
||||
|
||||
class Config
|
||||
|
||||
def self.auth_schemes
|
||||
SITE_CONFIG['authentication_schemes'] || []
|
||||
end
|
||||
|
||||
|
||||
def self.openid_enabled?
|
||||
auth_schemes.include?('open_id')
|
||||
end
|
||||
|
@ -13,7 +11,7 @@ module Tracks
|
|||
def self.cas_enabled?
|
||||
auth_schemes.include?('cas')
|
||||
end
|
||||
|
||||
|
||||
def self.prefered_auth?
|
||||
if SITE_CONFIG['prefered_auth']
|
||||
SITE_CONFIG['prefered_auth']
|
||||
|
@ -21,7 +19,5 @@ module Tracks
|
|||
auth_schemes.first
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
# Inspiration from Bruce Williams [http://codefluency.com/articles/2006/07/01/rails-views-getting-in-context/]
|
||||
module Tracks
|
||||
|
||||
module SourceViewSwitching
|
||||
|
||||
class Responder
|
||||
|
||||
def initialize(source_view)
|
||||
@source_view = source_view.underscore.gsub(/\s+/,'_').to_sym rescue nil
|
||||
end
|
||||
|
||||
|
||||
def nil?
|
||||
yield if @source_view.nil? && block_given?
|
||||
end
|
||||
|
@ -16,53 +13,46 @@ module Tracks
|
|||
def context
|
||||
yield if :context == @source_view && block_given?
|
||||
end
|
||||
|
||||
def method_missing(check_source_view,*args)
|
||||
|
||||
def method_missing(check_source_view, *args)
|
||||
yield if check_source_view == @source_view && block_given?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
module Controller
|
||||
|
||||
def self.included(base)
|
||||
base.send(:helper, Tracks::SourceViewSwitching::Helper)
|
||||
base.send(:helper_method, :source_view)
|
||||
end
|
||||
|
||||
def source_view_is( s )
|
||||
|
||||
def source_view_is(s)
|
||||
s == (params[:_source_view] || @source_view).to_sym
|
||||
end
|
||||
|
||||
def source_view_is_one_of( *s )
|
||||
|
||||
def source_view_is_one_of(*s)
|
||||
s.include?(params[:_source_view].to_sym)
|
||||
end
|
||||
|
||||
|
||||
def source_view
|
||||
responder = Tracks::SourceViewSwitching::Responder.new(params[:_source_view] || @source_view)
|
||||
block_given? ? yield(responder) : responder
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
module Helper
|
||||
|
||||
def source_view_tag(name)
|
||||
hidden_field_tag :_source_view, name.underscore.gsub(/\s+/,'_')
|
||||
end
|
||||
|
||||
def source_view_is( s )
|
||||
|
||||
def source_view_is(s)
|
||||
s == (params[:_source_view] || @source_view).to_sym
|
||||
end
|
||||
|
||||
def source_view_is_one_of( *s )
|
||||
|
||||
def source_view_is_one_of(*s)
|
||||
s.include?((params[:_source_view] || @source_view).to_sym)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ActionController::Base.send(:include, Tracks::SourceViewSwitching::Controller)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue