Skip to content

Commit

Permalink
Loading current assignment shows JSON error currently but ground work…
Browse files Browse the repository at this point in the history
… is there
  • Loading branch information
kvanland committed Oct 14, 2018
1 parent b83aa95 commit a573dc0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
19 changes: 17 additions & 2 deletions client/src/scenes/admin/ProjectMatching/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { InputGroup, Button, Intent, NonIdealState, Tabs } from '@blueprintjs/co
import { Loading } from '../../../components/Loading';
import autobind from 'autobind-decorator';
import { IProject } from 'common/interfaces';
import { MdLaunch } from 'react-icons/md';

interface IProjectMatchingProps {
}
Expand All @@ -30,8 +31,22 @@ class ProjectMatching extends React.Component<IProjectMatchingProps, IProjectMat
this.assignProjects = this.assignProjects.bind(this);
}

componentDidMount() {
async componentDidMount() {
this.setState({ isLoading: false });

try {
const response = await fetch(getApiURI('/projects/getassignment'));
const data = await response.json();

this.setState({
projects: data
});

console.log(data);
} catch (e) {
console.error(e);
}

}

async launch() {
Expand Down Expand Up @@ -59,7 +74,7 @@ class ProjectMatching extends React.Component<IProjectMatchingProps, IProjectMat
assignProjects() {
var request = new XMLHttpRequest();
request.withCredentials = true;
request.open('POST', 'http://localhost:8080/projects/assign-to-students');
request.open('POST', 'http://localhost:8080/projects/save-assignments');
var data = JSON.stringify(
this.state.projects
);
Expand Down
23 changes: 13 additions & 10 deletions server/src/main/java/capstone/controller/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,19 @@ public Project getProjectByEmailAndId(@PathVariable("email") String email,
@GetMapping("/assignment")
public List<Project> projectAssignment()
{
System.out.println("running assignment");
// 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();
}

@GetMapping("/getassignment")
public List<Project> getProjectAssignment() {
List<Project> projects = new ArrayList<Project>();
if(projectService.assignmentExistance()) {
projects = projectService.getExistingAssignments();
}
return projects;
}


@GetMapping("/assignment/exists")
public String assignmentExists() {
List<Project> existing = projectService.getExistingAssignments();
Expand All @@ -148,11 +151,11 @@ public String assignmentExists() {
if (proj.getProjectId() > 0) {
Project project = projectService.findByProjectId(proj.getProjectId());

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

// Determine stakeholder for project
Expand Down
26 changes: 25 additions & 1 deletion server/src/main/java/capstone/service/ProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,30 @@ public List<Project> getExistingAssignments() {
}
System.out.println(ac.getAssignment());
return ac.getAssignment();*/
return savedProjects;

List<Project> existingProjects = repository.findAll();
List<Student> students = (List<Student>) userService.getStudents();
for(Student s : students) {
int assignedIndex = existingProjects.indexOf(s.getProject());
if(assignedIndex > -1) {
existingProjects.get(assignedIndex).members.add(s);
}

}
return existingProjects;
}

public boolean assignmentExistance() {
boolean exists = false;
List<Project> existingProjects = repository.findAll();
List<Student> students = (List<Student>) userService.getStudents();
for(Student s : students) {
int assignedIndex = existingProjects.indexOf(s.getProject());
if(assignedIndex > -1) {
exists = true;
}

}
return exists;
}
}

0 comments on commit a573dc0

Please sign in to comment.