@gpa-gemstone/common-pages 0.0.123 → 0.0.125

Sign up to get free protection for your applications and to get access to all the features.
package/lib/TimeFilter.js DELETED
@@ -1,273 +0,0 @@
1
- "use strict";
2
- //******************************************************************************************************
3
- // TimeFilter.tsx - Gbtc
4
- //
5
- // Copyright © 2020, Grid Protection Alliance. All Rights Reserved.
6
- //
7
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
- // file except in compliance with the License. You may obtain a copy of the License at:
11
- //
12
- // http://opensource.org/licenses/MIT
13
- //
14
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
- // License for the specific language governing permissions and limitations.
17
- //
18
- // Code Modification History:
19
- // ----------------------------------------------------------------------------------------------------
20
- // 09/16/2021 - Christoph Lackner
21
- // Generated original version of source code.
22
- // 06/20/2024 - Ali Karrar
23
- // Moved TimeFilter from SEBrowser to gemstone
24
- //******************************************************************************************************
25
- var __assign = (this && this.__assign) || function () {
26
- __assign = Object.assign || function(t) {
27
- for (var s, i = 1, n = arguments.length; i < n; i++) {
28
- s = arguments[i];
29
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
30
- t[p] = s[p];
31
- }
32
- return t;
33
- };
34
- return __assign.apply(this, arguments);
35
- };
36
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
37
- if (k2 === undefined) k2 = k;
38
- var desc = Object.getOwnPropertyDescriptor(m, k);
39
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
40
- desc = { enumerable: true, get: function() { return m[k]; } };
41
- }
42
- Object.defineProperty(o, k2, desc);
43
- }) : (function(o, m, k, k2) {
44
- if (k2 === undefined) k2 = k;
45
- o[k2] = m[k];
46
- }));
47
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
48
- Object.defineProperty(o, "default", { enumerable: true, value: v });
49
- }) : function(o, v) {
50
- o["default"] = v;
51
- });
52
- var __importStar = (this && this.__importStar) || function (mod) {
53
- if (mod && mod.__esModule) return mod;
54
- var result = {};
55
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
56
- __setModuleDefault(result, mod);
57
- return result;
58
- };
59
- var __importDefault = (this && this.__importDefault) || function (mod) {
60
- return (mod && mod.__esModule) ? mod : { "default": mod };
61
- };
62
- Object.defineProperty(exports, "__esModule", { value: true });
63
- exports.getTimeWindow = getTimeWindow;
64
- var React = __importStar(require("react"));
65
- var moment_1 = __importDefault(require("moment"));
66
- var react_forms_1 = require("@gpa-gemstone/react-forms");
67
- var TimeWindowUtils_1 = require("./TimeWindowUtils");
68
- var QuickSelects_1 = require("./TimeFilter/QuickSelects");
69
- // Converts ITimeFilter to an ITimeWindow filter
70
- function getTimeWindow(flt, format) {
71
- var _a, _b;
72
- var _c, _d, _e;
73
- var center, start, end, unit, duration, halfDuration;
74
- if ('center' in flt && 'halfDuration' in flt) { // type is ICenterDuration
75
- center = (0, TimeWindowUtils_1.getMoment)(flt.center, format);
76
- _a = (0, TimeWindowUtils_1.getStartEndTime)(center, flt.halfDuration, flt.unit), start = _a[0], end = _a[1];
77
- unit = flt.unit;
78
- halfDuration = flt.halfDuration;
79
- duration = halfDuration * 2;
80
- }
81
- else if ('start' in flt && 'duration' in flt) { // type is IStartDuration
82
- start = (0, TimeWindowUtils_1.getMoment)(flt.start, format);
83
- var d = moment_1.default.duration(flt.duration / 2.0, flt.unit);
84
- center = start.clone().add(d);
85
- end = center.clone().add(d);
86
- unit = flt.unit;
87
- duration = flt.duration,
88
- halfDuration = duration / 2.0;
89
- }
90
- else if ('end' in flt && 'duration' in flt) { // type is IEndDuration
91
- end = (0, TimeWindowUtils_1.getMoment)(flt.end, format);
92
- var d = moment_1.default.duration(flt.duration / 2.0, flt.unit);
93
- center = end.clone().subtract(d);
94
- start = center.clone().subtract(d);
95
- unit = flt.unit;
96
- duration = flt.duration,
97
- halfDuration = duration / 2.0;
98
- }
99
- else if ('start' in flt && 'end' in flt) { // type is IStartEnd
100
- start = (0, TimeWindowUtils_1.getMoment)(flt.start, format);
101
- end = (0, TimeWindowUtils_1.getMoment)(flt.end, format);
102
- _b = (0, TimeWindowUtils_1.findAppropriateUnit)(start, end, undefined, true), unit = _b[0], halfDuration = _b[1];
103
- var d = moment_1.default.duration(halfDuration, unit);
104
- center = start.clone().add(d);
105
- duration = halfDuration * 2;
106
- }
107
- return { center: (_c = center === null || center === void 0 ? void 0 : center.format(format)) !== null && _c !== void 0 ? _c : '',
108
- start: (_d = start === null || start === void 0 ? void 0 : start.format(format)) !== null && _d !== void 0 ? _d : '',
109
- end: (_e = end === null || end === void 0 ? void 0 : end.format(format)) !== null && _e !== void 0 ? _e : '',
110
- unit: unit !== null && unit !== void 0 ? unit : 'ms',
111
- duration: duration !== null && duration !== void 0 ? duration : 0,
112
- halfDuration: halfDuration !== null && halfDuration !== void 0 ? halfDuration : 0 };
113
- }
114
- // Returns a row div element with props as children of row
115
- function Row(props) {
116
- var _a;
117
- if (props.addRow) {
118
- return React.createElement("div", { className: "row ".concat((_a = props.class) !== null && _a !== void 0 ? _a : '') }, props.children);
119
- }
120
- return React.createElement(React.Fragment, null, props.children);
121
- }
122
- var TimeFilter = function (props) {
123
- var _a, _b, _c;
124
- var format = (0, QuickSelects_1.getFormat)(props.format);
125
- var QuickSelects = React.useMemo(function () { return QuickSelects_1.AvailableQuickSelects.filter(function (qs) { return !qs.hideQuickPick(props.format); }); }, [props.format]);
126
- var _d = React.useState(-1), activeQP = _d[0], setActiveQP = _d[1];
127
- var _e = React.useState(getTimeWindow(props.filter, format)), filter = _e[0], setFilter = _e[1];
128
- React.useEffect(function () {
129
- if (!isEqual(filter, props.filter))
130
- props.setFilter(filter.center, filter.start, filter.end, filter.unit, filter.duration);
131
- }, [filter]);
132
- //Checks typing of ITimeFilter and then compares to ITimeWindow
133
- function isEqual(flt1, flt2) {
134
- var flt = getTimeWindow(flt2, format);
135
- return flt1.center == flt.center &&
136
- flt1.unit == flt.unit &&
137
- flt1.duration == flt.duration;
138
- }
139
- React.useEffect(function () {
140
- if (!isEqual(filter, props.filter)) {
141
- var flt = getTimeWindow(props.filter, format);
142
- setFilter(flt);
143
- }
144
- }, [props.filter]);
145
- return (React.createElement("fieldset", { className: "border", style: { padding: '10px', height: '100%' } },
146
- React.createElement("legend", { className: "w-auto", style: { fontSize: 'large' } }, "Date/Time Filter:"),
147
- React.createElement(Row, { addRow: props.isHorizontal },
148
- props.dateTimeSetting === 'center' ?
149
- React.createElement(Row, { addRow: !props.isHorizontal },
150
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-2' : 'col-6') : 'col-12' },
151
- React.createElement(react_forms_1.DatePicker, { Record: filter, Field: "center", Help: "All times are in system time. System time is currently set to ".concat(props.timeZone, ". "), Setter: function (r) {
152
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { center: r.center, start: r.start, end: r.end })); });
153
- setActiveQP(-1);
154
- }, Label: 'Time Window Center:', Type: (_a = props.format) !== null && _a !== void 0 ? _a : 'datetime-local', Valid: function () { return true; }, Format: format })))
155
- : null,
156
- props.dateTimeSetting === 'startWindow' || props.dateTimeSetting === 'startEnd' ?
157
- React.createElement(Row, { addRow: !props.isHorizontal },
158
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-2' : 'col-6') : 'col-12' },
159
- React.createElement(react_forms_1.DatePicker, { Record: filter, Field: "start", Help: "All times are in system time. System time is currently set to ".concat(props.timeZone, ". "), Setter: function (r) {
160
- var _a;
161
- var halfDur = filter.halfDuration;
162
- var unit = filter.unit;
163
- if (props.dateTimeSetting === 'startEnd') {
164
- _a = (0, TimeWindowUtils_1.findAppropriateUnit)((0, TimeWindowUtils_1.getMoment)(r.start, format), (0, TimeWindowUtils_1.getMoment)(filter.end, format), undefined, true), unit = _a[0], halfDur = _a[1];
165
- }
166
- var flt = getTimeWindow({ start: r.start, duration: halfDur * 2, unit: unit }, format);
167
- setFilter(flt);
168
- setActiveQP(-1);
169
- }, Label: 'Start of Time Window:', Type: (_b = props.format) !== null && _b !== void 0 ? _b : 'datetime-local', Valid: function () { return true; }, Format: format })))
170
- : null,
171
- props.dateTimeSetting === 'endWindow' || props.dateTimeSetting === 'startEnd' ?
172
- React.createElement(Row, { addRow: !props.isHorizontal },
173
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-2' : 'col-6') : 'col-12' },
174
- React.createElement(react_forms_1.DatePicker, { Record: filter, Field: "end", Help: "All times are in system time. System time is currently set to ".concat(props.timeZone, ". "), Setter: function (r) {
175
- var _a;
176
- var halfDur = filter.halfDuration;
177
- var unit = filter.unit;
178
- if (props.dateTimeSetting === 'startEnd') {
179
- _a = (0, TimeWindowUtils_1.findAppropriateUnit)((0, TimeWindowUtils_1.getMoment)(filter.start, format), (0, TimeWindowUtils_1.getMoment)(r.end, format), undefined, true), unit = _a[0], halfDur = _a[1];
180
- }
181
- var flt = getTimeWindow({ end: r.end, duration: halfDur * 2, unit: unit }, format);
182
- setFilter(flt);
183
- setActiveQP(-1);
184
- }, Label: 'End of Time Window :', Type: (_c = props.format) !== null && _c !== void 0 ? _c : 'datetime-local', Valid: function () { return true; }, Format: format })))
185
- : null,
186
- props.dateTimeSetting === 'center' ?
187
- React.createElement(React.Fragment, null,
188
- React.createElement("label", { style: { width: '100%', position: 'relative', float: "left" } }, "Time Window(+/-): "),
189
- React.createElement(Row, { addRow: !props.isHorizontal },
190
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
191
- React.createElement(react_forms_1.Input, { Record: filter, Field: 'halfDuration', Setter: function (r) {
192
- var flt = getTimeWindow({ center: filter.center, halfDuration: r.halfDuration, unit: filter.unit }, format);
193
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { duration: r.duration, halfDuration: r.halfDuration, start: flt.start, end: flt.end })); });
194
- setActiveQP(-1);
195
- }, Label: '', Valid: function () { return true; }, Type: 'number' })),
196
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
197
- React.createElement(react_forms_1.Select, { Record: filter, Label: '', Field: 'unit', Setter: function (r) {
198
- var flt = getTimeWindow({ center: filter.center, halfDuration: filter.halfDuration, unit: r.unit }, format);
199
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { unit: r.unit, start: flt.start, end: flt.end })); });
200
- setActiveQP(-1);
201
- }, Options: TimeWindowUtils_1.units.map(function (unit) { return ({
202
- Value: unit,
203
- Label: (0, TimeWindowUtils_1.readableUnit)(unit)
204
- }); }) }))))
205
- : null,
206
- props.dateTimeSetting === 'startWindow' ?
207
- React.createElement(React.Fragment, null,
208
- React.createElement("label", { style: { width: '100%', position: 'relative', float: "left" } }, "Time Window(+): "),
209
- React.createElement(Row, { addRow: !props.isHorizontal },
210
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
211
- React.createElement(react_forms_1.Input, { Record: filter, Field: 'duration', Setter: function (r) {
212
- var flt = getTimeWindow({ start: filter.start, duration: r.duration, unit: filter.unit }, format);
213
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { duration: r.duration, halfDuration: r.halfDuration, center: flt.center, end: flt.end })); });
214
- setActiveQP(-1);
215
- }, Label: '', Valid: function () { return true; }, Type: 'number' })),
216
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
217
- React.createElement(react_forms_1.Select, { Record: filter, Label: '', Field: 'unit', Setter: function (r) {
218
- var flt = getTimeWindow({ start: filter.start, duration: filter.duration, unit: r.unit }, format);
219
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { unit: r.unit, center: flt.center, end: flt.end })); });
220
- setActiveQP(-1);
221
- }, Options: TimeWindowUtils_1.units.map(function (unit) { return ({
222
- Value: unit,
223
- Label: (0, TimeWindowUtils_1.readableUnit)(unit)
224
- }); }) }))))
225
- : null,
226
- props.dateTimeSetting === 'endWindow' ?
227
- React.createElement(React.Fragment, null,
228
- React.createElement("label", { style: { width: '100%', position: 'relative', float: "left" } }, "Time Window(-): "),
229
- React.createElement(Row, { addRow: !props.isHorizontal },
230
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
231
- React.createElement(react_forms_1.Input, { Record: filter, Field: 'duration', Setter: function (r) {
232
- var flt = getTimeWindow({ end: filter.end, duration: r.duration, unit: filter.unit }, format);
233
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { duration: r.duration, halfDuration: r.halfDuration, center: flt.center, start: flt.start })); });
234
- setActiveQP(-1);
235
- }, Label: '', Valid: function () { return true; }, Type: 'number' })),
236
- React.createElement("div", { className: props.isHorizontal ? (props.showQuickSelect ? 'col-1' : 'col-3') : 'col-6' },
237
- React.createElement(react_forms_1.Select, { Record: filter, Label: '', Field: 'unit', Setter: function (r) {
238
- var flt = getTimeWindow({ end: filter.end, duration: filter.duration, unit: r.unit }, format);
239
- setFilter(function (prevFilter) { return (__assign(__assign({}, prevFilter), { unit: r.unit, center: flt.center, start: flt.start })); });
240
- setActiveQP(-1);
241
- }, Options: TimeWindowUtils_1.units.map(function (unit) { return ({
242
- Value: unit,
243
- Label: (0, TimeWindowUtils_1.readableUnit)(unit)
244
- }); }) }))))
245
- : null,
246
- props.showQuickSelect ?
247
- React.createElement("div", { className: props.isHorizontal ? 'col-8' : 'row' },
248
- React.createElement(Row, { addRow: props.isHorizontal, class: "justify-content-center" }, QuickSelects.map(function (qs, i) {
249
- if (i % 3 !== 0)
250
- return null;
251
- return (React.createElement("div", { key: i, className: props.isHorizontal ? 'col-2' : "col-4", style: { paddingLeft: (props.isHorizontal ? 0 : (i % 9 == 0 ? 15 : 0)), paddingRight: (props.isHorizontal ? 2 : ((i % 18 == 6 || i % 18 == 15) ? 15 : 2)), marginTop: 10 } },
252
- React.createElement("ul", { className: "list-group", key: i },
253
- React.createElement("li", { key: i, style: { cursor: 'pointer' }, onClick: function () {
254
- var flt = getTimeWindow(QuickSelects[i].createFilter(props.timeZone, props.format), format);
255
- props.setFilter(flt.center, flt.start, flt.end, flt.unit, flt.duration);
256
- setActiveQP(i);
257
- }, className: "item badge badge-" + (i == activeQP ? "primary" : "secondary") }, QuickSelects[i].label),
258
- i + 1 < QuickSelects.length ?
259
- React.createElement("li", { key: i + 1, style: { marginTop: 3, cursor: 'pointer' }, className: "item badge badge-" + (i + 1 == activeQP ? "primary" : "secondary"), onClick: function () {
260
- var flt = getTimeWindow(QuickSelects[i + 1].createFilter(props.timeZone, props.format), format);
261
- props.setFilter(flt.center, flt.start, flt.end, flt.unit, flt.duration);
262
- setActiveQP(i + 1);
263
- } }, QuickSelects[i + 1].label) : null,
264
- i + 2 < QuickSelects.length ?
265
- React.createElement("li", { key: i + 2, style: { marginTop: 3, cursor: 'pointer' }, className: "item badge badge-" + (i + 2 == activeQP ? "primary" : "secondary"), onClick: function () {
266
- var flt = getTimeWindow(QuickSelects[i + 2].createFilter(props.timeZone, props.format), format);
267
- props.setFilter(flt.center, flt.start, flt.end, flt.unit, flt.duration);
268
- setActiveQP(i + 2);
269
- } }, QuickSelects[i + 2].label) : null)));
270
- })))
271
- : null)));
272
- };
273
- exports.default = TimeFilter;
@@ -1,26 +0,0 @@
1
- import moment from 'moment';
2
- export interface IStartEnd {
3
- start: string;
4
- end: string;
5
- }
6
- export interface IStartDuration {
7
- start: string;
8
- duration: number;
9
- unit: TimeUnit;
10
- }
11
- export interface IEndDuration {
12
- end: string;
13
- duration: number;
14
- unit: TimeUnit;
15
- }
16
- export interface ICenterDuration {
17
- center: string;
18
- halfDuration: number;
19
- unit: TimeUnit;
20
- }
21
- export type TimeUnit = 'y' | 'M' | 'w' | 'd' | 'h' | 'm' | 's' | 'ms';
22
- export declare const units: TimeUnit[];
23
- export declare function findAppropriateUnit(startTime: moment.Moment, endTime: moment.Moment, unit?: TimeUnit, useHalfWindow?: boolean): [TimeUnit, number];
24
- export declare function getStartEndTime(center: moment.Moment, duration: number, unit: TimeUnit): [moment.Moment, moment.Moment];
25
- export declare function getMoment(date: string, format?: string, time?: string): moment.Moment;
26
- export declare function readableUnit(unit: TimeUnit): "Year(s)" | "Month(s)" | "Week(s)" | "Day(s)" | "Hour(s)" | "Minute(s)" | "Second(s)" | "Millisecond(s)";
@@ -1,110 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.units = void 0;
7
- exports.findAppropriateUnit = findAppropriateUnit;
8
- exports.getStartEndTime = getStartEndTime;
9
- exports.getMoment = getMoment;
10
- exports.readableUnit = readableUnit;
11
- //******************************************************************************************************
12
- // TimeWindowUtils.tsx - Gbtc
13
- //
14
- // Copyright © 2023, Grid Protection Alliance. All Rights Reserved.
15
- //
16
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
17
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
18
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
19
- // file except in compliance with the License. You may obtain a copy of the License at:
20
- //
21
- // http://opensource.org/licenses/MIT
22
- //
23
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
24
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
25
- // License for the specific language governing permissions and limitations.
26
- //
27
- // Code Modification History:
28
- // ----------------------------------------------------------------------------------------------------
29
- // 07/11/2023 - C. Lackner
30
- // Generated original version of source code.
31
- // 06/20/2024 - Ali Karrar
32
- // Moved TimeWindowUtil from SEBrowser to gemstone
33
- //******************************************************************************************************
34
- var moment_1 = __importDefault(require("moment"));
35
- exports.units = ['ms', 's', 'm', 'h', 'd', 'w', 'M', 'y'];
36
- /*
37
- * A Function to determine the most appropriate unit for a window of time specified by start and end time
38
- */
39
- function findAppropriateUnit(startTime, endTime, unit, useHalfWindow) {
40
- var unitIndex = exports.units.findIndex(function (u) { return u == unit; });
41
- if (unit === undefined)
42
- unitIndex = 7;
43
- var diff = endTime.diff(startTime, exports.units[unitIndex], true);
44
- if (useHalfWindow !== undefined && useHalfWindow)
45
- diff = diff / 2;
46
- for (var i = unitIndex; i >= 1; i--) {
47
- if (i == 6) // Remove month as appropriate due to innacuracy in definition (31/30/28/29 days)
48
- continue;
49
- if (Number.isInteger(diff)) {
50
- return [exports.units[i], diff];
51
- }
52
- var nextI = i - 1;
53
- if (nextI == 6)
54
- nextI = 5;
55
- diff = endTime.diff(startTime, exports.units[nextI], true);
56
- if (useHalfWindow !== undefined && useHalfWindow)
57
- diff = diff / 2;
58
- if (diff > 65000) {
59
- diff = endTime.diff(startTime, exports.units[i], true);
60
- if (useHalfWindow !== undefined && useHalfWindow)
61
- diff = diff / 2;
62
- return [exports.units[i], Math.round(diff)];
63
- }
64
- }
65
- return [exports.units[0], Math.round(diff)];
66
- }
67
- /*
68
- * Determines a start time and end time for a window given by center time and duration
69
- */
70
- function getStartEndTime(center, duration, unit) {
71
- var d = moment_1.default.duration(duration, unit);
72
- var start = center.clone().subtract(d.asHours(), 'h');
73
- var end = center.clone().add(d.asHours(), 'h');
74
- return [start, end];
75
- }
76
- /*
77
- * Returns a formatted version of date and time provided
78
- */
79
- function getMoment(date, format, time) {
80
- if (time === undefined)
81
- return (0, moment_1.default)(date, format !== null && format !== void 0 ? format : 'MM/DD/YYYY HH:mm:ss.SSS');
82
- return (0, moment_1.default)(date + ' ' + time, 'MM/DD/YYYY HH:mm:ss.SSS');
83
- }
84
- /*
85
- * Returns a unit string based on unit char input
86
- */
87
- function readableUnit(unit) {
88
- if (unit == 'y') {
89
- return 'Year(s)';
90
- }
91
- else if (unit == 'M') {
92
- return 'Month(s)';
93
- }
94
- else if (unit == 'w') {
95
- return 'Week(s)';
96
- }
97
- else if (unit == 'd') {
98
- return 'Day(s)';
99
- }
100
- else if (unit == 'h') {
101
- return 'Hour(s)';
102
- }
103
- else if (unit == 'm') {
104
- return 'Minute(s)';
105
- }
106
- else if (unit == 's') {
107
- return 'Second(s)';
108
- }
109
- return 'Millisecond(s)';
110
- }
@@ -1,10 +0,0 @@
1
- import * as React from 'react';
2
- import { SystemCenter } from '@gpa-gemstone/application-typings';
3
- import { IGenericSlice, ISearchableSlice } from '../SliceInterfaces';
4
- interface IProps {
5
- OnValueListSelect: (id: number) => void;
6
- ValueListSlice: ISearchableSlice<SystemCenter.Types.ValueListGroup>;
7
- ValueListItemSlice: IGenericSlice<SystemCenter.Types.ValueListItem>;
8
- }
9
- declare function ByValueListGroup(props: IProps): React.JSX.Element;
10
- export default ByValueListGroup;
@@ -1,141 +0,0 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // ValueList.tsx - Gbtc
4
- //
5
- // Copyright © 2020, Grid Protection Alliance. All Rights Reserved.
6
- //
7
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
- // file except in compliance with the License. You may obtain a copy of the License at:
11
- //
12
- // http://opensource.org/licenses/MIT
13
- //
14
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
- // License for the specific language governing permissions and limitations.
17
- //
18
- // Code Modification History:
19
- // ----------------------------------------------------------------------------------------------------
20
- // 07/10/2021 - C. Lackner
21
- // Generated original version of source code.
22
- // ******************************************************************************************************
23
- var __assign = (this && this.__assign) || function () {
24
- __assign = Object.assign || function(t) {
25
- for (var s, i = 1, n = arguments.length; i < n; i++) {
26
- s = arguments[i];
27
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
28
- t[p] = s[p];
29
- }
30
- return t;
31
- };
32
- return __assign.apply(this, arguments);
33
- };
34
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
35
- if (k2 === undefined) k2 = k;
36
- var desc = Object.getOwnPropertyDescriptor(m, k);
37
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
38
- desc = { enumerable: true, get: function() { return m[k]; } };
39
- }
40
- Object.defineProperty(o, k2, desc);
41
- }) : (function(o, m, k, k2) {
42
- if (k2 === undefined) k2 = k;
43
- o[k2] = m[k];
44
- }));
45
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
46
- Object.defineProperty(o, "default", { enumerable: true, value: v });
47
- }) : function(o, v) {
48
- o["default"] = v;
49
- });
50
- var __importStar = (this && this.__importStar) || function (mod) {
51
- if (mod && mod.__esModule) return mod;
52
- var result = {};
53
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
54
- __setModuleDefault(result, mod);
55
- return result;
56
- };
57
- var __importDefault = (this && this.__importDefault) || function (mod) {
58
- return (mod && mod.__esModule) ? mod : { "default": mod };
59
- };
60
- Object.defineProperty(exports, "__esModule", { value: true });
61
- var React = __importStar(require("react"));
62
- var react_table_1 = __importDefault(require("@gpa-gemstone/react-table"));
63
- var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
64
- var react_interactive_1 = require("@gpa-gemstone/react-interactive");
65
- var GroupForm_1 = __importDefault(require("./GroupForm"));
66
- var react_redux_1 = require("react-redux");
67
- function ByValueListGroup(props) {
68
- var dispatch = (0, react_redux_1.useDispatch)();
69
- var data = (0, react_redux_1.useSelector)(props.ValueListSlice.SearchResults);
70
- var dataStatus = (0, react_redux_1.useSelector)(props.ValueListSlice.SearchStatus);
71
- var groups = (0, react_redux_1.useSelector)(props.ValueListSlice.Data);
72
- var groupStatus = (0, react_redux_1.useSelector)(props.ValueListSlice.Status);
73
- var _a = React.useState('Name'), sortKey = _a[0], setSortKey = _a[1];
74
- var _b = React.useState(false), asc = _b[0], setASC = _b[1];
75
- var emptyRecord = { ID: 0, Name: '', Description: '' };
76
- var _c = React.useState(false), showNew = _c[0], setShowNew = _c[1];
77
- var _d = React.useState(emptyRecord), record = _d[0], setRecord = _d[1];
78
- var items = (0, react_redux_1.useSelector)(props.ValueListItemSlice.Data);
79
- var itemStatus = (0, react_redux_1.useSelector)(props.ValueListItemSlice.Status);
80
- var _e = React.useState([]), search = _e[0], setSearch = _e[1];
81
- var _f = React.useState([]), newErrors = _f[0], setNewErrors = _f[1];
82
- var _g = React.useState(true), validName = _g[0], setValidName = _g[1];
83
- React.useEffect(function () {
84
- if (dataStatus === 'unintiated' || dataStatus === 'changed')
85
- dispatch(props.ValueListSlice.DBSearch({ filter: search, sortField: sortKey, ascending: asc }));
86
- }, [dispatch]);
87
- React.useEffect(function () {
88
- dispatch(props.ValueListSlice.DBSearch({ filter: search, sortField: sortKey, ascending: asc }));
89
- }, [search, asc, sortKey]);
90
- React.useEffect(function () {
91
- if (itemStatus === 'unintiated' || itemStatus === 'changed')
92
- dispatch(props.ValueListItemSlice.Fetch());
93
- }, [dispatch]);
94
- React.useEffect(function () {
95
- if (groupStatus === 'unintiated' || groupStatus === 'changed')
96
- dispatch(props.ValueListSlice.Fetch());
97
- }, [dispatch]);
98
- React.useEffect(function () {
99
- if (record.Name == null)
100
- setValidName(true);
101
- else
102
- setValidName(groups.findIndex(function (g) { return g.Name.toLowerCase() === record.Name.toLowerCase(); }) < 0);
103
- }, [record]);
104
- return (React.createElement("div", { style: { width: '100%', height: '100%' } },
105
- React.createElement(react_interactive_1.SearchBar, { CollumnList: [{ label: 'Name', key: 'Name', type: 'string', isPivotField: false }], SetFilter: function (flds) { return setSearch(flds); }, Direction: 'left', defaultCollumn: { label: 'Name', key: 'Name', type: 'string', isPivotField: false }, Width: '50%', Label: 'Search', ShowLoading: dataStatus === 'loading' || itemStatus === 'loading', ResultNote: dataStatus === 'error' || itemStatus === 'error' ? 'Could not complete Search' : 'Found ' + data.length + ' Groups', GetEnum: function () { return function () { }; } },
106
- React.createElement("li", { className: "nav-item", style: { width: '15%', paddingRight: 10 } },
107
- React.createElement("fieldset", { className: "border", style: { padding: '10px', height: '100%' } },
108
- React.createElement("legend", { className: "w-auto", style: { fontSize: 'large' } }, "Actions:"),
109
- React.createElement("form", null,
110
- React.createElement("button", { className: "btn btn-primary", onClick: function (evt) { evt.preventDefault(); setRecord(__assign({}, emptyRecord)); setShowNew(true); } }, "Add Group"))))),
111
- React.createElement("div", { style: { width: '100%', height: 'calc( 100% - 136px)' } },
112
- React.createElement(react_table_1.default, { cols: [
113
- { key: 'Name', field: 'Name', label: 'Name', headerStyle: { width: '15%' }, rowStyle: { width: '15%' } },
114
- { key: 'Description', field: 'Description', label: 'Description/Comments', headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' } },
115
- { key: 'Items', field: 'Items', label: 'Items', headerStyle: { width: '10%' }, rowStyle: { width: '10%' }, content: function (item) { return items.filter(function (i) { return i.GroupID === item.ID; }).length; } },
116
- { key: 'Scroll', label: '', headerStyle: { width: 17, padding: 0 }, rowStyle: { width: 0, padding: 0 } },
117
- ], tableClass: "table table-hover", data: data, sortKey: sortKey, ascending: asc, onSort: function (d) {
118
- if (d.colKey === 'remove' || d.colKey === 'scroll' || d.colField === undefined)
119
- return;
120
- setSortKey(d.colField);
121
- if (d.colField === sortKey)
122
- setASC(function (b) { return !b; });
123
- else
124
- setASC(true);
125
- }, onClick: function (d) { return props.OnValueListSelect(d.row.ID); }, theadStyle: { fontSize: 'smaller', display: 'table', tableLayout: 'fixed', width: '100%' }, tbodyStyle: { display: 'block', overflowY: 'scroll', maxHeight: window.innerHeight - 300, width: '100%' }, rowStyle: { fontSize: 'smaller', display: 'table', tableLayout: 'fixed', width: '100%' }, selected: function (item) { return false; } })),
126
- React.createElement(react_interactive_1.Modal, { Show: showNew, Title: 'Add new Value List', ShowX: true, ShowCancel: false, DisableConfirm: newErrors.length > 0 || !validName, ConfirmShowToolTip: newErrors.length > 0 || !validName, ConfirmToolTipContent: React.createElement(React.Fragment, null,
127
- newErrors.map(function (t, i) { return React.createElement("p", { key: i },
128
- " ",
129
- gpa_symbols_1.CrossMark,
130
- " ",
131
- t); }),
132
- !validName ? React.createElement("p", null,
133
- gpa_symbols_1.CrossMark,
134
- " The Name has to be unique.") : null), CallBack: function (c) {
135
- setShowNew(false);
136
- if (c)
137
- dispatch(props.ValueListSlice.DBAction({ verb: 'POST', record: record }));
138
- } },
139
- React.createElement(GroupForm_1.default, { Record: record, Setter: setRecord, ErrorSetter: setNewErrors }))));
140
- }
141
- exports.default = ByValueListGroup;
@@ -1,11 +0,0 @@
1
- import * as React from 'react';
2
- import { SystemCenter } from '@gpa-gemstone/application-typings';
3
- import { IGenericSlice } from '../SliceInterfaces';
4
- interface IProps {
5
- Id: number;
6
- ValueListSlice: IGenericSlice<SystemCenter.Types.ValueListGroup>;
7
- ValueListItemSlice: IGenericSlice<SystemCenter.Types.ValueListItem>;
8
- OnDelete: () => {};
9
- }
10
- export default function ValueListGroup(props: IProps): React.JSX.Element | null;
11
- export {};