foreman_acd 0.0.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +82 -27
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +122 -0
  4. data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +71 -0
  5. data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -2
  6. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +54 -0
  7. data/app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb +0 -0
  8. data/app/controllers/foreman_acd/app_definitions_controller.rb +36 -4
  9. data/app/controllers/foreman_acd/app_instances_controller.rb +24 -90
  10. data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
  11. data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
  12. data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
  13. data/app/controllers/foreman_acd/remote_execution_controller.rb +49 -0
  14. data/app/controllers/ui_acd_controller.rb +11 -4
  15. data/app/models/foreman_acd/acd_provider.rb +27 -0
  16. data/app/models/foreman_acd/ansible_playbook.rb +50 -0
  17. data/app/models/foreman_acd/app_definition.rb +2 -1
  18. data/app/models/foreman_acd/app_instance.rb +7 -0
  19. data/app/services/foreman_acd/app_configurator.rb +57 -0
  20. data/app/services/foreman_acd/app_deployer.rb +139 -0
  21. data/app/services/foreman_acd/inventory_creator.rb +67 -0
  22. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +21 -0
  23. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +3 -0
  24. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  25. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  26. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +3 -0
  27. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +3 -0
  28. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +3 -0
  29. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +3 -0
  30. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +3 -0
  31. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +3 -0
  32. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -0
  33. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +3 -0
  34. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +3 -0
  35. data/app/views/foreman_acd/app_definitions/_form.html.erb +25 -19
  36. data/app/views/foreman_acd/app_definitions/edit.html.erb +5 -0
  37. data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
  38. data/app/views/foreman_acd/app_definitions/index.html.erb +9 -5
  39. data/app/views/foreman_acd/app_instances/_form.html.erb +10 -8
  40. data/app/views/foreman_acd/app_instances/deploy.html.erb +19 -0
  41. data/app/views/foreman_acd/app_instances/index.html.erb +10 -5
  42. data/app/views/foreman_acd/app_instances/report.html.erb +19 -0
  43. data/app/views/templates/job/run_acd_ansible_playbook.erb +49 -0
  44. data/app/views/ui_acd/ansible_data.json.rabl +6 -0
  45. data/app/views/ui_acd/app.json.rabl +6 -2
  46. data/app/views/ui_acd/app_definition.json.rabl +1 -1
  47. data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
  48. data/config/routes.rb +36 -1
  49. data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
  50. data/db/migrate/20190625140305_create_app_instances.rb +1 -1
  51. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  52. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  53. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +5 -0
  54. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +5 -0
  55. data/db/seeds.d/62_acd_proxy_feature.rb +6 -0
  56. data/db/seeds.d/75-job_templates.rb +8 -0
  57. data/lib/foreman_acd/engine.rb +7 -0
  58. data/lib/foreman_acd/plugin.rb +84 -13
  59. data/lib/foreman_acd/version.rb +1 -1
  60. data/package.json +1 -2
  61. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +378 -0
  62. data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
  63. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +295 -0
  64. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +14 -0
  65. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  66. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +243 -0
  67. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +8 -0
  68. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
  69. data/webpack/components/ApplicationDefinition/index.js +33 -0
  70. data/webpack/components/ApplicationInstance/ApplicationInstance.js +414 -0
  71. data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
  72. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +239 -0
  73. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +14 -0
  74. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +295 -0
  75. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +9 -0
  76. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
  77. data/webpack/components/ApplicationInstance/components/Service.js +30 -0
  78. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
  79. data/webpack/components/ApplicationInstance/index.js +35 -0
  80. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +155 -0
  81. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +27 -0
  82. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +86 -0
  83. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +4 -0
  84. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +52 -0
  85. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +5 -0
  86. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
  87. data/webpack/components/ApplicationInstanceReport/index.js +27 -0
  88. data/webpack/components/ParameterSelection/ParameterSelection.js +121 -192
  89. data/webpack/components/ParameterSelection/ParameterSelection.scss +9 -0
  90. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +80 -104
  91. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +15 -19
  92. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
  93. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +116 -84
  94. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
  95. data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
  96. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
  97. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
  98. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
  99. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
  100. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  101. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
  102. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
  103. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
  104. data/webpack/components/ParameterSelection/index.js +6 -8
  105. data/webpack/components/common/AddTableEntry.js +30 -0
  106. data/webpack/components/common/DeleteTableEntry.js +38 -0
  107. data/webpack/components/common/EasyHeaderFormatter.js +18 -0
  108. data/webpack/components/common/EditTableEntry.js +49 -0
  109. data/webpack/components/common/ExtSelect.js +43 -0
  110. data/webpack/components/common/LockTableEntry.js +59 -0
  111. data/webpack/components/common/RailsData.js +27 -0
  112. data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
  113. data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
  114. data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
  115. data/webpack/components/common/__tests__/RailsData.test.js +16 -0
  116. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
  117. data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
  118. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
  119. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
  120. data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
  121. data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
  122. data/webpack/helper.js +20 -0
  123. data/webpack/index.js +6 -0
  124. data/webpack/reducer.js +43 -3
  125. metadata +91 -39
