karafka-web 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +2 -8
  4. data/Gemfile.lock +1 -1
  5. data/lib/karafka/web/config.rb +0 -2
  6. data/lib/karafka/web/ui/base.rb +2 -6
  7. data/lib/karafka/web/ui/controllers/base.rb +0 -17
  8. data/lib/karafka/web/ui/controllers/cluster.rb +2 -5
  9. data/lib/karafka/web/ui/controllers/consumers.rb +1 -3
  10. data/lib/karafka/web/ui/controllers/errors.rb +6 -19
  11. data/lib/karafka/web/ui/controllers/jobs.rb +1 -3
  12. data/lib/karafka/web/ui/controllers/requests/params.rb +0 -10
  13. data/lib/karafka/web/ui/lib/paginate_array.rb +38 -0
  14. data/lib/karafka/web/ui/models/message.rb +38 -114
  15. data/lib/karafka/web/ui/models/status.rb +1 -3
  16. data/lib/karafka/web/ui/pro/app.rb +3 -11
  17. data/lib/karafka/web/ui/pro/controllers/consumers.rb +1 -3
  18. data/lib/karafka/web/ui/pro/controllers/dlq.rb +2 -1
  19. data/lib/karafka/web/ui/pro/controllers/errors.rb +10 -43
  20. data/lib/karafka/web/ui/pro/controllers/explorer.rb +7 -52
  21. data/lib/karafka/web/ui/pro/views/errors/_breadcrumbs.erb +6 -8
  22. data/lib/karafka/web/ui/pro/views/errors/_error.erb +1 -1
  23. data/lib/karafka/web/ui/pro/views/errors/_partition_option.erb +1 -1
  24. data/lib/karafka/web/ui/pro/views/errors/index.erb +56 -9
  25. data/lib/karafka/web/ui/pro/views/explorer/_breadcrumbs.erb +1 -1
  26. data/lib/karafka/web/ui/pro/views/explorer/_message.erb +2 -8
  27. data/lib/karafka/web/ui/pro/views/explorer/_partition_option.erb +1 -1
  28. data/lib/karafka/web/ui/pro/views/explorer/_topic.erb +1 -1
  29. data/lib/karafka/web/ui/pro/views/explorer/partition/_messages.erb +0 -1
  30. data/lib/karafka/web/ui/pro/views/explorer/partition.erb +1 -1
  31. data/lib/karafka/web/ui/pro/views/shared/_navigation.erb +1 -1
  32. data/lib/karafka/web/ui/views/cluster/_partition.erb +1 -1
  33. data/lib/karafka/web/ui/views/errors/_error.erb +1 -1
  34. data/lib/karafka/web/ui/views/shared/_pagination.erb +12 -16
  35. data/lib/karafka/web/version.rb +1 -1
  36. data.tar.gz.sig +0 -0
  37. metadata +2 -17
  38. metadata.gz.sig +0 -0
  39. data/lib/karafka/web/ui/lib/paginations/base.rb +0 -61
  40. data/lib/karafka/web/ui/lib/paginations/offset_based.rb +0 -96
  41. data/lib/karafka/web/ui/lib/paginations/page_based.rb +0 -70
  42. data/lib/karafka/web/ui/lib/paginations/paginators/arrays.rb +0 -33
  43. data/lib/karafka/web/ui/lib/paginations/paginators/base.rb +0 -23
  44. data/lib/karafka/web/ui/lib/paginations/paginators/partitions.rb +0 -52
  45. data/lib/karafka/web/ui/lib/paginations/paginators/sets.rb +0 -85
  46. data/lib/karafka/web/ui/lib/ttl_cache.rb +0 -74
  47. data/lib/karafka/web/ui/models/cluster_info.rb +0 -59
  48. data/lib/karafka/web/ui/pro/views/errors/_table.erb +0 -21
  49. data/lib/karafka/web/ui/pro/views/errors/_title_with_select.erb +0 -31
  50. data/lib/karafka/web/ui/pro/views/errors/partition.erb +0 -17
  51. data/lib/karafka/web/ui/pro/views/explorer/topic/_empty.erb +0 -3
  52. data/lib/karafka/web/ui/pro/views/explorer/topic/_limited.erb +0 -4
  53. data/lib/karafka/web/ui/pro/views/explorer/topic/_partitions.erb +0 -11
  54. data/lib/karafka/web/ui/pro/views/explorer/topic.erb +0 -49
