Skip to content
Snippets Groups Projects
Commit d911c20f authored by Larbi Gharib's avatar Larbi Gharib
Browse files

Change group blueprint

Change-Id: I6f0e3205f8e040e1c8b81a56659cd6d15199aa61
parent bbe6d232
No related branches found
No related tags found
No related merge requests found
...@@ -119,10 +119,12 @@ export default function TemporaryDrawer(props) { ...@@ -119,10 +119,12 @@ export default function TemporaryDrawer(props) {
const addUserToGroup = (username) => { const addUserToGroup = (username) => {
let url = ''; let url = '';
if(props.selectedBlueprint == ''){ console.log(props.blueprintLabel);
if(props.blueprintLabel == null){
url = api_path_put_update_group+"?groupName="+props.groupName+"&newName="+props.groupName+"&blueprintName=&groupMembers="+username; url = api_path_put_update_group+"?groupName="+props.groupName+"&newName="+props.groupName+"&blueprintName=&groupMembers="+username;
}else{ }else{
url = api_path_put_update_group+"?groupName="+props.groupName+"&newName="+props.groupName+"&blueprintName="+props.blueprintsOptions[props.selectedBlueprint].label+"&groupMembers="+username; url = api_path_put_update_group+"?groupName="+props.groupName+"&newName="+props.groupName+"&blueprintName="+props.blueprintLabel+"&groupMembers="+username;
} }
axios(configApiCall(url, 'PUT', null, null)).then((response) => { axios(configApiCall(url, 'PUT', null, null)).then((response) => {
......
...@@ -32,6 +32,9 @@ import AddCircleOutlineIcon from '@material-ui/icons/AddCircleOutline'; ...@@ -32,6 +32,9 @@ import AddCircleOutlineIcon from '@material-ui/icons/AddCircleOutline';
import EditIcon from '@material-ui/icons/Edit'; import EditIcon from '@material-ui/icons/Edit';
import PeopleOutlineIcon from '@material-ui/icons/PeopleOutline'; import PeopleOutlineIcon from '@material-ui/icons/PeopleOutline';
import IconButton from '@material-ui/core/IconButton';
import SaveIcon from '@material-ui/icons/Save';
import axios from "axios" import axios from "axios"
import configApiCall from "../../api" import configApiCall from "../../api"
import { import {
...@@ -48,7 +51,7 @@ import TemporaryDrawer from "components/Drawer/Drawer" ...@@ -48,7 +51,7 @@ import TemporaryDrawer from "components/Drawer/Drawer"
import * as tool from "../../tools"; import * as tool from "../../tools";
import auth from 'auth.js' import auth from 'auth.js'
const styles = ()=> ( { const useStyles = makeStyles((theme) => ({
...devicesStyle, ...devicesStyle,
...dashboardStyle, ...dashboardStyle,
root: { root: {
...@@ -89,20 +92,15 @@ const styles = ()=> ( { ...@@ -89,20 +92,15 @@ const styles = ()=> ( {
minWidth: '80vh', minWidth: '80vh',
maxWidth: '80vh' maxWidth: '80vh'
} }
}); }));
const useStyles = makeStyles(styles);
export default function EditGroup(props) { export default function EditGroup(props) {
const classes = useStyles(); const classes = useStyles();
const history = useHistory();
const [groupExists, setGroupExists] = React.useState(false)
const [name, setName] = React.useState(props.groupName)
const [blueprint, setBlueprint] = React.useState(null)
const [groupMembers, setGroupMembers] = React.useState([])
const [blueprints, setBlueprints] = React.useState([])
const [name, setName] = React.useState(props.groupName);
const [newName, setNewName] = React.useState(props.groupName);
const [blueprint, setBlueprint] = React.useState(null);
const [groupMembers, setGroupMembers] = React.useState([]);
const [openDrawer, setOpenDrawer] = React.useState(false); const [openDrawer, setOpenDrawer] = React.useState(false);
const getGroup = () => { const getGroup = () => {
...@@ -113,7 +111,8 @@ export default function EditGroup(props) { ...@@ -113,7 +111,8 @@ export default function EditGroup(props) {
if(group.name == props.groupName){ if(group.name == props.groupName){
props.getBlueprintsOptions().forEach((blueprintOption) => { props.getBlueprintsOptions().forEach((blueprintOption) => {
if(blueprintOption.label === group["blueprint"]){ if(blueprintOption.label === group["blueprint"]){
setBlueprint(blueprintOption.value) console.log("Group option value : " + blueprintOption.value);
setBlueprint(blueprintOption.value);
} }
}) })
setGroupMembers(group["groupMembers"]); setGroupMembers(group["groupMembers"]);
...@@ -136,9 +135,24 @@ export default function EditGroup(props) { ...@@ -136,9 +135,24 @@ export default function EditGroup(props) {
}) })
} }
React.useEffect(()=>{ const getGroupsOptions = () => {
getGroup() let blueprintsOptions = []
let index = 0
if(props.blueprints.length === 0)
blueprintsOptions.push({value: index, label: "No blueprint found"})
else {
props.blueprints.map((blueprintElement) => {
blueprintsOptions.push({value: index, label: blueprintElement.name});
index += 1
})
}
return blueprintsOptions
}
const blueprintsOptionsItems = tool.buildSelectMenuItems(getGroupsOptions());
React.useEffect(()=>{
getGroup();
}, []) }, [])
const handleUpdateGroup = (blueprintValue) => { const handleUpdateGroup = (blueprintValue) => {
...@@ -151,30 +165,11 @@ export default function EditGroup(props) { ...@@ -151,30 +165,11 @@ export default function EditGroup(props) {
} }
axios(configApiCall(url, 'PUT', null, null)).then((response) => { axios(configApiCall(url, 'PUT', null, null)).then((response) => {
getGroup() setNewName(name);
getGroup();
}).catch((error) => { }).catch((error) => {
console.log("Error updating group: " + error) console.log("Error updating group: " + error)
}) })
axios(configApiCall(api_path_blueprints+"?name=*", 'GET', null, null)).then((response) => {
console.log(blueprints);
setBlueprints(response.data)
}).catch((error) =>{
console.log(error);
if(error.response.status === 401){
auth.authenticated = false
history.push('/')
}
if(error.response.status === 500){
setBlueprints([])
}
});
}
const handleGroupUpdate = (data) => {
setName(data.name)
setGroupMembers(data.groupMembers)
} }
const removeUserFromGroup = (user) => { const removeUserFromGroup = (user) => {
...@@ -198,26 +193,11 @@ export default function EditGroup(props) { ...@@ -198,26 +193,11 @@ export default function EditGroup(props) {
handleUpdateGroup(blueprintValue) handleUpdateGroup(blueprintValue)
} }
const getGroupsOptions = () => {
let blueprintsOptions = []
let index = 0
if(blueprints.length === 0)
blueprintsOptions.push({value: index, label: "No blueprint found"})
else {
blueprints.map((blueprint) => {
blueprintsOptions.push({value: index, label: blueprint.name});
index += 1
})
}
return blueprintsOptions
}
const blueprintsOptionsItems = tool.buildSelectMenuItems(getGroupsOptions());
const tableCellClasses = classnames(classes.tableCell); const tableCellClasses = classnames(classes.tableCell);
return( return(
<div> <div>
<TemporaryDrawer openDrawer={openDrawer} setOpenDrawer={setOpenDrawer} direction="right" addingToGroup={true} placeholder="Add user ..." groupName={name === ''?props.groupName:name} selectedBlueprint={blueprint} getGroup={getGroup} blueprintsOptions={props.getBlueprintsOptions()}/> <TemporaryDrawer openDrawer={openDrawer} setOpenDrawer={setOpenDrawer} direction="right" addingToGroup={true} placeholder="Add user ..." groupName={name === ''?props.groupName:name} blueprintLabel={ blueprint == null ? null : props.getBlueprintsOptions()[blueprint].label} getGroup={getGroup}/>
<GridContainer> <GridContainer>
<GridItem xs={12} sm={12} md={4}> <GridItem xs={12} sm={12} md={4}>
<Card profile> <Card profile>
...@@ -226,7 +206,7 @@ export default function EditGroup(props) { ...@@ -226,7 +206,7 @@ export default function EditGroup(props) {
<EditIcon /> <EditIcon />
</CardIcon> </CardIcon>
<p className={classes.cardCategory}>Edit group</p> <p className={classes.cardCategory}>Edit group</p>
<h3 className={classes.cardTitle}>{props.groupName}</h3> <h3 className={classes.cardTitle}>{newName}</h3>
</CardHeader> </CardHeader>
<CardBody profile> <CardBody profile>
<div className={classes.root}> <div className={classes.root}>
...@@ -241,12 +221,19 @@ export default function EditGroup(props) { ...@@ -241,12 +221,19 @@ export default function EditGroup(props) {
<PeopleOutlineIcon /> <PeopleOutlineIcon />
</InputAdornment> </InputAdornment>
} }
endAdornment={
<IconButton color="primary" aria-label="upload picture" component="span"
onClick={() => {
handleUpdateGroup(blueprint);
}}
disabled={props.groupNameExits}
>
<SaveIcon />
</IconButton>
}
onChange={e => { onChange={e => {
setName(e.target.value); setName(e.target.value);
props.initCheckGroupNameExists(e.target.value) props.initCheckGroupNameExists(e.target.value)
if(!props.groupNameExits){
handleUpdateGroup(blueprint)
}
}} }}
/> />
</FormControl> </FormControl>
...@@ -260,7 +247,7 @@ export default function EditGroup(props) { ...@@ -260,7 +247,7 @@ export default function EditGroup(props) {
onChange={(e) => handleBlueprintsChange(e.target.value)} onChange={(e) => handleBlueprintsChange(e.target.value)}
variant="outlined" variant="outlined"
children={blueprintsOptionsItems} children={blueprintsOptionsItems}
disabled={blueprints.length === 0} disabled={props.blueprints.length === 0}
/> />
</FormControl> </FormControl>
</Grid> </Grid>
......
...@@ -115,6 +115,22 @@ export default function Groups() { ...@@ -115,6 +115,22 @@ export default function Groups() {
history.push('/admin/groups') history.push('/admin/groups')
} }
const loadBlueprints = () => {
axios(configApiCall(api_path_blueprints+"?name=*", 'GET', null, null)).then((response) => {
setBlueprints(response.data)
setSelectedBlueprint(getBlueprintsOptions()[0])
}).catch((error) =>{
console.log(error);
if(error.response.status === 401){
auth.authenticated = false
history.push('/')
}
if(error.response.status === 500){
setBlueprints([])
}
});
}
useEffect(() => { useEffect(() => {
setLoading(true) setLoading(true)
const timer = setInterval(() => { const timer = setInterval(() => {
...@@ -143,19 +159,7 @@ export default function Groups() { ...@@ -143,19 +159,7 @@ export default function Groups() {
history.push('/') history.push('/')
} }
}); });
axios(configApiCall(api_path_blueprints+"?name=*", 'GET', null, null)).then((response) => { loadBlueprints();
setBlueprints(response.data)
setSelectedBlueprint(getBlueprintsOptions()[0])
}).catch((error) =>{
console.log(error);
if(error.response.status === 401){
auth.authenticated = false
history.push('/')
}
if(error.response.status === 500){
setBlueprints([])
}
});
return () => { return () => {
clearInterval(timer); clearInterval(timer);
}; };
...@@ -241,9 +245,10 @@ export default function Groups() { ...@@ -241,9 +245,10 @@ export default function Groups() {
initCheckGroupNameExists={initCheckGroupNameExists} initCheckGroupNameExists={initCheckGroupNameExists}
groupNameExits={groupNameExits} groupNameExits={groupNameExits}
blueprintsOptionsItems={blueprintsOptionsItems} blueprintsOptionsItems={blueprintsOptionsItems}
selectedBlueprint={selectedBlueprint}
handleBlueprintsChange={handleBlueprintsChange} handleBlueprintsChange={handleBlueprintsChange}
getBlueprintsOptions={getBlueprintsOptions} getBlueprintsOptions={getBlueprintsOptions}
blueprints={blueprints}
disableCreate={disableCreate}
/> />
</div> </div>
) )
...@@ -261,7 +266,7 @@ export default function Groups() { ...@@ -261,7 +266,7 @@ export default function Groups() {
<DialogContentText id="alert-dialog-description"> <DialogContentText id="alert-dialog-description">
<Grid container spacing={2}> <Grid container spacing={2}>
<Grid item xs={12} sm={12} md={12}> <Grid item xs={12} sm={12} md={12}>
<FormControl className={classes.margin} size="medium" error={groupNameExits}> <FormControl className={classes.margin} error={groupNameExits} fullWidth>
<InputLabel htmlFor="groupName">Group name</InputLabel> <InputLabel htmlFor="groupName">Group name</InputLabel>
<Input <Input
id="groupName" id="groupName"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment