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

added edit project api and front end form modal #5

Merged
merged 1 commit into from
Oct 2, 2018
Merged
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';

import { getApiURI } from '../../../common/server';
import { HTMLTable, Button, Intent, Card } from '@blueprintjs/core';
import { InputGroup, FormGroup, HTMLTable, Button, Intent, Card, Dialog, TextArea } from '@blueprintjs/core';
import { Loading } from 'components/Loading';
import autobind from 'autobind-decorator';

interface IProjectListProps {
}
Expand All @@ -11,6 +12,8 @@ interface IProjectListState {
projects: Array<{}>;
isLoading: boolean;
selected: boolean;
isOpen: boolean;
selectedProject: IProject;
// <Button onClick={this.toggleCheckboxes}>Select All</Button>
}

Expand All @@ -24,16 +27,32 @@ interface IProject {
technologies: string;
background: string;
description: string;
projectSemester: string;
}

class ProjectProposalApprovalForm extends React.Component<IProjectListProps, IProjectListState> {
constructor(props: IProjectListProps) {
super(props);

var emptyProject: IProject;
emptyProject = ({
projectId: 0,
projectName: '',
semester: '',
statusId: 0,
minSize: '',
maxSize: '',
technologies: '',
background: '',
description: '',
projectSemester: '',
});
this.state = {
projects: [],
isLoading: false,
selected: false,
isOpen: false,
selectedProject: emptyProject,
};
this.submitClicked = this.submitClicked.bind(this);
this.handleChange = this.handleChange.bind(this);
Expand Down Expand Up @@ -68,6 +87,19 @@ class ProjectProposalApprovalForm extends React.Component<IProjectListProps, IPr
request.setRequestHeader('Cache-Control', 'no-cache');
request.send();
}
submitProjectEdit() {

var request = new XMLHttpRequest();
request.withCredentials = true;

console.log(this.state.selectedProject);

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

request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
request.setRequestHeader('Cache-Control', 'no-cache');
request.send(JSON.stringify(this.state.selectedProject));
}

handleChange(e: any) {
let projects = this.state.projects;
Expand All @@ -86,6 +118,33 @@ class ProjectProposalApprovalForm extends React.Component<IProjectListProps, IPr
projects: projects
});
}

handleOpenEditModal = (project) => this.setState({ isOpen: true, selectedProject: project });
handleCloseEditModal = () => this.setState({ isOpen: false });

@autobind
renderFormGroup(id: keyof IProject, type: string, label: string, placeholder: string) {
return (
<FormGroup label={label} labelFor={id}>
<InputGroup
type={type}
placeholder={placeholder}
id={id}
// value={(typeof this.state.selectedProject[id] == 'number') ? this.state.selectedProject[id].toString() : this.state.selectedProject[id]}
value={(this.state.selectedProject[id] == null) ? '' : this.state.selectedProject[id].toString()}
onChange={this.handleProjectEdit(id)}
/>
</FormGroup>
);
}

handleProjectEdit = (id: keyof IProject) => (e: React.ChangeEvent<any>) => {
let proj: IProject;
proj = Object.assign({}, this.state.selectedProject);
proj[id] = e.currentTarget.value;
this.setState({ selectedProject: proj } as any);
}

toggleCheckboxes() {
if (this.state.selected === false) {
this.setState({
Expand Down Expand Up @@ -160,10 +219,50 @@ class ProjectProposalApprovalForm extends React.Component<IProjectListProps, IPr
<Button intent={Intent.SUCCESS} onClick={() => this.submitClicked(project.projectId, 2)}>Approve</Button>
<Button intent={Intent.DANGER} onClick={() => this.submitClicked(project.projectId, 3)}>Reject</Button>
<Button intent={Intent.WARNING} onClick={() => this.submitClicked(project.projectId, 4)}>Change</Button>
<Button onClick={() => this.handleOpenEditModal(project)}>Make Edit</Button>
</td>
</tr>
)}
</tbody>
<Dialog
icon="info-sign"
onClose={this.handleCloseEditModal}
title="Edit Project Proposal"
{...this.state}
>

<div className={'project-edit-modal-body'}>
<p>
<strong>
Make edit to project proposal here.
</strong>
</p>

<div>
{this.renderFormGroup('projectName', 'text', 'Project Name', 'Project Name')}
{this.renderFormGroup('projectSemester', 'text', 'Project Semester', 'Project Semester')}
{this.renderFormGroup('minSize', 'text', 'Number of Students', 'Number of Students')}
{this.renderFormGroup('maxSize', 'text', 'Number of Students', 'Number of Students')}
{this.renderFormGroup('technologies', 'text', 'Technologies Expected', 'Technologies Expected')}
{this.renderFormGroup('background', 'text', 'Background Requested', 'Background Requested')}
{this.renderFormGroup('description', 'text', 'Project Description', 'Project Description')}

<Button intent={Intent.WARNING} onClick={() => this.submitProjectEdit()}>Submit Changes</Button>
{/* <FormGroup label="Description" labelFor="description">
<TextArea
placeholder="Description"
id="description"
value={this.state.description}
onChange={this.handleChange('description')}
/>
</FormGroup> */}

{/* <FormGroup>
<Button intent={Intent.PRIMARY} text="Submit Proposal" onClick={this.submitClicked} />
</FormGroup> */}
</div>
</div>
</Dialog>
</HTMLTable>
</Card>
</div>
Expand Down
20 changes: 20 additions & 0 deletions server/src/main/java/capstone/controller/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ public String assignmentExists() {
return Constants.SUCCESS;
}

@PostMapping("/edit/{projectId}")
public @ResponseBody String editProject(@PathVariable("projectId") int projectId,
@RequestBody Project updated_project) {
System.out.println("Updating Project");
Project project = projectService.findByProjectId(projectId);
project.setStatusId(4);

project.setSemester(updated_project.getSemester());
project.setTechnologies(updated_project.getTechnologies());
project.setProjectName(updated_project.getProjectName());
project.setDescription(updated_project.getDescription());
project.setBackground(updated_project.getBackground());
project.setMinSize(updated_project.getMinSize());
project.setMaxSize(updated_project.getMaxSize());

System.out.println(project);
System.out.println(project.getProjectName());
projectService.save(project);
return Constants.SUCCESS;
}

}

Expand Down