module TaskwarriorWeb::App::Helpers
Public Instance Methods
auto_link(text)
click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 33 def auto_link(text) Rinku.auto_link(text, :all, 'target="_blank"') 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
crud_links(task)
click to toggle source
# File lib/taskwarrior-web/helpers.rb, line 68 def crud_links(task) string = %(<span class="crud-links">) string << %(<a class="annotation-add" href="/tasks/#{task.uuid}/annotations/new"><i class="icon-comment"></i></a>) string << %( | ) string << %(<a href="/tasks/#{task.uuid}?destination=#{ERB::Util.u(request.path_info)}"><i class="icon-pencil"></i></a>) string << %( | ) string << %(<a href="/tasks/#{task.uuid}?destination=#{ERB::Util.u(request.path_info)}" data-method="DELETE" data-confirm="Are you sure you want to delete this task?"><i class="icon-trash"></i></a>) string << %(</span>) string 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
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> #{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