Module: TaskwarriorWeb::App::Helpers
- Defined in:
- lib/taskwarrior-web/helpers.rb
Instance Method Summary collapse
- #authorized? ⇒ Boolean
- #auto_link(text) ⇒ Object
- #badge_count ⇒ Object
- #colorize_date(timestamp) ⇒ Object
- #crud_links(task) ⇒ Object
- #flash_types ⇒ Object
- #format_date(timestamp) ⇒ Object
- #linkify(item) ⇒ Object
- #progress_bar(tasks) ⇒ Object
-
#protected! ⇒ Object
Authentication.
- #task_count ⇒ Object
- #unlinkify(item) ⇒ Object
Instance Method Details
#authorized? ⇒ Boolean
78 79 80 81 82 |
# File 'lib/taskwarrior-web/helpers.rb', line 78 def @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 |
#auto_link(text) ⇒ Object
29 30 31 |
# File 'lib/taskwarrior-web/helpers.rb', line 29 def auto_link(text) Rinku.auto_link(text, :all, 'target="_blank"') end |
#badge_count ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/taskwarrior-web/helpers.rb', line 46 def badge_count if filter = TaskwarriorWeb::Config.property('task-web.filter.badge') total = TaskwarriorWeb::Task.query(filter).count else total = task_count end total == 0 ? '' : total.to_s end |
#colorize_date(timestamp) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/taskwarrior-web/helpers.rb', line 9 def colorize_date() return if .nil? due_def = (TaskwarriorWeb::Config.due || 7).to_i date = Date.parse() 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) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/taskwarrior-web/helpers.rb', line 64 def crud_links(task) string = %(<span class="crud-links">) string << %(<a href="/tasks/#{task.uuid}"><i class="icon-pencil"></i></a>) string << %( | ) string << %(<a href="/tasks/#{task.uuid}/delete"><i class="icon-trash"></i></a>) string << %(</span>) string end |
#flash_types ⇒ Object
33 34 35 |
# File 'lib/taskwarrior-web/helpers.rb', line 33 def flash_types [:success, :info, :warning, :error] end |
#format_date(timestamp) ⇒ Object
4 5 6 7 |
# File 'lib/taskwarrior-web/helpers.rb', line 4 def format_date() format = TaskwarriorWeb::Config.dateformat || '%-m/%-d/%Y' Time.parse().localtime.strftime(format) end |
#linkify(item) ⇒ Object
21 22 23 |
# File 'lib/taskwarrior-web/helpers.rb', line 21 def linkify(item) item.gsub('.', '--') unless item.nil? unless item.nil? end |
#progress_bar(tasks) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/taskwarrior-web/helpers.rb', line 55 def (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! ⇒ Object
Authentication
74 75 76 |
# File 'lib/taskwarrior-web/helpers.rb', line 74 def protected! response['WWW-Authenticate'] = %(Basic realm="Taskworrior Web") and throw(:halt, [401, "Not authorized\n"]) and return unless end |
#task_count ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/taskwarrior-web/helpers.rb', line 37 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) ⇒ Object
25 26 27 |
# File 'lib/taskwarrior-web/helpers.rb', line 25 def unlinkify(item) item.gsub('--', '.') unless item.nil? end |