@@ -1 +1,10 @@
1
1
  @import '~@theforeman/vendor/scss/variables';
2
+
3
+ .param_selection_modal {
4
+ margin-top: 0;
5
+ margin-bottom: 0;
6
+ height: 100%;
7
+ width: 80%;
8
+ max-width: none !important;
9
+ }
10
+
@@ -16,37 +16,34 @@ import {
16
16
  } from 'foremanReact/common/helpers';
17
17
 
18
18
  import {
19
- isNewDefinition,
20
- isEditDefinition,
21
- isDefinition,
22
- isNewInstance,
23
- isEditInstance,
24
- isInstance,
25
19
  filterUsedParameterTypes,
26
20
  } from './ParameterSelectionHelper';
27
21
 
28
22
  import {
29
- INIT_PARAMETER_SELECTION,
30
- PARAMETER_TYPES,
31
- PARAMETER_DELETE,
32
- PARAMETER_ADD,
33
- PARAMETER_EDIT_ACTIVATE,
34
- PARAMETER_EDIT_CONFIRM,
35
- PARAMETER_EDIT_CHANGE,
36
- PARAMETER_EDIT_CANCEL,
37
- PARAMETER_SORT,
38
- LOAD_PARAMETER_SELECTION_REQUEST,
39
- LOAD_PARAMETER_SELECTION_SUCCESS,
40
- LOAD_PARAMETER_SELECTION_FAILURE,
41
- LOAD_FOREMAN_DATA_REQUEST,
42
- LOAD_FOREMAN_DATA_SUCCESS,
43
- LOAD_FOREMAN_DATA_FAILURE,
23
+ PARAMETER_SELECTION_INIT,
24
+ PARAMETER_SELECTION_TYPES,
25
+ PARAMETER_SELECTION_LOCK,
26
+ PARAMETER_SELECTION_DELETE,
27
+ PARAMETER_SELECTION_ADD,
28
+ PARAMETER_SELECTION_EDIT_ACTIVATE,
29
+ PARAMETER_SELECTION_EDIT_CONFIRM,
30
+ PARAMETER_SELECTION_EDIT_CHANGE,
31
+ PARAMETER_SELECTION_EDIT_CANCEL,
32
+ PARAMETER_SELECTION_SORT,
33
+ PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
34
+ PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
35
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST,
36
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS,
37
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE,
44
38
  } from './ParameterSelectionConstants';
45
39
 
46
40
  export const initParameterSelection = (
47
- mode,
48
- appDefinition,
41
+ paramType,
42
+ paramDefinition,
49
43
  parameters,
44
+ useDefaultValue,
45
+ allowNameAdjustment,
46
+ allowDescriptionAdjustment,
50
47
  sortingFormatter,
51
48
  sortableTransform,
52
49
  inlineEditFormatter,
@@ -60,23 +57,28 @@ export const initParameterSelection = (
60
57
  position: 0
61
58
  }
62
59
  };
63
- initialState.appDefinition = appDefinition;
60
+ initialState.paramDefinition = paramDefinition;
64
61
 
