2 * STANDARD_RIFT_IO_COPYRIGHT
5 import React from 'react';
6 import ReactDOM from 'react-dom';
7 import AppHeader from 'widgets/header/header.jsx';
8 import PlatformRoleManagementStore from './platformRoleManagementStore.js';
9 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
10 import 'style/layout.scss';
11 import './platformRoleManagement.scss';
12 import {Panel, PanelWrapper} from 'widgets/panel/panel';
13 import {InputCollection, FormSection} from 'widgets/form_controls/formControls.jsx';
15 import TextInput from 'widgets/form_controls/textInput.jsx';
16 import Input from 'widgets/form_controls/input.jsx';
17 import Button, {ButtonGroup} from 'widgets/button/sq-button.jsx';
18 import SelectOption from 'widgets/form_controls/selectOption.jsx';
19 import 'widgets/form_controls/formControls.scss';
20 import imgAdd from '../../node_modules/open-iconic/svg/plus.svg'
21 import imgRemove from '../../node_modules/open-iconic/svg/trash.svg'
23 class PlatformRoleManagement extends React.Component {
26 this.Store = this.props.flux.stores.hasOwnProperty('PlatformRoleManagementStore') ? this.props.flux.stores.PlatformRoleManagementStore : this.props.flux.createStore(PlatformRoleManagementStore);
27 this.state = this.Store.getState();
28 this.actions = this.state.actions;
29 this.Store.getPlatform();
30 this.Store.getUsers();
32 componentDidUpdate() {
35 componentWillMount() {
36 this.Store.listen(this.updateState);
38 componentWillUnmount() {
39 this.Store.unlisten(this.updateState);
41 updateState = (state) => {
44 updateInput = (key, e) => {
46 this.actions.handleUpdateInput({
47 [property]:e.target.value
50 disabledChange = (e) => {
51 this.actions.handleDisabledChange(e.target.checked);
53 platformChange = (platformRole, e) => {
54 this.actions.handlePlatformRoleUpdate(platformRole, e.currentTarget.checked);
57 this.actions.editPlatform(false);
59 cancelEditPlatform = () => {
60 this.actions.editPlatform(true)
63 this.actions.handleCloseProjectPanel();
65 updatePlatform = (e) => {
69 let platformUsers = self.state.platformUsers;
70 let cleanUsers = this.cleanUsers(platformUsers);
71 this.Store.updatePlatform({
72 'user': JSON.stringify(cleanUsers)
76 cleanUsers(platformUsers) {
79 //Remove null values from role
80 platformUsers.map((u) => {
82 u.role && u.role.map((r,i) => {
84 //Platform user can not change role of itself.
86 //removing key for rbac-platform
92 if (u['user-name'] != self.context.userProfile.userId) {
98 evaluateSubmit = (e) => {
99 if (e.keyCode == 13) {
100 if (this.props.isEdit) {
101 this.updatePlatform(e);
107 updateSelectedUser = (e) => {
112 addUserToProject = (e) => {
113 this.actions.handleAddUser();
115 removeUserFromProject = (userIndex, e) => {
116 this.actions.handleRemoveUserFromProject(userIndex);
118 updateUserRoleInProject = (userIndex, roleIndex, e) => {
119 this.actions.handleUpdateUserRoleInProject({
122 value: JSON.parse(e.target.value)
125 toggleUserRoleInProject = (userIndex, roleIndex, e) => {
126 this.actions.handleToggleUserRoleInProject({
129 checked: JSON.parse(e.currentTarget.checked)
132 removeRoleFromUserInProject = (userIndex, roleIndex, e) => {
133 this.actions.handleRemoveRoleFromUserInProject({
138 addRoleToUserInProject = (userIndex, e) => {
139 this.actions.addRoleToUserInProject(userIndex);
141 onTransitionEnd = (e) => {
142 this.actions.handleHideColumns(e);
143 console.log('transition end')
145 disableChange = (e) => {
146 let value = e.target.value;
147 value = value.toUpperCase();
158 let props = this.props;
159 let state = this.state;
160 let passwordSectionHTML = null;
161 let formButtonsHTML = (
162 <ButtonGroup className="buttonGroup">
163 <Button label="EDIT" type="submit" onClick={this.editProject} />
166 let platformUsers = [];
167 self.state.platformUsers.map((u) => {
168 platformUsers.push(u['user-name']);
171 if(!this.state.isReadOnly) {
175 <ButtonGroup className="buttonGroup">
176 <Button label="Update" type="submit" onClick={this.updatePlatform} />
177 <Button label="Cancel" onClick={this.cancelEditPlatform} />
181 <ButtonGroup className="buttonGroup">
182 <Button label="Edit" type="submit" onClick={this.updatePlatform} />
189 <PanelWrapper column>
190 <AppHeader nav={[{name: 'USER MANAGEMENT', onClick: this.context.router.push.bind(this, {pathname: '/'})}]}/>
191 <PanelWrapper className={`row projectManagement ${false ? 'projectList-open' : ''}`} style={{'alignContent': 'center', 'flexDirection': 'row'}} >
192 <PanelWrapper onKeyUp={this.evaluateSubmit}
193 className={`ProjectAdmin column`}>
196 style={{marginBottom: 0}}
198 <FormSection title="USER ROLES">
203 {!state.isReadOnly ? <td></td> : null}
206 state.roles.map((r,i) => {
207 return <td key={i}>{r}</td>
214 state.platformUsers.map((u,i)=> {
215 let userRoles = u.role && u.role.map((r) => {
220 {!state.isReadOnly ? <td><span
221 className="removeInput"
222 onClick={self.removeUserFromProject.bind(self, i)}
224 <img src={imgRemove} />
231 state.roles.map((r,j) => {
232 return <td key={j}><Input readonly={state.isReadOnly} type="checkbox" onChange={self.toggleUserRoleInProject.bind(self, i, j)} checked={(userRoles.indexOf(r) > -1)} /></td>
243 <div className="tableRow tableRow--header">
245 <div className="addUser">
247 onChange={this.actions.handleSelectedUser}
248 defaultValue={state.selectedUser}
250 options={state.users && state.users.filter((u) => {
251 return platformUsers.indexOf(u['user-name']) == -1
254 label: u['user-name'],
259 <span className="addInput" onClick={this.addUserToProject}><img src={imgAdd} />
277 // onClick={this.Store.update.bind(null, Account)}
278 PlatformRoleManagement.contextTypes = {
279 router: React.PropTypes.object,
280 userProfile: React.PropTypes.object
283 PlatformRoleManagement.defaultProps = {
288 export default SkyquakeComponent(PlatformRoleManagement);
291 function isElementInView(el) {
292 var rect = el && el.getBoundingClientRect() || {};
297 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
298 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
303 // isReadOnly={state.isReadOnly} disabled={state.disabled} onChange={this.disableChange}
305 class isDisabled extends React.Component {
310 let props = this.props;