@@ -18,11 +18,10 @@ module Karafka
18
18
  module Controllers
19
19
  # Data explorer controller
20
20
  class Explorer < Ui::Controllers::Base
21
- include Ui::Lib::Paginations
22
-
23
21
  # Lists all the topics we can explore
24
22
  def index
25
- @topics = Models::ClusterInfo
23
+ @topics = Karafka::Admin
24
+ .cluster_info
26
25
  .topics
27
26
  .reject { |topic| topic[:topic_name] == '__consumer_offsets' }
28
27
  .sort_by { |topic| topic[:topic_name] }
@@ -30,34 +29,6 @@ module Karafka
30
29
  respond
31
30
  end
32
31
 
33
- # Displays aggregated messages from (potentially) all partitions of a topic
34
- #
35
- # @param topic_id [String]
36
- #
37
- # @note This view may not be 100% accurate because we merge multiple partitions data
38
- # into a single view and this is never accurate. It can be used however to quickly
39
- # look at most recent data flowing, etc, hence it is still useful for aggregated
40
- # metrics information
41
- #
42
- # @note We cannot use offset references here because each of the partitions may have
43
- # completely different values
44
- def topic(topic_id)
45
- @topic_id = topic_id
46
- @partitions_count = Models::ClusterInfo.partitions_count(topic_id)
47
-
48
- @active_partitions, materialized_page, @limited = Paginators::Partitions.call(
49
- @partitions_count, @params.current_page
50
- )
51
-
52
- @messages, next_page = Models::Message.topic_page(
53
- topic_id, @active_partitions, materialized_page
54
- )
55
-
56
- paginate(@params.current_page, next_page)
57
-
58
- respond
59
- end
60
-
61
32
  # Shows messages available in a given partition
62
33
  #
63
34
  # @param topic_id [String]
@@ -65,16 +36,13 @@ module Karafka
65
36
  def partition(topic_id, partition_id)
66
37
  @topic_id = topic_id
67
38
  @partition_id = partition_id
68
- @watermark_offsets = Ui::Models::WatermarkOffsets.find(topic_id, partition_id)
69
- @partitions_count = Models::ClusterInfo.partitions_count(topic_id)
70
39
 
71
- previous_offset, @messages, next_offset = current_partition_data
40
+ @watermark_offsets = Ui::Models::WatermarkOffsets.find(topic_id, partition_id)
72
41
 
