Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Us2 admin projects #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/src/Components/Admin.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@
width: 190px;
height: 190px;
margin-left: 50px;
margin-bottom: 30px;
border: hidden;
}
.toprojectorgroupbtntext{
margin-top: 50px;
font-size: 30px;
font-size: 25px;
font-family: Arial, Helvetica, sans-serif;
}
14 changes: 5 additions & 9 deletions client/src/Components/AdminCreateProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AdminCreateProject extends Component {
}

setMaxGroupSize(e) {
if(e.target.value>=0)
this.setState({ max_group_size: e.target.value });
}

Expand All @@ -59,10 +60,10 @@ class AdminCreateProject extends Component {
</div>
<div className={css.projectrightcontent}>
<button className={css.createprojectfirstbtn} onClick={()=>this.handleSubmit()}>
Create
</button>
<button className={css.createprojectsecondbtn} onClick={()=>window.location.href="/admin/home"}>
Create
<button className={css.createprojectsecondbtn} onClick={()=>window.location.href="/admin/home"}>
Cancel
</button>
</button>
</div>
<div>
Expand All @@ -77,32 +78,27 @@ class AdminCreateProject extends Component {
value={ this.state.project_name }
></input>
</p>
<br/><br/>
<p className={css.subtitle}>
Max Group Size:
<input
type='number'
className={css.createprojectinput}
style={{marginLeft: '80.5px'}}
style={{marginLeft: '16px'}}
onChange={ this.setMaxGroupSize.bind(this) }
value={ this.state.max_group_size }
></input>
</p>
<br/><br/>
<p className={css.subtitle}>
Interest:
<input className={css.createprojectinput} style={{marginLeft: '131px'}}></input>
</p>
<br/><br/>
<p className={css.subtitle}>
Skills:
<input className={css.createprojectinput} style={{marginLeft: '160px'}}></input>
</p>
<br/><br/>
<p className={css.subtitle}>
Description:
</p>
<br/><br/>
<textarea className={css.createprojectdescriptioninput}></textarea>
</div>
</>
Expand Down
79 changes: 67 additions & 12 deletions client/src/Components/AdminEditProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,64 @@ import { signout } from './AuthenticationHelper'

class AdminCreateProject extends Component{

handleCancelButton(){
state={
project_name:'',
project_max_size:'',
}

componentDidMount(){
fetch('http://localhost:6060/api/admin/projects', {
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
})
.then(response => response.json())
.then(j => {
for(var i=0; i<j.length;i++)
{
if(j[i].id==this.props.match.params.project_id)
{
console.log(this.props.match.params.project_id);
this.setState({
project_name:j[i].name,
project_max_size:j[i].max_group_size,
});
}
}

})
}


setMaxGroupSize(e) {
if(e.target.value>=0)
this.setState({ project_max_size: e.target.value });
}

HandleCencelBtn()
{
this.props.history.goBack();
}

//NEED TO FIX
HandleEditBtn()
{
const jsonString = JSON.stringify({ name: this.state.project_name, max_group_size: this.state.max_group_size });
fetch('http://localhost:6060/api/admin/projects/' + this.props.match.params.project_id, {
method:'PUT',
credentials: 'include',
headers: { 'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Origin': "*",
'Access-Control-Allow-Methods': "PUT"},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This backend route does not exist, you currently cannot update a project via the front end

body: jsonString
})
.then(response => response.json())
.then(j => {
console.log(j)
this.props.history.goBack()
return j;
})
}

render() {
return(
Expand All @@ -27,39 +82,39 @@ class AdminCreateProject extends Component{
</nav>
</div>
<div className={css.projectrightcontent}>
<button className={css.createprojectfirstbtn}>
<button className={css.createprojectfirstbtn} onClick={()=>this.HandleEditBtn()}>
Edit
<br/>
<button className={css.createprojectsecondbtn} onClick={()=>this.handleCancelButton()}>Cancel</button>
<button className={css.createprojectsecondbtn} onClick={()=>this.HandleCencelBtn()}>Cancel</button>
</button>
</div>
<div>
<h1 className={css.title}>Edit Project {this.props.match.params.id}</h1>
<h1 className={css.title}>Edit Project {this.props.match.params.project_id}</h1>
<br/>
<p className={css.subtitle}>
Project Name:
<input className={css.createprojectinput} style={{marginLeft: '50px'}}></input>
<input className={css.createprojectinput} style={{marginLeft: '50px'}} defaultValue={this.state.project_name}></input>
</p>
<br/><br/>
<p className={css.subtitle}>
Group Size:
<input className={css.createprojectinput} style={{marginLeft: '80.5px'}}></input>
Max Group Size:
<input className={css.createprojectinput}
style={{marginLeft: '16px'}}
type='number'
value={this.state.project_max_size}
onChange={ this.setMaxGroupSize.bind(this) }
></input>
</p>
<br/><br/>
<p className={css.subtitle}>
Interest:
<input className={css.createprojectinput} style={{marginLeft: '131px'}}></input>
</p>
<br/><br/>
<p className={css.subtitle}>
Skills:
<input className={css.createprojectinput} style={{marginLeft: '160px'}}></input>
</p>
<br/><br/>
<p className={css.subtitle}>
Description:
</p>
<br/><br/>
<textarea className={css.createprojectdescriptioninput}></textarea>

</div>
Expand Down
4 changes: 2 additions & 2 deletions client/src/Components/AdminMainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AdminMainMenu extends Component{
</nav>
</div>
<div className={css.projectrightcontent}>
<button className={css.createprojectbtn} onClick={()=>{window.location.href="/admin/projects/new"}}>Create Project</button>
<button className={css.createprojectbtn} onClick={()=>{window.location.href="/admin/projects/create/new"}}>Create Project</button>
</div>
<div>
<h1 className={css.title}>
Expand All @@ -82,7 +82,7 @@ class AdminMainMenu extends Component{
className={css.toprojectorgroupbtn}
style={{backgroundColor: this.state.selectedcolor}}
>
<p className={css.toprojectorgroupbtnp} key={project.id}>
<p className={css.toprojectorgroupbtntext} key={project.id}>
{project.name}
</p>
</button>
Expand Down
57 changes: 45 additions & 12 deletions client/src/Components/AdminProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,48 @@ class AdminProject extends Component{
constructor(props){
super(props)
this.state = {
name: 'Project',
max_group_size: '',
project_name:'',
project_id:'',
project_group_size:'',
project_groups:[],
students_in_projects:[]

}
}

componentDidMount(){
fetch('http://localhost:6060/api/admin/projects/' + this.props.match.params.project_id, {
fetch('http://localhost:6060/api/admin/projects/', {
credentials: 'include',
headers: { 'Content-Type': 'application/json' }
})
.then(response => response.json())
.then(j => {
this.setState({ name: j.name, max_group_size: j.max_group_size });
for(var i=0; i<j.length;i++)
{
if(j[i].id==this.props.match.params.project_id)
{
console.log(this.props.match.params.project_id);
this.setState({
project_name:j[i].name,
project_group_size:j[i].max_group_size,
});
}
}

})


fetch('http://localhost:6060/api/admin/projects/'+ this.props.match.params.project_id +'/groups', {
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
})
.then(response => response.json())
.then(j => {

this.setState({ project_groups:j })
//console.log(this.state.project_groups)
})

}


Expand All @@ -47,6 +74,7 @@ class AdminProject extends Component{
this.props.history.push('/admin/projects/'+ project_id +'/edit')
}


render() {
return(
<>
Expand All @@ -69,7 +97,7 @@ class AdminProject extends Component{
<div className={css.projectrightcontent}>
<p className={css.subtitle}>
<br/>
Student List:

<button className={css.addstudentbtn} onClick={()=>this.goToAddStudentPage()}>Add Student</button>
<button className={css.projecttwobutton} onClick={()=>this.goToCreateGroupPage()}>Create Groups</button>
<button className={css.projecttwobutton} onClick={()=>this.goToEditGroupPage()}>Edit Groups</button>
Expand All @@ -78,15 +106,20 @@ class AdminProject extends Component{

<div >
<h1 className={css.title}>
{ this.state.name }
<button className={css.projectgraybutton} onClick={()=>this.goToSettingsPage()}>Edit Setting</button>
<button className={css.projectgraybutton}>Delete</button>
Project {this.props.match.params.project_id}
</h1>
<p className={css.textcontent}><br/><br/>Max Group Size: {this.state.max_group_size}</p>
<p className={css.textcontent}><br/><br/>Interests:</p>
<p className={css.textcontent}><br/><br/>Skills:</p>
<br/><br/><br/>
<p className={css.textcontent}><br/>&nbsp;&nbsp;&nbsp;Description: {this.state.project_name}</p>
<p className={css.textcontent}><br/>&nbsp;&nbsp;&nbsp;Max Group Size: {this.state.project_group_size}</p>
<br/>
<p className={css.textcontent} style={{fontSize: "35px"}}>&nbsp;&nbsp;Groups:</p>
{this.state.project_groups.map(project_group =>(
<li className={css.textcontent} key={project_group.id}>
Id: {project_group.id}&nbsp;
Group Number: {project_group.group_number}
<br/><br/>
</li>
))}

</div>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion client/src/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UrlSet extends Component{
<Route path="/student/projects/:project_id/groups/:group_id" exact strict component={StudentGroup}/>
<Route path="/admin/home" exact strict component={AdminMainMenu}/>
<Route path="/admin/notifications" exact strict component={AdminNotification}/>
<Route path="/admin/projects/new" exact strict component={AdminCreateProject}/>
<Route path="/admin/projects/create/new" exact strict component={AdminCreateProject}/>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a restful route https://restfulapi.net/resource-naming/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but the question is that since we set the project route : /admin/projects/:project_id
the previous route: /admin/projects/new many make project_id = new, which may cause problems.
So how to fix it?

<Route path="/admin/projects/:project_id" exact strict component={AdminProject}/>
<Route path="/admin/projects/:project_id/groups/create" exact strict component={AdminCreateGroup}/>
<Route path="/admin/projects/:project_id/add_student" exact strict component={AdminProjectAddStudents}/>
Expand Down