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

181 lines
6.7 KiB
TypeScript
Raw Normal View History

2019-01-18 18:03:45 +01:00
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
2019-05-16 18:11:41 +02:00
import { Router, ActivatedRoute, Params } from '@angular/router';
2019-01-18 18:03:45 +01:00
import { takeUntil } from 'rxjs/operators';
import { BaseComponent } from '../../core/common/base/base.component';
import { RecentActivityType } from '../../core/common/enum/recent-activity-type';
import { DashboardStatisticsModel } from '../../core/model/dashboard/dashboard-statistics-model';
import { SearchBarItem } from '../../core/model/dashboard/search-bar-item';
import { ProjectCriteria } from '../../core/query/project/project-criteria';
import { AuthService } from '../../core/services/auth/auth.service';
import { DashboardService } from '../../core/services/dashboard/dashboard.service';
import { ProjectService } from '../../core/services/project/project.service';
import { SearchBarService } from '../../core/services/search-bar/search-bar.service';
import { UserService } from '../../core/services/user/user.service';
import { SingleAutoCompleteConfiguration } from '../../library/auto-complete/single/single-auto-complete-configuration';
import { RequestItem } from '../../core/query/request-item';
import { DmpListingModel } from '../../core/model/dmp/dmp-listing';
import { DmpService } from '../../core/services/dmp/dmp.service';
import { DataTableRequest } from '../../core/model/data-table/data-table-request';
import { DmpCriteria } from '../../core/query/dmp/dmp-criteria';
import { ExploreDmpCriteriaModel } from '../../core/query/explore-dmp/explore-dmp-criteria';
import { DatasetListingModel } from '../../core/model/dataset/dataset-listing';
import { DatasetService } from '../../core/services/dataset/dataset.service';
import { ExploreDatasetCriteriaModel } from '../../core/query/explore-dataset/explore-dataset-criteria';
2019-05-16 18:11:41 +02:00
import { BreadcrumbItem } from '../misc/breadcrumb/definition/breadcrumb-item';
import { IBreadCrumbComponent } from '../misc/breadcrumb/definition/IBreadCrumbComponent';
import { Observable } from 'rxjs';
2019-01-18 18:03:45 +01:00
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss'],
})
2019-05-16 18:11:41 +02:00
export class DashboardComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
breadCrumbs: Observable<BreadcrumbItem[]>;
2019-01-18 18:03:45 +01:00
public userInfo: any;
datasetActivities: any[];
projectActivities: any[];
dmpActivities: any[];
2019-04-24 11:26:53 +02:00
organisationActivities: any[];
2019-01-18 18:03:45 +01:00
public dashboardStatisticsData: DashboardStatisticsModel;
public formControl = new FormControl();
projectAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
public searchControl = new FormControl();
filteredOptions: Observable<SearchBarItem[]>;
recentActivityTypeEnum = RecentActivityType;
public search = false;
dmpListingItems: DmpListingModel[] = [];
datasetListingItems: DatasetListingModel[] = [];
2019-01-18 18:03:45 +01:00
constructor(
private router: Router,
2019-05-16 18:11:41 +02:00
private route: ActivatedRoute,
2019-01-18 18:03:45 +01:00
private projectService: ProjectService,
private dmpService: DmpService,
private datasetService: DatasetService,
2019-01-18 18:03:45 +01:00
private dashboardService: DashboardService,
private searchBarService: SearchBarService,
private authentication: AuthService,
private userService: UserService
) {
super();
// this.dashboardStatisticsData.totalDataManagementPlanCount = 0;
// this.dashboardStatisticsData.totalDataSetCount = 0;
// this.dashboardStatisticsData.totalProjectCount = 0;
}
ngOnInit() {
// if (this.isAuthenticated()) {
// this.userService.getRecentActivity()
// .pipe(takeUntil(this._destroyed))
// .subscribe(response => {
// this.datasetActivities = response['recentDatasetActivities'];
// this.dmpActivities = response['recentDmpActivities'];
// this.projectActivities = response['recentProjectActivities'];
// this.organisationActivities = response['totalOrganisationCount'];
// });
// }
2019-01-18 18:03:45 +01:00
// this.projectAutoCompleteConfiguration = {
// filterFn: this.searchProject.bind(this),
// items: this.searchProject(''),
// displayFn: (item) => item['label'],
// titleFn: (item) => item['label']
2019-01-18 18:03:45 +01:00
// };
2019-05-16 18:11:41 +02:00
const breadCrumbs = [];
this.breadCrumbs = Observable.of(breadCrumbs);
2019-01-18 18:03:45 +01:00
if (!this.isAuthenticated()) {
this.dashboardService.getStatistics()
.pipe(takeUntil(this._destroyed))
.subscribe(results => {
//let data = results['payload'];
this.dashboardStatisticsData = results;
});
} else {
this.dashboardService.getUserStatistics()
.pipe(takeUntil(this._destroyed))
.subscribe(results => {
this.dashboardStatisticsData = results;
});
}
this.filteredOptions = this.searchControl.valueChanges.flatMap(x => {
return this.searchBarService.search(x);
});
this.getPublicDmps();
this.getPublicDatasets();
2019-01-18 18:03:45 +01:00
}
public isAuthenticated(): boolean {
return !(!this.authentication.current());
}
searchProject(query: string) {
const projectRequestItem: RequestItem<ProjectCriteria> = new RequestItem();
projectRequestItem.criteria = new ProjectCriteria();
projectRequestItem.criteria.like = query;
return this.projectService.getWithExternal(projectRequestItem);
}
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 ');
}
}
getPublicDmps() {
const dmpCriteria = new ExploreDmpCriteriaModel();
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<ExploreDmpCriteriaModel> = new DataTableRequest(0, 2, { fields: fields });
dataTableRequest.criteria = dmpCriteria;
return this.dmpService.getPublicPaged(dataTableRequest).pipe(takeUntil(this._destroyed)).subscribe(result => { this.dmpListingItems = result.data; });
}
getPublicDatasets() {
const dmpCriteria = new ExploreDatasetCriteriaModel();
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<ExploreDatasetCriteriaModel> = new DataTableRequest(0, 4, { fields: fields });
dataTableRequest.criteria = dmpCriteria;
return this.datasetService.getPublicPaged(dataTableRequest).pipe(takeUntil(this._destroyed)).subscribe(result => { this.datasetListingItems = result.data; });
}
dmpClicked(dmp: DmpListingModel) {
this.router.navigate(['/plans/publicEdit/' + dmp.id]);
}
datasetClicked(dataset: DatasetListingModel) {
this.router.navigate(['/datasets/publicEdit/' + dataset.id]);
}
viewAllPublicDmpsClicked() {
this.router.navigate(['/explore-plans']);
}
viewAllPublicDatasetsClicked() {
this.router.navigate(['explore']);
}
2019-01-18 18:03:45 +01:00
}