argos/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.comp...

194 lines
9.7 KiB
TypeScript
Raw Normal View History

2023-10-25 16:47:48 +02:00
import { Location } from '@angular/common';
2023-12-05 21:36:00 +01:00
import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormControl } from '@angular/forms';
2023-10-25 16:47:48 +02:00
import { ActivatedRoute, Router } from '@angular/router';
import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order';
2023-12-05 21:36:00 +01:00
import { RecentActivityItem } from '@app/core/model/dashboard/recent-activity-item';
import { DescriptionTemplate } from '@app/core/model/description-template/description-template';
import { Description } from '@app/core/model/description/description';
import { Dmp, DmpUser } from '@app/core/model/dmp/dmp';
import { FileFormat } from '@app/core/model/file/file-format.model';
2023-12-05 21:36:00 +01:00
import { DmpReference, Reference } from '@app/core/model/reference/reference';
import { RecentActivityItemLookup } from '@app/core/query/recent-activity-item-lookup.lookup';
import { AuthService } from '@app/core/services/auth/auth.service';
2023-10-25 16:47:48 +02:00
import { DashboardService } from '@app/core/services/dashboard/dashboard.service';
import { DmpServiceNew } from '@app/core/services/dmp/dmp.service';
2023-10-25 16:47:48 +02:00
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
2023-10-25 16:47:48 +02:00
import { BaseComponent } from '@common/base/base.component';
2023-12-05 21:36:00 +01:00
import { debounceTime, takeUntil } from 'rxjs/operators';
2023-10-25 16:47:48 +02:00
import { nameof } from 'ts-simple-nameof';
2019-04-24 11:26:53 +02:00
@Component({
2019-04-25 11:03:22 +02:00
selector: 'app-recent-edited-activity',
templateUrl: './recent-edited-activity.component.html',
styleUrls: ['./recent-edited-activity.component.css']
2019-04-24 11:26:53 +02:00
})
export class RecentEditedActivityComponent extends BaseComponent implements OnInit {
2020-07-02 18:34:27 +02:00
2023-12-05 21:36:00 +01:00
lookup: RecentActivityItemLookup = new RecentActivityItemLookup();
2020-07-02 18:34:27 +02:00
pageSize: number = 5;
2023-12-05 21:36:00 +01:00
listingItems: RecentActivityItem[];
fileFormats: FileFormat[] = [];
2023-12-05 21:36:00 +01:00
2023-10-05 15:39:17 +02:00
public formGroup = new UntypedFormBuilder().group({
like: new UntypedFormControl(),
order: new UntypedFormControl()
2020-07-10 15:52:35 +02:00
});
2020-08-03 10:40:38 +02:00
publicMode = false;
2019-04-24 11:26:53 +02:00
2020-07-13 12:01:03 +02:00
order = RecentActivityOrder;
2023-12-05 21:36:00 +01:00
totalCount: number;
startIndex: number = 0;
offsetLess: number = 0;
page: number = 1;
@Input() isActive: boolean = false;
2019-04-25 11:03:22 +02:00
constructor(
private route: ActivatedRoute,
private router: Router,
2019-04-25 11:03:22 +02:00
public enumUtils: EnumUtils,
private authentication: AuthService,
2020-07-02 18:34:27 +02:00
private dashboardService: DashboardService,
private location: Location,
private matomoService: MatomoService,
private dmpServiceNew: DmpServiceNew
) {
super();
}
2019-04-24 11:26:53 +02:00
2019-04-25 11:03:22 +02:00
ngOnInit() {
2023-12-05 21:36:00 +01:00
this.matomoService.trackPageView('Recent DMP Activity');
this.route.queryParams.subscribe(params => {
2023-10-25 16:47:48 +02:00
if (this.isActive) {
let page = (params['page'] === undefined) ? 1 : +params['page'];
this.page = (page <= 0) ? 1 : page;
2023-12-05 21:36:00 +01:00
this.startIndex = (this.page - 1) * this.pageSize;
2023-10-25 16:47:48 +02:00
if (this.page > 1) {
this.offsetLess = (this.page - 2) * this.pageSize;
}
let order = params['order'];
if (this.isAuthenticated()) {
2023-12-05 21:36:00 +01:00
if (order === undefined || (order != this.order.UpdatedAt && order != this.order.Label && order != this.order.Status)) {
order = this.order.UpdatedAt;
}
} else {
2023-10-25 16:47:48 +02:00
if (order === undefined || (order != this.order.PUBLISHED && order != this.order.LABEL)) {
order = this.order.PUBLISHED;
}
}
this.formGroup.get('order').setValue(order);
let keyword = (params['keyword'] === undefined || params['keyword'].length <= 0) ? "" : params['keyword'];
this.formGroup.get("like").setValue(keyword);
this.updateUrl();
}
});
this.dmpServiceNew.getExportFormats().pipe(takeUntil(this._destroyed)).subscribe(result => this.fileFormats = result);
2019-04-25 11:03:22 +02:00
if (this.isAuthenticated()) {
2023-12-05 21:36:00 +01:00
this.refresh();
2020-07-10 15:52:35 +02:00
}
2019-04-25 11:03:22 +02:00
}
ngOnChanges() {
2023-10-25 16:47:48 +02:00
if (this.isActive) {
this.updateUrl();
}
}
updateUrl() {
2023-12-05 21:36:00 +01:00
let parameters = "?type=dmps" +
(this.page != 1 ? "&page=" + this.page : "") +
(((this.formGroup.get("order").value != this.order.MODIFIED && !this.publicMode) || (this.formGroup.get("order").value != this.order.PUBLISHED && this.publicMode)) ? "&order=" + this.formGroup.get("order").value : "") +
(this.formGroup.get("like").value ? ("&keyword=" + this.formGroup.get("like").value) : "");
2023-10-25 16:47:48 +02:00
this.location.go(this.router.url.split('?')[0] + parameters);
}
2019-04-25 11:03:22 +02:00
public isAuthenticated(): boolean {
2023-10-11 16:53:12 +02:00
return this.authentication.currentAccountIsAuthenticated();
2019-04-25 11:03:22 +02:00
}
2019-04-24 11:26:53 +02:00
2020-07-10 15:52:35 +02:00
refresh(): void {
2023-12-05 21:36:00 +01:00
if (!this.formGroup.get('order').value) {
this.formGroup.get('order').setValue(this.order.UpdatedAt);
}
this.lookup.page = { size: this.pageSize, offset: 0 };
this.lookup.orderField = this.formGroup.get('order').value;
this.lookup.like = this.formGroup.get('like').value;
this.lookup.project = {
fields: [
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.status)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.accessType)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.version)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.groupId)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.updatedAt)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.user.id)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.role)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.status)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.updatedAt)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.descriptionTemplate), nameof<DescriptionTemplate>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.descriptionTemplate), nameof<DescriptionTemplate>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.descriptionTemplate), nameof<DescriptionTemplate>(x => x.groupId)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.accessType)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.user.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.role)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.type)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.reference)].join('.'),
]
};
2020-07-10 15:52:35 +02:00
this.dashboardService
2023-12-05 21:36:00 +01:00
.getMyRecentActivityItems(this.lookup)
.pipe(takeUntil(this._destroyed))
2020-07-10 15:52:35 +02:00
.subscribe(response => {
2023-12-05 21:36:00 +01:00
this.listingItems = response;
//this.totalCount = response.totalCount;
2020-07-02 18:34:27 +02:00
2023-12-05 21:36:00 +01:00
//this.totalCountDmps.emit(this.dmpActivities.length);
// if (this.totalCount > 0 && this.totalCount <= (this.page - 1) * this.pageSize && this.page > 1) {
// let queryParams = { type: "dmps", page: 1, order: this.formGroup.get("order").value };
// if (this.formGroup.get("like").value) {
// queryParams['keyword'] = this.formGroup.get("like").value;
// }
// this.router.navigate(["/home"], { queryParams: queryParams })
// }
2023-12-05 21:36:00 +01:00
// this.totalCount < this.pageSize ? this.totalCountDmps.emit(response.totalCount) : this.totalCountDmps.emit(this.pageSize);
// this.totalCountDmps.emit(this.totalCount);
// this.dmpActivities.forEach(dmpActivity => {
// const recentActivity: RecentActivity = {
// activityData: dmpActivity,
// activityType: RecentActivityType.Dmp
// };
// this.allRecentActivities.push(recentActivity)
// })
});
this.formGroup.get('like').valueChanges
.pipe(takeUntil(this._destroyed), debounceTime(500))
.subscribe(x => this.refresh());
this.formGroup.get('order').valueChanges
.pipe(takeUntil(this._destroyed))
.subscribe(x => this.refresh());
}
2019-04-24 11:26:53 +02:00
}