foreman_acd 0.0.3 → 0.3.0

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