pt 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c872c7de07ff476f016e21cd526a26cde532c61
4
- data.tar.gz: 2b5cd00d28ad94fcf20842d6c50b9eb02bf4ef8d
3
+ metadata.gz: 0c8f668fcc562a3434ef7c4254e2d00d1598c49a
4
+ data.tar.gz: 7f022d8b46d4e628af5d0aee958368d5196c0497
5
5
  SHA512:
6
- metadata.gz: dae2f14490c2b022db21fc2f5408e29365907091b0f41992aa65577f2aeac8b037f41d4487459042ec05aaedba4489c67ae184391b31f571c8abe137de328535
7
- data.tar.gz: eccedbf39e375f0389423657e0bf9abab46600211ed377735e91a4b364ac2798422a5269dfc1eebdb44efa246c48f031ff6ba6cefec078d26ab6ca66bccee6a6
6
+ metadata.gz: d9126e08e452d2e25573a2a5ed5bb91d42ec6dfa2d3c7af3095a56aec121d9c4cf75cbeb82325ab27fc86a4b755b5ec5cdfa30129629b6ad5384ba35a16ee5c2
7
+ data.tar.gz: e2a021d5eb32c5bd49d2aef9fe46808ddf6f151fbcd80d43daaaa900f704aee476fd99c8f347f5863a2cf2ce84e23ab6c0feb0f29b1fd85ec062e0d573629fdd
@@ -1,8 +1,9 @@
1
1
  # pt changelog
2
2
 
3
+ ## v0.10.0
4
+ - remove interactive pagination, pagination option can be set through cli flag ( --page and --limit )
3
5
  ## v0.9.0
4
6
  - add pagination for long stories (limit: default is 20, can be changed by set :limit: on local .pt file)
5
- -
6
7
 
7
8
  ## v0.8.6
8
9
  - replace ruby save navigation operator
@@ -10,6 +10,9 @@ module PT
10
10
  include PT::Helper
11
11
  attr_reader :project
12
12
 
13
+ class_option "limit", aliases: :l, type: :numeric, default: 10, desc: 'change limit'
14
+ class_option "page", aliases: :p, type: :numeric, desc: 'show n-th page'
15
+
13
16
  def initialize(*args)
14
17
  super
15
18
  @io = HighLine.new
@@ -24,15 +27,14 @@ module PT
24
27
  define_method(state.to_sym) do |owner = nil|
25
28
  filter = "state:#{state}"
26
29
  filter << " owner:#{owner}" if owner
27
- story = select_story_from_paginated_table do |page|
28
- @client.get_stories(filter: filter, page: page)
29
- end
30
- show_story(story)
30
+ stories = @client.get_stories(filter: filter, page: options[:page], limit: options[:limit])
31
+ print_stories_table(stories)
31
32
  end
32
33
  end
33
34
 
34
35
  %w[show tasks open assign comments label estimate start finish deliver accept reject done].each do |action|
35
36
  desc "#{action} [id]", "#{action} story"
37
+ method_option "interactive", aliases: :i, type: :boolean, default: true, desc: 'enable interactive method'
36
38
  define_method(action.to_sym) do |story_id = nil|
37
39
  if story_id
38
40
  story = task_by_id_or_pt_id(story_id.to_i)
@@ -42,13 +44,12 @@ module PT
42
44
  end
43
45
  else
44
46
  method_name = "get_stories_to_#{action}"
45
- story = select_story_from_paginated_table do |page|
46
- if @client.respond_to?(method_name.to_sym)
47
- @client.send("get_stories_to_#{action}", page: page)
48
- else
49
- @client.get_stories(page: page)
50
- end
47
+ stories = if @client.respond_to?(method_name.to_sym)
48
+ @client.send("get_stories_to_#{action}", page: options[:page], limit: options[:limit])
49
+ else
50
+ @client.get_stories(page: options[:page], limit: options[:limit])
51
51
  end
52
+ story = select_story_from_paginated_table(stories)
52
53
  end
53
54
  title("#{action} '#{story.name}'")
54
55
  send("#{action}_story", story)
@@ -57,10 +58,8 @@ module PT
57
58
 
58
59
  desc 'mywork', 'list all your stories'
59
60
  def mywork
60
- story = select_story_from_paginated_table do |page|
61
- @client.get_stories(filter: "owner:#{@local_config[:user_name]} -state:accepted", page: page)
62
- end
63
- show_story(story)
61
+ stories = @client.get_stories(filter: "owner:#{@local_config[:user_name]} -state:accepted", page: options[:page])
62
+ print_stories_table(stories)
64
63
  end
65
64
 
66
65
  desc "list [owner]", "list all stories from owner"
@@ -68,10 +67,8 @@ module PT
68
67
  if owner
69
68
  if owner == "all"
70
69
  stories = @client.get_work
71
- TasksTable.new(stories).print @global_config
72
70
  else
73
71
  stories = @client.get_my_work(owner)
74
- TasksTable.new(stories).print @global_config
75
72
  end
76
73
  else
77
74
  members = @client.get_members
@@ -79,8 +76,8 @@ module PT
79
76
  user = select("Please select a member to see his tasks.", table).name
