@gpa-gemstone/common-pages 0.0.103 → 0.0.105

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.
Files changed (47) hide show
  1. package/lib/ErrorBoundary.d.ts +17 -17
  2. package/lib/ErrorBoundary.js +91 -68
  3. package/lib/Note.d.ts +22 -22
  4. package/lib/Note.js +256 -230
  5. package/lib/SearchBar.d.ts +37 -37
  6. package/lib/SearchBar.js +203 -180
  7. package/lib/SelectionPopup.d.ts +42 -42
  8. package/lib/SelectionPopup.js +93 -90
  9. package/lib/Setting.d.ts +8 -8
  10. package/lib/Setting.js +151 -125
  11. package/lib/SliceInterfaces.d.ts +76 -76
  12. package/lib/SliceInterfaces.js +2 -2
  13. package/lib/StandardSelectPopup.d.ts +20 -20
  14. package/lib/StandardSelectPopup.js +135 -109
  15. package/lib/TimeFilter/QuickSelects.d.ts +7 -0
  16. package/lib/TimeFilter/QuickSelects.js +240 -0
  17. package/lib/TimeFilter.d.ts +26 -0
  18. package/lib/TimeFilter.js +270 -0
  19. package/lib/TimeWindowUtils.d.ts +33 -0
  20. package/lib/TimeWindowUtils.js +121 -0
  21. package/lib/ValueList/ByValueList.d.ts +10 -10
  22. package/lib/ValueList/ByValueList.js +141 -115
  23. package/lib/ValueList/Group.d.ts +11 -11
  24. package/lib/ValueList/Group.js +97 -71
  25. package/lib/ValueList/GroupForm.d.ts +9 -9
  26. package/lib/ValueList/GroupForm.js +74 -51
  27. package/lib/ValueList/GroupInfo.d.ts +8 -8
  28. package/lib/ValueList/GroupInfo.js +95 -69
  29. package/lib/ValueList/GroupItem.d.ts +9 -9
  30. package/lib/ValueList/GroupItem.js +142 -116
  31. package/lib/ValueList/ItemForm.d.ts +9 -9
  32. package/lib/ValueList/ItemForm.js +82 -59
  33. package/lib/index.d.ts +12 -11
  34. package/lib/index.js +50 -45
  35. package/lib/user/AdditionalField.d.ts +26 -26
  36. package/lib/user/AdditionalField.js +290 -264
  37. package/lib/user/ByUser.d.ts +12 -12
  38. package/lib/user/ByUser.js +174 -148
  39. package/lib/user/User.d.ts +14 -14
  40. package/lib/user/User.js +97 -71
  41. package/lib/user/UserForm.d.ts +12 -12
  42. package/lib/user/UserForm.js +166 -143
  43. package/lib/user/UserInfo.d.ts +7 -7
  44. package/lib/user/UserInfo.js +123 -97
  45. package/lib/user/UserPermissions.d.ts +8 -8
  46. package/lib/user/UserPermissions.js +106 -83
  47. package/package.json +9 -8
