@gpa-gemstone/common-pages 0.0.122 → 0.0.124

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,106 +0,0 @@
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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- var desc = Object.getOwnPropertyDescriptor(m, k);
26
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
- desc = { enumerable: true, get: function() { return m[k]; } };
28
- }
29
- Object.defineProperty(o, k2, desc);
30
- }) : (function(o, m, k, k2) {
31
- if (k2 === undefined) k2 = k;
32
- o[k2] = m[k];
33
- }));
34
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
- Object.defineProperty(o, "default", { enumerable: true, value: v });
36
- }) : function(o, v) {
37
- o["default"] = v;
38
- });
39
- var __importStar = (this && this.__importStar) || function (mod) {
40
- if (mod && mod.__esModule) return mod;
41
- var result = {};
42
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
- __setModuleDefault(result, mod);
44
- return result;
45
- };
46
- Object.defineProperty(exports, "__esModule", { value: true });
47
- var React = __importStar(require("react"));
48
- var _ = __importStar(require("lodash"));
49
- var react_forms_1 = require("@gpa-gemstone/react-forms");
50
- var react_redux_1 = require("react-redux");
51
- function UserPermission(props) {
52
- var dispatch = (0, react_redux_1.useDispatch)();
53
- var currentRoles = (0, react_redux_1.useSelector)(props.RoleSlice.Roles);
54
- var allRoleStatus = (0, react_redux_1.useSelector)(props.RoleSlice.Status);
55
- var availableRoles = (0, react_redux_1.useSelector)(props.RoleSlice.AvailableRoles);
56
- var currentRoleStatus = (0, react_redux_1.useSelector)(props.RoleSlice.CurrentRoleStatus);
57
- var _a = React.useState([]), workingRoles = _a[0], setWorkingRoles = _a[1];
58
- var _b = React.useState(false), changed = _b[0], setChanged = _b[1];
59
- React.useEffect(function () {
60
- if (allRoleStatus === 'unintiated' || allRoleStatus === 'changed')
61
- dispatch(props.RoleSlice.FetchRoles());
62
- }, [dispatch, allRoleStatus]);
63
- React.useEffect(function () {
64
- if (currentRoleStatus === 'unintiated' || currentRoleStatus === 'changed')
65
- dispatch(props.RoleSlice.FetchUserRoles(props.UserID));
66
- }, [dispatch, currentRoleStatus, props.UserID]);
67
- React.useEffect(function () {
68
- resetCurrentRoles(availableRoles, currentRoles);
69
- }, [currentRoles, availableRoles]);
70
- function resetCurrentRoles(avRoles, currRoles) {
71
- setChanged(false);
72
- setWorkingRoles(avRoles.map(function (src) {
73
- var upd = _.cloneDeep(src);
74
- upd.Assigned = currRoles.find(function (usrc) { return usrc.ApplicationRoleID === upd.ID; }) !== undefined;
75
- return upd;
76
- }));
77
- }
78
- return (React.createElement("div", { className: "card", style: { marginBottom: 10 } },
79
- React.createElement("div", { className: "card-header" },
80
- React.createElement("div", { className: "row" },
81
- React.createElement("div", { className: "col" },
82
- React.createElement("h4", null, "User Permissions:")))),
83
- React.createElement("div", { className: "card-body" },
84
- React.createElement("div", { className: "row" },
85
- React.createElement("div", { className: "col" },
86
- React.createElement("fieldset", { className: "border", style: { padding: '10px', height: '100%' } },
87
- React.createElement("legend", { className: "w-auto", style: { fontSize: 'large' } }, "System Center:"),
88
- 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) {
89
- scr.Assigned = record.Assigned;
90
- var newArray = _.clone(array);
91
- setWorkingRoles(newArray);
92
- setChanged(true);
93
- } }); })))),
94
- React.createElement("div", { className: "col" }))),
95
- React.createElement("div", { className: "card-footer" },
96
- React.createElement("div", { className: "btn-group mr-2" },
97
- React.createElement("button", { className: "btn btn-primary", onClick: function () {
98
- return dispatch(props.RoleSlice.SetUserRoles({
99
- UserId: props.UserID,
100
- Roles: workingRoles.filter(function (scr) { return scr.Assigned; }).map(function (scr) { return ({ ID: '00000000-0000-0000-0000-000000000000', ApplicationRoleID: scr.ID, UserAccountID: props.UserID }); })
101
- }));
102
- }, disabled: !changed }, "Update")),
103
- React.createElement("div", { className: "btn-group mr-2" },
104
- React.createElement("button", { className: "btn btn-default", onClick: function () { return resetCurrentRoles(availableRoles, currentRoles); }, disabled: !changed }, "Reset")))));
105
- }
106
- exports.default = UserPermission;