foreman/app/controllers/puppetclasses_controller.rb @ d9a2ebac
017e1049 | Ohad Levy | require 'foreman/controller/environments'
|
|
c6eee281 | Ohad Levy | class PuppetclassesController < ApplicationController
|
|
1c4e9d45 | Ohad Levy | include Foreman::Controller::Environments
|
|
ac7fe332 | Ohad Levy | include Foreman::Controller::AutoCompleteSearch
|
|
a3ab05bd | Ohad Levy | before_filter :find_by_name, :only => [:edit, :update, :destroy, :assign]
|
|
31207a31 | Ohad Levy | before_filter :setup_search_options, :only => :index
|
|
bee8f73b | Ohad Levy | ||
af6e2624 | Ohad Levy | def index
|
|
31207a31 | Ohad Levy | begin
|
|
values = Puppetclass.search_for(params[:search], :order => params[:order])
|
|||
rescue => e
|
|||
error e.to_s
|
|||
values = Puppetclass.search_for ""
|
|||
end
|
|||
3aa6ea3f | Ohad Levy | respond_to do |format|
|
|
format.html do
|
|||
31207a31 | Ohad Levy | @puppetclasses = values.paginate :page => params[:page], :include => [:environments, :hostgroups]
|
|
d9a2ebac | Ohad Levy | @host_counter = Host.count(:group => :puppetclass_id, :joins => :puppetclasses, :conditions => {:puppetclasses => {:id => @puppetclasses}})
|
|
@keys_counter = LookupKey.count(:group => :puppetclass_id, :conditions => {:puppetclass_id => @puppetclasses})
|
|||
3aa6ea3f | Ohad Levy | end
|
|
ac7fe332 | Ohad Levy | format.json { render :json => Puppetclass.classes2hash(values.all(:select => "name, id")) }
|
|
3aa6ea3f | Ohad Levy | end
|
|
6e50fa1d | Ohad Levy | end
|
|
af6e2624 | Ohad Levy | ||
def new
|
|||
@puppetclass = Puppetclass.new
|
|||
end
|
|||
def create
|
|||
@puppetclass = Puppetclass.new(params[:puppetclass])
|
|||
if @puppetclass.save
|
|||
754b1a01 | Ohad Levy | notice "Successfully created puppetclass."
|
|
af6e2624 | Ohad Levy | redirect_to puppetclasses_url
|
|
else
|
|||
render :action => 'new'
|
|||
end
|
|||
end
|
|||
def edit
|
|||
end
|
|||
def update
|
|||
if @puppetclass.update_attributes(params[:puppetclass])
|
|||
754b1a01 | Ohad Levy | notice "Successfully updated puppetclass."
|
|
af6e2624 | Ohad Levy | redirect_to puppetclasses_url
|
|
else
|
|||
render :action => 'edit'
|
|||
end
|
|||
end
|
|||
def destroy
|
|||
if @puppetclass.destroy
|
|||
754b1a01 | Ohad Levy | notice "Successfully destroyed puppetclass."
|
|
af6e2624 | Ohad Levy | else
|
|
754b1a01 | Ohad Levy | error @puppetclass.errors.full_messages.join("<br/>")
|
|
af6e2624 | Ohad Levy | end
|
|
redirect_to puppetclasses_url
|
|||
end
|
|||
6e50fa1d | Ohad Levy | end
|