Class: ApplicationTypesController

Inherits:
ConsoleController show all
Includes:
Console::ModelHelper
Defined in:
app/controllers/application_types_controller.rb

Instance Method Summary collapse

Methods included from Console::ModelHelper

#can_scale_application_type, #cannot_scale_title, #cartridge_gear_group_count, #common_tags_for, #gear_group_count, #gear_group_count_title, #gear_group_state, #gear_group_states, #in_groups_by_tag, #scale_from_options, #scale_options, #scale_range, #scale_to_options, #web_cartridge_scale_title

Methods inherited from ConsoleController

#active_tab

Methods included from SshkeyAware

#sshkey_uploaded?

Methods included from DomainAware

#domain_is_missing, #user_default_domain

Methods included from CapabilityAware

#user_capabilities

Instance Method Details

#indexObject



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
43
44
45
46
47
# File 'app/controllers/application_types_controller.rb', line 5

def index
  @capabilities = user_capabilities
  flash.now[:warning] = "You have no free gears.  You'll need to scale down or delete another application first." unless @capabilities.gears_free?

  @browse_tags = [
    ['Java', :java],
    ['PHP', :php],
    ['Ruby', :ruby],
    ['Python', :python],
    ['Node.js', :nodejs],
    ['Perl', :perl],
    nil,
    ['All web cartridges', :cartridge],
    ['All quickstart applications', :instant_app],
    nil,
    ['Blogs', :blog],
    ['Content management systems', :cms],
    #['MongoDB', :mongo],
  ]

  if @tag = params[:tag].presence
    types = ApplicationType.tagged(@tag)
    @type_groups = [["Tagged with #{Array(@tag).to_sentence}", types.sort!]]

    render :search
  elsif @search = params[:search].presence
    types = ApplicationType.search(@search)
    @type_groups = [["Matches search '#{@search}'", types]]

    render :search
  else
    types = ApplicationType.all
    @featured_types = types.select{ |t| t.tags.include?(:featured) }.sample(3).sort!
    groups, other = in_groups_by_tag(types - @featured_types, [:instant_app, :java, :php, :ruby, :python])
    groups.each do |g|
      g[2] = application_types_path(:tag => g[0])
      g[1].sort!
      g[0] = I18n.t(g[0], :scope => :types, :default => g[0].to_s.titleize)
    end
    groups << ['Other types', other.sort!] unless other.empty?
    @type_groups = groups
  end
end

#showObject



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
77
78
79
# File 'app/controllers/application_types_controller.rb', line 49

def show
  app_params = params[:application] || params
  app_type_params = params[:application_type] || app_params
  @advanced = to_boolean(params[:advanced])

  user_default_domain rescue (@domain = Domain.new)

  @compact = false # @domain.persisted?

  @application_type = params[:id] == 'custom' ?
    ApplicationType.custom(app_type_params) :
    ApplicationType.find(params[:id])

  @capabilities = user_capabilities :refresh => true

  @application = (@application_type >> Application.new(:as => current_user)).assign_attributes(app_params)
  @application.gear_profile = @capabilities.gear_sizes.first unless @capabilities.gear_sizes.include?(@application.gear_profile)

  begin
    @cartridges, @missing_cartridges = @application_type.matching_cartridges
    flash.now[:error] = "No cartridges are defined for this type - all applications require at least one web cartridge" unless @cartridges.present?
  rescue ApplicationType::CartridgeSpecInvalid
    logger.debug $!
    flash.now[:error] = "The cartridges defined for this type are not valid.  The #{@application_type.source} may not be correct."
  end

  flash.now[:error] = "You have no free gears.  You'll need to scale down or delete another application first." unless @capabilities.gears_free?
  @disabled = @missing_cartridges.present? || @cartridges.blank?

  user_default_domain rescue nil
end