foreman_acd 0.2.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -56
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +199 -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 +1 -0
  6. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +62 -0
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +19 -10
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +111 -137
  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 +62 -0
  13. data/app/controllers/ui_acd_controller.rb +20 -3
  14. data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +47 -0
  15. data/app/lib/actions/foreman_acd/run_configurator.rb +44 -0
  16. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +51 -0
  17. data/app/models/foreman_acd/acd_provider.rb +36 -0
  18. data/app/models/foreman_acd/ansible_playbook.rb +68 -0
  19. data/app/models/foreman_acd/app_definition.rb +25 -0
  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/acd_proxy_proxy_selector.rb +17 -0
  24. data/app/services/foreman_acd/app_configurator.rb +98 -0
  25. data/app/services/foreman_acd/app_deployer.rb +157 -0
  26. data/app/services/foreman_acd/inventory_creator.rb +68 -0
  27. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +64 -0
  28. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +11 -0
  29. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  30. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  31. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +5 -0
  32. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +5 -0
  33. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +9 -0
  34. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +5 -0
  35. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +5 -0
  36. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +9 -0
  37. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +5 -0
  38. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +5 -0
  39. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +5 -0
  40. data/app/views/foreman_acd/app_definitions/_form.html.erb +34 -12
  41. data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -0
  42. data/app/views/foreman_acd/app_definitions/index.html.erb +4 -4
  43. data/app/views/foreman_acd/app_instances/_form.html.erb +11 -9
  44. data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
  45. data/app/views/foreman_acd/app_instances/index.html.erb +89 -10
  46. data/app/views/foreman_acd/app_instances/report.html.erb +6 -3
  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 +32 -2
  53. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  54. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  55. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +8 -0
  56. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +8 -0
  57. data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
  58. data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
  59. data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
  60. data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
  61. data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
  62. data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
  63. data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
  64. data/db/migrate/20210316151145_add_git_commit_to_ansible_playbooks.rb +8 -0
  65. data/db/migrate/20210503122809_add_git_url_to_ansible_playbooks.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.rb +12 -0
  69. data/lib/foreman_acd/engine.rb +43 -3
  70. data/lib/foreman_acd/plugin.rb +88 -22
  71. data/lib/foreman_acd/version.rb +1 -1
  72. data/lib/tasks/foreman_acd_tasks.rake +0 -12
  73. data/locale/en/foreman_acd.edit.po +326 -0
  74. data/locale/en/foreman_acd.po +232 -2
  75. data/locale/en/foreman_acd.po.time_stamp +0 -0
  76. data/locale/foreman_acd.pot +343 -8
  77. data/package.json +9 -9
  78. data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
  79. data/test/controllers/app_instances_controller_test.rb +8 -3
  80. data/test/controllers/ui_acd_controller_test.rb +22 -6
  81. data/test/factories/foreman_acd_factories.rb +18 -4
  82. data/test/models/acd_provider_test.rb +37 -0
  83. data/test/models/ansible_playbook_test.rb +11 -0
  84. data/test/models/app_definition_test.rb +1 -1
  85. data/test/models/app_instance_test.rb +2 -0
  86. data/test/models/concerns/host_extensions_test.rb +26 -0
  87. data/test/models/foreman_host_test.rb +12 -0
  88. data/webpack/__mocks__/foremanReact/API.js +2 -0
  89. data/webpack/__mocks__/foremanReact/common/I18n.js +3 -0
  90. data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
  91. data/webpack/__mocks__/foremanReact/components/ForemanModal.js +7 -0
  92. data/webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js +2 -0
  93. data/webpack/__mocks__/foremanReact/components/common/forms/TextInput.js +2 -0
  94. data/webpack/__mocks__/foremanReact/components/hosts/powerStatus.js +1 -0
  95. data/webpack/__snapshots__/helper.test.js.snap +14 -0
  96. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +159 -29
  97. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +106 -14
  98. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +8 -2
  99. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  100. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +143 -21
  101. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +3 -0
  102. data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionConfData_1.fixtures.js +288 -0
  103. data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionReducer.fixtures.js +79 -0
  104. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +25 -0
  105. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionReducer.test.js +119 -0
  106. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +41 -0
  107. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +200 -0
  108. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionReducer.test.js.snap +3033 -0
  109. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +299 -0
  110. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +50 -0
  111. data/webpack/components/ApplicationDefinition/components/__tests__/AnsiblePlaybookSelector.test.js +41 -0
  112. data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +121 -0
  113. data/webpack/components/ApplicationDefinition/index.js +6 -0
  114. data/webpack/components/ApplicationInstance/ApplicationInstance.js +151 -44
  115. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +47 -10
  116. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +5 -2
  117. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +114 -28
  118. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +3 -1
  119. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceConfData_1.fixtures.js +263 -0
  120. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +78 -0
  121. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +23 -0
  122. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +119 -0
  123. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +44 -0
  124. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +209 -0
  125. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +2719 -0
  126. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +276 -0
  127. data/webpack/components/ApplicationInstance/components/Service.js +1 -1
  128. data/webpack/components/ApplicationInstance/index.js +4 -0
  129. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +53 -60
  130. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +17 -0
  131. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +7 -51
  132. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -4
  133. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +4 -18
  134. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +0 -1
  135. data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportData_1.fixtures.js +349 -0
  136. data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportReducer.fixtures.js +20 -0
  137. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js +47 -0
  138. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportReducer.test.js +41 -0
  139. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportSelectors.test.js +26 -0
  140. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +130 -0
  141. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap +718 -0
  142. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportSelectors.test.js.snap +347 -0
  143. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +1 -1
  144. data/webpack/components/ApplicationInstanceReport/components/__tests__/ReportViewer.test.js +24 -0
  145. data/webpack/components/ApplicationInstanceReport/components/__tests__/__snapshots__/ReportViewer.test.js.snap +24 -0
  146. data/webpack/components/ApplicationInstanceReport/index.js +0 -2
  147. data/webpack/components/ParameterSelection/ParameterSelection.js +85 -50
  148. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +68 -62
  149. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +6 -3
  150. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +0 -32
  151. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +47 -35
  152. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +2 -2
  153. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +116 -84
  154. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +10 -4
  155. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +36 -46
  156. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +31 -25
  157. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  158. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +2 -126
  159. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +1483 -872
  160. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +117 -79
  161. data/webpack/components/ParameterSelection/index.js +4 -4
  162. data/webpack/components/SyncGitRepo/SyncGitRepo.js +210 -0
  163. data/webpack/components/SyncGitRepo/SyncGitRepo.scss +1 -0
  164. data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +124 -0
  165. data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +9 -0
  166. data/webpack/components/SyncGitRepo/SyncGitRepoReducer.js +80 -0
  167. data/webpack/components/SyncGitRepo/SyncGitRepoSelectors.js +6 -0
  168. data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoConfData_1.fixtures.js +7 -0
  169. data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoReducer.fixtures.js +44 -0
  170. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepo.test.js +27 -0
  171. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoReducer.test.js +95 -0
  172. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoSelectors.test.js +32 -0
  173. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +30 -0
  174. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoReducer.test.js.snap +137 -0
  175. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoSelectors.test.js.snap +13 -0
  176. data/webpack/components/SyncGitRepo/components/FormTextInput.js +42 -0
  177. data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +46 -0
  178. data/webpack/components/SyncGitRepo/index.js +28 -0
  179. data/webpack/components/common/DeleteTableEntry.js +3 -3
  180. data/webpack/components/common/EditTableEntry.js +50 -0
  181. data/webpack/components/common/ExtTextInput.js +43 -0
  182. data/webpack/components/common/LockTableEntry.js +60 -0
  183. data/webpack/components/common/__tests__/EditTableEntry.test.js +53 -0
  184. data/webpack/components/common/__tests__/LockTableEntry.test.js +35 -0
  185. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +2 -2
  186. data/webpack/components/common/__tests__/__snapshots__/EditTableEntry.test.js.snap +81 -0
  187. data/webpack/components/common/__tests__/__snapshots__/LockTableEntry.test.js.snap +60 -0
  188. data/webpack/helper.js +15 -1
  189. data/webpack/helper.test.js +37 -0
  190. data/webpack/index.js +2 -0
  191. data/webpack/reducer.js +18 -11
  192. metadata +184 -10
  193. data/app/views/foreman_acd/app_instances/deploy.html.erb +0 -19
  194. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +0 -35
  195. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +0 -41
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import * as sort from 'sortabular';
3
+ import { translate as __ } from 'foremanReact/common/I18n';
3
4
 
