Module: Foreman::Controller::TaxonomiesController

Extended by:
ActiveSupport::Concern
Included in:
LocationsController, OrganizationsController
Defined in:
lib/foreman/controller/taxonomies_controller.rb

Instance Method Summary collapse

Instance Method Details

#assign_all_hostsObject


130
131
132
133
134
# File 'lib/foreman/controller/taxonomies_controller.rb', line 130

def assign_all_hosts
  Host.send("no_#{taxonomy_single}").update_all(taxonomy_id => @taxonomy.id)
  @taxonomy.import_missing_ids
  redirect_to send("#{taxonomies_plural}_path"), :notice => _("All hosts previously with no %{single} are now assigned to %{name}") % { :single => taxonomy_single, :name => @taxonomy.name }
end

#assign_hostsObject


124
125
126
127
128
# File 'lib/foreman/controller/taxonomies_controller.rb', line 124

def assign_hosts
  @taxonomy_type = taxonomy_single.classify
  @hosts = Host.my_hosts.send("no_#{taxonomy_single}").search_for(params[:search],:order => params[:order]).paginate :page => params[:page], :include => included_associations
  render "hosts/assign_hosts"
end

#assign_selected_hostsObject


136
137
138
139
140
141
# File 'lib/foreman/controller/taxonomies_controller.rb', line 136

def assign_selected_hosts
  host_ids = params[taxonomy_single.to_sym][:host_ids] - ["0"]
  @hosts = Host.where(:id => host_ids).update_all(taxonomy_id => @taxonomy.id)
  @taxonomy.import_missing_ids
  redirect_to send("#{taxonomies_plural}_path"), :notice => _("Selected hosts are now assigned to %s") % @taxonomy.name
end

#clearObject


98
99
100
101
102
103
104
# File 'lib/foreman/controller/taxonomies_controller.rb', line 98

def clear
  taxonomy_class.current = nil
  session[taxonomy_id] = nil

  TopbarSweeper.expire_cache(self)
  redirect_back_or_to root_url
end

#clone_taxonomyObject

cannot name this method “clone” since Object has a clone method and the mixin doesn't overwrite it


38
39
40
41
42
# File 'lib/foreman/controller/taxonomies_controller.rb', line 38

def clone_taxonomy
  @old_name = @taxonomy.name
  @taxonomy = @taxonomy.dup
  render 'taxonomies/clone'
end

#createObject


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/foreman/controller/taxonomies_controller.rb', line 44

def create
  @taxonomy = taxonomy_class.new(params[taxonomy_single.to_sym])
  if @taxonomy.save
    if @count_nil_hosts > 0
      redirect_to send("step2_#{taxonomy_single}_path",@taxonomy)
    else
      process_success(:object => @taxonomy)
    end
  else
    process_error(:render => "taxonomies/new", :object => @taxonomy)
  end
end

#destroyObject


82
83
84
85
86
87
88
# File 'lib/foreman/controller/taxonomies_controller.rb', line 82

def destroy
  if @taxonomy.destroy
    process_success
  else
    process_error
  end
end

#editObject


57
58
59
60
61
62
# File 'lib/foreman/controller/taxonomies_controller.rb', line 57

def edit
  Taxonomy.no_taxonomy_scope do
    # we explicitly render here in order to evaluate the view without taxonomy scope
    render 'taxonomies/edit'
  end
end

#import_mismatchesObject


113
114
115
116
117
118
119
120
121
122
# File 'lib/foreman/controller/taxonomies_controller.rb', line 113

def import_mismatches
  @taxonomy = Taxonomy.find_by_id(params[:id])
  if @taxonomy
    @mismatches = @taxonomy.import_missing_ids
    redirect_to send("edit_#{taxonomy_single}_path", @taxonomy), :notice => _("All mismatches between hosts and %s have been fixed") % @taxonomy.name
  else
    Taxonomy.all_import_missing_ids
    redirect_to send("#{taxonomies_plural}_path"), :notice => _("All mismatches between hosts and locations/organizations have been fixed")
  end
end

#indexObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/foreman/controller/taxonomies_controller.rb', line 12

def index
  begin
    values = taxonomy_class.send("my_#{taxonomies_plural}").search_for(params[:search], :order => params[:order])
  rescue => e
    error e.to_s
    values = taxonomy_class.send("my_#{taxonomies_plural}")
  end

  respond_to do |format|
    format.html do
      @taxonomies = values.paginate(:page => params[:page])
      @counter = Host.group(taxonomy_id).where(taxonomy_id => values).count
      render 'taxonomies/index'
    end
  end
end

#mismatchesObject


106
107
108
109
110
111
# File 'lib/foreman/controller/taxonomies_controller.rb', line 106

def mismatches
  Taxonomy.no_taxonomy_scope do
    @mismatches = Taxonomy.all_mismatcheds
  end
  render 'taxonomies/mismatches'
end

#newObject


29
30
31
32
33
34
35
# File 'lib/foreman/controller/taxonomies_controller.rb', line 29

def new
  @taxonomy = taxonomy_class.new
  Taxonomy.no_taxonomy_scope do
    # we explicitly render here in order to evaluate the view without taxonomy scope
    render 'taxonomies/new'
  end
end

#selectObject


90
91
92
93
94
95
96
# File 'lib/foreman/controller/taxonomies_controller.rb', line 90

def select
  taxonomy_class.current = @taxonomy
  session[taxonomy_id] = @taxonomy ? @taxonomy.id : nil

  TopbarSweeper.expire_cache(self)
  redirect_back_or_to root_url
end

#step2Object


64
65
66
67
68
# File 'lib/foreman/controller/taxonomies_controller.rb', line 64

def step2
  Taxonomy.no_taxonomy_scope do
    render 'taxonomies/step2'
  end
end

#updateObject


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/foreman/controller/taxonomies_controller.rb', line 70

def update
  result = Taxonomy.no_taxonomy_scope do
    (params[taxonomy_single.to_sym][:ignore_types] -= ["0"]) if params[taxonomy_single.to_sym][:ignore_types]
    @taxonomy.update_attributes(params[taxonomy_single.to_sym])
  end
  if result
    process_success(:object => @taxonomy)
  else
    process_error(:render => "taxonomies/edit", :object => @taxonomy)
  end
end