126 lines
4.8 KiB
TypeScript
126 lines
4.8 KiB
TypeScript
import { Component, OnInit, Input } from '@angular/core';
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
import { DashboardService } from '../../app/services/dashboard/dashboard.service';
|
|
import { DashboardStatisticsModel } from '../models/dashboard/DashboardStatisticsModel';
|
|
import { JsonSerializer } from '../utilities/JsonSerializer';
|
|
import { AuthService } from '../services/auth/auth.service';
|
|
import { FormControl } from '@angular/forms';
|
|
import { RequestItem } from '../models/criteria/RequestItem';
|
|
import { ProjectCriteria } from '../models/criteria/project/ProjectCriteria';
|
|
import { ProjectService } from '../services/project/project.service';
|
|
import { SingleAutoCompleteConfiguration } from '../shared/components/autocompletes/single/single-auto-complete-configuration';
|
|
import { UserReferenceService } from '../services/user-reference/user-reference-data.service';
|
|
import { RecentActivityTypes } from '../users/activity/RecentActivityTypes';
|
|
import { Observable } from 'rxjs/internal/Observable';
|
|
import { SearchBarItem } from '../models/dashboard/SearchBarItem';
|
|
import { SearchBarType } from '../shared/components/search-bar/types/search-bar-type';
|
|
|
|
@Component({
|
|
selector: 'app-homepage',
|
|
templateUrl: './homepage.component.html',
|
|
styleUrls: ['./homepage.component.scss'],
|
|
providers: [ProjectService, UserReferenceService]
|
|
})
|
|
export class HomepageComponent implements OnInit {
|
|
|
|
public userInfo: any;
|
|
datasetActivities: any[];
|
|
projectActivities: any[];
|
|
dmpActivities: any[];
|
|
public dashboardStatisticsData: DashboardStatisticsModel = new DashboardStatisticsModel();
|
|
public formControl = new FormControl();
|
|
projectAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
public searchControl = new FormControl();
|
|
filteredOptions: Observable<SearchBarItem[]>;
|
|
RecentActivityTypes = RecentActivityTypes;
|
|
public search = false;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private projectService: ProjectService,
|
|
private dashBoardService: DashboardService,
|
|
private authentication: AuthService,
|
|
private userReferenceService: UserReferenceService
|
|
|
|
) {
|
|
this.dashboardStatisticsData.totalDataManagementPlanCount = 0;
|
|
this.dashboardStatisticsData.totalDataSetCount = 0;
|
|
this.dashboardStatisticsData.totalProjectCount = 0;
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if (this.isAuthenticated()) {
|
|
this.userReferenceService.getRecentActivity().subscribe(response => {
|
|
this.datasetActivities = response['recentDatasetActivities'];
|
|
this.dmpActivities = response['recentDmpActivities'];
|
|
this.projectActivities = response['recentProjectActivities'];
|
|
});
|
|
}
|
|
|
|
this.projectAutoCompleteConfiguration = {
|
|
filterFn: this.searchProject.bind(this),
|
|
items: this.searchProject(''),
|
|
displayFn: (item) => item['label'],
|
|
titleFn: (item) => item['label'],
|
|
//mapFn: (item) => new JsonSerializer<ProjectReference>().fromJSONArray(item, ProjectReference).map(item => item.toDropdownList()),
|
|
loadDataOnStart: true
|
|
};
|
|
|
|
if (!this.isAuthenticated()) {
|
|
this.dashBoardService.getStatistics().subscribe(results => {
|
|
//let data = results['payload'];
|
|
this.dashboardStatisticsData = JsonSerializer.fromJSONObject(results, DashboardStatisticsModel);
|
|
});
|
|
} else {
|
|
this.dashBoardService.getStatisticsSpecificuser().subscribe(results => {
|
|
this.dashboardStatisticsData = JsonSerializer.fromJSONObject(results, DashboardStatisticsModel);
|
|
});
|
|
}
|
|
|
|
this.filteredOptions = this.searchControl.valueChanges.flatMap(x => {
|
|
return this.dashBoardService.searchUserItems(x);
|
|
});
|
|
|
|
}
|
|
|
|
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: RecentActivityTypes) {
|
|
switch (type) {
|
|
case RecentActivityTypes.PROJECT: {
|
|
this.router.navigate(['projects/edit/' + id]);
|
|
return;
|
|
}
|
|
case RecentActivityTypes.DATASET: {
|
|
this.router.navigate(['datasets/edit/' + id]);
|
|
return;
|
|
}
|
|
case RecentActivityTypes.DMP: {
|
|
this.router.navigate(['dmps/edit/' + id]);
|
|
return;
|
|
}
|
|
default: throw new Error('Unsupported Activity Type ');
|
|
}
|
|
|
|
}
|
|
|
|
onOptionSelected(event: any) {
|
|
const selectedSearchBarItem = event.option.value;
|
|
if (selectedSearchBarItem.type === SearchBarType.DATASET) { this.router.navigate(['datasets/edit/' + selectedSearchBarItem.id]); }
|
|
if (selectedSearchBarItem.type === SearchBarType.PROJECT) { this.router.navigate(['projects/edit/' + selectedSearchBarItem.id]); }
|
|
if (selectedSearchBarItem.type === SearchBarType.DATAMANAGEMENTPLAN) { this.router.navigate(['dmps/edit/' + selectedSearchBarItem.id]); }
|
|
}
|
|
}
|