Skip to content

Commit

Permalink
Merge pull request #18 from AMOSTeam1/alla-changes
Browse files Browse the repository at this point in the history
Alla's changes
  • Loading branch information
HarishVijayamohan authored May 9, 2018
2 parents 2139590 + 527f702 commit 96eb223
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 69 deletions.
4 changes: 2 additions & 2 deletions nfabackend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
<artifactId>hibernate-core</artifactId>
<version>5.2.12.Final</version>
</dependency>
<!-- <dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<scope>provided</scope>
</dependency> -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public List<Project> getAllProject() {
@Path("/create")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createProject(Project project, @Context UriInfo uriInfo) {
public Response createProject(Project project, @Context UriInfo uriInfo) {

Project createProject = queryService.createProject(project);
String newId = String.valueOf(createProject.getId());
Expand All @@ -54,4 +54,13 @@ public Response createProject(Project project, @Context UriInfo uriInfo) {
public void deleteProject(@PathParam("ProjectId") Long Id) {
queryService.removeProject(Id);
}


@POST
@Path("/edit")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void editProject(Project project, @Context UriInfo uriInfo) {
queryService.updateProject(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public List<Project> getAllProject() {
return listProject;
}

/**
* Create new project
* @param project
* @return Project
*/
public Project createProject(Project project) {
try {
tx.begin();
Expand Down Expand Up @@ -81,4 +86,36 @@ public void removeProject(Long id) {
}

}

/**
* Updates a project by finding it by id first
* @param id
*/
public void updateProject(Project editedProject) {
try {
tx.begin();

Project project = em.find(Project.class, editedProject.getId());

project.setCustomerName(editedProject.getCustomerName());
project.setBranch(editedProject.getBranch());
project.setContactPersCustomer(editedProject.getContactPersCustomer());
project.setContactPersMsg(editedProject.getContactPersMsg());
project.setDevelopmentProcess(editedProject.getDevelopmentProcess());
project.setProjectPhase(editedProject.getProjectPhase());
project.setProjectStatus(editedProject.getProjectStatus());
project.setProjectType(editedProject.getProjectType());



em.merge(editedProject);
tx.commit();
}catch(Exception e){
LOG.log(Level.SEVERE, "Searching project failed...", e);
tx.rollback();
}finally {
em.close();
emf.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
<!-- <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/> -->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
</properties>
</persistence-unit>
</persistence>
2 changes: 1 addition & 1 deletion nfafrontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const appRoutes: Routes = [
{path: 'home', component: HomeComponent},
{path: 'curr-projects', component: CurrentProjectComponent, children: [
{path: ':id', component: ProjectDetailComponent},
{path: ':id/edit', component: ProjectEditComponent}
{path: ':id/edit', component: ProjectEditComponent}
]}
];
@NgModule({
Expand Down
18 changes: 6 additions & 12 deletions nfafrontend/src/app/current-project/current-project.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import {Subject} from 'rxjs/Subject';
import {Currentproject} from '../shared/currentproject.model';
import {Project} from '../shared/project.model';


export class CurrentProjectService {
projectsChanged = new Subject<Currentproject[]>();
// private projects: Currentproject[];
private projects: Currentproject[] = [
new Currentproject('1', 'ArbeitAgentur', 'James', 'Thomas', 'Public Sector', 'Communication',
'agil', 'lastenheft', 'onprocess'),
new Currentproject('2', 'XYZ Agentur', 'Greg', 'Walt', 'Automotive', 'Datenaustausch',
'Klassisch', 'Pflichtenheft', 'onprocess')
];
projectsChanged = new Subject<Project[]>();
private projects: Project[];


getProjects() {
Expand All @@ -21,17 +15,17 @@ export class CurrentProjectService {
return this.projects[index];
}

updateProject(index: number, newProject: Currentproject) {
updateProject(index: number, newProject: Project) {
this.projects[index] = newProject;
this.projectsChanged.next(this.projects.slice());
}

deleteProject(index: number) {
this.projects.splice(index,1);
this.projectsChanged.next(this.projects.slice());
}

setProjects(projects: Currentproject[]){
setProjects(projects: Project[]){
this.projects = projects;
this.projectsChanged.next(this.projects.slice());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Params, Router} from '@angular/router';
import {DataStorageService} from '../../shared/data-storage.service';
import {Currentproject} from '../../shared/currentproject.model';
import {Project} from '../../shared/project.model';
import {CurrentProjectService} from '../current-project.service';
import {Response} from '@angular/http';

Expand All @@ -11,7 +11,7 @@ import {Response} from '@angular/http';
styleUrls: ['./project-detail.component.css']
})
export class ProjectDetailComponent implements OnInit {
project: Currentproject;
project: Project;
id: number;
constructor(private route: ActivatedRoute,
private router: Router,
Expand All @@ -36,7 +36,7 @@ export class ProjectDetailComponent implements OnInit {
this.currentProjectService.deleteProject(this.id);
this.dataStorageService.deleteProject(this.project)
.subscribe(
(response: Response) => {
(response) => {
this.router.navigate(['../'], {relativeTo: this.route});
this.currentProjectService.projectsChanged.next(this.currentProjectService.getProjects());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
<p>
project-edit works!
</p>
<div class="row">
<div class="col-xs-12" style="text-align: center">
<span class="label label-default">Edit Project</span>
</div>
</div>
<hr>
<div class ="div1">
<form (ngSubmit) = "onUpdateProject()">
<label>Customer name</label>
<input type="text"
class="txt"
name="customerName"
style="float:right"
[(ngModel)]="project.customerName">
<br><br>
<label>Contact person for customer</label>
<input type="text"
class="txt"
name="contactPersCustomer"
style="float:right"
[(ngModel)]="project.contactPersCustomer">
<br><br>
<label>Contact person for msg</label>
<input type="text"
class="txt"
name="contactPersMsg"
style="float:right"
[(ngModel)]="project.contactPersMsg">
<br><br>

<label>Branch</label>
<select name="branch" style="float:right" [(ngModel)]="project.branch">
<option value="" disabled>Choose branch</option>
<option value="Public Sector">Public Sector</option>
<option value="Automotive">Automotive</option>
<option value="Banking">Banking</option>
</select><br><br><br>
<label>Project type</label>
<select name="projectType" style="float:right" [(ngModel)]="project.projectType">
<option value="" disabled>Choose project type</option>
<option value="Communication project">Communication project</option>
<option value="Data exchange project">Data exchange project</option>
</select><br><br><br>
<label>Development process</label>
<select name="developmentProcess" style="float:right" [(ngModel)]="project.developmentProcess">
<option value="" disabled>Choose development process</option>
<option value="Agile">Agile</option>
<option value="Classic">Classic</option>
</select><br><br><br>
<label>Project phase</label>
<select name="projectPhase" style="float:right" [(ngModel)]="project.projectPhase">
<option value="" disabled>Choose project phase</option>
<option value="Specification Sheet">Specification Sheet</option>
<option value="Requirements Specification">Requirements Specification</option>
</select><br><br><br>
<table style="width: 100%">
<tr>
<td align="right">
<button class="btn btn-primary" type="submit" style="float:right">Save project</button>
</td>
</tr>
</table>
</form>
</div>
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import { DataStorageService } from '../../shared/data-storage.service';
import { Component, OnInit } from '@angular/core';
import { Project } from '../../shared/project.model';
import { CurrentProjectService } from '../current-project.service';
import { ActivatedRoute, Router, Params } from '@angular/router';


@Component({
selector: 'app-project-edit',
templateUrl: './project-edit.component.html',
styleUrls: ['./project-edit.component.css']
})
export class ProjectEditComponent implements OnInit {

constructor() { }
project: Project;
id: number;
constructor(private route: ActivatedRoute,
private router: Router,
private currentProjectService: CurrentProjectService,
private dataStorage: DataStorageService) { }

ngOnInit() {
this.route.params.subscribe(
(params) => {
this.id = +params['id'];
this.project = this.copy(
this.currentProjectService.getProject(this.id));
});
}

private copy(toEdit: Project) {
return new Project(toEdit.id,
toEdit.customerName,
toEdit.contactPersCustomer,
toEdit.contactPersMsg,
toEdit.branch,
toEdit.projectType,
toEdit.developmentProcess,
toEdit.projectPhase,
toEdit.projectStatus);
}

onUpdateProject() {
this.dataStorage.updateProject(this.project).subscribe((response) => {
this.currentProjectService.updateProject(this.id, this.project);
this.router.navigate(['../'], {relativeTo: this.route});
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, Input, OnInit} from '@angular/core';
import {Currentproject} from '../../../shared/currentproject.model';
import {Project} from '../../../shared/project.model';

@Component({
selector: 'app-project-item',
Expand All @@ -8,7 +8,7 @@ import {Currentproject} from '../../../shared/currentproject.model';
})
export class ProjectItemComponent implements OnInit {

@Input() project: Currentproject;
@Input() project: Project;
@Input() index: number;

constructor() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="col-xs-12">

<app-project-item
*ngFor="let projectEl of projects; let i = index"
*ngFor="let projectEl of projects let i = index"
[project]="projectEl"
[index]="i"></app-project-item>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import {DataStorageService} from '../../shared/data-storage.service';
import {Currentproject} from '../../shared/currentproject.model';
import {Project} from '../../shared/project.model';
import {Response} from '@angular/http';
import {CurrentProjectService} from '../current-project.service';

Expand All @@ -10,21 +10,21 @@ import {CurrentProjectService} from '../current-project.service';
styleUrls: ['./project-list.component.css']
})
export class ProjectListComponent implements OnInit {
projects: Currentproject[];

projects: Project[];
constructor(private currentProjectService: CurrentProjectService,
private dataStorageService: DataStorageService) { }


ngOnInit() {
this.dataStorageService.getCurrentProjects()
.subscribe(
(response: Response) => {
const projects: Currentproject[] = response.json();
this.currentProjectService.setProjects(projects);
this.projects = projects;
}
const projects: Project[] = response.json();
this.currentProjectService.setProjects(projects);
this.projects = projects;
}
);
this.projects = this.currentProjectService.getProjects();
}

}
10 changes: 7 additions & 3 deletions nfafrontend/src/app/newproject/newproject.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import {DataStorageService} from '../shared/data-storage.service';
import {Project} from './project.model';
import {Project} from '../shared/project.model';
import {NgForm} from '@angular/forms';
import { EditableTableService } from '../editable-table/editable-table.service';

Expand All @@ -11,7 +11,7 @@ import { EditableTableService } from '../editable-table/editable-table.service';
})
export class NewprojectComponent implements OnInit {
messageField;
project = new Project();
project = this.initProject();
tableHeaders = ['Project Type'];
tableRowsWithId: any[][] = [
[1, 'Type1'],
Expand All @@ -38,10 +38,14 @@ export class NewprojectComponent implements OnInit {
// TODO -> check server-failure and show some message...
this.project = response.json();
this.messageField = 'A new project with ID ' + this.project.id + ' created';
this.project = new Project();
this.project = this.initProject();
});
}

private initProject() {
return new Project(null, null, null, null, null, null, null, null, null);
}

clearMessage() {
this.messageField = '';
}
Expand Down
Loading

0 comments on commit 96eb223

Please sign in to comment.