2019-09-23 10:17:03 +02:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { FormControl } from '@angular/forms';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { RecentActivityType } from '@app/core/common/enum/recent-activity-type';
|
|
|
|
import { DashboardStatisticsModel } from '@app/core/model/dashboard/dashboard-statistics-model';
|
|
|
|
import { SearchBarItem } from '@app/core/model/dashboard/search-bar-item';
|
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
|
|
import { DatasetListingModel } from '@app/core/model/dataset/dataset-listing';
|
|
|
|
import { DmpListingModel } from '@app/core/model/dmp/dmp-listing';
|
|
|
|
import { ExploreDatasetCriteriaModel } from '@app/core/query/explore-dataset/explore-dataset-criteria';
|
|
|
|
import { ExploreDmpCriteriaModel } from '@app/core/query/explore-dmp/explore-dmp-criteria';
|
|
|
|
import { GrantCriteria } from '@app/core/query/grant/grant-criteria';
|
|
|
|
import { RequestItem } from '@app/core/query/request-item';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
|
|
|
import { DashboardService } from '@app/core/services/dashboard/dashboard.service';
|
|
|
|
import { DatasetService } from '@app/core/services/dataset/dataset.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { GrantService } from '@app/core/services/grant/grant.service';
|
|
|
|
import { SearchBarService } from '@app/core/services/search-bar/search-bar.service';
|
|
|
|
import { UserService } from '@app/core/services/user/user.service';
|
|
|
|
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { Observable, of as observableOf } from 'rxjs';
|
|
|
|
import { mergeMap, takeUntil } from 'rxjs/operators';
|
2019-05-16 18:11:41 +02:00
|
|
|
import { BreadcrumbItem } from '../misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '../misc/breadcrumb/definition/IBreadCrumbComponent';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2019-12-11 15:51:03 +01:00
|
|
|
|
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[];
|
2019-08-01 09:54:40 +02:00
|
|
|
grantActivities: any[];
|
2019-01-18 18:03:45 +01:00
|
|
|
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();
|
2019-08-01 09:54:40 +02:00
|
|
|
grantAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
2019-01-18 18:03:45 +01:00
|
|
|
public searchControl = new FormControl();
|
|
|
|
filteredOptions: Observable<SearchBarItem[]>;
|
|
|
|
recentActivityTypeEnum = RecentActivityType;
|
|
|
|
public search = false;
|
2019-05-15 17:21:04 +02:00
|
|
|
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-08-01 09:54:40 +02:00
|
|
|
private grantService: GrantService,
|
2019-05-15 17:21:04 +02:00
|
|
|
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;
|
2019-08-01 09:54:40 +02:00
|
|
|
// this.dashboardStatisticsData.totalGrantCount = 0;
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
2019-05-10 10:33:48 +02:00
|
|
|
// if (this.isAuthenticated()) {
|
|
|
|
// this.userService.getRecentActivity()
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(response => {
|
|
|
|
// this.datasetActivities = response['recentDatasetActivities'];
|
|
|
|
// this.dmpActivities = response['recentDmpActivities'];
|
2019-08-01 09:54:40 +02:00
|
|
|
// this.grantActivities = response['recentGrantActivities'];
|
2019-05-10 10:33:48 +02:00
|
|
|
// this.organisationActivities = response['totalOrganisationCount'];
|
|
|
|
// });
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
// this.grantAutoCompleteConfiguration = {
|
|
|
|
// filterFn: this.searchGrant.bind(this),
|
|
|
|
// items: this.searchGrant(''),
|
2019-01-18 18:03:45 +01:00
|
|
|
// displayFn: (item) => item['label'],
|
2019-01-21 12:14:20 +01:00
|
|
|
// titleFn: (item) => item['label']
|
2019-01-18 18:03:45 +01:00
|
|
|
// };
|
|
|
|
|
2019-05-16 18:11:41 +02:00
|
|
|
const breadCrumbs = [];
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf(breadCrumbs);
|
2019-05-16 18:11:41 +02:00
|
|
|
|
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;
|
|
|
|
});
|
2019-06-04 09:36:39 +02:00
|
|
|
this.getPublicDmps();
|
|
|
|
this.getPublicDatasets();
|
2019-01-18 18:03:45 +01:00
|
|
|
} else {
|
|
|
|
this.dashboardService.getUserStatistics()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(results => {
|
|
|
|
this.dashboardStatisticsData = results;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
this.filteredOptions = this.searchControl.valueChanges.pipe(mergeMap(x => {
|
2019-01-18 18:03:45 +01:00
|
|
|
return this.searchBarService.search(x);
|
2019-09-23 10:17:03 +02:00
|
|
|
}));
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public isAuthenticated(): boolean {
|
|
|
|
return !(!this.authentication.current());
|
|
|
|
}
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
searchGrant(query: string) {
|
|
|
|
const grantRequestItem: RequestItem<GrantCriteria> = new RequestItem();
|
|
|
|
grantRequestItem.criteria = new GrantCriteria();
|
|
|
|
grantRequestItem.criteria.like = query;
|
|
|
|
return this.grantService.getWithExternal(grantRequestItem);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
redirect(id: string, type: RecentActivityType) {
|
|
|
|
switch (type) {
|
2019-08-01 09:54:40 +02:00
|
|
|
case RecentActivityType.Grant: {
|
|
|
|
this.router.navigate(['grants/edit/' + id]);
|
2019-01-18 18:03:45 +01:00
|
|
|
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 ');
|
|
|
|
}
|
|
|
|
}
|
2019-05-15 17:21:04 +02:00
|
|
|
|
|
|
|
getPublicDmps() {
|
|
|
|
const dmpCriteria = new ExploreDmpCriteriaModel();
|
|
|
|
const fields: Array<string> = new Array<string>();
|
2019-09-23 17:11:29 +02:00
|
|
|
fields.push('-finalizedAt');
|
2019-05-15 17:21:04 +02:00
|
|
|
const dataTableRequest: DataTableRequest<ExploreDmpCriteriaModel> = new DataTableRequest(0, 2, { fields: fields });
|
|
|
|
dataTableRequest.criteria = dmpCriteria;
|
2019-06-11 10:25:32 +02:00
|
|
|
return this.dmpService.getPublicPaged(dataTableRequest, "listing").pipe(takeUntil(this._destroyed)).subscribe(result => { this.dmpListingItems = result.data; });
|
2019-05-15 17:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getPublicDatasets() {
|
|
|
|
const dmpCriteria = new ExploreDatasetCriteriaModel();
|
|
|
|
const fields: Array<string> = new Array<string>();
|
2019-12-12 10:26:19 +01:00
|
|
|
fields.push('-modified');
|
2019-05-15 17:21:04 +02:00
|
|
|
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) {
|
2019-09-20 12:54:37 +02:00
|
|
|
if (!this.isAuthenticated()) {
|
|
|
|
this.router.navigate(['../explore-plans/overview', dmp.id], { relativeTo: this.route });
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['/plans/publicEdit/' + dmp.id]);
|
|
|
|
}
|
2019-05-15 17:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
datasetClicked(dataset: DatasetListingModel) {
|
|
|
|
this.router.navigate(['/datasets/publicEdit/' + dataset.id]);
|
|
|
|
}
|
|
|
|
|
2019-10-25 13:54:12 +02:00
|
|
|
// viewAllPublicDmpsClicked() {
|
|
|
|
// this.router.navigate(['/explore-plans']);
|
|
|
|
// }
|
2019-05-15 17:21:04 +02:00
|
|
|
|
2019-10-25 13:54:12 +02:00
|
|
|
// viewAllPublicDatasetsClicked() {
|
|
|
|
// this.router.navigate(['explore']);
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|