package/lib/Note.js CHANGED
@@ -1,230 +1,256 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // Note.tsx - Gbtc
4
- //
5
- // Copyright © 2021, 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
- // 04/28/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
- Object.defineProperty(exports, "__esModule", { value: true });
35
- var React = require("react");
36
- var react_forms_1 = require("@gpa-gemstone/react-forms");
37
- var react_table_1 = require("@gpa-gemstone/react-table");
38
- var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
39
- var react_interactive_1 = require("@gpa-gemstone/react-interactive");
40
- var moment = require("moment");
41
- var react_redux_1 = require("react-redux");
42
- function Note(props) {
43
- var dispatch = (0, react_redux_1.useDispatch)();
44
- var standardCollumns = [
45
- {
46
- key: 'Note', field: 'Note', label: 'Note',
47
- headerStyle: { width: '50%' }, rowStyle: { width: '50%' }
48
- },
49
- {
50
- key: 'Timestamp', field: 'Timestamp', label: 'Time',
51
- headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' },
52
- content: function (item) { return moment.utc(item.Timestamp).format("MM/DD/YYYY HH:mm"); }
53
- },
54
- {
55
- key: 'UserAccount', field: 'UserAccount', label: 'User',
56
- headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' }
57
- }
58
- ];
59
- var allowEdit = props.AllowEdit === undefined ? true : props.AllowEdit;
60
- var allowRemove = props.AllowRemove === undefined ? true : props.AllowRemove;
61
- var allowAdd = props.AllowAdd === undefined ? true : props.AllowAdd;
62
- var useFixedApp = props.NoteApplications.length === 1 || props.DefaultApplication !== undefined;
63
- var defaultApplication = props.DefaultApplication !== undefined ? props.DefaultApplication : props.NoteApplications[0];
64
- var showCard = props.ShowCard === undefined || props.ShowCard;
65
- var _a = React.useState(false), showEdit = _a[0], setEdit = _a[1];
66
- var _b = React.useState('none'), hover = _b[0], setHover = _b[1];
67
- var _c = React.useState(standardCollumns), collumns = _c[0], setCollumns = _c[1];
68
- var data = (0, react_redux_1.useSelector)(props.NoteSlice.Data);
69
- var dataStatus = (0, react_redux_1.useSelector)(props.NoteSlice.Status);
70
- var parentID = (0, react_redux_1.useSelector)((props.NoteSlice.ParentID === undefined ? function (state) { return props.ReferenceTableID; } : props.NoteSlice.ParentID));
71
- var sortField = (0, react_redux_1.useSelector)(props.NoteSlice.SortField);
72
- var ascending = (0, react_redux_1.useSelector)(props.NoteSlice.Ascending);
73
- var _d = React.useState(CreateNewNote()), note = _d[0], setNote = _d[1];
74
- var _e = React.useState([]), notes = _e[0], setNotes = _e[1];
75
- React.useEffect(function () {
76
- if (dataStatus === 'unintiated' || dataStatus === 'changed' || parentID !== props.ReferenceTableID)
77
- dispatch(props.NoteSlice.Fetch(props.ReferenceTableID));
78
- }, [props.ReferenceTableID, dispatch, dataStatus]);
79
- React.useEffect(function () {
80
- if (note.NoteTypeID > 0 || props.NoteTypes.length === 0)
81
- return;
82
- setNote(function (n) { return (__assign(__assign({}, n), { NoteTypeID: props.NoteTypes[0].ID })); });
83
- }, [props.NoteTypes]);
84
- React.useEffect(function () {
85
- if (note.NoteApplicationID > 0 || props.NoteApplications.length === 0)
86
- return;
87
- setNote(function (n) { return (__assign(__assign({}, n), { NoteApplicationID: props.NoteApplications[0].ID })); });
88
- }, [props.NoteApplications]);
89
- React.useEffect(function () {
90
- if (note.NoteTagID > 0 || props.NoteTags.length === 0)
91
- return;
92
- setNote(function (n) { return (__assign(__assign({}, n), { NoteTagID: props.NoteTags[0].ID })); });
93
- }, [props.NoteTags]);
94
- React.useEffect(function () {
95
- if (note.ReferenceTableID === undefined)
96
- return;
97
- setNote(function (n) { return (__assign(__assign({}, n), { ReferenceTableID: props.ReferenceTableID !== undefined ? props.ReferenceTableID : -1 })); });
98
- }, [props.ReferenceTableID]);
99
- React.useEffect(function () {
100
- var c = standardCollumns;
101
- if (props.AdditionalCollumns !== undefined)
102
- c.push.apply(c, props.AdditionalCollumns);
103
- if (props.NoteTags.length > 1)
104
- c.push({ key: 'NoteTagID', field: 'NoteTagID', label: 'Type', headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' },
105
- content: function (n) { var _a; return (_a = props.NoteTags.find(function (t) { return t.ID === n.NoteTagID; })) === null || _a === void 0 ? void 0 : _a.Name; } });
106
- if (props.NoteApplications.length > 1)
107
- c.push({ key: 'NoteApplicationID', field: 'NoteApplicationID', label: 'Application', headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' },
108
- content: function (n) { var _a; return (_a = props.NoteApplications.find(function (t) { return t.ID === n.NoteApplicationID; })) === null || _a === void 0 ? void 0 : _a.Name; } });
109
- c.push({
110
- key: 'buttons',
111
- label: '',
112
- headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' },
113
- content: function (item) { return React.createElement(React.Fragment, null,
114
- allowEdit ? React.createElement("button", { className: "btn btn-sm", onClick: function () { return handleEdit(item); } },
115
- React.createElement("span", null,
116
- " ",
117
- gpa_symbols_1.Pencil,
118
- " ")) : null,
119
- allowRemove ? React.createElement("button", { className: "btn btn-sm", onClick: function () { return dispatch(props.NoteSlice.DBAction({ verb: 'DELETE', record: item })); } },
120
- React.createElement("span", null,
121
- " ",
122
- gpa_symbols_1.TrashCan,
123
- " ")) : null); }
124
- });
125
- setCollumns(c);
126
- }, [props.NoteTags, props.NoteApplications, props.AdditionalCollumns]);
127
- React.useEffect(function () {
128
- setNotes(data.filter(function (n) { return (props.Filter === undefined ? true : props.Filter(n)); }));
129
- }, [props.Filter, data]);
130
- function CreateNewNote() {
131
- var newNote = { ID: -1, ReferenceTableID: -1, NoteTagID: -1, NoteTypeID: -1, NoteApplicationID: -1, Timestamp: '', UserAccount: '', Note: '' };
132
- if (props.ReferenceTableID !== undefined)
133
- newNote.ReferenceTableID = props.ReferenceTableID;
134
- if (defaultApplication != null)
135
- newNote.NoteApplicationID = defaultApplication.ID;
136
- if (props.NoteTypes.length > 0)
137
- newNote.NoteTypeID = props.NoteTypes[0].ID;
138
- if (props.NoteTags.length > 0)
139
- newNote.NoteTagID = props.NoteTags[0].ID;
140
- return newNote;
141
- }
142
- function handleEdit(d) {
143
- setNote(d);
144
- setEdit(true);
145
- }
146
- function handleAdd(d) {
147
- dispatch(props.NoteSlice.DBAction({ verb: 'POST', record: __assign(__assign({}, d), { UserAccount: undefined, Timestamp: moment().format('MM/DD/YYYY HH:mm') }) }));
148
- setNote(CreateNewNote());
149
- }
150
- function handleSaveEdit(confirm) {
151
- if (note.Note.length === 0 && confirm)
152
- return;
153
- setEdit(false);
154
- if (confirm && allowEdit)
155
- dispatch(props.NoteSlice.DBAction({ verb: 'PATCH', record: note }));
156
- setNote(CreateNewNote());
157
- }
158
- if (dataStatus === "error")
159
- return (React.createElement("div", { style: { width: '100%', height: '100%' } },
160
- React.createElement("div", { style: { height: '40px', margin: 'auto', marginTop: 'calc(50% - 20 px)' } },
161
- React.createElement(react_interactive_1.ServerErrorIcon, { Show: true, Size: 40 }))));
162
- return (React.createElement("div", { className: showCard ? "card" : "", style: { marginBottom: 10, maxHeight: props.MaxHeight, width: '100%' } },
163
- React.createElement(react_interactive_1.LoadingScreen, { Show: dataStatus === 'loading' }),
164
- React.createElement("div", { className: props.ShowCard === undefined || props.ShowCard ? "card-header" : "" },
165
- React.createElement("div", { className: "row" },
166
- React.createElement("div", { className: "col" },
167
- React.createElement("h4", null, props.Title !== undefined ? props.Title : 'Notes:')))),
168
- React.createElement("div", { className: showCard ? "card-body" : "", style: { maxHeight: props.MaxHeight - 100, overflowY: 'auto', width: '100%' } },
169
- allowAdd && !showCard ?
170
- React.createElement(React.Fragment, null,
171
- React.createElement(NoteOptions, { Record: note, Setter: function (n) { return setNote(n); }, NoteTags: props.NoteTags, NoteTypes: props.NoteTypes, NoteApplications: props.NoteApplications, ShowApplications: !useFixedApp }),
172
- React.createElement("div", { className: "btn-group mr-2" },
173
- React.createElement("button", { className: "btn btn-primary" + (note.Note === null || note.Note.length === 0 ? ' disabled' : ''), onClick: function () { if (note.Note !== null && note.Note.length > 0)
174
- handleAdd(note); }, "data-tooltip": "Add", style: { cursor: note.Note === null || note.Note.length === 0 ? 'not-allowed' : 'pointer' }, onMouseOver: function () { return setHover('add'); }, onMouseOut: function () { return setHover('none'); } }, "Add Note"),
175
- React.createElement(react_interactive_1.ToolTip, { Show: hover === 'add' && (note.Note === null || note.Note.length === 0), Position: 'top', Theme: 'dark', Target: "Add" },
176
- React.createElement("p", null,
177
- gpa_symbols_1.CrossMark,
178
- " A note needs to be entered. "))),
179
- React.createElement("div", { className: "btn-group mr-2" },
180
- React.createElement("button", { className: "btn btn-default" + (note.Note === null || note.Note.length === 0 ? ' disabled' : ''), onClick: function () { return setNote(function (n) { return (__assign(__assign({}, n), { Note: '' })); }); }, style: { cursor: note.Note === null || note.Note.length === 0 ? 'not-allowed' : 'pointer' }, "data-tooltip": "Remove", onMouseOver: function () { return setHover('clear'); }, onMouseOut: function () { return setHover('none'); } }, "Clear"),
181
- React.createElement(react_interactive_1.ToolTip, { Show: hover === 'clear' && (note.Note === null || note.Note.length === 0), Position: 'top', Theme: 'dark', Target: "Remove" },
182
- React.createElement("p", null,
183
- gpa_symbols_1.CrossMark,
184
- " The note field is already empty. ")))) : null,
185
- React.createElement("div", null,
186
- React.createElement(react_table_1.default, { cols: collumns, tableClass: "table table-hover", data: notes, sortKey: sortField, ascending: ascending, onSort: function (d) {
187
- if (d.colField === undefined)
188
- return;
189
- if (d.colField === sortField)
190
- dispatch(props.NoteSlice.Sort({ SortField: sortField, Ascending: ascending }));
191
- else
192
- dispatch(props.NoteSlice.Sort({ SortField: d.colField, Ascending: true }));
193
- }, onClick: function () { return; }, theadStyle: { fontSize: 'smaller', display: 'table', tableLayout: 'fixed', width: '100%' }, tbodyStyle: { display: 'block', overflowY: 'scroll', maxHeight: props.MaxHeight - 300, width: '100%' }, rowStyle: { fontSize: 'smaller', display: 'table', tableLayout: 'fixed', width: '100%' }, selected: function () { return false; } })),
194
- allowAdd && showCard ?
195
- React.createElement(NoteOptions, { Record: note, Setter: function (n) { return setNote(n); }, NoteTags: props.NoteTags, NoteTypes: props.NoteTypes, NoteApplications: props.NoteApplications, ShowApplications: !useFixedApp })
196
- : null,
197
- React.createElement(react_interactive_1.Modal, { Show: showEdit, Title: 'Edit Note', ShowCancel: true, CallBack: handleSaveEdit, DisableConfirm: note.Note == null || note.Note.length === 0, ShowX: true, ConfirmShowToolTip: note.Note == null || note.Note.length === 0, ConfirmToolTipContent: React.createElement("p", null,
198
- " ",
199
- gpa_symbols_1.CrossMark,
200
- " An empty Note can not be saved. ") },
201
- React.createElement(NoteOptions, { ShowApplications: !useFixedApp, Record: note, Setter: function (n) { return setNote(n); }, NoteTags: props.NoteTags, NoteTypes: props.NoteTypes, NoteApplications: props.NoteApplications }))),
202
- allowAdd && showCard ?
203
- React.createElement("div", { className: "card-footer" },
204
- React.createElement("div", { className: "btn-group mr-2" },
205
- React.createElement("button", { className: "btn btn-primary" + (note.Note === null || note.Note.length === 0 ? ' disabled' : ''), onClick: function () { if (note.Note !== null && note.Note.length > 0)
206
- handleAdd(note); }, "data-tooltip": "Add", style: { cursor: note.Note === null || note.Note.length === 0 ? 'not-allowed' : 'pointer' }, onMouseOver: function () { return setHover('add'); }, onMouseOut: function () { return setHover('none'); } }, "Add Note"),
207
- React.createElement(react_interactive_1.ToolTip, { Show: hover === 'add' && (note.Note === null || note.Note.length === 0), Position: 'top', Theme: 'dark', Target: "Add" },
208
- React.createElement("p", null,
209
- gpa_symbols_1.CrossMark,
210
- " A note needs to be entered. "))),
211
- React.createElement("div", { className: "btn-group mr-2" },
212
- React.createElement("button", { className: "btn btn-default" + (note.Note === null || note.Note.length === 0 ? ' disabled' : ''), onClick: function () { return setNote(function (n) { return (__assign(__assign({}, n), { Note: '' })); }); }, style: { cursor: note.Note === null || note.Note.length === 0 ? 'not-allowed' : 'pointer' }, "data-tooltip": "Remove", onMouseOver: function () { return setHover('clear'); }, onMouseOut: function () { return setHover('none'); } }, "Clear"),
213
- React.createElement(react_interactive_1.ToolTip, { Show: hover === 'clear' && (note.Note === null || note.Note.length === 0), Position: 'top', Theme: 'dark', Target: "Remove" },
214
- React.createElement("p", null,
215
- gpa_symbols_1.CrossMark,
216
- " The note field is already empty. "))))
217
- : null,
218
- !allowAdd && showCard ? React.createElement("div", { className: props.ShowCard === undefined || props.ShowCard ? "card-footer" : "" }, " ") : null));
219
- }
220
- function NoteOptions(props) {
221
- var showOptions = props.NoteTags.length > 1 || props.NoteTypes.length > 1 || props.NoteApplications.length > 1;
222
- return (React.createElement("div", { className: "row", style: { marginRight: 0, marginLeft: 0 } },
223
- React.createElement("div", { className: showOptions ? "col-6" : 'col-12' },
224
- React.createElement(react_forms_1.TextArea, { Record: props.Record, Rows: 4, Field: 'Note', Setter: function (n) { return props.Setter(n); }, Valid: function () { return props.Record.Note != null && props.Record.Note.length > 0; }, Label: '' })),
225
- showOptions ? React.createElement("div", { className: "col-6" },
226
- props.NoteTypes.length > 1 ? React.createElement(react_forms_1.Select, { Record: props.Record, Field: 'NoteTypeID', Label: 'Note for: ', Options: props.NoteTypes.map(function (r) { return ({ Value: r.ID.toString(), Label: r.Name }); }), Setter: function (record) { return props.Setter(__assign(__assign({}, record), { NoteTypeID: parseInt(record.NoteTypeID.toString(), 10) })); } }) : null,
227
- props.NoteTags.length > 1 ? React.createElement(react_forms_1.Select, { Record: props.Record, Field: 'NoteTagID', Label: 'Type: ', Options: props.NoteTags.map(function (r) { return ({ Value: r.ID.toString(), Label: r.Name }); }), Setter: function (record) { return props.Setter(__assign(__assign({}, record), { NoteTagID: parseInt(record.NoteTagID.toString(), 10) })); } }) : null,
228
- props.ShowApplications && props.NoteApplications.length > 1 ? React.createElement(react_forms_1.Select, { Record: props.Record, Field: 'NoteApplicationID', Label: 'Application: ', Options: props.NoteApplications.map(function (r) { return ({ Value: r.ID.toString(), Label: r.Name }); }), Setter: function (record) { return props.Setter(__assign(__assign({}, record), { NoteApplicationID: parseInt(record.NoteApplicationID.toString(), 10) })); } }) : null) : null));
229
- }
230
- exports.default = Note;
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // Note.tsx - Gbtc
4
+ //
5
+ // Copyright © 2021, 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
+ // 04/28/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_forms_1 = require("@gpa-gemstone/react-forms");
63
+ var react_table_1 = __importDefault(require("@gpa-gemstone/react-table"));
64
+ var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
65
+ var react_interactive_1 = require("@gpa-gemstone/react-interactive");
66
+ var moment = require("moment");
67
+ var react_redux_1 = require("react-redux");
68
+ function Note(props) {
69
+ var dispatch = (0, react_redux_1.useDispatch)();
70
+ var standardCollumns = [
71
+ {
72
+ key: 'Note', field: 'Note', label: 'Note',
73
+ headerStyle: { width: '50%' }, rowStyle: { width: '50%' }
74
+ },
75
+ {
76
+ key: 'Timestamp', field: 'Timestamp', label: 'Time',
77
+ headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' },
78
+ content: function (item) { return moment.utc(item.Timestamp).format("MM/DD/YYYY HH:mm"); }
79
+ },
80
+ {
81
+ key: 'UserAccount', field: 'UserAccount', label: 'User',
82
+ headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' }
83
+ }
84
+ ];
85
+ var allowEdit = props.AllowEdit === undefined ? true : props.AllowEdit;
86
+ var allowRemove = props.AllowRemove === undefined ? true : props.AllowRemove;
87
+ var allowAdd = props.AllowAdd === undefined ? true : props.AllowAdd;
88
+ var useFixedApp = props.NoteApplications.length === 1 || props.DefaultApplication !== undefined;
89
+ var defaultApplication = props.DefaultApplication !== undefined ? props.DefaultApplication : props.NoteApplications[0];
90
+ var showCard = props.ShowCard === undefined || props.ShowCard;
91
+ var _a = React.useState(false), showEdit = _a[0], setEdit = _a[1];
92
+ var _b = React.useState('none'), hover = _b[0], setHover = _b[1];
93
+ var _c = React.useState(standardCollumns), collumns = _c[0], setCollumns = _c[1];
94
+ var data = (0, react_redux_1.useSelector)(props.NoteSlice.Data);
95
+ var dataStatus = (0, react_redux_1.useSelector)(props.NoteSlice.Status);
96
+ var parentID = (0, react_redux_1.useSelector)((props.NoteSlice.ParentID === undefined ? function (state) { return props.ReferenceTableID; } : props.NoteSlice.ParentID));
97
+ var sortField = (0, react_redux_1.useSelector)(props.NoteSlice.SortField);
98
+ var ascending = (0, react_redux_1.useSelector)(props.NoteSlice.Ascending);
99
+ var _d = React.useState(CreateNewNote()), note = _d[0], setNote = _d[1];
100
+ var _e = React.useState([]), notes = _e[0], setNotes = _e[1];
101
+ React.useEffect(function () {
102
+ if (dataStatus === 'unintiated' || dataStatus === 'changed' || parentID !== props.ReferenceTableID)
103
+ dispatch(props.NoteSlice.Fetch(props.ReferenceTableID));
104
+ }, [props.ReferenceTableID, dispatch, dataStatus]);
105
+ React.useEffect(function () {
106
+ if (note.NoteTypeID > 0 || props.NoteTypes.length === 0)
107
+ return;
108
+ setNote(function (n) { return (__assign(__assign({}, n), { NoteTypeID: props.NoteTypes[0].ID })); });
109
+ }, [props.NoteTypes]);
110
+ React.useEffect(function () {
111
+ if (note.NoteApplicationID > 0 || props.NoteApplications.length === 0)
112
+ return;
113
+ setNote(function (n) { return (__assign(__assign({}, n), { NoteApplicationID: props.NoteApplications[0].ID })); });
114
+ }, [props.NoteApplications]);
115
+ React.useEffect(function () {
116
+ if (note.NoteTagID > 0 || props.NoteTags.length === 0)
117
+ return;
118
+ setNote(function (n) { return (__assign(__assign({}, n), { NoteTagID: props.NoteTags[0].ID })); });
119
+ }, [props.NoteTags]);
120
+ React.useEffect(function () {
121
+ if (note.ReferenceTableID === undefined)
122
+ return;
123
+ setNote(function (n) { return (__assign(__assign({}, n), { ReferenceTableID: props.ReferenceTableID !== undefined ? props.ReferenceTableID : -1 })); });
124
+ }, [props.ReferenceTableID]);
125
+ React.useEffect(function () {
126
+ var c = standardCollumns;
127
+ if (props.AdditionalCollumns !== undefined)
128
+ c.push.apply(c, props.AdditionalCollumns);
129
+ if (props.NoteTags.length > 1)
130
+ c.push({ key: 'NoteTagID', field: 'NoteTagID', label: 'Type', headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' },
131
+ content: function (n) { var _a; return (_a = props.NoteTags.find(function (t) { return t.ID === n.NoteTagID; })) === null || _a === void 0 ? void 0 : _a.Name; } });
132
+ if (props.NoteApplications.length > 1)
133
+ c.push({ key: 'NoteApplicationID', field: 'NoteApplicationID', label: 'Application', headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' },
134
+ content: function (n) { var _a; return (_a = props.NoteApplications.find(function (t) { return t.ID === n.NoteApplicationID; })) === null || _a === void 0 ? void 0 : _a.Name; } });
135
+ c.push({
136
+ key: 'buttons',
137
+ label: '',
138
+ headerStyle: { width: 'auto' }, rowStyle: { width: 'auto' },
139
+ content: function (item) { return React.createElement(React.Fragment, null,
140
+ allowEdit ? React.createElement("button", { className: "btn btn-sm", onClick: function () { return handleEdit(item); } },
141
+ React.createElement("span", null,
142
+ " ",
143
+ gpa_symbols_1.Pencil,
144
+ " ")) : null,
145
+ allowRemove ? React.createElement("button", { className: "btn btn-sm", onClick: function () { return dispatch(props.NoteSlice.DBAction({ verb: 'DELETE', record: item })); } },
146
+ React.createElement("span", null,
147
+ " ",
148
+ gpa_symbols_1.TrashCan,
149
+ " ")) : null); }
150
+ });
151
+ setCollumns(c);
152
+ }, [props.NoteTags, props.NoteApplications, props.AdditionalCollumns]);
153
+ React.useEffect(function () {
154
+ setNotes(data.filter(function (n) { return (props.Filter === undefined ? true : props.Filter(n)); }));
155
+ }, [props.Filter, data]);
156
+ function CreateNewNote() {
157
+ var newNote = { ID: -1, ReferenceTableID: -1, NoteTagID: -1, NoteTypeID: -1, NoteApplicationID: -1, Timestamp: '', UserAccount: '', Note: '' };
158
+ if (props.ReferenceTableID !== undefined)
159
+ newNote.ReferenceTableID = props.ReferenceTableID;
160
+ if (defaultApplication != null)
161
+ newNote.NoteApplicationID = defaultApplication.ID;
162
+ if (props.NoteTypes.length > 0)
163
+ newNote.NoteTypeID = props.NoteTypes[0].ID;
164
+ if (props.NoteTags.length > 0)
165
+ newNote.NoteTagID = props.NoteTags[0].ID;
166
+ return newNote;
167
+ }
168
+ function handleEdit(d) {
169
+ setNote(d);
170
+ setEdit(true);
171
+ }
172
+ function handleAdd(d) {
173
+ dispatch(props.NoteSlice.DBAction({ verb: 'POST', record: __assign(__assign({}, d), { UserAccount: undefined, Timestamp: moment().format('MM/DD/YYYY HH:mm') }) }));
174
+ setNote(CreateNewNote());
175
+ }
176
+ function handleSaveEdit(confirm) {
177
+ if (note.Note.length === 0 && confirm)
178
+ return;
179
+ setEdit(false);
180
+ if (confirm && allowEdit)
181
+ dispatch(props.NoteSlice.DBAction({ verb: 'PATCH', record: note }));
182
+ setNote(CreateNewNote());
183
+ }
184
+ if (dataStatus === "error")
185
+ return (React.createElement("div", { style: { width: '100%', height: '100%' } },
186
+ React.createElement("div", { style: { height: '40px', margin: 'auto', marginTop: 'calc(50% - 20 px)' } },
187
+ React.createElement(react_interactive_1.ServerErrorIcon, { Show: true, Size: 40 }))));
188
+ return (React.createElement("div", { className: showCard ? "card" : "", style: { marginBottom: 10, maxHeight: props.MaxHeight, width: '100%' } },
189
+ React.createElement(react_interactive_1.LoadingScreen, { Show: dataStatus === 'loading' }),
190
+ React.createElement("div", { className: props.ShowCard === undefined || props.ShowCard ? "card-header" : "" },
191
+ React.createElement("div", { className: "row" },
192
+ React.createElement("div", { className: "col" },
193
+ React.createElement("h4", null, props.Title !== undefined ? props.Title : 'Notes:')))),
194
+ React.createElement("div", { className: showCard ? "card-body" : "", style: { maxHeight: props.MaxHeight - 100, overflowY: 'auto', width: '100%' } },
195
+ allowAdd && !showCard ?
196
+ React.createElement(React.Fragment, null,
197
+ React.createElement(NoteOptions, { Record: note, Setter: function (n) { return setNote(n); }, NoteTags: props.NoteTags, NoteTypes: props.NoteTypes, NoteApplications: props.NoteApplications, ShowApplications: !useFixedApp }),
198
+ React.createElement("div", { className: "btn-group mr-2" },
199
+ React.createElement("button", { className: "btn btn-primary" + (note.Note === null || note.Note.length === 0 ? ' disabled' : ''), onClick: function () { if (note.Note !== null && note.Note.length > 0)
200
+ handleAdd(note); }, "data-tooltip": "Add", style: { cursor: note.Note === null || note.Note.length === 0 ? 'not-allowed' : 'pointer' }, onMouseOver: function () { return setHover('add'); }, onMouseOut: function () { return setHover('none'); } }, "Add Note"),
201
+ React.createElement(react_interactive_1.ToolTip, { Show: hover === 'add' && (note.Note === null || note.Note.length === 0), Position: 'top', Theme: 'dark', Target: "Add" },
202
+ React.createElement("p", null,
203
+ gpa_symbols_1.CrossMark,
204
+ " A note needs to be entered. "))),
205
+ React.createElement("div", { className: "btn-group mr-2" },
206
+ React.createElement("button", { className: "btn btn-default" + (note.Note === null || note.Note.length === 0 ? ' disabled' : ''), onClick: function () { return setNote(function (n) { return (__assign(__assign({}, n), { Note: '' })); }); }, style: { cursor: note.Note === null || note.Note.length === 0 ? 'not-allowed' : 'pointer' }, "data-tooltip": "Remove", onMouseOver: function () { return setHover('clear'); }, onMouseOut: function () { return setHover('none'); } }, "Clear"),
207
+ React.createElement(react_interactive_1.ToolTip, { Show: hover === 'clear' && (note.Note === null || note.Note.length === 0), Position: 'top', Theme: 'dark', Target: "Remove" },
208
+ React.createElement("p", null,
209
+ gpa_symbols_1.CrossMark,
210
+ " The note field is already empty. ")))) : null,
211
+ React.createElement("div", null,
212
+ React.createElement(react_table_1.default, { cols: collumns, tableClass: "table table-hover", data: notes, sortKey: sortField, ascending: ascending, onSort: function (d) {
213
+ if (d.colField === undefined)
214
+ return;
215
+ if (d.colField === sortField)
216
+ dispatch(props.NoteSlice.Sort({ SortField: sortField, Ascending: ascending }));
217
+ else
218
+ dispatch(props.NoteSlice.Sort({ SortField: d.colField, Ascending: true }));
219
+ }, onClick: function () { return; }, theadStyle: { fontSize: 'smaller', display: 'table', tableLayout: 'fixed', width: '100%' }, tbodyStyle: { display: 'block', overflowY: 'scroll', maxHeight: props.MaxHeight - 300, width: '100%' }, rowStyle: { fontSize: 'smaller', display: 'table', tableLayout: 'fixed', width: '100%' }, selected: function () { return false; } })),
220
+ allowAdd && showCard ?
221
+ React.createElement(NoteOptions, { Record: note, Setter: function (n) { return setNote(n); }, NoteTags: props.NoteTags, NoteTypes: props.NoteTypes, NoteApplications: props.NoteApplications, ShowApplications: !useFixedApp })
222
+ : null,
223
+ React.createElement(react_interactive_1.Modal, { Show: showEdit, Title: 'Edit Note', ShowCancel: true, CallBack: handleSaveEdit, DisableConfirm: note.Note == null || note.Note.length === 0, ShowX: true, ConfirmShowToolTip: note.Note == null || note.Note.length === 0, ConfirmToolTipContent: React.createElement("p", null,
224
+ " ",
225
+ gpa_symbols_1.CrossMark,
226
+ " An empty Note can not be saved. ") },
227
+ React.createElement(NoteOptions, { ShowApplications: !useFixedApp, Record: note, Setter: function (n) { return setNote(n); }, NoteTags: props.NoteTags, NoteTypes: props.NoteTypes, NoteApplications: props.NoteApplications }))),
228
+ allowAdd && showCard ?
229
+ React.createElement("div", { className: "card-footer" },
230
+ React.createElement("div", { className: "btn-group mr-2" },
231
+ React.createElement("button", { className: "btn btn-primary" + (note.Note === null || note.Note.length === 0 ? ' disabled' : ''), onClick: function () { if (note.Note !== null && note.Note.length > 0)
232
+ handleAdd(note); }, "data-tooltip": "Add", style: { cursor: note.Note === null || note.Note.length === 0 ? 'not-allowed' : 'pointer' }, onMouseOver: function () { return setHover('add'); }, onMouseOut: function () { return setHover('none'); } }, "Add Note"),
233
+ React.createElement(react_interactive_1.ToolTip, { Show: hover === 'add' && (note.Note === null || note.Note.length === 0), Position: 'top', Theme: 'dark', Target: "Add" },
234
+ React.createElement("p", null,
235
+ gpa_symbols_1.CrossMark,
236
+ " A note needs to be entered. "))),
237
+ React.createElement("div", { className: "btn-group mr-2" },
238
+ React.createElement("button", { className: "btn btn-default" + (note.Note === null || note.Note.length === 0 ? ' disabled' : ''), onClick: function () { return setNote(function (n) { return (__assign(__assign({}, n), { Note: '' })); }); }, style: { cursor: note.Note === null || note.Note.length === 0 ? 'not-allowed' : 'pointer' }, "data-tooltip": "Remove", onMouseOver: function () { return setHover('clear'); }, onMouseOut: function () { return setHover('none'); } }, "Clear"),
239
+ React.createElement(react_interactive_1.ToolTip, { Show: hover === 'clear' && (note.Note === null || note.Note.length === 0), Position: 'top', Theme: 'dark', Target: "Remove" },
240
+ React.createElement("p", null,
241
+ gpa_symbols_1.CrossMark,
242
+ " The note field is already empty. "))))
243
+ : null,
244
+ !allowAdd && showCard ? React.createElement("div", { className: props.ShowCard === undefined || props.ShowCard ? "card-footer" : "" }, " ") : null));
245
+ }
246
+ function NoteOptions(props) {
247
+ var showOptions = props.NoteTags.length > 1 || props.NoteTypes.length > 1 || props.NoteApplications.length > 1;
248
+ return (React.createElement("div", { className: "row", style: { marginRight: 0, marginLeft: 0 } },
249
+ React.createElement("div", { className: showOptions ? "col-6" : 'col-12' },
250
+ React.createElement(react_forms_1.TextArea, { Record: props.Record, Rows: 4, Field: 'Note', Setter: function (n) { return props.Setter(n); }, Valid: function () { return props.Record.Note != null && props.Record.Note.length > 0; }, Label: '' })),
251
+ showOptions ? React.createElement("div", { className: "col-6" },
252
+ props.NoteTypes.length > 1 ? React.createElement(react_forms_1.Select, { Record: props.Record, Field: 'NoteTypeID', Label: 'Note for: ', Options: props.NoteTypes.map(function (r) { return ({ Value: r.ID.toString(), Label: r.Name }); }), Setter: function (record) { return props.Setter(__assign(__assign({}, record), { NoteTypeID: parseInt(record.NoteTypeID.toString(), 10) })); } }) : null,
253
+ props.NoteTags.length > 1 ? React.createElement(react_forms_1.Select, { Record: props.Record, Field: 'NoteTagID', Label: 'Type: ', Options: props.NoteTags.map(function (r) { return ({ Value: r.ID.toString(), Label: r.Name }); }), Setter: function (record) { return props.Setter(__assign(__assign({}, record), { NoteTagID: parseInt(record.NoteTagID.toString(), 10) })); } }) : null,
254
+ props.ShowApplications && props.NoteApplications.length > 1 ? React.createElement(react_forms_1.Select, { Record: props.Record, Field: 'NoteApplicationID', Label: 'Application: ', Options: props.NoteApplications.map(function (r) { return ({ Value: r.ID.toString(), Label: r.Name }); }), Setter: function (record) { return props.Setter(__assign(__assign({}, record), { NoteApplicationID: parseInt(record.NoteApplicationID.toString(), 10) })); } }) : null) : null));
255
+ }
256
+ exports.default = Note;
@@ -1,37 +1,37 @@
1
- import * as React from 'react';
2
- import { GenericSlice, Search } from '@gpa-gemstone/react-interactive';
3
- import { OpenXDA, SystemCenter, Application } from '@gpa-gemstone/application-typings';
4
- interface U {
5
- ID: number | string;
6
- }
7
- interface IProps<T extends U> {
8
- /** A Generic Slyce for the Search */
9
- Slice: GenericSlice<T>;
10
- /** Functions that gets available values for any ENUM Types */
11
- GetEnum: (setOptions: (options: IOptions[]) => void, field: Search.IField<T>) => () => void;
12
- /** Function that Grabs any additional Filters that shoudl be available (such as Addl Fields) */
13
- GetAddlFields: (setAddlFields: (cols: Search.IField<T>[]) => void) => () => void;
14
- children: React.ReactNode;
15
- AddlFilters?: Search.IFilter<T>[];
16
- StorageID?: string;
17
- }
18
- interface IOptions {
19
- Value: string;
20
- Label: string;
21
- }
22
- /** This Implements a few standardized SearchBars */
23
- export declare namespace DefaultSearch {
24
- /** This Implements a standard Meter Search */
25
- function Meter(props: IProps<SystemCenter.Types.DetailedMeter>): JSX.Element;
26
- /** This Implements a standard Substation Search */
27
- function Location(props: IProps<SystemCenter.Types.DetailedLocation>): JSX.Element;
28
- /** This Implements a standard Transmission Asset Search */
29
- function Asset(props: IProps<SystemCenter.Types.DetailedAsset>): JSX.Element;
30
- /** This Implements a standard AssetGroup Search */
31
- function AssetGroup(props: IProps<OpenXDA.Types.AssetGroup>): JSX.Element;
32
- /** This Implements a standard User Search */
33
- function User(props: IProps<Application.Types.iUserAccount>): JSX.Element;
34
- /** This Implements a standard Customer Search */
35
- function Customer(props: IProps<OpenXDA.Types.Customer>): JSX.Element;
36
- }
37
- export {};
1
+ import * as React from 'react';
2
+ import { GenericSlice, Search } from '@gpa-gemstone/react-interactive';
3
+ import { OpenXDA, SystemCenter, Application } from '@gpa-gemstone/application-typings';
4
+ interface U {
5
+ ID: number | string;
6
+ }
7
+ interface IProps<T extends U> {
8
+ /** A Generic Slyce for the Search */
9
+ Slice: GenericSlice<T>;
10
+ /** Functions that gets available values for any ENUM Types */
11
+ GetEnum: (setOptions: (options: IOptions[]) => void, field: Search.IField<T>) => () => void;
12
+ /** Function that Grabs any additional Filters that shoudl be available (such as Addl Fields) */
13
+ GetAddlFields: (setAddlFields: (cols: Search.IField<T>[]) => void) => () => void;
14
+ children: React.ReactNode;
15
+ AddlFilters?: Search.IFilter<T>[];
16
+ StorageID?: string;
17
+ }
18
+ interface IOptions {
19
+ Value: string;
20
+ Label: string;
21
+ }
22
+ /** This Implements a few standardized SearchBars */
23
+ export declare namespace DefaultSearch {
24
+ /** This Implements a standard Meter Search */
25
+ function Meter(props: IProps<SystemCenter.Types.DetailedMeter>): React.JSX.Element;
26
+ /** This Implements a standard Substation Search */
27
+ function Location(props: IProps<SystemCenter.Types.DetailedLocation>): React.JSX.Element;
28
+ /** This Implements a standard Transmission Asset Search */
29
+ function Asset(props: IProps<SystemCenter.Types.DetailedAsset>): React.JSX.Element;
30
+ /** This Implements a standard AssetGroup Search */
31
+ function AssetGroup(props: IProps<OpenXDA.Types.AssetGroup>): React.JSX.Element;
32
+ /** This Implements a standard User Search */
33
+ function User(props: IProps<Application.Types.iUserAccount>): React.JSX.Element;
34
+ /** This Implements a standard Customer Search */
35
+ function Customer(props: IProps<OpenXDA.Types.Customer>): React.JSX.Element;
36
+ }
37
+ export {};