Skip to content

Commit

Permalink
Backend for editing projects is there possibly not working as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
kvanland committed Oct 11, 2018
1 parent 90a0135 commit 9194146
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 10 deletions.
34 changes: 30 additions & 4 deletions client/src/scenes/stakeholder/ProjectPage/ProjectInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Card,
HTMLTable
} from '@blueprintjs/core';

import autobind from 'autobind-decorator';
import { getApiURI } from '../../../common/server';
import CardHeader from 'reactstrap/lib/CardHeader';
import CardBody from 'reactstrap/lib/CardBody';
Expand Down Expand Up @@ -42,6 +42,7 @@ class ProjectInformation extends React.Component<IProjectProps, IProjectState> {
description: '',
isLoading: true
};

this.handleChange = this.handleChange.bind(this);
}

Expand Down Expand Up @@ -72,11 +73,32 @@ class ProjectInformation extends React.Component<IProjectProps, IProjectState> {
this.setState({ [id]: e.currentTarget.value } as any);
}

@autobind
async submitProjectEdit() {
var request = new XMLHttpRequest();
request.withCredentials = true;

request.open('POST', 'http://localhost:8080/projects/editMinor/' + this.state.projectId);

request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
request.setRequestHeader('Cache-Control', 'no-cache');
request.send(JSON.stringify(this.state));
request.onreadystatechange = function () {
if (this.readyState === this.DONE) {
if (request.status === 200) {
alert('Change made successfully');
} else {
alert('Change could not be made at this time');
}
}
};
}

render() {
return (
<div className="csci-form-container">
<div className="csci-main">
<h1 style={{ margin: 0, textAlign: 'center' }}>Project Information</h1>
<h1 style={{ margin: 0, textAlign: 'center' }}>Project Information</h1>
<Card>
<CardBody>
<FormGroup label="Project Name">
Expand Down Expand Up @@ -135,7 +157,11 @@ class ProjectInformation extends React.Component<IProjectProps, IProjectState> {
</FormGroup>

<FormGroup>
<Button type="submit">Edit/Save</Button>
<Button
type="submit"
onClick={this.submitProjectEdit}
text="Edit/Save"
/>
</FormGroup>
</CardBody>
<Card>
Expand Down Expand Up @@ -168,7 +194,7 @@ class ProjectInformation extends React.Component<IProjectProps, IProjectState> {
</Card>
</Card>
</div>
</div>
</div >
);

}
Expand Down
53 changes: 47 additions & 6 deletions server/src/main/java/capstone/controller/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public Project getProjectByEmailAndId(@PathVariable("email") String email,
@GetMapping("/student/{email:.+}")
public @ResponseBody Project getUserProject(@PathVariable("email") String email) {
Student user = (Student) userService.findUserByEmail(email);
System.out.println(user.getProject().getProjectName());
return user.getProject();
}

Expand Down Expand Up @@ -122,11 +121,12 @@ public Project getProjectByEmailAndId(@PathVariable("email") String email,
public List<Project> projectAssignment()
{
System.out.println("running assignment");
/*// WIP: Return an existing matching if students have already been assigned to projects
* List<Project> existing = projectService.getExistingAssignments();
// Return an existing matching if students have already been assigned to projects
List<Project> existing = projectService.getExistingAssignments();
if (existing != null && existing.size() > 0) {
System.out.println("Returning existing assignment");
return existing;
}*/
}
return projectService.runAlgorithm();
}

Expand All @@ -147,6 +147,12 @@ public String assignmentExists() {
for (Project proj : projectMatches) {
if (proj.getProjectId() > 0) {
Project project = projectService.findByProjectId(proj.getProjectId());

// List<Long> projectMembers = new ArrayList<Long>();
// for(Student s : proj.getMembers()) {
// projectMembers.add(s.getUserId());
// }
// project.setMemberIDs(projectMembers);
updatedProjects.add(project);

// Determine stakeholder for project
Expand All @@ -161,14 +167,37 @@ public String assignmentExists() {
// Construct email body
String messageBody = project.getProjectName() + "\n\nProject Background: " + project.getBackground() + "\n\nProject Description: " + project.getDescription()
+ "\n\nStakeholder Email: " + stakeholderEmail + "\n\nTo find out who is on your team please login to the class website.";

// Email each student in the group the information
for (Student student : proj.getMembers()) {
// Set the given project for each student
Student saveStudent = userService.findByUserId(student.getUserId());
saveStudent.setProject(project);

emailService.sendEmail("CSCI 401 Project Assignment", messageBody, saveStudent.getEmail());
String email = saveStudent.getEmail();
emailService.sendEmail("CSCI 401 Project Assignment", messageBody, email);
userService.saveUser(saveStudent);
}
}
}
projectService.saveAssignment(updatedProjects);
return Constants.SUCCESS;
}

// Save projects when altered
@PostMapping("/save-assignments")
public @ResponseBody String saveProjectsToStudents(@RequestBody List<Project> projectMatches) {
List<Project> updatedProjects = new ArrayList<Project>();

for (Project proj : projectMatches) {
if (proj.getProjectId() > 0) {
Project project = projectService.findByProjectId(proj.getProjectId());
updatedProjects.add(project);

for (Student student : proj.getMembers()) {
// Set the given project for each student
Student saveStudent = userService.findByUserId(student.getUserId());
saveStudent.setProject(project);

userService.saveUser(saveStudent);
}
}
Expand Down Expand Up @@ -260,6 +289,18 @@ public String assignmentExists() {
return Constants.SUCCESS;
}

@PostMapping("/editMinor/{projectid}")
public @ResponseBody String editProjectMinor(@PathVariable("projectId") int projectId,
@RequestBody Project updated_project) {
Project project = projectService.findByProjectId(projectId);
project.setProjectName(updated_project.getProjectName());
project.setTechnologies(updated_project.getTechnologies());
project.setBackground(updated_project.getBackground());
project.setDescription(updated_project.getDescription());

projectService.save(project);
return Constants.SUCCESS;
}
}


Expand Down

0 comments on commit 9194146

Please sign in to comment.