foreman_acd 0.7.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +17 -2
  4. data/app/controllers/foreman_acd/app_definitions_controller.rb +104 -7
  5. data/app/controllers/foreman_acd/app_instances_controller.rb +15 -30
  6. data/app/controllers/foreman_acd/concerns/app_instance_mixins.rb +36 -0
  7. data/app/controllers/ui_acd_controller.rb +42 -3
  8. data/app/lib/actions/foreman_acd/run_configurator.rb +1 -0
  9. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +40 -27
  10. data/app/models/foreman_acd/app_instance.rb +47 -2
  11. data/app/models/foreman_acd/foreman_host.rb +8 -0
  12. data/app/services/foreman_acd/app_deployer.rb +19 -2
  13. data/app/services/foreman_acd/inventory_creator.rb +11 -1
  14. data/app/views/foreman_acd/app_definitions/_form.html.erb +4 -0
  15. data/app/views/foreman_acd/app_definitions/import.html.erb +20 -1
  16. data/app/views/foreman_acd/app_definitions/index.html.erb +3 -6
  17. data/app/views/foreman_acd/app_instances/_form.html.erb +4 -0
  18. data/app/views/foreman_acd/app_instances/index.html.erb +15 -11
  19. data/app/views/foreman_acd/app_instances/report.html.erb +7 -2
  20. data/app/views/ui_acd/host_report.json.rabl +4 -0
  21. data/app/views/ui_acd/report_data.json.rabl +10 -0
  22. data/app/views/ui_acd/validate_hostname.json.rabl +6 -0
  23. data/config/routes.rb +3 -0
  24. data/db/migrate/20210818125913_add_is_existing_host_to_foreman_host.rb +8 -0
  25. data/db/migrate/20210902110645_add_initial_configure_task.rb +8 -0
  26. data/lib/foreman_acd/plugin.rb +9 -9
  27. data/lib/foreman_acd/version.rb +1 -1
  28. data/lib/foreman_acd.rb +27 -9
  29. data/package.json +8 -25
  30. data/test/controllers/ui_acd_controller_test.rb +4 -1
  31. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
  32. data/webpack/__snapshots__/helper.test.js.snap +1 -1
  33. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +34 -10
  34. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +12 -0
  35. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +1 -0
  36. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +30 -9
  37. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +4 -0
  38. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +1 -0
  39. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +12 -0
  40. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +31 -5
  41. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +8 -0
  42. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +1 -1
  43. data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +3 -3
  44. data/webpack/components/ApplicationDefinition/index.js +8 -0
  45. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.js +214 -0
  46. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.scss +1 -0
  47. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportActions.js +161 -0
  48. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportConstants.js +6 -0
  49. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportReducer.js +79 -0
  50. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportSelectors.js +8 -0
  51. data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportConfData_1.fixtures.js +129 -0
  52. data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportReducer.fixtures.js +29 -0
  53. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImport.test.js +20 -0
  54. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportReducer.test.js +43 -0
  55. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportSelectors.test.js +29 -0
  56. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImport.test.js.snap +62 -0
  57. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportReducer.test.js.snap +362 -0
  58. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportSelectors.test.js.snap +130 -0
  59. data/webpack/components/ApplicationDefinitionImport/index.js +32 -0
  60. data/webpack/components/ApplicationInstance/ApplicationInstance.js +102 -26
  61. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +118 -6
  62. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +4 -0
  63. data/webpack/components/ApplicationInstance/ApplicationInstanceHelper.js +15 -0
  64. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +71 -30
  65. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +4 -0
  66. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +2 -0
  67. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +1 -0
  68. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +12 -0
  69. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +12 -0
  70. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +98 -7
  71. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +271 -0
  72. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +8 -0
  73. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +1 -0
  74. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +1 -1
  75. data/webpack/components/ApplicationInstance/helper.js +0 -0
  76. data/webpack/components/ApplicationInstance/index.js +8 -0
  77. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +81 -6
  78. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +35 -1
  79. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +3 -0
  80. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +19 -0
  81. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -0
  82. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +1 -124
  83. data/webpack/components/ApplicationInstanceReport/index.js +8 -1
  84. data/webpack/components/ExistingHostSelection/ExistingHostSelection.js +104 -0
  85. data/webpack/components/ExistingHostSelection/ExistingHostSelection.scss +15 -0
  86. data/webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js +71 -0
  87. data/webpack/components/ExistingHostSelection/ExistingHostSelectionConstants.js +4 -0
  88. data/webpack/components/ExistingHostSelection/ExistingHostSelectionHelper.js +0 -0
  89. data/webpack/components/ExistingHostSelection/ExistingHostSelectionReducer.js +90 -0
  90. data/webpack/components/ExistingHostSelection/ExistingHostSelectionSelectors.js +8 -0
  91. data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionConfData_1.fixtures.js +191 -0
  92. data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionReducer.fixtures.js +203 -0
  93. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelection.test.js +19 -0
  94. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionReducer.test.js +59 -0
  95. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionSelectors.test.js +36 -0
  96. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelection.test.js.snap +35 -0
  97. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionReducer.test.js.snap +614 -0
  98. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionSelectors.test.js.snap +27 -0
  99. data/webpack/components/ExistingHostSelection/components/ServiceSelector.js +48 -0
  100. data/webpack/components/ExistingHostSelection/components/__tests__/ServiceSelector.test.js +35 -0
  101. data/webpack/components/ExistingHostSelection/components/__tests__/__snapshots__/ServiceSelector.test.js.snap +77 -0
  102. data/webpack/components/ExistingHostSelection/index.js +26 -0
  103. data/webpack/components/ParameterSelection/ParameterSelection.js +103 -1
  104. data/webpack/components/ParameterSelection/ParameterSelection.scss +7 -0
  105. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +46 -4
  106. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +2 -0
  107. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +5 -1
  108. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +52 -11
  109. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +2 -0
  110. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +8 -0
  111. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +2 -0
  112. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -0
  113. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +96 -0
  114. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +117 -17
  115. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +13 -0
  116. data/webpack/components/ParameterSelection/index.js +4 -1
  117. data/webpack/components/SyncGitRepo/SyncGitRepo.js +2 -10
  118. data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +2 -3
  119. data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +0 -1
  120. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +1 -0
  121. data/webpack/components/SyncGitRepo/components/FormTextInput.js +1 -1
  122. data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +3 -2
  123. data/webpack/components/common/DeleteTableEntry.js +16 -2
  124. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +38 -0
  125. data/webpack/helper.js +21 -1
  126. data/webpack/helper.test.js +20 -1
  127. data/webpack/index.js +5 -0
  128. data/webpack/js-yaml.js +3874 -0
  129. data/webpack/reducer.js +13 -2
  130. data/webpack/test_setup.js +0 -2
  131. metadata +46 -2
