[CST-7757] Subscriptions porting (wip)

This commit is contained in:
Davide Negretti
2022-12-23 18:25:04 +01:00
parent 3ab552ed38
commit a6cd39c906
4 changed files with 101 additions and 38 deletions

View File

@@ -188,25 +188,44 @@ export class SubscriptionModalComponent implements OnInit {
}
}
if (currentSubscription && someCheckboxSelected) {
console.log('UPDATE');
this.subscriptionService.updateSubscription(body, this.ePersonId, this.dso.uuid).pipe(
getFirstCompletedRemoteData(),
).subscribe((res) => {
if (currentSubscription) {
const subscriptionsToBeRemobed = this.subscriptions?.filter(
(s) => s.subscriptionType === type && s.id !== currentSubscription.id
);
for (let s of subscriptionsToBeRemobed) {
this.subscriptionService.deleteSubscription(currentSubscription.id).pipe(
getFirstCompletedRemoteData(),
).subscribe((res) => {
if (res.hasSucceeded) {
this.notifySuccess();
this.activeModal.close();
console.warn(`An additional subscription with type=${type} and id=${s.id} has been removed`);
} else {
this.notifyFailure();
}
});
}
}
if (currentSubscription && someCheckboxSelected) {
// Update the existing subscription
this.subscriptionService.updateSubscription(body, this.ePersonId, this.dso.uuid).pipe(
getFirstCompletedRemoteData(),
).subscribe((res) => {
if (res.hasSucceeded) {
this.notifySuccess();
this.activeModal.close();
} else {
this.notifyFailure();
}
);
});
} else if (currentSubscription && !someCheckboxSelected) {
console.log('DELETE');
// Delete the existing subscription
this.subscriptionService.deleteSubscription(currentSubscription.id).subscribe(console.log);
// TODO handle notifications
} else if (someCheckboxSelected) {
console.log('CREATE');
// Create a new subscription
this.subscriptionService.createSubscription(body, this.ePersonId, this.dso.uuid).subscribe(console.log);
// TODO handle notifications
}

View File

@@ -10,7 +10,7 @@
<ds-pagination
*ngIf="subscriptions?.pageInfo?.totalElements > 0 && !(loading$ | async)"
[paginationOptions]="config"
[pageInfoState]="subscriptions?.pageInfo"
[pageInfoState]="obs(subscriptions?.pageInfo)"
[collectionSize]="subscriptions?.pageInfo?.totalPages"
[hideGear]="true"
[hidePagerWhenSinglePage]="true">

View File

@@ -1,6 +1,6 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { BehaviorSubject, Subscription as rxSubscription } from 'rxjs';
import { switchMap, take } from 'rxjs/operators';
import { BehaviorSubject, combineLatestWith, Observable, of, shareReplay, Subscription as rxSubscription } from 'rxjs';
import { combineLatest, map, switchMap, take, tap } from 'rxjs/operators';
import { Subscription } from '../shared/subscriptions/models/subscription.model';
import { buildPaginatedList, PaginatedList } from '../core/data/paginated-list.model';
import { SubscriptionService } from '../shared/subscriptions/subscription.service';
@@ -9,6 +9,7 @@ import { PaginationService } from '../core/pagination/pagination.service';
import { PageInfo } from '../core/shared/page-info.model';
import { AuthService } from '../core/auth/auth.service';
import { EPerson } from '../core/eperson/models/eperson.model';
import { getFirstSucceededRemoteDataPayload } from '../core/shared/operators';
@Component({
selector: 'ds-subscriptions-page',
@@ -42,10 +43,12 @@ export class SubscriptionsPageComponent implements OnInit, OnDestroy {
*/
loading$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
ePersonId$: Observable<string>;
/**
* EPerson id of the logged in user
*/
eperson: string;
// ePersonId: string;
constructor(
private paginationService: PaginationService,
@@ -58,27 +61,32 @@ export class SubscriptionsPageComponent implements OnInit, OnDestroy {
* When page is changed it will request the new subscriptions for the new page config
*/
ngOnInit(): void {
this.authService.getAuthenticatedUserFromStore().pipe(take(1)).subscribe( (eperson: EPerson) => {
this.eperson = eperson.id;
this.sub = this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
switchMap((findListOptions) => {
this.loading$.next(true);
return this.subscriptionService.findByEPerson(this.eperson,{
currentPage: findListOptions.currentPage,
elementsPerPage: findListOptions.pageSize
});
}
)
).subscribe({
next: (res: any) => {
this.subscriptions$.next(res);
this.loading$.next(false);
},
error: () => {
this.loading$.next(false);
}
});
this.ePersonId$ = this.authService.getAuthenticatedUserFromStore().pipe(
take(1),
map((ePerson: EPerson) => ePerson.id),
shareReplay(),
/*tap((ePersonId: string) => { // TODO unused
this.ePersonId = ePersonId;
}),*/
);
const currentPagination$ = this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
tap(console.log),
combineLatestWith(this.ePersonId$),
tap(() => {this.loading$.next(true);}),
switchMap(([currentPagination, ePersonId]) => this.subscriptionService.findByEPerson(ePersonId,{
currentPage: currentPagination.currentPage,
elementsPerPage: currentPagination.pageSize
})),
tap((x) => console.log('find', x)),
// getFirstSucceededRemoteDataPayload(),
).subscribe({
next: (res: any) => {
this.subscriptions$.next(res);
this.loading$.next(false);
},
error: () => {
this.loading$.next(false);
}
});
}
@@ -86,11 +94,11 @@ export class SubscriptionsPageComponent implements OnInit, OnDestroy {
* When an action is made and the information is changed refresh the information
*/
refresh(): void {
this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
/*this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
take(1),
switchMap((findListOptions) => {
this.loading$.next(true);
return this.subscriptionService.findByEPerson(this.eperson,{
return this.subscriptionService.findByEPerson(this.ePersonId,{
currentPage: findListOptions.currentPage,
elementsPerPage: findListOptions.pageSize
});
@@ -104,7 +112,7 @@ export class SubscriptionsPageComponent implements OnInit, OnDestroy {
error: () => {
this.loading$.next(false);
}
});
});*/
}
/**
@@ -114,4 +122,8 @@ export class SubscriptionsPageComponent implements OnInit, OnDestroy {
this.sub.unsubscribe();
}
obs(v) {
return of(v);
}
}

View File

@@ -2915,6 +2915,8 @@
"nav.stop-impersonating": "Stop impersonating EPerson",
"nav.subscriptions" : "Subscriptions",
"nav.toggle" : "Toggle navigation",
"nav.user.description" : "User profile bar",
@@ -4492,6 +4494,36 @@
"submission.workspace.generic.view-help": "Select this option to view the item's metadata.",
"subscriptions.title": "Subscriptions",
"subscriptions.item": "Subscriptions for items",
"subscriptions.collection": "Subscriptions for collections",
"subscriptions.community": "Subscriptions for communities",
"subscriptions.subscription_type": "Subscription type",
"subscriptions.frequency": "Subscription frequency",
"subscriptions.frequency.D": "Daily",
"subscriptions.frequency.M": "Monthly",
"subscriptions.frequency.W": "Weekly",
"subscriptions.table.dso": "Subject",
"subscriptions.table.subscription_type": "Subscription Type",
"subscriptions.table.subscription_frequency": "Subscription Frequency",
"subscriptions.table.action": "Action",
"subscriptions.table.empty.message": "You have not subscribed any notification yet. To subscribe notification about an object please use the contextual menu in the object detail view",
"thumbnail.default.alt": "Thumbnail Image",
"thumbnail.default.placeholder": "No Thumbnail Available",