Skip to content

Commit

Permalink
[frontend] Fix sorting of image templates
Browse files Browse the repository at this point in the history
* Shows templates from local projects first, and remotes afterwards.
  This broke with 89d7fc5.
* Sorts each template within a project by it's title. The title is what
  is visible by the user.
  • Loading branch information
bgeuken committed Oct 11, 2017
1 parent 9fe3eb3 commit 38e11ff
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def autocomplete(search)
# will return all projects with attribute 'OBS:ImageTemplates'
scope :local_image_templates, lambda {
includes(:packages).joins(attribs: { attrib_type: :attrib_namespace }).
where(attrib_types: { name: 'ImageTemplates' }, attrib_namespaces: { name: 'OBS' })
where(attrib_types: { name: 'ImageTemplates' }, attrib_namespaces: { name: 'OBS' }).
order(:title)
}

scope :for_user, ->(user_id) { joins(:relationships).where(relationships: { user_id: user_id, role_id: Role.hashed['maintainer'] }) }
Expand Down Expand Up @@ -159,7 +160,7 @@ def self.restore(project_name, backend_opts = {})
end

def self.image_templates
(local_image_templates + remote_image_templates).sort_by(&:name)
local_image_templates + remote_image_templates
end

def self.remote_image_templates
Expand Down

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

6 changes: 4 additions & 2 deletions src/api/spec/features/webui/image_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

context "branching" do
let!(:project) { create(:project, name: "my_project") }
let!(:package1) { create(:package_with_file, project: project, name: "first_package") }
let!(:package2) { create(:package_with_file, project: project, name: "second_package") }
let!(:package1) { create(:package_with_file, project: project, name: "first_package", title: "a") }
let!(:package2) { create(:package_with_file, project: project, name: "second_package", title: "c") }
let!(:package3) { create(:package_with_file, project: project, name: "third_package", title: "b") }
let!(:attrib) { create(:template_attrib, project: project) }

scenario "branch image template" do
Expand All @@ -22,6 +23,7 @@

expect(page).to have_text(package1.title)
expect(find("input[data-package='#{package1}']", visible: false)['checked']).to be true
expect(find("input[data-package='#{package3}']", visible: false)['checked']).to be false
expect(find("input[data-package='#{package2}']", visible: false)['checked']).to be false

expect(page).to have_field('target_package', with: package1)
Expand Down

0 comments on commit 38e11ff

Please sign in to comment.