foreman_ansible 6.2.0 → 6.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ansible_roles_controller.rb +12 -8
- data/app/controllers/ansible_variables_controller.rb +4 -0
- data/app/controllers/api/v2/ansible_roles_controller.rb +32 -11
- data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
- data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
- data/app/helpers/foreman_ansible/ansible_reports_helper.rb +8 -0
- data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
- data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
- data/app/jobs/sync_roles_and_variables.rb +20 -0
- data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +7 -4
- data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +7 -4
- data/app/models/foreman_ansible/ansible_provider.rb +2 -1
- data/app/models/host_ansible_role.rb +1 -0
- data/app/models/hostgroup_ansible_role.rb +1 -0
- data/app/models/setting/ansible.rb +9 -0
- data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
- data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
- data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
- data/app/services/foreman_ansible/fact_parser.rb +21 -1
- data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
- data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
- data/app/services/foreman_ansible/inventory_creator.rb +3 -7
- data/app/services/foreman_ansible/roles_importer.rb +3 -2
- data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
- data/app/services/foreman_ansible/variables_importer.rb +32 -2
- data/app/views/ansible_roles/import.html.erb +10 -50
- data/app/views/ansible_variables/index.html.erb +1 -2
- data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
- data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +1 -2
- data/app/views/foreman_ansible/config_reports/_ansible.html.erb +13 -6
- data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
- data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
- data/config/routes.rb +5 -4
- data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
- data/db/seeds.d/100_common_parameters.rb +7 -0
- data/db/seeds.d/90_notification_blueprints.rb +19 -1
- data/lib/foreman_ansible/engine.rb +1 -0
- data/lib/foreman_ansible/register.rb +5 -5
- data/lib/foreman_ansible/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ca/foreman_ansible.po +1 -1
- data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/cs_CZ/foreman_ansible.po +1 -1
- data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/de/foreman_ansible.po +1 -1
- data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en/foreman_ansible.po +1 -1
- data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en_GB/foreman_ansible.po +1 -1
- data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/es/foreman_ansible.po +1 -1
- data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/fr/foreman_ansible.po +1 -1
- data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/gl/foreman_ansible.po +1 -1
- data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/it/foreman_ansible.po +1 -1
- data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ja/foreman_ansible.po +1 -1
- data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ko/foreman_ansible.po +1 -1
- data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/nl_NL/foreman_ansible.po +1 -1
- data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pl/foreman_ansible.po +1 -1
- data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pt_BR/foreman_ansible.po +1 -1
- data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ru/foreman_ansible.po +1 -1
- data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/sv_SE/foreman_ansible.po +1 -1
- data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_CN/foreman_ansible.po +1 -1
- data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_TW/foreman_ansible.po +1 -1
- data/test/factories/ansible_roles.rb +12 -0
- data/test/factories/host_ansible_enhancements.rb +23 -0
- data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
- data/test/functional/ansible_variables_controller_test.rb +0 -15
- data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
- data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
- data/test/functional/api/v2/hosts_controller_test.rb +9 -8
- data/test/functional/hosts_controller_test.rb +10 -6
- data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
- data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
- data/test/unit/host_ansible_role_test.rb +2 -1
- data/test/unit/hostgroup_ansible_role_test.rb +2 -1
- data/test/unit/ignore_roles_test.rb +43 -0
- data/test/unit/import_roles_and_variables.rb +60 -0
- data/test/unit/services/api_roles_importer_test.rb +22 -5
- data/test/unit/services/fact_parser_test.rb +16 -0
- data/test/unit/services/inventory_creator_test.rb +15 -7
- data/test/unit/services/ui_roles_importer_test.rb +2 -2
- data/webpack/__mocks__/foremanReact/common/helpers.js +13 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/OrderableSelect/helpers.js +5 -0
- data/webpack/__mocks__/foremanReact/redux/API.js +7 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
- data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +14 -18
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +6 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
- data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +2 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +0 -8
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +2 -15
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -9
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +3 -0
- data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
- data/webpack/components/AnsibleRolesSwitcher/index.js +3 -7
- data/webpack/index.js +6 -0
- metadata +55 -9
- data/app/views/ansible_variables/import.html.erb +0 -56
data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
|
2
|
+
import ImportRolesAndVariablesTable from '../AnsibleRolesAndVariables';
|
3
|
+
|
4
|
+
const rowsData = [
|
5
|
+
{
|
6
|
+
cells: [
|
7
|
+
'bennojoy.ntp',
|
8
|
+
'Update Role Variables',
|
9
|
+
'Add: 1 Remove: 2 ',
|
10
|
+
'',
|
11
|
+
'',
|
12
|
+
],
|
13
|
+
kind: 'old',
|
14
|
+
id: 'bennojoy.ntp',
|
15
|
+
},
|
16
|
+
{
|
17
|
+
cells: ['0ta2.git_role', 'Import Role ', 'Add: 5 ', '', ''],
|
18
|
+
kind: 'new',
|
19
|
+
id: '0ta2.git_role',
|
20
|
+
},
|
21
|
+
];
|
22
|
+
|
23
|
+
const columnsData = [
|
24
|
+
{ title: 'Name' },
|
25
|
+
{ title: 'Operation' },
|
26
|
+
{ title: 'Variables' },
|
27
|
+
{ title: 'Hosts Count' },
|
28
|
+
{ title: 'Hostgroups count' },
|
29
|
+
];
|
30
|
+
|
31
|
+
const fixtures = {
|
32
|
+
'should render': {
|
33
|
+
rowsData,
|
34
|
+
columnsData,
|
35
|
+
},
|
36
|
+
};
|
37
|
+
|
38
|
+
describe('ImportRolesAndVariablesTable', () =>
|
39
|
+
testComponentSnapshotsWithFixtures(ImportRolesAndVariablesTable, fixtures));
|
@@ -0,0 +1,177 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`ImportRolesAndVariablesTable should render 1`] = `
|
4
|
+
<div
|
5
|
+
id="import-ansible-roles-variables"
|
6
|
+
>
|
7
|
+
<Toolbar>
|
8
|
+
<ToolbarContent
|
9
|
+
isExpanded={false}
|
10
|
+
showClearFiltersButton={false}
|
11
|
+
>
|
12
|
+
<ForwardRef
|
13
|
+
variant="icon-button-group"
|
14
|
+
>
|
15
|
+
<ToolbarItem>
|
16
|
+
<Checkbox
|
17
|
+
aria-label="select all checkbox"
|
18
|
+
className=""
|
19
|
+
id="select-all"
|
20
|
+
isChecked={false}
|
21
|
+
isDisabled={false}
|
22
|
+
isValid={true}
|
23
|
+
label="Select all"
|
24
|
+
name="select-all"
|
25
|
+
onChange={[Function]}
|
26
|
+
/>
|
27
|
+
</ToolbarItem>
|
28
|
+
</ForwardRef>
|
29
|
+
</ToolbarContent>
|
30
|
+
</Toolbar>
|
31
|
+
<Table
|
32
|
+
aria-label="import roles and variables"
|
33
|
+
borders={true}
|
34
|
+
canSelectAll={false}
|
35
|
+
canSortFavorites={true}
|
36
|
+
cells={
|
37
|
+
Array [
|
38
|
+
Object {
|
39
|
+
"title": "Name",
|
40
|
+
"transforms": Array [
|
41
|
+
[Function],
|
42
|
+
],
|
43
|
+
},
|
44
|
+
Object {
|
45
|
+
"title": "Operation",
|
46
|
+
"transforms": Array [
|
47
|
+
[Function],
|
48
|
+
],
|
49
|
+
},
|
50
|
+
Object {
|
51
|
+
"title": "Variables",
|
52
|
+
"transforms": Array [
|
53
|
+
[Function],
|
54
|
+
],
|
55
|
+
},
|
56
|
+
Object {
|
57
|
+
"title": "Hosts Count",
|
58
|
+
"transforms": Array [
|
59
|
+
[Function],
|
60
|
+
],
|
61
|
+
},
|
62
|
+
Object {
|
63
|
+
"title": "Hostgroups count",
|
64
|
+
"transforms": Array [
|
65
|
+
[Function],
|
66
|
+
],
|
67
|
+
},
|
68
|
+
]
|
69
|
+
}
|
70
|
+
className=""
|
71
|
+
contentId="expanded-content"
|
72
|
+
dropdownDirection="down"
|
73
|
+
dropdownPosition="right"
|
74
|
+
expandId="expandable-toggle"
|
75
|
+
gridBreakPoint="grid-md"
|
76
|
+
isStickyHeader={false}
|
77
|
+
onSelect={[Function]}
|
78
|
+
ouiaSafe={true}
|
79
|
+
role="grid"
|
80
|
+
rowLabeledBy="simple-node"
|
81
|
+
rows={
|
82
|
+
Array [
|
83
|
+
Object {
|
84
|
+
"cells": Array [
|
85
|
+
"bennojoy.ntp",
|
86
|
+
"Update Role Variables",
|
87
|
+
"Add: 1 Remove: 2 ",
|
88
|
+
"",
|
89
|
+
"",
|
90
|
+
],
|
91
|
+
"id": "bennojoy.ntp",
|
92
|
+
"kind": "old",
|
93
|
+
},
|
94
|
+
Object {
|
95
|
+
"cells": Array [
|
96
|
+
"0ta2.git_role",
|
97
|
+
"Import Role ",
|
98
|
+
"Add: 5 ",
|
99
|
+
"",
|
100
|
+
"",
|
101
|
+
],
|
102
|
+
"id": "0ta2.git_role",
|
103
|
+
"kind": "new",
|
104
|
+
},
|
105
|
+
]
|
106
|
+
}
|
107
|
+
selectVariant="checkbox"
|
108
|
+
variant={null}
|
109
|
+
>
|
110
|
+
<TableHeader />
|
111
|
+
<Component />
|
112
|
+
</Table>
|
113
|
+
<Pagination
|
114
|
+
className=""
|
115
|
+
defaultToFullPage={true}
|
116
|
+
firstPage={1}
|
117
|
+
isCompact={true}
|
118
|
+
isDisabled={false}
|
119
|
+
isSticky={false}
|
120
|
+
itemCount={2}
|
121
|
+
itemsEnd={null}
|
122
|
+
itemsStart={null}
|
123
|
+
offset={0}
|
124
|
+
onFirstClick={[Function]}
|
125
|
+
onLastClick={[Function]}
|
126
|
+
onNextClick={[Function]}
|
127
|
+
onPageInput={[Function]}
|
128
|
+
onPerPageSelect={[Function]}
|
129
|
+
onPreviousClick={[Function]}
|
130
|
+
onSetPage={[Function]}
|
131
|
+
ouiaSafe={true}
|
132
|
+
page={0}
|
133
|
+
perPage={5}
|
134
|
+
perPageOptions={
|
135
|
+
Array [
|
136
|
+
Object {
|
137
|
+
"title": "3",
|
138
|
+
"value": 3,
|
139
|
+
},
|
140
|
+
Object {
|
141
|
+
"title": "5",
|
142
|
+
"value": 5,
|
143
|
+
},
|
144
|
+
Object {
|
145
|
+
"title": "10",
|
146
|
+
"value": 10,
|
147
|
+
},
|
148
|
+
]
|
149
|
+
}
|
150
|
+
titles={
|
151
|
+
Object {
|
152
|
+
"paginationTitle": "top pagination",
|
153
|
+
}
|
154
|
+
}
|
155
|
+
toggleTemplate={[Function]}
|
156
|
+
variant="top"
|
157
|
+
widgetId="pagination-options-menu"
|
158
|
+
/>
|
159
|
+
<div
|
160
|
+
className="submit-cancel-btns"
|
161
|
+
>
|
162
|
+
<br />
|
163
|
+
<br />
|
164
|
+
<Button
|
165
|
+
onClick={[Function]}
|
166
|
+
variant="primary"
|
167
|
+
>
|
168
|
+
Submit
|
169
|
+
</Button>
|
170
|
+
<Button
|
171
|
+
variant="secondary"
|
172
|
+
>
|
173
|
+
Cancel
|
174
|
+
</Button>
|
175
|
+
</div>
|
176
|
+
</div>
|
177
|
+
`;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { useDispatch } from 'react-redux';
|
3
|
+
import { push } from 'connected-react-router';
|
4
|
+
|
5
|
+
import ImportRolesAndVariablesTable from './AnsibleRolesAndVariables';
|
6
|
+
import { onSubmit } from './AnsibleRolesAndVariablesActions';
|
7
|
+
import { ANSIBLE_ROLES_INDEX } from './AnsibleRolesAndVariablesConstants';
|
8
|
+
|
9
|
+
const WrappedImportRolesAndVariables = props => {
|
10
|
+
const cols = [
|
11
|
+
{ title: 'Name' },
|
12
|
+
{ title: 'Operation' },
|
13
|
+
{ title: 'Variables' },
|
14
|
+
{ title: 'Hosts Count' },
|
15
|
+
{ title: 'Hostgroups count' },
|
16
|
+
];
|
17
|
+
const dispatch = useDispatch();
|
18
|
+
const submit = (rows, proxy) => dispatch(onSubmit(rows, proxy));
|
19
|
+
const onCancel = () => {
|
20
|
+
dispatch(push(ANSIBLE_ROLES_INDEX));
|
21
|
+
};
|
22
|
+
return (
|
23
|
+
<ImportRolesAndVariablesTable
|
24
|
+
{...props}
|
25
|
+
columnsData={cols}
|
26
|
+
onSubmit={submit}
|
27
|
+
onCancel={onCancel}
|
28
|
+
/>
|
29
|
+
);
|
30
|
+
};
|
31
|
+
export default WrappedImportRolesAndVariables;
|
@@ -7,6 +7,7 @@ import { translate as __ } from 'foremanReact/common/I18n';
|
|
7
7
|
import AvailableRolesList from './components/AvailableRolesList';
|
8
8
|
import AssignedRolesList from './components/AssignedRolesList';
|
9
9
|
import AnsibleRolesSwitcherError from './components/AnsibleRolesSwitcherError';
|
10
|
+
import OrderedRolesTooltip from './components/OrderedRolesTooltip';
|
10
11
|
import { excludeAssignedRolesSearch } from './AnsibleRolesSwitcherHelpers';
|
11
12
|
|
12
13
|
class AnsibleRolesSwitcher extends React.Component {
|
@@ -37,13 +38,11 @@ class AnsibleRolesSwitcher extends React.Component {
|
|
37
38
|
itemCount,
|
38
39
|
addAnsibleRole,
|
39
40
|
removeAnsibleRole,
|
41
|
+
moveAnsibleRole,
|
40
42
|
getAnsibleRoles,
|
41
|
-
changeAssignedPage,
|
42
|
-
assignedPagination,
|
43
|
-
assignedRolesCount,
|
44
43
|
assignedRoles,
|
45
|
-
allAssignedRoles,
|
46
44
|
unassignedRoles,
|
45
|
+
toDestroyRoles,
|
47
46
|
error,
|
48
47
|
} = this.props;
|
49
48
|
|
@@ -57,12 +56,12 @@ class AnsibleRolesSwitcher extends React.Component {
|
|
57
56
|
const onListingChange = paginationArgs =>
|
58
57
|
getAnsibleRoles(
|
59
58
|
availableRolesUrl,
|
60
|
-
|
59
|
+
assignedRoles,
|
61
60
|
inheritedRoleIds,
|
62
61
|
resourceId,
|
63
62
|
resourceName,
|
64
63
|
paginationArgs,
|
65
|
-
excludeAssignedRolesSearch(
|
64
|
+
excludeAssignedRolesSearch(assignedRoles)
|
66
65
|
);
|
67
66
|
|
68
67
|
return (
|
@@ -85,16 +84,18 @@ class AnsibleRolesSwitcher extends React.Component {
|
|
85
84
|
|
86
85
|
<Col sm={6} className="assigned-roles-container">
|
87
86
|
<div className="assigned-roles-header">
|
88
|
-
<h2>
|
87
|
+
<h2>
|
88
|
+
<OrderedRolesTooltip />
|
89
|
+
{__('Assigned Ansible Roles')}
|
90
|
+
</h2>
|
89
91
|
</div>
|
90
92
|
<AssignedRolesList
|
91
93
|
assignedRoles={assignedRoles}
|
92
|
-
|
93
|
-
pagination={assignedPagination}
|
94
|
-
itemCount={assignedRolesCount}
|
95
|
-
onPaginationChange={changeAssignedPage}
|
94
|
+
unassignedRoles={unassignedRoles}
|
96
95
|
onRemoveRole={removeAnsibleRole}
|
96
|
+
onMoveRole={moveAnsibleRole}
|
97
97
|
resourceName={lowerCase(resourceName || '')}
|
98
|
+
toDestroyRoles={toDestroyRoles}
|
98
99
|
/>
|
99
100
|
</Col>
|
100
101
|
</Row>
|
@@ -118,14 +119,9 @@ AnsibleRolesSwitcher.propTypes = {
|
|
118
119
|
itemCount: PropTypes.number.isRequired,
|
119
120
|
addAnsibleRole: PropTypes.func.isRequired,
|
120
121
|
removeAnsibleRole: PropTypes.func.isRequired,
|
121
|
-
|
122
|
-
assignedPagination: PropTypes.shape({
|
123
|
-
page: PropTypes.number,
|
124
|
-
perPage: PropTypes.number,
|
125
|
-
}).isRequired,
|
126
|
-
assignedRolesCount: PropTypes.number.isRequired,
|
122
|
+
moveAnsibleRole: PropTypes.func.isRequired,
|
127
123
|
assignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
128
|
-
|
124
|
+
toDestroyRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
129
125
|
unassignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
130
126
|
error: PropTypes.shape({
|
131
127
|
errorMsg: PropTypes.string,
|
@@ -10,6 +10,7 @@ import {
|
|
10
10
|
ANSIBLE_ROLES_FAILURE,
|
11
11
|
ANSIBLE_ROLES_ADD,
|
12
12
|
ANSIBLE_ROLES_REMOVE,
|
13
|
+
ANSIBLE_ROLES_MOVE,
|
13
14
|
ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
14
15
|
} from './AnsibleRolesSwitcherConstants';
|
15
16
|
|
@@ -63,6 +64,11 @@ export const removeAnsibleRole = role => ({
|
|
63
64
|
payload: { role },
|
64
65
|
});
|
65
66
|
|
67
|
+
export const moveAnsibleRole = roles => ({
|
68
|
+
type: ANSIBLE_ROLES_MOVE,
|
69
|
+
payload: { roles },
|
70
|
+
});
|
71
|
+
|
66
72
|
export const changeAssignedPage = pagination => ({
|
67
73
|
type: ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
68
74
|
payload: { pagination },
|
@@ -3,5 +3,4 @@ export const ANSIBLE_ROLES_SUCCESS = 'ANSIBLE_ROLES_SUCCESS';
|
|
3
3
|
export const ANSIBLE_ROLES_FAILURE = 'ANSIBLE_ROLES_FAILURE';
|
4
4
|
export const ANSIBLE_ROLES_ADD = 'ANSIBLE_ROLES_ADD';
|
5
5
|
export const ANSIBLE_ROLES_REMOVE = 'ANSIBLE_ROLES_REMOVE';
|
6
|
-
export const
|
7
|
-
'ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE';
|
6
|
+
export const ANSIBLE_ROLES_MOVE = 'ANSIBLE_ROLE_MOVE';
|
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
ANSIBLE_ROLES_FAILURE,
|
7
7
|
ANSIBLE_ROLES_ADD,
|
8
8
|
ANSIBLE_ROLES_REMOVE,
|
9
|
-
|
9
|
+
ANSIBLE_ROLES_MOVE,
|
10
10
|
} from './AnsibleRolesSwitcherConstants';
|
11
11
|
|
12
12
|
export const initialState = Immutable({
|
@@ -17,12 +17,9 @@ export const initialState = Immutable({
|
|
17
17
|
perPage: 10,
|
18
18
|
},
|
19
19
|
assignedRoles: [],
|
20
|
+
toDestroyRoles: [],
|
20
21
|
inheritedRoleIds: [],
|
21
22
|
results: [],
|
22
|
-
assignedPagination: {
|
23
|
-
page: 1,
|
24
|
-
perPage: 10,
|
25
|
-
},
|
26
23
|
error: { errorMsg: '', status: '', statusText: '' },
|
27
24
|
});
|
28
25
|
|
@@ -49,6 +46,9 @@ const ansibleRoles = (state = initialState, action) => {
|
|
49
46
|
case ANSIBLE_ROLES_ADD:
|
50
47
|
return state.merge({
|
51
48
|
assignedRoles: state.assignedRoles.concat([payload.role]),
|
49
|
+
toDestroyRoles: state.toDestroyRoles.filter(
|
50
|
+
item => item.id !== payload.role.id
|
51
|
+
),
|
52
52
|
itemCount: state.itemCount - 1,
|
53
53
|
});
|
54
54
|
case ANSIBLE_ROLES_REMOVE:
|
@@ -56,11 +56,16 @@ const ansibleRoles = (state = initialState, action) => {
|
|
56
56
|
assignedRoles: Immutable.flatMap(state.assignedRoles, item =>
|
57
57
|
item.id === payload.role.id ? [] : item
|
58
58
|
),
|
59
|
-
results: state.results.
|
59
|
+
results: state.results.find(item => payload.role.id === item.id)
|
60
|
+
? state.results
|
61
|
+
: state.results.concat([payload.role]),
|
62
|
+
toDestroyRoles: state.toDestroyRoles.concat([
|
63
|
+
{ ...payload.role, destroy: true },
|
64
|
+
]),
|
60
65
|
itemCount: state.itemCount + 1,
|
61
66
|
});
|
62
|
-
case
|
63
|
-
return state.set('
|
67
|
+
case ANSIBLE_ROLES_MOVE:
|
68
|
+
return state.set('assignedRoles', payload.roles);
|
64
69
|
default:
|
65
70
|
return state;
|
66
71
|
}
|
@@ -1,16 +1,7 @@
|
|
1
|
-
import { differenceBy,
|
1
|
+
import { differenceBy, includes } from 'lodash';
|
2
2
|
import Immutable from 'seamless-immutable';
|
3
3
|
import { createSelector } from 'reselect';
|
4
|
-
|
5
|
-
const compare = (a, b) => {
|
6
|
-
if (a.name < b.name) {
|
7
|
-
return -1;
|
8
|
-
}
|
9
|
-
if (a.name > b.name) {
|
10
|
-
return 1;
|
11
|
-
}
|
12
|
-
return 0;
|
13
|
-
};
|
4
|
+
import { propsToCamelCase } from 'foremanReact/common/helpers';
|
14
5
|
|
15
6
|
const switcherState = state => state.foremanAnsible.ansibleRolesSwitcher;
|
16
7
|
|
@@ -21,7 +12,7 @@ const markInheritedRoles = (roles, inheritedRoleIds) =>
|
|
21
12
|
|
22
13
|
export const selectResults = state =>
|
23
14
|
Immutable(
|
24
|
-
Immutable.asMutable(
|
15
|
+
Immutable.asMutable(switcherState(state).results.map(propsToCamelCase))
|
25
16
|
);
|
26
17
|
|
27
18
|
export const selectItemCount = state => switcherState(state).itemCount;
|
@@ -29,16 +20,15 @@ export const selectItemCount = state => switcherState(state).itemCount;
|
|
29
20
|
export const selectAssignedRoles = state =>
|
30
21
|
Immutable.asMutable(
|
31
22
|
markInheritedRoles(
|
32
|
-
switcherState(state).assignedRoles,
|
23
|
+
switcherState(state).assignedRoles.map(propsToCamelCase),
|
33
24
|
switcherState(state).inheritedRoleIds
|
34
25
|
)
|
35
|
-
)
|
26
|
+
);
|
27
|
+
|
28
|
+
export const selectToDestroyRoles = state =>
|
29
|
+
switcherState(state).toDestroyRoles;
|
36
30
|
|
37
|
-
export const selectAssignedRolesCount = state =>
|
38
|
-
selectAssignedRoles(state).length;
|
39
31
|
export const selectLoading = state => switcherState(state).loading;
|
40
|
-
export const selectAssignedPagination = state =>
|
41
|
-
switcherState(state).assignedPagination;
|
42
32
|
export const selectError = state => switcherState(state).error;
|
43
33
|
export const selectPagination = state => switcherState(state).pagination;
|
44
34
|
|
@@ -56,13 +46,3 @@ export const selectUnassignedRoles = createSelector(
|
|
56
46
|
selectAssignedRoles,
|
57
47
|
(results, assignedRoles) => differenceBy(results, assignedRoles, 'id')
|
58
48
|
);
|
59
|
-
|
60
|
-
export const selectAssignedRolesPage = createSelector(
|
61
|
-
selectAssignedPagination,
|
62
|
-
selectAssignedRoles,
|
63
|
-
(assignedPagination, assignedRoles) => {
|
64
|
-
const offset = (assignedPagination.page - 1) * assignedPagination.perPage;
|
65
|
-
|
66
|
-
return slice(assignedRoles, offset, offset + assignedPagination.perPage);
|
67
|
-
}
|
68
|
-
);
|