4
5
  import {
5
6
  actionHeaderCellFormatter,
@@ -16,18 +17,13 @@ import {
16
17
  } from 'foremanReact/common/helpers';
17
18
 
18
19
  import {
19
- isNewDefinition,
20
- isEditDefinition,
21
- isDefinition,
22
- isNewInstance,
23
- isEditInstance,
24
- isInstance,
25
20
  filterUsedParameterTypes,
26
21
  } from './ParameterSelectionHelper';
27
22
 
28
23
  import {
29
24
  PARAMETER_SELECTION_INIT,
30
25
  PARAMETER_SELECTION_TYPES,
26
+ PARAMETER_SELECTION_LOCK,
31
27
  PARAMETER_SELECTION_DELETE,
32
28
  PARAMETER_SELECTION_ADD,
33
29
  PARAMETER_SELECTION_EDIT_ACTIVATE,
@@ -35,15 +31,20 @@ import {
35
31
  PARAMETER_SELECTION_EDIT_CHANGE,
36
32
  PARAMETER_SELECTION_EDIT_CANCEL,
37
33
  PARAMETER_SELECTION_SORT,
38
- PARAMETER_SELECTION_LOAD_FOREMAN_DATA_REQUEST,
39
- PARAMETER_SELECTION_LOAD_FOREMAN_DATA_SUCCESS,
40
- PARAMETER_SELECTION_LOAD_FOREMAN_DATA_FAILURE,
34
+ PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
35
+ PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
36
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST,
37
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS,
38
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE,
41
39
  } from './ParameterSelectionConstants';
42
40
 
43
41
  export const initParameterSelection = (
44
- mode,
45
- serviceDefinition,
42
+ paramType,
43
+ paramDefinition,
46
44
  parameters,
45
+ useDefaultValue,
46
+ allowNameAdjustment,
47
+ allowDescriptionAdjustment,
47
48
  sortingFormatter,
48
49
  sortableTransform,
49
50
  inlineEditFormatter,
@@ -57,23 +58,28 @@ export const initParameterSelection = (
57
58
  position: 0
58
59
  }
59
60
  };
60
- initialState.serviceDefinition = serviceDefinition;
61
+ initialState.paramDefinition = paramDefinition;
61
62
 
62
- let valueLabel = 'Value';
63
- if (isDefinition(mode)) {
64
- valueLabel = 'Default value';
63
+ let valueLabel = __('Value');
64
+ if (useDefaultValue) {
65
+ valueLabel = __('Default value');
65
66
  }
66
67
 
67
- initialState.columns = [
68
- {
68
+ initialState.columns = []
69
+ const addToColumns = (obj, idx) => {
70
+ obj.header.props.index = idx;
71
+ initialState.columns.push(obj);
72
+ }
73
+
74
+ let idx = 0;
75
+ addToColumns( {
69
76
  property: 'name',
70
77
  header: {
71
- label: 'Name',
78
+ label: __('Name'),
72
79
  props: {
73
- index: 0,
74
80
  sort: true,
75
81
  style: {
76
- width: '20%'
82
+ width: '25%'
77
83
  }
78
84
  },
79
85
  transforms: [sortableTransform],
@@ -81,18 +87,18 @@ export const initParameterSelection = (
81
87
  customFormatters: [sortableHeaderCellFormatter]
82
88
  },
83
89
  cell: {
84
- formatters: [isDefinition(mode) ? inlineEditFormatter : tableCellFormatter]
90
+ formatters: [allowNameAdjustment ? inlineEditFormatter : tableCellFormatter]
85
91
  }
86
- },
87
- {
92
+ }, idx++);
93
+
94
+ addToColumns( {
88
95
  property: 'description',
89
96
  header: {
90
- label: 'Description',
97
+ label: __('Description'),
91
98
  props: {
92
- index: 1,
93
99
  sort: true,
94
100
  style: {
95
- width: '20%'
101
+ width: '25%'
96
102
  }
97
103
  },
98
104
  transforms: [sortableTransform],
@@ -103,15 +109,16 @@ export const initParameterSelection = (
103
109
  props: {
104
110
  index: 1
105
111
  },
106
- formatters: [isDefinition(mode) ? inlineEditFormatter : tableCellFormatter]
112
+ formatters: [allowDescriptionAdjustment ? inlineEditFormatter : tableCellFormatter]
107
113
  }
108
- },
109
- {
114
+ }, idx++);
115
+
116
+ if (paramType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) {
117
+ addToColumns( {
110
118
  property: 'type',
111
119
  header: {
112
- label: 'Type',
120
+ label: __('Type'),
113
121
  props: {
114
- index: 2,
115
122
  sort: true,
116
123
  style: {
117
124
  width: '20%'
@@ -126,13 +133,14 @@ export const initParameterSelection = (
126
133
  // the well formatted type name is shown
127
134
  formatters: [inlineEditFormatter]
128
135
  }
129
- },
130
- {
136
+ }, idx++);
137
+ }
138
+
139
+ addToColumns( {
131
140
  property: 'value',
132
141
  header: {
133
142
  label: valueLabel,
134
143
  props: {
135
- index: 3,
136
144
  sort: true,
137
145
  style: {
138
146
  width: '20%'
@@ -145,15 +153,15 @@ export const initParameterSelection = (
145
153
  cell: {
146
154
  formatters: [inlineEditFormatter]
147
155
  }
148
- },
149
- {
156
+ }, idx++);
157
+
158
+ addToColumns( {
150
159
  property: 'actions',
151
160
  header: {
152
- label: 'Actions',
161
+ label: __('Actions'),
153
162
  props: {
154
- index: 4,
155
163
  style: {
156
- width: '20%'
164
+ width: '10%'
157
165
  }
158
166
  },
159
167
  formatters: [actionHeaderCellFormatter]
@@ -161,21 +169,11 @@ export const initParameterSelection = (
161
169
  cell: {
162
170
  formatters: [inlineEditButtonsFormatter]
163
171
  }
164
- }
165
- ];
172
+ }, idx++);
166
173
 
167
- if (isNewDefinition(mode)) {
168
- initialState.parameters = [];
169
- } else if ((isEditDefinition(mode)) || (isInstance(mode))) {
170
- initialState.parameters = parameters;
171
- initialState.hostgroupId = serviceDefinition.hostgroup_id;
172
- } else {
173
- // FIXME: should never ever happen
174
- }
174
+ initialState.parameters = parameters;
175
175
 
176
- if (isNewDefinition(mode)) {
177
- initialState.parameterTypes = PARAMETER_SELECTION_TYPES;
178
- } else {
176
+ if ((paramType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) && (parameters)) {
179
177
  initialState.parameterTypes = filterUsedParameterTypes(PARAMETER_SELECTION_TYPES, parameters);
180
178
  }
181
179
 
@@ -187,12 +185,19 @@ export const initParameterSelection = (
187
185
 
188
186
  const errorHandler = (msg, err) => {
189
187
  const error = {
190
- errorMsg: 'Failed to fetch data from server.',
188
+ errorMsg: __('Failed to fetch data from server.'),
191
189
  statusText: err,
192
190
  };
193
191
  return { type: msg, payload: { error } };
194
192
  };
195
193
 
194
+ export const lockParameter = (additionalData) => ({
195
+ type: PARAMETER_SELECTION_LOCK,
196
+ payload: {
197
+ ...additionalData,
198
+ },
199
+ });
200
+
196
201
  export const addParameter = (additionalData) => ({
197
202
  type: PARAMETER_SELECTION_ADD,
198
203
  payload: {
@@ -244,22 +249,23 @@ export const sortParameter = (selectedColumn, defaultSortingOrder) => ({
244
249
  },
245
250
  });
246
251
 
247
- export const loadForemanData = (
248
- hostgroupId,
249
- additionalData,
250
- ) => dispatch => {
251
- dispatch({ type: PARAMETER_SELECTION_LOAD_FOREMAN_DATA_REQUEST, payload: { clearParameters: additionalData.clearParameters } });
252
+ export const loadParamData = (attr) => dispatch => {
253
+ dispatch( { type: PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST, payload: { dataType: attr.dataType, clearParameters: attr.clearParameters } });
252
254
 
253
- const realUrl = additionalData.url.replace("__id__", hostgroupId);
255
+ let realUrl = attr.url.replace("__id__", attr.paramDefinition.dataId);
256
+
257
+ if (attr.paramDefinition.hasOwnProperty('dataSubId')) {
258
+ realUrl = realUrl.replace("__subid__", attr.paramDefinition.dataSubId);
259
+ }
254
260
 
255
261
  return api
256
262
  .get(realUrl, {}, {})
257
263
  .then(({ data }) =>
258
264
  dispatch({
259
- type: PARAMETER_SELECTION_LOAD_FOREMAN_DATA_SUCCESS,
260
- payload: data,
265
+ type: PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS,
266
+ payload: { ...data, dataType: attr.dataType }
261
267
  })
262
268
  )
263
- .catch(error => dispatch(errorHandler(PARAMETER_SELECTION_LOAD_FOREMAN_DATA_FAILURE, error)));
269
+ .catch(error => dispatch(errorHandler(PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE, error)));
264
270
  };
265
271
 
@@ -1,4 +1,5 @@
1
1
  export const PARAMETER_SELECTION_INIT = 'INIT_PARAMETER_SELECTION_INIT';
2
+ export const PARAMETER_SELECTION_LOCK = 'PARAMETER_SELECTION_LOCK';
2
3
  export const PARAMETER_SELECTION_DELETE = 'PARAMETER_SELECTION_DELETE';
3
4
  export const PARAMETER_SELECTION_ADD = 'PARAMETER_SELECTION_ADD';
4
5
  export const PARAMETER_SELECTION_EDIT_ACTIVATE = 'PARAMETER_SELECTION_EDIT_ACTIVATE';
@@ -6,9 +7,11 @@ export const PARAMETER_SELECTION_EDIT_CONFIRM = 'PARAMETER_SELECTION_EDIT_CONFIR
6
7
  export const PARAMETER_SELECTION_EDIT_CHANGE = 'PARAMETER_SELECTION_EDIT_CHANGE';
7
8
  export const PARAMETER_SELECTION_EDIT_CANCEL = 'PARAMETER_SELECTION_EDIT_CANCEL';
8
9
  export const PARAMETER_SELECTION_SORT = 'PARAMETER_SELECTION_SORT';
9
- export const PARAMETER_SELECTION_LOAD_FOREMAN_DATA_REQUEST = 'PARAMETER_SELECTION_LOAD_FOREMAN_DATA_REQUEST';
10
- export const PARAMETER_SELECTION_LOAD_FOREMAN_DATA_SUCCESS = 'PARAMETER_SELECTION_LOAD_FOREMAN_DATA_SUCCESS';
11
- export const PARAMETER_SELECTION_LOAD_FOREMAN_DATA_FAILURE = 'PARAMETER_SELECTION_LOAD_FOREMAN_DATA_FAILURE';
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';
12
15
 
13
16
  // Make sure the object is sorted by value
14
17
  // (Compute Profile -> Partition table -> Root password)
@@ -2,38 +2,6 @@ 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 "";
@@ -15,6 +15,7 @@ import * as sort from 'sortabular';
15
15
  import {
16
16
  PARAMETER_SELECTION_INIT,
17
17
  PARAMETER_SELECTION_TYPES,
18
+ PARAMETER_SELECTION_LOCK,
18
19
  PARAMETER_SELECTION_DELETE,
19
20
  PARAMETER_SELECTION_ADD,
20
21
  PARAMETER_SELECTION_EDIT_ACTIVATE,
@@ -22,15 +23,13 @@ import {
22
23
  PARAMETER_SELECTION_EDIT_CHANGE,
23
24
  PARAMETER_SELECTION_EDIT_CANCEL,
24
25
  PARAMETER_SELECTION_SORT,
25
- PARAMETER_SELECTION_LOAD_FOREMAN_DATA_REQUEST,
26
- PARAMETER_SELECTION_LOAD_FOREMAN_DATA_SUCCESS,
27
- PARAMETER_SELECTION_LOAD_FOREMAN_DATA_FAILURE,
26
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST,
27
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS,
28
+ PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE,
29
+ PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
30
+ PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
28
31
  } from './ParameterSelectionConstants';
29
32
 
30
- import {
31
- APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE,
32
- } from '../ApplicationDefinition/ApplicationDefinitionConstants';
33
-
34
33
  export const initialState = Immutable({
35
34
  editMode: false,
36
35
  error: { errorMsg: '', status: '', statusText: '' },
@@ -52,7 +51,7 @@ const parameterSelectionParameters = (state = initialState, action) => {
52
51
  index = Math.max(...parameters.map(e => e.id)) + 1;
53
52
  }
54
53
 
55
- const newRow = {id: index, name: "", description: '', type: '', value: '', newEntry: true };
54
+ const newRow = {id: index, locked: false, name: "", description: '', type: '', value: '', newEntry: true };
56
55
  newRow.backup = cloneDeep(newRow)
57
56
  parameters.push(newRow);
58
57
 
@@ -61,6 +60,20 @@ const parameterSelectionParameters = (state = initialState, action) => {
61
60
  parameters: parameters
62
61
  });
63
62
  }
63
+ case PARAMETER_SELECTION_LOCK: {
64
+ const parameters = cloneDeep(state.parameters);
65
+ const index = findIndex(parameters, { id: payload.rowData.id });
66
+
67
+ if (parameters[index].locked !== undefined) {
68
+ parameters[index].locked = !parameters[index].locked;
69
+ } else {
70
+ parameters[index].locked = true;
71
+ }
72
+
73
+ return state.merge({
74
+ parameters: parameters
75
+ });
76
+ }
64
77
  case PARAMETER_SELECTION_DELETE: {
65
78
  const parameters = state.parameters.filter(v => v.id !== payload.rowData.id);
66
79
  return state.merge({
@@ -127,18 +140,26 @@ const parameterSelectionParameters = (state = initialState, action) => {
127
140
  })
128
141
  );
129
142
  }
130
- case PARAMETER_SELECTION_LOAD_FOREMAN_DATA_FAILURE: {
143
+ case PARAMETER_SELECTION_LOAD_PARAM_DATA_FAILURE: {
131
144
  return state.merge({
132
145
  error: payload.error,
133
146
  loading: false
134
147
  });
135
148
  }
136
- case PARAMETER_SELECTION_LOAD_FOREMAN_DATA_REQUEST: {
137
- const newState = {
138
- foremanData: {},
139
- hostgroupId: -1,
140
- loading: true
141
- };
149
+ case PARAMETER_SELECTION_LOAD_PARAM_DATA_REQUEST: {
150
+ let newState = {};
151
+
152
+ if (payload.dataType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) {
153
+ newState = {
154
+ paramData: {},
155
+ hostgroupId: -1,
156
+ loading: true
157
+ };
158
+ } else if (payload.dataType == PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE) {
159
+ newState = {
160
+ loading: true
161
+ };
162
+ }
142
163
 
143
164
  if (payload.clearParameters === true) {
144
165
  Object.assign(newState, { parameters: [] });
@@ -146,27 +167,18 @@ const parameterSelectionParameters = (state = initialState, action) => {
146
167
 
147
168
  return state.merge(newState);
148
169
  }
149
- case PARAMETER_SELECTION_LOAD_FOREMAN_DATA_SUCCESS: {
150
- return state.merge({
151
- loading: false,
152
- foremanData: payload,
153
- hostgroupId: payload.hostgroup_id,
154
- });
155
- }
156
- case APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE: {
157
- const parameters = cloneDeep(state.parameters);
158
-
159
- parameters.forEach((param, index) => {
160
- delete parameters[index].backup;
161
- if (parameters[index].newEntry === true) {
162
- parameters.splice(index, 1);
163
- }
164
- });
170
+ case PARAMETER_SELECTION_LOAD_PARAM_DATA_SUCCESS: {
171
+ let newState = {};
172
+
173
+ if (payload.dataType == PARAMETER_SELECTION_PARAM_TYPE_FOREMAN) {
174
+ newState = {
175
+ loading: false,
176
+ paramData: payload,
177
+ hostgroupId: payload.hostgroup_id,
178
+ };
179
+ }
165
180
 
166
- return state.merge({
167
- editMode: false,
168
- parameters: parameters
169
- });
181
+ return state.merge(newState);
170
182
  }
171
183
  default:
172
184
  return state;
@@ -2,10 +2,10 @@ const parameterState = state => state.foremanAcd.parameterSelectionParameters;
2
2
 
3
3
  export const selectLoading = state => parameterState(state).loading;
4
4
  export const selectEditMode = state => parameterState(state).editMode;
5
- export const selectForemanData = state => parameterState(state).foremanData;
5
+ export const selectParamData = state => parameterState(state).paramData;
6
6
  export const selectParameterTypes = state => parameterState(state).parameterTypes;
7
7
  export const selectParameters = state => parameterState(state).parameters;
8
8
  export const selectSortingColumns = state => parameterState(state).sortingColumns;
9
9
  export const selectColumns = state => parameterState(state).columns;
10
- export const selectServiceDefinition = state => parameterState(state).serviceDefinition;
10
+ export const selectParamDefinition = state => parameterState(state).paramDefinition;
11
11
  export const selectHostgroupId = state => parameterState(state).hostgroupId;