module TaskwarriorWeb::App::Helpers

Public Instance Methods

authorized?() click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 84
def authorized?
  @auth ||=  Rack::Auth::Basic::Request.new(request.env)
  values = [TaskwarriorWeb::Config.property('task-web.user'), TaskwarriorWeb::Config.property('task-web.passwd')]
  @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == values
end
badge_count() click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 50
def badge_count
  if filter = TaskwarriorWeb::Config.property('task-web.filter.badge')
    total = TaskwarriorWeb::Task.query(filter).count
  else
    total = task_count
  end
  total.to_i == 0 ? '' : total.to_s
end
colorize_date(timestamp) click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 13
def colorize_date(timestamp)
  return if timestamp.nil?
  due_def = (TaskwarriorWeb::Config.due || 7).to_i
  date = Date.parse(timestamp)
  case
    when Date.today == date then 'warning'                            # today
    when Date.today > date then 'error'                               # overdue
    when Date.today.advance(:days => due_def) >= date then 'success'  # within the "due" range
    else 'regular'                                                    # just a regular task
  end
end
flash_types() click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 37
def flash_types
  [:success, :info, :warning, :error]
end
format_date(timestamp) click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 4
def format_date(timestamp)
  format = TaskwarriorWeb::Config.dateformat || '%-m/%-d/%Y'
  Time.parse(timestamp).localtime.strftime(format)
end
format_tags(tags) click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 9
def format_tags(tags)
  tags.join(', ')
end
linkify(item) click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 25
def linkify(item)
  item.gsub('.', '--') unless item.nil? unless item.nil?
end
progress_bar(tasks) click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 59
def progress_bar(tasks)
  return 0 if tasks.empty?
  doneness = (tasks.select { |t| t.status == 'completed' }.count.to_f / tasks.count.to_f) * 100
  string = %(<div class="progress progress-striped">)
  string << %(<div class="bar" style="width: #{doneness.to_i}%;"></div>&nbsp;#{doneness.to_i}%)
  string << %(</div>)
  string
end
protected!() click to toggle source

Authentication

# File lib/taskwarrior-web/helpers.rb, line 80
def protected!
  response['WWW-Authenticate'] = %(Basic realm="Taskwarrior Web") and throw(:halt, [401, "Not authorized\n"]) and return unless authorized?
end
sync() click to toggle source

Syncronise the local task database with the server

# File lib/taskwarrior-web/helpers.rb, line 92
def sync
  TaskwarriorWeb::Command.new(:sync, nil, nil).run
end
task_count() click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 41
def task_count
  if filter = TaskwarriorWeb::Config.property('task-web.filter')
    total = TaskwarriorWeb::Task.query(filter).count
  else
    total = TaskwarriorWeb::Task.count(:status => :pending)
  end
  total.to_s
end
unlinkify(item) click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 29
def unlinkify(item)
  item.gsub('--', '.') unless item.nil?
end