2023-12-05 21:36:00 +01:00
|
|
|
import { Location } from '@angular/common';
|
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { UntypedFormBuilder, UntypedFormControl } from '@angular/forms';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order';
|
|
|
|
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';
|
2023-12-28 16:18:49 +01:00
|
|
|
import { DmpReference } from '@app/core/model/dmp/dmp-reference';
|
|
|
|
import { Reference } from '@app/core/model/reference/reference';
|
2023-12-05 21:36:00 +01:00
|
|
|
import { DescriptionLookup } from '@app/core/query/description.lookup';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
|
|
|
import { DescriptionService } from '@app/core/services/description/description.service';
|
|
|
|
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { debounceTime, takeUntil } from 'rxjs/operators';
|
|
|
|
import { nameof } from 'ts-simple-nameof';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-recent-edited-description-activity',
|
|
|
|
templateUrl: './recent-edited-description-activity.component.html',
|
|
|
|
styleUrls: ['./recent-edited-description-activity.component.scss']
|
|
|
|
})
|
|
|
|
export class RecentEditedDescriptionActivityComponent extends BaseComponent implements OnInit {
|
|
|
|
|
|
|
|
lookup: DescriptionLookup = new DescriptionLookup();
|
|
|
|
pageSize: number = 5;
|
|
|
|
listingItems: Description[];
|
|
|
|
|
|
|
|
|
|
|
|
public formGroup = new UntypedFormBuilder().group({
|
|
|
|
like: new UntypedFormControl(),
|
|
|
|
order: new UntypedFormControl()
|
|
|
|
});
|
|
|
|
publicMode = false;
|
|
|
|
|
|
|
|
order = RecentActivityOrder;
|
|
|
|
|
|
|
|
totalCount: number;
|
|
|
|
startIndex: number = 0;
|
|
|
|
offsetLess: number = 0;
|
|
|
|
page: number = 1;
|
|
|
|
@Input() isActive: boolean = false;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
private authentication: AuthService,
|
|
|
|
private descriptionService: DescriptionService,
|
|
|
|
private location: Location,
|
|
|
|
private matomoService: MatomoService
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.matomoService.trackPageView('Recent DMP Activity');
|
|
|
|
this.route.queryParams.subscribe(params => {
|
|
|
|
if (this.isActive) {
|
|
|
|
let page = (params['page'] === undefined) ? 1 : +params['page'];
|
|
|
|
this.page = (page <= 0) ? 1 : page;
|
|
|
|
|
|
|
|
this.startIndex = (this.page - 1) * this.pageSize;
|
|
|
|
if (this.page > 1) {
|
|
|
|
this.offsetLess = (this.page - 2) * this.pageSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
let order = params['order'];
|
|
|
|
if (this.isAuthenticated()) {
|
|
|
|
if (order === undefined || (order != this.order.UpdatedAt && order != this.order.Label && order != this.order.Status)) {
|
|
|
|
order = this.order.UpdatedAt;
|
|
|
|
}
|
|
|
|
} else {
|
2023-12-29 16:04:16 +01:00
|
|
|
//TODO refactor
|
|
|
|
// if (order === undefined || (order != this.order.PUBLISHED && order != this.order.LABEL)) {
|
|
|
|
// order = this.order.PUBLISHED;
|
|
|
|
// }
|
2023-12-05 21:36:00 +01:00
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (this.isAuthenticated()) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges() {
|
|
|
|
if (this.isActive) {
|
|
|
|
this.updateUrl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateUrl() {
|
|
|
|
let parameters = "?type=dmps" +
|
|
|
|
(this.page != 1 ? "&page=" + this.page : "") +
|
2023-12-29 16:04:16 +01:00
|
|
|
//TODO refactor
|
|
|
|
//(((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 : "") +
|
2023-12-05 21:36:00 +01:00
|
|
|
(this.formGroup.get("like").value ? ("&keyword=" + this.formGroup.get("like").value) : "");
|
|
|
|
this.location.go(this.router.url.split('?')[0] + parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
public isAuthenticated(): boolean {
|
|
|
|
return this.authentication.currentAccountIsAuthenticated();
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh(): void {
|
|
|
|
if (!this.formGroup.get('order').value) {
|
|
|
|
this.formGroup.get('order').setValue(this.order.UpdatedAt);
|
|
|
|
}
|
|
|
|
this.lookup.page = { size: this.pageSize, offset: 0 };
|
|
|
|
this.lookup.order = { items: ['-' + this.formGroup.get('order').value] };
|
|
|
|
this.lookup.like = this.formGroup.get('like').value;
|
|
|
|
this.lookup.project = {
|
|
|
|
|
|
|
|
fields: [
|
|
|
|
[nameof<Description>(x => x.id)].join('.'),
|
|
|
|
[nameof<Description>(x => x.label)].join('.'),
|
|
|
|
[nameof<Description>(x => x.status)].join('.'),
|
|
|
|
[nameof<Description>(x => x.updatedAt)].join('.'),
|
|
|
|
[nameof<Description>(x => x.descriptionTemplate), nameof<DescriptionTemplate>(x => x.id)].join('.'),
|
|
|
|
[nameof<Description>(x => x.descriptionTemplate), nameof<DescriptionTemplate>(x => x.label)].join('.'),
|
|
|
|
[nameof<Description>(x => x.descriptionTemplate), nameof<DescriptionTemplate>(x => x.groupId)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.id)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.label)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.accessType)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.id)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.user.id)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.role)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.id)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.id)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.label)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.type)].join('.'),
|
|
|
|
[nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.reference)].join('.'),
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.descriptionService
|
|
|
|
.query(this.lookup)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
this.listingItems = response.items;
|
|
|
|
this.totalCount = response.count;
|
|
|
|
|
|
|
|
|
|
|
|
//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 })
|
|
|
|
// }
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
}
|