foreman_acd 0.0.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +122 -0
  3. data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +54 -0
  4. data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -2
  5. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +54 -0
  6. data/app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb +0 -0
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +35 -4
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +43 -87
  9. data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
  10. data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
  11. data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
  12. data/app/controllers/ui_acd_controller.rb +11 -4
  13. data/app/models/foreman_acd/ansible_playbook.rb +50 -0
  14. data/app/models/foreman_acd/app_definition.rb +2 -1
  15. data/app/models/foreman_acd/app_instance.rb +7 -0
  16. data/app/services/foreman_acd/app_configurator.rb +70 -0
  17. data/app/services/foreman_acd/app_deployer.rb +143 -0
  18. data/app/services/foreman_acd/inventory_creator.rb +67 -0
  19. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +21 -0
  20. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +3 -0
  21. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  22. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  23. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +3 -0
  24. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +3 -0
  25. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +3 -0
  26. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +3 -0
  27. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +3 -0
  28. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +3 -0
  29. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -0
  30. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +3 -0
  31. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +3 -0
  32. data/app/views/foreman_acd/app_definitions/_form.html.erb +25 -19
  33. data/app/views/foreman_acd/app_definitions/edit.html.erb +5 -0
  34. data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
  35. data/app/views/foreman_acd/app_definitions/index.html.erb +9 -5
  36. data/app/views/foreman_acd/app_instances/_form.html.erb +10 -8
  37. data/app/views/foreman_acd/app_instances/deploy.html.erb +19 -0
  38. data/app/views/foreman_acd/app_instances/index.html.erb +10 -5
  39. data/app/views/foreman_acd/app_instances/report.html.erb +19 -0
  40. data/app/views/templates/job/run_acd_ansible_playbook.erb +49 -0
  41. data/app/views/ui_acd/ansible_data.json.rabl +6 -0
  42. data/app/views/ui_acd/app.json.rabl +6 -2
  43. data/app/views/ui_acd/app_definition.json.rabl +1 -1
  44. data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
  45. data/config/routes.rb +31 -1
  46. data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
  47. data/db/migrate/20190625140305_create_app_instances.rb +1 -1
  48. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  49. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  50. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +5 -0
  51. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +5 -0
  52. data/db/seeds.d/75-job_templates.rb +8 -0
  53. data/lib/foreman_acd/engine.rb +3 -0
  54. data/lib/foreman_acd/plugin.rb +72 -4
  55. data/lib/foreman_acd/version.rb +1 -1
  56. data/package.json +2 -1
  57. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +376 -0
  58. data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
  59. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +295 -0
  60. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +14 -0
  61. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  62. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +243 -0
  63. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +8 -0
  64. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
  65. data/webpack/components/ApplicationDefinition/index.js +33 -0
  66. data/webpack/components/ApplicationInstance/ApplicationInstance.js +412 -0
  67. data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
  68. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +239 -0
  69. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +14 -0
  70. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +295 -0
  71. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +9 -0
  72. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
  73. data/webpack/components/ApplicationInstance/components/Service.js +30 -0
  74. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
  75. data/webpack/components/ApplicationInstance/index.js +35 -0
  76. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +155 -0
  77. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +27 -0
  78. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +86 -0
  79. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +4 -0
  80. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +52 -0
  81. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +5 -0
  82. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
  83. data/webpack/components/ApplicationInstanceReport/index.js +27 -0
  84. data/webpack/components/ParameterSelection/ParameterSelection.js +96 -183
  85. data/webpack/components/ParameterSelection/ParameterSelection.scss +10 -3
  86. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +72 -104
  87. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +14 -19
  88. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
  89. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +100 -83
  90. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
  91. data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
  92. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
  93. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
  94. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
  95. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
  96. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  97. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
  98. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
  99. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
  100. data/webpack/components/ParameterSelection/index.js +6 -8
  101. data/webpack/components/common/AddTableEntry.js +30 -0
  102. data/webpack/components/common/DeleteTableEntry.js +39 -0
  103. data/webpack/components/common/ExtSelect.js +43 -0
  104. data/webpack/components/common/RailsData.js +27 -0
  105. data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
  106. data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
  107. data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
  108. data/webpack/components/common/__tests__/RailsData.test.js +16 -0
  109. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
  110. data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
  111. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
  112. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
  113. data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
  114. data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
  115. data/webpack/helper.js +20 -0
  116. data/webpack/index.js +6 -0
  117. data/webpack/reducer.js +43 -3
  118. metadata +85 -39
@@ -0,0 +1,5 @@
1
+ const applicationInstanceReport = state => state.foremanAcd.applicationInstanceReport;
2
+
3
+ export const selectHosts = state => applicationInstanceReport(state).hosts;
4
+ export const selectReport = state => applicationInstanceReport(state).report;
5
+ export const selectActiveHostId = state => applicationInstanceReport(state).activeHostId;
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ const ReportViewer= ({
5
+ hidden,
6
+ report,
7
+ }) =>{
8
+ if (hidden) {
9
+ return null;
10
+ }
11
+
12
+ if (report === undefined) {
13
+ return null;
14
+ }
15
+
16
+ return report.map((task, id) => (
17
+ <div key={"report_task_"+id} className="report_task">{task.name}</div>
18
+ ));
19
+ };
20
+
21
+ ReportViewer.propTypes = {
22
+ hidden: PropTypes.bool,
23
+ report: PropTypes.array,
24
+ };
25
+
26
+ export default ReportViewer;
@@ -0,0 +1,27 @@
1
+ import { bindActionCreators } from 'redux';
2
+ import { connect } from 'react-redux';
3
+
4
+ import './ApplicationInstanceReport.scss';
5
+ import ApplicationInstanceReport from './ApplicationInstanceReport';
6
+ import * as ApplicationInstanceReportActions from './ApplicationInstanceReportActions';
7
+
8
+ import {
9
+ selectHosts,
10
+ selectReport,
11
+ selectActiveHostId,
12
+ } from './ApplicationInstanceReportSelectors';
13
+
14
+ const mapStateToProps = state => ({
15
+ hosts: selectHosts(state),
16
+ report: selectReport(state),
17
+ activeHostId: selectActiveHostId(state),
18
+ });
19
+
20
+ const mapDispatchToProps = dispatch =>
21
+ bindActionCreators(ApplicationInstanceReportActions, dispatch);
22
+
23
+ export default connect(
24
+ mapStateToProps,
25
+ mapDispatchToProps
26
+ )(ApplicationInstanceReport);
27
+
@@ -5,14 +5,11 @@ import * as sort from 'sortabular';
5
5
  import { orderBy } from 'lodash';
6
6
  import * as resolve from 'table-resolver';
7
7
  import Select from 'foremanReact/components/common/forms/Select';
8
+ import AddTableEntry from '../common/AddTableEntry';
9
+ import DeleteTableEntry from '../common/DeleteTableEntry';
10
+ import ExtSelect from '../common/ExtSelect';
8
11
 
9
12
  import {
10
- isNewDefinition,
11
- isEditDefinition,
12
- isDefinition,
13
- isNewInstance,
14
- isEditInstance,
15
- isInstance,
16
13
  transformForemanData,
17
14
  } from './ParameterSelectionHelper';
18
15
 
@@ -22,9 +19,10 @@ import {
22
19
  cloneDeep,
23
20
  } from 'lodash';
24
21
 
25
-
26
22
  import {
27
- PARAMETER_TYPES,
23
+ PARAMETER_SELECTION_TYPES,
24
+ PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
25
+ PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
28
26
  } from './ParameterSelectionConstants';
29
27
 
30
28
  import {
@@ -43,86 +41,12 @@ const theme = {
43
41
  base00: 'rgba(0, 0, 0, 0)',
44
42
  };
45
43
 
46
-
47
44
  class ParameterSelection extends React.Component {
48
45
 
49
46
  constructor(props) {
50
47
  super(props);
51
48
  }
52
49
 
53
- renderAddButton(mode, addParameter) {
54
- if (isInstance(mode))
55
- return null;
56
-
57
- return (
58
- <Button bsStyle="default" disabled={ this.props.editMode || this.props.hostgroupId <= 0 } onClick={() => addParameter()}>
59
- <Icon type="fa" name="plus" />
60
- </Button>
61
- );
62
- }
63
-
64
- renderDeleteButton(mode, deleteParameter, additionalData, disabled=false) {
65
- if (isInstance(mode))
66
- return null;
67
-
68
- return (
69
- <span>
70
- &nbsp;
71
- <Button
72
- bsStyle="default"
73
- disabled={disabled}
74
- onClick={() => window.confirm("Are you sure you wish to delete this item?") && deleteParameter(additionalData) }
75
- >
76
- <Icon type="pf" name="delete" />
77
- </Button>
78
- </span>
79
- );
80
- }
81
-
82
- renderSelectApplication(applications, url, loadParameterSelection, appDefinition) {
83
- return (
84
- <Select
85
- value={appDefinition.id.toString()}
86
- onChange={e => loadParameterSelection(url, e.target.value) }
87
- options={applications}
88
- allowClear
89
- key="key"
90
- />
91
- );
92
- }
93
-
94
- renderSelectHostgroup(hostgroups, url, loadForemanData, hostgroupId) {
95
- return (
96
- <Select
97
- value={hostgroupId.toString()}
98
- onChange={e => loadForemanData(url, e.target.value, true) }
99
- options={hostgroups}
100
- allowClear
101
- key="key"
102
- />
103
- );
104
- }
105
-
106
- renderRailsInputHidden(view, parameter, value) {
107
- var id = "foreman_acd_"+ view +"_"+ parameter;
108
- var name = "foreman_acd_"+ view +"["+ parameter +"]";
109
-
110
- return (
111
- <input
112
- id={id}
113
- name={name}
114
- value={value}
115
- type="hidden"
116
- />
117
- );
118
- }
119
-
120
- renderShowDivText(text) {
121
- return (
122
- <div>{text}</div>
123
- );
124
- }
125
-
126
50
  isEditing({rowData}) {
127
51
  return (rowData.backup !== undefined);
128
52
  }
@@ -130,31 +54,29 @@ class ParameterSelection extends React.Component {
130
54
  // enables our custom header formatters extensions to reactabular
131
55
  customHeaderFormatters = customHeaderFormattersDefinition;
132
56
 
133
- validateRows() {
134
- var result = (this.props.rows.map(e => e.value).filter(i => i == "").length == 0);
135
- if (result === false) {
136
- window.alert("All parameters need to have a value!");
137
- }
138
- return result;
139
- }
140
-
141
57
  componentDidMount() {
142
58
  const {
143
- data: { mode, appDefinition, location, organization, loadForemanDataUrl, parameters },
59
+ data: { useDefaultValue, allowRowAdjustment, allowNameAdjustment, allowDescriptionAdjustment, parameters, paramDefinition },
60
+ location,
61
+ organization,
62
+ paramType,
63
+ paramDataUrl,
144
64
  initParameterSelection,
145
65
  sortParameter,
146
66
  deleteParameter,
147
67
  activateEditParameter,
148
68
  changeEditParameter,
149
- loadForemanData,
69
+ loadParamData,
150
70
  } = this.props;
151
71
 
152
- if (isEditDefinition(mode) || isEditInstance(mode)) {
153
- loadForemanData(loadForemanDataUrl, appDefinition.hostgroup_id);
154
- }
155
-
156
- if (isInstance(mode)) {
157
- $('input[type="submit"][name="commit"]').on('click', () => this.validateRows());
72
+ if (paramDataUrl !== undefined) {
73
+ switch (paramType) {
74
+ case PARAMETER_SELECTION_PARAM_TYPE_FOREMAN: {
75
+ loadParamData({ paramDefinition: paramDefinition, url: paramDataUrl, dataType: paramType, clearParameters: false });
76
+ break;
77
+ }
78
+ default: { }
79
+ }
158
80
  }
159
81
 
160
82
  const inlineEditButtonsFormatter = inlineEditFormatterFactory({
@@ -167,7 +89,12 @@ class ParameterSelection extends React.Component {
167
89
  >
168
90
  <Icon type="pf" name="edit" />
169
91
  </Button>
170
- {this.renderDeleteButton(mode, deleteParameter, additionalData)}
92
+ <DeleteTableEntry
93
+ hidden={!allowRowAdjustment}
94
+ disabled={false}
95
+ onDeleteTableEntry={deleteParameter}
96
+ additionalData={additionalData}
97
+ />
171
98
  </td>
172
99
  ),
173
100
  renderEdit: (value, additionalData) => (
@@ -175,7 +102,12 @@ class ParameterSelection extends React.Component {
175
102
  <Button bsStyle="default" disabled>
176
103
  <Icon type="pf" name="edit" />
177
104
  </Button>
178
- {this.renderDeleteButton(mode, deleteParameter, additionalData, true)}
105
+ <DeleteTableEntry
106
+ hidden={!allowRowAdjustment}
107
+ disabled={true}
108
+ onDeleteTableEntry={deleteParameter}
109
+ additionalData={additionalData}
110
+ />
179
111
  </td>
180
112
  )
181
113
  });
@@ -225,28 +157,36 @@ class ParameterSelection extends React.Component {
225
157
  ),
226
158
  };
227
159
 
160
+ // TODO: should we differentiate between paramType FOREMAN and ANSIBLE?
161
+
228
162
  const inlineEditFormatter = inlineEditFormatterFactory({
229
163
  isEditing: additionalData => this.isEditing(additionalData),
230
164
  renderValue: (value, additionalData) => {
231
- var prettyValue = value;
165
+ let prettyValue = value;
232
166
  if (additionalData.property == 'type') {
233
- prettyValue = PARAMETER_TYPES[value];
167
+ prettyValue = PARAMETER_SELECTION_TYPES[value];
234
168
  } else if (additionalData.property == 'value') {
235
169
  switch (additionalData.rowData.type) {
236
170
  case 'computeprofile':
237
- prettyValue = transformForemanData(this.props.foremanData['computeprofiles'])[value]
171
+ prettyValue = transformForemanData(this.props.paramData['computeprofiles'])[value]
238
172
  break;
239
173
  case 'domain':
240
- prettyValue = transformForemanData(this.props.foremanData['domains'])[value]
174
+ prettyValue = transformForemanData(this.props.paramData['domains'])[value]
241
175
  break;
242
176
  case 'lifecycleenv':
243
- prettyValue = transformForemanData(this.props.foremanData['lifecycle_environments'])[value]
177
+ prettyValue = transformForemanData(this.props.paramData['lifecycle_environments'])[value]
244
178
  break;
245
179
  case 'ptable':
246
- prettyValue = transformForemanData(this.props.foremanData['ptables'])[value]
180
+ prettyValue = transformForemanData(this.props.paramData['ptables'])[value]
181
+ break;
182
+ case 'password':
183
+ prettyValue = '****************'
247
184
  break;
248
185
  case 'puppetenv':
249
- prettyValue = transformForemanData(this.props.foremanData['environments'])[value]
186
+ prettyValue = transformForemanData(this.props.paramData['environments'])[value]
187
+ break;
188
+ case 'text':
189
+ prettyValue = value
250
190
  break;
251
191
  }
252
192
  }
@@ -258,19 +198,21 @@ class ParameterSelection extends React.Component {
258
198
  if (additionalData.rowData.newEntry === true) {
259
199
  return inlineEditFormatterImpl.renderEditSelect(value, additionalData, this.props.parameterTypes);
260
200
  }
261
- return inlineEditFormatterImpl.renderValue(PARAMETER_TYPES[value], additionalData)
201
+ return inlineEditFormatterImpl.renderValue(PARAMETER_SELECTION_TYPES[value], additionalData)
262
202
  case 'value':
263
203
  switch (additionalData.rowData.type) {
264
204
  case 'computeprofile':
265
- return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.foremanData['computeprofiles']));
205
+ return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.paramData['computeprofiles']));
266
206
  case 'domain':
267
- return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.foremanData['domains']));
207
+ return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.paramData['domains']));
268
208
  case 'lifecycleenv':
269
- return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.foremanData['lifecycle_environments']));
209
+ return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.paramData['lifecycle_environments']));
270
210
  case 'puppetenv':
271
- return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.foremanData['environments']));
211
+ return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.paramData['environments']));
272
212
  case 'ptable':
273
- return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.foremanData['ptables']));
213
+ return inlineEditFormatterImpl.renderEditSelect(value, additionalData, transformForemanData(this.props.paramData['ptables']));
214
+ case 'password':
215
+ return inlineEditFormatterImpl.renderEditText(value, additionalData, 'password');
274
216
  case 'text':
275
217
  default:
276
218
  return inlineEditFormatterImpl.renderEditText(value, additionalData);
@@ -283,9 +225,12 @@ class ParameterSelection extends React.Component {
283
225
  this.inlineEditFormatter = inlineEditFormatter;
284
226
 
285
227
  initParameterSelection(
286
- mode,
287
- appDefinition,
228
+ paramType,
229
+ paramDefinition,
288
230
  parameters,
231
+ useDefaultValue,
232
+ allowNameAdjustment,
233
+ allowDescriptionAdjustment,
289
234
  this.sortingFormatter,
290
235
  this.sortableTransform,
291
236
  this.inlineEditFormatter,
@@ -298,84 +243,56 @@ class ParameterSelection extends React.Component {
298
243
 
299
244
  render() {
300
245
  const {
301
- data: { mode, applications, hostgroups, loadParameterSelectionUrl, loadForemanDataUrl },
302
- rows,
246
+ data: { allowRowAdjustment, applications },
247
+ location,
248
+ organization,
249
+ parameters,
303
250
  columns,
304
251
  sortingColumns,
305
252
  loading,
306
253
  addParameter,
307
254
  confirmEditParameter,
308
255
  cancelEditParameter,
309
- loadParameterSelection,
310
- loadForemanData,
311
- appDefinition,
312
- hostgroupId,
313
256
  } = this.props;
314
257
 
315
- var sortedRows;
316
- var newEntryIndex = findIndex(rows, 'newEntry');
258
+ let sortedParameters;
259
+ const newEntryIndex = findIndex(parameters, 'newEntry');
317
260
 
318
261
  if (newEntryIndex >= 0) {
319
- let newEntry = rows[newEntryIndex];
262
+ const newEntry = parameters[newEntryIndex];
320
263
  // sort all elements, besides the newEntry which will be
321
264
  // added to the end of the Array
322
- var tmpRows = cloneDeep(rows);
323
- tmpRows.splice(newEntryIndex, 1);
324
- sortedRows = this.compose(
265
+ const tmpParameters = cloneDeep(parameters);
266
+ tmpParameters.splice(newEntryIndex, 1);
267
+ sortedParameters = this.compose(
325
268
  sort.sorter({
326
269
  columns,
327
270
  sortingColumns,
328
271
  sort: orderBy,
329
272
  strategy: sort.strategies.byProperty
330
273
  })
331
- )(tmpRows);
332
- sortedRows.push(newEntry);
274
+ )(tmpParameters);
275
+ sortedParameters.push(newEntry);
333
276
  } else {
334
- sortedRows = this.compose(
277
+ sortedParameters = this.compose(
335
278
  sort.sorter({
336
279
  columns,
337
280
  sortingColumns,
338
281
  sort: orderBy,
339
282
  strategy: sort.strategies.byProperty
340
283
  })
341
- )(rows);
284
+ )(parameters);
342
285
  }
343
286
 
344
287
  return(
345
288
  <div>
346
- {isDefinition(mode) ? (
347
- <div className="clearfix">
348
- <div className="form-group">
349
- <label className="col-md-2 control-label">Host Group</label>
350
- <div className="col-md-4">
351
- {isNewDefinition(mode) && this.renderSelectHostgroup(hostgroups, loadForemanDataUrl, loadForemanData, hostgroupId) }
352
- {isEditDefinition(mode) && this.renderShowDivText(hostgroups[hostgroupId]) }
353
- {this.renderRailsInputHidden('app_definition', 'hostgroup_id', hostgroupId) }
354
- </div>
355
- </div>
356
- </div>
357
- ) : (
358
- <div className="clearfix">
359
- <div className="form-group">
360
- <label className="col-md-2 control-label">Application Definition</label>
361
- <div className="col-md-4">
362
- {isNewInstance(mode) && this.renderSelectApplication(applications, loadParameterSelectionUrl, loadParameterSelection, appDefinition)}
363
- {isEditInstance(mode) && this.renderShowDivText(appDefinition.name)}
364
- {isInstance(mode) && this.renderRailsInputHidden('app_instance', 'app_definition_id', appDefinition.id)}
365
- </div>
366
- </div>
367
- </div>
368
- )}
369
- <div className="clearfix">
370
- <div className="form-group">
371
- <label className="col-md-1 control-label">Application parameters</label>
372
- <div className="col-md-5">&nbsp;</div>
373
- </div>
374
- </div>
375
-
376
289
  <div className="clearfix">
377
290
  <div className="form-group">
378
- {this.renderAddButton(mode, addParameter)}
291
+ <AddTableEntry
292
+ hidden={!allowRowAdjustment}
293
+ disabled={ this.props.editMode }
294
+ onAddTableEntry={ addParameter }
295
+ />
379
296
  <Table.PfProvider
380
297
  striped
381
298
  bordered
@@ -400,20 +317,23 @@ class ParameterSelection extends React.Component {
400
317
  >
401
318
  <Table.Header headerRows={resolve.headerRows({ columns })} />
402
319
  <Table.Body
403
- rows={sortedRows}
320
+ rows={sortedParameters}
404
321
  rowKey="id"
405
322
  onRow={(rowData, { rowIndex }) => ({
406
323
  role: 'row',
407
324
  isEditing: () => this.isEditing({ rowData }),
408
325
  onCancel: () => cancelEditParameter({ rowData, rowIndex }),
409
326
  onConfirm: () => confirmEditParameter({ rowData, rowIndex }),
410
- last: rowIndex === sortedRows.length - 1
327
+ last: rowIndex === sortedParameters.length - 1
411
328
  })}
412
329
  />
413
330
  </Table.PfProvider>
414
- {this.renderAddButton(mode, addParameter)}
331
+ <AddTableEntry
332
+ hidden={!allowRowAdjustment}
333
+ disabled={ this.props.editMode }
334
+ onAddTableEntry={ addParameter }
335
+ />
415
336
  </div>
416
- {this.renderRailsInputHidden(isDefinition(mode) ? 'app_definition' : 'app_instance', 'parameters', JSON.stringify(this.props.rows))}
417
337
  </div>
418
338
  </div>
419
339
  );
@@ -424,32 +344,27 @@ ParameterSelection.defaultProps = {
424
344
  error: {},
425
345
  editMode: false,
426
346
  loading: false,
427
- foremanData: {},
428
- rows: [],
347
+ paramData: {},
348
+ parameters: [],
429
349
  columns: [],
430
350
  sortingColumns: {},
431
- appDefinition: { "id": '', "name": '', "hostgroup_id": '', "parameters": [] },
432
- hostgroupId: -1,
433
351
  };
434
352
 
435
353
  ParameterSelection.propTypes = {
436
354
  data: PropTypes.shape({
437
- mode: PropTypes.string.isRequired,
438
- location: PropTypes.string.isRequired,
439
- organization: PropTypes.string.isRequired,
440
355
  parameters: PropTypes.array,
441
- appDefinition: PropTypes.object,
356
+ paramDefinition: PropTypes.object,
442
357
  applications: PropTypes.object,
443
- hostgroups: PropTypes.object,
444
- loadParameterSelectionUrl: PropTypes.string,
445
- loadForemanDataUrl: PropTypes.string,
446
358
  }).isRequired,
359
+ location: PropTypes.string.isRequired,
360
+ organization: PropTypes.string.isRequired,
361
+ paramDataUrl: PropTypes.string,
447
362
  initParameterSelection: PropTypes.func,
448
363
  editMode: PropTypes.bool.isRequired,
449
364
  loading: PropTypes.bool.isRequired,
450
- foremanData: PropTypes.object.isRequired,
365
+ paramData: PropTypes.object.isRequired,
451
366
  parameterTypes: PropTypes.object,
452
- rows: PropTypes.array,
367
+ parameters: PropTypes.array,
453
368
  sortingColumns: PropTypes.object,
454
369
  columns: PropTypes.array,
455
370
  sortParameter: PropTypes.func,
@@ -459,10 +374,8 @@ ParameterSelection.propTypes = {
459
374
  confirmEditParameter: PropTypes.func,
460
375
  cancelEditParameter: PropTypes.func,
461
376
  changeEditParameter: PropTypes.func,
462
- loadParameterSelection: PropTypes.func,
463
- loadForemanData: PropTypes.func,
464
- appDefinition: PropTypes.object,
465
- hostgroupId: PropTypes.number,
377
+ loadParamData: PropTypes.func,
378
+ paramDefinition: PropTypes.object,
466
379
  };
467
380
 
468
381
  export default ParameterSelection;