Class: Kaui::BundlesController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::BundlesController
- Defined in:
- app/controllers/kaui/bundles_controller.rb
Constant Summary
Constants included from EngineControllerUtil
EngineControllerUtil::MAXIMUM_NUMBER_OF_RECORDS_DOWNLOAD, EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD
Instance Method Summary collapse
- #do_pause_resume ⇒ Object
- #do_transfer ⇒ Object
-
#index ⇒ Object
rubocop:disable Lint/HashCompareByIdentity.
- #pause_resume ⇒ Object
- #restful_show ⇒ Object
-
#transfer ⇒ Object
rubocop:enable Lint/HashCompareByIdentity.
Methods inherited from EngineController
#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient, #populate_account_details, #retrieve_allowed_users_for_current_user, #retrieve_tenants_for_current_user
Methods included from ErrorHandler
Instance Method Details
#do_pause_resume ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/kaui/bundles_controller.rb', line 104 def do_pause_resume bundle = Kaui::Bundle.new(bundle_id: params.require(:id)) paused = false resumed = false if params[:pause_requested_date].present? bundle.pause(params[:pause_requested_date], current_user.kb_username, params[:reason], params[:comment], ) paused = true end if params[:resume_requested_date].present? bundle.resume(params[:resume_requested_date], current_user.kb_username, params[:reason], params[:comment], ) resumed = true end msg = 'Bundle was successfully ' msg += if paused && !resumed 'paused' elsif !paused && resumed 'resumed' else 'updated' end redirect_to kaui_engine.account_bundles_path(@account.account_id), notice: msg end |
#do_transfer ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/kaui/bundles_controller.rb', line 83 def do_transfer = new_account = Kaui::Account.find_by_id_or_key(params.require(:new_account_key), false, false, ) bundle = Kaui::Bundle.new(bundle_id: params.require(:id), account_id: new_account.account_id) bundle.transfer(nil, params[:billing_policy], current_user.kb_username, params[:reason], params[:comment], ) redirect_to kaui_engine.account_bundles_path(new_account.account_id), notice: 'Bundle was successfully transferred' end |
#index ⇒ Object
rubocop:disable Lint/HashCompareByIdentity
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 = @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 = promise do = @account.(:BUNDLE, false, 'NONE', ) .each_with_object({}) do |entry, hsh| (hsh[entry.object_id] ||= []) << entry end end = promise do = @account.(:SUBSCRIPTION, false, 'NONE', ) .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', ) 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', ) all_subscription_fields.each_with_object({}) do |entry, hsh| (hsh[entry.object_id] ||= []) << entry end end = promise { Kaui::TagDefinition.all_for_bundle() } = promise { Kaui::TagDefinition.all_for_subscription() } if @search_query.present? @bundles = search_bundles(@search_query, @search_by, ) @total_pages = 1 @page = 1 else fetched = Kaui::Account.paginated_bundles(@account.account_id, (@page - 1) * @per_page, @per_page, 'NONE', ) @bundles = fetched @total_pages = (fetched.pagination_max_nb_records.to_f / @per_page).ceil end @tags_per_bundle = wait() @tags_per_subscription = wait() @custom_fields_per_bundle = wait(fetch_bundle_fields) @custom_fields_per_subscription = wait(fetch_subscription_fields) @available_tags = wait() @available_subscription_tags = wait() # Collect the distinct start dates from subscriptions on this page, then fetch # only the catalog versions needed — one per unique date — to avoid loading all # historical versions into memory. 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, )&.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 |
#pause_resume ⇒ Object
99 100 101 102 |
# File 'app/controllers/kaui/bundles_controller.rb', line 99 def pause_resume @bundle = Kaui::Bundle.find_by_id_or_key(params.require(:id), ) @base_subscription = @bundle.subscriptions.find { |sub| sub.product_category == 'BASE' } end |
#restful_show ⇒ Object
94 95 96 97 |
# File 'app/controllers/kaui/bundles_controller.rb', line 94 def restful_show bundle = Kaui::Bundle.find_by_id_or_key(params.require(:id), ) redirect_to kaui_engine.account_bundles_path(bundle.account_id) end |
#transfer ⇒ Object
rubocop:enable Lint/HashCompareByIdentity
79 80 81 |
# File 'app/controllers/kaui/bundles_controller.rb', line 79 def transfer @bundle_id = params.require(:id) end |