6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/kaui/bundles_controller.rb', line 6
def index
cached_options_for_klient = options_for_klient
@search_query = params[:q].presence
@search_by = params[:search_by] || 'bundle_id'
@per_page = (params[:per_page] || 10).to_i
@page = (params[:page] || 1).to_i
fetch_bundle_tags = promise do
all_bundle_tags = @account.all_tags(:BUNDLE, false, 'NONE', cached_options_for_klient)
all_bundle_tags.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
end
fetch_subscription_tags = promise do
all_subscription_tags = @account.all_tags(:SUBSCRIPTION, false, 'NONE', cached_options_for_klient)
all_subscription_tags.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
end
fetch_bundle_fields = promise do
all_bundle_fields = @account.all_custom_fields(:BUNDLE, 'NONE', cached_options_for_klient)
all_bundle_fields.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
end
fetch_subscription_fields = promise do
all_subscription_fields = @account.all_custom_fields(:SUBSCRIPTION, 'NONE', cached_options_for_klient)
all_subscription_fields.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
end
fetch_available_tags = promise { Kaui::TagDefinition.all_for_bundle(cached_options_for_klient) }
fetch_available_subscription_tags = promise { Kaui::TagDefinition.all_for_subscription(cached_options_for_klient) }
if @search_query.present?
@bundles = search_bundles(@search_query, @search_by, cached_options_for_klient)
@total_pages = 1
@page = 1
else
fetched = Kaui::Account.paginated_bundles(@account.account_id, (@page - 1) * @per_page, @per_page, 'NONE', cached_options_for_klient)
@bundles = fetched
@total_pages = (fetched..to_f / @per_page).ceil
end
@tags_per_bundle = wait(fetch_bundle_tags)
@tags_per_subscription = wait(fetch_subscription_tags)
@custom_fields_per_bundle = wait(fetch_bundle_fields)
@custom_fields_per_subscription = wait(fetch_subscription_fields)
@available_tags = wait(fetch_available_tags)
@available_subscription_tags = wait(fetch_available_subscription_tags)
start_dates = @bundles.flat_map(&:subscriptions).filter_map(&:start_date).uniq
@catalogs = start_dates.filter_map do |date|
Kaui::Catalog.get_account_catalog_json(@account.account_id, date, cached_options_for_klient)&.last
rescue StandardError
nil
end.uniq(&:effective_date)
@subscription = {}
@bundles.each do |bundle|
bundle.subscriptions.each do |sub|
next if sub.product_category == 'ADD_ON'
@subscription[bundle.bundle_id] = sub
break
end
end
end
|