foreman_acd 0.0.6 → 0.6.0

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