Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move category to package branch

Also, fix PackagesController#index view. Woo!
  • Loading branch information...
commit 90dddd55117df12e21f94eb259cb610126c9f02f 1 parent a70c024
@jnraine authored
View
6 app/controllers/packages_controller.rb
@@ -2,11 +2,7 @@ class PackagesController < ApplicationController
cache_sweeper :package_sweeper, :only => [:create, :edit, :destroy]
def index
- # TO-DO This query can be rethought because of the way the view uses this list of packages
- # it might be better to grab all the package branches from this environment and then iterate
- # through those grabbing all the different versions using the @packages@ method.
- # @packages = Package.latest_from_unit_and_environment(current_unit,current_environment).sort {|a,b| a.package_branch.name <=> b.package_branch.name }
- @package_branches = PackageBranch.unit(current_unit).order("name ASC").includes(:packages)
+ @package_branches = PackageBranch.unit(current_unit).order("name ASC").includes(:packages, :package_category)
respond_to do |format|
format.html
View
45 app/helpers/packages_helper.rb
@@ -28,35 +28,28 @@ def icon_picker(array,current_icon)
htmlcode += "</p>"
end
- def package_header(package, editable = nil)
- editable ||= false
+ def package_header(package, editable = nil)
+ editable ||= false
render :partial => 'record_header', :locals => {:title => package.display_name,
- :img => package.icon,
- :soft_info => package.name,
- :bold_info => package.version,
- :packages => package.package_branch.packages,
- :editable => editable }
- end
-
- def recent_packages
- pkgs = Package.recent(current_unit)
- shared_pkgs = Package.shared_recent(current_unit)
- render :partial => 'recent', :locals => { :pkgs => pkgs, :shared_pkgs => shared_pkgs }
- end
-
- def package_table(packages)
- # Split different categories into different arrays
- categorized = {}
- packages.each do |package|
- category_name = package.package_category.name
- categorized[category_name] ||= []
- categorized[category_name] << package
- end
+ :img => package.icon,
+ :soft_info => package.name,
+ :bold_info => package.version,
+ :packages => package.package_branch.packages,
+ :editable => editable }
+ end
+
+ def recent_packages
+ pkgs = Package.recent(current_unit)
+ shared_pkgs = Package.shared_recent(current_unit)
+ render :partial => 'recent', :locals => { :pkgs => pkgs, :shared_pkgs => shared_pkgs }
+ end
+
+ def package_table(package_branches)
+ categorized = package_branches.group_by {|pb| pb.package_category }
output = ""
- # Render header and table for each category
- categorized.each_pair do |category_name, packages|
- output += render :partial => 'packages_of_category_table', :locals => {:category_name => category_name, :packages => packages}
+ categorized.each_pair do |category, package_branches|
+ output += render :partial => 'packages_of_category_table', :locals => {:category => category, :package_branches => package_branches}
end
output.html_safe
end
View
5 app/models/package.rb
@@ -8,7 +8,6 @@ class Package < ActiveRecord::Base
# Dependancy relationships
belongs_to :package_branch
- belongs_to :package_category
belongs_to :icon
has_many :dependents, :class_name => "RequireItem", :dependent => :destroy
has_many :require_items, :as => :manifest, :dependent => :destroy
@@ -283,6 +282,10 @@ def public_filename
"/packages/#{environment_id}/#{unit_id}/#{installer_item_location}"
end
+ def package_category
+ package_branch.package_category
+ end
+
# If there is no associated icon, then it asks for the package categories icon instead
def icon
begin
View
4 app/models/package_branch.rb
@@ -22,9 +22,11 @@ class PackageBranch < ActiveRecord::Base
has_many :require_items, :dependent => :destroy
has_many :update_for_items, :dependent => :destroy
has_many :notifications, :as => :notified
- has_many :packages, :order => "version DESC"
+ has_many :packages, :order => "version DESC", :dependent => :destroy
has_one :version_tracker, :dependent => :destroy, :autosave => true
+ belongs_to :package_category
+
before_validation :require_display_name
before_save :require_version_tracker
View
10 app/use_cases/process_package_upload.rb
@@ -156,7 +156,7 @@ def assemble(package_file, pkginfo, special_attributes)
pkginfo.delete("catalogs")
name = PackageBranch.conform_to_name_constraints(pkginfo["name"])
- package.package_branch = retrieve_package_branch(name, pkginfo["display_name"], special_attributes[:unit_id])
+ package.package_branch = retrieve_package_branch(name, pkginfo["display_name"], special_attributes[:unit_id], PackageCategory.default(package.installer_type).id)
pkginfo.delete("name")
pkginfo.each do |k,v|
@@ -168,7 +168,6 @@ def assemble(package_file, pkginfo, special_attributes)
end
package.attributes = pkginfo
- package.package_category_id = PackageCategory.default(package.installer_type).id
package.installer_item_location = File.basename(package_file.path)
package.add_raw_tag("installer_item_hash", Digest::SHA256.file(package_file.path).hexdigest)
package = apply_special_attributes(package, special_attributes)
@@ -185,15 +184,16 @@ def assemble(package_file, pkginfo, special_attributes)
# Create a new package branch if not existing
# else pick the existing package branch and assign to the package
- def retrieve_package_branch(name, display_name, unit_id)
- PackageBranch.where(:name => name, :unit_id => unit_id).first || create_package_branch(name, display_name, unit_id)
+ def retrieve_package_branch(name, display_name, unit_id, package_category_id)
+ PackageBranch.where(:name => name, :unit_id => unit_id).first || create_package_branch(name, display_name, unit_id, package_category_id)
end
- def create_package_branch(name, display_name, unit_id)
+ def create_package_branch(name, display_name, unit_id, package_category_id)
PackageBranch.create! do |pb|
pb.name = name
pb.display_name = display_name
pb.unit_id = unit_id
+ pb.package_category_id = package_category_id
end
end
View
8 app/views/packages/_edit_package_tabs.html.erb
@@ -28,14 +28,6 @@
</tr>
<tr>
<td>
- Category
- </td>
- <td>
- <%= f.collection_select :package_category_id, PackageCategory.all, :id, :name %>
- </td>
- </tr>
- <tr>
- <td>
Restart Action
</td>
<td>
View
20 app/views/packages/_package_table_row.html.erb
@@ -1,20 +1,20 @@
<tr>
- <td rowspan="<%= package.versions.count %>"><%= image_tag(package.icon.url(:small), :class => "thumbnail", "data-package-branch-id" => package.package_branch_id) if package.icon %></td>
- <td rowspan="<%= package.versions.count %>">
- <%= package.display_name %><br />
- <em><%= package.name %></em>
+ <td rowspan="<%= package_branch.packages.count %>"><%= image_tag(package_branch.packages.first.icon.url(:small), :class => "thumbnail", "data-package-branch-id" => package_branch.id) if package_branch.packages.first %></td>
+ <td rowspan="<%= package_branch.packages.count %>">
+ <%= package_branch.display_name %><br />
+ <em><%= package_branch.name %></em>
</td>
- <%= render :partial => 'package_version_column', :locals => {:pkg => package.versions.first} %>
- <td rowspan="<%= package.versions.count %>" class="centerize">
- <% unless package.has_dependencies? %>
- <%= update_or_import(package) %>
+ <%= render :partial => 'package_version_column', :locals => {:pkg => package_branch.packages.first} %>
+ <td rowspan="<%= package_branch.packages.count %>" class="centerize">
+ <% unless package_branch.packages.first.has_dependencies? %>
+ <%= update_or_import(package_branch.packages.first) %>
<% end %>
</td>
</tr>
-<% package.versions.each_with_index do |pkg,i| %>
+<% package_branch.packages.each_with_index do |package , i| %>
<% unless i == 0 %>
<tr>
- <%= render :partial => 'package_version_column', :locals => {:pkg => pkg} %>
+ <%= render :partial => 'package_version_column', :locals => {:pkg => package} %>
</tr>
<% end %>
<% end %>
View
10 app/views/packages/_packages_of_category_table.html.erb
@@ -1,12 +1,12 @@
-<h4><%= category_name.capitalize %></h4>
+<h4><%= category.name.capitalize %></h4>
<table class="zebra packages">
<thead>
<tr>
<!-- <th> Checkbox</th> -->
<th><!-- Icon --></th>
<th>Display Name<br/><em>Branch</em></th>
- <th><%= check_box_tag("selected_#{category_name.downcase}", nil, false, :class => "select_all") %></th>
- <th>package</th>
+ <th><%= check_box_tag("selected_#{category.name.downcase}", nil, false, :class => "select_all") %></th>
+ <th>Version</th>
<th>Actions</th>
<th>
Update
@@ -14,7 +14,7 @@
</th>
</tr>
</thead>
- <% packages.each do |package| %>
- <%= render :partial => 'package_table_row', :locals => {:package => package} %>
+ <% package_branches.each do |package_branch| %>
+ <%= render :partial => 'package_table_row', :locals => {:package_branch => package_branch} %>
<% end %>
</table>
View
6 app/views/packages/index.html.erb
@@ -18,14 +18,14 @@
<h3><%= current_environment %></h3>
- <% if @packages.length == 0 %>
+ <% if @package_branches.length == 0 %>
<h5>There are no packages in the <%= current_environment.to_s.downcase %> environment</h5>
<% if can? :create, Package.new_for_can(current_unit) %>
<p>Why don't you <%= link_to "upload a package", new_package_path %> or two?</p>
<% end %>
<% else %>
<%= form_tag edit_multiple_packages_path, :method => :get, :id => "bulk_edit_form", :remote => true do %>
- <p><%= record_count(@packages) %><%= submit_tag "Edit Selection", :id => "bulk_edit" %></p>
- <%= package_table(@packages) %>
+ <p><%= record_count(@package_branches.map(&:packages).flatten) %><%= submit_tag "Edit Selection", :id => "bulk_edit" %></p>
+ <%= package_table(@package_branches) %>
<% end %>
<% end %>
View
6 db/migrate/20120602001304_add_unit_id_and_package_category_id_to_package_branch.rb
@@ -0,0 +1,6 @@
+class AddUnitIdAndPackageCategoryIdToPackageBranch < ActiveRecord::Migration
+ def change
+ add_column :package_branches, :unit_id, :integer
+ add_column :package_branches, :package_category_id, :integer
+ end
+end
View
5 db/migrate/20120602001304_add_unit_id_to_package_branch.rb
@@ -1,5 +0,0 @@
-class AddUnitIdToPackageBranch < ActiveRecord::Migration
- def change
- add_column :package_branches, :unit_id, :integer
- end
-end
View
5 db/schema.rb
@@ -189,9 +189,10 @@
create_table "package_branches", :force => true do |t|
t.string "name"
t.string "display_name"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.integer "unit_id"
+ t.integer "package_category_id"
end
create_table "package_categories", :force => true do |t|
Please sign in to comment.
Something went wrong with that request. Please try again.