argos/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts

65 lines
2.0 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, Input } from '@angular/core';
import { DatasetService } from '../../../core/services/dataset/dataset.service';
import { DataTableRequest } from '../../../core/model/data-table/data-table-request';
import { DatasetCriteria } from '../../../core/query/dataset/dataset-criteria';
import { DatasetListingModel } from '../../../core/model/dataset/dataset-listing';
import { AuthService } from '../../../core/services/auth/auth.service';
import { RecentActivityType } from '../../../core/common/enum/recent-activity-type';
import { Router} from '@angular/router';
2019-04-24 11:26:53 +02:00
@Component({
selector: 'app-drafts',
templateUrl: './drafts.component.html',
styleUrls: ['./drafts.component.css']
2019-04-24 11:26:53 +02:00
})
export class DraftsComponent implements OnInit {
datasetDrafts: DatasetListingModel[];
datasetDraftsTypeEnum = RecentActivityType;
@Input() routerLink: string;
status: number;
2019-04-24 11:26:53 +02:00
constructor(
private router: Router,
private datasetService: DatasetService,
private authentication: AuthService
) { }
2019-04-24 11:26:53 +02:00
ngOnInit() {
const fields: Array<string> = [];
const dmpDataTableRequest: DataTableRequest<DatasetCriteria> = new DataTableRequest(0, 2, { fields: fields });
dmpDataTableRequest.criteria = new DatasetCriteria();
dmpDataTableRequest.criteria.status = 0;
this.datasetService.getPaged(dmpDataTableRequest).subscribe(response => {
this.datasetDrafts = response.data;
});
}
2019-04-24 11:26:53 +02:00
redirect(id: string, type: RecentActivityType) {
switch (type) {
case RecentActivityType.Project: {
this.router.navigate(["projects/edit/" + id]);
return;
}
case RecentActivityType.Dataset: {
this.router.navigate(["datasets/edit/" + id]);
return;
}
case RecentActivityType.Dmp: {
this.router.navigate(["plans/edit/" + id]);
return;
}
default:
throw new Error("Unsupported Activity Type ");
}
}
public isAuthenticated(): boolean {
return !!this.authentication.current();
}
navigateToUrl() {
if (!this.isAuthenticated()) { return; }
this.router.navigate(['/datasets'], { queryParams: { status: 0 } });
}
2019-04-24 11:26:53 +02:00
}