@@ -0,0 +1,35 @@
1
+ import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
2
+
3
+ import ServiceSelector from '../ServiceSelector';
4
+
5
+ const noop = () => {};
6
+
7
+ const data = [
8
+ { name: 'report 1', status: 'done' },
9
+ { name: 'report 2', status: 'pending' }
10
+ ];
11
+
12
+ const fixtures = {
13
+ 'should render the service selector': {
14
+ hidden: false,
15
+ label: 'Test Label',
16
+ viewText: 'view service',
17
+ selectValue: '1',
18
+ onChange: noop,
19
+ options: { first: 'first', second: 'second'},
20
+ additionalData: { moreData: 'moooore' },
21
+ },
22
+ 'should render the hidden service selector': {
23
+ hidden: true,
24
+ label: 'Test Label',
25
+ viewText: 'view service',
26
+ selectValue: '1',
27
+ onChange: noop,
28
+ options: { first: 'first', second: 'second'},
29
+ additionalData: { },
30
+ },
31
+ };
32
+
33
+ describe('ServiceSelector', () =>
34
+ testComponentSnapshotsWithFixtures(ServiceSelector, fixtures));
35
+
@@ -0,0 +1,77 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ServiceSelector should render the hidden service selector 1`] = `
4
+ <div
5
+ className="form-group"
6
+ >
7
+ <label
8
+ className="col-md-2 control-label"
9
+ >
10
+ Test Label
11
+ </label>
12
+ <div
13
+ className="col-md-4"
14
+ >
15
+ <ExtSelect
16
+ additionalData={Object {}}
17
+ editable={true}
18
+ hidden={true}
19
+ onChange={[Function]}
20
+ options={
21
+ Object {
22
+ "first": "first",
23
+ "second": "second",
24
+ }
25
+ }
26
+ selectValue="1"
27
+ viewText="view service"
28
+ />
29
+ <RailsData
30
+ key="service_id"
31
+ parameter="service_id"
32
+ value="1"
33
+ view="existing_host_selection"
34
+ />
35
+ </div>
36
+ </div>
37
+ `;
38
+
39
+ exports[`ServiceSelector should render the service selector 1`] = `
40
+ <div
41
+ className="form-group"
42
+ >
43
+ <label
44
+ className="col-md-2 control-label"
45
+ >
46
+ Test Label
47
+ </label>
48
+ <div
49
+ className="col-md-4"
50
+ >
51
+ <ExtSelect
52
+ additionalData={
53
+ Object {
54
+ "moreData": "moooore",
55
+ }
56
+ }
57
+ editable={true}
58
+ hidden={false}
59
+ onChange={[Function]}
60
+ options={
61
+ Object {
62
+ "first": "first",
63
+ "second": "second",
64
+ }
65
+ }
66
+ selectValue="1"
67
+ viewText="view service"
68
+ />
69
+ <RailsData
70
+ key="service_id"
71
+ parameter="service_id"
72
+ value="1"
73
+ view="existing_host_selection"
74
+ />
75
+ </div>
76
+ </div>
77
+ `;
@@ -0,0 +1,26 @@
1
+ import { bindActionCreators } from 'redux';
2
+ import { connect } from 'react-redux';
3
+
4
+ import './ExistingHostSelection.scss';
5
+ import ExistingHostSelection from './ExistingHostSelection';
6
+ import * as ExistingHostSelectionActions from './ExistingHostSelectionActions';
7
+
8
+ import {
9
+ selectServiceId,
10
+ selectAvailableHosts,
11
+ selectAlreadyUsedHosts,
12
+ } from './ExistingHostSelectionSelectors';
13
+
14
+ const mapStateToProps = state => ({
15
+ serviceId: selectServiceId(state),
16
+ availableHosts: selectAvailableHosts(state),
17
+ alreadyUsedHosts: selectAlreadyUsedHosts(state),
18
+ });
19
+
20
+ const mapDispatchToProps = dispatch =>
21
+ bindActionCreators(ExistingHostSelectionActions, dispatch);
22
+
23
+ export default connect(
24
+ mapStateToProps,
25
+ mapDispatchToProps
26
+ )(ExistingHostSelection);
@@ -9,7 +9,8 @@ import AddTableEntry from '../common/AddTableEntry';
9
9
  import EditTableEntry from '../common/EditTableEntry';
10
10
  import DeleteTableEntry from '../common/DeleteTableEntry';
11
11
  import LockTableEntry from '../common/LockTableEntry';
12
- import ExtSelect from '../common/ExtSelect';
12
+ import ForemanModal from 'foremanReact/components/ForemanModal';
13
+ import * as YamlValidator from '../../js-yaml';
13
14
 
14
15
  import {
15
16
  transformForemanData,
@@ -32,6 +33,7 @@ import {
32
33
  Button,
33
34
  Table,
34
35
  FormControl,
36
+ InputGroup,
35
37
  defaultSortingOrder,
36
38
  customHeaderFormattersDefinition,
37
39
  inlineEditFormatterFactory,
@@ -47,12 +49,42 @@ class ParameterSelection extends React.Component {
47
49
 
48
50
  constructor(props) {
49
51
  super(props);
52
+ this.state = {textValue: ''};
50
53
  }
51
54
 
55
+ handleChange = event => {
56
+ this.setState({textValue: event.target.value});
57
+ };
58
+
52
59
  isEditing({rowData}) {
53
60
  return (rowData.backup !== undefined);
54
61
  }
55
62
 
63
+ yamlValidator() {
64
+ let result = true;
65
+ let msg = "";
66
+ try {
67
+ const doc = YamlValidator.load(this.state.textValue);
68
+ } catch (e) {
69
+ result = false;
70
+ msg = "Invalid Yaml: " + e.name + ": " + e.message;
71
+ }
72
+ return {
73
+ validateResult: result,
74
+ validateMsg: msg
75
+ }
76
+ }
77
+
78
+ yamlValue() {
79
+ if (this.props.editParamsRowIndex != undefined) {
80
+ let id = this.props.editParamsRowIndex;
81
+ if (this.props.parameters[id] != undefined) {
82
+ return this.props.parameters[id]['value'];
83
+ }
84
+ }
85
+ return '';
86
+ }
87
+
56
88
  // enables our custom header formatters extensions to reactabular
57
89
  customHeaderFormatters = customHeaderFormattersDefinition;
58
90
 
@@ -63,12 +95,15 @@ class ParameterSelection extends React.Component {
63
95
  organization,
64
96
  paramType,
65
97
  paramDataUrl,
98
+ hiddenParameterTypes,
66
99
  initParameterSelection,
67
100
  sortParameter,
68
101
  deleteParameter,
69
102
  lockParameter,
70
103
  activateEditParameter,
71
104
  changeEditParameter,
105
+ openParameterSelectionDialogBox,
106
+ closeParameterSelectionDialogBox,
72
107
  loadParamData,
73
108
  } = this.props;
74
109
 
@@ -165,6 +200,22 @@ class ParameterSelection extends React.Component {
165
200
  />
166
201
  </td>
167
202
  ),
203
+ renderEditComplexText: (value, additionalData, subtype='text') => (
204
+ <td className="editing">
205
+ <InputGroup>
206
+ <FormControl
207
+ type={subtype}
208
+ defaultValue={additionalData.rowData.isYaml == true ? '' : value}
209
+ onBlur={e => changeEditParameter(e.target.value, additionalData) }
210
+ readOnly={additionalData.rowData.isYaml}
211
+ placeholder={'Press YAML button for Yaml Data'}
212
+ />
213
+ <InputGroup.Button>
214
+ <Button onClick= {e => openParameterSelectionDialogBox(e)}> YAML </Button>
215
+ </InputGroup.Button>
216
+ </InputGroup>
217
+ </td>
218
+ ),
168
219
  renderEditSelect: (value, additionalData, options) => (
169
220
  <td className="editing">
170
221
  <Select
@@ -209,6 +260,10 @@ class ParameterSelection extends React.Component {
209
260
  case 'text':
210
261
  prettyValue = value
211
262
  break;
263
+ case 'complex':
264
+ prettyValue = additionalData.rowData.isYaml ? 'YAML value' : value;
265
+ break;
266
+
212
267
  }
213
268
  }
214
269
  return inlineEditFormatterImpl.renderValue(prettyValue, additionalData)
@@ -235,6 +290,8 @@ class ParameterSelection extends React.Component {
235
290
  case 'password':
236
291
  return inlineEditFormatterImpl.renderEditText(value, additionalData, 'password');
237
292
  case 'text':
293
+ case 'complex':
294
+ return inlineEditFormatterImpl.renderEditComplexText(value, additionalData);
238
295
  default:
239
296
  return inlineEditFormatterImpl.renderEditText(value, additionalData);
240
297
  }
@@ -243,12 +300,14 @@ class ParameterSelection extends React.Component {
243
300
  }
244
301
  }
245
302
  });
303
+
246
304
  this.inlineEditFormatter = inlineEditFormatter;
247
305
 
248
306
  initParameterSelection(
249
307
  paramType,
250
308
  paramDefinition,
251
309
  parameters,
310
+ hiddenParameterTypes,
252
311
  useDefaultValue,
253
312
  allowNameAdjustment,
254
313
  allowDescriptionAdjustment,
@@ -274,6 +333,7 @@ class ParameterSelection extends React.Component {
274
333
  addParameter,
275
334
  confirmEditParameter,
276
335
  cancelEditParameter,
336
+ closeParameterSelectionDialogBox,
277
337
  editModeCallback,
278
338
  } = this.props;
279
339
 
@@ -282,6 +342,7 @@ class ParameterSelection extends React.Component {
282
342
 
283
343
  if (newEntryIndex >= 0) {
284
344
  const newEntry = parameters[newEntryIndex];
345
+
285
346
  // sort all elements, besides the newEntry which will be
286
347
  // added to the end of the Array
287
348
  const tmpParameters = cloneDeep(parameters);
@@ -312,6 +373,8 @@ class ParameterSelection extends React.Component {
312
373
  editModeCallback(this.props.editMode);
313
374
  }
314
375
 
376
+ let { validateResult, validateMsg } = this.yamlValidator();
377
+
315
378
  return(
316
379
  <div>
317
380
  <div className="clearfix">
@@ -358,6 +421,38 @@ class ParameterSelection extends React.Component {
358
421
  />
359
422
  </div>
360
423
  </div>
424
+ <div>
425
+ <ForemanModal
426
+ id="ParameterSelectionComplexDataModal"
427
+ dialogClassName="complex_data_modal"
428
+ title={__("YAML Data Input")}
429
+
430
+ >
431
+ <ForemanModal.Header closeButton={false}>
432
+ </ForemanModal.Header>
433
+ <textarea id='yamlData'
434
+ defaultValue= {this.yamlValue()}
435
+ onChange={this.handleChange}
436
+ style={{width: "550px", height: "350px", fontFamily: "Courier"}} />
437
+ <ForemanModal.Footer>
438
+ <div>
439
+ {validateResult == false ? (
440
+ <div className="form-group">
441
+ <div class="alert alert-danger alert-dismissable">
442
+ <button type="button" class="close" data-dismiss="alert" aria-label="Close">
443
+ <span class="pficon pficon-close"></span>
444
+ </button>
445
+ <span class="pficon pficon-error-circle-o"></span>
446
+ {validateMsg}
447
+ </div>
448
+ </div>
449
+ ) : (<div></div>)}
450
+ <Button bsStyle="primary" onClick ={() => closeParameterSelectionDialogBox({ mode: 'save' })}>{__("Save")}</Button>
451
+ <Button bsStyle="default" onClick={() => closeParameterSelectionDialogBox({ mode: 'cancel' })}>{__("Cancel")}</Button>
452
+ </div>
453
+ </ForemanModal.Footer>
454
+ </ForemanModal>
455
+ </div>
361
456
  </div>
362
457
  );
363
458
  }
@@ -370,7 +465,9 @@ ParameterSelection.defaultProps = {
370
465
  paramData: {},
371
466
  parameters: [],
372
467
  columns: [],
468
+ hiddenParameterTypes: [],
373
469
  sortingColumns: {},
470
+ editParamsRowIndex: [],
374
471
  editModeCallback: undefined,
375
472
  };
376
473
 
@@ -387,6 +484,8 @@ ParameterSelection.propTypes = {
387
484
  editMode: PropTypes.bool.isRequired,
388
485
  loading: PropTypes.bool.isRequired,
389
486
  paramData: PropTypes.object.isRequired,
487
+ hiddenParameterTypes: PropTypes.array.isRequired,
488
+ allowedParameterTypes: PropTypes.object,
390
489
  parameterTypes: PropTypes.object,
391
490
  parameters: PropTypes.array,
392
491
  sortingColumns: PropTypes.object,
@@ -400,8 +499,11 @@ ParameterSelection.propTypes = {
400
499
  confirmEditParameter: PropTypes.func,
401
500
  cancelEditParameter: PropTypes.func,
402
501
  changeEditParameter: PropTypes.func,
502
+ openParameterSelectionDialogBox: PropTypes.func,
503
+ closeParameterSelectionDialogBox: PropTypes.func,
403
504
  loadParamData: PropTypes.func,
404
505
  paramDefinition: PropTypes.object,
506
+ editParamsRowIndex: PropTypes.array,
405
507
  };
406
508
 
407
509
  export default ParameterSelection;
@@ -8,3 +8,10 @@
8
8
  max-width: none !important;
9
9
  }
10
10
 
11
+ .complex_data_modal {
12
+ margin-top: 0;
13
+ margin-bottom: 0;
14
+ height: 80%;
15
+ width: 40%;
16
+ max-width: none !important;
17
+ }
@@ -17,9 +17,14 @@ import {
17
17
  } from 'foremanReact/common/helpers';
18
18
 
19
19
  import {
20
- filterUsedParameterTypes,
20
+ filterParameterTypes,
21
21
  } from './ParameterSelectionHelper';
22
22
 
23
+ import {
24
+ setModalOpen,
25
+ setModalClosed,
26
+ } from 'foremanReact/components/ForemanModal/ForemanModalActions';
27
+
23
28
  import {
24
29
  PARAMETER_SELECTION_INIT,
25
30
  PARAMETER_SELECTION_TYPES,
@@ -36,12 +41,15 @@ import {
36
41
  PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST,
37
42
  PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS,
38
43
  PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE,
44
+ PARAMETER_SELECTION_COMPLEX_DATA_MODAL_OPEN,
45
+ PARAMETER_SELECTION_COMPLEX_DATA_MODAL_CLOSE,
39
46
  } from './ParameterSelectionConstants';
40
47
 
41
48
  export const initParameterSelection = (
42
49
  paramType,
43
50
  paramDefinition,
44
51
  parameters,
52
+ hiddenParameterTypes,
45
53
  useDefaultValue,
46
54
  allowNameAdjustment,
47
55
  allowDescriptionAdjustment,
@@ -174,9 +182,18 @@ export const initParameterSelection = (
174
182
  initialState.parameters = parameters;
175
183
 
176
184
  if ((paramType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) && (parameters)) {
177
- initialState.parameterTypes = filterUsedParameterTypes(PARAMETER_SELECTION_TYPES, parameters);
185
+ let pTypes = PARAMETER_SELECTION_TYPES;
186
+
187
+ // filter hidden parameters
188
+ hiddenParameterTypes.forEach(item => delete pTypes[item]);
189
+ initialState.allowedParameterTypes = pTypes;
190
+
191
+ // filter already used parameter types
192
+ initialState.parameterTypes = filterParameterTypes(pTypes, parameters);
178
193
  }
179
194
 
195
+ initialState.paramType = paramType;
196
+
180
197
  dispatch({
181
198
  type: PARAMETER_SELECTION_INIT,
182
199
  payload: initialState,
@@ -198,7 +215,33 @@ export const lockParameter = (additionalData) => ({
198
215
  },
199
216
  });
200
217
 
201
- export const addParameter = (additionalData) => ({
218
+ export const openParameterSelectionDialogBox = (additionalData) => dispatch => {
219
+ dispatch({
220
+ type: PARAMETER_SELECTION_COMPLEX_DATA_MODAL_OPEN,
221
+ payload: {
222
+ ...additionalData,
223
+ }
224
+ });
225
+ dispatch(
226
+ setModalOpen({ id: 'ParameterSelectionComplexDataModal' })
227
+ );
228
+ };
229
+
230
+ export const closeParameterSelectionDialogBox = (additionalData) => dispatch => {
231
+ dispatch({
232
+ type: PARAMETER_SELECTION_COMPLEX_DATA_MODAL_CLOSE,
233
+ payload: {
234
+ ...additionalData,
235
+ }
236
+ });
237
+
238
+ dispatch(
239
+ setModalClosed({ id: 'ParameterSelectionComplexDataModal' })
240
+ );
241
+ };
242
+
243
+ export const addParameter = (additionalData) => (
244
+ {
202
245
  type: PARAMETER_SELECTION_ADD,
203
246
  payload: {
204
247
  ...additionalData,
@@ -268,4 +311,3 @@ export const loadParamData = (attr) => dispatch => {
268
311
  )
269
312
  .catch(error => dispatch(errorHandler(PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE, error)));
270
313
  };
271
-
@@ -12,6 +12,8 @@ export const PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS = 'PARAMETER_SELECTION_
12
12
  export const PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE = 'PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE';
13
13
  export const PARAMETER_SELECTION_PARAM_TYPE_FOREMAN = 'PARAMETER_SELECTION_PARAM_TYPE_FOREMAN';
14
14
  export const PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE = 'PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE';
15
+ export const PARAMETER_SELECTION_COMPLEX_DATA_MODAL_OPEN = 'PARAMETER_SELECTION_COMPLEX_DATA_MODAL_OPEN';
16
+ export const PARAMETER_SELECTION_COMPLEX_DATA_MODAL_CLOSE = 'PARAMETER_SELECTION_COMPLEX_DATA_MODAL_CLOSE';
15
17
 
16
18
  // Make sure the object is sorted by value
17
19
  // (Compute Profile -> Partition table -> Root password)
@@ -11,10 +11,14 @@ export const transformForemanData = (fdata) => {
11
11
  return (result);
12
12
  }
13
13
 
14
- export const filterUsedParameterTypes = (options, parameters) => {
14
+ export const filterParameterTypes = (options, parameters) => {
15
15
  const newOptions = cloneDeep(options);
16
+
16
17
  // hostparam can be used multiple times
17
18
  const alreadyUsed = parameters.map(item => item["type"]).filter(item => item != 'hostparam');
19
+
20
+ // remove already used items
18
21
  alreadyUsed.forEach(item => delete newOptions[item])
22
+
19
23
  return newOptions;
20
24
  }
@@ -7,7 +7,7 @@ import {
7
7
  } from 'lodash';
8
8
 
9
9
  import {
10
- filterUsedParameterTypes,
10
+ filterParameterTypes,
11
11
  } from './ParameterSelectionHelper';
12
12
 
13
13
  import * as sort from 'sortabular';
@@ -28,6 +28,8 @@ import {
28
28
  PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE,
29
29
  PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
30
30
  PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
31
+ PARAMETER_SELECTION_COMPLEX_DATA_MODAL_OPEN,
32
+ PARAMETER_SELECTION_COMPLEX_DATA_MODAL_CLOSE,
31
33
  } from './ParameterSelectionConstants';
32
34
 
33
35
  export const initialState = Immutable({
@@ -51,13 +53,16 @@ const parameterSelectionParameters = (state = initialState, action) => {
51
53
  index = Math.max(...parameters.map(e => e.id)) + 1;
52
54
  }
53
55
 
54
- const newRow = {id: index, locked: false, name: "", description: '', type: '', value: '', newEntry: true };
56
+ const newRow = {id: index, locked: false, name: "", description: '', type: '', value: '', isYaml: false, newEntry: true };
57
+ if (state.paramType == 'PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE') {
58
+ newRow['type'] = 'complex';
59
+ }
55
60
  newRow.backup = cloneDeep(newRow)
56
61
  parameters.push(newRow);
57
-
58
62
  return state.merge({
59
63
  editMode: true,
60
- parameters: parameters
64
+ parameters: parameters,
65
+ editParamsRowIndex: index,
61
66
  });
62
67
  }
63
68
  case PARAMETER_SELECTION_LOCK: {
@@ -78,7 +83,7 @@ const parameterSelectionParameters = (state = initialState, action) => {
78
83
  const parameters = state.parameters.filter(v => v.id !== payload.rowData.id);
79
84
  return state.merge({
80
85
  parameters: parameters,
81
- parameterTypes: filterUsedParameterTypes(PARAMETER_SELECTION_TYPES, parameters),
86
+ parameterTypes: filterParameterTypes(state.allowedParameterTypes, parameters),
82
87
  })
83
88
  }
84
89
  case PARAMETER_SELECTION_EDIT_ACTIVATE: {
@@ -86,10 +91,10 @@ const parameterSelectionParameters = (state = initialState, action) => {
86
91
  const index = findIndex(parameters, { id: payload.rowData.id });
87
92
 
88
93
  parameters[index].backup = cloneDeep(parameters[index]);
89
-
90
94
  return state.merge({
91
95
  editMode: true,
92
- parameters: parameters
96
+ parameters: parameters,
97
+ editParamsRowIndex: index,
93
98
  });
94
99
  }
95
100
  case PARAMETER_SELECTION_EDIT_CONFIRM: {
@@ -101,7 +106,7 @@ const parameterSelectionParameters = (state = initialState, action) => {
101
106
 
102
107
  return state.merge({
103
108
  editMode: false,
104
- parameterTypes: filterUsedParameterTypes(PARAMETER_SELECTION_TYPES, parameters),
109
+ parameterTypes: filterParameterTypes(state.allowedParameterTypes, parameters),
105
110
  parameters: parameters
106
111
  });
107
112
  }
@@ -109,9 +114,15 @@ const parameterSelectionParameters = (state = initialState, action) => {
109
114
  const parameters = cloneDeep(state.parameters);
110
115
  const index = findIndex(parameters, { id: payload.rowData.id });
111
116
 
112
- parameters[index][payload.property] = payload.value;
113
-
114
- return state.set('parameters', parameters);
117
+ if (!parameters[index]['isYaml'] && payload.property == 'value') {
118
+ parameters[index]['value'] = payload.value;
119
+ } else if (payload.property != 'value') {
120
+ parameters[index][payload.property] = payload.value;
121
+ }
122
+ return state.merge({
123
+ parameters: parameters,
124
+ editParamsRowIndex: index
125
+ });
115
126
  }
116
127
  case PARAMETER_SELECTION_EDIT_CANCEL: {
117
128
  const parameters = cloneDeep(state.parameters);
@@ -180,6 +191,36 @@ const parameterSelectionParameters = (state = initialState, action) => {
180
191
 
181
192
  return state.merge(newState);
182
193
  }
194
+ case PARAMETER_SELECTION_COMPLEX_DATA_MODAL_OPEN: {
195
+ return state;
196
+ }
197
+ case PARAMETER_SELECTION_COMPLEX_DATA_MODAL_CLOSE: {
198
+ let str;
199
+ let element = document.getElementById('yamlData');
200
+ if (element != null) {
201
+ str = element.value;
202
+ }
203
+ else {
204
+ str = '';
205
+ }
206
+ let newState = {};
207
+ let index = state.editParamsRowIndex;
208
+ const parameters = cloneDeep(state.parameters);
209
+ if (payload.mode == 'save') {
210
+ parameters[index]['value'] = str;
211
+ if (str == '') {
212
+ parameters[index]['isYaml'] = false;
213
+ } else {
214
+ parameters[index]['isYaml'] = true;
215
+ }
216
+ newState = {
217
+ parameters: parameters,
218
+ };
219
+ } else {
220
+ newState = {};
221
+ }
222
+ return state.merge(newState);
223
+ }
183
224
  default:
184
225
  return state;
185
226
  }
@@ -3,9 +3,11 @@ const parameterState = state => state.foremanAcd.parameterSelectionParameters;
3
3
  export const selectLoading = state => parameterState(state).loading;
4
4
  export const selectEditMode = state => parameterState(state).editMode;
5
5
  export const selectParamData = state => parameterState(state).paramData;
6
+ export const selectAllowedParameterTypes = state => parameterState(state).allowedParameterTypes;
6
7
  export const selectParameterTypes = state => parameterState(state).parameterTypes;
7
8
  export const selectParameters = state => parameterState(state).parameters;
8
9
  export const selectSortingColumns = state => parameterState(state).sortingColumns;
9
10
  export const selectColumns = state => parameterState(state).columns;
10
11
  export const selectParamDefinition = state => parameterState(state).paramDefinition;
11
12
  export const selectHostgroupId = state => parameterState(state).hostgroupId;
13
+ export const selectEditParamsRowIndex = state => parameterState(state).editParamsRowIndex;
@@ -215,6 +215,14 @@ export const parameterSelectionData_1 = {
215
215
  value: '1'
216
216
  }
217
217
  ],
218
+ allowedParameterTypes: [
219
+ 'domain',
220
+ 'hostparam',
221
+ 'ip',
222
+ 'ptable',
223
+ 'puppetenv',
224
+ 'password',
225
+ ],
218
226
  parameterTypes: {
219
227
  domain: 'Domain',
220
228
  hostparam: 'Host parameter',
@@ -31,6 +31,8 @@ import {
31
31
  PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST,
32
32
  PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS,
33
33
  PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE,
34
+ PARAMETER_SELECTION_COMPLEX_DATA_MODAL_OPEN,
35
+ PARAMETER_SELECTION_COMPLEX_DATA_MODAL_CLOSE,
34
36
  } from '../ParameterSelectionConstants';
35
37
 
36
38
  const fixtures = {
@@ -4,12 +4,14 @@ import {
4
4
  selectLoading,
5
5
  selectEditMode,
6
6
  selectParamData,
7
+ selectAllowedParameterTypes,
7
8
  selectParameterTypes,
8
9
  selectParameters,
9
10
  selectSortingColumns,
10
11
  selectColumns,
11
12
  selectParamDefinition,
12
13
  selectHostgroupId,
14
+ selectEditParamsRowIndex,
13
15
  } from '../ParameterSelectionSelectors';
14
16
 
15
17
  import {
@@ -29,6 +31,8 @@ const fixtures = {
29
31
  selectEditMode(stateFactory(parameterSelectionData_1)),
30
32
  'should return paramData from parameterSelectionData_1 fixtures': () =>
31
33
  selectParamData(stateFactory(parameterSelectionData_1)),
34
+ 'should return allowedParameterTypes from parameterSelectionData_1 fixtures': () =>
35
+ selectAllowedParameterTypes(stateFactory(parameterSelectionData_1)),
32
36
  'should return parameterTypes from parameterSelectionData_1 fixtures': () =>
33
37
  selectParameterTypes(stateFactory(parameterSelectionData_1)),
34
38
  'should return parameters from parameterSelectionData_1 fixtures': () =>
@@ -41,6 +45,8 @@ const fixtures = {
41
45
  selectParamDefinition(stateFactory(parameterSelectionData_1)),
42
46
  'should return hostgroupId from parameterSelectionData_1 fixtures': () =>
43
47
  selectHostgroupId(stateFactory(parameterSelectionData_1)),
48
+ 'should return editParamsRowIndex from parameterSelectionData_1 fixtures': () =>
49
+ selectEditParamsRowIndex(stateFactory(parameterSelectionData_1)),
44
50
  };
45
51
 
46
52
  describe('ParameterSelectionSelectors', () =>