Class: Kaui::BundlesController

Inherits:
EngineController show all
Defined in:
app/controllers/kaui/bundles_controller.rb

Constant Summary

Constants included from EngineControllerUtil

EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD

Instance Method Summary collapse

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

Instance Method Details

#do_pause_resumeObject


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/kaui/bundles_controller.rb', line 69

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], options_for_klient)
    paused = true
  end

  if params[:resume_requested_date].present?
    bundle.resume(params[:resume_requested_date], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
    resumed = true
  end

  msg = 'Bundle was successfully '
  if paused && !resumed
    msg += 'paused'
  elsif !paused && resumed
    msg += 'resumed'
  else
    msg += 'updated'
  end
  redirect_to kaui_engine.(@account.), :notice => msg
end

#do_transferObject


48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/kaui/bundles_controller.rb', line 48

def do_transfer
  cached_options_for_klient = options_for_klient

   = Kaui::Account::find_by_id_or_key(params.require(:new_account_key), false, false, cached_options_for_klient)

  bundle = Kaui::Bundle::new(:bundle_id => params.require(:id), :account_id => .)
  bundle.transfer(nil, params[:billing_policy], current_user.kb_username, params[:reason], params[:comment], cached_options_for_klient)

  redirect_to kaui_engine.(.), :notice => 'Bundle was successfully transferred'
end

#indexObject


3
4
5
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
# File 'app/controllers/kaui/bundles_controller.rb', line 3

def index
  cached_options_for_klient = options_for_klient

  fetch_bundles = promise { @account.bundles(cached_options_for_klient) }
  fetch_bundle_tags = promise {
    all_bundle_tags = @account.all_tags(:BUNDLE, false, 'NONE', cached_options_for_klient)
    all_bundle_tags.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
  }
  fetch_subscription_tags = promise {
    all_subscription_tags = @account.all_tags(:SUBSCRIPTION, false, 'NONE', cached_options_for_klient)
    all_subscription_tags.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
  }
  fetch_bundle_fields = promise {
    all_bundle_fields = @account.all_custom_fields(:BUNDLE, 'NONE', cached_options_for_klient)
    all_bundle_fields.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
  }
  fetch_subscription_fields = promise {
    all_subscription_fields = @account.all_custom_fields(:SUBSCRIPTION, 'NONE', cached_options_for_klient)
    all_subscription_fields.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
  }
  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) }

  @bundles = wait(fetch_bundles)
  @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)

  @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_resumeObject


64
65
66
67
# File 'app/controllers/kaui/bundles_controller.rb', line 64

def pause_resume
  @bundle = Kaui::Bundle.find_by_id_or_key(params.require(:id), options_for_klient)
  @base_subscription = @bundle.subscriptions.find { |sub| sub.product_category == 'BASE' }
end

#restful_showObject


59
60
61
62
# File 'app/controllers/kaui/bundles_controller.rb', line 59

def restful_show
  bundle = Kaui::Bundle.find_by_id_or_key(params.require(:id), options_for_klient)
  redirect_to kaui_engine.(bundle.)
end

#transferObject


44
45
46
# File 'app/controllers/kaui/bundles_controller.rb', line 44

def transfer
  @bundle_id = params.require(:id)
end