73
- paginate(
74
- previous_offset,
75
- @params.current_offset,
76
- next_offset,
77
- @messages.map(&:offset)
42
+ @previous_page, @messages, @next_page, @partitions_count = Ui::Models::Message.page(
43
+ @topic_id,
44
+ @partition_id,
45
+ @params.current_page
78
46
  )
79
47
 
80
48
  respond
@@ -106,19 +74,6 @@ module Karafka
106
74
 
107
75
  respond
108
76
  end
109
-
110
- private
111
-
112
- # Fetches current page data
113
- # @return [Array] fetched data with pagination information for the requested partition
114
- def current_partition_data
115
- Ui::Models::Message.offset_page(
116
- @topic_id,
117
- @partition_id,
118
- @params.current_offset,
119
- @watermark_offsets
120
- )
121
- end
122
77
  end
123
78
  end
124
79
  end
@@ -1,16 +1,14 @@
1
1
  <li class="breadcrumb-item">
2
- <a href="<%= root_path('errors') %>">
2
+ <a href="<%= root_path('errors', 0) %>">
3
3
  Errors
4
4
  </a>
5
5
  </li>
6
6
 
7
- <% if @partition_id %>
8
- <li class="breadcrumb-item">
9
- <a href="<%= root_path('errors', @partition_id) %>">
10
- Partition <%= @partition_id %>
11
- </a>
12
- </li>
13
- <% end %>
7
+ <li class="breadcrumb-item">
8
+ <a href="<%= root_path('errors', @partition_id) %>">
9
+ Partition <%= @partition_id %>
10
+ </a>
11
+ </li>
14
12
 
15
13
  <% if @offset %>
16
14
  <li class="breadcrumb-item">
@@ -1,4 +1,4 @@
1
- <% if error_msg.is_a?(Array) %>
1
+ <% if error_msg.is_a?(Integer) %>
2
2
  <tr>
3
3
  <td colspan="5" class="text-center text-muted">
4
4
  This error has either been removed or compacted and is no longer available.
@@ -3,5 +3,5 @@
3
3
  <% else %>
4
4
  <option value="<%= root_path('errors', partition) %>">
5
5
  <% end %>
6
- <%= partition || 'All' %>
6
+ <%= partition %>
7
7
  </option>
@@ -1,18 +1,65 @@
1
- <%== partial('errors/title_with_select') %>
1
+ <div class="container mb-4">
2
+ <div class="row">
3
+ <div class="col">
4
+ <h3>
5
+ Errors
6
+ </h3>
7
+ </div>
8
+
9
+ <div class="col">
10
+ <div class="col-auto text-end">
11
+ <label class="col-form-label">Partition</label>
12
+ </div>
13
+ </div>
14
+
15
+ <div class="col pt-1 mb-0 pb-0">
16
+ <div class="col-auto">
17
+ <select class="form-select form-select-sm mb-0 form-control" id="current-partition">
18
+ <%==
19
+ each_partial(
20
+ @partitions_count.times.to_a,
21
+ 'errors/partition_option',
22
+ local: :partition
23
+ )
24
+ %>
25
+ </select>
26
+ </div>
27
+ </div>
28
+ </div>
29
+
30
+ <hr>
31
+ </div>
2
32
 
3
33
  <div class="container">
4
34
  <div class="row mb-5">
5
35
  <div class="col-sm-12">
6
- <%== partial('explorer/topic/partitions') %>
7
-
8
- <% if @limited %>
9
- <%== partial('explorer/topic/limited') %>
10
- <% end %>
36
+ <%== partial('explorer/partition/watermark_offsets') %>
11
37
 
12
- <% if @error_messages.empty? && params.current_page == 1 %>
13
- <%== partial 'explorer/topic/empty' %>
38
+ <% if @watermark_offsets.empty? %>
39
+ <%== partial 'errors/no_errors' %>
40
+ <% elsif @watermark_offsets.cleaned? %>
41
+ <%== partial 'errors/cleaned' %>
14
42
  <% else %>
15
- <%== partial 'errors/table' %>
43
+ <table class="processes bg-white table table-hover table-bordered table-striped mb-0 align-middle">
44
+ <thead>
45
+ <tr class="align-middle">
46
+ <th>Origin</th>
47
+ <th>Process name</th>
48
+ <th>Error</th>
49
+ <th>Occurred at</th>
50
+ <th></th>
51
+ </tr>
52
+ </thead>
53
+ <tbody>
54
+ <%==
55
+ each_partial(
56
+ @error_messages,
57
+ 'errors/error',
58
+ local: :error_msg
59
+ )
60
+ %>
61
+ </tbody>
62
+ </table>
16
63
  <% end %>
17
64
  </div>
18
65
  </div>
@@ -6,7 +6,7 @@
6
6
 
7
7
  <% if @topic_id %>
8
8
  <li class="breadcrumb-item">
9
- <a href="<%= root_path('explorer', @topic_id) %>">
9
+ <a href="<%= root_path('explorer', @topic_id, 0) %>">
10
10
  <%= @topic_id %>
11
11
  </a>
12
12
  </li>
@@ -1,10 +1,7 @@
1
- <% if message.is_a?(Array) %>
1
+ <% if message.is_a?(Integer) %>
2
2
  <tr>
3
3
  <td class="text-muted">
4
- <%= message[0] %>
5
- </td>
6
- <td class="text-muted">
7
- <%= message[1] %>
4
+ <%= message %>
8
5
  </td>
9
6
  <td colspan="3" class="text-center text-muted">
10
7
  This message has either been removed or compacted and is no longer available.
@@ -12,9 +9,6 @@
12
9
  </tr>
13
10
  <% else %>
14
11
  <tr>
15
- <td>
16
- <%= message.partition %>
17
- </td>
18
12
  <td>
19
13
  <%= message.offset %>
20
14
  </td>
@@ -3,5 +3,5 @@
3
3
  <% else %>
4
4
  <option value="<%= root_path('explorer', @topic_id, partition) %>">
5
5
  <% end %>
6
- <%= partition || 'All' %>
6
+ <%= partition %>
7
7
  </option>
@@ -2,7 +2,7 @@
2
2
  <div class="card" >
3
3
  <div class="card-body p-2">
4
4
  <p class="card-text mb-0 p-2">
5
- <a href="<%= root_path('explorer', topic[:topic_name]) %>">
5
+ <a href="<%= root_path('explorer', topic[:topic_name], 0) %>">
6
6
  <%= topic[:topic_name] %> /
7
7
  <%= topic[:partition_count] %>
8
8
  </a>
@@ -1,7 +1,6 @@
1
1
  <table class="processes bg-white table table-hover table-bordered table-striped mb-0 align-middle">
2
2
  <thead>
3
3
  <tr class="align-middle">
4
- <th>Partition</th>
5
4
  <th>Offset</th>
6
5
  <th>Timestamp</th>
7
6
  <th>Key</th>
@@ -17,7 +17,7 @@
17
17
  <select class="form-select form-select-sm mb-0 form-control" id="current-partition">
18
18
  <%==
19
19
  each_partial(
20
- [nil] + @partitions_count.times.to_a,
20
+ @partitions_count.times.to_a,
21
21
  'explorer/partition_option',
22
22
  local: :partition
23
23
  )
@@ -31,7 +31,7 @@
31
31
  </a>
32
32
  </li>
33
33
  <li class="nav-item ms-3">
34
- <a class="nav-link <%= nav_class(start_with: '/errors') %>" href="<%= root_path('errors') %>">
34
+ <a class="nav-link <%= nav_class(start_with: '/errors') %>" href="<%= root_path('errors/0') %>">
35
35
  Errors
36
36
  </a>
37
37
  </li>
@@ -3,7 +3,7 @@
3
3
  <% if topic[:topic_name] != '__consumer_offsets' %>
4
4
  <tr>
5
5
  <td>
6
- <a href="<%= root_path('explorer', topic[:topic_name]) %>">
6
+ <a href="<%= root_path('explorer', topic[:topic_name], 0) %>">
7
7
  <%= topic[:topic_name] %>
8
8
  </a>
9
9
  <td>
@@ -1,4 +1,4 @@
1
- <% if error_msg.is_a?(Array) %>
1
+ <% if error_msg.is_a?(Integer) %>
2
2
  <tr>
3
3
  <td colspan="5" class="text-center text-muted">
4
4
  This error has either been removed or compacted and is no longer available.
@@ -1,32 +1,28 @@
1
- <% if @pagination && @pagination.paginate? %>
1
+ <% if @current_page && (@current_page > 1 || @next_page) %>
2
2
  <div id="pagination" class="container mb-5">
3
3
  <div class="row">
4
4
  <nav>
5
5
  <ul class="pagination justify-content-center">
6
- <li class="page-item <%= 'disabled' unless @pagination.first_offset? %>">
7
- <a class="page-link" href="<%= current_path(@pagination.offset_key => @pagination.first_offset) %>">
6
+ <li class="page-item <%= 'disabled' if @current_page <= 1 %>">
7
+ <a class="page-link" href="<%= current_path(page: 1) %>">
8
8
  <span>&laquo;</span>
9
9
  </a>
10
10
  </li>
11
11
 
12
- <li class="page-item <%= 'disabled' unless @pagination.previous_offset? %>">
13
- <a class="page-link" href="<%= current_path(@pagination.offset_key => @pagination.previous_offset) %>">
12
+ <li class="page-item <%= 'disabled' if @current_page <= 1 %>">
13
+ <a class="page-link" href="<%= current_path(page: @current_page - 1) %>">
14
14
  <span>&lsaquo; Prev</span>
15
15
  </a>
16
16
  </li>
17
17
 
18
- <% if @pagination.current_offset? %>
19
- <li class="page-item active disabled">
20
- <a class="page-link" href="<%= current_path(@pagination.offset_key => @pagination.current_offset) %>">
21
- <span>
22
- <%= @pagination.current_label %>
23
- </span>
24
- </a>
25
- </li>
26
- <% end %>
18
+ <li class="page-item active disabled">
19
+ <a class="page-link" href="<%= current_path(page: @current_page) %>">
20
+ <span><%= @current_page %></span>
21
+ </a>
22
+ </li>
27
23
 
28
- <li class="page-item <%= 'disabled' unless @pagination.next_offset? %>">
29
- <a class="page-link" href="<%= current_path(@pagination.offset_key => @pagination.next_offset) %>">
24
+ <li class="page-item <%= 'disabled' unless @next_page %>">
25
+ <a class="page-link" href="<%= current_path(page: @next_page) %>">
30
26
  <span>Next &rsaquo;</span>
31
27
  </a>
32
28
  </li>
@@ -3,6 +3,6 @@
3
3
  module Karafka
4
4
  module Web
5
5
  # Current gem version
6
- VERSION = '0.6.2'
6
+ VERSION = '0.6.3'
7
7
  end
8
8
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -218,15 +218,7 @@ files:
218
218
  - lib/karafka/web/ui/controllers/status.rb
219
219
  - lib/karafka/web/ui/helpers/application_helper.rb
220
220
  - lib/karafka/web/ui/lib/hash_proxy.rb
221
- - lib/karafka/web/ui/lib/paginations/base.rb
222
- - lib/karafka/web/ui/lib/paginations/offset_based.rb
223
- - lib/karafka/web/ui/lib/paginations/page_based.rb
224
- - lib/karafka/web/ui/lib/paginations/paginators/arrays.rb
225
- - lib/karafka/web/ui/lib/paginations/paginators/base.rb
226
- - lib/karafka/web/ui/lib/paginations/paginators/partitions.rb
227
- - lib/karafka/web/ui/lib/paginations/paginators/sets.rb
228
- - lib/karafka/web/ui/lib/ttl_cache.rb
229
- - lib/karafka/web/ui/models/cluster_info.rb
221
+ - lib/karafka/web/ui/lib/paginate_array.rb
230
222
  - lib/karafka/web/ui/models/consumer_group.rb
231
223
  - lib/karafka/web/ui/models/counters.rb
232
224
  - lib/karafka/web/ui/models/health.rb
@@ -272,10 +264,7 @@ files:
272
264
  - lib/karafka/web/ui/pro/views/errors/_breadcrumbs.erb
273
265
  - lib/karafka/web/ui/pro/views/errors/_error.erb
274
266
  - lib/karafka/web/ui/pro/views/errors/_partition_option.erb
275
- - lib/karafka/web/ui/pro/views/errors/_table.erb
276
- - lib/karafka/web/ui/pro/views/errors/_title_with_select.erb
277
267
  - lib/karafka/web/ui/pro/views/errors/index.erb
278
- - lib/karafka/web/ui/pro/views/errors/partition.erb
279
268
  - lib/karafka/web/ui/pro/views/errors/show.erb
280
269
  - lib/karafka/web/ui/pro/views/explorer/_breadcrumbs.erb
281
270
  - lib/karafka/web/ui/pro/views/explorer/_detail.erb
@@ -291,10 +280,6 @@ files:
291
280
  - lib/karafka/web/ui/pro/views/explorer/partition/_messages.erb
292
281
  - lib/karafka/web/ui/pro/views/explorer/partition/_watermark_offsets.erb
293
282
  - lib/karafka/web/ui/pro/views/explorer/show.erb
294
- - lib/karafka/web/ui/pro/views/explorer/topic.erb
295
- - lib/karafka/web/ui/pro/views/explorer/topic/_empty.erb
296
- - lib/karafka/web/ui/pro/views/explorer/topic/_limited.erb
297
- - lib/karafka/web/ui/pro/views/explorer/topic/_partitions.erb
298
283
  - lib/karafka/web/ui/pro/views/health/_breadcrumbs.erb
299
284
  - lib/karafka/web/ui/pro/views/health/_partition.erb
300
285
  - lib/karafka/web/ui/pro/views/health/index.erb
metadata.gz.sig CHANGED
Binary file
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Karafka
4
- module Web
5
- module Ui
6
- module Lib
7
- # Namespace for all the types of pagination engines we want to support
8
- module Paginations
9
- # Abstraction on top of pagination, so we can alter pagination key and other things
10
- # for non-standard pagination views (non page based, etc)
11
- #
12
- # @note We do not use `_page` explicitly to indicate, that the page scope may not operate
13
- # on numerable pages (1,2,3,4) but can operate on offsets or times, etc. `_offset` is
14
- # more general and may refer to many types of pagination.
15
- class Base
16
- attr_reader :previous_offset, :current_offset, :next_offset
17
-
18
- # @return [Boolean] Should we show pagination at all
19
- def paginate?
20
- raise NotImplementedError, 'Implement in a subclass'
21
- end
22
-
23
- # @return [Boolean] Should first offset link be active. If false, the first offset link
24
- # will be disabled
25
- def first_offset?
26
- raise NotImplementedError, 'Implement in a subclass'
27
- end
28
-
29
- # @return [String] first offset url value
30
- def first_offset
31
- raise NotImplementedError, 'Implement in a subclass'
32
- end
33
-
34
- # @return [Boolean] Should previous offset link be active. If false, the previous
35
- # offset link will be disabled
36
- def previous_offset?
37
- raise NotImplementedError, 'Implement in a subclass'
38
- end
39
-
40
- # @return [Boolean] Should we show current offset. If false, the current offset link
41
- # will not be visible at all. Useful for non-linear pagination.
42
- def current_offset?
43
- raise NotImplementedError, 'Implement in a subclass'
44
- end
45
-
46
- # @return [Boolean] Should we show next offset pagination. If false, next offset link
47
- # will be disabled.
48
- def next_offset?
49
- raise NotImplementedError, 'Implement in a subclass'
50
- end
51
-
52
- # @return [String] the url offset key
53
- def offset_key
54
- raise NotImplementedError, 'Implement in a subclass'
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Karafka
4
- module Web
5
- module Ui
6
- module Lib
7
- module Paginations
8
- # Kafka offset based pagination backend
9
- #
10
- # Allows us to support paginating over offsets
11
- class OffsetBased < Base
12
- # @param previous_offset [Integer, false] previous offset or false if should not be
13
- # presented
14
- # @param current_offset [Integer] current offset
15
- # @param next_offset [Integer, Boolean] should we show next offset page button. If
16
- # false it will not be presented.
17
- # @param visible_offsets [Array<Integer>] offsets that are visible in the paginated
18
- # view. It is needed for the current page label
19
- def initialize(
20
- previous_offset,
21
- current_offset,
22
- next_offset,
23
- visible_offsets
24
- )
25
- @previous_offset = previous_offset
26
- @current_offset = current_offset
27
- @next_offset = next_offset
28
- @visible_offsets = visible_offsets
29
- super()
30
- end
31
-
32
- # Show pagination only when there is more than one page of results to be presented
33
- #
34
- # @return [Boolean]
35
- def paginate?
36
- @current_offset && (!!@previous_offset || !!@next_offset)
37
- end
38
-
39
- # @return [Boolean] active only when we are not on the first page. First page is always
40
- # indicated by the current offset being -1. If there is someone that sets up the
41
- # current offset to a value equal to the last message in the topic partition, we do
42
- # not consider it as a first page and we allow to "reset" to -1 via the first page
43
- # button
44
- def first_offset?
45
- @current_offset != -1
46
- end
47
-
48
- # @return [Boolean] first page offset is always nothing because we use the default -1
49
- # for the offset.
50
- def first_offset
51
- false
52
- end
53
-
54
- # @return [Boolean] Active previous page link when it is not the first page
55
- def previous_offset?
56
- !!@previous_offset
57
- end
58
-
59
- # @return [Boolean] We show current label with offsets that are present on the given
60
- # page
61
- def current_offset?
62
- true
63
- end
64
-
65
- # @return [Boolean] move to the next page if not false. False indicates, that there is
66
- # no next page to move to
67
- def next_offset?
68
- !!@next_offset
69
- end
70
-
71
- # If there is no next offset, we point to 0 as there should be no smaller offset than
72
- # that in Kafka ever
73
- # @return [Integer]
74
- def next_offset
75
- next_offset? ? @next_offset : 0
76
- end
77
-
78
- # @return [String] label of the current page. It is combined out of the first and
79
- # the last offsets to show the range where we are. It will be empty if no offsets
80
- # but this is not a problem as then we should not display pagination at all
81
- def current_label
82
- first = @visible_offsets.first
83
- last = @visible_offsets.last
84
- [first, last].compact.uniq.join(' - ').to_s
85
- end
86
-
87
- # @return [String] for offset based pagination we use the offset param name
88
- def offset_key
89
- 'offset'
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Karafka
4
- module Web
5
- module Ui
6
- module Lib
7
- module Paginations
8
- # Regular page-based pagination engine
9
- class PageBased < Base
10
- # @param current_offset [Integer] current page
11
- # @param show_next_offset [Boolean] should we show next page
12
- # (value is computed automatically)
13
- def initialize(
14
- current_offset,
15
- show_next_offset
16
- )
17
- @previous_offset = current_offset - 1
18
- @current_offset = current_offset
19
- @next_offset = show_next_offset ? current_offset + 1 : false
20
- super()
21
- end
22
-
23
- # Show pagination only when there is more than one page
24
- # @return [Boolean]
25
- def paginate?
26
- @current_offset && (@current_offset > 1 || !!@next_offset)
27
- end
28
-
29
- # @return [Boolean] active the first page link when we are not on the first page
30
- def first_offset?
31
- @current_offset > 1
32
- end
33
-
34
- # @return [Boolean] first page for page based pagination is always empty as it moves us
35
- # to the initial page so we do not include any page info
36
- def first_offset
37
- false
38
- end
39
-
40
- # @return [Boolean] Active previous page link when it is not the first page
41
- def previous_offset?
42
- @current_offset > 1
43
- end
44
-
45
- # @return [Boolean] always show current offset pagination value
46
- def current_offset?
47
- true
48
- end
49
-
50
- # @return [String] label of the current page
51
- def current_label
52
- @current_offset.to_s
53
- end
54
-
55
- # @return [Boolean] move to the next page if not false. False indicates, that there is
56
- # no next page to move to
57
- def next_offset?
58
- @next_offset
59
- end
60
-
61
- # @return [String] for page pages pagination, always use page as the url value
62
- def offset_key
63
- 'page'
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end