@iapps/ng-dhis2-ui 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/index.mjs +4 -1
- package/esm2022/lib/modules/button/button.component.mjs +2 -2
- package/esm2022/lib/modules/header-bar/header-bar.component.mjs +7 -8
- package/esm2022/lib/modules/organisation-unit-selector/components/OrgUnitDimension.mjs +212 -0
- package/esm2022/lib/modules/organisation-unit-selector/components/index.mjs +6 -0
- package/esm2022/lib/modules/organisation-unit-selector/components/styles/OrgUnitDimension.style.mjs +83 -0
- package/esm2022/lib/modules/organisation-unit-selector/components/utils/index.mjs +6 -0
- package/esm2022/lib/modules/organisation-unit-selector/components/utils/ouIdHelper/index.mjs +18 -0
- package/esm2022/lib/modules/organisation-unit-selector/components/utils/ouLevelUtils/index.mjs +27 -0
- package/esm2022/lib/modules/organisation-unit-selector/index.mjs +6 -0
- package/esm2022/lib/modules/organisation-unit-selector/models/index.mjs +5 -0
- package/esm2022/lib/modules/organisation-unit-selector/models/organisation-unit-config.model.mjs +16 -0
- package/esm2022/lib/modules/organisation-unit-selector/organisation-unit-selector.component.mjs +78 -0
- package/esm2022/lib/modules/organisation-unit-selector/organisation-unit-selector.module.mjs +19 -0
- package/esm2022/lib/modules/period-selector/components/FixedPeriodFilter.mjs +44 -0
- package/esm2022/lib/modules/period-selector/components/PeriodDimension.mjs +41 -0
- package/esm2022/lib/modules/period-selector/components/PeriodTransfer.mjs +110 -0
- package/esm2022/lib/modules/period-selector/components/RelativePeriodFilter.mjs +28 -0
- package/esm2022/lib/modules/period-selector/components/utils/fixedPeriods.mjs +308 -0
- package/esm2022/lib/modules/period-selector/components/utils/index.mjs +5 -0
- package/esm2022/lib/modules/period-selector/components/utils/periodTypes.mjs +23 -0
- package/esm2022/lib/modules/period-selector/components/utils/relativePeriods.mjs +139 -0
- package/esm2022/lib/modules/period-selector/index.mjs +6 -0
- package/esm2022/lib/modules/period-selector/period-selector.component.mjs +66 -0
- package/esm2022/lib/modules/period-selector/period-selector.module.mjs +19 -0
- package/esm2022/lib/modules/react-wrapper/index.mjs +6 -0
- package/esm2022/lib/modules/react-wrapper/react-wrapper.component.mjs +53 -0
- package/esm2022/lib/modules/react-wrapper/react-wrapper.module.mjs +18 -0
- package/esm2022/lib/shared/assets/AssignedCategoriesIcon.mjs +12 -0
- package/esm2022/lib/shared/assets/DimensionItemIcons/PeriodIcon.mjs +4 -0
- package/esm2022/lib/shared/components/TransferOption.mjs +130 -0
- package/esm2022/lib/shared/components/index.mjs +2 -3
- package/esm2022/lib/shared/index.mjs +7 -0
- package/esm2022/lib/shared/styles/DimensionSelector.style.mjs +39 -0
- package/esm2022/lib/shared/styles/index.mjs +5 -0
- package/esm2022/lib/shared/utils/axis.mjs +25 -0
- package/esm2022/lib/shared/utils/axisGetDimension.mjs +5 -0
- package/esm2022/lib/shared/utils/axisHasDimension.mjs +3 -0
- package/esm2022/lib/shared/utils/dimension.mjs +52 -0
- package/esm2022/lib/shared/utils/dimensionGetItems.mjs +6 -0
- package/esm2022/lib/shared/utils/dimensionIs.mjs +3 -0
- package/esm2022/lib/shared/utils/dimensionIsEmpty.mjs +5 -0
- package/esm2022/lib/shared/utils/dimensionIsValid.mjs +16 -0
- package/esm2022/lib/shared/utils/dimensionSelectorHelper.mjs +4 -0
- package/esm2022/lib/shared/utils/index.mjs +15 -0
- package/esm2022/lib/shared/utils/layoutGetAllAxes.mjs +7 -0
- package/esm2022/lib/shared/utils/layoutGetAllDimensions.mjs +6 -0
- package/esm2022/lib/shared/utils/layoutGetDimension.mjs +4 -0
- package/esm2022/lib/shared/utils/layoutReplaceDimension.mjs +17 -0
- package/esm2022/lib/shared/utils/list.mjs +15 -0
- package/esm2022/lib/shared/utils/predefinedDimensions.mjs +45 -0
- package/fesm2022/iapps-ng-dhis2-ui.mjs +1652 -77
- package/fesm2022/iapps-ng-dhis2-ui.mjs.map +1 -1
- package/index.d.ts +3 -0
- package/lib/modules/button/button.component.d.ts +1 -1
- package/lib/modules/header-bar/header-bar.component.d.ts +1 -4
- package/lib/modules/organisation-unit-selector/components/OrgUnitDimension.d.ts +26 -0
- package/lib/modules/organisation-unit-selector/components/index.d.ts +2 -0
- package/lib/modules/organisation-unit-selector/components/styles/OrgUnitDimension.style.d.ts +1 -0
- package/lib/modules/organisation-unit-selector/components/utils/index.d.ts +2 -0
- package/lib/modules/organisation-unit-selector/components/utils/ouIdHelper/index.d.ts +10 -0
- package/lib/modules/organisation-unit-selector/components/utils/ouLevelUtils/index.d.ts +1 -0
- package/lib/modules/organisation-unit-selector/index.d.ts +2 -0
- package/lib/modules/organisation-unit-selector/models/index.d.ts +1 -0
- package/lib/modules/organisation-unit-selector/models/organisation-unit-config.model.d.ts +12 -0
- package/lib/modules/organisation-unit-selector/organisation-unit-selector.component.d.ts +26 -0
- package/lib/modules/organisation-unit-selector/organisation-unit-selector.module.d.ts +9 -0
- package/lib/modules/period-selector/components/FixedPeriodFilter.d.ts +18 -0
- package/lib/modules/period-selector/components/PeriodDimension.d.ts +15 -0
- package/lib/modules/period-selector/components/PeriodTransfer.d.ts +28 -0
- package/lib/modules/period-selector/components/RelativePeriodFilter.d.ts +11 -0
- package/lib/modules/period-selector/components/utils/fixedPeriods.d.ts +17 -0
- package/lib/modules/period-selector/components/utils/index.d.ts +4 -0
- package/lib/modules/period-selector/components/utils/periodTypes.d.ts +19 -0
- package/lib/modules/period-selector/components/utils/relativePeriods.d.ts +17 -0
- package/lib/modules/period-selector/index.d.ts +2 -0
- package/lib/modules/period-selector/period-selector.component.d.ts +21 -0
- package/lib/modules/period-selector/period-selector.module.d.ts +9 -0
- package/lib/modules/react-wrapper/index.d.ts +2 -0
- package/lib/modules/react-wrapper/react-wrapper.module.d.ts +8 -0
- package/lib/shared/assets/AssignedCategoriesIcon.d.ts +2 -0
- package/lib/shared/assets/DimensionItemIcons/PeriodIcon.d.ts +3 -0
- package/lib/shared/components/TransferOption.d.ts +19 -0
- package/lib/shared/components/index.d.ts +1 -2
- package/lib/shared/index.d.ts +3 -0
- package/lib/shared/styles/DimensionSelector.style.d.ts +2 -0
- package/lib/shared/styles/index.d.ts +1 -0
- package/lib/shared/utils/axis.d.ts +11 -0
- package/lib/shared/utils/axisGetDimension.d.ts +1 -0
- package/lib/shared/utils/axisHasDimension.d.ts +1 -0
- package/lib/shared/utils/dimension.d.ts +45 -0
- package/lib/shared/utils/dimensionGetItems.d.ts +1 -0
- package/lib/shared/utils/dimensionIs.d.ts +1 -0
- package/lib/shared/utils/dimensionIsEmpty.d.ts +1 -0
- package/lib/shared/utils/dimensionIsValid.d.ts +1 -0
- package/lib/shared/utils/dimensionSelectorHelper.d.ts +3 -0
- package/lib/shared/utils/index.d.ts +11 -0
- package/lib/shared/utils/layoutGetAllAxes.d.ts +1 -0
- package/lib/shared/utils/layoutGetAllDimensions.d.ts +1 -0
- package/lib/shared/utils/layoutGetDimension.d.ts +1 -0
- package/lib/shared/utils/layoutReplaceDimension.d.ts +1 -0
- package/lib/shared/utils/list.d.ts +1 -0
- package/lib/shared/utils/predefinedDimensions.d.ts +65 -0
- package/package.json +1 -1
- package/esm2022/lib/shared/components/react-component-wrapper/react-wrapper.component.mjs +0 -53
- /package/lib/{shared/components/react-component-wrapper → modules/react-wrapper}/react-wrapper.component.d.ts +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { NgModule, Directive, Input, ContentChild, Component, EventEmitter, Output } from '@angular/core';
|
|
3
|
-
import * as i2 from '@angular/common';
|
|
4
3
|
import { CommonModule } from '@angular/common';
|
|
5
|
-
import
|
|
4
|
+
import { IconEdit16, spacers, colors, theme, Tooltip, Button as Button$1, IconDimensionData16, IconClock16, IconDimensionOrgUnit16, SingleSelectField, SingleSelectOption, InputField as InputField$1, TabBar, Tab, Transfer, Checkbox, OrganisationUnitTree, MultiSelect, MultiSelectOption, IconWarningFilled16 } from '@dhis2/ui';
|
|
5
|
+
import cx from 'classnames';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import React__default, { useState, useCallback, useRef, useEffect, createContext, useContext, useMemo } from 'react';
|
|
8
|
-
import
|
|
9
|
+
import { useDataQuery, useConfig, useAlert, clearSensitiveCaches, DataProvider, useDataEngine } from '@dhis2/app-runtime';
|
|
9
10
|
import * as i1 from '@iapps/ngx-dhis2-http-client';
|
|
11
|
+
import * as ReactDOM from 'react-dom/client';
|
|
10
12
|
import { catchError, of, map, zip, firstValueFrom } from 'rxjs';
|
|
11
|
-
import { useDataQuery, useConfig, useAlert, clearSensitiveCaches, DataProvider } from '@dhis2/app-runtime';
|
|
12
13
|
import i18n from '@dhis2/d2-i18n';
|
|
13
|
-
import { colors, theme, spacers } from '@dhis2/ui-constants';
|
|
14
|
-
import PropTypes from 'prop-types';
|
|
14
|
+
import { colors as colors$1, theme as theme$1, spacers as spacers$1 } from '@dhis2/ui-constants';
|
|
15
15
|
import { Card } from '@dhis2-ui/card';
|
|
16
16
|
import { InputField } from '@dhis2-ui/input';
|
|
17
17
|
import { IconSettings24, IconApps24, IconMessages24, IconMail24, IconUser24, IconQuestion24, IconInfo24, IconLogOut24 } from '@dhis2/ui-icons';
|
|
@@ -24,7 +24,9 @@ import { Divider } from '@dhis2-ui/divider';
|
|
|
24
24
|
import { Layer } from '@dhis2-ui/layer';
|
|
25
25
|
import { CircularLoader } from '@dhis2-ui/loader';
|
|
26
26
|
import { MenuItem, MenuDivider } from '@dhis2-ui/menu';
|
|
27
|
-
import
|
|
27
|
+
import parse from 'html-react-parser';
|
|
28
|
+
import { getNowInCalendar, generateFixedPeriods } from '@dhis2/multi-calendar-dates';
|
|
29
|
+
import { isObject, isString } from 'lodash';
|
|
28
30
|
|
|
29
31
|
class NgDhis2UiModule {
|
|
30
32
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgDhis2UiModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
@@ -38,53 +40,131 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
|
|
|
38
40
|
}]
|
|
39
41
|
}] });
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
43
|
+
const TransferOption = ({ disabled, label, highlighted, selected, onClick, onDoubleClick, value, icon, active, tooltipText, dataTest, onEditClick, }) => {
|
|
44
|
+
const renderContent = () => (React__default.createElement("div", { className: cx('chip', {
|
|
45
|
+
highlighted,
|
|
46
|
+
disabled,
|
|
47
|
+
selected,
|
|
48
|
+
inactive: active !== undefined && !active,
|
|
49
|
+
}), "data-test": `${dataTest}-content`, onClick: (event) => {
|
|
50
|
+
if (disabled) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
onClick({ label, value }, event);
|
|
54
|
+
}, onDoubleClick: (event) => {
|
|
55
|
+
if (disabled) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
onDoubleClick({ label, value }, event);
|
|
59
|
+
} },
|
|
60
|
+
React__default.createElement("span", { className: "icon" }, icon),
|
|
61
|
+
React__default.createElement("span", { className: "label" }, label),
|
|
62
|
+
onEditClick && (React__default.createElement("span", { className: "edit", onClick: (e) => {
|
|
63
|
+
e.stopPropagation();
|
|
64
|
+
onEditClick();
|
|
65
|
+
}, "data-test": `${dataTest}-edit-button` },
|
|
66
|
+
React__default.createElement(IconEdit16, null))),
|
|
67
|
+
React__default.createElement("style", { jsx: true }, `
|
|
68
|
+
.wrapper:last-child {
|
|
69
|
+
margin-bottom: ${spacers.dp4};
|
|
70
|
+
}
|
|
71
|
+
.chip {
|
|
72
|
+
display: inline-flex;
|
|
73
|
+
background: ${colors.grey200};
|
|
74
|
+
font-size: 14px;
|
|
75
|
+
line-height: 16px;
|
|
76
|
+
padding: 2px ${spacers.dp8} 2px ${spacers.dp4};
|
|
77
|
+
margin: ${spacers.dp4} ${spacers.dp8} 0 ${spacers.dp8};
|
|
78
|
+
border-radius: 3px;
|
|
79
|
+
user-select: none;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.chip:hover {
|
|
83
|
+
background: ${colors.grey300};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.selected {
|
|
87
|
+
background: ${theme.secondary100};
|
|
88
|
+
color: ${theme.secondary900};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.selected :global(.icon path) {
|
|
92
|
+
fill: ${theme.secondary700};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.selected:hover {
|
|
96
|
+
background: #c9edeb;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.highlighted,
|
|
100
|
+
.highlighted:hover {
|
|
101
|
+
background: ${theme.secondary800};
|
|
102
|
+
color: ${colors.white};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.highlighted :global(.icon path) {
|
|
106
|
+
fill: ${colors.white};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.disabled {
|
|
110
|
+
opacity: 0.3;
|
|
111
|
+
cursor: not-allowed;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.inactive {
|
|
115
|
+
opacity: 0.3;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.icon,
|
|
119
|
+
.label {
|
|
120
|
+
line-height: 18px;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.icon {
|
|
124
|
+
margin-right: ${spacers.dp4};
|
|
125
|
+
display: inline-flex;
|
|
126
|
+
vertical-align: text-bottom;
|
|
127
|
+
padding-top: 1px;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.label {
|
|
131
|
+
font-size: 14px;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.edit {
|
|
135
|
+
height: 16px;
|
|
136
|
+
margin-top: 1px;
|
|
137
|
+
margin-left: ${spacers.dp8};
|
|
138
|
+
cursor: pointer;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.edit:hover {
|
|
142
|
+
background-color: rgba(0, 0, 0, 0.12);
|
|
143
|
+
outline: 1px solid rgba(0, 0, 0, 0.12);
|
|
144
|
+
border-radius: 3px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.highlighted .edit:hover {
|
|
148
|
+
background-color: rgba(255, 255, 255, 0.12);
|
|
149
|
+
outline: 1px solid rgba(255, 255, 255, 0.12);
|
|
150
|
+
}
|
|
151
|
+
`)));
|
|
152
|
+
return (React__default.createElement("div", { "data-value": value, "data-test": dataTest, className: "wrapper" }, tooltipText ? (React__default.createElement(Tooltip, { key: `${value}`, content: tooltipText, placement: 'top', openDelay: 750, closeDelay: 150 }, renderContent())) : (renderContent())));
|
|
153
|
+
};
|
|
154
|
+
TransferOption.propTypes = {
|
|
155
|
+
label: PropTypes.string.isRequired,
|
|
156
|
+
value: PropTypes.string.isRequired,
|
|
157
|
+
active: PropTypes.bool,
|
|
158
|
+
dataTest: PropTypes.string,
|
|
159
|
+
disabled: PropTypes.bool,
|
|
160
|
+
highlighted: PropTypes.bool,
|
|
161
|
+
icon: PropTypes.node,
|
|
162
|
+
selected: PropTypes.bool,
|
|
163
|
+
tooltipText: PropTypes.string,
|
|
164
|
+
onClick: PropTypes.func,
|
|
165
|
+
onDoubleClick: PropTypes.func,
|
|
166
|
+
onEditClick: PropTypes.func,
|
|
167
|
+
};
|
|
88
168
|
|
|
89
169
|
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
90
170
|
// Use of this source code is governed by a BSD-style
|
|
@@ -201,7 +281,7 @@ function Search({ value, onChange, baseUrl }) {
|
|
|
201
281
|
React__default.createElement(InputField, { value: value, name: "filter", placeholder: i18n.t('Search apps'), onChange: onChange, initialFocus: true })),
|
|
202
282
|
React__default.createElement("span", { className: "headerbar-apps-search-icon" },
|
|
203
283
|
React__default.createElement("a", { href: joinPath(baseUrl, 'dhis-web-menu-management') },
|
|
204
|
-
React__default.createElement(IconSettings24, { color: colors.grey700 }))),
|
|
284
|
+
React__default.createElement(IconSettings24, { color: colors$1.grey700 }))),
|
|
205
285
|
React__default.createElement("style", { jsx: true }, `
|
|
206
286
|
.headerbar-apps-search {
|
|
207
287
|
display: flex;
|
|
@@ -259,7 +339,7 @@ function Item({ name, path, img }) {
|
|
|
259
339
|
|
|
260
340
|
.headerbar-app-item-logo:hover,
|
|
261
341
|
.headerbar-app-item-logo:focus {
|
|
262
|
-
background-color: ${theme.primary050};
|
|
342
|
+
background-color: ${theme$1.primary050};
|
|
263
343
|
cursor: pointer;
|
|
264
344
|
}
|
|
265
345
|
|
|
@@ -364,13 +444,13 @@ const Apps = ({ apps, baseUrl }) => {
|
|
|
364
444
|
}, [onDocClick]);
|
|
365
445
|
return (React__default.createElement("div", { className: "headerbar-apps", ref: containerEl, "data-test": "headerbar-apps" },
|
|
366
446
|
React__default.createElement("button", { onClick: handleVisibilityToggle, "data-test": "headerbar-apps-icon" },
|
|
367
|
-
React__default.createElement(IconApps24, { color: colors.white })),
|
|
447
|
+
React__default.createElement(IconApps24, { color: colors$1.white })),
|
|
368
448
|
show ? (React__default.createElement(AppMenu, { apps: apps, filter: filter, baseUrl: baseUrl, onFilterChange: handleFilterChange })) : null,
|
|
369
449
|
React__default.createElement("style", { jsx: true }, `
|
|
370
450
|
.headerbar-apps button {
|
|
371
451
|
display: block;
|
|
372
452
|
background: transparent;
|
|
373
|
-
padding: ${spacers.dp4} ${spacers.dp12} 0;
|
|
453
|
+
padding: ${spacers$1.dp4} ${spacers$1.dp12} 0;
|
|
374
454
|
border: 0;
|
|
375
455
|
cursor: pointer;
|
|
376
456
|
height: 100%;
|
|
@@ -484,10 +564,10 @@ const Logo = ({ baseUrl }) => {
|
|
|
484
564
|
|
|
485
565
|
function icon(kind) {
|
|
486
566
|
if (kind === 'message') {
|
|
487
|
-
return React__default.createElement(IconMessages24, { color: colors.white });
|
|
567
|
+
return React__default.createElement(IconMessages24, { color: colors$1.white });
|
|
488
568
|
}
|
|
489
569
|
else {
|
|
490
|
-
return React__default.createElement(IconMail24, { color: colors.white });
|
|
570
|
+
return React__default.createElement(IconMail24, { color: colors$1.white });
|
|
491
571
|
}
|
|
492
572
|
}
|
|
493
573
|
const NotificationIcon = (params) => {
|
|
@@ -501,7 +581,7 @@ const NotificationIcon = (params) => {
|
|
|
501
581
|
position: relative;
|
|
502
582
|
margin: 0;
|
|
503
583
|
cursor: pointer;
|
|
504
|
-
padding: 0 ${spacers.dp12};
|
|
584
|
+
padding: 0 ${spacers$1.dp12};
|
|
505
585
|
height: 100%;
|
|
506
586
|
display: flex;
|
|
507
587
|
align-items: center;
|
|
@@ -529,17 +609,17 @@ const NotificationIcon = (params) => {
|
|
|
529
609
|
right: 2px;
|
|
530
610
|
min-width: 18px;
|
|
531
611
|
min-height: 18px;
|
|
532
|
-
border-radius: ${spacers.dp12};
|
|
612
|
+
border-radius: ${spacers$1.dp12};
|
|
533
613
|
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1),
|
|
534
614
|
0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
|
535
|
-
background-color: ${theme.secondary500};
|
|
536
|
-
color: ${colors.white};
|
|
615
|
+
background-color: ${theme$1.secondary500};
|
|
616
|
+
color: ${colors$1.white};
|
|
537
617
|
font-size: 13px;
|
|
538
618
|
font-weight: 600;
|
|
539
619
|
line-height: 15px;
|
|
540
620
|
text-align: center;
|
|
541
621
|
cursor: inherit;
|
|
542
|
-
padding: 0 ${spacers.dp4};
|
|
622
|
+
padding: 0 ${spacers$1.dp4};
|
|
543
623
|
}
|
|
544
624
|
`)));
|
|
545
625
|
};
|
|
@@ -619,7 +699,7 @@ function DebugInfoTable() {
|
|
|
619
699
|
white-space: pre-wrap;
|
|
620
700
|
font-size: 14px;
|
|
621
701
|
line-height: 1.2;
|
|
622
|
-
color: ${colors.grey700};
|
|
702
|
+
color: ${colors$1.grey700};
|
|
623
703
|
font-famile: Menlo, Courier, monospace !important;
|
|
624
704
|
}
|
|
625
705
|
td {
|
|
@@ -679,7 +759,7 @@ const DebugInfoMenuItem = (params) => {
|
|
|
679
759
|
: i18n.t('App version unknown')),
|
|
680
760
|
React__default.createElement("style", { jsx: true }, `
|
|
681
761
|
.root {
|
|
682
|
-
color: ${colors.grey700};
|
|
762
|
+
color: ${colors$1.grey700};
|
|
683
763
|
font-style: italic;
|
|
684
764
|
font-size: 14px;
|
|
685
765
|
line-height: 17px;
|
|
@@ -833,7 +913,7 @@ function UpdateNotification(params) {
|
|
|
833
913
|
height: 12px;
|
|
834
914
|
margin: 0 8px;
|
|
835
915
|
border-radius: 6px;
|
|
836
|
-
background-color: ${colors.blue600};
|
|
916
|
+
background-color: ${colors$1.blue600};
|
|
837
917
|
}
|
|
838
918
|
.spacer {
|
|
839
919
|
display: inline-block;
|
|
@@ -861,10 +941,10 @@ const ProfileContents = (params) => {
|
|
|
861
941
|
React__default.createElement(ProfileHeader, { name: name, email: email, avatarId: avatarId }),
|
|
862
942
|
React__default.createElement(Divider, { margin: "13px 0 7px 0" }),
|
|
863
943
|
React__default.createElement("ul", { "data-test": "headerbar-profile-menu" },
|
|
864
|
-
React__default.createElement(MenuItem, { href: joinPath(baseUrl, 'dhis-web-user-profile/#/settings'), label: i18n.t('Settings'), value: "settings", icon: React__default.createElement(IconSettings24, { color: colors.grey700 }) }),
|
|
865
|
-
React__default.createElement(MenuItem, { href: joinPath(baseUrl, 'dhis-web-user-profile/#/account'), label: i18n.t('Account'), value: "account", icon: React__default.createElement(IconUser24, { color: colors.grey700 }) }),
|
|
866
|
-
helpUrl && (React__default.createElement(MenuItem, { href: helpUrl, label: i18n.t('Help'), value: "help", icon: React__default.createElement(IconQuestion24, { color: colors.grey700 }) })),
|
|
867
|
-
React__default.createElement(MenuItem, { href: joinPath(baseUrl, 'dhis-web-user-profile/#/aboutPage'), label: i18n.t('About DHIS2'), value: "about", icon: React__default.createElement(IconInfo24, { color: colors.grey700 }) }),
|
|
944
|
+
React__default.createElement(MenuItem, { href: joinPath(baseUrl, 'dhis-web-user-profile/#/settings'), label: i18n.t('Settings'), value: "settings", icon: React__default.createElement(IconSettings24, { color: colors$1.grey700 }) }),
|
|
945
|
+
React__default.createElement(MenuItem, { href: joinPath(baseUrl, 'dhis-web-user-profile/#/account'), label: i18n.t('Account'), value: "account", icon: React__default.createElement(IconUser24, { color: colors$1.grey700 }) }),
|
|
946
|
+
helpUrl && (React__default.createElement(MenuItem, { href: helpUrl, label: i18n.t('Help'), value: "help", icon: React__default.createElement(IconQuestion24, { color: colors$1.grey700 }) })),
|
|
947
|
+
React__default.createElement(MenuItem, { href: joinPath(baseUrl, 'dhis-web-user-profile/#/aboutPage'), label: i18n.t('About DHIS2'), value: "about", icon: React__default.createElement(IconInfo24, { color: colors$1.grey700 }) }),
|
|
868
948
|
React__default.createElement(MenuItem, { href: joinPath(baseUrl, 'dhis-web-commons-security/logout.action'),
|
|
869
949
|
// NB: By MenuItem implementation, this callback
|
|
870
950
|
// overwrites default navigation behavior but maintains
|
|
@@ -874,7 +954,7 @@ const ProfileContents = (params) => {
|
|
|
874
954
|
await clearSensitiveCaches();
|
|
875
955
|
setLoading(false);
|
|
876
956
|
window.location.assign(joinPath(baseUrl, 'dhis-web-commons-security/logout.action'));
|
|
877
|
-
}, label: i18n.t('Logout'), value: "logout", icon: React__default.createElement(IconLogOut24, { color: colors.grey700 }) }),
|
|
957
|
+
}, label: i18n.t('Logout'), value: "logout", icon: React__default.createElement(IconLogOut24, { color: colors$1.grey700 }) }),
|
|
878
958
|
React__default.createElement(MenuDivider, { dense: true }),
|
|
879
959
|
React__default.createElement(DebugInfoMenuItem, { hideProfileMenu: hideProfileMenu, showDebugInfoModal: showDebugInfoModal }),
|
|
880
960
|
React__default.createElement(UpdateNotification, { hideProfileMenu: hideProfileMenu }))),
|
|
@@ -1055,7 +1135,7 @@ const HeaderBar = ({ appName, data, className }) => {
|
|
|
1055
1135
|
align-items: center;
|
|
1056
1136
|
justify-content: space-between;
|
|
1057
1137
|
background-color: #2c6693;
|
|
1058
|
-
color: ${colors.white};
|
|
1138
|
+
color: ${colors$1.white};
|
|
1059
1139
|
height: 48px;
|
|
1060
1140
|
}
|
|
1061
1141
|
.right-control-spacer {
|
|
@@ -1071,6 +1151,72 @@ HeaderBar.propTypes = {
|
|
|
1071
1151
|
onApplyAvailableUpdate: PropTypes.func,
|
|
1072
1152
|
};
|
|
1073
1153
|
|
|
1154
|
+
window.React = React;
|
|
1155
|
+
class ReactWrapperComponent {
|
|
1156
|
+
constructor(elementRef) {
|
|
1157
|
+
this.elementRef = elementRef;
|
|
1158
|
+
}
|
|
1159
|
+
ngAfterViewInit() {
|
|
1160
|
+
if (!this.elementRef)
|
|
1161
|
+
throw new Error('No element ref');
|
|
1162
|
+
this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
|
|
1163
|
+
this.render();
|
|
1164
|
+
}
|
|
1165
|
+
ngOnChanges() {
|
|
1166
|
+
if (this.elementRef)
|
|
1167
|
+
this.render();
|
|
1168
|
+
}
|
|
1169
|
+
ngOnDestroy() {
|
|
1170
|
+
this.reactDomRoot?.unmount();
|
|
1171
|
+
}
|
|
1172
|
+
render() {
|
|
1173
|
+
if (!this.component)
|
|
1174
|
+
throw new Error('React component must be supplied');
|
|
1175
|
+
if (!this.reactDomRoot)
|
|
1176
|
+
return;
|
|
1177
|
+
const jsxContent = this.content?.nativeElement?.outerHTML
|
|
1178
|
+
? parse(this.content?.nativeElement?.outerHTML)
|
|
1179
|
+
: undefined;
|
|
1180
|
+
this.reactDomRoot.render(React.createElement(this.component, { ...this.props },
|
|
1181
|
+
" ",
|
|
1182
|
+
jsxContent || '',
|
|
1183
|
+
" "));
|
|
1184
|
+
}
|
|
1185
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ReactWrapperComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1186
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: ReactWrapperComponent, selector: "ng-dhis2-ui-wrapper", inputs: { props: "props", component: "component" }, queries: [{ propertyName: "content", first: true, predicate: ["ngDhis2UiContent"], descendants: true }], usesOnChanges: true, ngImport: i0 }); }
|
|
1187
|
+
}
|
|
1188
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ReactWrapperComponent, decorators: [{
|
|
1189
|
+
type: Directive,
|
|
1190
|
+
args: [{
|
|
1191
|
+
selector: 'ng-dhis2-ui-wrapper',
|
|
1192
|
+
}]
|
|
1193
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { props: [{
|
|
1194
|
+
type: Input
|
|
1195
|
+
}], component: [{
|
|
1196
|
+
type: Input
|
|
1197
|
+
}], content: [{
|
|
1198
|
+
type: ContentChild,
|
|
1199
|
+
args: ['ngDhis2UiContent']
|
|
1200
|
+
}] } });
|
|
1201
|
+
|
|
1202
|
+
class ReactWrapperModule {
|
|
1203
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ReactWrapperModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1204
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: ReactWrapperModule, declarations: [ReactWrapperComponent], imports: [CommonModule], exports: [ReactWrapperComponent] }); }
|
|
1205
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ReactWrapperModule, imports: [CommonModule] }); }
|
|
1206
|
+
}
|
|
1207
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ReactWrapperModule, decorators: [{
|
|
1208
|
+
type: NgModule,
|
|
1209
|
+
args: [{
|
|
1210
|
+
imports: [CommonModule],
|
|
1211
|
+
declarations: [ReactWrapperComponent],
|
|
1212
|
+
exports: [ReactWrapperComponent],
|
|
1213
|
+
}]
|
|
1214
|
+
}] });
|
|
1215
|
+
|
|
1216
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
1217
|
+
// Use of this source code is governed by a BSD-style
|
|
1218
|
+
// license that can be found in the LICENSE file.
|
|
1219
|
+
|
|
1074
1220
|
class HeaderBarComponent extends ReactWrapperComponent {
|
|
1075
1221
|
constructor(elementRef, httpClient) {
|
|
1076
1222
|
super(elementRef);
|
|
@@ -1088,13 +1234,13 @@ class HeaderBarComponent extends ReactWrapperComponent {
|
|
|
1088
1234
|
this.render();
|
|
1089
1235
|
}
|
|
1090
1236
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: HeaderBarComponent, deps: [{ token: i0.ElementRef }, { token: i1.NgxDhis2HttpClientService }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1091
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: HeaderBarComponent, selector: "ng-dhis2-ui-header-bar", usesInheritance: true, ngImport: i0, template: `<ng-container
|
|
1237
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: HeaderBarComponent, selector: "ng-dhis2-ui-header-bar", usesInheritance: true, ngImport: i0, template: `<ng-container></ng-container>`, isInline: true }); }
|
|
1092
1238
|
}
|
|
1093
1239
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: HeaderBarComponent, decorators: [{
|
|
1094
1240
|
type: Component,
|
|
1095
1241
|
args: [{
|
|
1096
1242
|
selector: 'ng-dhis2-ui-header-bar',
|
|
1097
|
-
template: `<ng-container
|
|
1243
|
+
template: `<ng-container></ng-container>`,
|
|
1098
1244
|
}]
|
|
1099
1245
|
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }]; } });
|
|
1100
1246
|
|
|
@@ -1185,9 +1331,1438 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
|
|
|
1185
1331
|
// Use of this source code is governed by a BSD-style
|
|
1186
1332
|
// license that can be found in the LICENSE file.
|
|
1187
1333
|
|
|
1334
|
+
const AssignedCategoriesIcon = () => {
|
|
1335
|
+
return (React__default.createElement("svg", { height: "16", viewBox: "0 0 16 16", width: "16" },
|
|
1336
|
+
React__default.createElement("g", { fill: "#212934", fillRule: "evenodd" },
|
|
1337
|
+
React__default.createElement("path", { d: "m2 7h11v1h-11z" }),
|
|
1338
|
+
React__default.createElement("path", { d: "m2 13h11v1h-11z" }),
|
|
1339
|
+
React__default.createElement("path", { d: "m2 2h11v1h-11z" }),
|
|
1340
|
+
React__default.createElement("path", { d: "m7 8h1v5h-1z" }),
|
|
1341
|
+
React__default.createElement("path", { d: "m12 3h1v10h-1z" }),
|
|
1342
|
+
React__default.createElement("path", { d: "m2 3h1v10h-1z" }))));
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1345
|
+
const DIMENSION_ID_DATA = 'dx';
|
|
1346
|
+
const DIMENSION_ID_PERIOD = 'pe';
|
|
1347
|
+
const DIMENSION_ID_ORGUNIT = 'ou';
|
|
1348
|
+
const DIMENSION_ID_ASSIGNED_CATEGORIES = 'co';
|
|
1349
|
+
const DIMENSION_PROP_NO_ITEMS = 'noItems';
|
|
1350
|
+
const getFixedDimensions = () => ({
|
|
1351
|
+
[DIMENSION_ID_DATA]: {
|
|
1352
|
+
id: DIMENSION_ID_DATA,
|
|
1353
|
+
name: i18n.t('Data'),
|
|
1354
|
+
iconName: 'DataIcon',
|
|
1355
|
+
icon: IconDimensionData16,
|
|
1356
|
+
},
|
|
1357
|
+
[DIMENSION_ID_PERIOD]: {
|
|
1358
|
+
id: DIMENSION_ID_PERIOD,
|
|
1359
|
+
name: i18n.t('Period'),
|
|
1360
|
+
iconName: 'PeriodIcon',
|
|
1361
|
+
icon: IconClock16,
|
|
1362
|
+
},
|
|
1363
|
+
[DIMENSION_ID_ORGUNIT]: {
|
|
1364
|
+
id: DIMENSION_ID_ORGUNIT,
|
|
1365
|
+
name: i18n.t('Organisation unit'),
|
|
1366
|
+
iconName: 'OrgUnitIcon',
|
|
1367
|
+
icon: IconDimensionOrgUnit16,
|
|
1368
|
+
},
|
|
1369
|
+
});
|
|
1370
|
+
const getDynamicDimensions = () => ({
|
|
1371
|
+
[DIMENSION_ID_ASSIGNED_CATEGORIES]: {
|
|
1372
|
+
id: DIMENSION_ID_ASSIGNED_CATEGORIES,
|
|
1373
|
+
name: i18n.t('Assigned Categories'),
|
|
1374
|
+
iconName: 'AssignedCategoriesIcon',
|
|
1375
|
+
icon: AssignedCategoriesIcon,
|
|
1376
|
+
[DIMENSION_PROP_NO_ITEMS]: true,
|
|
1377
|
+
},
|
|
1378
|
+
});
|
|
1379
|
+
const getPredefinedDimensions = () => ({
|
|
1380
|
+
...getFixedDimensions(),
|
|
1381
|
+
...getDynamicDimensions(),
|
|
1382
|
+
});
|
|
1383
|
+
const filterOutPredefinedDimensions = (dimensionIds) => dimensionIds.filter((dimensionId) => !Object.keys(getPredefinedDimensions()).includes(dimensionId));
|
|
1384
|
+
const getPredefinedDimensionProp = (dimensionId, propName) => (getPredefinedDimensions()[dimensionId] || {})[propName];
|
|
1385
|
+
const getDimensionById = (dimensionId) => getPredefinedDimensions()[dimensionId];
|
|
1386
|
+
|
|
1387
|
+
const TRANSFER_OPTIONS_WIDTH = '420px';
|
|
1388
|
+
const TRANSFER_SELECTED_WIDTH = '298px';
|
|
1389
|
+
const TRANSFER_HEIGHT = '512px';
|
|
1390
|
+
|
|
1391
|
+
const formatList = (items) => {
|
|
1392
|
+
// Wrap Intl.ListFormat in try/catch as DHIS2 locales are not always ISO 639 compliant
|
|
1393
|
+
try {
|
|
1394
|
+
const formatter = new Intl.ListFormat(i18n.language, {
|
|
1395
|
+
style: 'long',
|
|
1396
|
+
type: 'conjunction',
|
|
1397
|
+
});
|
|
1398
|
+
return formatter.format(items);
|
|
1399
|
+
}
|
|
1400
|
+
catch (error) {
|
|
1401
|
+
return items.join(', ');
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
// Axis
|
|
1406
|
+
const AXIS = {
|
|
1407
|
+
defaultValue: [],
|
|
1408
|
+
isValid: (axis) => Array.isArray(axis),
|
|
1409
|
+
};
|
|
1410
|
+
// Axis ids
|
|
1411
|
+
const AXIS_ID_COLUMNS = 'columns';
|
|
1412
|
+
const AXIS_ID_ROWS = 'rows';
|
|
1413
|
+
const AXIS_ID_FILTERS = 'filters';
|
|
1414
|
+
const AXIS_ID_YEAR_OVER_YEAR_SERIES = 'yearOverYearSeries';
|
|
1415
|
+
const AXIS_ID_YEAR_OVER_YEAR_CATEGORY = 'yearOverYearCategory';
|
|
1416
|
+
//export const AXIS_ID_POINTS_CATEGORY = 'pointsCategory'
|
|
1417
|
+
const DEFAULT_AXIS_IDS = [
|
|
1418
|
+
AXIS_ID_COLUMNS,
|
|
1419
|
+
AXIS_ID_ROWS,
|
|
1420
|
+
AXIS_ID_FILTERS,
|
|
1421
|
+
];
|
|
1422
|
+
const ALL_AXIS_IDS = [
|
|
1423
|
+
AXIS_ID_COLUMNS,
|
|
1424
|
+
AXIS_ID_ROWS,
|
|
1425
|
+
AXIS_ID_FILTERS,
|
|
1426
|
+
AXIS_ID_YEAR_OVER_YEAR_SERIES,
|
|
1427
|
+
AXIS_ID_YEAR_OVER_YEAR_CATEGORY,
|
|
1428
|
+
];
|
|
1429
|
+
|
|
1430
|
+
// Dimension
|
|
1431
|
+
const DIMENSION = {
|
|
1432
|
+
isValid: (dimension) => isObject(dimension),
|
|
1433
|
+
};
|
|
1434
|
+
// Props
|
|
1435
|
+
const DIMENSION_PROP_ID = {
|
|
1436
|
+
name: 'dimension',
|
|
1437
|
+
defaultValue: '',
|
|
1438
|
+
required: true,
|
|
1439
|
+
isValid: (prop) => isString(prop),
|
|
1440
|
+
};
|
|
1441
|
+
const DIMENSION_PROP_ITEMS = {
|
|
1442
|
+
name: 'items',
|
|
1443
|
+
defaultValue: [],
|
|
1444
|
+
required: false,
|
|
1445
|
+
isValid: (prop) => Array.isArray(prop),
|
|
1446
|
+
};
|
|
1447
|
+
const DIMENSION_PROP_FILTER = {
|
|
1448
|
+
name: 'filter',
|
|
1449
|
+
defaultValue: [],
|
|
1450
|
+
required: false,
|
|
1451
|
+
isValid: (prop) => isString(prop),
|
|
1452
|
+
};
|
|
1453
|
+
const DIMENSION_PROP_LEGEND_SET = {
|
|
1454
|
+
name: 'legendSet',
|
|
1455
|
+
defaultValue: [],
|
|
1456
|
+
required: false,
|
|
1457
|
+
isValid: (prop) => isString(prop),
|
|
1458
|
+
};
|
|
1459
|
+
const DIMENSION_PROP_PROGRAM_STAGE = {
|
|
1460
|
+
name: 'programStage',
|
|
1461
|
+
defaultValue: {},
|
|
1462
|
+
required: false,
|
|
1463
|
+
isValid: (prop) => isObject(prop),
|
|
1464
|
+
};
|
|
1465
|
+
const DIMENSION_PROP_REPETITION = {
|
|
1466
|
+
name: 'repetition',
|
|
1467
|
+
defaultValue: [],
|
|
1468
|
+
required: false,
|
|
1469
|
+
isValid: (prop) => Array.isArray(prop),
|
|
1470
|
+
};
|
|
1471
|
+
const DIMENSION_PROPS = [
|
|
1472
|
+
DIMENSION_PROP_ID,
|
|
1473
|
+
DIMENSION_PROP_ITEMS,
|
|
1474
|
+
DIMENSION_PROP_FILTER,
|
|
1475
|
+
DIMENSION_PROP_LEGEND_SET,
|
|
1476
|
+
DIMENSION_PROP_PROGRAM_STAGE,
|
|
1477
|
+
DIMENSION_PROP_REPETITION,
|
|
1478
|
+
];
|
|
1479
|
+
|
|
1480
|
+
const dimensionIs = (dimension, dimensionId) => dimension[DIMENSION_PROP_ID.name] === dimensionId;
|
|
1481
|
+
|
|
1482
|
+
const axisGetDimension = (axis, dimensionId) => AXIS.isValid(axis) &&
|
|
1483
|
+
axis.find((dimension) => dimensionIs(dimension, dimensionId));
|
|
1484
|
+
|
|
1485
|
+
const axisHasDimension = (axis, dimensionId) => Boolean(axisGetDimension(axis, dimensionId));
|
|
1486
|
+
|
|
1487
|
+
const layoutReplaceDimension = (layout, dimensionId, items) => {
|
|
1488
|
+
const axisId = DEFAULT_AXIS_IDS.find((a) => axisHasDimension(layout[a], dimensionId));
|
|
1489
|
+
if (!axisId) {
|
|
1490
|
+
return Object.assign({}, layout);
|
|
1491
|
+
}
|
|
1492
|
+
const newAxisDimensions = layout[axisId].map((dimension) => {
|
|
1493
|
+
if (dimensionIs(dimension, dimensionId)) {
|
|
1494
|
+
return Object.assign({}, dimension, { items });
|
|
1495
|
+
}
|
|
1496
|
+
return dimension;
|
|
1497
|
+
});
|
|
1498
|
+
return Object.assign({}, layout, { [axisId]: newAxisDimensions });
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
const layoutGetAllAxes = (layout) => [
|
|
1502
|
+
layout[AXIS_ID_COLUMNS],
|
|
1503
|
+
layout[AXIS_ID_ROWS],
|
|
1504
|
+
layout[AXIS_ID_FILTERS],
|
|
1505
|
+
];
|
|
1506
|
+
|
|
1507
|
+
const layoutGetAllDimensions = (layout) => layoutGetAllAxes(layout).reduce((allDimensions, axis) => {
|
|
1508
|
+
allDimensions.push(...axis);
|
|
1509
|
+
return allDimensions;
|
|
1510
|
+
}, []);
|
|
1511
|
+
|
|
1512
|
+
const layoutGetDimension = (layout, dimensionId) => layoutGetAllDimensions(layout).find((dimension) => dimensionIs(dimension, dimensionId));
|
|
1513
|
+
|
|
1514
|
+
const dimensionIsEmpty = (dimension) => !(DIMENSION.isValid(dimension) &&
|
|
1515
|
+
DIMENSION_PROP_ITEMS.isValid(dimension[DIMENSION_PROP_ITEMS.name]) &&
|
|
1516
|
+
dimension[DIMENSION_PROP_ITEMS.name].length);
|
|
1517
|
+
|
|
1518
|
+
const dimensionIsValid = (dimension, { requireItems } = {}) => {
|
|
1519
|
+
if (!DIMENSION.isValid(dimension)) {
|
|
1520
|
+
return false;
|
|
1521
|
+
}
|
|
1522
|
+
const requiredProps = DIMENSION_PROPS.filter((prop) => prop.required);
|
|
1523
|
+
if (!requiredProps.every((prop) => prop.isValid(dimension[prop.name]))) {
|
|
1524
|
+
return false;
|
|
1525
|
+
}
|
|
1526
|
+
if (requireItems === true && dimensionIsEmpty(dimension)) {
|
|
1527
|
+
return false;
|
|
1528
|
+
}
|
|
1529
|
+
return true;
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
const dimensionGetItems = (dimension) => dimensionIsValid(dimension, { requireItems: true })
|
|
1533
|
+
? dimension[DIMENSION_PROP_ITEMS.name]
|
|
1534
|
+
: DIMENSION_PROP_ITEMS.defaultValue;
|
|
1535
|
+
|
|
1536
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
1537
|
+
// Use of this source code is governed by a BSD-style
|
|
1538
|
+
// license that can be found in the LICENSE file.
|
|
1539
|
+
|
|
1540
|
+
var styles$1 = `
|
|
1541
|
+
.filterContainer {
|
|
1542
|
+
display: flex;
|
|
1543
|
+
margin-bottom: ${spacers.dp12};
|
|
1544
|
+
margin-top: ${spacers.dp8};
|
|
1545
|
+
}
|
|
1546
|
+
.emptyList {
|
|
1547
|
+
text-align: center;
|
|
1548
|
+
font-size: 14px;
|
|
1549
|
+
line-height: 16px;
|
|
1550
|
+
margin: ${spacers.dp24} 0 0;
|
|
1551
|
+
color: ${colors.grey700};
|
|
1552
|
+
}
|
|
1553
|
+
.rightHeader {
|
|
1554
|
+
font-size: 14px;
|
|
1555
|
+
font-weight: 400;
|
|
1556
|
+
}
|
|
1557
|
+
.leftHeader {
|
|
1558
|
+
padding: ${spacers.dp12} ${spacers.dp4};
|
|
1559
|
+
}
|
|
1560
|
+
.info-container {
|
|
1561
|
+
display: flex;
|
|
1562
|
+
margin-bottom: ${spacers.dp8};
|
|
1563
|
+
padding: ${spacers.dp8};
|
|
1564
|
+
background-color: ${colors.grey200};
|
|
1565
|
+
border-radius: 3px;
|
|
1566
|
+
}
|
|
1567
|
+
.info-text {
|
|
1568
|
+
padding-left: ${spacers.dp8};
|
|
1569
|
+
color: ${colors.grey900};
|
|
1570
|
+
font-size: 12px;
|
|
1571
|
+
line-height: 16px;
|
|
1572
|
+
}
|
|
1573
|
+
.calculation-button {
|
|
1574
|
+
margin: ${spacers.dp8} 0;
|
|
1575
|
+
}
|
|
1576
|
+
`;
|
|
1577
|
+
|
|
1578
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
1579
|
+
// Use of this source code is governed by a BSD-style
|
|
1580
|
+
// license that can be found in the LICENSE file.
|
|
1581
|
+
|
|
1582
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
1583
|
+
// Use of this source code is governed by a BSD-style
|
|
1584
|
+
// license that can be found in the LICENSE file.
|
|
1585
|
+
|
|
1586
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
1587
|
+
// Use of this source code is governed by a BSD-style
|
|
1588
|
+
// license that can be found in the LICENSE file.
|
|
1589
|
+
const DAILY = 'DAILY';
|
|
1590
|
+
const WEEKLY = 'WEEKLY';
|
|
1591
|
+
const WEEKLYWED = 'WEEKLYWED';
|
|
1592
|
+
const WEEKLYTHU = 'WEEKLYTHU';
|
|
1593
|
+
const WEEKLYSAT = 'WEEKLYSAT';
|
|
1594
|
+
const WEEKLYSUN = 'WEEKLYSUN';
|
|
1595
|
+
const WEEKS_THIS_YEAR = 'WEEKS_THIS_YEAR';
|
|
1596
|
+
const BIWEEKLY = 'BIWEEKLY';
|
|
1597
|
+
const MONTHLY = 'MONTHLY';
|
|
1598
|
+
const BIMONTHLY = 'BIMONTHLY';
|
|
1599
|
+
const QUARTERLY = 'QUARTERLY';
|
|
1600
|
+
const SIXMONTHLY = 'SIXMONTHLY';
|
|
1601
|
+
const SIXMONTHLYAPR = 'SIXMONTHLYAPR';
|
|
1602
|
+
const YEARLY = 'YEARLY';
|
|
1603
|
+
const FINANCIAL = 'FINANCIAL';
|
|
1604
|
+
const FYNOV = 'FYNOV';
|
|
1605
|
+
const FYOCT = 'FYOCT';
|
|
1606
|
+
const FYJUL = 'FYJUL';
|
|
1607
|
+
const FYAPR = 'FYAPR';
|
|
1608
|
+
|
|
1609
|
+
const getDaysPeriodType = () => [
|
|
1610
|
+
{ id: 'TODAY', name: i18n.t('Today') },
|
|
1611
|
+
{ id: 'YESTERDAY', name: i18n.t('Yesterday') },
|
|
1612
|
+
{ id: 'LAST_3_DAYS', name: i18n.t('Last 3 days') },
|
|
1613
|
+
{ id: 'LAST_7_DAYS', name: i18n.t('Last 7 days') },
|
|
1614
|
+
{ id: 'LAST_14_DAYS', name: i18n.t('Last 14 days') },
|
|
1615
|
+
{ id: 'LAST_30_DAYS', name: i18n.t('Last 30 days') },
|
|
1616
|
+
{ id: 'LAST_60_DAYS', name: i18n.t('Last 60 days') },
|
|
1617
|
+
{ id: 'LAST_90_DAYS', name: i18n.t('Last 90 days') },
|
|
1618
|
+
{ id: 'LAST_180_DAYS', name: i18n.t('Last 180 days') },
|
|
1619
|
+
];
|
|
1620
|
+
const getWeeksPeriodType = () => [
|
|
1621
|
+
{ id: 'THIS_WEEK', name: i18n.t('This week') },
|
|
1622
|
+
{ id: 'LAST_WEEK', name: i18n.t('Last week') },
|
|
1623
|
+
{ id: 'LAST_4_WEEKS', name: i18n.t('Last 4 weeks') },
|
|
1624
|
+
{ id: 'LAST_12_WEEKS', name: i18n.t('Last 12 weeks') },
|
|
1625
|
+
{ id: 'LAST_52_WEEKS', name: i18n.t('Last 52 weeks') },
|
|
1626
|
+
{ id: WEEKS_THIS_YEAR, name: i18n.t('Weeks this year') },
|
|
1627
|
+
];
|
|
1628
|
+
const getBiWeeksPeriodType = () => [
|
|
1629
|
+
{ id: 'THIS_BIWEEK', name: i18n.t('This bi-week') },
|
|
1630
|
+
{ id: 'LAST_BIWEEK', name: i18n.t('Last bi-week') },
|
|
1631
|
+
{ id: 'LAST_4_BIWEEKS', name: i18n.t('Last 4 bi-weeks') },
|
|
1632
|
+
];
|
|
1633
|
+
const getMonthsPeriodType = () => [
|
|
1634
|
+
{ id: 'THIS_MONTH', name: i18n.t('This month') },
|
|
1635
|
+
{ id: 'LAST_MONTH', name: i18n.t('Last month') },
|
|
1636
|
+
{ id: 'LAST_3_MONTHS', name: i18n.t('Last 3 months') },
|
|
1637
|
+
{ id: 'LAST_6_MONTHS', name: i18n.t('Last 6 months') },
|
|
1638
|
+
{ id: 'LAST_12_MONTHS', name: i18n.t('Last 12 months') },
|
|
1639
|
+
{
|
|
1640
|
+
id: 'MONTHS_THIS_YEAR',
|
|
1641
|
+
name: i18n.t('Months this year'),
|
|
1642
|
+
},
|
|
1643
|
+
];
|
|
1644
|
+
const getBiMonthsPeriodType = () => [
|
|
1645
|
+
{ id: 'THIS_BIMONTH', name: i18n.t('This bi-month') },
|
|
1646
|
+
{ id: 'LAST_BIMONTH', name: i18n.t('Last bi-month') },
|
|
1647
|
+
{
|
|
1648
|
+
id: 'LAST_6_BIMONTHS',
|
|
1649
|
+
name: i18n.t('Last 6 bi-months'),
|
|
1650
|
+
},
|
|
1651
|
+
{
|
|
1652
|
+
id: 'BIMONTHS_THIS_YEAR',
|
|
1653
|
+
name: i18n.t('Bi-months this year'),
|
|
1654
|
+
},
|
|
1655
|
+
];
|
|
1656
|
+
const getQuartersPeriodType = () => [
|
|
1657
|
+
{ id: 'THIS_QUARTER', name: i18n.t('This quarter') },
|
|
1658
|
+
{ id: 'LAST_QUARTER', name: i18n.t('Last quarter') },
|
|
1659
|
+
{ id: 'LAST_4_QUARTERS', name: i18n.t('Last 4 quarters') },
|
|
1660
|
+
{
|
|
1661
|
+
id: 'QUARTERS_THIS_YEAR',
|
|
1662
|
+
name: i18n.t('Quarters this year'),
|
|
1663
|
+
},
|
|
1664
|
+
];
|
|
1665
|
+
const getSixMonthsPeriodType = () => [
|
|
1666
|
+
{ id: 'THIS_SIX_MONTH', name: i18n.t('This six-month') },
|
|
1667
|
+
{ id: 'LAST_SIX_MONTH', name: i18n.t('Last six-month') },
|
|
1668
|
+
{
|
|
1669
|
+
id: 'LAST_2_SIXMONTHS',
|
|
1670
|
+
name: i18n.t('Last 2 six-month'),
|
|
1671
|
+
},
|
|
1672
|
+
];
|
|
1673
|
+
const getFinancialYearsPeriodType = () => [
|
|
1674
|
+
{
|
|
1675
|
+
id: 'THIS_FINANCIAL_YEAR',
|
|
1676
|
+
name: i18n.t('This financial year'),
|
|
1677
|
+
},
|
|
1678
|
+
{
|
|
1679
|
+
id: 'LAST_FINANCIAL_YEAR',
|
|
1680
|
+
name: i18n.t('Last financial year'),
|
|
1681
|
+
},
|
|
1682
|
+
{
|
|
1683
|
+
id: 'LAST_5_FINANCIAL_YEARS',
|
|
1684
|
+
name: i18n.t('Last 5 financial years'),
|
|
1685
|
+
},
|
|
1686
|
+
];
|
|
1687
|
+
const getYearsPeriodType = () => [
|
|
1688
|
+
{ id: 'THIS_YEAR', name: i18n.t('This year') },
|
|
1689
|
+
{ id: 'LAST_YEAR', name: i18n.t('Last year') },
|
|
1690
|
+
{ id: 'LAST_5_YEARS', name: i18n.t('Last 5 years') },
|
|
1691
|
+
{ id: 'LAST_10_YEARS', name: i18n.t('Last 10 years') },
|
|
1692
|
+
];
|
|
1693
|
+
const getOptions$1 = () => [
|
|
1694
|
+
{
|
|
1695
|
+
id: DAILY,
|
|
1696
|
+
getPeriods: () => getDaysPeriodType(),
|
|
1697
|
+
name: i18n.t('Days'),
|
|
1698
|
+
},
|
|
1699
|
+
{
|
|
1700
|
+
id: WEEKLY,
|
|
1701
|
+
getPeriods: () => getWeeksPeriodType(),
|
|
1702
|
+
name: i18n.t('Weeks'),
|
|
1703
|
+
},
|
|
1704
|
+
{
|
|
1705
|
+
id: BIWEEKLY,
|
|
1706
|
+
getPeriods: () => getBiWeeksPeriodType(),
|
|
1707
|
+
name: i18n.t('Bi-weeks'),
|
|
1708
|
+
},
|
|
1709
|
+
{
|
|
1710
|
+
id: MONTHLY,
|
|
1711
|
+
getPeriods: () => getMonthsPeriodType(),
|
|
1712
|
+
name: i18n.t('Months'),
|
|
1713
|
+
},
|
|
1714
|
+
{
|
|
1715
|
+
id: BIMONTHLY,
|
|
1716
|
+
getPeriods: () => getBiMonthsPeriodType(),
|
|
1717
|
+
name: i18n.t('Bi-months'),
|
|
1718
|
+
},
|
|
1719
|
+
{
|
|
1720
|
+
id: QUARTERLY,
|
|
1721
|
+
getPeriods: () => getQuartersPeriodType(),
|
|
1722
|
+
name: i18n.t('Quarters'),
|
|
1723
|
+
},
|
|
1724
|
+
{
|
|
1725
|
+
id: SIXMONTHLY,
|
|
1726
|
+
getPeriods: () => getSixMonthsPeriodType(),
|
|
1727
|
+
name: i18n.t('Six-months'),
|
|
1728
|
+
},
|
|
1729
|
+
{
|
|
1730
|
+
id: FINANCIAL,
|
|
1731
|
+
getPeriods: () => getFinancialYearsPeriodType(),
|
|
1732
|
+
name: i18n.t('Financial Years'),
|
|
1733
|
+
},
|
|
1734
|
+
{
|
|
1735
|
+
id: YEARLY,
|
|
1736
|
+
getPeriods: () => getYearsPeriodType(),
|
|
1737
|
+
name: i18n.t('Years'),
|
|
1738
|
+
},
|
|
1739
|
+
];
|
|
1740
|
+
const getRelativePeriodsOptionsById = (id) => getOptions$1().find((option) => option.id === id);
|
|
1741
|
+
const getRelativePeriodsOptions = () => getOptions$1();
|
|
1742
|
+
const getRelativePeriodIds = () => Object.values(getOptions$1())
|
|
1743
|
+
.map((option) => option.getPeriods().map((period) => period.id))
|
|
1744
|
+
.flat();
|
|
1745
|
+
|
|
1746
|
+
const PERIOD_TYPE_REGEX = {
|
|
1747
|
+
[DAILY]: /^([0-9]{4})([0-9]{2})([0-9]{2})$/,
|
|
1748
|
+
[WEEKLY]: /^([0-9]{4})()W([0-9]{1,2})$/,
|
|
1749
|
+
[BIWEEKLY]: /^([0-9]{4})BiW([0-9]{1,2})$/,
|
|
1750
|
+
[WEEKLYWED]: /^([0-9]{4})(Wed)W([0-9]{1,2})$/,
|
|
1751
|
+
[WEEKLYTHU]: /^([0-9]{4})(Thu)W([0-9]{1,2})$/,
|
|
1752
|
+
[WEEKLYSAT]: /^([0-9]{4})(Sat)W([0-9]{1,2})$/,
|
|
1753
|
+
[WEEKLYSUN]: /^([0-9]{4})(Sun)W([0-9]{1,2})$/,
|
|
1754
|
+
[MONTHLY]: /^([0-9]{4})([0-9]{2})$/,
|
|
1755
|
+
[BIMONTHLY]: /^([0-9]{4})([0-9]{2})B$/,
|
|
1756
|
+
[QUARTERLY]: /^([0-9]{4})Q([1234])$/,
|
|
1757
|
+
[SIXMONTHLY]: /^([0-9]{4})S([12])$/,
|
|
1758
|
+
[SIXMONTHLYAPR]: /^([0-9]{4})AprilS([12])$/,
|
|
1759
|
+
// [SIXMONTHLYNOV]: /^([0-9]{4})NovS([12])$/, // YYYY"NovS"[1/2] Not supported?
|
|
1760
|
+
[YEARLY]: /^([0-9]{4})$/,
|
|
1761
|
+
[FYNOV]: /^([0-9]{4})Nov$/,
|
|
1762
|
+
[FYOCT]: /^([0-9]{4})Oct$/,
|
|
1763
|
+
[FYJUL]: /^([0-9]{4})July$/,
|
|
1764
|
+
[FYAPR]: /^([0-9]{4})April$/, // YYYY"April"
|
|
1765
|
+
};
|
|
1766
|
+
const getPeriods = ({ periodType, config, fnFilter, periodSettings = {}, }) => {
|
|
1767
|
+
const offset = parseInt(config.offset, 10);
|
|
1768
|
+
const isFilter = config.filterFuturePeriods;
|
|
1769
|
+
const isReverse = periodType.match(/^FY|YEARLY/)
|
|
1770
|
+
? true
|
|
1771
|
+
: config.reversePeriods;
|
|
1772
|
+
const { calendar = 'gregory', locale = 'en' } = periodSettings;
|
|
1773
|
+
const now = getNowInCalendar(calendar);
|
|
1774
|
+
const year = (now.eraYear || now.year) + offset;
|
|
1775
|
+
const params = {
|
|
1776
|
+
periodType,
|
|
1777
|
+
year,
|
|
1778
|
+
calendar,
|
|
1779
|
+
locale,
|
|
1780
|
+
startingDay: config.startDay,
|
|
1781
|
+
};
|
|
1782
|
+
let periods = generateFixedPeriods(params);
|
|
1783
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
1784
|
+
periods = !isReverse ? periods : periods.reverse();
|
|
1785
|
+
return periods;
|
|
1786
|
+
};
|
|
1787
|
+
const getDailyPeriodType = (fnFilter, periodSettings) => {
|
|
1788
|
+
return (config) => {
|
|
1789
|
+
return getPeriods({
|
|
1790
|
+
periodType: 'DAILY',
|
|
1791
|
+
config,
|
|
1792
|
+
fnFilter,
|
|
1793
|
+
periodSettings,
|
|
1794
|
+
});
|
|
1795
|
+
};
|
|
1796
|
+
};
|
|
1797
|
+
const getWeeklyPeriodType = (weekObj, fnFilter, periodSettings) => {
|
|
1798
|
+
return (config) => {
|
|
1799
|
+
return getPeriods({
|
|
1800
|
+
periodType: 'WEEKLY',
|
|
1801
|
+
config: {
|
|
1802
|
+
...config,
|
|
1803
|
+
startDay: weekObj.startDay,
|
|
1804
|
+
},
|
|
1805
|
+
fnFilter,
|
|
1806
|
+
periodSettings,
|
|
1807
|
+
});
|
|
1808
|
+
};
|
|
1809
|
+
};
|
|
1810
|
+
const getBiWeeklyPeriodType = (fnFilter, periodSettings) => {
|
|
1811
|
+
return (config) => {
|
|
1812
|
+
return getPeriods({
|
|
1813
|
+
periodType: 'BIWEEKLY',
|
|
1814
|
+
config,
|
|
1815
|
+
fnFilter,
|
|
1816
|
+
periodSettings,
|
|
1817
|
+
});
|
|
1818
|
+
};
|
|
1819
|
+
};
|
|
1820
|
+
const getMonthlyPeriodType = (fnFilter, periodSettings) => {
|
|
1821
|
+
return (config) => {
|
|
1822
|
+
return getPeriods({
|
|
1823
|
+
periodType: 'MONTHLY',
|
|
1824
|
+
config,
|
|
1825
|
+
fnFilter,
|
|
1826
|
+
periodSettings,
|
|
1827
|
+
});
|
|
1828
|
+
};
|
|
1829
|
+
};
|
|
1830
|
+
const getBiMonthlyPeriodType = (fnFilter, periodSettings) => {
|
|
1831
|
+
return (config) => {
|
|
1832
|
+
return getPeriods({
|
|
1833
|
+
periodType: 'BIMONTHLY',
|
|
1834
|
+
config,
|
|
1835
|
+
fnFilter,
|
|
1836
|
+
periodSettings,
|
|
1837
|
+
});
|
|
1838
|
+
};
|
|
1839
|
+
};
|
|
1840
|
+
const getQuarterlyPeriodType = (fnFilter, periodSettings) => {
|
|
1841
|
+
return (config) => {
|
|
1842
|
+
return getPeriods({
|
|
1843
|
+
periodType: 'QUARTERLY',
|
|
1844
|
+
config,
|
|
1845
|
+
fnFilter,
|
|
1846
|
+
periodSettings,
|
|
1847
|
+
});
|
|
1848
|
+
};
|
|
1849
|
+
};
|
|
1850
|
+
const getSixMonthlyPeriodType = (fnFilter, periodSettings) => {
|
|
1851
|
+
return (config) => {
|
|
1852
|
+
return getPeriods({
|
|
1853
|
+
periodType: 'SIXMONTHLY',
|
|
1854
|
+
config,
|
|
1855
|
+
fnFilter,
|
|
1856
|
+
periodSettings,
|
|
1857
|
+
});
|
|
1858
|
+
};
|
|
1859
|
+
};
|
|
1860
|
+
const getSixMonthlyAprilPeriodType = (fnFilter, periodSettings) => {
|
|
1861
|
+
return (config) => {
|
|
1862
|
+
return getPeriods({
|
|
1863
|
+
periodType: 'SIXMONTHLYAPR',
|
|
1864
|
+
config,
|
|
1865
|
+
fnFilter,
|
|
1866
|
+
periodSettings,
|
|
1867
|
+
});
|
|
1868
|
+
};
|
|
1869
|
+
};
|
|
1870
|
+
const getYearlyPeriodType = (fnFilter, periodSettings) => {
|
|
1871
|
+
return (config) => {
|
|
1872
|
+
return getPeriods({
|
|
1873
|
+
periodType: 'YEARLY',
|
|
1874
|
+
config,
|
|
1875
|
+
fnFilter,
|
|
1876
|
+
periodSettings,
|
|
1877
|
+
});
|
|
1878
|
+
};
|
|
1879
|
+
};
|
|
1880
|
+
const getFinancialOctoberPeriodType = (fnFilter, periodSettings) => {
|
|
1881
|
+
return (config) => {
|
|
1882
|
+
return getPeriods({
|
|
1883
|
+
periodType: 'FYOCT',
|
|
1884
|
+
config,
|
|
1885
|
+
fnFilter,
|
|
1886
|
+
periodSettings,
|
|
1887
|
+
});
|
|
1888
|
+
};
|
|
1889
|
+
};
|
|
1890
|
+
const getFinancialNovemberPeriodType = (fnFilter, periodSettings) => {
|
|
1891
|
+
return (config) => {
|
|
1892
|
+
return getPeriods({
|
|
1893
|
+
periodType: 'FYNOV',
|
|
1894
|
+
config,
|
|
1895
|
+
fnFilter,
|
|
1896
|
+
periodSettings,
|
|
1897
|
+
});
|
|
1898
|
+
};
|
|
1899
|
+
};
|
|
1900
|
+
const getFinancialJulyPeriodType = (fnFilter, periodSettings) => {
|
|
1901
|
+
return (config) => {
|
|
1902
|
+
return getPeriods({
|
|
1903
|
+
periodType: 'FYJUL',
|
|
1904
|
+
config,
|
|
1905
|
+
fnFilter,
|
|
1906
|
+
periodSettings,
|
|
1907
|
+
});
|
|
1908
|
+
};
|
|
1909
|
+
};
|
|
1910
|
+
const getFinancialAprilPeriodType = (fnFilter, periodSettings) => {
|
|
1911
|
+
return (config) => {
|
|
1912
|
+
return getPeriods({
|
|
1913
|
+
periodType: 'FYAPR',
|
|
1914
|
+
config,
|
|
1915
|
+
fnFilter,
|
|
1916
|
+
periodSettings,
|
|
1917
|
+
});
|
|
1918
|
+
};
|
|
1919
|
+
};
|
|
1920
|
+
const filterFuturePeriods = (periods) => {
|
|
1921
|
+
const array = [];
|
|
1922
|
+
const now = new Date(Date.now());
|
|
1923
|
+
for (let i = 0; i < periods.length; i++) {
|
|
1924
|
+
if (new Date(periods[i].startDate) <= now) {
|
|
1925
|
+
array.push(periods[i]);
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
return array;
|
|
1929
|
+
};
|
|
1930
|
+
const getOptions = (periodSettings) => {
|
|
1931
|
+
return [
|
|
1932
|
+
{
|
|
1933
|
+
id: DAILY,
|
|
1934
|
+
getPeriods: getDailyPeriodType(filterFuturePeriods, periodSettings),
|
|
1935
|
+
name: i18n.t('Daily'),
|
|
1936
|
+
},
|
|
1937
|
+
{
|
|
1938
|
+
id: WEEKLY,
|
|
1939
|
+
getPeriods: getWeeklyPeriodType({ startDay: 1 }, filterFuturePeriods, periodSettings),
|
|
1940
|
+
name: i18n.t('Weekly'),
|
|
1941
|
+
},
|
|
1942
|
+
{
|
|
1943
|
+
id: WEEKLYWED,
|
|
1944
|
+
getPeriods: getWeeklyPeriodType({ startDay: 3 }, filterFuturePeriods, periodSettings),
|
|
1945
|
+
name: i18n.t('Weekly (Start Wednesday)'),
|
|
1946
|
+
},
|
|
1947
|
+
{
|
|
1948
|
+
id: WEEKLYTHU,
|
|
1949
|
+
getPeriods: getWeeklyPeriodType({ startDay: 4 }, filterFuturePeriods, periodSettings),
|
|
1950
|
+
name: i18n.t('Weekly (Start Thursday)'),
|
|
1951
|
+
},
|
|
1952
|
+
{
|
|
1953
|
+
id: WEEKLYSAT,
|
|
1954
|
+
getPeriods: getWeeklyPeriodType({ startDay: 6 }, filterFuturePeriods, periodSettings),
|
|
1955
|
+
name: i18n.t('Weekly (Start Saturday)'),
|
|
1956
|
+
},
|
|
1957
|
+
{
|
|
1958
|
+
id: WEEKLYSUN,
|
|
1959
|
+
getPeriods: getWeeklyPeriodType({ startDay: 7 }, filterFuturePeriods, periodSettings),
|
|
1960
|
+
name: i18n.t('Weekly (Start Sunday)'),
|
|
1961
|
+
},
|
|
1962
|
+
{
|
|
1963
|
+
id: BIWEEKLY,
|
|
1964
|
+
getPeriods: getBiWeeklyPeriodType(filterFuturePeriods, periodSettings),
|
|
1965
|
+
name: i18n.t('Bi-weekly'),
|
|
1966
|
+
},
|
|
1967
|
+
{
|
|
1968
|
+
id: MONTHLY,
|
|
1969
|
+
getPeriods: getMonthlyPeriodType(filterFuturePeriods, periodSettings),
|
|
1970
|
+
name: i18n.t('Monthly'),
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
id: BIMONTHLY,
|
|
1974
|
+
getPeriods: getBiMonthlyPeriodType(filterFuturePeriods, periodSettings),
|
|
1975
|
+
name: i18n.t('Bi-monthly'),
|
|
1976
|
+
},
|
|
1977
|
+
{
|
|
1978
|
+
id: QUARTERLY,
|
|
1979
|
+
getPeriods: getQuarterlyPeriodType(filterFuturePeriods, periodSettings),
|
|
1980
|
+
name: i18n.t('Quarterly'),
|
|
1981
|
+
},
|
|
1982
|
+
{
|
|
1983
|
+
id: SIXMONTHLY,
|
|
1984
|
+
getPeriods: getSixMonthlyPeriodType(filterFuturePeriods, periodSettings),
|
|
1985
|
+
name: i18n.t('Six-monthly'),
|
|
1986
|
+
},
|
|
1987
|
+
{
|
|
1988
|
+
id: SIXMONTHLYAPR,
|
|
1989
|
+
getPeriods: getSixMonthlyAprilPeriodType(filterFuturePeriods, periodSettings),
|
|
1990
|
+
name: i18n.t('Six-monthly April'),
|
|
1991
|
+
},
|
|
1992
|
+
{
|
|
1993
|
+
id: YEARLY,
|
|
1994
|
+
getPeriods: getYearlyPeriodType(filterFuturePeriods, periodSettings),
|
|
1995
|
+
name: i18n.t('Yearly'),
|
|
1996
|
+
},
|
|
1997
|
+
{
|
|
1998
|
+
id: FYNOV,
|
|
1999
|
+
getPeriods: getFinancialNovemberPeriodType(filterFuturePeriods, periodSettings),
|
|
2000
|
+
name: i18n.t('Financial year (Start November)'),
|
|
2001
|
+
},
|
|
2002
|
+
{
|
|
2003
|
+
id: FYOCT,
|
|
2004
|
+
getPeriods: getFinancialOctoberPeriodType(filterFuturePeriods, periodSettings),
|
|
2005
|
+
name: i18n.t('Financial year (Start October)'),
|
|
2006
|
+
},
|
|
2007
|
+
{
|
|
2008
|
+
id: FYJUL,
|
|
2009
|
+
getPeriods: getFinancialJulyPeriodType(filterFuturePeriods, periodSettings),
|
|
2010
|
+
name: i18n.t('Financial year (Start July)'),
|
|
2011
|
+
},
|
|
2012
|
+
{
|
|
2013
|
+
id: FYAPR,
|
|
2014
|
+
getPeriods: getFinancialAprilPeriodType(filterFuturePeriods, periodSettings),
|
|
2015
|
+
name: i18n.t('Financial year (Start April)'),
|
|
2016
|
+
},
|
|
2017
|
+
];
|
|
2018
|
+
};
|
|
2019
|
+
const getFixedPeriodsOptionsById = (id, periodSettings) => {
|
|
2020
|
+
return getOptions(periodSettings).find((option) => option.id === id);
|
|
2021
|
+
};
|
|
2022
|
+
const getFixedPeriodsOptions = () => getOptions();
|
|
2023
|
+
const getYearOffsetFromNow = (yearStr) => parseInt(yearStr) - new Date(Date.now()).getFullYear();
|
|
2024
|
+
const parsePeriodCode = (code, allowedTypes) => {
|
|
2025
|
+
const periodTypes = Object.keys(PERIOD_TYPE_REGEX);
|
|
2026
|
+
let i = 0;
|
|
2027
|
+
let type = '';
|
|
2028
|
+
let match = undefined;
|
|
2029
|
+
while (i < periodTypes.length && !match) {
|
|
2030
|
+
type = periodTypes[i];
|
|
2031
|
+
match = code.match(PERIOD_TYPE_REGEX[type]);
|
|
2032
|
+
i++;
|
|
2033
|
+
}
|
|
2034
|
+
if (!match ||
|
|
2035
|
+
(Array.isArray(allowedTypes) && !allowedTypes.some((t) => t === type))) {
|
|
2036
|
+
return undefined;
|
|
2037
|
+
}
|
|
2038
|
+
const period = getFixedPeriodsOptionsById(type);
|
|
2039
|
+
const offset = getYearOffsetFromNow(match[1]);
|
|
2040
|
+
const options = period?.getPeriods({ offset });
|
|
2041
|
+
return period
|
|
2042
|
+
? {
|
|
2043
|
+
id: period.id,
|
|
2044
|
+
name: period.name,
|
|
2045
|
+
year: match[1],
|
|
2046
|
+
options,
|
|
2047
|
+
}
|
|
2048
|
+
: null;
|
|
2049
|
+
};
|
|
2050
|
+
|
|
2051
|
+
const filterPeriodTypesById = (allPeriodTypes = [], excludedPeriodTypes = []) => allPeriodTypes.filter((period) => !excludedPeriodTypes.includes(period['id']));
|
|
2052
|
+
|
|
2053
|
+
const FixedPeriodFilter = ({ allowedPeriodTypes, excludedPeriodTypes, currentPeriodType, currentYear, onSelectPeriodType, onSelectYear, dataTest, }) => {
|
|
2054
|
+
const onlyAllowedTypeIsSelected = Array.isArray(allowedPeriodTypes) &&
|
|
2055
|
+
allowedPeriodTypes.length === 1 &&
|
|
2056
|
+
allowedPeriodTypes[0] === currentPeriodType;
|
|
2057
|
+
return (React__default.createElement(React__default.Fragment, null,
|
|
2058
|
+
React__default.createElement("div", { className: "leftSection" },
|
|
2059
|
+
React__default.createElement(SingleSelectField, { label: i18n.t('Period type'), onChange: ({ selected }) => onSelectPeriodType(selected), dense: true, selected: currentPeriodType, disabled: onlyAllowedTypeIsSelected, className: "filterElement", dataTest: `${dataTest}-period-type` }, (allowedPeriodTypes
|
|
2060
|
+
? getFixedPeriodsOptions().filter((option) => allowedPeriodTypes.some((type) => type === option.id))
|
|
2061
|
+
: filterPeriodTypesById(getFixedPeriodsOptions(), excludedPeriodTypes)).map((option) => (React__default.createElement(SingleSelectOption, { key: option.id, value: option.id, label: option.name, dataTest: `${dataTest}-period-type-option-${option.id}` }))))),
|
|
2062
|
+
React__default.createElement("div", { className: "rightSection" },
|
|
2063
|
+
React__default.createElement(InputField$1, { label: i18n.t('Year'), className: "filterElement", type: "number", placeholder: i18n.t('Select year'), value: currentYear, onChange: ({ value }) => onSelectYear(value), dense: true, dataTest: `${dataTest}-year` })),
|
|
2064
|
+
React__default.createElement("style", { jsx: true }, `
|
|
2065
|
+
.leftSection {
|
|
2066
|
+
flex-grow: 1;
|
|
2067
|
+
}
|
|
2068
|
+
.leftSection > :global(.filterElement),
|
|
2069
|
+
.rightSection > :global(.filterElement) {
|
|
2070
|
+
margin: 0;
|
|
2071
|
+
}
|
|
2072
|
+
.rightSection {
|
|
2073
|
+
width: 120px;
|
|
2074
|
+
margin-left: ${spacers.dp8};
|
|
2075
|
+
}
|
|
2076
|
+
`)));
|
|
2077
|
+
};
|
|
2078
|
+
FixedPeriodFilter.defaultProps = {
|
|
2079
|
+
excludedPeriodTypes: [],
|
|
2080
|
+
};
|
|
2081
|
+
FixedPeriodFilter.propTypes = {
|
|
2082
|
+
currentPeriodType: PropTypes.string.isRequired,
|
|
2083
|
+
currentYear: PropTypes.string.isRequired,
|
|
2084
|
+
onSelectPeriodType: PropTypes.func.isRequired,
|
|
2085
|
+
onSelectYear: PropTypes.func.isRequired,
|
|
2086
|
+
allowedPeriodTypes: PropTypes.arrayOf(PropTypes.string),
|
|
2087
|
+
dataTest: PropTypes.string,
|
|
2088
|
+
excludedPeriodTypes: PropTypes.arrayOf(PropTypes.string),
|
|
2089
|
+
};
|
|
2090
|
+
|
|
2091
|
+
const RelativePeriodFilter = ({ currentFilter, onSelectFilter, dataTest, excludedPeriodTypes, }) => (React__default.createElement("div", { className: "leftSection" },
|
|
2092
|
+
React__default.createElement(SingleSelectField, { label: i18n.t('Period type'), onChange: ({ selected }) => onSelectFilter(selected), dense: true, selected: currentFilter, className: "filterElement", dataTest: dataTest }, filterPeriodTypesById(getRelativePeriodsOptions(), excludedPeriodTypes).map((option) => (React__default.createElement(SingleSelectOption, { key: option.id, value: option.id, label: option.name, dataTest: `${dataTest}-option-${option.id}` })))),
|
|
2093
|
+
React__default.createElement("style", { jsx: true }, `
|
|
2094
|
+
.leftSection {
|
|
2095
|
+
flex-grow: 1;
|
|
2096
|
+
}
|
|
2097
|
+
.leftSection > :global(.filterElement),
|
|
2098
|
+
.rightSection > :global(.filterElement) {
|
|
2099
|
+
margin: 0;
|
|
2100
|
+
}
|
|
2101
|
+
.rightSection {
|
|
2102
|
+
width: 120px;
|
|
2103
|
+
margin-left: ${spacers.dp8};
|
|
2104
|
+
}
|
|
2105
|
+
`)));
|
|
2106
|
+
RelativePeriodFilter.propTypes = {
|
|
2107
|
+
currentFilter: PropTypes.string.isRequired,
|
|
2108
|
+
onSelectFilter: PropTypes.func.isRequired,
|
|
2109
|
+
dataTest: PropTypes.string,
|
|
2110
|
+
excludedPeriodTypes: PropTypes.arrayOf(PropTypes.string),
|
|
2111
|
+
};
|
|
2112
|
+
|
|
2113
|
+
var PeriodIcon = (React__default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 16 16" },
|
|
2114
|
+
React__default.createElement("path", { fill: "#6E7A8A", d: "M8,4 C10.209139,4 12,5.790861 12,8 C12,10.209139 10.209139,12 8,12 C5.790861,12 4,10.209139 4,8 C4,5.790861 5.790861,4 8,4 Z M8,5 C6.34314575,5 5,6.34314575 5,8 C5,9.65685425 6.34314575,11 8,11 C9.65685425,11 11,9.65685425 11,8 C11,6.34314575 9.65685425,5 8,5 Z M8.5,6 L8.5,7.5 L9.5,7.5 L9.5,8.5 L7.5,8.5 L7.5,6 L8.5,6 Z" })));
|
|
2115
|
+
|
|
2116
|
+
const PeriodTransfer = ({ onSelect, dataTest, initialSelectedPeriods, rightFooter, excludedPeriodTypes, periodsSettings, }) => {
|
|
2117
|
+
const defaultRelativePeriodType = excludedPeriodTypes.includes(MONTHLY)
|
|
2118
|
+
? getRelativePeriodsOptionsById(QUARTERLY)
|
|
2119
|
+
: getRelativePeriodsOptionsById(MONTHLY);
|
|
2120
|
+
const defaultFixedPeriodType = excludedPeriodTypes.includes(MONTHLY)
|
|
2121
|
+
? getFixedPeriodsOptionsById(QUARTERLY, periodsSettings)
|
|
2122
|
+
: getFixedPeriodsOptionsById(MONTHLY, periodsSettings);
|
|
2123
|
+
const now = getNowInCalendar(periodsSettings.calendar);
|
|
2124
|
+
// use ".eraYear" rather than ".year" because in Ethiopian calendar, eraYear is what our users expect to see (for other calendars, it doesn't matter)
|
|
2125
|
+
// there is still a pending decision in Temporal regarding which era to use by default: https://github.com/js-temporal/temporal-polyfill/blob/9350ee7dd0d29f329fc097debf923a517c32f813/lib/calendar.ts#L1964
|
|
2126
|
+
const defaultFixedPeriodYear = now.eraYear || now.year;
|
|
2127
|
+
const fixedPeriodConfig = (year) => ({
|
|
2128
|
+
offset: year - defaultFixedPeriodYear,
|
|
2129
|
+
filterFuturePeriods: false,
|
|
2130
|
+
reversePeriods: false,
|
|
2131
|
+
});
|
|
2132
|
+
const [allPeriods, setAllPeriods] = useState(defaultRelativePeriodType?.getPeriods() || []);
|
|
2133
|
+
const [selectedPeriods, setSelectedPeriods] = useState(initialSelectedPeriods);
|
|
2134
|
+
const [isRelative, setIsRelative] = useState(true);
|
|
2135
|
+
const [relativeFilter, setRelativeFilter] = useState({
|
|
2136
|
+
periodType: defaultRelativePeriodType?.id || '',
|
|
2137
|
+
});
|
|
2138
|
+
const [fixedFilter, setFixedFilter] = useState({
|
|
2139
|
+
periodType: defaultFixedPeriodType?.id || '',
|
|
2140
|
+
year: defaultFixedPeriodYear.toString(),
|
|
2141
|
+
});
|
|
2142
|
+
const onIsRelativeClick = (state) => {
|
|
2143
|
+
if (state !== isRelative) {
|
|
2144
|
+
setIsRelative(state);
|
|
2145
|
+
setAllPeriods(state
|
|
2146
|
+
? getRelativePeriodsOptionsById(relativeFilter.periodType)?.getPeriods() || []
|
|
2147
|
+
: getFixedPeriodsOptionsById(fixedFilter.periodType, periodsSettings)?.getPeriods(fixedPeriodConfig(Number(fixedFilter.year))) || []);
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
const renderLeftHeader = () => (React__default.createElement(React__default.Fragment, null,
|
|
2151
|
+
React__default.createElement(TabBar, null,
|
|
2152
|
+
React__default.createElement(Tab, { selected: isRelative, onClick: () => onIsRelativeClick(true), dataTest: `${dataTest}-relative-periods-button` }, i18n.t('Relative periods')),
|
|
2153
|
+
React__default.createElement(Tab, { selected: !isRelative, onClick: () => onIsRelativeClick(false), dataTest: `${dataTest}-fixed-periods-button` }, i18n.t('Fixed periods'))),
|
|
2154
|
+
React__default.createElement("div", { className: "filterContainer" }, isRelative ? (React__default.createElement(RelativePeriodFilter, { currentFilter: relativeFilter.periodType, onSelectFilter: (filter) => {
|
|
2155
|
+
setRelativeFilter({ periodType: filter });
|
|
2156
|
+
setAllPeriods(getRelativePeriodsOptionsById(filter)?.getPeriods() || []);
|
|
2157
|
+
}, dataTest: `${dataTest}-relative-period-filter`, excludedPeriodTypes: excludedPeriodTypes })) : (React__default.createElement(FixedPeriodFilter, { currentPeriodType: fixedFilter.periodType, currentYear: fixedFilter.year, onSelectPeriodType: (periodType) => {
|
|
2158
|
+
onSelectFixedPeriods({
|
|
2159
|
+
periodType,
|
|
2160
|
+
year: fixedFilter.year,
|
|
2161
|
+
});
|
|
2162
|
+
}, onSelectYear: (year) => {
|
|
2163
|
+
onSelectFixedPeriods({
|
|
2164
|
+
periodType: fixedFilter.periodType,
|
|
2165
|
+
year,
|
|
2166
|
+
});
|
|
2167
|
+
}, dataTest: `${dataTest}-fixed-period-filter`, excludedPeriodTypes: excludedPeriodTypes }))),
|
|
2168
|
+
React__default.createElement("style", { jsx: true }, styles$1)));
|
|
2169
|
+
const renderRightHeader = () => (React__default.createElement(React__default.Fragment, null,
|
|
2170
|
+
React__default.createElement("p", { className: "rightHeader" }, i18n.t('Selected Periods')),
|
|
2171
|
+
React__default.createElement("style", { jsx: true }, styles$1)));
|
|
2172
|
+
const onSelectFixedPeriods = (filter) => {
|
|
2173
|
+
setFixedFilter(filter);
|
|
2174
|
+
setAllPeriods((getFixedPeriodsOptionsById(filter.periodType, periodsSettings)?.getPeriods(fixedPeriodConfig(Number(filter.year))) || []));
|
|
2175
|
+
};
|
|
2176
|
+
const renderEmptySelection = () => (React__default.createElement(React__default.Fragment, null,
|
|
2177
|
+
React__default.createElement("p", { className: "emptyList" }, i18n.t('No periods selected')),
|
|
2178
|
+
React__default.createElement("style", { jsx: true }, styles$1)));
|
|
2179
|
+
return (React__default.createElement(Transfer, { onChange: ({ selected }) => {
|
|
2180
|
+
const formattedItems = selected.map((id) => ({
|
|
2181
|
+
id,
|
|
2182
|
+
name: [...allPeriods, ...selectedPeriods].find((item) => item.id === id).name,
|
|
2183
|
+
}));
|
|
2184
|
+
setSelectedPeriods(formattedItems);
|
|
2185
|
+
onSelect(formattedItems);
|
|
2186
|
+
}, selected: selectedPeriods.map((period) => period.id), leftHeader: renderLeftHeader(), enableOrderChange: true, height: TRANSFER_HEIGHT, optionsWidth: TRANSFER_OPTIONS_WIDTH, selectedWidth: TRANSFER_SELECTED_WIDTH, selectedEmptyComponent: renderEmptySelection(), rightHeader: renderRightHeader(), rightFooter: rightFooter, options: [...allPeriods, ...selectedPeriods].map(({ id, name }) => ({
|
|
2187
|
+
label: name,
|
|
2188
|
+
value: id,
|
|
2189
|
+
})), renderOption: (props) => (React__default.createElement(TransferOption, { ...props, icon: PeriodIcon, dataTest: `${dataTest}-transfer-option` })), dataTest: `${dataTest}-transfer` }));
|
|
2190
|
+
};
|
|
2191
|
+
PeriodTransfer.defaultProps = {
|
|
2192
|
+
initialSelectedPeriods: [],
|
|
2193
|
+
excludedPeriodTypes: [],
|
|
2194
|
+
periodsSettings: {
|
|
2195
|
+
calendar: 'gregory',
|
|
2196
|
+
locale: 'en',
|
|
2197
|
+
},
|
|
2198
|
+
};
|
|
2199
|
+
PeriodTransfer.propTypes = {
|
|
2200
|
+
onSelect: PropTypes.func.isRequired,
|
|
2201
|
+
dataTest: PropTypes.string,
|
|
2202
|
+
excludedPeriodTypes: PropTypes.arrayOf(PropTypes.string),
|
|
2203
|
+
initialSelectedPeriods: PropTypes.arrayOf(PropTypes.shape({
|
|
2204
|
+
id: PropTypes.string,
|
|
2205
|
+
name: PropTypes.string,
|
|
2206
|
+
})),
|
|
2207
|
+
periodsSettings: PropTypes.shape({
|
|
2208
|
+
calendar: PropTypes.string,
|
|
2209
|
+
locale: PropTypes.string,
|
|
2210
|
+
}),
|
|
2211
|
+
rightFooter: PropTypes.node,
|
|
2212
|
+
};
|
|
2213
|
+
|
|
2214
|
+
const userSettingsQuery = {
|
|
2215
|
+
userSettings: {
|
|
2216
|
+
resource: 'userSettings',
|
|
2217
|
+
params: {
|
|
2218
|
+
key: ['keyUiLocale'],
|
|
2219
|
+
},
|
|
2220
|
+
},
|
|
2221
|
+
};
|
|
2222
|
+
const PeriodDimension = ({ onSelect, selectedPeriods, rightFooter, excludedPeriodTypes, systemInfo, }) => {
|
|
2223
|
+
const result = useDataQuery(userSettingsQuery);
|
|
2224
|
+
const { calendar = 'gregory' } = systemInfo;
|
|
2225
|
+
// const { data: { userSettings: { keyUiLocale: locale } = {} } = {} } =
|
|
2226
|
+
// result as any;
|
|
2227
|
+
const locale = result.data && result.data['userSettings']
|
|
2228
|
+
? result.data['userSettings']['keyUiLocale']
|
|
2229
|
+
: '';
|
|
2230
|
+
const periodsSettings = { calendar, locale };
|
|
2231
|
+
const selectPeriods = (periods) => {
|
|
2232
|
+
onSelect({
|
|
2233
|
+
dimensionId: DIMENSION_ID_PERIOD,
|
|
2234
|
+
items: periods,
|
|
2235
|
+
});
|
|
2236
|
+
};
|
|
2237
|
+
return (React__default.createElement(PeriodTransfer, { onSelect: selectPeriods, initialSelectedPeriods: selectedPeriods, rightFooter: rightFooter, dataTest: 'period-dimension', excludedPeriodTypes: excludedPeriodTypes, periodsSettings: periodsSettings }));
|
|
2238
|
+
};
|
|
2239
|
+
PeriodDimension.propTypes = {
|
|
2240
|
+
onSelect: PropTypes.func.isRequired,
|
|
2241
|
+
excludedPeriodTypes: PropTypes.arrayOf(PropTypes.string),
|
|
2242
|
+
rightFooter: PropTypes.node,
|
|
2243
|
+
selectedPeriods: PropTypes.array,
|
|
2244
|
+
systemInfo: PropTypes.object,
|
|
2245
|
+
};
|
|
2246
|
+
PeriodDimension.defaultProps = {
|
|
2247
|
+
selectedPeriods: [],
|
|
2248
|
+
};
|
|
2249
|
+
|
|
2250
|
+
class PeriodSelectorComponent extends ReactWrapperComponent {
|
|
2251
|
+
constructor(elementRef, httpClient) {
|
|
2252
|
+
super(elementRef);
|
|
2253
|
+
this.httpClient = httpClient;
|
|
2254
|
+
this.selectedPeriods = [];
|
|
2255
|
+
this.selectPeriods = new EventEmitter();
|
|
2256
|
+
this.props = {
|
|
2257
|
+
onSelect: (e) => {
|
|
2258
|
+
this.onSelectItems(e);
|
|
2259
|
+
},
|
|
2260
|
+
};
|
|
2261
|
+
this.getExcludedPeriodTypes = (systemSettings = {}) => {
|
|
2262
|
+
const types = [];
|
|
2263
|
+
if (systemSettings['hideDailyPeriods']) {
|
|
2264
|
+
types.push(DAILY);
|
|
2265
|
+
}
|
|
2266
|
+
if (systemSettings['hideWeeklyPeriods']) {
|
|
2267
|
+
types.push(WEEKLY, WEEKLYWED, WEEKLYTHU, WEEKLYSAT, WEEKLYSUN);
|
|
2268
|
+
}
|
|
2269
|
+
if (systemSettings['hideBiWeeklyPeriods']) {
|
|
2270
|
+
types.push(BIWEEKLY);
|
|
2271
|
+
}
|
|
2272
|
+
if (systemSettings['hideMonthlyPeriods']) {
|
|
2273
|
+
types.push(MONTHLY);
|
|
2274
|
+
}
|
|
2275
|
+
if (systemSettings['hideBiMonthlyPeriods']) {
|
|
2276
|
+
types.push(BIMONTHLY);
|
|
2277
|
+
}
|
|
2278
|
+
return types;
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
async ngAfterViewInit() {
|
|
2282
|
+
if (!this.elementRef)
|
|
2283
|
+
throw new Error('No element ref');
|
|
2284
|
+
this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
|
|
2285
|
+
const systemInfo = await firstValueFrom(this.httpClient.systemInfo());
|
|
2286
|
+
const excludedPeriodTypes = this.getExcludedPeriodTypes(systemInfo);
|
|
2287
|
+
this.component = () => (React__default.createElement(DataProvider, null, React__default.createElement(PeriodDimension, { selectedPeriods: this.selectedPeriods, onSelect: (selectionEvent) => this.onSelectItems(selectionEvent), excludedPeriodTypes: excludedPeriodTypes, systemInfo: systemInfo })));
|
|
2288
|
+
this.render();
|
|
2289
|
+
}
|
|
2290
|
+
onSelectItems(selectionEvent) {
|
|
2291
|
+
this.selectPeriods.emit(selectionEvent.items);
|
|
2292
|
+
}
|
|
2293
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PeriodSelectorComponent, deps: [{ token: i0.ElementRef }, { token: i1.NgxDhis2HttpClientService }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2294
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: PeriodSelectorComponent, selector: "ng-dhis2-ui-period-selector", inputs: { selectedPeriods: "selectedPeriods" }, outputs: { selectPeriods: "selectPeriods" }, usesInheritance: true, ngImport: i0, template: `<ng-container></ng-container>`, isInline: true, styles: ["::ng-deep .content-container{z-index:0!important}\n"] }); }
|
|
2295
|
+
}
|
|
2296
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PeriodSelectorComponent, decorators: [{
|
|
2297
|
+
type: Component,
|
|
2298
|
+
args: [{ selector: 'ng-dhis2-ui-period-selector', template: `<ng-container></ng-container>`, styles: ["::ng-deep .content-container{z-index:0!important}\n"] }]
|
|
2299
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }]; }, propDecorators: { selectedPeriods: [{
|
|
2300
|
+
type: Input
|
|
2301
|
+
}], selectPeriods: [{
|
|
2302
|
+
type: Output
|
|
2303
|
+
}] } });
|
|
2304
|
+
|
|
2305
|
+
class PeriodSelectorModule {
|
|
2306
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PeriodSelectorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
2307
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: PeriodSelectorModule, declarations: [PeriodSelectorComponent], imports: [CommonModule, SharedDhis2UiModule], exports: [PeriodSelectorComponent] }); }
|
|
2308
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PeriodSelectorModule, imports: [CommonModule, SharedDhis2UiModule] }); }
|
|
2309
|
+
}
|
|
2310
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PeriodSelectorModule, decorators: [{
|
|
2311
|
+
type: NgModule,
|
|
2312
|
+
args: [{
|
|
2313
|
+
imports: [CommonModule, SharedDhis2UiModule],
|
|
2314
|
+
declarations: [PeriodSelectorComponent],
|
|
2315
|
+
exports: [PeriodSelectorComponent],
|
|
2316
|
+
}]
|
|
2317
|
+
}] });
|
|
2318
|
+
|
|
2319
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
2320
|
+
// Use of this source code is governed by a BSD-style
|
|
2321
|
+
// license that can be found in the LICENSE file.
|
|
2322
|
+
|
|
2323
|
+
const LEVEL_ID_PREFIX = 'LEVEL';
|
|
2324
|
+
const GROUP_ID_PREFIX = 'OU_GROUP';
|
|
2325
|
+
const USER_ORG_UNIT = 'USER_ORGUNIT';
|
|
2326
|
+
const USER_ORG_UNIT_CHILDREN = 'USER_ORGUNIT_CHILDREN';
|
|
2327
|
+
const USER_ORG_UNIT_GRANDCHILDREN = 'USER_ORGUNIT_GRANDCHILDREN';
|
|
2328
|
+
const hasGroupPrefix = (id) => id.substr(0, GROUP_ID_PREFIX.length) === GROUP_ID_PREFIX;
|
|
2329
|
+
const hasLevelPrefix = (id) => id.substr(0, LEVEL_ID_PREFIX.length) === LEVEL_ID_PREFIX;
|
|
2330
|
+
const stripLevelPrefix = (id) => hasLevelPrefix(id) ? id.substr(LEVEL_ID_PREFIX.length + 1) : id;
|
|
2331
|
+
const stripGroupPrefix = (id) => hasGroupPrefix(id) ? id.substr(GROUP_ID_PREFIX.length + 1) : id;
|
|
2332
|
+
const removePrefix = (id) => stripGroupPrefix(stripLevelPrefix(id));
|
|
2333
|
+
const ouIdHelper = Object.freeze({
|
|
2334
|
+
addLevelPrefix: (id) => `${LEVEL_ID_PREFIX}-${removePrefix(id)}`,
|
|
2335
|
+
addGroupPrefix: (id) => `${GROUP_ID_PREFIX}-${removePrefix(id)}`,
|
|
2336
|
+
removePrefix,
|
|
2337
|
+
hasGroupPrefix,
|
|
2338
|
+
hasLevelPrefix,
|
|
2339
|
+
});
|
|
2340
|
+
|
|
2341
|
+
const isOuLevelIntId = (id) => ouIdHelper.hasLevelPrefix(id)
|
|
2342
|
+
? Number.isInteger(parseInt(ouIdHelper.removePrefix(id), 10))
|
|
2343
|
+
: false;
|
|
2344
|
+
const replaceNumericOuLevelWithUid = (ouLevels) => (item) => {
|
|
2345
|
+
if (!isOuLevelIntId(item.id)) {
|
|
2346
|
+
return item;
|
|
2347
|
+
}
|
|
2348
|
+
const ouIntId = parseInt(ouIdHelper.removePrefix(item.id), 10);
|
|
2349
|
+
const ouUid = ouLevels.find((l) => parseInt(l.level, 10) === ouIntId)?.id;
|
|
2350
|
+
return ouUid
|
|
2351
|
+
? Object.assign({}, item, { id: ouIdHelper.addLevelPrefix(ouUid) })
|
|
2352
|
+
: item;
|
|
2353
|
+
};
|
|
2354
|
+
const convertOuLevelsToUids = (ouLevels, layout) => {
|
|
2355
|
+
const ouDimension = layoutGetDimension(layout, DIMENSION_ID_ORGUNIT);
|
|
2356
|
+
const hasNumericOuLevels = ouDimension &&
|
|
2357
|
+
dimensionGetItems(ouDimension).some((item) => isOuLevelIntId(item.id));
|
|
2358
|
+
if (hasNumericOuLevels) {
|
|
2359
|
+
const replaceNumericOuLevel = replaceNumericOuLevelWithUid(ouLevels);
|
|
2360
|
+
const updatedOuItems = dimensionGetItems(ouDimension).map(replaceNumericOuLevel);
|
|
2361
|
+
return layoutReplaceDimension(layout, DIMENSION_ID_ORGUNIT, updatedOuItems);
|
|
2362
|
+
}
|
|
2363
|
+
return layout;
|
|
2364
|
+
};
|
|
2365
|
+
|
|
2366
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
2367
|
+
// Use of this source code is governed by a BSD-style
|
|
2368
|
+
// license that can be found in the LICENSE file.
|
|
2369
|
+
|
|
2370
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
2371
|
+
// Use of this source code is governed by a BSD-style
|
|
2372
|
+
// license that can be found in the LICENSE file.
|
|
2373
|
+
|
|
2374
|
+
const styles = `
|
|
2375
|
+
.container {
|
|
2376
|
+
height: 100%;
|
|
2377
|
+
display: flex;
|
|
2378
|
+
flex-direction: column;
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
.orgUnitTreeWrapper {
|
|
2382
|
+
height: 382px;
|
|
2383
|
+
flex-grow: 1;
|
|
2384
|
+
overflow: auto;
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
.orgUnitTreeWrapper > :global(*) {
|
|
2388
|
+
flex-grow: 1;
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
.disabled {
|
|
2392
|
+
cursor: not-allowed;
|
|
2393
|
+
opacity: 0.5;
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
.disabled > :global(*) {
|
|
2397
|
+
pointer-events: none;
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
.userOrgUnitsWrapper {
|
|
2401
|
+
display: flex;
|
|
2402
|
+
background: ${colors.grey200};
|
|
2403
|
+
padding: ${spacers.dp8} ${spacers.dp8} ${spacers.dp8} ${spacers.dp24};
|
|
2404
|
+
margin-bottom: ${spacers.dp12};
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
.userOrgUnitsWrapper > :global(*) {
|
|
2408
|
+
margin-right: ${spacers.dp48};
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
.selectsWrapper {
|
|
2412
|
+
display: flex;
|
|
2413
|
+
align-items: flex-start;
|
|
2414
|
+
gap: ${spacers.dp8};
|
|
2415
|
+
margin-top: ${spacers.dp12};
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
.selectsWrapper.hidden {
|
|
2419
|
+
display: none;
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
.selectsWrapper > :global(*) {
|
|
2423
|
+
width: 50%;
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
.summaryWrapper {
|
|
2427
|
+
display: inline-flex;
|
|
2428
|
+
align-items: center;
|
|
2429
|
+
margin-top: ${spacers.dp8};
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
.warningWrapper {
|
|
2433
|
+
display: inline-flex;
|
|
2434
|
+
align-items: center;
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
.warningText {
|
|
2438
|
+
margin-left: ${spacers.dp8};
|
|
2439
|
+
font-size: 14px;
|
|
2440
|
+
line-height: 18px;
|
|
2441
|
+
color: ${colors.red600};
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
.summaryText {
|
|
2445
|
+
font-size: 14px;
|
|
2446
|
+
line-height: 18px;
|
|
2447
|
+
color: ${colors.grey700};
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
.deselectButton {
|
|
2451
|
+
display: inline-block;
|
|
2452
|
+
margin-left: ${spacers.dp8};
|
|
2453
|
+
}
|
|
2454
|
+
`;
|
|
2455
|
+
|
|
2456
|
+
const DYNAMIC_ORG_UNITS = [
|
|
2457
|
+
USER_ORG_UNIT,
|
|
2458
|
+
USER_ORG_UNIT_CHILDREN,
|
|
2459
|
+
USER_ORG_UNIT_GRANDCHILDREN,
|
|
2460
|
+
];
|
|
2461
|
+
const OrgUnitDimension = ({ roots, selected, onSelect, hideGroupSelect, hideLevelSelect, hideUserOrgUnits, warning, orgUnitGroupPromise, orgUnitLevelPromise, }) => {
|
|
2462
|
+
const [ouLevels, setOuLevels] = useState([]);
|
|
2463
|
+
const [ouGroups, setOuGroups] = useState([]);
|
|
2464
|
+
const [selectedItems, setSelectedItems] = useState(selected);
|
|
2465
|
+
const dataEngine = useDataEngine();
|
|
2466
|
+
const onSelectItems = (selectedItem) => {
|
|
2467
|
+
const { id, checked, displayName, path } = selectedItem;
|
|
2468
|
+
let result = [...selectedItems];
|
|
2469
|
+
if (checked && DYNAMIC_ORG_UNITS.includes(id)) {
|
|
2470
|
+
result = [
|
|
2471
|
+
...result.filter((item) => DYNAMIC_ORG_UNITS.includes(item.id)),
|
|
2472
|
+
{ id, displayName },
|
|
2473
|
+
];
|
|
2474
|
+
}
|
|
2475
|
+
else if (checked) {
|
|
2476
|
+
result.push({ id, path, name: displayName });
|
|
2477
|
+
}
|
|
2478
|
+
else {
|
|
2479
|
+
result = [...result.filter((item) => item.id !== id)];
|
|
2480
|
+
}
|
|
2481
|
+
setSelectedItems(result);
|
|
2482
|
+
onSelect({
|
|
2483
|
+
dimensionId: DIMENSION_ID_ORGUNIT,
|
|
2484
|
+
items: result,
|
|
2485
|
+
});
|
|
2486
|
+
};
|
|
2487
|
+
const clearSelection = () => {
|
|
2488
|
+
setSelectedItems([]);
|
|
2489
|
+
onSelect({
|
|
2490
|
+
dimensionId: DIMENSION_ID_ORGUNIT,
|
|
2491
|
+
items: [],
|
|
2492
|
+
});
|
|
2493
|
+
};
|
|
2494
|
+
useEffect(() => {
|
|
2495
|
+
const doFetchOuLevels = async () => {
|
|
2496
|
+
const result = await orgUnitLevelPromise;
|
|
2497
|
+
result.sort((a, b) => (a.level > b.level ? 1 : -1));
|
|
2498
|
+
setOuLevels(result);
|
|
2499
|
+
};
|
|
2500
|
+
const doFetchOuGroups = async () => {
|
|
2501
|
+
const result = await orgUnitGroupPromise;
|
|
2502
|
+
setOuGroups(result);
|
|
2503
|
+
};
|
|
2504
|
+
!hideLevelSelect && doFetchOuLevels();
|
|
2505
|
+
!hideGroupSelect && doFetchOuGroups();
|
|
2506
|
+
}, [dataEngine, hideLevelSelect, hideGroupSelect]);
|
|
2507
|
+
const onLevelChange = (ids) => {
|
|
2508
|
+
const items = ids.map((id) => ({
|
|
2509
|
+
id: ouIdHelper.addLevelPrefix(id),
|
|
2510
|
+
name: ouLevels?.find((level) => level.id === id)
|
|
2511
|
+
?.displayName,
|
|
2512
|
+
}));
|
|
2513
|
+
setSelectedItems([
|
|
2514
|
+
...selectedItems.filter((ou) => !ouIdHelper.hasLevelPrefix(ou.id)),
|
|
2515
|
+
...items,
|
|
2516
|
+
]);
|
|
2517
|
+
onSelect({
|
|
2518
|
+
dimensionId: DIMENSION_ID_ORGUNIT,
|
|
2519
|
+
items: selectedItems,
|
|
2520
|
+
});
|
|
2521
|
+
};
|
|
2522
|
+
const onGroupChange = (ids) => {
|
|
2523
|
+
const items = ids.map((id) => ({
|
|
2524
|
+
id: ouIdHelper.addGroupPrefix(id),
|
|
2525
|
+
name: (ouGroups?.find((group) => group.id === id) || {})
|
|
2526
|
+
.displayName,
|
|
2527
|
+
}));
|
|
2528
|
+
setSelectedItems([
|
|
2529
|
+
...selectedItems.filter((ou) => !ouIdHelper.hasGroupPrefix(ou.id)),
|
|
2530
|
+
...items,
|
|
2531
|
+
]);
|
|
2532
|
+
onSelect({
|
|
2533
|
+
dimensionId: DIMENSION_ID_ORGUNIT,
|
|
2534
|
+
items: selectedItems,
|
|
2535
|
+
});
|
|
2536
|
+
};
|
|
2537
|
+
const getSummary = () => {
|
|
2538
|
+
let summary;
|
|
2539
|
+
if (selectedItems.length) {
|
|
2540
|
+
const numberOfOrgUnits = selectedItems.filter((item) => !DYNAMIC_ORG_UNITS.includes(item.id) &&
|
|
2541
|
+
!ouIdHelper.hasLevelPrefix(item.id) &&
|
|
2542
|
+
!ouIdHelper.hasGroupPrefix(item.id)).length;
|
|
2543
|
+
const numberOfLevels = selectedItems.filter((item) => ouIdHelper.hasLevelPrefix(item.id)).length;
|
|
2544
|
+
const numberOfGroups = selectedItems.filter((item) => ouIdHelper.hasGroupPrefix(item.id)).length;
|
|
2545
|
+
const userOrgUnits = selectedItems.filter((item) => DYNAMIC_ORG_UNITS.includes(item.id));
|
|
2546
|
+
const parts = [];
|
|
2547
|
+
if (numberOfOrgUnits) {
|
|
2548
|
+
parts.push(i18n.t('{{count}} org units', {
|
|
2549
|
+
count: numberOfOrgUnits,
|
|
2550
|
+
defaultValue: '{{count}} org unit',
|
|
2551
|
+
defaultValue_plural: '{{count}} org units',
|
|
2552
|
+
}));
|
|
2553
|
+
}
|
|
2554
|
+
if (numberOfLevels) {
|
|
2555
|
+
parts.push(i18n.t('{{count}} levels', {
|
|
2556
|
+
count: numberOfLevels,
|
|
2557
|
+
defaultValue: '{{count}} level',
|
|
2558
|
+
defaultValue_plural: '{{count}} levels',
|
|
2559
|
+
}));
|
|
2560
|
+
}
|
|
2561
|
+
if (numberOfGroups) {
|
|
2562
|
+
parts.push(i18n.t('{{count}} groups', {
|
|
2563
|
+
count: numberOfGroups,
|
|
2564
|
+
defaultValue: '{{count}} group',
|
|
2565
|
+
defaultValue_plural: '{{count}} groups',
|
|
2566
|
+
}));
|
|
2567
|
+
}
|
|
2568
|
+
userOrgUnits.forEach((orgUnit) => {
|
|
2569
|
+
parts.push(orgUnit.name || orgUnit.displayName);
|
|
2570
|
+
});
|
|
2571
|
+
summary = i18n.t('Selected: {{commaSeparatedListOfOrganisationUnits}}', {
|
|
2572
|
+
keySeparator: '>',
|
|
2573
|
+
nsSeparator: '|',
|
|
2574
|
+
commaSeparatedListOfOrganisationUnits: formatList(parts),
|
|
2575
|
+
});
|
|
2576
|
+
}
|
|
2577
|
+
else {
|
|
2578
|
+
summary = i18n.t('Nothing selected');
|
|
2579
|
+
}
|
|
2580
|
+
return summary;
|
|
2581
|
+
};
|
|
2582
|
+
return (React__default.createElement("div", { className: "container" },
|
|
2583
|
+
!hideUserOrgUnits && (React__default.createElement("div", { className: "userOrgUnitsWrapper" },
|
|
2584
|
+
React__default.createElement(Checkbox, { label: i18n.t('User organisation unit'), checked: selectedItems.some((item) => item.id === USER_ORG_UNIT), onChange: ({ checked }) => onSelectItems({
|
|
2585
|
+
id: USER_ORG_UNIT,
|
|
2586
|
+
checked,
|
|
2587
|
+
displayName: i18n.t('User organisation unit'),
|
|
2588
|
+
}), dense: true }),
|
|
2589
|
+
React__default.createElement(Checkbox, { label: i18n.t('User sub-units'), checked: selectedItems.some((item) => item.id === USER_ORG_UNIT_CHILDREN), onChange: ({ checked }) => onSelectItems({
|
|
2590
|
+
id: USER_ORG_UNIT_CHILDREN,
|
|
2591
|
+
checked,
|
|
2592
|
+
displayName: i18n.t('User sub-units'),
|
|
2593
|
+
}), dense: true }),
|
|
2594
|
+
React__default.createElement(Checkbox, { label: i18n.t('User sub-x2-units'), checked: selectedItems.some((item) => item.id === USER_ORG_UNIT_GRANDCHILDREN), onChange: ({ checked }) => onSelectItems({
|
|
2595
|
+
id: USER_ORG_UNIT_GRANDCHILDREN,
|
|
2596
|
+
checked,
|
|
2597
|
+
displayName: i18n.t('User sub-x2-units'),
|
|
2598
|
+
}), dense: true }))),
|
|
2599
|
+
React__default.createElement("div", { className: cx('orgUnitTreeWrapper', {
|
|
2600
|
+
disabled: selectedItems.some((item) => DYNAMIC_ORG_UNITS.includes(item.id)),
|
|
2601
|
+
}) },
|
|
2602
|
+
React__default.createElement(OrganisationUnitTree, { roots: roots, initiallyExpanded: [
|
|
2603
|
+
...(roots.length === 1 ? [`/${roots[0]}`] : []),
|
|
2604
|
+
...selectedItems
|
|
2605
|
+
.filter((item) => !DYNAMIC_ORG_UNITS.includes(item.id) &&
|
|
2606
|
+
!ouIdHelper.hasLevelPrefix(item.id) &&
|
|
2607
|
+
!ouIdHelper.hasGroupPrefix(item.id))
|
|
2608
|
+
.map((item) => item.path.substring(0, item.path.lastIndexOf('/')))
|
|
2609
|
+
.filter((path) => path),
|
|
2610
|
+
], selected: selectedItems
|
|
2611
|
+
.filter((item) => !DYNAMIC_ORG_UNITS.includes(item.id) &&
|
|
2612
|
+
!ouIdHelper.hasLevelPrefix(item.id) &&
|
|
2613
|
+
!ouIdHelper.hasGroupPrefix(item.id))
|
|
2614
|
+
.map((item) => item.path), onChange: onSelectItems, dataTest: 'org-unit-tree' })),
|
|
2615
|
+
React__default.createElement("div", { className: cx('selectsWrapper', {
|
|
2616
|
+
disabled: selectedItems.some((item) => DYNAMIC_ORG_UNITS.includes(item.id)),
|
|
2617
|
+
hidden: hideLevelSelect && hideGroupSelect,
|
|
2618
|
+
}) },
|
|
2619
|
+
!hideLevelSelect && (React__default.createElement(MultiSelect, { selected: ouLevels.length
|
|
2620
|
+
? selectedItems
|
|
2621
|
+
.filter((item) => ouIdHelper.hasLevelPrefix(item.id))
|
|
2622
|
+
.map((item) => ouIdHelper.removePrefix(item.id))
|
|
2623
|
+
: [], onChange: ({ selected }) => onLevelChange(selected), placeholder: i18n.t('Select a level'), loading: !ouLevels.length, dense: true, dataTest: 'org-unit-level-select' }, ouLevels.map((level) => (React__default.createElement(MultiSelectOption, { key: level.id, value: level.id, label: level.displayName, dataTest: `org-unit-level-select-option-${level.id}` }))))),
|
|
2624
|
+
!hideGroupSelect && (React__default.createElement(MultiSelect, { selected: ouGroups.length
|
|
2625
|
+
? selectedItems
|
|
2626
|
+
.filter((item) => ouIdHelper.hasGroupPrefix(item.id))
|
|
2627
|
+
.map((item) => ouIdHelper.removePrefix(item.id))
|
|
2628
|
+
: [], onChange: ({ selected }) => onGroupChange(selected), placeholder: i18n.t('Select a group'), loading: !ouGroups.length, dense: true, dataTest: 'org-unit-group-select' }, ouGroups.map((group) => (React__default.createElement(MultiSelectOption, { key: group.id, value: group.id, label: group.displayName, dataTest: `org-unit-group-select-option-${group.id}` })))))),
|
|
2629
|
+
React__default.createElement("div", { className: "summaryWrapper" },
|
|
2630
|
+
warning ? (React__default.createElement("div", { className: "warningWrapper" },
|
|
2631
|
+
React__default.createElement(IconWarningFilled16, { color: colors.red500 }),
|
|
2632
|
+
React__default.createElement("span", { className: "warningText" }, warning))) : (React__default.createElement("span", { className: "summaryText" }, getSummary())),
|
|
2633
|
+
React__default.createElement("div", { className: "deselectButton" },
|
|
2634
|
+
React__default.createElement(Button$1, { secondary: true, small: true, onClick: clearSelection, disabled: !selectedItems.length }, i18n.t('Deselect all')))),
|
|
2635
|
+
React__default.createElement("style", { jsx: true }, styles)));
|
|
2636
|
+
};
|
|
2637
|
+
OrgUnitDimension.defaultProps = {
|
|
2638
|
+
hideGroupSelect: false,
|
|
2639
|
+
hideLevelSelect: false,
|
|
2640
|
+
hideUserOrgUnits: false,
|
|
2641
|
+
};
|
|
2642
|
+
OrgUnitDimension.propTypes = {
|
|
2643
|
+
hideGroupSelect: PropTypes.bool,
|
|
2644
|
+
hideLevelSelect: PropTypes.bool,
|
|
2645
|
+
hideUserOrgUnits: PropTypes.bool,
|
|
2646
|
+
roots: PropTypes.arrayOf(PropTypes.string),
|
|
2647
|
+
selected: PropTypes.arrayOf(PropTypes.shape({
|
|
2648
|
+
id: PropTypes.string.isRequired,
|
|
2649
|
+
name: PropTypes.string.isRequired,
|
|
2650
|
+
path: PropTypes.string,
|
|
2651
|
+
})),
|
|
2652
|
+
warning: PropTypes.string,
|
|
2653
|
+
onSelect: PropTypes.func,
|
|
2654
|
+
orgUnitGroupPromise: PropTypes.any,
|
|
2655
|
+
orgUnitLevelPromise: PropTypes.any,
|
|
2656
|
+
};
|
|
2657
|
+
|
|
2658
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
2659
|
+
// Use of this source code is governed by a BSD-style
|
|
2660
|
+
// license that can be found in the LICENSE file.
|
|
2661
|
+
class OrganisationUnitSelectionConfig {
|
|
2662
|
+
constructor(params) {
|
|
2663
|
+
this.hideGroupSelect = params?.hideGroupSelect || false;
|
|
2664
|
+
this.hideLevelSelect = params?.hideLevelSelect || false;
|
|
2665
|
+
this.hideUserOrgUnits = params?.hideUserOrgUnits || false;
|
|
2666
|
+
this.usageType = params?.usageType || 'DATA_ENTRY';
|
|
2667
|
+
this.minLevel = params?.minLevel;
|
|
2668
|
+
this.allowSingleSelection = params?.allowSingleSelection || false;
|
|
2669
|
+
this.batchSize = params?.batchSize;
|
|
2670
|
+
this.additionalQueryFields = params?.additionalQueryFields;
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2674
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
2675
|
+
// Use of this source code is governed by a BSD-style
|
|
2676
|
+
// license that can be found in the LICENSE file.
|
|
2677
|
+
|
|
2678
|
+
class OrganisationUnitSelectorComponent extends ReactWrapperComponent {
|
|
2679
|
+
constructor(elementRef, httpClient) {
|
|
2680
|
+
super(elementRef);
|
|
2681
|
+
this.httpClient = httpClient;
|
|
2682
|
+
this.selectedOrgUnits = [];
|
|
2683
|
+
this.orgUnitSelectionConfig = new OrganisationUnitSelectionConfig();
|
|
2684
|
+
this.selectOrgUnits = new EventEmitter();
|
|
2685
|
+
this.props = {
|
|
2686
|
+
onSelect: (e) => {
|
|
2687
|
+
this.onSelectItems(e);
|
|
2688
|
+
},
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
async ngAfterViewInit() {
|
|
2692
|
+
if (!this.elementRef)
|
|
2693
|
+
throw new Error('No element ref');
|
|
2694
|
+
this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
|
|
2695
|
+
const rootOrgUnits = await this.getRootOrgUnits();
|
|
2696
|
+
this.component = () => (React__default.createElement(DataProvider, null, React__default.createElement(OrgUnitDimension, { selected: this.selectedOrgUnits, hideGroupSelect: this.orgUnitSelectionConfig.hideGroupSelect, hideLevelSelect: this.orgUnitSelectionConfig.hideLevelSelect, hideUserOrgUnits: this.orgUnitSelectionConfig.hideUserOrgUnits, onSelect: (selectionEvent) => this.onSelectItems(selectionEvent), orgUnitGroupPromise: this.getOrgUnitGroups(), orgUnitLevelPromise: this.getOrgUnitLevels(), roots: rootOrgUnits })));
|
|
2697
|
+
this.render();
|
|
2698
|
+
}
|
|
2699
|
+
getOrgUnitAttributeByUsage(usageType) {
|
|
2700
|
+
switch (usageType) {
|
|
2701
|
+
case 'DATA_ENTRY':
|
|
2702
|
+
return 'organisationUnits';
|
|
2703
|
+
case 'DATA_VIEW':
|
|
2704
|
+
return 'dataViewOrganisationUnits';
|
|
2705
|
+
default:
|
|
2706
|
+
return 'organisationUnits';
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
getRootOrgUnits() {
|
|
2710
|
+
const orgUnitAttribute = this.getOrgUnitAttributeByUsage(this.orgUnitSelectionConfig.usageType);
|
|
2711
|
+
return firstValueFrom(this.httpClient
|
|
2712
|
+
.me()
|
|
2713
|
+
.pipe(map((user) => (user ? user[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id))));
|
|
2714
|
+
}
|
|
2715
|
+
getOrgUnitGroups() {
|
|
2716
|
+
return firstValueFrom(this.httpClient
|
|
2717
|
+
.get('organisationUnitGroups.json?fields=id,displayName,name&paging=false')
|
|
2718
|
+
.pipe(map((res) => res?.['organisationUnitGroups'])));
|
|
2719
|
+
}
|
|
2720
|
+
getOrgUnitLevels() {
|
|
2721
|
+
return firstValueFrom(this.httpClient
|
|
2722
|
+
.get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false')
|
|
2723
|
+
.pipe(map((res) => res?.['organisationUnitLevels'])));
|
|
2724
|
+
}
|
|
2725
|
+
onSelectItems(selectionEvent) {
|
|
2726
|
+
this.selectOrgUnits.emit(selectionEvent.items);
|
|
2727
|
+
}
|
|
2728
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: OrganisationUnitSelectorComponent, deps: [{ token: i0.ElementRef }, { token: i1.NgxDhis2HttpClientService }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2729
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: OrganisationUnitSelectorComponent, selector: "ng-dhis2-ui-org-unit-selector", inputs: { selectedOrgUnits: "selectedOrgUnits", orgUnitSelectionConfig: "orgUnitSelectionConfig" }, outputs: { selectOrgUnits: "selectOrgUnits" }, usesInheritance: true, ngImport: i0, template: '<ng-container><ng-container>', isInline: true }); }
|
|
2730
|
+
}
|
|
2731
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: OrganisationUnitSelectorComponent, decorators: [{
|
|
2732
|
+
type: Component,
|
|
2733
|
+
args: [{
|
|
2734
|
+
selector: 'ng-dhis2-ui-org-unit-selector',
|
|
2735
|
+
template: '<ng-container><ng-container>',
|
|
2736
|
+
}]
|
|
2737
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }]; }, propDecorators: { selectedOrgUnits: [{
|
|
2738
|
+
type: Input
|
|
2739
|
+
}], orgUnitSelectionConfig: [{
|
|
2740
|
+
type: Input
|
|
2741
|
+
}], selectOrgUnits: [{
|
|
2742
|
+
type: Output
|
|
2743
|
+
}] } });
|
|
2744
|
+
|
|
2745
|
+
class OrganisationUnitSelectorModule {
|
|
2746
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: OrganisationUnitSelectorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
2747
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: OrganisationUnitSelectorModule, declarations: [OrganisationUnitSelectorComponent], imports: [CommonModule, SharedDhis2UiModule], exports: [OrganisationUnitSelectorComponent] }); }
|
|
2748
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: OrganisationUnitSelectorModule, imports: [CommonModule, SharedDhis2UiModule] }); }
|
|
2749
|
+
}
|
|
2750
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: OrganisationUnitSelectorModule, decorators: [{
|
|
2751
|
+
type: NgModule,
|
|
2752
|
+
args: [{
|
|
2753
|
+
imports: [CommonModule, SharedDhis2UiModule],
|
|
2754
|
+
declarations: [OrganisationUnitSelectorComponent],
|
|
2755
|
+
exports: [OrganisationUnitSelectorComponent],
|
|
2756
|
+
}]
|
|
2757
|
+
}] });
|
|
2758
|
+
|
|
2759
|
+
// Copyright 2023 UDSM DHIS2 Lab. All rights reserved.
|
|
2760
|
+
// Use of this source code is governed by a BSD-style
|
|
2761
|
+
// license that can be found in the LICENSE file.
|
|
2762
|
+
|
|
1188
2763
|
/**
|
|
1189
2764
|
* Generated bundle index. Do not edit.
|
|
1190
2765
|
*/
|
|
1191
2766
|
|
|
1192
|
-
export { ButtonComponent, ButtonModule, HeaderBarComponent, HeaderBarModule, NgDhis2UiModule };
|
|
2767
|
+
export { ButtonComponent, ButtonModule, HeaderBarComponent, HeaderBarModule, NgDhis2UiModule, OrganisationUnitSelectorComponent, OrganisationUnitSelectorModule, PeriodSelectorComponent, PeriodSelectorModule, ReactWrapperComponent, ReactWrapperModule };
|
|
1193
2768
|
//# sourceMappingURL=iapps-ng-dhis2-ui.mjs.map
|