94 lines
2.7 KiB
TypeScript
94 lines
2.7 KiB
TypeScript
|
import { Component, OnInit, Input, ViewChild } from '@angular/core';
|
||
|
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 { Dmp } from '../entities/model/Dmp';
|
||
|
import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-data-table-bootstrap-4';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'projects',
|
||
|
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{
|
||
|
|
||
|
returnUrl: string;
|
||
|
@Input() projects: Project[];
|
||
|
projectResource :DataTableResource<Project>;
|
||
|
@Input() projectCount = 0;
|
||
|
|
||
|
@ViewChild(DataTable) projectsTable;
|
||
|
|
||
|
constructor(
|
||
|
private serverService: ServerService,
|
||
|
private route: ActivatedRoute,
|
||
|
private router: Router){
|
||
|
|
||
|
}
|
||
|
|
||
|
ngOnInit() {
|
||
|
//this.projects = this.serverService.getDummyProjects();
|
||
|
this.projects = [];
|
||
|
this.serverService.getProjects().subscribe(
|
||
|
response => {
|
||
|
|
||
|
console.log("response");
|
||
|
console.log(response);
|
||
|
response.forEach(resp => {
|
||
|
let pr = new Project();
|
||
|
pr.id = resp.id;
|
||
|
pr.name = resp.label;
|
||
|
pr.abbreviation = resp.abbreviation;
|
||
|
pr.definition = resp.definition;
|
||
|
pr.uri = resp.uri;
|
||
|
pr.dmp = new Dmp();
|
||
|
// pr.dmp.id = resp.dmp;
|
||
|
pr.dmp.id = resp.dmp =! null || resp.dmp ==! undefined ? resp.dmp.id : null;
|
||
|
// pr.dmp.dataset = resp.dmp.dataset != null ? resp.dmp.dataset.id: null;
|
||
|
this.projects.push(pr);
|
||
|
var params = {limit:8,offset:0, sortAsc:false}
|
||
|
this.afterLoad();
|
||
|
this.projectResource.query(params).then(projects => this.projects = projects);
|
||
|
});
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
reloadProjects(params) {
|
||
|
this.projectResource.query(params).then(projects => this.projects = projects);
|
||
|
}
|
||
|
|
||
|
afterLoad(){
|
||
|
this.projectResource = new DataTableResource(this.projects);
|
||
|
this.projectResource.count().then(count => this.projectCount = count);
|
||
|
}
|
||
|
|
||
|
// special params:
|
||
|
translations = <DataTableTranslations>{
|
||
|
indexColumn: 'Index column',
|
||
|
expandColumn: 'Expand column',
|
||
|
selectColumn: 'Select column',
|
||
|
paginationLimit: 'Max results',
|
||
|
paginationRange: 'Result range'
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
}
|