Skip to content

Commit

Permalink
Replace old container provider forms with the new DDF version
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Jul 1, 2020
1 parent 7f92798 commit 659afdc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 37 deletions.
4 changes: 4 additions & 0 deletions app/helpers/ems_container_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ module EmsContainerHelper
include ContainerSummaryHelper
include_concern 'TextualSummary'
include_concern 'ComplianceSummaryHelper'

def edit_redirect_path(lastaction, ems)
lastaction == 'show_list' ? ems_containers_path : ems_container_path(ems)
end
end
17 changes: 17 additions & 0 deletions app/javascript/components/provider-form/detect-button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';

import fieldsMapper from '../../forms/mappers/formFieldsMapper';
import { componentTypes } from '@@ddf';

const Component = fieldsMapper[componentTypes.BUTTON];

const DetectButton = ({ formOptions, ...props }) => {
const onClick = () => {
// TODO: api('detect endpoint data').then('store in form using formOptions');
};

return <Component formOptions={formOptions} {...props} onClick={onClick} />;
};

export default DetectButton;
2 changes: 2 additions & 0 deletions app/javascript/components/provider-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ProtocolSelector from './protocol-selector';
import ProviderSelectField from './provider-select-field';
import ProviderCredentials from './provider-credentials';
import ValidateProviderCredentials from './validate-provider-credentials';
import DetectButton from './detect-button';

const findSkipSubmits = (schema, items) => {
const found = schema.skipSubmit && items.includes(schema.name) ? [schema.name] : [];
Expand Down Expand Up @@ -146,6 +147,7 @@ const ProviderForm = ({ providerId, kind, title, redirect }) => {
'provider-select-field': ProviderSelectField,
'provider-credentials': ProviderCredentials,
'validate-provider-credentials': ValidateProviderCredentials,
'detect-button': DetectButton,
};

return (
Expand Down
19 changes: 1 addition & 18 deletions app/views/ems_container/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
= form_for(@ems,
:url => "/#{controller_name}/#{@ems.id}",
:method => :patch,
:html => {"ng-controller" => "emsCommonFormController",
"name" => "angularForm",
"ng-show" => "afterGet",
"update-url" => "/#{controller_name}/#{@ems.id}",
"form-fields-url" => "/#{controller_name}/ems_container_form_fields/",
"novalidate" => true}) do |f|
%input{:type => 'hidden', :id => "form_id", :value => "##{f.options[:html][:id]}"}
%input{:type => 'hidden', :id => "button_name", :name => "button", :value => "save"}
%input{:type => 'hidden', :id => "cred_type", :name => "cred_type", :value => "default"}

= render :partial => "form"

:javascript
ManageIQ.angular.app.value('emsCommonFormId', '#{@ems.id || "new"}');
miq_bootstrap($('#form_id').val());
= react('ProviderForm', :providerId => @ems.id.to_s, :redirect => edit_redirect_path(@lastaction, @ems), :kind => 'container', :title => ui_lookup(:model => 'ManageIQ::Providers::ContainerManager'))
20 changes: 1 addition & 19 deletions app/views/ems_container/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
- url = @ems.persisted? ? ems_containers_path(@ems) : ems_containers_path
= form_for(@ems,
:url => url,
:method => :post,
:html => {"ng-controller" => "emsCommonFormController",
"name" => "angularForm",
"ng-show" => "afterGet",
"create-url" => url,
"form-fields-url" => "/#{controller_name}/ems_container_form_fields/",
"novalidate" => true}) do |f|
%input{:type => 'hidden', :id => "form_id", :value => "##{f.options[:html][:id]}"}
%input{:type => 'hidden', :id => "button_name", :name => "button", :value => "add"}
%input{:type => 'hidden', :id => "cred_type", :name => "cred_type", :value => "default"}

= render :partial => "form"

:javascript
ManageIQ.angular.app.value('emsCommonFormId', '#{@ems.id || "new"}');
miq_bootstrap($('#form_id').val());
= react('ProviderForm', :redirect => ems_containers_path, :kind => 'container', :title => ui_lookup(:model => 'ManageIQ::Providers::ContainerManager'))

0 comments on commit 659afdc

Please sign in to comment.