lightened the dmp ts

This commit is contained in:
Nikolaos Laskaris 2017-11-01 13:30:39 +02:00
parent ce829dafc7
commit a13134230f
2 changed files with 42 additions and 71 deletions

View File

@ -26,7 +26,7 @@ declare var $ :any;
export class DmpComponent implements OnInit{
// Start ALTERNATIVE
// Start ALTERNATIVE
//whole dmp data model
tableData : any[] = new Array();
@ -52,12 +52,12 @@ export class DmpComponent implements OnInit{
@Input() dmps: Dmp[];
//@Input() dmps: Dmp[];
dmp:any;
@Input() dmpCount = 0;
@Input() projectsDropDown:DropdownField;
@Input() dataSetVisibe:boolean;
@Input() projects: Project[];
//@Input() projects: Project[];
dmpIdforDatasets: string;
dmpLabelforDatasets:string;
@ViewChild(DatasetsComponent) datasetsComponent:DatasetsComponent;
@ -92,46 +92,21 @@ export class DmpComponent implements OnInit{
gapi.load('auth2', function() {
gapi.auth2.init({});
});
this.dmps = [];
this.serverService.getDmpOfUser().subscribe(
response => {
this.tableData = response;
console.log(response);
response.forEach(resp => {
// let dmp = new Dmp();
// dmp.id = resp.id;
// dmp.label = resp.label;
// dmp.version = resp.version;
// dmp.dataset = resp.dataset;
// dmp.projectLabel = resp.project.label;
// dmp.projectid = resp.project.id;
// dmp.previous = resp.previous;
// dmp.profile = resp.profile;
// dmp.profileData = resp.profileData;
// this.dmps.push(dmp);
// var params = {limit:8,offset:0, sortAsc:false}
//this.afterLoad();
//this.dmpResource.query(params).then(dmps => this.dmps = dmps);
}
);
(err: HttpErrorResponse) => {debugger;
this.tableData = response;
},
(err: HttpErrorResponse) => {
if (err.error instanceof Error) {
// A client-side or network error occurred. Handle it accordingly.
console.log('An error occurred:', err.error.message);
console.log("An error occurred:", err.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
if(err.status == 401){
this.isignOutBtn.nativeElement.click();
}
console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
console.log("Backend returned code ${err.status}, body was: ${err.error}");
}
}
});
);
this.serverService.getAllProjects().subscribe(
response => {
console.log("response");
console.log(response);
//let params = new Param();
response.forEach((dmp) => {
@ -141,63 +116,59 @@ export class DmpComponent implements OnInit{
this.projectsDropDown.options.push(params);
});
},
(err: HttpErrorResponse) => {
}
)
}
CallDmps(){
getDmps(){
this.serverService.getDmpOfUser().subscribe(
response => {
response.forEach(resp => {
let dmp = new Dmp();
dmp.id = resp.id;
dmp.label = resp.label;
dmp.version = resp.version;
dmp.dataset = resp.dataset;
dmp.projectLabel = resp.project.label;
this.dmps.push(dmp);
var params = {limit:8,offset:0, sortAsc:false}
//this.afterLoad();
//this.dmpResource.query(params).then(dmps => this.dmps = dmps);
}
);
});
response => {
this.tableData = response;
},
(err: HttpErrorResponse) => {
if (err.error instanceof Error) {
console.log("An error occurred:", err.error.message);
} else {
console.log("Backend returned code ${err.status}, body was: ${err.error}");
}
}
);
}
SaveNewDmp(){
newDMP(){
console.log(this.dmp, this.dmp.projectsDropDownKey);
//this.http.post('http://someurl', JSON.stringify(this.project))
this.dmp.project = {"id":this.dmp.project};
debugger;
this.dmp.project = {"id" : this.dmp.project};
this.dmp["version"] = 1;
this.serverService.createDmpForCurrentUser(this.dmp)
.subscribe(
response =>{
console.log("response");
console.log(response);
this.dmps = [];
this.CallDmps();
this.getDmps();
}
);
$("#newDmpModal").modal("hide");
}
SaveUpdatesDmp(){
updateDMP(){
console.log(this.dmp, this.dmp.projectsDropDownKey);
//this.http.post('http://someurl', JSON.stringify(this.project))
this.dmp.project = {"id":this.dmp.project};
this.dmp["version"] = 1;
this.serverService.updateDmpForCurrentUser(this.dmp)
debugger;
this.serverService.updateDmp(this.dmp)
.subscribe(
response =>{
console.log("response");
console.log(response);
this.dmps = [];
this.CallDmps();
}
);
$("#newDmpModal").modal("hide");
@ -205,16 +176,14 @@ SaveUpdatesDmp(){
}
SaveDmp(){ debugger;
SaveDmp(){
debugger;
if (this.dmp.id == null)
this.SaveNewDmp();
this.newDMP();
else
this.SaveUpdatesDmp();
this.updateDMP();
}
signOut() {
    this.serverService.logOut();
}
selectDmp(item){
this.dmpIdforDatasets = item.id;
@ -265,7 +234,8 @@ newDmp(item){
}
refreshTable(){
this.CallDmps();
this.getDmps();
}
}

View File

@ -103,9 +103,10 @@ export class ServerService {
return this.restBase.post("dmp/createofuser", data);
}
public updateDmpForCurrentUser(data:any){
return this.restBase.post("dmp/update", data);
}
public updateDmp(data:any){
return this.restBase.post("dmp/update", data);
}
public getDatasetForDmp(data:any){
return this.restBase.post("dmp/getdatasets", data);