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 UserManagementStore from './userMgmtStore.js';
9 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
10 import 'style/layout.scss';
11 import './userMgmt.scss';
12 import {Panel, PanelWrapper} from 'widgets/panel/panel';
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 UserManagementDashboard extends React.Component {
26 this.Store = this.props.flux.stores.hasOwnProperty('UserManagementStore') ? this.props.flux.stores.UserManagementStore : this.props.flux.createStore(UserManagementStore);
27 this.Store.getUsers();
28 this.state = this.Store.getState();
29 this.actions = this.state.actions;
31 componentDidUpdate() {
33 ReactDOM.findDOMNode(this.UserList).addEventListener('transitionend', this.onTransitionEnd, false);
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);
56 addProjectRole = (e) => {
57 this.actions.handleAddProjectItem();
59 removeProjectRole = (i, e) => {
60 this.actions.handleRemoveProjectItem(i);
62 updateProjectRole = (i, e) => {
63 this.actions.handleUpdateProjectRole(i, e)
66 this.actions.handleAddUser();
68 viewUser = (un, index) => {
70 this.actions.viewUser(un, index);
73 this.actions.handleCloseUserPanel();
79 this.Store.updateUser();
84 this.Store.deleteUser({
85 'user-name': this.state['user-name'],
86 'user-domain': this.state['user-domain']
92 if(this.state['new-password'] != this.state['confirm-password']) {
93 this.props.actions.showNotification('Passwords do not match')
95 this.Store.createUser({
96 'user-name': this.state['user-name'],
97 'user-domain': this.state['user-domain'],
98 'password': this.state['new-password']
99 // 'confirm-password': this.state['confirm-password']
104 onTransitionEnd = (e) => {
105 this.actions.handleHideColumns(e);
106 console.log('transition end')
111 let props = this.props;
112 let state = this.state;
114 <PanelWrapper className={`row userManagement ${!this.state.userOpen ? 'userList-open' : ''}`} style={{'alignContent': 'center', 'flexDirection': 'row'}} >
115 <PanelWrapper ref={(div) => { this.UserList = div}} className={`column userList expanded ${this.state.userOpen ? 'collapsed ' : ' '} ${this.state.hideColumns ? 'hideColumns ' : ' '}`}>
116 <Panel title="User List" style={{marginBottom: 0}} no-corners>
117 <div className="tableRow tableRow--header">
118 <div className="userName">
125 {state.users.map((u, k) => {
126 let platformRoles = [];
127 for(let role in u.platformRoles) {
128 platformRoles.push(<div>{`${role}: ${u.platformRoles[role]}`}</div>)
131 <div className={`tableRow tableRow--data ${((self.state.activeIndex == k) && !self.state.userOpen) ? 'tableRow--data-active' : ''}`} key={k}>
133 className={`userName userName-header ${((self.state.activeIndex == k) && self.state.userOpen) ? 'activeUser' : ''}`}
134 onClick={self.viewUser.bind(null, u, k)}>
146 <ButtonGroup className="buttonGroup" style={{margin: '0 0.5rem 0.5rem', background: '#ddd', paddingBottom: '0.5rem'}}>
147 <Button label="Add User" onClick={this.addUser} />
151 className={`userAdmin column`}>
153 title={state.isEdit ? state['user-name'] : 'Create User'}
154 style={{marginBottom: 0}}
155 hasCloseButton={this.closePanel}
157 <FormSection title="USER INFO">
161 : <Input label="Username" value={state['user-name']} onChange={this.updateInput.bind(null, 'user-name')} />
163 <Input label="Domain" value={state['user-domain']} onChange={this.updateInput.bind(null, 'user-domain')}></Input>
164 <Input label="Disabled" onChange={this.disabledChange} checked={state.disabled} type="checkbox" />
166 <FormSection title="PLATFORM ROLES">
167 <Input label="Super Admin" onChange={this.platformChange.bind(null, 'super_admin')} checked={state.platformRoles.super_admin} type="checkbox" />
168 <Input label="Platform Admin" onChange={this.platformChange.bind(null, 'platform_admin')} checked={state.platformRoles.platform_admin} type="checkbox" />
169 <Input label="Platform Oper" onChange={this.platformChange.bind(null, 'platform_oper')} checked={state.platformRoles.platform_oper} type="checkbox" />
171 <FormSection title="PROJECT ROLES">
175 options={state.projectRolesOptions}
176 collection={state.projectRoles}
177 onChange={this.updateProjectRole}
178 AddItemFn={this.addProjectRole}
179 RemoveItemFn={this.removeProjectRole}
182 { this.state.isEdit ?
184 <FormSection title="PASSWORD CHANGE">
185 <Input label="OLD PASSWORD" type="password" value={state['old-password']} onChange={this.updateInput.bind(null, 'old-password')} />
186 <Input label="NEW PASSWORD" type="password" value={state['new-password']} onChange={this.updateInput.bind(null, 'new-password')}/>
187 <Input label="REPEAT NEW PASSWORD" type="password" value={state['confirm-password']} onChange={this.updateInput.bind(null, 'confirm-password')}/>
191 <FormSection title="CREATE PASSWORD">
192 <Input label="CREATE PASSWORD" type="password" value={state.newPassword} onChange={this.updateInput.bind(null, 'new-password')}/>
193 <Input label="REPEAT PASSWORD" type="password" value={state.repeatNewPassword} onChange={this.updateInput.bind(null, 'confirm-password')}/>
203 <ButtonGroup className="buttonGroup">
204 <Button label="Update" onClick={this.updateUser} />
205 <Button label="Delete" onClick={this.deleteUser} />
209 <ButtonGroup className="buttonGroup">
210 <Button label="Create" onClick={this.createUser} />
222 // onClick={this.Store.update.bind(null, Account)}
223 UserManagementDashboard.contextTypes = {
224 router: React.PropTypes.object
227 UserManagementDashboard.defaultProps = {
232 export default SkyquakeComponent(UserManagementDashboard);
240 class InputCollection extends React.Component {
243 this.collection = props.collection;
245 buildTextInput(onChange, v, i) {
248 style={{flex: '1 1'}}
251 onChange= {onChange.bind(null, i)}
255 buildSelectOption(initial, options, onChange, v, i) {
258 key={`${i}-${v.replace(' ', '_')}`}
262 onChange={onChange.bind(null, i)}
270 const props = this.props;
272 let className = "InputCollection";
273 if (props.className) {
274 className = `${className} ${props.className}`;
276 if (props.type == 'select') {
277 inputType = this.buildSelectOption.bind(this, props.initial, props.options, props.onChange);
279 inputType = this.buildTextInput.bind(this, props.onChange)
282 <div className="InputCollection-wrapper">
283 {props.collection.map((v,i) => {
285 <div key={i} className={className} >
287 <span onClick={props.RemoveItemFn.bind(null, i)} className="removeInput"><img src={imgRemove} />Remove</span>
291 <span onClick={props.AddItemFn} className="addInput"><img src={imgAdd} />Add</span>
298 InputCollection.defaultProps = {
301 onChange: function(i, e) {
303 Updating with: ${e.target.value}
307 AddItemFn: function(e) {
308 console.log(`Adding a new item to collection`)
310 RemoveItemFn: function(i, e) {
311 console.log(`Removing item from collection at index of: ${i}`)
315 class FormSection extends React.Component {
317 let className = 'FormSection ' + this.props.className;
320 style={this.props.style}
321 className={className}
323 <div className="FormSection-title">
326 <div className="FormSection-body">
327 {this.props.children}
335 FormSection.defaultProps = {