lib/pt/ui.rb in pt-0.5.5 vs lib/pt/ui.rb in pt-0.5.6
- old
+ new
@@ -20,34 +20,39 @@
end
def my_work
title("My Work for #{user_s} in #{project_to_s}")
stories = @client.get_my_work(@project, @local_config[:user_name])
- PT::TasksTable.new(stories).print
+ PT::TasksTable.new(stories).print @global_config
end
def todo
title("My Work for #{user_s} in #{project_to_s}")
stories = @client.get_my_work(@project, @local_config[:user_name])
stories = stories.select { |story| story.current_state == "unscheduled" }
- PT::TasksTable.new(stories).print
+ PT::TasksTable.new(stories).print @global_config
end
def list
if @params[0]
- user = find_owner @params[0]
- if user
- stories = @client.get_my_work(@project, user.name)
- PT::TasksTable.new(stories).print
+ if @params[0] == "all"
+ stories = @client.get_work(@project)
+ PT::TasksTable.new(stories).print @global_config
+ else
+ user = find_owner @params[0]
+ if user
+ stories = @client.get_my_work(@project, user.name)
+ PT::TasksTable.new(stories).print @global_config
+ end
end
else
members = @client.get_members(@project)
table = PT::MembersTable.new(members)
user = select("Please select a member to see his tasks.", table).name
title("Work for #{user} in #{project_to_s}")
stories = @client.get_my_work(@project, user)
- PT::TasksTable.new(stories).print
+ PT::TasksTable.new(stories).print @global_config
end
end
def create
if @params[0]
@@ -131,15 +136,17 @@
else
title("Tasks for #{user_s} in #{project_to_s}")
tasks = @client.get_tasks_to_assign(@project, @local_config[:user_name])
table = PT::TasksTable.new(tasks)
task = select("Please select a task to assign it an owner", table)
+ end
+ unless owner
members = @client.get_members(@project)
table = PT::MembersTable.new(members)
owner = select("Please select a member to assign him the task", table).name
end
- result = @client.assign_task(@project, task, owner.name)
+ result = @client.assign_task(@project, task, owner)
if result.errors.any?
error(result.errors.errors)
else
congrats("Task assigned to #{owner}, thanks!")
end
@@ -357,18 +364,29 @@
congrats("Task delivered, congrats!")
end
end
def find
- tasks = @client.get_my_work(@project, @local_config[:user_name])
+ if (story_id = @params[0].to_i).nonzero?
+ if task = @client.get_task_by_id(story_id)
+ return show_task(task)
+ else
+ message("Task not found by id (#{story_id}), falling back to text search")
+ end
+ end
+
if @params[0]
- tasks.each do | task |
- if (task.name.downcase.index @params[0]) && (task.current_state != 'delivered')
- title("--- [#{(tasks.index task) + 1 }] -----------------")
- show_task(task)
- end
+ tasks = @client.get_my_work(@project, @local_config[:user_name])
+ matched_tasks = tasks.select do | task |
+ task.name.downcase.index(@params[0]) && task.current_state != 'delivered'
end
+
+ matched_tasks.each do | task |
+ title("--- [#{(tasks.index task) + 1 }] -----------------")
+ show_task(task)
+ end
+ message("No matches found for '#{@params[0]}'") if matched_tasks.empty?
else
message("You need to provide a substring for a tasks title.")
end
end
@@ -402,10 +420,11 @@
puts("pt accept [id] # mark a task as accepted")
puts("pt reject [id] [reason] # mark a task as rejected, explaining why")
puts("pt find [query] # looks in your tasks by title and presents it")
puts("pt done [id] ~[0-3] ~[comment] # lazy mans finish task, does everything")
puts("pt list [member] # list all tasks for another pt user")
+ puts("pt list all # list all tasks for all users")
puts("pt updates [number] # shows number recent activity from your current project")
puts("")
puts("All commands can be ran without arguments for a wizard like UI.")
end
@@ -491,19 +510,19 @@
end
def select(msg, table)
if table.length > 0
begin
- table.print
+ table.print @global_config
row = ask "#{msg} (1-#{table.length}, 'q' to exit)"
quit if row == 'q'
selected = table[row]
error "Invalid selection, try again:" unless selected
end until selected
selected
else
- table.print
+ table.print @global_config
message "Sorry, there are no options to select."
quit
end
end
@@ -553,17 +572,12 @@
end
end
end
def find_owner query
- members = @client.get_members(@project)
- members.each do | member |
- if member.name.downcase.index query.to_s
- return member
- end
- if member.initials.downcase.index query.to_s
- return member
- end
+ if query
+ member = @client.get_member(@project, query)
+ return member ? member.name : nil
end
nil
end
def show_task(task)