Project

General

Profile

Revision 329cfcba

Added by Sebastian Gräßl about 5 years ago

Fixes #18902 - Enable autocomplete for container image search

This enables the autocomplete for the image name search and
improves the usability of searching for container images on
Docker Hub or an external Registry.

View differences:

app/controllers/image_search_controller.rb
1 1
class ImageSearchController < ::ApplicationController
2
  def auto_complete_repository_name
3
    catch_network_errors do
4
      available = image_search_service.available?(params[:search])
5
      render :text => available.to_s
6
    end
7
  end
8

  
9
  def auto_complete_image_tag
10
    catch_network_errors do
11
      tags = image_search_service.search({
12
        term: params[:search],
13
        tags: 'true'
14
      })
15

  
16
      respond_to do |format|
17
        format.js do
18
          render :json => prepare_for_autocomplete(tags)
19
        end
20
      end
21
    end
22
  end
23

  
24 2
  def search_repository
25 3
    catch_network_errors do
26
      repositories = image_search_service.search({
27
        term: params[:search].split(':').first,
28
        tags: 'false'
29
      })
4
      tags_enabled = params[:tags] || 'false'
5
      result = image_search_service.search(term: params[:search], tags: tags_enabled)
30 6

  
31 7
      respond_to do |format|
32
        format.js do
33
          render :partial => 'repository_search_results',
34
                 :locals  => { :repositories => repositories,
35
                               :use_hub => use_hub? }
8
        format.js { render json: prepare_for_autocomplete(result) }
9
        format.html do
10
          render partial: 'repository_search_results', locals: { repositories: result }
36 11
        end
37 12
      end
38 13
    end
......
51 26
           :status => 500
52 27
  end
53 28

  
54
  def use_hub?
55
    @registry.nil?
56
  end
57

  
58 29
  def action_permission
59 30
    case params[:action]
60
    when 'auto_complete_repository_name', 'auto_complete_image_tag', 'search_repository'
31
    when 'search_repository'
61 32
      :search_repository
62 33
    else
63 34
      super

Also available in: Unified diff