Skip to content

Commit

Permalink
Adding imagelayers link to search results
Browse files Browse the repository at this point in the history
  • Loading branch information
rheinwein committed Jun 18, 2015
1 parent 1552836 commit 667576a
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/panamax/images.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ul.images li {
padding-bottom: 22px;
padding-top: 22px;

.image-layers-link {
.imagelayers-link {
background: image-url('icon_image_layers.svg') -10px -17px;
background-size: 40px 40px;
float: left;
Expand Down
12 changes: 12 additions & 0 deletions app/assets/stylesheets/panamax/search.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ body#search_flow main:after {
font-size: 0.8em;
line-height: 1.2;
}

.imagelayers {
height: 40px;
width: 40px;
text-indent: -9999px;
color: transparent;
background: image-url('icon_image_layers.svg') -10px -17px no-repeat;
background-size: 40px 40px;
&:hover {
background-position: -10px 3px;
}
}
}

.actions {
Expand Down
10 changes: 10 additions & 0 deletions app/models/base_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def docker_index_url
end
end

def imagelayers_url
if remote?
"#{IMAGELAYERS_BASE_URL}?images=#{source}"
else
image_name = self.tags.first.split(':').first
"#{IMAGELAYERS_BASE_URL}?images=#{image_name}"
end
end

def short_description
truncate(description, length: 165, escape: false, separator: ' ')
end
Expand All @@ -49,6 +58,7 @@ def as_json(options={})
'status_label' => status_label,
'short_description' => short_description,
'docker_index_url' => docker_index_url,
'imagelayers_url' => imagelayers_url,
'badge_class' => badge_class
)
end
Expand Down
1 change: 1 addition & 0 deletions app/models/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class BaseResource < ActiveResource::Base

DOCKER_INDEX_BASE_URL = 'https://registry.hub.docker.com/'
IMAGELAYERS_BASE_URL = 'https://imagelayers.io/'

self.site = PanamaxApi::URL

Expand Down
5 changes: 0 additions & 5 deletions app/models/local_image.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
class LocalImage < BaseImage
PANAMAX_IMAGE_NAMES = ['centurylink/panamax-ui:latest', 'centurylink/panamax-api:latest']
IMAGE_LAYERS_BASE_URL = 'https://ImageLayers.io'

def panamax_image?
PANAMAX_IMAGE_NAMES.include?(name)
end

def image_layers_url
IMAGE_LAYERS_BASE_URL + "?images=#{name}"
end

def local?
true
end
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/image_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(image, view_context)
end

delegate :description, :status_label, :badge_class, :short_description,
:star_count, :docker_index_url, :registry_id,
:star_count, :docker_index_url, :imagelayers_url, :registry_id,
to: :@image

def title
Expand Down
4 changes: 4 additions & 0 deletions app/presenters/json_image_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def docker_index_url
'{{docker_index_url}}'
end

def imagelayers_url
'{{imagelayers_url}}'
end

def badge_class
'{{badge_class}}'
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/images/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
%ul.images
- @images.each do |image|
%li
- il_message = "Inspect #{image.name} with ImageLayers.io"
= link_to il_message, image.image_layers_url, { class: 'image-layers-link', title: il_message, target: '_blank' }
- il_message = "Inspect #{image.name} with imagelayers.io"
= link_to il_message, image.imagelayers_url, { class: 'imagelayers-link', title: il_message, target: '_blank' }
%h3= image.name
%h6= image.tags[1..-1].try(:join, ', ')
%dl
Expand Down
3 changes: 2 additions & 1 deletion app/views/search/_image_row.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
.basic-info
%h3
- if remote
= link_to presenter.title, presenter.docker_index_url, target: '_blank', title: 'View details on the Docker Hub'
= link_to presenter.title, presenter.docker_index_url, target: '_blank', title: 'View details on the Docker Hub', class: 'docker-hub'
= link_to presenter.title, presenter.imagelayers_url, target: '_blank', title: 'Inspect this image on imagelayers.io', class: 'imagelayers'
- else
= presenter.title
%p= presenter.short_description
Expand Down
3 changes: 2 additions & 1 deletion app/views/search/_modal_image_row.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
.basic-info
%h3
- if remote
= link_to presenter.title, presenter.docker_index_url, target: '_blank', title: 'View details on the Docker Hub'
= link_to presenter.title, presenter.docker_index_url, target: '_blank', title: 'View details on the Docker Hub', class: 'docker-hub'
= link_to presenter.title, presenter.imagelayers_url, target: '_blank', title: 'Inspect this image on imagelayers.io', class: 'imagelayers'
- else
= presenter.title
%p= presenter.short_description
Expand Down
2 changes: 1 addition & 1 deletion spec/features/manage_images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
it 'can visit the image layers page for an image' do
visit '/images'

expect(page).to have_link 'Inspect socialize_api:latest with ImageLayers.io', href: 'https://ImageLayers.io?images=socialize_api:latest'
expect(page).to have_link 'Inspect socialize_api:latest with imagelayers.io', href: 'https://imagelayers.io/?images=socialize_api'
end
end
end
3 changes: 2 additions & 1 deletion spec/features/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
expect(page).to have_title 'Panamax > Search Results'

# remote image result
expect(page.find_link('tutum/wordpress')['href']).to eq "#{DOCKER_INDEX_BASE_URL}u/tutum/wordpress"
expect(page.find_link('Docker Hub')['href']).to eq "#{DOCKER_INDEX_BASE_URL}u/tutum/wordpress"
expect(page.find_link('imagelayers.io')['href']).to eq "#{IMAGELAYERS_URL}?images=tutum/wordpress"
expect(page).to have_content 'Wordpress Docker image - listens in port 80.'
expect(page).to have_css '.star-count', text: '7'

Expand Down
9 changes: 5 additions & 4 deletions spec/models/local_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
end
end

describe '#image_layers_url' do
it 'concatenates the image layers URL with the image name' do
expect(subject.image_layers_url).to eq 'https://ImageLayers.io?images=blah/not-panamax'
describe '#imagelayers_url' do
it 'concatenates the imagelayers URL with the image name' do
expect(subject.imagelayers_url).to eq "#{IMAGELAYERS_URL}?images=blah/not-panamax"
end
end

Expand Down Expand Up @@ -124,7 +124,8 @@
'short_description' => 'this thing goes boom shaka laka',
'status_label' => 'Local',
'badge_class' => 'local',
'docker_index_url' => nil
'docker_index_url' => nil,
'imagelayers_url' => "#{IMAGELAYERS_URL}?images=blah/not-panamax"
)
expect(subject.as_json).to eq expected
end
Expand Down
3 changes: 2 additions & 1 deletion spec/models/remote_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
'short_description' => 'this thing goes boom shaka laka',
'status_label' => 'Repository',
'badge_class' => 'repository',
'docker_index_url' => "#{DOCKER_INDEX_BASE_URL}u/boom/shaka"
'docker_index_url' => "#{DOCKER_INDEX_BASE_URL}u/boom/shaka",
'imagelayers_url' => "#{IMAGELAYERS_URL}?images=boom/shaka"
)
expect(subject.as_json).to eq expected
end
Expand Down
11 changes: 9 additions & 2 deletions spec/presenters/image_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
status_label: 'Local',
badge_class: 'local',
star_count: 123,
docker_index_url: 'index.docker/boom/shaka'
docker_index_url: "#{DOCKER_INDEX_BASE_URL}boom/shaka",
imagelayers_url: "#{IMAGELAYERS_URL}?images=boom/shaka"
)
end

Expand Down Expand Up @@ -58,7 +59,13 @@

describe '#docker_index_url' do
it 'exposes the docker index url' do
expect(subject.docker_index_url).to eq 'index.docker/boom/shaka'
expect(subject.docker_index_url).to eq "#{DOCKER_INDEX_BASE_URL}boom/shaka"
end
end

describe '#imagelayers_url' do
it 'exposes the imagelayers url' do
expect(subject.imagelayers_url).to eq "#{IMAGELAYERS_URL}?images=boom/shaka"
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/presenters/json_image_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
end
end

describe '#imagelayers_url' do
it 'exposes the handlebar template tag for imagelayers url' do
expect(subject.imagelayers_url).to eq '{{imagelayers_url}}'
end
end

describe '#badge_class' do
it 'exposes handlebar template for badge_class' do
expect(subject.badge_class).to eq '{{badge_class}}'
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
end

DOCKER_INDEX_BASE_URL = 'https://registry.hub.docker.com/'
IMAGELAYERS_URL = 'https://imagelayers.io/'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Expand Down

0 comments on commit 667576a

Please sign in to comment.