Project

General

Profile

Revision f4c209f1

Added by Dmitri Dolguikh about 8 years ago

fixes #9004: wizard moves correctly between persisted states now

View differences:

app/assets/javascripts/foreman_docker/image_step.js
18 18
  });
19 19

  
20 20
  $('#hub_tab').click( function() {
21
      $('#wizard_states_image_registry_id').val('');
21
      $('#docker_container_wizard_states_image_registry_id').val('');
22 22
  });
23 23
});
24 24

  
......
26 26
  $.ajax({
27 27
    type:'get',
28 28
    url: $(item).attr('data-url'),
29
    data: { search: item.val(), registry_id: $('#wizard_states_image_registry_id').val() },
29
    data: { search: item.val(), registry_id: $('#docker_container_wizard_states_image_registry_id').val() },
30 30
    //data:'search=' + item.val(),
31 31
    success:function (result) {
32 32
      if(result == 'true'){
......
52 52
  tag.addClass('tags-autocomplete-loading');
53 53
  tag.val('');
54 54
  var source = [];
55
  $.getJSON( tag.data("url"), { search: $('#search').val(), registry_id: $('#wizard_states_image_registry_id').val() },
55
  $.getJSON( tag.data("url"), { search: $('#search').val(), registry_id: $('#docker_container_wizard_states_image_registry_id').val() },
56 56
      function(data) {
57 57
        $('#searching_spinner').hide();
58 58
        tag.removeClass('tags-autocomplete-loading');
......
72 72
    type:'get',
73 73
    dataType:'text',
74 74
    url: $(item).attr('data-url'),
75
    data: { search: $('#search').val(), registry_id: $('#wizard_states_image_registry_id').val() },
75
    data: { search: $('#search').val(), registry_id: $('#docker_container_wizard_states_image_registry_id').val() },
76 76
    success: function (result) {
77 77
      $('#repository_search_results').html(result);
78 78
    },
app/controllers/containers/steps_controller.rb
5 5

  
6 6
    steps :preliminary, :image, :configuration, :environment
7 7

  
8
    before_filter :build_state
9
    before_filter :set_form
8
    before_filter :find_state
9
    before_filter :build_state, :only => [:update]
10
    before_filter :set_form, :only => [:show]
10 11

  
11 12
    def show
12 13
      @container_resources = allowed_resources if step == :preliminary
......
23 24

  
24 25
    private
25 26

  
26
    def build_state
27
    def find_state
27 28
      @state = DockerContainerWizardState.find(params[:wizard_state_id])
28
      @state.send(:"build_#{step}", params[:"docker_container_wizard_states_#{step}"])
29 29
    rescue ActiveRecord::RecordNotFound
30 30
      not_found
31 31
    end
32 32

  
33
    def build_state
34
      @state.send(:"build_#{step}", params[:"docker_container_wizard_states_#{step}"])
35
    end
36

  
33 37
    def set_form
34
      instance_variable_set("@#{step}", @state.send(:"#{step}") || @state.send(:"build_#{step}"))
38
      instance_variable_set(
39
          "@docker_container_wizard_states_#{step}",
40
          @state.send(:"#{step}") || @state.send(:"build_#{step}"))
35 41
    end
36 42

  
37 43
    def create_container
app/helpers/container_steps_helper.rb
10 10
    registries = DockerRegistry.with_taxonomy_scope_override(@location, @organization)
11 11
      .authorized(:view_registries)
12 12
    field(f, 'docker_container_wizard_states_image[registry_id]', :label => _("Registry")) do
13
      collection_select :wizard_states_image, :registry_id,
13
      collection_select :docker_container_wizard_states_image, :registry_id,
14 14
                        registries,
15 15
                        :id, :name,
16 16
                        { :prompt => _("Select a registry") },
app/models/docker_container_wizard_states/preliminary.rb
7 7
                              :foreign_key => :docker_container_wizard_state_id
8 8

  
9 9
    validates :compute_resource_id, :presence => true
10

  
11
    def used_location_ids
12
      Location.joins(:taxable_taxonomies).where(
13
          'taxable_taxonomies.taxable_type' => 'DockerContainerWizardStates::Preliminary',
14
          'taxable_taxonomies.taxable_id' => id).pluck(:id)
15
    end
16

  
17
    def used_organization_ids
18
      Organization.joins(:taxable_taxonomies).where(
19
          'taxable_taxonomies.taxable_type' => 'DockerContainerWizardStates::Preliminary',
20
          'taxable_taxonomies.taxable_id' => id).pluck(:id)
21
    end
10 22
  end
11 23
end
app/views/containers/steps/configuration.html.erb
1 1
<%= render :layout => 'title', :locals => { :step => 3 } do %>
2
  <%= form_for @configuration, :url => wizard_path, :method => :put do |f| %>
2
  <%= form_for @docker_container_wizard_states_configuration, :url => wizard_path, :method => :put do |f| %>
3 3
    <h3><%= _("Basic options") %></h3>
4 4
    <%= text_f f, :name,       :size => 'col-md-4' %>
5 5
    <%= text_f f, :command,    :size => 'col-md-4' %>
app/views/containers/steps/environment.html.erb
1 1
<%= render :layout => 'title', :locals => { :step => 4 } do %>
2
  <%= form_for @environment, :url => wizard_path, :method => :put do |f| %>
2
  <%= form_for @docker_container_wizard_states_environment, :url => wizard_path, :method => :put do |f| %>
3 3
    <div class='row'>
4 4
      <div class='col-md-6 col-md-push-7'>
5 5
        <h3><%= _("Shell") %></h3>
......
10 10
      </div>
11 11
      <div class='col-md-6 col-md-pull-6'>
12 12
        <h3><%= _("Environment variables") %></h3>
13
        <%= f.fields_for :environment_variables, @environment.environment_variables do |builder| %>
13
        <%= f.fields_for :environment_variables, @docker_container_wizard_states_environment.environment_variables do |builder| %>
14 14
          <%= render 'foreman_docker/common_parameters/environment_variable', :f => builder %>
15 15
        <% end %>
16 16
        <%= link_to_add_fields(_("Add environment variable"), f, :environment_variables,
app/views/containers/steps/image.html.erb
3 3

  
4 4
<%= render :layout => 'title', :locals => { :step => 2 } do %>
5 5
    <ul class="nav nav-tabs" data-tabs="tabs">
6
      <li class="active"><a href="#hub" data-toggle="tab" id="hub_tab">
6
      <li class=<%= ("active" if @docker_container_wizard_states_image.registry_id.nil?) %>><a href="#hub" data-toggle="tab" id="hub_tab">
7 7
        <span class="glyphicon glyphicon-cloud-download"></span>
8 8
        <%= _("Docker hub") %>
9 9
      </a></li>
10
      <li><a href="#registry" data-toggle="tab" id="registry_tab">
10
      <li class=<%= ("active" unless @docker_container_wizard_states_image.registry_id.nil?) %>><a href="#registry" data-toggle="tab" id="registry_tab">
11 11
        <span class="glyphicon glyphicon-cloud-download"></span>
12 12
        <%= _("External registry") %>
13 13
      </a></li>
14 14
    </ul>
15 15

  
16
    <%= form_for @image, :class => 'form-horizontal', :url => wizard_path, :method => :put do |f| %>
16
    <%= form_for @docker_container_wizard_states_image, :class => 'form-horizontal', :url => wizard_path, :method => :put do |f| %>
17 17
        <div class="tab-content">
18
          <div class="tab-pane active" id="hub">
19
          </div>
20
          <div class="tab-pane" id="registry">
18
          <% if @docker_container_wizard_states_image.registry_id.nil? %>
19
              <div class="tab-pane active" id="hub">
20
              </div>
21
              <div class="tab-pane" id="registry">
22
          <% else %>
23
              <div class="tab-pane" id="hub">
24
              </div>
25
              <div class="tab-pane active" id="registry">
26
          <% end %>
21 27
            <div class="input-group col-md-6">
22 28
              <%= select_registry f %>
23 29
            </div>
......
28 34
              <div class="input-group">
29 35

  
30 36
                <%= auto_complete_docker_search('docker_container_wizard_states_image[repository_name]', '',
31
                                         :'data-url'  => auto_complete_repository_name_image_search_path(@image.compute_resource_id),
37
                                         :'data-url'  => auto_complete_repository_name_image_search_path(@docker_container_wizard_states_image.compute_resource_id),
32 38
                                         :value       => f.object.repository_name.present? ? f.object.repository_name : '',
33 39
                                         :id          => :search,
34 40
                                         :focus_on_load => true,
......
38 44
                  <%= button_tag(:class      => 'btn btn-default',
39 45
                                 :type       => 'button',
40 46
                                 :id         => 'search_repository',
41
                                 :'data-url' => search_repository_image_search_path(@image.compute_resource_id),
47
                                 :'data-url' => search_repository_image_search_path(@docker_container_wizard_states_image.compute_resource_id),
42 48
                                 :onclick    => 'searchRepo(this)') do %>
43 49
                    <span class="glyphicon glyphicon-search"></span>
44 50
                  <% end %>
......
47 53
            </div>
48 54
            <%= text_f f, :tag,
49 55
                          :id         => 'tag',
50
                          :'data-url' => auto_complete_image_tag_image_search_path(@image.compute_resource_id) %>
56
                          :'data-url' => auto_complete_image_tag_image_search_path(@docker_container_wizard_states_image.compute_resource_id) %>
51 57
            <div class="col-md-12">
52 58
              <div id='searching_spinner' class='col-md-offset-3 hide'>
53 59
                <span id='waiting_text'>
app/views/containers/steps/preliminary.html.erb
1 1
<%= render :layout => 'title', :locals => { :step => 1 } do %>
2
<%= form_for @preliminary, :url => wizard_path, :method => :put do |f| %>
2
<%= form_for @docker_container_wizard_states_preliminary, :url => wizard_path, :method => :put do |f| %>
3 3
  <ul class="nav nav-tabs" data-tabs="tabs">
4 4
    <li class="active"><a href="#primary" data-toggle="tab">
5 5
      <span class="glyphicon glyphicon-tasks"></span>
......
26 26
        </div>
27 27
      <% end %>
28 28
    </div>
29
    <%= render "taxonomies/loc_org_tabs", :f => f, :obj => @preliminary %>
29
    <%= render "taxonomies/loc_org_tabs", :f => f, :obj => @docker_container_wizard_states_preliminary %>
30 30
  </div>
31 31
  <% if @container_resources.present? %>
32 32
    <%= render :partial => 'form_buttons' %>

Also available in: Unified diff