80
77
  title("Work for #{user} in #{project_to_s}")
81
78
  stories = @client.get_my_work(user)
82
- TasksTable.new(stories).print @global_config
83
79
  end
80
+ print_stories_table(stories)
84
81
  end
85
82
 
86
83
  desc "recent", "show stories you've recently shown or commented on with pt"
@@ -128,7 +125,6 @@ module PT
128
125
  else
129
126
  owner = nil
130
127
  end
131
- requester = @local_config[:user_name]
132
128
  type = ask('Type? (c)hore, (b)ug, anything else for feature)')
133
129
  end
134
130
 
@@ -164,10 +160,8 @@ module PT
164
160
 
165
161
  desc "find [query] " ,"looks in your stories by title and presents it"
166
162
  def find(query)
167
- story = select_story_from_paginated_table do |page|
168
- @client.get_stories(filter: query, page: page)
169
- end
170
- show_story(story)
163
+ stories = @client.get_stories(filter: query, page: options[:page])
164
+ print_stories_table(stories)
171
165
  end
172
166
 
173
167
  desc "updates","shows number recent activity from your current project"
@@ -21,6 +21,19 @@ module PT
21
21
  @project = @client.project(local_config[:project_id]) if local_config
22
22
  end
23
23
 
24
+ def total_page(limit=nil)
25
+ limit ||= @config[:limit]
26
+ @total_record = @client.last_response.env.response_headers["X-Tracker-Pagination-Total"]
27
+ @total_record ? (@total_record.to_f/limit).ceil : 1
28
+ end
29
+
30
+ def current_page(limit=nil)
31
+ limit ||= @config[:limit]
32
+ offset = @client.last_response.env.response_headers["X-Tracker-Pagination-Offset"]
33
+ offset ? ((offset.to_f/limit)+1).to_i.ceil : 1
34
+ end
35
+
36
+
24
37
  def get_project(project_id)
25
38
  project = @client.project(project_id)
26
39
  project
@@ -106,9 +119,9 @@ module PT
106
119
  end
107
120
 
108
121
  def get_stories(params={})
109
- limit = config[:limit] || 20
110
- page = params[:page] || 0
111
- offset = page*limit
122
+ limit = params[:limit] || config[:limit] || 10
123
+ page = params[:page] || 1
124
+ offset = (page-1)*limit
112
125
  filter = params[:filter] || '-state=accepted'
113
126
  project.stories limit: limit, fields: STORY_FIELDS, auto_paginate: false, offset: offset, filter: filter
114
127
  end
@@ -112,30 +112,6 @@ module PT
112
112
  puts "\n#{split_lines(msg).red.bold}"
113
113
  end
114
114
 
115
- def select(msg, table)
116
- if table.length > 0
117
- begin
118
- table.print @global_config
119
- row = ask "#{msg} (1-#{table.length}, 'n' to fetch next data, 'p' to fetch previous data, 'q' to exit)"
120
- case row
121
- when 'q'
122
- quit
123
- when 'n'
124
- return 'n'
125
- when 'p'
126
- return 'p'
127
- end
128
- selected = table[row]
129
- error "Invalid selection, try again:" unless selected
130
- end until selected
131
- selected
132
- else
133
- table.print @global_config
134
- message "Sorry, there are no options to select."
135
- quit
136
- end
137
- end
138
-
139
115
  def quit
140
116
  message "bye!"
141
117
  exit
@@ -251,20 +227,33 @@ module PT
251
227
  save_config( @local_config, get_local_config_path() )
252
228
  end
253
229
 
254
- def select_story_from_paginated_table(&block)
255
- prompt = "Please select a story"
256
- page = 0
257
- begin
258
- stories = block.call(page)
259
- table = TasksTable.new(stories)
260
- story = select(prompt, table)
261
- if story == 'n'
262
- page+=1
263
- elsif story == 'p'
264
- page-=1
265
- end
266
- end while story.kind_of?(String)
267
- story
230
+ def select(msg, table)
231
+ if table.length > 0
232
+ begin
233
+ table.print @global_config
234
+ row = ask "#{msg} (1-#{table.length}, 'q' to exit)"
235
+ quit if row == 'q'
236
+ selected = table[row]
237
+ error "Invalid selection, try again:" unless selected
238
+ end until selected
239
+ selected
240
+ else
241
+ table.print @global_config
242
+ message "Sorry, there are no options to select."
243
+ quit
244
+ end
245
+ end
246
+
247
+ def print_stories_table(stories)
248
+ table = TasksTable.new(stories)
249
+ puts "[#{@client.current_page(options[:limit])}/#{@client.total_page(options[:limit])}]"
250
+ table.print @global_config
251
+ end
252
+
253
+ def select_story_from_paginated_table(stories)
254
+ puts "[#{@client.current_page(options[:limit])}/#{@client.total_page(options[:limit])}]"
255
+ table = TasksTable.new(stories)
256
+ select("Please select a story", table)
268
257
  end
269
258
  end
270
259
  end
@@ -1,3 +1,3 @@
1
1
  module PT
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Slamet Kristanto
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-02-08 00:00:00.000000000 Z
14
+ date: 2017-02-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler