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

109 lines
2.9 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';
@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[];
datasetResource :DataTableResource<Dataset>;
@Input() datasetCount = 0;
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-18 18:30:39 +02:00
}
ngOnInit() {
//this.projects = this.serverService.getDummyProjects();
this.datasets = [];
this.serverService.getAllDataSet().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
});
}
);
}
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
}
// special params:
translations = <DataTableTranslations>{
indexColumn: 'Index column',
expandColumn: 'Expand column',
selectColumn: 'Select column',
paginationLimit: 'Max results',
paginationRange: 'Result range'
};
}