Skip to content

Commit

Permalink
Added OS Family attribute to Partition Tables and Installation Medium
Browse files Browse the repository at this point in the history
  • Loading branch information
ohadlevy committed Jun 24, 2012
1 parent ec80ab8 commit 8dbb38e
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 11 deletions.
5 changes: 5 additions & 0 deletions app/helpers/operatingsystems_helper.rb
Expand Up @@ -30,4 +30,9 @@ def os_name record, opts = {}
"#{icon(record, opts)} #{record}".html_safe
end

def os_habtm_family type, obj
result = type.where(:os_family => obj.family)
result.empty? ? type : result
end

end
4 changes: 3 additions & 1 deletion app/models/medium.rb
Expand Up @@ -18,7 +18,9 @@ class Medium < ActiveRecord::Base

before_destroy EnsureNotUsedBy.new(:hosts)
default_scope :order => 'LOWER(media.name)'
scoped_search :on => [:name, :path], :complete_value => :true
scoped_search :on => :name, :complete_value => :true, :default_order => true
scoped_search :on => :path, :complete_value => :true
scoped_search :on => :os_family, :rename => "family", :complete_value => :true

def as_json(options={})
options ||= {}
Expand Down
3 changes: 2 additions & 1 deletion app/models/ptable.rb
Expand Up @@ -13,8 +13,9 @@ class Ptable < ActiveRecord::Base
validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => "can't be blank or contain trailing white spaces."
default_scope :order => 'LOWER(ptables.name)'

scoped_search :on => :name, :complete_value => true
scoped_search :on => :name, :complete_value => true, :default_order => true
scoped_search :on => :layout, :complete_value => false
scoped_search :on => :os_family, :rename => "family", :complete_value => :true

def as_json(options={})
options ||= {}
Expand Down
2 changes: 1 addition & 1 deletion app/views/media/_form.html.erb
Expand Up @@ -9,7 +9,7 @@
<%= text_f f, :config_path, :class => "input-xxlarge", :help_inline => "The NFS path to the jumpstart control files." %>
<%= text_f f, :image_path, :class => "input-xxlarge", :help_inline => "The NFS path to the image directory." %>
</span>
<%= multiple_checkboxes f, :operatingsystems, @medium, Operatingsystem, :label => 'Operating Systems' %>
<%= selectable_f f, :os_family, Operatingsystem.families, { :include_blank => true }, { :label => "Operating System Family" } %>
<%= submit_or_cancel f %>
<% end %>
Expand Down
8 changes: 5 additions & 3 deletions app/views/media/index.html.erb
Expand Up @@ -6,14 +6,16 @@
<tr>
<th><%= sort :name %></th>
<th><%= sort :path %></th>
<th>Family</th>
<th>Operating systems</th>
<th></th>
</tr>
<% for medium in @media %>
<tr class="<%= cycle("even", "odd") -%>">
<td><%= link_to_if_authorized h(medium), hash_for_edit_medium_path(:id => medium.id) %></td>
<td><%=h medium.path %></td>
<td><%=h medium.operatingsystems.to_sentence %></td>
<td><%= link_to_if_authorized medium, hash_for_edit_medium_path(:id => medium.id) %></td>
<td><%= medium.path %></td>
<td><%= medium.os_family %></td>
<td><%= medium.operatingsystems.to_sentence %></td>
<td>
<%= display_delete_if_authorized hash_for_medium_path(:id => medium), :confirm => "Delete #{medium.name}?" %>
</td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/operatingsystems/_form.html.erb
Expand Up @@ -23,8 +23,8 @@
</div>

<%= multiple_checkboxes f, :architectures, @operatingsystem, Architecture %>
<%= multiple_checkboxes f, :ptables, @operatingsystem, Ptable, :label => "Partition tables" %>
<%= multiple_checkboxes f, :media, @operatingsystem, Medium, :label => "Installation media" %>
<%= multiple_checkboxes f, :ptables, @operatingsystem, os_habtm_family(Ptable, f.object), :label => "Partition tables" %>
<%= multiple_checkboxes f, :media, @operatingsystem, os_habtm_family(Medium, f.object), :label => "Installation media" %>
</div>

<%= render('template_defaults', :f => f) if SETTINGS[:unattended] -%>
Expand Down
2 changes: 1 addition & 1 deletion app/views/ptables/_form.html.erb
Expand Up @@ -3,6 +3,6 @@
<%= text_f f, :name %>
<%= textarea_f f, :layout, :class => "input-xxlarge",
:help_block => "<span class='label label-info'>Notice</span> you may use #{link_to 'a script as well', 'http://theforeman.org/projects/foreman/wiki/Dynamic_disk_partitioning', :rel => 'external'}".html_safe %>
<%= multiple_checkboxes f, :operatingsystems, @ptable, Operatingsystem, :label => "Operating Systems" %>
<%= selectable_f f, :os_family, Operatingsystem.families, { :include_blank => true }, { :label => "Operating System Family" } %>
<%= submit_or_cancel f %>
<% end %>
6 changes: 4 additions & 2 deletions app/views/ptables/index.html.erb
Expand Up @@ -4,13 +4,15 @@
<table class="table table-bordered table-striped">
<tr>
<th><%= sort :name %></th>
<th>Family</th>
<th>Operating systems</th>
<th></th>
</tr>
<% for ptable in @ptables %>
<tr class="<%= cycle("even", "odd") -%>">
<td><%=link_to_if_authorized h(ptable.name), hash_for_edit_ptable_path(:id => ptable.id) %></td>
<td><%=h ptable.operatingsystems.to_sentence %></td>
<td><%= link_to_if_authorized ptable, hash_for_edit_ptable_path(:id => ptable.id) %></td>
<td><%= ptable.os_family %></td>
<td><%= ptable.operatingsystems.to_sentence %></td>
<td>
<%= display_delete_if_authorized hash_for_ptable_path(:id => ptable), :confirm => "Delete #{ptable.name}?"%>
</td>
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20120624093958_add_os_family_to_media.rb
@@ -0,0 +1,14 @@
class AddOsFamilyToMedia < ActiveRecord::Migration
def self.up
add_column :media, :os_family, :string
Medium.reset_column_information
Medium.all.each do |m|
family = m.operatingsystems.map(&:family).uniq.first rescue nil
m.update_attribute(:os_family, family) if family
end
end

def self.down
remove_column :media, :os_family
end
end
17 changes: 17 additions & 0 deletions db/migrate/20120624094034_add_os_family_to_ptable.rb
@@ -0,0 +1,17 @@
class AddOsFamilyToPtable < ActiveRecord::Migration
def self.up
add_column :ptables, :os_family, :string
remove_column :ptables, :operatingsystem_id
Ptable.reset_column_information
Ptable.all.each do |p|
family = p.operatingsystems.map(&:family).uniq.first rescue nil
p.update_attribute(:os_family, family) if family
end

end

def self.down
remove_column :ptables, :os_family
add_column :ptables, :operatingsystem_id, :integer
end
end

0 comments on commit 8dbb38e

Please sign in to comment.