65
- var valueLabel = 'Value';
66
- if (isDefinition(mode)) {
62
+ let valueLabel = 'Value';
63
+ if (useDefaultValue) {
67
64
  valueLabel = 'Default value';
68
65
  }
69
66
 
70
- initialState.columns = [
71
- {
67
+ initialState.columns = []
68
+ const addToColumns = (obj, idx) => {
69
+ obj.header.props.index = idx;
70
+ initialState.columns.push(obj);
71
+ }
72
+
73
+ let idx = 0;
74
+ addToColumns( {
72
75
  property: 'name',
73
76
  header: {
74
77
  label: 'Name',
75
78
  props: {
76
- index: 0,
77
79
  sort: true,
78
80
  style: {
79
- width: '20%'
81
+ width: '25%'
80
82
  }
81
83
  },
82
84
  transforms: [sortableTransform],
@@ -84,15 +86,15 @@ export const initParameterSelection = (
84
86
  customFormatters: [sortableHeaderCellFormatter]
85
87
  },
86
88
  cell: {
87
- formatters: [isDefinition(mode) ? inlineEditFormatter : tableCellFormatter]
89
+ formatters: [allowNameAdjustment ? inlineEditFormatter : tableCellFormatter]
88
90
  }
89
- },
90
- {
91
+ }, idx++);
92
+
93
+ addToColumns( {
91
94
  property: 'description',
92
95
  header: {
93
96
  label: 'Description',
94
97
  props: {
95
- index: 1,
96
98
  sort: true,
97
99
  style: {
98
100
  width: '25%'
@@ -106,15 +108,16 @@ export const initParameterSelection = (
106
108
  props: {
107
109
  index: 1
108
110
  },
109
- formatters: [isDefinition(mode) ? inlineEditFormatter : tableCellFormatter]
111
+ formatters: [allowDescriptionAdjustment ? inlineEditFormatter : tableCellFormatter]
110
112
  }
111
- },
112
- {
113
+ }, idx++);
114
+
115
+ if (paramType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) {
116
+ addToColumns( {
113
117
  property: 'type',
114
118
  header: {
115
119
  label: 'Type',
116
120
  props: {
117
- index: 2,
118
121
  sort: true,
119
122
  style: {
120
123
  width: '20%'
@@ -125,23 +128,21 @@ export const initParameterSelection = (
125
128
  customFormatters: [sortableHeaderCellFormatter]
126
129
  },
127
130
  cell: {
128
- props: {
129
- index: 2
130
- },
131
131
  // we are always using the inlineEditFormatter so that
132
132
  // the well formatted type name is shown
133
133
  formatters: [inlineEditFormatter]
134
134
  }
135
- },
136
- {
135
+ }, idx++);
136
+ }
137
+
138
+ addToColumns( {
137
139
  property: 'value',
138
140
  header: {
139
141
  label: valueLabel,
140
142
  props: {
141
- index: 3,
142
143
  sort: true,
143
144
  style: {
144
- width: '25%'
145
+ width: '20%'
145
146
  }
146
147
  },
147
148
  transforms: [sortableTransform],
@@ -149,47 +150,34 @@ export const initParameterSelection = (
149
150
  customFormatters: [sortableHeaderCellFormatter]
150
151
  },
151
152
  cell: {
152
- props: {
153
- index: 3
154
- },
155
153
  formatters: [inlineEditFormatter]
156
154
  }
157
- },
158
- {
155
+ }, idx++);
156
+
157
+ addToColumns( {
159
158
  property: 'actions',
160
159
  header: {
161
160
  label: 'Actions',
162
161
  props: {
163
- index: 4
162
+ style: {
163
+ width: '10%'
164
+ }
164
165
  },
165
166
  formatters: [actionHeaderCellFormatter]
166
167
  },
167
168
  cell: {
168
- props: {
169
- index: 4
170
- },
171
169
  formatters: [inlineEditButtonsFormatter]
172
170
  }
173
- }
174
- ];
171
+ }, idx++);
175
172
 
176
- if ((isNewDefinition(mode)) || (isNewInstance(mode))) {
177
- initialState.rows = [];
178
- } else if ((isEditDefinition(mode)) || (isEditInstance(mode))) {
179
- initialState.rows = parameters;
180
- initialState.hostgroupId = appDefinition.hostgroup_id;
181
- } else {
182
- // FIXME: should never ever happen
183
- }
173
+ initialState.parameters = parameters;
184
174
 
185
- if (isNewDefinition(mode) || isNewInstance(mode)) {
186
- initialState.parameterTypes = PARAMETER_TYPES;
187
- } else {
188
- initialState.parameterTypes = filterUsedParameterTypes(PARAMETER_TYPES, parameters);
175
+ if ((paramType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) && (parameters)) {
176
+ initialState.parameterTypes = filterUsedParameterTypes(PARAMETER_SELECTION_TYPES, parameters);
189
177
  }
190
178
 
191
179
  dispatch({
192
- type: INIT_PARAMETER_SELECTION,
180
+ type: PARAMETER_SELECTION_INIT,
193
181
  payload: initialState,
194
182
  });
195
183
  }
@@ -202,43 +190,50 @@ const errorHandler = (msg, err) => {
202
190
  return { type: msg, payload: { error } };
203
191
  };
204
192
 
193
+ export const lockParameter = (additionalData) => ({
194
+ type: PARAMETER_SELECTION_LOCK,
195
+ payload: {
196
+ ...additionalData,
197
+ },
198
+ });
199
+
205
200
  export const addParameter = (additionalData) => ({
206
- type: PARAMETER_ADD,
201
+ type: PARAMETER_SELECTION_ADD,
207
202
  payload: {
208
203
  ...additionalData,
209
204
  },
210
205
  });
211
206
 
212
207
  export const deleteParameter = (additionalData) => ({
213
- type: PARAMETER_DELETE,
208
+ type: PARAMETER_SELECTION_DELETE,
214
209
  payload: {
215
210
  ...additionalData,
216
211
  },
217
212
  });
218
213
 
219
214
  export const activateEditParameter = (additionalData) => ({
220
- type: PARAMETER_EDIT_ACTIVATE,
215
+ type: PARAMETER_SELECTION_EDIT_ACTIVATE,
221
216
  payload: {
222
217
  ...additionalData,
223
218
  },
224
219
  });
225
220
 
226
221
  export const confirmEditParameter = (rowData) => ({
227
- type: PARAMETER_EDIT_CONFIRM,
222
+ type: PARAMETER_SELECTION_EDIT_CONFIRM,
228
223
  payload: {
229
224
  ...rowData,
230
225
  },
231
226
  });
232
227
 
233
228
  export const cancelEditParameter = (rowData) => ({
234
- type: PARAMETER_EDIT_CANCEL,
229
+ type: PARAMETER_SELECTION_EDIT_CANCEL,
235
230
  payload: {
236
231
  ...rowData,
237
232
  },
238
233
  });
239
234
 
240
235
  export const changeEditParameter = (value, additionalData) => ({
241
- type: PARAMETER_EDIT_CHANGE,
236
+ type: PARAMETER_SELECTION_EDIT_CHANGE,
242
237
  payload: {
243
238
  value,
244
239
  ...additionalData,
@@ -246,49 +241,30 @@ export const changeEditParameter = (value, additionalData) => ({
246
241
  });
247
242
 
248
243
  export const sortParameter = (selectedColumn, defaultSortingOrder) => ({
249
- type: PARAMETER_SORT,
244
+ type: PARAMETER_SELECTION_SORT,
250
245
  payload: {
251
246
  selectedColumn,
252
247
  defaultSortingOrder,
253
248
  },
254
249
  });
255
250
 
256
- export const loadParameterSelection = (
257
- url,
258
- applicationDefinitionId
259
- ) => dispatch => {
260
- dispatch({ type: LOAD_PARAMETER_SELECTION_REQUEST });
251
+ export const loadParamData = (attr) => dispatch => {
252
+ dispatch( { type: PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST, payload: { dataType: attr.dataType, clearParameters: attr.clearParameters } });
261
253
 
262
- var realUrl = url.replace("__id__", applicationDefinitionId);
254
+ let realUrl = attr.url.replace("__id__", attr.paramDefinition.dataId);
263
255
 
264
- return api
265
- .get(realUrl, {}, {})
266
- .then(({ data }) =>
267
- dispatch({
268
- type: LOAD_PARAMETER_SELECTION_SUCCESS,
269
- payload: data,
270
- })
271
- )
272
- .catch(error => dispatch(errorHandler(LOAD_PARAMETER_SELECTION_FAILURE, error)));
273
- };
274
-
275
- export const loadForemanData = (
276
- url,
277
- hostgroupId,
278
- clearRows = false,
279
- ) => dispatch => {
280
- dispatch({ type: LOAD_FOREMAN_DATA_REQUEST, payload: { clearRows: clearRows } });
281
-
282
- var realUrl = url.replace("__id__", hostgroupId);
256
+ if (attr.paramDefinition.hasOwnProperty('dataSubId')) {
257
+ realUrl = realUrl.replace("__subid__", attr.paramDefinition.dataSubId);
258
+ }
283
259
 
284
260
  return api
285
261
  .get(realUrl, {}, {})
286
262
  .then(({ data }) =>
287
263
  dispatch({
288
- type: LOAD_FOREMAN_DATA_SUCCESS,
289
- payload: data,
264
+ type: PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS,
265
+ payload: { ...data, dataType: attr.dataType }
290
266
  })
291
267
  )
292
- .catch(error => dispatch(errorHandler(LOAD_FOREMAN_DATA_FAILURE, error)));
268
+ .catch(error => dispatch(errorHandler(PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE, error)));
293
269
  };
294
270
 
@@ -1,27 +1,23 @@
1
- export const INIT_PARAMETER_SELECTION = 'INIT_PARAMETER_SELECTION';
2
-
3
- export const PARAMETER_DELETE = 'PARAMETER_DELETE';
4
- export const PARAMETER_ADD = 'PARAMETER_ADD';
5
- export const PARAMETER_EDIT_ACTIVATE = 'PARAMETER_EDIT_ACTIVATE';
6
- export const PARAMETER_EDIT_CONFIRM = 'PARAMETER_EDIT_CONFIRM';
7
- export const PARAMETER_EDIT_CHANGE = 'PARAMETER_EDIT_CHANGE';
8
- export const PARAMETER_EDIT_CANCEL = 'PARAMETER_EDIT_CANCEL';
9
- export const PARAMETER_SORT = 'PARAMETER_SORT';
10
-
11
- export const LOAD_PARAMETER_SELECTION_REQUEST = 'LOAD_PARAMETER_SELECTION_REQUEST';
12
- export const LOAD_PARAMETER_SELECTION_SUCCESS = 'LOAD_PARAMETER_SELECTION_SUCCESS';
13
- export const LOAD_PARAMETER_SELECTION_FAILURE = 'LOAD_PARAMETER_SELECTION_FAILURE';
14
-
15
- export const LOAD_FOREMAN_DATA_REQUEST = 'LOAD_FOREMAN_DATA_REQUEST';
16
- export const LOAD_FOREMAN_DATA_SUCCESS = 'LOAD_FOREMAN_DATA_SUCCESS';
17
- export const LOAD_FOREMAN_DATA_FAILURE = 'LOAD_FOREMAN_DATA_FAILURE';
1
+ export const PARAMETER_SELECTION_INIT = 'INIT_PARAMETER_SELECTION_INIT';
2
+ export const PARAMETER_SELECTION_LOCK = 'PARAMETER_SELECTION_LOCK';
3
+ export const PARAMETER_SELECTION_DELETE = 'PARAMETER_SELECTION_DELETE';
4
+ export const PARAMETER_SELECTION_ADD = 'PARAMETER_SELECTION_ADD';
5
+ export const PARAMETER_SELECTION_EDIT_ACTIVATE = 'PARAMETER_SELECTION_EDIT_ACTIVATE';
6
+ export const PARAMETER_SELECTION_EDIT_CONFIRM = 'PARAMETER_SELECTION_EDIT_CONFIRM';
7
+ export const PARAMETER_SELECTION_EDIT_CHANGE = 'PARAMETER_SELECTION_EDIT_CHANGE';
8
+ export const PARAMETER_SELECTION_EDIT_CANCEL = 'PARAMETER_SELECTION_EDIT_CANCEL';
9
+ export const PARAMETER_SELECTION_SORT = 'PARAMETER_SELECTION_SORT';
10
+ export const PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST = 'PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST';
11
+ export const PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS = 'PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS';
12
+ export const PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE = 'PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE';
13
+ export const PARAMETER_SELECTION_PARAM_TYPE_FOREMAN = 'PARAMETER_SELECTION_PARAM_TYPE_FOREMAN';
14
+ export const PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE = 'PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE';
18
15
 
19
16
  // Make sure the object is sorted by value
20
17
  // (Compute Profile -> Partition table -> Root password)
21
- export const PARAMETER_TYPES = {
18
+ export const PARAMETER_SELECTION_TYPES = {
22
19
  computeprofile: 'Compute profile',
23
20
  domain: 'Domain',
24
- hostname: 'Hostname',
25
21
  hostparam: 'Host parameter',
26
22
  ip: 'IP',
27
23
  lifecycleenv: 'Lifecycle environment',
@@ -2,51 +2,19 @@ import {
2
2
  cloneDeep,
3
3
  } from 'lodash';
4
4
 
5
- export const isNewDefinition = (mode) => {
6
- if (mode == "newDefinition")
7
- return true;
8
- return false;
9
- }
10
-
11
- export const isEditDefinition = (mode) => {
12
- if (mode == "editDefinition")
13
- return true;
14
- return false;
15
- }
16
-
17
- export const isDefinition = (mode) => {
18
- return (isNewDefinition(mode) || isEditDefinition(mode))
19
- }
20
-
21
- export const isNewInstance = (mode) => {
22
- if (mode == "newInstance")
23
- return true;
24
- return false;
25
- }
26
-
27
- export const isEditInstance = (mode) => {
28
- if (mode == "editInstance")
29
- return true;
30
- return false;
31
- }
32
-
33
- export const isInstance = (mode) => {
34
- return (isNewInstance(mode) || isEditInstance(mode))
35
- }
36
-
37
5
  export const transformForemanData = (fdata) => {
38
6
  if (fdata === undefined) {
39
7
  return "";
40
8
  }
41
- var result = {};
9
+ const result = {};
42
10
  fdata.map(item => result[item.id] = item.name)
43
11
  return (result);
44
12
  }
45
13
 
46
14
  export const filterUsedParameterTypes = (options, parameters) => {
47
- var newOptions = cloneDeep(options);
15
+ const newOptions = cloneDeep(options);
48
16
  // hostparam can be used multiple times
49
- var alreadyUsed = parameters.map(item => item["type"]).filter(item => item != 'hostparam');
17
+ const alreadyUsed = parameters.map(item => item["type"]).filter(item => item != 'hostparam');
50
18
  alreadyUsed.forEach(item => delete newOptions[item])
51
19
  return newOptions;
52
20
  }
@@ -13,23 +13,27 @@ import {
13
13
  import * as sort from 'sortabular';
14
14
 
15
15
  import {
16
- INIT_PARAMETER_SELECTION,
17
- PARAMETER_TYPES,
18
- PARAMETER_DELETE,
19
- PARAMETER_ADD,
20
- PARAMETER_EDIT_ACTIVATE,
21
- PARAMETER_EDIT_CONFIRM,
22
- PARAMETER_EDIT_CHANGE,
23
- PARAMETER_EDIT_CANCEL,
24
- PARAMETER_SORT,
25
- LOAD_PARAMETER_SELECTION_REQUEST,
26
- LOAD_PARAMETER_SELECTION_SUCCESS,
27
- LOAD_PARAMETER_SELECTION_FAILURE,
28
- LOAD_FOREMAN_DATA_REQUEST,
29
- LOAD_FOREMAN_DATA_SUCCESS,
30
- LOAD_FOREMAN_DATA_FAILURE,
16
+ PARAMETER_SELECTION_INIT,
17
+ PARAMETER_SELECTION_TYPES,
18
+ PARAMETER_SELECTION_LOCK,
19
+ PARAMETER_SELECTION_DELETE,
20
+ PARAMETER_SELECTION_ADD,
21
+ PARAMETER_SELECTION_EDIT_ACTIVATE,
22
+ PARAMETER_SELECTION_EDIT_CONFIRM,
23
+ PARAMETER_SELECTION_EDIT_CHANGE,
24
+ PARAMETER_SELECTION_EDIT_CANCEL,
25
+ PARAMETER_SELECTION_SORT,
26
+ PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
27
+ PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
28
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST,
29
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS,
30
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE,
31
31
  } from './ParameterSelectionConstants';
32
32
 
33
+ import {
34
+ APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE,
35
+ } from '../ApplicationDefinition/ApplicationDefinitionConstants';
36
+
33
37
  export const initialState = Immutable({
34
38
  editMode: false,
35
39
  error: { errorMsg: '', status: '', statusText: '' },
@@ -39,83 +43,97 @@ const parameterSelectionParameters = (state = initialState, action) => {
39
43
  const { payload } = action;
40
44
 
41
45
  switch (action.type) {
42
- case INIT_PARAMETER_SELECTION: {
46
+ case PARAMETER_SELECTION_INIT: {
43
47
  return state.merge(payload);
44
48
  }
45
- case PARAMETER_ADD: {
46
- var rows = [];
47
- var index = 0;
49
+ case PARAMETER_SELECTION_ADD: {
50
+ let parameters = [];
51
+ let index = 1;
48
52
 
49
- if ('rows' in state && state.rows !== undefined && state.rows.length > 0) {
50
- rows = cloneDeep(state.rows);
51
- index = Math.max(...rows.map(e => e.id)) + 1;
53
+ if ('parameters' in state && state.parameters !== undefined && state.parameters.length > 0) {
54
+ parameters = cloneDeep(state.parameters);
55
+ index = Math.max(...parameters.map(e => e.id)) + 1;
52
56
  }
53
57
 
54
- const newRow = {id: index, name: "", description: '', type: '', value: '', newEntry: true };
58
+ const newRow = {id: index, locked: false, name: "", description: '', type: '', value: '', newEntry: true };
55
59
  newRow.backup = cloneDeep(newRow)
56
- rows.push(newRow);
60
+ parameters.push(newRow);
57
61
 
58
62
  return state.merge({
59
63
  editMode: true,
60
- rows: rows
64
+ parameters: parameters
61
65
  });
62
66
  }
63
- case PARAMETER_DELETE: {
64
- var rows = state.rows.filter(v => v.id !== payload.rowData.id);
67
+ case PARAMETER_SELECTION_LOCK: {
68
+ const parameters = cloneDeep(state.parameters);
69
+ const index = findIndex(parameters, { id: payload.rowData.id });
70
+
71
+ if (parameters[index].locked !== undefined) {
72
+ parameters[index].locked = !parameters[index].locked;
73
+ } else {
74
+ parameters[index].locked = true;
75
+ }
76
+
65
77
  return state.merge({
66
- rows: rows,
67
- parameterTypes: filterUsedParameterTypes(PARAMETER_TYPES, rows),
78
+ parameters: parameters
79
+ });
80
+ }
81
+ case PARAMETER_SELECTION_DELETE: {
82
+ const parameters = state.parameters.filter(v => v.id !== payload.rowData.id);
83
+ return state.merge({
84
+ parameters: parameters,
85
+ parameterTypes: filterUsedParameterTypes(PARAMETER_SELECTION_TYPES, parameters),
68
86
  })
69
87
  }
70
- case PARAMETER_EDIT_ACTIVATE: {
71
- const rows = cloneDeep(state.rows);
72
- const index = findIndex(rows, { id: payload.rowData.id });
88
+ case PARAMETER_SELECTION_EDIT_ACTIVATE: {
89
+ const parameters = cloneDeep(state.parameters);
90
+ const index = findIndex(parameters, { id: payload.rowData.id });
73
91
 
74
- rows[index].backup = cloneDeep(rows[index]);
92
+ parameters[index].backup = cloneDeep(parameters[index]);
75
93
 
76
94
  return state.merge({
77
95
  editMode: true,
78
- rows: rows
96
+ parameters: parameters
79
97
  });
80
98
  }
81
- case PARAMETER_EDIT_CONFIRM: {
82
- const rows = cloneDeep(state.rows);
83
- const index = findIndex(rows, { id: payload.rowData.id });
99
+ case PARAMETER_SELECTION_EDIT_CONFIRM: {
100
+ const parameters = cloneDeep(state.parameters);
101
+ const index = findIndex(parameters, { id: payload.rowData.id });
84
102
 
85
- delete rows[index].backup;
86
- delete rows[index].newEntry;
103
+ delete parameters[index].backup;
104
+ delete parameters[index].newEntry;
87
105
 
88
106
  return state.merge({
89
107
  editMode: false,
90
- parameterTypes: filterUsedParameterTypes(PARAMETER_TYPES, rows),
91
- rows: rows
108
+ parameterTypes: filterUsedParameterTypes(PARAMETER_SELECTION_TYPES, parameters),
109
+ parameters: parameters
92
110
  });
93
111
  }
94
- case PARAMETER_EDIT_CHANGE: {
95
- const rows = cloneDeep(state.rows);
96
- const index = findIndex(rows, { id: payload.rowData.id });
112
+ case PARAMETER_SELECTION_EDIT_CHANGE: {
113
+ const parameters = cloneDeep(state.parameters);
114
+ const index = findIndex(parameters, { id: payload.rowData.id });
97
115
 
98
- rows[index][payload.property] = payload.value;
116
+ parameters[index][payload.property] = payload.value;
99
117
 
100
- return state.set('rows', rows);
118
+ return state.set('parameters', parameters);
101
119
  }
102
- case PARAMETER_EDIT_CANCEL: {
103
- const rows = cloneDeep(state.rows);
104
- const index = findIndex(rows, { id: payload.rowData.id });
120
+ case PARAMETER_SELECTION_EDIT_CANCEL: {
121
+ const parameters = cloneDeep(state.parameters);
122
+ const index = findIndex(parameters, { id: payload.rowData.id });
105
123
 
106
- rows[index] = cloneDeep(rows[index].backup);
107
- delete rows[index].backup;
124
+ parameters[index] = cloneDeep(parameters[index].backup);
125
+ delete parameters[index].backup;
108
126
 
109
- if (rows[index].newEntry === true) {
110
- rows.splice(index, 1);
127
+ if (parameters[index].newEntry === true) {
128
+ parameters.splice(index, 1);
111
129
  }
112
130
 
113
131
  return state.merge({
114
132
  editMode: false,
115
- rows: rows
133
+ parameters: parameters
116
134
  });
117
135
  }
118
- case PARAMETER_SORT: {
136
+ case PARAMETER_SELECTION_SORT: {
119
137
  const selectedColumn = payload.selectedColumn;
120
138
  return state.set(
121
139
  'sortingColumns',
@@ -126,45 +144,59 @@ const parameterSelectionParameters = (state = initialState, action) => {
126
144
  })
127
145
  );
128
146
  }
129
- case LOAD_PARAMETER_SELECTION_FAILURE: {
130
- return state.merge({ error: payload.error, loading: false });
131
- }
132
- case LOAD_PARAMETER_SELECTION_REQUEST: {
133
- return state.set('loading', true);
134
- }
135
- case LOAD_PARAMETER_SELECTION_SUCCESS: {
136
- return state.merge({
137
- appDefinition: payload.app_definition,
138
- loading: false,
139
- rows: JSON.parse(payload.app_definition.parameters),
140
- hostgroupId: payload.app_definition.hostgroup_id,
141
- foremanData: payload.fdata,
142
- });
143
- }
144
- case LOAD_FOREMAN_DATA_FAILURE: {
147
+ case PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE: {
145
148
  return state.merge({
146
149
  error: payload.error,
147
150
  loading: false
148
151
  });
149
152
  }
150
- case LOAD_FOREMAN_DATA_REQUEST: {
151
- var newState = {
152
- foremanData: {},
153
- hostgroupId: -1,
154
- loading: true
155
- };
156
-
157
- if (payload.clearRows === true) {
158
- Object.assign(newState, { rows: [] });
153
+ case PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST: {
154
+ let newState = {};
155
+
156
+ if (payload.dataType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) {
157
+ newState = {
158
+ paramData: {},
159
+ hostgroupId: -1,
160
+ loading: true
161
+ };
162
+ } else if (payload.dataType == PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE) {
163
+ newState = {
164
+ loading: true
165
+ };
166
+ }
167
+
168
+ if (payload.clearParameters === true) {
169
+ Object.assign(newState, { parameters: [] });
170
+ }
171
+
172
+ return state.merge(newState);
173
+ }
174
+ case PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS: {
175
+ let newState = {};
176
+
177
+ if (payload.dataType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) {
178
+ newState = {
179
+ loading: false,
180
+ paramData: payload,
181
+ hostgroupId: payload.hostgroup_id,
182
+ };
159
183
  }
160
184
 
161
185
  return state.merge(newState);
162
186
  }
163
- case LOAD_FOREMAN_DATA_SUCCESS: {
187
+ case APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE: {
188
+ const parameters = cloneDeep(state.parameters);
189
+
190
+ parameters.forEach((param, index) => {
191
+ delete parameters[index].backup;
192
+ if (parameters[index].newEntry === true) {
193
+ parameters.splice(index, 1);
194
+ }
195
+ });
196
+
164
197
  return state.merge({
165
- loading: false,
166
- foremanData: payload,
167
- hostgroupId: payload.hostgroup_id,
198
+ editMode: false,
199
+ parameters: parameters
168
200
  });
169
201
  }
170
202
  default: