module Tempo::Views
Public Class Methods
already_exists_error(item, request)
click to toggle source
# File lib/tempo/views/base.rb, line 73 def already_exists_error(item, request) ViewRecords::Message.new "#{item} '#{request}' already exists", category: :error end
ambiguous_project(matches, command)
click to toggle source
# File lib/tempo/views/projects_view.rb, line 63 def ambiguous_project(matches, command) ViewRecords::Message.new "The following projects matched your search:" Tempo::Views::Reporter.add_options active: true projects_flat_list_view matches ViewRecords::Message.new "please refine your search or use --exact to match args exactly" ViewRecords::Message.new "cannot #{command} multiple projects", category: :error end
arrange_already_root(project)
click to toggle source
# File lib/tempo/views/arrange_view.rb, line 17 def arrange_already_root(project) ViewRecords::Message.new "already a root project:" ViewRecords::Project.new project end
arrange_parent_child(parent, child)
click to toggle source
# File lib/tempo/views/arrange_view.rb, line 5 def arrange_parent_child(parent, child) ViewRecords::Message.new "parent project:" ViewRecords::Project.new parent ViewRecords::Message.new "child project:" ViewRecords::Project.new child end
arrange_parse_error()
click to toggle source
# File lib/tempo/views/arrange_view.rb, line 22 def arrange_parse_error ViewRecords::Message.new "arrange requires a colon (:) in the arguments", category: :error end
arrange_root(project)
click to toggle source
# File lib/tempo/views/arrange_view.rb, line 12 def arrange_root(project) ViewRecords::Message.new "root project:" ViewRecords::Project.new project end
checkout_assistance(options={})
click to toggle source
# File lib/tempo/views/base.rb, line 77 def checkout_assistance(options={}) ViewRecords::Message.new "checkout command run with no arguments" ViewRecords::Message.new "perhaps you meant one of these?" ViewRecords::Message.new " tempo checkout --add <new project name>" ViewRecords::Message.new " tempo checkout <existing project>" ViewRecords::Message.new "run `tempo checkout --help` for more information" end
delete_time_record_view(time_record)
click to toggle source
# File lib/tempo/views/time_record_view.rb, line 25 def delete_time_record_view(time_record) ViewRecords::Message.new "time record deleted:" time_record_view time_record end
end_time_record_view(time_record)
click to toggle source
# File lib/tempo/views/time_record_view.rb, line 15 def end_time_record_view(time_record) ViewRecords::Message.new "time record ended:" time_record_view time_record end
error(message)
click to toggle source
# File lib/tempo/views/base.rb, line 64 def error(message) ViewRecords::Message.new message, category: :error end
initialize_view_options(command, global_options, options)
click to toggle source
called in the pre block, pushes relavent options to the reporter
# File lib/tempo/views/base.rb, line 6 def initialize_view_options(command, global_options, options) view_opts = {} view_opts[:verbose] = global_options[:verbose] view_opts[:id] = global_options[:id] case command when :project, :p if global_options[:verbose] view_opts[:id] = true view_opts[:tags] = true view_opts[:active] = true view_opts[:depth] = true else if options[:list] view_opts[:depth] = true view_opts[:active] = true end view_opts[:tags] = options[:tag] || options[:untag] ? true : false view_opts[:id] = global_options[:id] || options[:id] ? true : false end when :report, :r if /^p(roject)?$/.match(options[:order]) && ! global_options[:verbose] view_opts[:bullet_report] = true end end Tempo::Views::Reporter.add_options view_opts end
interactive_confirm_clean()
click to toggle source
# File lib/tempo/views/interactive.rb, line 18 def interactive_confirm_clean query = "\nCleaning Tempo records resaves all records, looking for errors.\n" + "In the event that a record cannot be corrected, you wil be prompted to repair the record manually.\n" + "A backup of the records will also be created before any changes are made.\n\n" + "Do you wish to continue? [YyNn]" interactive_query(query) end
interactive_confirm_move_old_records()
click to toggle source
# File lib/tempo/views/interactive.rb, line 26 def interactive_confirm_move_old_records query = "\nYou have files which match an older file structure, do you want to move them so they will be included in your records? [YyNn]" interactive_query(query) end
interactive_progress(message)
click to toggle source
# File lib/tempo/views/interactive.rb, line 10 def interactive_progress(message) ViewRecords::Message.new message, category: :progress end
interactive_progress_partial(message)
click to toggle source
# File lib/tempo/views/interactive.rb, line 14 def interactive_progress_partial(message) ViewRecords::Message.new message, category: :progress_partial end
interactive_query(query)
click to toggle source
Must be allowed to return results
# File lib/tempo/views/interactive.rb, line 6 def interactive_query(query) ViewRecords::Query.new query end
message(message, category=:info)
click to toggle source
# File lib/tempo/views/base.rb, line 56 def message(message, category=:info) ViewRecords::Message.new message, category: category end
no_items(items, category=:info)
click to toggle source
# File lib/tempo/views/base.rb, line 48 def no_items(items, category=:info) ViewRecords::Message.new "no #{items} exist", category: category if items == "projects" ViewRecords::Message.new "You must create at least one project before you can begin tracking time" ViewRecords::Message.new "run `tempo project --help` for more information" end end
no_match_error(items, request, plural=true)
click to toggle source
# File lib/tempo/views/base.rb, line 68 def no_match_error(items, request, plural=true) match = plural ? "match" : "matches" ViewRecords::Message.new "no #{items} #{match} the request: #{request}", category: :error end
options_report(command, global_options, options, args)
click to toggle source
called in the preblock when verbose = true
# File lib/tempo/views/base.rb, line 34 def options_report(command, global_options, options, args) globals_list = "global options: " global_options.each {|k,v| globals_list += "#{k} = #{v}, " if k.kind_of? String and k.length > 1 and !v.nil? } ViewRecords::Message.new globals_list[0..-2], category: :debug options_list = "command options: " options.each {|k,v| options_list += "#{k} = #{v}, " if k.kind_of? String and k.length > 1 and !v.nil? } ViewRecords::Message.new options_list[0..-2], category: :debug ViewRecords::Message.new "command: #{command}", category: :debug ViewRecords::Message.new "args: #{args}", category: :debug end
project_added(project)
click to toggle source
# File lib/tempo/views/projects_view.rb, line 38 def project_added(project) ViewRecords::Message.new "added project:" project_view project end
project_already_current(project)
click to toggle source
# File lib/tempo/views/projects_view.rb, line 53 def project_already_current(project) ViewRecords::Message.new "already on project:" project_view project end
project_assistance()
click to toggle source
# File lib/tempo/views/projects_view.rb, line 75 def project_assistance ViewRecords::Message.new "you need to set up a new project before running your command" ViewRecords::Message.new "run`tempo project --help` for more information" no_items "projects", :error end
project_checkout(project)
click to toggle source
# File lib/tempo/views/projects_view.rb, line 48 def project_checkout(project) ViewRecords::Message.new "switched to project:" project_view project end
project_deleted(project)
click to toggle source
# File lib/tempo/views/projects_view.rb, line 43 def project_deleted(project) ViewRecords::Message.new "deleted project:" project_view project end
project_view(project, depth=0)
click to toggle source
# File lib/tempo/views/projects_view.rb, line 5 def project_view project, depth=0 ViewRecords::Project.new project, depth: depth end
projects_flat_list_view(projects=Tempo::Model::Project.index)
click to toggle source
list of sorted projects, no hierarchy
# File lib/tempo/views/projects_view.rb, line 29 def projects_flat_list_view(projects=Tempo::Model::Project.index) Tempo::Model::Project.sort_by_title projects do |projects| projects.each do |p| project_view p end end end
projects_list_view(projects=Tempo::Model::Project.index, parent=:root, depth=0)
click to toggle source
# File lib/tempo/views/projects_view.rb, line 9 def projects_list_view(projects=Tempo::Model::Project.index, parent=:root, depth=0) return no_items( "projects" ) if projects.empty? Tempo::Model::Project.sort_by_title projects do |projects| projects.each do |p| if p.parent == parent project_view p, depth if not p.children.empty? next_depth = depth + 1 next_parent = p.id child_array = projects_list_view projects, next_parent, next_depth end end end end end
report_records_view(options={})
click to toggle source
# File lib/tempo/views/report_view.rb, line 5 def report_records_view(options={}) # Haven't we already checked for this? projects = options.fetch(:projects, Tempo::Model::Project.index) return no_items("projects") if projects.empty? # TODO: Document here days index structure, give example of sending in subsets # so the Records Controller can manage the organization of the records. time_records = options.fetch( :time_records, Tempo::Model::TimeRecord.days_index ) # It this going to break if 1 of X record containers is empty? # Or should the controller not send empty records and this is good to check for? # Maybe No time records for <date>? return no_items("time records") if time_records.empty? if options[:order] == "date" || options[:order] == "d" order_by_date time_records elsif options[:order] == "project" || options[:order] == "p" order_by_project projects, time_records else return error "Unable to report time records sorted by '#{options[:order]}'" end end
start_time_record_view(time_record)
click to toggle source
# File lib/tempo/views/time_record_view.rb, line 10 def start_time_record_view(time_record) ViewRecords::Message.new "time record started:" time_record_view time_record end
time_record_view(time_record, options={})
click to toggle source
Container sends postpone: true through options
# File lib/tempo/views/time_record_view.rb, line 6 def time_record_view(time_record, options={}) ViewRecords::TimeRecord.new time_record, options end
update_time_record_view(time_record)
click to toggle source
# File lib/tempo/views/time_record_view.rb, line 20 def update_time_record_view(time_record) ViewRecords::Message.new "time record updated:" time_record_view time_record end
warning(message)
click to toggle source
# File lib/tempo/views/base.rb, line 60 def warning(message) ViewRecords::Message.new message, category: :warning end
Private Class Methods
order_by_date(time_records)
click to toggle source
# File lib/tempo/views/report_view.rb, line 31 def order_by_date(time_records) time_records.each do |d_id, days_record| day = Tempo::Model::TimeRecord.day_id_to_time d_id container = ViewRecords::TimeRecordContainer.new container.pre = ViewRecords::Message.new day.strftime("Records for %m/%d/%Y:\n\n"), postpone: true days_record.each do |time_record| container.add(time_record_view time_record, postpone: true) end end end
order_by_project(projects, time_records)
click to toggle source
# File lib/tempo/views/report_view.rb, line 45 def order_by_project(projects, time_records) project_records = Hash.new {|this_hash, nonexistent_key| this_hash[nonexistent_key] = [] } time_records.each do |d_id, days_records| days_records.each do |days_record| # TODO: if project in projects (for filtering) project_records[days_record.project] << days_record end end project_records.each do |pr,time_records| container = ViewRecords::TimeRecordContainer.new #require 'pry'; binding.pry container.pre = ViewRecords::Message.new "Records for #{Model::Project.find_by_id(pr).title}\n", postpone: true time_records.each do |time_record| container.add(time_record_view time_record, postpone: true) end end end