Skip to content

Commit

Permalink
Merge pull request #3882 from DavidKang/remove-patternType
Browse files Browse the repository at this point in the history
Show package_groups without patternType
  • Loading branch information
ChrisBr committed Oct 5, 2017
2 parents 182ea73 + 3707ccb commit 4cce9cd
Show file tree
Hide file tree
Showing 13 changed files with 1,662 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/api/app/assets/stylesheets/webui/application/kiwi_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
}
}

#kiwi-packages-list {
.pattern {
color: #999;
font-size: 1em;
border-bottom: 1px solid #999;
margin-left: 0;
margin-top: 20px;
padding-left: 5px;
padding-bottom: 5px;
}
}

#kiwi-repositories-list, #kiwi-packages-list {
padding-left: 10px;
padding-right: 10px;
Expand Down
19 changes: 17 additions & 2 deletions src/api/app/models/kiwi/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Kiwi::Image < ApplicationRecord
has_one :package, foreign_key: 'kiwi_image_id', class_name: '::Package', dependent: :nullify, inverse_of: :kiwi_image
has_many :repositories, -> { order(order: :asc) }, dependent: :destroy, index_errors: true
has_many :package_groups, -> { order(:id) }, dependent: :destroy, index_errors: true
has_many :kiwi_packages, -> { where(kiwi_package_groups: { kiwi_type: Kiwi::PackageGroup.kiwi_types[:image], pattern_type: 'onlyRequired' }) },
has_many :kiwi_packages, -> { where(kiwi_package_groups: { kiwi_type: Kiwi::PackageGroup.kiwi_types[:image] }) },
through: :package_groups, source: :packages, inverse_of: :kiwi_image

#### Callbacks macros: before_save, after_save, etc.
Expand All @@ -31,6 +31,8 @@ class Kiwi::Image < ApplicationRecord
#### Validations macros
validates :name, presence: true
validate :check_use_project_repositories
validate :check_package_groups
validate :check_package_group_type_image
accepts_nested_attributes_for :repositories, allow_destroy: true
accepts_nested_attributes_for :package_groups, allow_destroy: true
accepts_nested_attributes_for :kiwi_packages, allow_destroy: true
Expand Down Expand Up @@ -133,7 +135,7 @@ def outdated?
end

def default_package_group
package_groups.find_or_create_by(kiwi_type: :image, pattern_type: 'onlyRequired')
package_groups.type_image.first || package_groups.create(kiwi_type: :image, pattern_type: 'onlyRequired')
end

def self.find_binaries_by_name(query, project, repositories, options = {})
Expand Down Expand Up @@ -170,6 +172,19 @@ def check_use_project_repositories
errors.add(:base,
"A repository with source_path=\"obsrepositories:/\" has been set. If you want to use it, please remove the other repositories.")
end

def check_package_group_type_image
return if package_groups.select(&:kiwi_type_image?).size <= 2

errors.add(:base, "Having more than 2 package groups with type='image' is not allowed.")
end

def check_package_groups
return if package_groups.group_by { |package_group| [package_group.kiwi_type, package_group.pattern_type] }
.select { |_key, value| value.count > 1 }.keys.empty?

errors.add(:base, "Multiple package groups with same attributes is not allowed.")
end
end

# == Schema Information
Expand Down
6 changes: 6 additions & 0 deletions src/api/app/models/kiwi/package_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Kiwi::PackageGroup < ApplicationRecord
# exist in Active Record, such as "delete"
enum kiwi_type: %i[bootstrap delete docker image iso lxc oem pxe split testsuite vmx], _prefix: :type

scope :type_image, -> { where(kiwi_type: :image) }

validates :kiwi_type, presence: true

accepts_nested_attributes_for :packages, reject_if: :all_blank, allow_destroy: true
Expand All @@ -24,6 +26,10 @@ def to_xml

builder.to_xml save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION | Nokogiri::XML::Node::SaveOptions::FORMAT
end

def kiwi_type_image?
kiwi_type == 'image'
end
end

# == Schema Information
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4cce9cd

Please sign in to comment.