argos/dmp-frontend/src/app/datasets/dataset.component.ts

152 lines
4.2 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, Input, ViewChild, NgZone ,Output ,EventEmitter} from '@angular/core';
2017-10-18 18:30:39 +02:00
import {GoogleSignInSuccess} from 'angular-google-signin';
import { Router, ActivatedRoute } from '@angular/router';
import { ServerService } from '../../app/services/server.service';
import { Project } from '../entities/model/project';
import { Dataset } from '../entities/model/dataset';
2017-10-27 10:34:05 +02:00
import { Dmp } from '../entities/model/dmp';
2017-10-18 18:30:39 +02:00
import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-data-table-bootstrap-4';
2017-10-27 16:08:10 +02:00
import { DropdownField } from '../../app/form/fields/dropdown/field-dropdown';
import { Param } from '../entities/model/param';
2017-10-18 18:30:39 +02:00
@Component({
selector: 'datasets-table',
2017-10-18 18:30:39 +02:00
templateUrl: 'dataset.html',
// template: `
// <h1 class="title">Projects</h1>
// <ul class="list-group col-md-4">
// <li *ngFor="let project of projects"
// class="list-group-item">
// <a [routerLink]="['/dynamic-form', project.id]" >
// {{ project.name }}
// </a>
// </li>
// </ul>
// <router-outlet></router-outlet>
// `,
providers: [ServerService]
})
export class DatasetsComponent implements OnInit{
2017-10-18 18:30:39 +02:00
returnUrl: string;
@Input() datasets: Dataset[];
2017-10-27 16:08:10 +02:00
@Input() datasetProfileDropDown: DropdownField;
datasetResource :DataTableResource<Dataset>;
@Input() datasetCount = 0;
2017-10-27 16:08:10 +02:00
@Input() dmpIdforDatasets: string;
dataset:any;
2017-10-18 18:30:39 +02:00
@ViewChild(DataTable) projectsTable;
dataSetValue:boolean
@Input()
get dataSetVisibe(){
return this.dataSetValue;
}
@Output()
public dataSetValueChange = new EventEmitter();
set dataSetVisibe(value:any){
this.dataSetValue = value
this.dataSetValueChange.emit(this.dataSetValue)
}
2017-10-18 18:30:39 +02:00
constructor(
private serverService: ServerService,
private route: ActivatedRoute,
private router: Router,
private ngZone: NgZone){
2017-10-27 16:08:10 +02:00
this.dataset = {
id:null,
label:'',
reference:'',
uri:'',
properties:'',
profile:{"id": ''},
dmp:{"id": ''}
}
this.datasetProfileDropDown = new DropdownField();
this.datasetProfileDropDown.options = [];
2017-10-18 18:30:39 +02:00
}
ngOnInit() {
//this.projects = this.serverService.getDummyProjects();
this.datasets = [];
2017-10-27 16:08:10 +02:00
console.log(this.dmpIdforDatasets);
this.serverService.getDatasetForDmp({"id":this.dmpIdforDatasets}).subscribe(
2017-10-18 18:30:39 +02:00
response => {
console.log("response");
console.log(response);
response.forEach(resp => {
let dt = new Dataset();
dt.id = resp.id;
dt.name = resp.label;
dt.uriDataset = resp.uri;
this.datasets.push(dt);
2017-10-18 18:30:39 +02:00
var params = {limit:8,offset:0, sortAsc:false}
this.afterLoad();
this.datasetResource.query(params).then(datasets => this.datasets = datasets);
2017-10-18 18:30:39 +02:00
});
}
2017-10-27 16:08:10 +02:00
);
this.serverService.getAllDatsetsProfile().subscribe(
response => {
console.log("response");
console.log(response);
//let params = new Param();
response.forEach((datasetprofile) => {
let params = new Param();
params.key = datasetprofile.id;
params.value = datasetprofile.label;
this.datasetProfileDropDown.options.push(params);
});
}
)
2017-10-18 18:30:39 +02:00
}
reloadDatasets(params) {
this.datasetResource = new DataTableResource(this.datasets);
this.datasetResource.query(params).then(projects => this.datasets = projects);
2017-10-18 18:30:39 +02:00
}
afterLoad(){
this.datasetResource = new DataTableResource(this.datasets);
this.datasetResource.count().then(count => this.datasetCount = count);
}
rowClick(rowEvent){
this.ngZone.run(() => this.router.navigateByUrl('dynamic-form', rowEvent.row.item.id));
2017-10-18 18:30:39 +02:00
}
2017-10-27 16:08:10 +02:00
SaveNewDataset(){debugger;
this.dataset.dmp={"id": this.dmpIdforDatasets}
this.dataset.profile = {"id": this.dataset.profile}
this.serverService.createDatasetForDmp(this.dataset).subscribe(
response=>{
console.log(response);
}
)
}
2017-10-18 18:30:39 +02:00
// special params:
translations = <DataTableTranslations>{
indexColumn: 'Index column',
expandColumn: 'Expand column',
selectColumn: 'Select column',
paginationLimit: 'Max results',
paginationRange: 'Result range'
};
}