Class: ImageSearchController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ImageSearchController
- Defined in:
- app/controllers/image_search_controller.rb
Instance Method Summary collapse
- #action_permission ⇒ Object
- #auto_complete_image_tag ⇒ Object
- #auto_complete_repository_name ⇒ Object
- #find_resource ⇒ Object
- #hub_auto_complete_image_tags(terms) ⇒ Object
- #hub_image_exists?(terms) ⇒ Boolean
- #hub_search_image(terms) ⇒ Object
- #registry_auto_complete_image_tags(terms) ⇒ Object
- #registry_image_exists?(term) ⇒ Boolean
- #registry_search_image(terms) ⇒ Object
- #search_repository ⇒ Object
- #use_hub? ⇒ Boolean
Instance Method Details
#action_permission ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'app/controllers/image_search_controller.rb', line 70 def case params[:action] when 'auto_complete_repository_name', 'auto_complete_image_tag', 'search_repository' :search_repository else super end end |
#auto_complete_image_tag ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/image_search_controller.rb', line 9 def auto_complete_image_tag # This is the format jQuery UI autocomplete expects = use_hub? ? (params[:search]) : (params[:search]) respond_to do |format| format.js do .map! { |tag| { :label => CGI.escapeHTML(tag), :value => CGI.escapeHTML(tag) } } render :json => end end end |
#auto_complete_repository_name ⇒ Object
4 5 6 7 |
# File 'app/controllers/image_search_controller.rb', line 4 def auto_complete_repository_name render :text => (use_hub? ? hub_image_exists?(params[:search]) : registry_image_exists?(params[:search])).to_s end |
#find_resource ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/image_search_controller.rb', line 79 def find_resource if params[:registry_id].present? @registry = DockerRegistry.(:view_registries).find(params[:registry_id]) else @compute_resource = ComputeResource.(:view_compute_resources).find(params[:id]) end rescue ActiveRecord::RecordNotFound not_found end |
#hub_auto_complete_image_tags(terms) ⇒ Object
40 41 42 |
# File 'app/controllers/image_search_controller.rb', line 40 def (terms) @compute_resource.(terms) end |
#hub_image_exists?(terms) ⇒ Boolean
36 37 38 |
# File 'app/controllers/image_search_controller.rb', line 36 def hub_image_exists?(terms) @compute_resource.exist?(terms) end |
#hub_search_image(terms) ⇒ Object
44 45 46 |
# File 'app/controllers/image_search_controller.rb', line 44 def hub_search_image(terms) @compute_resource.search(terms) end |
#registry_auto_complete_image_tags(terms) ⇒ Object
57 58 59 60 61 |
# File 'app/controllers/image_search_controller.rb', line 57 def (terms) ::Service::RegistryApi.new(:url => @registry.url, :user => @registry.username, :password => @registry.password).(terms).keys end |
#registry_image_exists?(term) ⇒ Boolean
48 49 50 51 52 53 54 55 |
# File 'app/controllers/image_search_controller.rb', line 48 def registry_image_exists?(term) result = ::Service::RegistryApi.new(:url => @registry.url, :user => @registry.username, :password => @registry.password).search(term) registry_name = term.split('/').size > 1 ? term : 'library/' + term result['results'].any? { |r| r['name'] == registry_name } end |
#registry_search_image(terms) ⇒ Object
63 64 65 66 67 68 |
# File 'app/controllers/image_search_controller.rb', line 63 def registry_search_image(terms) r = ::Service::RegistryApi.new(:url => @registry.url, :user => @registry.username, :password => @registry.password).search(terms) r['results'] end |
#search_repository ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/image_search_controller.rb', line 21 def search_repository repositories = use_hub? ? hub_search_image(params[:search]) : registry_search_image(params[:search]) respond_to do |format| format.js do render :partial => 'repository_search_results', :locals => { :repositories => repositories } end end end |
#use_hub? ⇒ Boolean
32 33 34 |
# File 'app/controllers/image_search_controller.rb', line 32 def use_hub? @registry.nil? end |