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']
103 evaluateSubmit = (e) => {
104 if (e.keyCode == 13) {
105 if (this.props.isEdit) {
114 onTransitionEnd = (e) => {
115 this.actions.handleHideColumns(e);
116 console.log('transition end')
121 let props = this.props;
122 let state = this.state;
124 <PanelWrapper className={`row userManagement ${!this.state.userOpen ? 'userList-open' : ''}`} style={{'alignContent': 'center', 'flexDirection': 'row'}} >
125 <PanelWrapper ref={(div) => { this.UserList = div}} className={`column userList expanded ${this.state.userOpen ? 'collapsed ' : ' '} ${this.state.hideColumns ? 'hideColumns ' : ' '}`}>
126 <Panel title="User List" style={{marginBottom: 0}} no-corners>
127 <div className="tableRow tableRow--header">
128 <div className="userName">
135 {state.users && state.users.map((u, k) => {
136 let platformRoles = [];
137 for(let role in u.platformRoles) {
138 platformRoles.push(<div>{`${role}: ${u.platformRoles[role]}`}</div>)
141 <div className={`tableRow tableRow--data ${((self.state.activeIndex == k) && self.state.userOpen) ? 'tableRow--data-active' : ''}`} key={k}>
143 className={`userName userName-header ${((self.state.activeIndex == k) && self.state.userOpen) ? 'activeUser' : ''}`}
144 onClick={self.viewUser.bind(null, u, k)}>
156 <ButtonGroup className="buttonGroup" style={{margin: '0 0.5rem 0.5rem', background: '#ddd', paddingBottom: '0.5rem'}}>
157 <Button label="Add User" onClick={this.addUser} />
160 <PanelWrapper onKeyUp={this.evaluateSubmit}
161 className={`userAdmin column`}>
163 title={state.isEdit ? state['user-name'] : 'Create User'}
164 style={{marginBottom: 0}}
165 hasCloseButton={this.closePanel}
167 <FormSection title="USER INFO">
171 : <Input label="Username" value={state['user-name']} onChange={this.updateInput.bind(null, 'user-name')} />
173 <Input label="Domain" value={state['user-domain']} onChange={this.updateInput.bind(null, 'user-domain')}></Input>
174 <Input label="Disabled" onChange={this.disabledChange} checked={state.disabled} type="checkbox" />
176 <FormSection title="PLATFORM ROLES">
177 <Input label="Super Admin" onChange={this.platformChange.bind(null, 'super_admin')} checked={state.platformRoles.super_admin} type="checkbox" />
178 <Input label="Platform Admin" onChange={this.platformChange.bind(null, 'platform_admin')} checked={state.platformRoles.platform_admin} type="checkbox" />
179 <Input label="Platform Oper" onChange={this.platformChange.bind(null, 'platform_oper')} checked={state.platformRoles.platform_oper} type="checkbox" />
181 <FormSection title="PROJECT ROLES">
185 options={state.projectRolesOptions}
186 collection={state.projectRoles}
187 onChange={this.updateProjectRole}
188 AddItemFn={this.addProjectRole}
189 RemoveItemFn={this.removeProjectRole}
192 { this.state.isEdit ?
194 <FormSection title="PASSWORD CHANGE">
195 <Input label="OLD PASSWORD" type="password" value={state['old-password']} onChange={this.updateInput.bind(null, 'old-password')} />
196 <Input label="NEW PASSWORD" type="password" value={state['new-password']} onChange={this.updateInput.bind(null, 'new-password')}/>
197 <Input label="REPEAT NEW PASSWORD" type="password" value={state['confirm-password']} onChange={this.updateInput.bind(null, 'confirm-password')}/>
201 <FormSection title="CREATE PASSWORD">
202 <Input label="CREATE PASSWORD" type="password" value={state.newPassword} onChange={this.updateInput.bind(null, 'new-password')}/>
203 <Input label="REPEAT PASSWORD" type="password" value={state.repeatNewPassword} onChange={this.updateInput.bind(null, 'confirm-password')}/>
213 <ButtonGroup className="buttonGroup">
214 <Button label="Update" type="submit" onClick={this.updateUser} />
215 <Button label="Delete" onClick={this.deleteUser} />
219 <ButtonGroup className="buttonGroup">
220 <Button label="Create" type="submit" onClick={this.createUser} />
231 // onClick={this.Store.update.bind(null, Account)}
232 UserManagementDashboard.contextTypes = {
233 router: React.PropTypes.object
236 UserManagementDashboard.defaultProps = {
241 export default SkyquakeComponent(UserManagementDashboard);
249 class InputCollection extends React.Component {
252 this.collection = props.collection;
254 buildTextInput(onChange, v, i) {
257 style={{flex: '1 1'}}
260 onChange= {onChange.bind(null, i)}
264 buildSelectOption(initial, options, onChange, v, i) {
267 key={`${i}-${v.replace(' ', '_')}`}
271 onChange={onChange.bind(null, i)}
279 const props = this.props;
281 let className = "InputCollection";
282 if (props.className) {
283 className = `${className} ${props.className}`;
285 if (props.type == 'select') {
286 inputType = this.buildSelectOption.bind(this, props.initial, props.options, props.onChange);
288 inputType = this.buildTextInput.bind(this, props.onChange)
291 <div className="InputCollection-wrapper">
292 {props.collection.map((v,i) => {
294 <div key={i} className={className} >
296 <span onClick={props.RemoveItemFn.bind(null, i)} className="removeInput"><img src={imgRemove} />Remove</span>
300 <span onClick={props.AddItemFn} className="addInput"><img src={imgAdd} />Add</span>
307 InputCollection.defaultProps = {
310 onChange: function(i, e) {
312 Updating with: ${e.target.value}
316 AddItemFn: function(e) {
317 console.log(`Adding a new item to collection`)
319 RemoveItemFn: function(i, e) {
320 console.log(`Removing item from collection at index of: ${i}`)
324 class FormSection extends React.Component {
326 let className = 'FormSection ' + this.props.className;
329 style={this.props.style}
330 className={className}
332 <div className="FormSection-title">
335 <div className="FormSection-body">
336 {this.props.children}
344 FormSection.defaultProps = {