@gpa-gemstone/common-pages 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { Application, SystemCenter } from '@gpa-gemstone/application-typings';
3
+ import { IAdditionalFieldSlice, IGenericSlice, ISecurityRoleSlice, IUserAccountSlice } from '../SliceInterfaces';
4
+ interface IProps {
5
+ UserID: string;
6
+ OnDelete: () => void;
7
+ SecurityRoleSlice: ISecurityRoleSlice;
8
+ UserSlice: IUserAccountSlice;
9
+ AdditionalFieldSlice: IAdditionalFieldSlice<Application.Types.iAdditionalUserField, Application.Types.iAdditionalUserFieldValue>;
10
+ ValueListItemSlice: IGenericSlice<SystemCenter.Types.ValueListItem>;
11
+ ValueListGroupSlice: IGenericSlice<SystemCenter.Types.ValueListGroup>;
12
+ }
13
+ declare function User(props: IProps): JSX.Element;
14
+ export default User;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // User.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/14/2021 - C. Lackner
21
+ // Generated original version of source code.
22
+ // ******************************************************************************************************
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ var React = require("react");
25
+ var react_interactive_1 = require("@gpa-gemstone/react-interactive");
26
+ var UserInfo_1 = require("./UserInfo");
27
+ var UserPermissions_1 = require("./UserPermissions");
28
+ var AdditionalField_1 = require("./AdditionalField");
29
+ var react_redux_1 = require("react-redux");
30
+ var react_forms_1 = require("@gpa-gemstone/react-forms");
31
+ function User(props) {
32
+ var dispatch = react_redux_1.useDispatch();
33
+ var user = react_redux_1.useSelector(props.UserSlice.CurrentUser);
34
+ var status = react_redux_1.useSelector(props.UserSlice.Status);
35
+ var _a = React.useState('userInfo'), tab = _a[0], setTab = _a[1];
36
+ var _b = React.useState(false), showWarning = _b[0], setShowWarning = _b[1];
37
+ React.useEffect(function () {
38
+ dispatch(props.UserSlice.LoadExistingUser(props.UserID));
39
+ }, [dispatch, props.UserID]);
40
+ if (status === 'error')
41
+ return React.createElement("div", { style: { width: '100%', height: '100%' } },
42
+ React.createElement(react_interactive_1.ServerErrorIcon, { Show: true, Label: 'A Server Error Occured. Please Reload the Application' }));
43
+ var Tabs = [
44
+ { Id: "userInfo", Label: "User Info" },
45
+ { Id: "permissions", Label: "Permissions" },
46
+ { Id: "additionalFields", Label: "Additional Fields" }
47
+ ];
48
+ return (React.createElement("div", { style: { width: '100%', height: window.innerHeight - 63, maxHeight: window.innerHeight - 63, overflow: 'hidden', padding: 15 } },
49
+ React.createElement("div", { className: "row" },
50
+ React.createElement("div", { className: "col" },
51
+ React.createElement("h2", null, user != null ? user.FirstName + " " + user.LastName : '')),
52
+ React.createElement("div", { className: "col" },
53
+ React.createElement("button", { className: "btn btn-danger pull-right", hidden: user == null, onClick: function () { return setShowWarning(true); } }, "Delete User"))),
54
+ React.createElement(react_interactive_1.LoadingScreen, { Show: status === 'loading' }),
55
+ React.createElement("hr", null),
56
+ React.createElement(react_interactive_1.TabSelector, { CurrentTab: tab, SetTab: function (t) { return setTab(t); }, Tabs: Tabs }),
57
+ React.createElement("div", { className: "tab-content", style: { maxHeight: window.innerHeight - 235, overflow: 'hidden' } },
58
+ React.createElement("div", { className: "tab-pane " + (tab === "userInfo" ? " active" : "fade") },
59
+ React.createElement(UserInfo_1.default, { UserSlice: props.UserSlice })),
60
+ React.createElement("div", { className: "tab-pane " + (tab === "permissions" ? " active" : "fade") }, user == null ? null : React.createElement(UserPermissions_1.default, { UserID: user.ID, RoleSlice: props.SecurityRoleSlice })),
61
+ React.createElement("div", { className: "tab-pane " + (tab === "additionalFields" ? " active" : "fade"), style: { maxHeight: window.innerHeight - 215 } },
62
+ React.createElement(AdditionalField_1.default, { Id: props.UserID, AdditionalFieldSlice: props.AdditionalFieldSlice, ValueListItemSlice: props.ValueListItemSlice, ValueListGroupSlice: props.ValueListGroupSlice, EmptyField: { ID: -1, IsSecure: false, FieldName: '', Type: 'string' }, GetFieldValueIndex: function (field, values) { return values.findIndex(function (v) { return v.AdditionalUserFieldID === field.ID; }); }, GetFieldIndex: function (value, fields) { return fields.findIndex(function (f) { return f.ID === value.AdditionalUserFieldID; }); }, FieldKeySelector: function (field) { return (field.ID === -1 ? 'new' : field.ID.toString()); }, ValidateField: function () { return []; }, FieldUI: function (fld, setter) { return React.createElement(react_forms_1.CheckBox, { Record: fld, Field: 'IsSecure', Label: "Secure Data", Setter: setter }); }, CreateValue: function (fld) { return ({ Value: '', ID: -1, UserAccountID: props.UserID, AdditionalUserFieldID: fld.ID }); } }))),
63
+ React.createElement(react_interactive_1.Warning, { Message: 'This will permanently remove the User. Are you sure you want to continue?', Title: 'Warning', Show: showWarning, CallBack: function (c) {
64
+ setShowWarning(false);
65
+ if (c) {
66
+ dispatch(props.UserSlice.DBAction({ verb: 'DELETE', record: user }));
67
+ props.OnDelete();
68
+ }
69
+ } })));
70
+ }
71
+ exports.default = User;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { Application } from '@gpa-gemstone/application-typings';
3
+ import { IUserAccountSlice } from '../SliceInterfaces';
4
+ interface IProps {
5
+ UserAccount: Application.Types.iUserAccount;
6
+ Setter: (record: Application.Types.iUserAccount) => void;
7
+ Edit: boolean;
8
+ SetErrors?: (e: string[]) => void;
9
+ UserSlice: IUserAccountSlice;
10
+ }
11
+ declare function UserForm(props: IProps): JSX.Element | null;
12
+ export default UserForm;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // UserForm.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/14/2021 - C. Lackner
21
+ // Generated original version of source code.
22
+ // ******************************************************************************************************
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ var React = require("react");
25
+ var react_forms_1 = require("@gpa-gemstone/react-forms");
26
+ var _ = require("lodash");
27
+ var react_redux_1 = require("react-redux");
28
+ function UserForm(props) {
29
+ var dispatch = react_redux_1.useDispatch();
30
+ var _a = React.useState(false), updatedAD = _a[0], setUpdatedAD = _a[1];
31
+ var userValidation = react_redux_1.useSelector(props.UserSlice.ADValidation);
32
+ var _b = React.useState([]), userError = _b[0], setUserError = _b[1];
33
+ React.useEffect(function () {
34
+ if (userValidation === 'Valid' && !props.Edit && updatedAD === false)
35
+ dispatch(props.UserSlice.ADUpdate());
36
+ }, [userValidation, updatedAD]);
37
+ React.useEffect(function () {
38
+ if (props.SetErrors !== undefined)
39
+ props.SetErrors(userError);
40
+ }, [userError, props.SetErrors]);
41
+ React.useEffect(function () {
42
+ if (props.UserAccount == null)
43
+ return;
44
+ var e = [];
45
+ if (props.UserAccount.Name == null || props.UserAccount.Name.length === 0)
46
+ e.push('An AccountName is required.');
47
+ if (props.UserAccount.UseADAuthentication && userValidation !== 'Valid')
48
+ e.push('The user could not be validated by the AD.');
49
+ setUserError(e);
50
+ }, [props.UserAccount, userValidation]);
51
+ function validUserAccountField(user, field) {
52
+ if (field === 'Name')
53
+ return user.Name != null && user.Name.length > 0 && user.Name.length <= 200;
54
+ else if (field === 'Password')
55
+ return user.Password == null || user.Password.length <= 200;
56
+ else if (field === 'FirstName')
57
+ return user.FirstName == null || user.FirstName.length <= 200;
58
+ else if (field === 'LastName')
59
+ return user.LastName == null || user.LastName.length <= 200;
60
+ else if (field === 'Phone')
61
+ return user.Phone == null || user.Phone.length <= 200;
62
+ else if (field === 'Email')
63
+ return user.Email == null || user.Email.length <= 200;
64
+ return false;
65
+ }
66
+ if (props.UserAccount == null)
67
+ return null;
68
+ return (React.createElement(React.Fragment, null,
69
+ React.createElement("form", null,
70
+ React.createElement("div", { className: "row" },
71
+ React.createElement("div", { className: "col" },
72
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Disabled: props.Edit, Field: 'Name', Feedback: 'A Name of less than 200 characters is required.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: function (record) {
73
+ setUpdatedAD(false);
74
+ props.Setter(record);
75
+ } }),
76
+ React.createElement("div", { className: "row", style: { position: 'absolute', top: 0, left: 100 }, hidden: !props.UserAccount.UseADAuthentication },
77
+ React.createElement("span", { id: "resolvingAccount", hidden: userValidation !== 'Resolving' },
78
+ React.createElement("i", { style: { height: 10, width: 10, color: 'grey' }, className: "fa fa fa-spin fa-refresh" }),
79
+ "\u00A0",
80
+ React.createElement("em", { className: "small" }, "Resolving account details...")),
81
+ React.createElement("span", { id: "accountValid", hidden: userValidation !== 'Valid' },
82
+ React.createElement("i", { style: { height: 20, width: 20, color: 'green' }, className: "fa fa-check-circle" }),
83
+ "\u00A0",
84
+ React.createElement("em", { className: "small" }, "Resolved account name ")),
85
+ React.createElement("span", { id: "accountInvalid", hidden: userValidation !== 'Invalid' },
86
+ React.createElement("i", { style: { height: 20, width: 20, color: 'red' }, className: "fa fa-times-circle" }),
87
+ "\u00A0",
88
+ React.createElement("em", { className: "small" }, "Cannot resolve account name")),
89
+ React.createElement("span", { id: "accountUnknown", hidden: userValidation !== 'Unknown' },
90
+ React.createElement("i", { style: { height: 20, width: 20, color: 'orange' }, className: "fa fa-exclamation-circle" }),
91
+ "\u00A0",
92
+ React.createElement("em", { className: "small" }, "Valid account name is not a user or Active Directory access is limited"))),
93
+ React.createElement("button", { style: { marginBottom: 10 }, type: "button", className: "btn btn-primary btn-sm", onClick: function (evt) { evt.preventDefault(); dispatch(props.UserSlice.ADUpdate()); }, hidden: userValidation !== 'Valid' || !props.Edit }, "Load Information from AD"),
94
+ React.createElement("div", { className: "card" },
95
+ React.createElement("div", { className: "card-header" },
96
+ React.createElement("div", { className: "row" },
97
+ React.createElement("div", { className: "col-xs-4" },
98
+ React.createElement("div", { className: "form-check-inline" },
99
+ React.createElement("label", { className: "form-check-label" },
100
+ React.createElement("input", { disabled: props.Edit, className: 'form-check-input', type: 'radio', checked: props.UserAccount.UseADAuthentication, onChange: function (e) {
101
+ var record = _.clone(props.UserAccount);
102
+ record.UseADAuthentication = e.target.checked;
103
+ props.Setter(record);
104
+ } }),
105
+ "Active Directory User"))),
106
+ React.createElement("div", { className: "col-xs-4" },
107
+ React.createElement("div", { className: "form-check-inline" },
108
+ React.createElement("label", { className: "form-check-label" },
109
+ React.createElement("input", { disabled: props.Edit, className: 'form-check-input', type: 'radio', checked: !props.UserAccount.UseADAuthentication, onChange: function (e) {
110
+ var record = _.clone(props.UserAccount);
111
+ record.UseADAuthentication = !e.target.checked;
112
+ props.Setter(record);
113
+ } }),
114
+ "Database User"))))),
115
+ React.createElement("div", { className: "card-body", hidden: !props.UserAccount.UseADAuthentication },
116
+ React.createElement("div", { className: "row" },
117
+ React.createElement("div", { className: "col" },
118
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'FirstName', Label: 'First Name', Feedback: 'First Name must be less than 200 characters.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter }),
119
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'LastName', Label: 'Last Name', Feedback: 'Last Name must be less than 200 characters.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter })),
120
+ React.createElement("div", { className: "col" },
121
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'Phone', Feedback: 'Phone must be less than 200 characters.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter }),
122
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'Email', Feedback: 'Email must be less than 200 characters.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter })))),
123
+ React.createElement("div", { className: "card-body", hidden: props.UserAccount.UseADAuthentication },
124
+ React.createElement("div", { className: "row" },
125
+ React.createElement("div", { className: "col" },
126
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'Password', Feedback: 'Password must be less than 200 characters.', Type: 'password', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter }),
127
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'FirstName', Label: 'First Name', Feedback: 'First Name must be less than 200 characters.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter }),
128
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'LastName', Label: 'Last Name', Feedback: 'Last Name must be less than 200 characters.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter })),
129
+ React.createElement("div", { className: "col" },
130
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'Phone', Feedback: 'Password must be less than 200 characters.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter }),
131
+ React.createElement(react_forms_1.Input, { Record: props.UserAccount, Field: 'Email', Feedback: 'Password must be less than 200 characters.', Valid: function (field) { return validUserAccountField(props.UserAccount, field); }, Setter: props.Setter }),
132
+ React.createElement(react_forms_1.DatePicker, { Record: props.UserAccount, Field: 'ChangePasswordOn', Label: 'Change Password On', Setter: props.Setter })))),
133
+ React.createElement("div", { className: "row" },
134
+ React.createElement("div", { className: "col", style: { margin: 10 } },
135
+ React.createElement(react_forms_1.CheckBox, { Record: props.UserAccount, Label: 'Locked Out', Field: 'LockedOut', Setter: props.Setter }),
136
+ React.createElement(react_forms_1.CheckBox, { Record: props.UserAccount, Field: 'Approved', Setter: props.Setter })),
137
+ React.createElement("div", { className: "col-lg-6" },
138
+ React.createElement(react_forms_1.CheckBox, { Record: props.UserAccount, Label: 'Phone Confirmed', Field: 'PhoneConfirmed', Setter: props.Setter }),
139
+ React.createElement(react_forms_1.CheckBox, { Record: props.UserAccount, Label: 'Email Confirmed', Field: 'EmailConfirmed', Setter: props.Setter })))))))));
140
+ }
141
+ exports.default = UserForm;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { IUserAccountSlice } from '../SliceInterfaces';
3
+ interface IProps {
4
+ UserSlice: IUserAccountSlice;
5
+ }
6
+ declare function UserInfo(props: IProps): JSX.Element;
7
+ export default UserInfo;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // UserInfo.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/14/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 CryptoJS = require("crypto-js");
37
+ var UserForm_1 = require("./UserForm");
38
+ var react_interactive_1 = require("@gpa-gemstone/react-interactive");
39
+ var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
40
+ var react_redux_1 = require("react-redux");
41
+ function UserInfo(props) {
42
+ var dispatch = react_redux_1.useDispatch();
43
+ var currentUser = react_redux_1.useSelector(props.UserSlice.CurrentUser);
44
+ var _a = React.useState(currentUser), user = _a[0], setUser = _a[1];
45
+ var _b = React.useState([]), warnings = _b[0], setWarning = _b[1];
46
+ var _c = React.useState('None'), hover = _c[0], setHover = _c[1];
47
+ React.useEffect(function () {
48
+ if (currentUser == null || user == null)
49
+ return;
50
+ var encryptedPwd = (user.Password !== currentUser.Password ? CryptoJS.SHA256(user.Password + "0").toString(CryptoJS.enc.Base64) : user.Password);
51
+ var w = [];
52
+ if (currentUser.FirstName !== user.FirstName)
53
+ w.push('Changes to First Name will be lost.');
54
+ if (currentUser.LastName !== user.LastName)
55
+ w.push('Changes to Last Name will be lost.');
56
+ if (currentUser.Phone !== user.Phone)
57
+ w.push('Changes to Phone will be lost.');
58
+ if (currentUser.Email !== user.Email)
59
+ w.push('Changes to Email will be lost.');
60
+ if (currentUser.ChangePasswordOn !== user.ChangePasswordOn)
61
+ w.push('Changes to Change Password Date will be lost.');
62
+ if (currentUser.LockedOut !== user.LockedOut)
63
+ w.push('Changes to Account Locked Status will be lost.');
64
+ if (currentUser.Approved !== user.Approved)
65
+ w.push('Changes Account Approved Status will be lost.');
66
+ if (currentUser.PhoneConfirmed !== user.PhoneConfirmed)
67
+ w.push('Changes to Phone Confirmed Status will be lost.');
68
+ if (currentUser.EmailConfirmed !== user.EmailConfirmed)
69
+ w.push('Changes to Email confirmed Status will be lost.');
70
+ if (!currentUser.UseADAuthentication && currentUser.Password !== encryptedPwd)
71
+ w.push('Changes to Password will be lost.');
72
+ setWarning(w);
73
+ }, [currentUser, user]);
74
+ React.useEffect(function () { setUser(currentUser); }, [currentUser]);
75
+ function updateUser() {
76
+ var encryptedPwd = (user.Password !== currentUser.Password ? CryptoJS.SHA256(user.Password + "0").toString(CryptoJS.enc.Base64) : user.Password);
77
+ dispatch(props.UserSlice.SetCurrentUser(__assign(__assign({}, user), { Name: currentUser.Name, Password: encryptedPwd })));
78
+ dispatch(props.UserSlice.DBAction({ verb: 'PATCH', record: __assign(__assign({}, user), { Name: currentUser.Name, Password: encryptedPwd }) }));
79
+ }
80
+ return (React.createElement("div", { className: "card", style: { marginBottom: 10 } },
81
+ React.createElement("div", { className: "card-header" },
82
+ React.createElement("div", { className: "row" },
83
+ React.createElement("div", { className: "col" },
84
+ React.createElement("h4", null, "User Information:")))),
85
+ React.createElement("div", { className: "card-body", style: { height: window.innerHeight - 440, maxHeight: window.innerHeight - 440, overflowY: 'auto' } },
86
+ React.createElement(UserForm_1.default, { UserAccount: user, Setter: function (u) { return setUser(u); }, Edit: true, UserSlice: props.UserSlice })),
87
+ React.createElement("div", { className: "card-footer" },
88
+ React.createElement("div", { className: "btn-group mr-2" },
89
+ React.createElement("button", { className: "btn btn-primary", onClick: function () { return updateUser(); }, disabled: warnings.length === 0 }, "Update")),
90
+ React.createElement("div", { className: "btn-group mr-2" },
91
+ React.createElement("button", { className: "btn btn-default", onClick: function () { return setUser(currentUser); }, disabled: warnings.length === 0, "data-tooltip": 'Clr', onMouseEnter: function () { return setHover('Clear'); }, onMouseLeave: function () { return setHover('None'); } }, "Reset")),
92
+ React.createElement(react_interactive_1.ToolTip, { Show: hover === 'Clear' && (warnings.length > 0), Position: 'top', Theme: 'dark', Target: "Clr" }, warnings.map(function (t, i) { return React.createElement("p", { key: i },
93
+ gpa_symbols_1.Warning,
94
+ " ",
95
+ t); })))));
96
+ }
97
+ exports.default = UserInfo;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { ISecurityRoleSlice } from '../SliceInterfaces';
3
+ interface IProps {
4
+ UserID: string;
5
+ RoleSlice: ISecurityRoleSlice;
6
+ }
7
+ declare function UserPermission(props: IProps): JSX.Element;
8
+ export default UserPermission;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // UserPermission.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/14/2021 - C. Lackner
21
+ // Generated original version of source code.
22
+ // ******************************************************************************************************
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ var React = require("react");
25
+ var _ = require("lodash");
26
+ var react_forms_1 = require("@gpa-gemstone/react-forms");
27
+ var react_redux_1 = require("react-redux");
28
+ function UserPermission(props) {
29
+ var dispatch = react_redux_1.useDispatch();
30
+ var currentRoles = react_redux_1.useSelector(props.RoleSlice.Roles);
31
+ var allRoleStatus = react_redux_1.useSelector(props.RoleSlice.Status);
32
+ var availableRoles = react_redux_1.useSelector(props.RoleSlice.AvailableRoles);
33
+ var currentRoleStatus = react_redux_1.useSelector(props.RoleSlice.CurrentRoleStatus);
34
+ var _a = React.useState([]), workingRoles = _a[0], setWorkingRoles = _a[1];
35
+ var _b = React.useState(false), changed = _b[0], setChanged = _b[1];
36
+ React.useEffect(function () {
37
+ if (allRoleStatus === 'unintiated' || allRoleStatus === 'changed')
38
+ dispatch(props.RoleSlice.FetchRoles());
39
+ }, [dispatch, allRoleStatus]);
40
+ React.useEffect(function () {
41
+ if (currentRoleStatus === 'unintiated' || currentRoleStatus === 'changed')
42
+ dispatch(props.RoleSlice.FetchUserRoles(props.UserID));
43
+ }, [dispatch, currentRoleStatus, props.UserID]);
44
+ React.useEffect(function () {
45
+ resetCurrentRoles(availableRoles, currentRoles);
46
+ }, [currentRoles, availableRoles]);
47
+ function resetCurrentRoles(avRoles, currRoles) {
48
+ setChanged(false);
49
+ setWorkingRoles(avRoles.map(function (src) {
50
+ var upd = _.cloneDeep(src);
51
+ upd.Assigned = currRoles.find(function (usrc) { return usrc.ApplicationRoleID === upd.ID; }) !== undefined;
52
+ return upd;
53
+ }));
54
+ }
55
+ return (React.createElement("div", { className: "card", style: { marginBottom: 10 } },
56
+ React.createElement("div", { className: "card-header" },
57
+ React.createElement("div", { className: "row" },
58
+ React.createElement("div", { className: "col" },
59
+ React.createElement("h4", null, "User Permissions:")))),
60
+ React.createElement("div", { className: "card-body" },
61
+ React.createElement("div", { className: "row" },
62
+ React.createElement("div", { className: "col" },
63
+ React.createElement("fieldset", { className: "border", style: { padding: '10px', height: '100%' } },
64
+ React.createElement("legend", { className: "w-auto", style: { fontSize: 'large' } }, "System Center:"),
65
+ React.createElement("form", null, workingRoles.map(function (scr, i, array) { return React.createElement(react_forms_1.CheckBox, { key: scr.ID, Record: scr, Field: 'Assigned', Label: scr.Name, Setter: function (record) {
66
+ scr.Assigned = record.Assigned;
67
+ var newArray = _.clone(array);
68
+ setWorkingRoles(newArray);
69
+ setChanged(true);
70
+ } }); })))),
71
+ React.createElement("div", { className: "col" }))),
72
+ React.createElement("div", { className: "card-footer" },
73
+ React.createElement("div", { className: "btn-group mr-2" },
74
+ React.createElement("button", { className: "btn btn-primary", onClick: function () {
75
+ return dispatch(props.RoleSlice.SetUserRoles({
76
+ UserId: props.UserID,
77
+ Roles: workingRoles.filter(function (scr) { return scr.Assigned; }).map(function (scr) { return ({ ID: '00000000-0000-0000-0000-000000000000', ApplicationRoleID: scr.ID, UserAccountID: props.UserID }); })
78
+ }));
79
+ }, disabled: !changed }, "Update")),
80
+ React.createElement("div", { className: "btn-group mr-2" },
81
+ React.createElement("button", { className: "btn btn-default", onClick: function () { return resetCurrentRoles(availableRoles, currentRoles); }, disabled: !changed }, "Reset")))));
82
+ }
83
+ exports.default = UserPermission;
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@gpa-gemstone/common-pages",
3
+ "version": "0.0.14",
4
+ "description": "Common UI pages for GPA products",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/**/*"
9
+ ],
10
+ "scripts": {
11
+ "test": "jest --config jestconfig.json",
12
+ "build": "tsc",
13
+ "format": "prettier --write \"src/**/*.tsx\"",
14
+ "lint": "tslint -p tsconfig.json",
15
+ "prepare": "npm run build",
16
+ "prepublishOnly": "npm test && npm run lint",
17
+ "preversion": "npm run lint",
18
+ "version": "npm run format && git add -A src",
19
+ "postversion": "git push && git push --tags"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/GridProtectionAlliance/gpa-gemstone.git"
24
+ },
25
+ "keywords": [
26
+ "React",
27
+ "Interactive",
28
+ "GSF",
29
+ "Gemstone",
30
+ "GridProtectionAlliance"
31
+ ],
32
+ "author": "GridProtectionAlliance",
33
+ "license": "MIT",
34
+ "bugs": {
35
+ "url": "https://github.com/GridProtectionAlliance/gpa-gemstone/issues"
36
+ },
37
+ "homepage": "https://github.com/GridProtectionAlliance/gpa-gemstone#readme",
38
+ "devDependencies": {
39
+ "@types/jest": "^26.0.4",
40
+ "jest": "^27.0.6",
41
+ "prettier": "^2.3.2",
42
+ "ts-jest": "^27.0.3",
43
+ "tslint": "^6.1.3",
44
+ "tslint-config-prettier": "^1.18.0",
45
+ "typescript": "4.3.4",
46
+ "@types/jquery": "3.5.6",
47
+ "@types/crypto-js": "4.0.2"
48
+ },
49
+ "dependencies": {
50
+ "@gpa-gemstone/application-typings": "0.0.26",
51
+ "@gpa-gemstone/gpa-symbols": "0.0.13",
52
+ "@gpa-gemstone/react-forms": "1.1.12",
53
+ "@gpa-gemstone/react-interactive": "1.0.17",
54
+ "@gpa-gemstone/react-table": "1.2.4",
55
+ "@gpa-gemstone/helper-functions": "0.0.8",
56
+ "moment": "^2.29.1",
57
+ "react": "^17.0.2",
58
+ "styled-components": "^5.3.0",
59
+ "crypto-js": "4.0.0",
60
+ "react-redux": "7.2.4",
61
+ "@reduxjs/toolkit": "1.6.0"
62
+ },
63
+ "publishConfig": {
64
+ "access": "public"
65
+ }
66
+ }