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