foreman_statistics 0.1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_statistics/api/v2/statistics_controller.rb +9 -1
  3. data/app/controllers/foreman_statistics/api/v2/trends_controller.rb +8 -0
  4. data/app/jobs/foreman_statistics/trend_counter_job.rb +23 -0
  5. data/app/views/foreman_statistics/layouts/application_react.html.erb +1 -2
  6. data/app/views/foreman_statistics/trends/_empty_data.html.erb +0 -1
  7. data/app/views/foreman_statistics/trends/index.html.erb +3 -12
  8. data/app/views/foreman_statistics/trends/welcome.html.erb +1 -1
  9. data/db/migrate/20200605153005_migrate_core_types.rb +6 -2
  10. data/lib/foreman_statistics/engine.rb +13 -1
  11. data/lib/foreman_statistics/version.rb +1 -1
  12. data/lib/tasks/foreman_statistics_tasks.rake +3 -2
  13. data/locale/action_names.rb +5 -0
  14. data/locale/en/LC_MESSAGES/foreman_statistics.mo +0 -0
  15. data/locale/en/foreman_statistics.edit.po +258 -0
  16. data/locale/en/foreman_statistics.po +181 -2
  17. data/locale/en/foreman_statistics.po.time_stamp +0 -0
  18. data/locale/foreman_statistics.pot +265 -8
  19. data/locale/gemspec.rb +1 -1
  20. data/package.json +42 -0
  21. data/test/functional/foreman_statistics/api/v2/statistics_controller_test.rb +1 -1
  22. data/test/functional/foreman_statistics/api/v2/trends_controller_test.rb +1 -1
  23. data/test/functional/foreman_statistics/statistics_controller_test.rb +5 -7
  24. data/test/functional/foreman_statistics/trends_controller_test.rb +3 -3
  25. data/test/models/foreman_statistics/trend_counter_test.rb +1 -1
  26. data/test/models/foreman_statistics/trend_test.rb +1 -1
  27. data/test/{test_plugin_helper.rb → test_statistics_helper.rb} +0 -0
  28. data/test/unit/foreman_statistics/access_permissions_test.rb +1 -1
  29. data/test/unit/foreman_statistics/statistics_test.rb +1 -1
  30. data/test/unit/foreman_statistics_test.rb +1 -1
  31. data/test/unit/tasks/foreman_statistics_tasks_test.rb +1 -1
  32. data/webpack/__mocks__/foremanReact/API.js +7 -0
  33. data/webpack/__mocks__/foremanReact/common/HOC.js +24 -0
  34. data/webpack/__mocks__/foremanReact/common/I18n.js +3 -0
  35. data/webpack/__mocks__/foremanReact/common/helpers.js +1 -0
  36. data/webpack/__mocks__/foremanReact/common/urlHelpers.js +1 -0
  37. data/webpack/__mocks__/foremanReact/components/ChartBox/index.js +2 -0
  38. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
  39. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalHooks.js +10 -0
  40. data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +4 -0
  41. data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +2 -0
  42. data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +2 -0
  43. data/webpack/__mocks__/foremanReact/components/common/EmptyState.js +5 -0
  44. data/webpack/__mocks__/foremanReact/components/common/MessageBox.js +4 -0
  45. data/webpack/__mocks__/foremanReact/components/common/dates/LongDateTime.js +5 -0
  46. data/webpack/__mocks__/foremanReact/components/common/dates/RelativeDateTime.js +3 -0
  47. data/webpack/__mocks__/foremanReact/components/common/table.js +5 -0
  48. data/webpack/__mocks__/foremanReact/components/common/table/actionsHelpers/actionTypeCreator.js +7 -0
  49. data/webpack/__mocks__/foremanReact/constants.js +24 -0
  50. data/webpack/__mocks__/foremanReact/readme.md +11 -0
  51. data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
  52. data/webpack/__mocks__/foremanReact/routes/common/PageLayout/PageLayout.js +10 -0
  53. data/webpack/__mocks__/foremanReact/routes/common/PageLayout/components/ExportButton/ExportButton.js +5 -0
  54. data/webpack/__mocks__/foremanReact/routes/common/reducerHOC/withDataReducer.js +35 -0
  55. data/webpack/fills_index.js +15 -0
  56. data/webpack/index.js +21 -0
  57. data/webpack/src/Components/StatisticsChartsList/StatisticsChartsList.fixtures.js +19 -0
  58. data/webpack/src/Components/StatisticsChartsList/StatisticsChartsList.test.js +18 -0
  59. data/webpack/src/Components/StatisticsChartsList/StatisticsChartsListStyles.scss +28 -0
  60. data/webpack/src/Components/StatisticsChartsList/__snapshots__/StatisticsChartsList.test.js.snap +42 -0
  61. data/webpack/src/Components/StatisticsChartsList/index.js +32 -0
  62. data/webpack/src/ForemanStatistics.js +11 -0
  63. data/webpack/src/Router/StatisticsPage/Statistics/Statistics.js +27 -0
  64. data/webpack/src/Router/StatisticsPage/StatisticsPage.fixtures.js +11 -0
  65. data/webpack/src/Router/StatisticsPage/StatisticsPage.js +21 -0
  66. data/webpack/src/Router/StatisticsPage/StatisticsPageActions.js +43 -0
  67. data/webpack/src/Router/StatisticsPage/StatisticsPageSelectors.js +13 -0
  68. data/webpack/src/Router/StatisticsPage/__tests__/StatisticsPage.test.js +12 -0
  69. data/webpack/src/Router/StatisticsPage/__tests__/StatisticsPageActions.test.js +27 -0
  70. data/webpack/src/Router/StatisticsPage/__tests__/StatisticsPageSelectors.test.js +34 -0
  71. data/webpack/src/Router/StatisticsPage/__tests__/__snapshots__/StatisticsPage.test.js.snap +32 -0
  72. data/webpack/src/Router/StatisticsPage/__tests__/__snapshots__/StatisticsPageActions.test.js.snap +54 -0
  73. data/webpack/src/Router/StatisticsPage/__tests__/__snapshots__/StatisticsPageSelectors.test.js.snap +35 -0
  74. data/webpack/src/Router/StatisticsPage/constants.js +4 -0
  75. data/webpack/src/Router/StatisticsPage/index.js +36 -0
  76. data/webpack/src/Router/__snapshots__/routes.test.js.snap +47 -0
  77. data/webpack/src/Router/index.js +14 -0
  78. data/webpack/src/Router/routes.js +11 -0
  79. data/webpack/src/Router/routes.test.js +27 -0
  80. data/webpack/src/index.js +1 -0
  81. data/webpack/src/reducers.js +9 -0
  82. data/webpack/src/trends.js +7 -0
  83. data/webpack/src/trends.test.js +44 -0
  84. metadata +67 -9
