Class: ApplicationsController

Inherits:
ConsoleController show all
Defined in:
app/controllers/applications_controller.rb

Instance Method Summary collapse

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

#createObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'app/controllers/applications_controller.rb', line 106

def create
  app_params = params[:application] || params
  @advanced = to_boolean(params[:advanced])
  type = params[:application_type] || app_params[:application_type]
  domain_name = app_params[:domain_name].presence || app_params[:domain_id].presence

  @application_type = (type == 'custom' || !type.is_a?(String)) ?
    ApplicationType.custom(type) :
    ApplicationType.find(type)

  @capabilities = user_capabilities :refresh => true

  @application = (@application_type >> Application.new(:as => current_user)).assign_attributes(app_params)

  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

  #@cartridges, @missing_cartridges = ApplicationType.matching_cartridges(@application.cartridge_names.presence || @application_type.cartridges)

  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?

  # opened bug 789763 to track simplifying this block - with domain_name submission we would
  # only need to check that domain_name is set (which it should be by the show form)
  @domain = Domain.find :first, :as => current_user
  unless @domain
    @domain = Domain.create :name => domain_name, :as => current_user
    unless @domain.persisted?
      logger.debug "Unable to create domain, #{@domain.errors.to_hash.inspect}"
      @application.valid? # set any errors on the application object
      #FIXME: Ideally this should be inferred via associations between @domain and @application
      @domain.errors.values.flatten.uniq.each {|e| @application.errors.add(:domain_name, e) }

      return render 'application_types/show'
    end
  end
  @application.domain = @domain

  if @application.save
    messages = @application.remote_results

    redirect_to get_started_application_path(@application, :wizard => true), :flash => {:info_pre => messages}
  else
    logger.debug @application.errors.inspect

    render 'application_types/show'
  end
end

#deleteObject



94
95
96
97
98
99
100
# File 'app/controllers/applications_controller.rb', line 94

def delete
  #@domain = Domain.find :one, :as => current_user
  user_default_domain
  @application = @domain.find_application params[:id]

  @referer = application_path(@application)
end

#destroyObject



84
85
86
87
88
89
90
91
92
# File 'app/controllers/applications_controller.rb', line 84

def destroy
  @domain = Domain.find :one, :as => current_user
  @application = @domain.find_application params[:id]
  if @application.destroy
    redirect_to applications_path, :flash => {:success => "The application '#{@application.name}' has been deleted"}
  else
    render :delete
  end
end

#get_startedObject



170
171
172
173
174
175
176
177
# File 'app/controllers/applications_controller.rb', line 170

def get_started
  #@domain = Domain.find :one, :as => current_user
  user_default_domain
  @application = @domain.find_application params[:id]

  @wizard = !params[:wizard].nil?
  sshkey_uploaded?
end

#indexObject



73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/applications_controller.rb', line 73

def index
  # replace domains with Applications.find :all, :as => current_user
  # in the future
  #domain = Domain.find :one, :as => current_user rescue nil
  user_default_domain rescue nil
  return redirect_to application_types_path, :notice => 'Create your first application now!' if @domain.nil? || @domain.applications.empty?

  @applications_filter = ApplicationsFilter.new params[:applications_filter]
  @applications = @applications_filter.apply(@domain.applications)
end

#newObject



102
103
104
# File 'app/controllers/applications_controller.rb', line 102

def new
  redirect_to application_types_path
end

#showObject



160
161
162
163
164
165
166
167
168
# File 'app/controllers/applications_controller.rb', line 160

def show
  #@domain = Domain.find :one, :as => current_user
  user_default_domain
  @application = @domain.find_application params[:id]

  @gear_groups = @application.gear_groups_with_state

  sshkey_uploaded?
end