Project Management styling and usermanagement workflow to table
authorLaurence Maultsby <laurence.maultsby@riftio.com>
Thu, 16 Mar 2017 19:40:03 +0000 (15:40 -0400)
committerkashalkar <kiran.kashalkar@riftio.com>
Thu, 16 Mar 2017 19:50:27 +0000 (20:50 +0100)
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
skyquake/plugins/project_management/src/dashboard/dashboard.jsx
skyquake/plugins/project_management/src/dashboard/projectMgmt.scss
skyquake/plugins/project_management/src/dashboard/projectMgmtActions.js
skyquake/plugins/project_management/src/dashboard/projectMgmtStore.js

index 2b25227..60e06df 100644 (file)
@@ -172,6 +172,13 @@ class ProjectManagementDashboard extends React.Component {
             value: JSON.parse(e.target.value)
         })
     }
+    toggleUserRoleInProject = (userIndex, roleIndex, e) => {
+        this.actions.handleToggleUserRoleInProject({
+            userIndex,
+            roleIndex,
+            checked: JSON.parse(e.currentTarget.checked)
+        })
+    }
     removeRoleFromUserInProject = (userIndex, roleIndex, e) => {
         this.actions.handleRemoveRoleFromUserInProject({
             userIndex,
@@ -206,6 +213,11 @@ class ProjectManagementDashboard extends React.Component {
                 <Button label="EDIT" type="submit" onClick={this.editProject} />
             </ButtonGroup>
         );
+        let projectUsers = [];
+        self.state.projectUsers.map((u) => {
+            projectUsers.push(u['user-name']);
+        });
+
         if(!this.state.isReadOnly) {
             formButtonsHTML = (
                                 state.isEdit ?
@@ -277,70 +289,119 @@ class ProjectManagementDashboard extends React.Component {
                             <Input readonly={state.isReadOnly} type="textarea" label="Description" value={state['description']}  onChange={this.updateInput.bind(null, 'description')}></Input>
                         </FormSection>
                         <FormSection title="USER ROLES">
-                        <div className="tableRow tableRow--header">
-                            <div className="projectName">
-                                User Name
-                            </div>
-                            <div>
-                                Role
-                            </div>
-                        </div>
-                            {
-                                state.projectUsers && state.projectUsers.map((u, k) => {
-                                    return (
-                                        <div ref={(el) => this[`project-ref-${k}`] = el} className={`tableRow tableRow--data projectUsers`} key={k}>
-                                            <div className="userName" style={state.isReadOnly ? {paddingTop: '0.25rem'} : {} }>{u['user-name']}</div>
-                                            <div>
-                                                {
-                                                    u.role && u.role.map((r, l) => {
-                                                        return (
-                                                            <div key={l}>
-                                                                <div style={{display: 'flex'}} className="selectRole">
-                                                                    <SelectOption
-                                                                        readonly={state.isReadOnly}
-                                                                        defaultValue={r.role}
-                                                                        options={state.roles}
-                                                                        onChange={self.updateUserRoleInProject.bind(self, k, l)}
-                                                                    />
-                                                                    {!state.isReadOnly ?
-                                                                        <span
-                                                                        className="removeInput"
-                                                                        onClick={self.removeRoleFromUserInProject.bind(self, k, l)}
-                                                                        >
-                                                                            <img src={imgRemove} />
-                                                                            Remove Role
-                                                                        </span>
-                                                                        : null
-                                                                    }
 
-                                                                </div>
-                                                            </div>
-                                                        )
-                                                    })
-                                                }
-                                                {!state.isReadOnly ?
-                                                    <div className="buttonGroup">
-                                                        <span className="addInput addRole" onClick={self.addRoleToUserInProject.bind(self, k)}><img src={imgAdd} />
-                                                            Add Role
-                                                        </span>
-                                                        {
-                                                            (!(u.role && u.role.length)) ?
-                                                                <span
+                        <table>
+                            <thead>
+                                <tr>
+                                    {!state.isReadOnly ? <td></td> : null}
+                                    <td>User Name</td>
+                                    {
+                                        state.roles.map((r,i) => {
+                                            return <td key={i}>{r}</td>
+                                        })
+                                    }
+                                </tr>
+                            </thead>
+                            <tbody>
+                                {
+                            state.projectUsers.map((u,i)=> {
+                                let userRoles = u.role.map((r) => {
+                                    return r.role;
+                                })
+                                return (
+                                    <tr key={i}>
+                                        {!state.isReadOnly ? <td><span
                                                                     className="removeInput"
-                                                                    onClick={self.removeUserFromProject.bind(self, k)}
+                                                                    onClick={self.removeUserFromProject.bind(self, u)}
                                                                 >
                                                                     <img src={imgRemove} />
-                                                                    Remove User
-                                                                </span> : null
-                                                        }
-                                                    </div>
-                                                    : null
-                                                }
+
+                                                                </span></td> : null}
+                                        <td>
+                                            {u['user-name']}
+                                        </td>
+                                        {
+                                            state.roles.map((r,j) => {
+                                                return <td key={j}><Input type="checkbox" onChange={self.toggleUserRoleInProject.bind(self, i, j)} checked={(userRoles.indexOf(r) > -1)} /></td>
+                                            })
+                                        }
+                                    </tr>
+                                )
+                            })
+                        }
+                            </tbody>
+                        </table>
+
+
+                        { false ?
+                            <div>
+                                <div className="tableRow tableRow--header">
+                                    <div className="projectName">
+                                        User Name
+                                    </div>
+                                    <div>
+                                        Role
+                                    </div>
+                                </div>
+                                {
+                                    state.projectUsers && state.projectUsers.map((u, k) => {
+                                        return (
+                                            <div ref={(el) => this[`project-ref-${k}`] = el} className={`tableRow tableRow--data projectUsers`} key={k}>
+                                                <div className="userName" style={state.isReadOnly ? {paddingTop: '0.25rem'} : {} }>{u['user-name']}</div>
+                                                <div>
+                                                    {
+                                                        u.role && u.role.map((r, l) => {
+                                                            return (
+                                                                <div key={l}>
+                                                                    <div style={{display: 'flex'}} className="selectRole">
+                                                                        <SelectOption
+                                                                            readonly={state.isReadOnly}
+                                                                            defaultValue={r.role}
+                                                                            options={state.roles}
+                                                                            onChange={self.updateUserRoleInProject.bind(self, k, l)}
+                                                                        />
+                                                                        {!state.isReadOnly ?
+                                                                            <span
+                                                                            className="removeInput"
+                                                                            onClick={self.removeRoleFromUserInProject.bind(self, k, l)}
+                                                                            >
+                                                                                <img src={imgRemove} />
+                                                                                Remove Role
+                                                                            </span>
+                                                                            : null
+                                                                        }
+
+                                                                    </div>
+                                                                </div>
+                                                            )
+                                                        })
+                                                    }
+                                                    {!state.isReadOnly ?
+                                                        <div className="buttonGroup">
+                                                            <span className="addInput addRole" onClick={self.addRoleToUserInProject.bind(self, k)}><img src={imgAdd} />
+                                                                Add Role
+                                                            </span>
+                                                            {
+                                                                (!(u.role && u.role.length)) ?
+                                                                    <span
+                                                                        className="removeInput"
+                                                                        onClick={self.removeUserFromProject.bind(self, k)}
+                                                                    >
+                                                                        <img src={imgRemove} />
+                                                                        Remove User
+                                                                    </span> : null
+                                                            }
+                                                        </div>
+                                                        : null
+                                                    }
+                                                </div>
                                             </div>
-                                        </div>
-                                    )
-                                })
-                            }
+                                        )
+                                    })
+                                }
+                                </div>
+                                 : null
+                             }
                             {
                                 !state.isReadOnly ?
                                     <div className="tableRow tableRow--header">
@@ -350,7 +411,9 @@ class ProjectManagementDashboard extends React.Component {
                                                     onChange={this.actions.handleSelectedUser}
                                                     defaultValue={state.selectedUser}
                                                     initial={true}
-                                                    options={state.users && state.users.map((u) => {
+                                                    options={state.users && state.users.filter((u) => {
+                                                        return projectUsers.indexOf(u['user-name']) == -1
+                                                    }).map((u) => {
                                                         return {
                                                             label: u['user-name'],
                                                             value: u
index 3c2b58e..dc8fcce 100644 (file)
             background:none;
             color: black;
         }
+
+    table {
+        thead {
+            border-bottom:1px solid #d3d3d3;
+            td{
+                font-weight:bold;
+            }
+        }
+        td{
+            padding:0.25rem 0.5rem;
+            vertical-align: middle;
+            .checkbox {
+                -ms-flex-pack:center;
+                    justify-content:center;
+            }
+        }
+    }
 }
 
 
     padding: 0.25rem;
     margin: .125rem 0;
     >div {
-        padding:0.25rem 1rem 0.25rem 0;
+        padding: 0.25rem;
         -ms-flex: 1 1 33%;
             flex: 1 1 33%;
         display: -ms-flexbox;
index d0baf61..5f2b1ea 100644 (file)
@@ -25,6 +25,7 @@ module.exports = function(Alt) {
                                        'handleUpdateProject',
                                        'handleUpdateSelectedUser',
                                        'handleUpdateUserRoleInProject',
+                                       'handleToggleUserRoleInProject',
                                        'addRoleToUserInProject',
                                        'handleRemoveRoleFromUserInProject',
                                        'updateProjectSuccess',
index 92a4395..6ad46be 100644 (file)
@@ -15,7 +15,9 @@ export default class ProjectManagementStore {
         this.projectUsers = [];
         this.selectedUser = null;
         this.selectedRole = null;
-        this.roles = ['Assign a role', 'super_admin'];
+        this.roles = ['super_admin', 'operator_role'
+        // 'some_other_role', 'yet_another_role', 'operator_role', 'some_other_role', 'yet_another_role'
+        ];
         this.users = [];
         this.activeIndex = null;
         this.isReadOnly = true;
@@ -158,7 +160,25 @@ export default class ProjectManagementStore {
             }
           ]
         })
-        this.setState({projectUsers})
+        this.setState({projectUsers, selectedUser: null})
+    }
+    handleToggleUserRoleInProject(data) {
+        let self = this;
+        let {userIndex, roleIndex, checked} = data;
+        let projectUsers = this.projectUsers;
+        let selectedRole = self.roles[roleIndex];
+        if(checked) {
+            projectUsers[userIndex].role.push({
+                role: self.roles[roleIndex],
+                keys: self.roles[roleIndex]
+            })
+        } else {
+            let role = projectUsers[userIndex].role;
+            let roleIndex = _.findIndex(role, {role:selectedRole, keys: selectedRole})
+            projectUsers[userIndex].role.splice(roleIndex, 1)
+        }
+       self.setState({projectUsers});
+
     }
     handleUpdateUserRoleInProject(data) {
         let {userIndex, roleIndex, value} = data;