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

254 lines
8.3 KiB
TypeScript
Raw Normal View History

2019-09-23 10:17:03 +02:00
2024-03-20 17:06:05 +01:00
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { UntypedFormBuilder, Validators } from '@angular/forms';
2023-12-05 21:36:00 +01:00
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
2023-12-05 21:36:00 +01:00
import { DashboardStatistics } from '@app/core/model/dashboard/dashboard-statistics';
import { AuthService } from '@app/core/services/auth/auth.service';
2024-03-20 17:06:05 +01:00
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
import { DashboardService } from '@app/core/services/dashboard/dashboard.service';
2023-12-05 21:36:00 +01:00
import { MatomoService } from '@app/core/services/matomo/matomo-service';
2024-03-20 17:06:05 +01:00
import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service';
2023-12-05 21:36:00 +01:00
import { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.constants';
import { GuidedTourService } from '@app/library/guided-tour/guided-tour.service';
import { BaseComponent } from '@common/base/base.component';
2020-09-18 13:14:48 +02:00
import { TranslateService } from '@ngx-translate/core';
2024-03-20 17:06:05 +01:00
import * as moment from 'moment';
import { CookieService } from 'ngx-cookie-service';
2023-12-05 21:36:00 +01:00
import { takeUntil } from 'rxjs/operators';
2024-03-19 17:27:30 +01:00
import { StartNewDescriptionDialogComponent } from '../description/start-new-description-dialog/start-new-description-dialog.component';
2024-03-20 17:06:05 +01:00
import { StartNewDmpDialogComponent } from '../dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component';
2019-01-18 18:03:45 +01:00
2019-01-18 18:03:45 +01:00
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
2024-03-20 17:06:05 +01:00
styleUrls: ['./dashboard.component.scss']
2019-01-18 18:03:45 +01:00
})
export class DashboardComponent extends BaseComponent implements OnInit {
2019-01-18 18:03:45 +01:00
2023-12-05 21:36:00 +01:00
public dashboardStatistics: DashboardStatistics;
public grantCount = 0;
public organizationCount = 0;
currentType: string = "recent";
2024-03-20 17:06:05 +01:00
newReleaseNotificationVisible = false;
isIntroCardVisible = true;
2020-07-01 17:25:16 +02:00
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 dashboardService: DashboardService,
private authentication: AuthService,
2020-09-18 13:14:48 +02:00
private dialog: MatDialog,
private language: TranslateService,
2020-12-10 14:29:24 +01:00
private guidedTourService: GuidedTourService,
private matomoService: MatomoService,
2024-03-19 17:27:30 +01:00
public referenceTypeService: ReferenceTypeService,
private fb: UntypedFormBuilder,
2024-03-20 17:06:05 +01:00
private cookieService: CookieService,
public configurationService: ConfigurationService
2019-01-18 18:03:45 +01:00
) {
super();
}
ngOnInit() {
this.route.queryParams.subscribe(params => {
let type = params['type'];
2023-12-05 21:36:00 +01:00
if (type || type == "recent" || (type == "drafts" && this.isAuthenticated()) || type == "dmps" || type == "descriptions") {
this.currentType = type;
} else {
this.currentType = "recent";
}
});
2020-12-10 14:29:24 +01:00
this.matomoService.trackPageView('Home Dashboard');
2019-01-18 18:03:45 +01:00
if (!this.isAuthenticated()) {
2023-12-05 21:36:00 +01:00
this.dashboardService.getPublicDashboardStatistics()
2019-01-18 18:03:45 +01:00
.pipe(takeUntil(this._destroyed))
.subscribe(results => {
2023-12-05 21:36:00 +01:00
this.dashboardStatistics = results;
this.grantCount = this.dashboardStatistics.referenceTypeStatistics.filter(x => x.referenceType.id == this.referenceTypeService.getGrantReferenceType())?.find(Boolean).count;
this.organizationCount = this.dashboardStatistics.referenceTypeStatistics.filter(x => x.referenceType.id == this.referenceTypeService.getOrganizationReferenceType())?.find(Boolean).count;
2019-01-18 18:03:45 +01:00
});
} else {
2023-12-05 21:36:00 +01:00
this.dashboardService.getMyDashboardStatistics()
2019-01-18 18:03:45 +01:00
.pipe(takeUntil(this._destroyed))
.subscribe(results => {
2023-12-05 21:36:00 +01:00
this.dashboardStatistics = results;
this.grantCount = this.dashboardStatistics.referenceTypeStatistics.filter(x => x.referenceType.id == this.referenceTypeService.getGrantReferenceType())?.find(Boolean).count;
this.organizationCount = this.dashboardStatistics.referenceTypeStatistics.filter(x => x.referenceType.id == this.referenceTypeService.getOrganizationReferenceType())?.find(Boolean).count;
2023-12-05 21:36:00 +01:00
if (this.dashboardStatistics && this.dashboardStatistics.dmpCount === 0) {
this.openDashboardTour();
}
2019-01-18 18:03:45 +01:00
});
}
2024-03-20 17:06:05 +01:00
this.newReleaseNotificationVisible = this.isNewReleaseNotificationVisible();
2019-01-18 18:03:45 +01:00
}
public get indexFromCurrentType() {
2023-12-05 21:36:00 +01:00
if (this.currentType == "recent") {
return 0;
}
2023-12-05 21:36:00 +01:00
if (this.currentType == "drafts") {
return 1;
}
2023-12-05 21:36:00 +01:00
if (this.currentType == "dmps") {
return this.isAuthenticated() ? 2 : 1;
}
2023-12-05 21:36:00 +01:00
if (this.currentType == "descriptions") {
return this.isAuthenticated() ? 3 : 2;
}
return 0;
}
2019-01-18 18:03:45 +01:00
public isAuthenticated(): boolean {
2023-10-11 16:53:12 +02:00
return this.authentication.currentAccountIsAuthenticated();
2019-01-18 18:03:45 +01:00
}
openNewDmpDialog() {
if (this.dialog.openDialogs.length > 0) {
this.dialog.closeAll();
}
else {
const dialogRef = this.dialog.open(StartNewDmpDialogComponent, {
disableClose: false,
data: {
isDialog: true
}
});
}
}
2020-08-03 10:40:38 +02:00
public hasDmps(): boolean {
2023-12-05 21:36:00 +01:00
if (this.dashboardStatistics) {
return this.dashboardStatistics.dmpCount !== 0
|| this.dashboardStatistics.descriptionCount !== 0
|| this.dashboardStatistics.referenceTypeStatistics.length !== 0
2020-08-03 10:40:38 +02:00
} else {
return false;
}
}
2023-12-05 21:36:00 +01:00
addNewDescription() {
2024-03-19 17:27:30 +01:00
const formGroup = this.fb.group({
dmpId: this.fb.control(null, Validators.required),
})
const dialogRef = this.dialog.open(StartNewDescriptionDialogComponent, {
disableClose: false,
restoreFocus: false,
data: {
startNewDmp: false,
formGroup: formGroup
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
if (result.startNewDmp) {
this.openNewDmpDialog();
} else {
this.router.navigate(['/plans', 'edit', result.formGroup.get('dmpId').value]);
2024-03-19 17:27:30 +01:00
}
}
});
2020-09-18 13:14:48 +02:00
}
public dashboardTour: GuidedTour = {
tourId: 'dashboard-tour',
useOrb: true,
steps: [
{
selector: '.new-dmp-dialog',
content: 'Step 1',
orientation: Orientation.BottomRight,
isStepUnique: false,
highlightPadding: 10,
closeAction: () => this.openNewDmpDialog()
},
{
selector: '.import-file',
content: 'Step 2',
orientation: Orientation.Bottom,
isStepUnique: false,
highlightPadding: 10
},
{
selector: '.start-wizard',
content: 'Step 3',
orientation: Orientation.Bottom,
isStepUnique: false,
highlightPadding: 10,
closeAction: () => this.dialog.closeAll()
},
{
2023-12-05 21:36:00 +01:00
selector: '.new-description-tour',
content: 'Step 4',
orientation: Orientation.BottomLeft,
isStepUnique: false,
highlightPadding: 10
}
]
};
public setDashboardTourDmpText(): void {
2023-12-05 21:36:00 +01:00
const dmpText = this.language.instant('DASHBOARD.TOUR-GUIDE.DMP') + '\n\n' +
this.language.instant('DASHBOARD.TOUR-GUIDE.START-NEW');
2023-12-05 21:36:00 +01:00
this.dashboardTour.steps[0].title = dmpText;
}
public setDashboardImportFileText(): void {
2023-12-05 21:36:00 +01:00
const importFileText = this.language.instant('DASHBOARD.TOUR-GUIDE.IMPORT-DMP');
this.dashboardTour.steps[1].title = importFileText;
}
public setDashboardStartWizardText(): void {
2023-12-05 21:36:00 +01:00
const startWizardText = this.language.instant('DASHBOARD.TOUR-GUIDE.START-WIZARD');
this.dashboardTour.steps[2].title = startWizardText;
}
2023-12-05 21:36:00 +01:00
public setDescriptionText(): void {
2024-03-21 19:57:51 +01:00
const descriptionText = this.language.instant('DASHBOARD.TOUR-GUIDE.DESCRIPTION') + '\n\n' +
this.language.instant('DASHBOARD.TOUR-GUIDE.NEW-DESCRIPTION');
2023-12-05 21:36:00 +01:00
this.dashboardTour.steps[3].title = descriptionText;
}
openDashboardTour() {
this.setDashboardTourDmpText();
this.setDashboardImportFileText();
this.setDashboardStartWizardText();
2023-12-05 21:36:00 +01:00
this.setDescriptionText();
this.guidedTourService.startTour(this.dashboardTour);
}
2024-03-20 17:06:05 +01:00
dismissIntroCard() {
this.isIntroCardVisible = false;
}
dismissNewReleaseNotification() {
this.cookieService.set('new-release-dismiss-' + this.configurationService.newReleaseNotificationVersionCode, 'true', 5000, null, null, false, 'Lax');
this.newReleaseNotificationVisible = false;
}
isNewReleaseNotificationVisible() {
if (this.configurationService.newReleaseNotificationVersionCode == null) {
return false;
}
if (this.configurationService.newReleaseNotificationExpires == null && this.configurationService.newReleaseNotificationLink == null) {
return false;
}
if (this.configurationService.newReleaseNotificationExpires != null && moment(this.configurationService.newReleaseNotificationExpires).tz('UTC') < moment.utc()) {
return false;
}
if (this.cookieService.get('new-release-dismiss-' + this.configurationService.newReleaseNotificationVersionCode) === 'true') {
return false;
}
return true;
}
2019-01-18 18:03:45 +01:00
}