@@ -0,0 +1,4 @@
1
+ export const STATISTICS_PAGE_DATA_RESOLVED = 'STATISTICS_PAGE_DATA_RESOLVED';
2
+ export const STATISTICS_PAGE_DATA_FAILED = 'STATISTICS_PAGE_FETCH_FAILED';
3
+ export const STATISTICS_PAGE_HIDE_LOADING = 'STATISTICS_PAGE_HIDE_LOADING';
4
+ export const STATISTICS_PAGE_URL = '/foreman_statistics/statistics';
@@ -0,0 +1,36 @@
1
+ import { compose, bindActionCreators } from 'redux';
2
+ import { connect } from 'react-redux';
3
+ import { callOnMount } from 'foremanReact/common/HOC';
4
+ import withDataReducer from 'foremanReact/routes/common/reducerHOC/withDataReducer';
5
+
6
+ import * as actions from './StatisticsPageActions';
7
+ import {
8
+ selectStatisticsMetadata,
9
+ selectStatisticsMessage,
10
+ selectStatisticsIsLoading,
11
+ selectStatisticsHasMetadata,
12
+ selectStatisticsHasError,
13
+ } from './StatisticsPageSelectors';
14
+
15
+ import StatisticsPage from './StatisticsPage';
16
+
17
+ // map state to props
18
+ const mapStateToProps = state => ({
19
+ statisticsMeta: selectStatisticsMetadata(state),
20
+ isLoading: selectStatisticsIsLoading(state),
21
+ message: selectStatisticsMessage(state),
22
+ hasData: selectStatisticsHasMetadata(state),
23
+ hasError: selectStatisticsHasError(state),
24
+ });
25
+
26
+ // map action dispatchers to props
27
+ const mapDispatchToProps = dispatch => bindActionCreators(actions, dispatch);
28
+
29
+ // export reducers
30
+ export const reducers = { statisticsPage: withDataReducer('STATISTICS_PAGE') };
31
+
32
+ // export connected component
33
+ export default compose(
34
+ connect(mapStateToProps, mapDispatchToProps),
35
+ callOnMount(({ getStatisticsMeta }) => getStatisticsMeta())
36
+ )(StatisticsPage);
@@ -0,0 +1,47 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ForemanPluginTemplateRoutes should create routes 1`] = `
4
+ Object {
5
+ "statistics": Object {
6
+ "component": Object {
7
+ "$$typeof": Symbol(react.memo),
8
+ "WrappedComponent": [Function],
9
+ "compare": null,
10
+ "displayName": "Connect(Component)",
11
+ "type": [Function],
12
+ },
13
+ "exact": true,
14
+ "path": "/foreman_statistics/statistics",
15
+ "renderResult": <ContextProvider
16
+ value={
17
+ Object {
18
+ "store": Object {
19
+ "dispatch": [MockFunction],
20
+ "getState": [Function],
21
+ "subscribe": [MockFunction],
22
+ },
23
+ "subscription": Subscription {
24
+ "handleChangeWrapper": [Function],
25
+ "listeners": Object {
26
+ "notify": [Function],
27
+ },
28
+ "onStateChange": [Function],
29
+ "parentSub": undefined,
30
+ "store": Object {
31
+ "dispatch": [MockFunction],
32
+ "getState": [Function],
33
+ "subscribe": [MockFunction],
34
+ },
35
+ "unsubscribe": null,
36
+ },
37
+ }
38
+ }
39
+ >
40
+ <Connect(Component)
41
+ history={Object {}}
42
+ some="props"
43
+ />
44
+ </ContextProvider>,
45
+ },
46
+ }
47
+ `;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { Switch, Route } from 'react-router-dom';
3
+
4
+ import routes from './routes';
5
+
6
+ const Router = () => (
7
+ <Switch>
8
+ {Object.entries(routes).map(([key, props]) => (
9
+ <Route key={key} {...props} />
10
+ ))}
11
+ </Switch>
12
+ );
13
+
14
+ export default Router;
@@ -0,0 +1,11 @@
1
+ import StatisticsPage from './StatisticsPage';
2
+
3
+ const routes = {
4
+ statistics: {
5
+ path: '/foreman_statistics/statistics',
6
+ exact: true,
7
+ component: StatisticsPage,
8
+ },
9
+ };
10
+
11
+ export default routes;
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { Provider } from 'react-redux';
3
+ import { shallow } from '@theforeman/test';
4
+
5
+ import { statisticsProps } from './StatisticsPage/StatisticsPage.fixtures';
6
+ import Routes from './routes';
7
+
8
+ describe('ForemanPluginTemplateRoutes', () => {
9
+ it('should create routes', () => {
10
+ Object.entries(Routes).forEach(([key, Route]) => {
11
+ const store = {
12
+ subscribe: jest.fn(),
13
+ dispatch: jest.fn(),
14
+ getState: () => statisticsProps,
15
+ };
16
+ const RouteComponent = Route.component;
17
+ const component = shallow(
18
+ <Provider store={store}>
19
+ <RouteComponent history={{}} some="props" />
20
+ </Provider>
21
+ );
22
+ Route.renderResult = component;
23
+ });
24
+
25
+ expect(Routes).toMatchSnapshot();
26
+ });
27
+ });
@@ -0,0 +1 @@
1
+ export { default } from './ForemanStatistics';
@@ -0,0 +1,9 @@
1
+ import { combineReducers } from 'redux';
2
+
3
+ import { reducers as statisticsPageReducers } from './Router/StatisticsPage';
4
+
5
+ const reducers = {
6
+ foremanStatistics: combineReducers(statisticsPageReducers),
7
+ };
8
+
9
+ export default reducers;
@@ -0,0 +1,7 @@
1
+ export function trendTypeSelected({ value }) {
2
+ ['trend_trendable_id', 'trend_name'].forEach(id => {
3
+ const element = document.getElementById(id);
4
+ element.disabled = value !== 'FactName';
5
+ element.value = '';
6
+ });
7
+ }
@@ -0,0 +1,44 @@
1
+ /* eslint-disable jquery/no-val */
2
+ /* eslint-disable jquery/no-is */
3
+
4
+ import $ from 'jquery';
5
+
6
+ jest.unmock('jquery');
7
+ jest.unmock('./trends');
8
+ window.trends = require('./trends');
9
+
10
+ describe('selecting trend type', () => {
11
+ it('should disable fields on non-fact trend', () => {
12
+ document.body.innerHTML = `<select id="trendable_type" onchange="trends.trendTypeSelected(this)">
13
+ <option value="FactName">Facts</option>
14
+ <option value="Hostgroup">Host group</option>
15
+ </select>
16
+ <select id="trend_trendable_id">
17
+ <option value=""></option>
18
+ <option value="27">architecture</option>
19
+ </select>
20
+ <input id="trend_name">`;
21
+ $('#trendable_type')
22
+ .val('Hostgroup')
23
+ .change();
24
+ expect($('#trend_trendable_id').is(':disabled')).toBeTruthy();
25
+ expect($('#trend_name').is(':disabled')).toBeTruthy();
26
+ });
27
+
28
+ it('should enable fields on non-fact trend', () => {
29
+ document.body.innerHTML = `<select id="trendable_type" onchange="trends.trendTypeSelected(this)">
30
+ <option value="Evironment">Environment</option>
31
+ <option value="FactName">Facts</option>
32
+ </select>
33
+ <select id="trend_trendable_id" disabled>
34
+ <option value=""></option>
35
+ <option value="27">architecture</option>
36
+ </select>
37
+ <input id="trend_name" disabled>`;
38
+ $('#trendable_type')
39
+ .val('FactName')
40
+ .change();
41
+ expect($('#trend_trendable_id').is(':disabled')).toBeFalsy();
42
+ expect($('#trend_name').is(':disabled')).toBeFalsy();
43
+ });
44
+ });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondrej Ezr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-10 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.87.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.87.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop-minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +97,7 @@ files:
97
97
  - app/controllers/foreman_statistics/statistics_controller.rb
98
98
  - app/controllers/foreman_statistics/trends_controller.rb
99
99
  - app/helpers/foreman_statistics/trends_helper.rb
100
+ - app/jobs/foreman_statistics/trend_counter_job.rb
100
101
  - app/models/concerns/foreman_statistics/compute_resource_decorations.rb
101
102
  - app/models/concerns/foreman_statistics/environment_decorations.rb
102
103
  - app/models/concerns/foreman_statistics/general_setting_decorations.rb
@@ -142,9 +143,14 @@ files:
142
143
  - lib/foreman_statistics/version.rb
143
144
  - lib/tasks/foreman_statistics_tasks.rake
144
145
  - locale/Makefile
146
+ - locale/action_names.rb
147
+ - locale/en/LC_MESSAGES/foreman_statistics.mo
148
+ - locale/en/foreman_statistics.edit.po
145
149
  - locale/en/foreman_statistics.po
150
+ - locale/en/foreman_statistics.po.time_stamp
146
151
  - locale/foreman_statistics.pot
147
152
  - locale/gemspec.rb
153
+ - package.json
148
154
  - test/factories/foreman_statistics_factories.rb
149
155
  - test/fixtures/permissions.yml
150
156
  - test/fixtures/settings.yml
@@ -154,11 +160,63 @@ files:
154
160
  - test/functional/foreman_statistics/trends_controller_test.rb
155
161
  - test/models/foreman_statistics/trend_counter_test.rb
156
162
  - test/models/foreman_statistics/trend_test.rb
157
- - test/test_plugin_helper.rb
163
+ - test/test_statistics_helper.rb
158
164
  - test/unit/foreman_statistics/access_permissions_test.rb
159
165
  - test/unit/foreman_statistics/statistics_test.rb
160
166
  - test/unit/foreman_statistics_test.rb
161
167
  - test/unit/tasks/foreman_statistics_tasks_test.rb
168
+ - webpack/__mocks__/foremanReact/API.js
169
+ - webpack/__mocks__/foremanReact/common/HOC.js
170
+ - webpack/__mocks__/foremanReact/common/I18n.js
171
+ - webpack/__mocks__/foremanReact/common/helpers.js
172
+ - webpack/__mocks__/foremanReact/common/urlHelpers.js
173
+ - webpack/__mocks__/foremanReact/components/ChartBox/index.js
174
+ - webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js
175
+ - webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalHooks.js
176
+ - webpack/__mocks__/foremanReact/components/ForemanModal/index.js
177
+ - webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js
178
+ - webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js
179
+ - webpack/__mocks__/foremanReact/components/common/EmptyState.js
180
+ - webpack/__mocks__/foremanReact/components/common/MessageBox.js
181
+ - webpack/__mocks__/foremanReact/components/common/dates/LongDateTime.js
182
+ - webpack/__mocks__/foremanReact/components/common/dates/RelativeDateTime.js
183
+ - webpack/__mocks__/foremanReact/components/common/table.js
184
+ - webpack/__mocks__/foremanReact/components/common/table/actionsHelpers/actionTypeCreator.js
185
+ - webpack/__mocks__/foremanReact/constants.js
186
+ - webpack/__mocks__/foremanReact/readme.md
187
+ - webpack/__mocks__/foremanReact/redux/actions/toasts.js
188
+ - webpack/__mocks__/foremanReact/routes/common/PageLayout/PageLayout.js
189
+ - webpack/__mocks__/foremanReact/routes/common/PageLayout/components/ExportButton/ExportButton.js
190
+ - webpack/__mocks__/foremanReact/routes/common/reducerHOC/withDataReducer.js
191
+ - webpack/fills_index.js
192
+ - webpack/index.js
193
+ - webpack/src/Components/StatisticsChartsList/StatisticsChartsList.fixtures.js
194
+ - webpack/src/Components/StatisticsChartsList/StatisticsChartsList.test.js
195
+ - webpack/src/Components/StatisticsChartsList/StatisticsChartsListStyles.scss
196
+ - webpack/src/Components/StatisticsChartsList/__snapshots__/StatisticsChartsList.test.js.snap
197
+ - webpack/src/Components/StatisticsChartsList/index.js
198
+ - webpack/src/ForemanStatistics.js
199
+ - webpack/src/Router/StatisticsPage/Statistics/Statistics.js
200
+ - webpack/src/Router/StatisticsPage/StatisticsPage.fixtures.js
201
+ - webpack/src/Router/StatisticsPage/StatisticsPage.js
202
+ - webpack/src/Router/StatisticsPage/StatisticsPageActions.js
203
+ - webpack/src/Router/StatisticsPage/StatisticsPageSelectors.js
204
+ - webpack/src/Router/StatisticsPage/__tests__/StatisticsPage.test.js
205
+ - webpack/src/Router/StatisticsPage/__tests__/StatisticsPageActions.test.js
206
+ - webpack/src/Router/StatisticsPage/__tests__/StatisticsPageSelectors.test.js
207
+ - webpack/src/Router/StatisticsPage/__tests__/__snapshots__/StatisticsPage.test.js.snap
208
+ - webpack/src/Router/StatisticsPage/__tests__/__snapshots__/StatisticsPageActions.test.js.snap
209
+ - webpack/src/Router/StatisticsPage/__tests__/__snapshots__/StatisticsPageSelectors.test.js.snap
210
+ - webpack/src/Router/StatisticsPage/constants.js
211
+ - webpack/src/Router/StatisticsPage/index.js
212
+ - webpack/src/Router/__snapshots__/routes.test.js.snap
213
+ - webpack/src/Router/index.js
214
+ - webpack/src/Router/routes.js
215
+ - webpack/src/Router/routes.test.js
216
+ - webpack/src/index.js
217
+ - webpack/src/reducers.js
218
+ - webpack/src/trends.js
219
+ - webpack/src/trends.test.js
162
220
  homepage: https://theforeman.org
163
221
  licenses:
164
222
  - GPL-3.0
@@ -178,11 +236,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
236
  - !ruby/object:Gem::Version
179
237
  version: '0'
180
238
  requirements: []
181
- rubygems_version: 3.0.3
239
+ rubygems_version: 3.1.4
182
240
  signing_key:
183
241
  specification_version: 4
184
242
  summary: Add Statistics and Trends.
185
243
  test_files:
244
+ - test/test_statistics_helper.rb
186
245
  - test/functional/foreman_statistics/trends_controller_test.rb
187
246
  - test/functional/foreman_statistics/statistics_controller_test.rb
188
247
  - test/functional/foreman_statistics/api/v2/trends_controller_test.rb
@@ -196,4 +255,3 @@ test_files:
196
255
  - test/factories/foreman_statistics_factories.rb
197
256
  - test/fixtures/settings.yml
198
257
  - test/fixtures/permissions.yml
199
- - test/test_plugin_helper.rb