mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-7757] Subscriptions porting (wip)
This commit is contained in:
@@ -188,25 +188,44 @@ export class SubscriptionModalComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentSubscription && someCheckboxSelected) {
|
if (currentSubscription) {
|
||||||
console.log('UPDATE');
|
const subscriptionsToBeRemobed = this.subscriptions?.filter(
|
||||||
this.subscriptionService.updateSubscription(body, this.ePersonId, this.dso.uuid).pipe(
|
(s) => s.subscriptionType === type && s.id !== currentSubscription.id
|
||||||
getFirstCompletedRemoteData(),
|
);
|
||||||
).subscribe((res) => {
|
for (let s of subscriptionsToBeRemobed) {
|
||||||
|
this.subscriptionService.deleteSubscription(currentSubscription.id).pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
).subscribe((res) => {
|
||||||
if (res.hasSucceeded) {
|
if (res.hasSucceeded) {
|
||||||
this.notifySuccess();
|
console.warn(`An additional subscription with type=${type} and id=${s.id} has been removed`);
|
||||||
this.activeModal.close();
|
|
||||||
} else {
|
} else {
|
||||||
this.notifyFailure();
|
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) {
|
} else if (currentSubscription && !someCheckboxSelected) {
|
||||||
console.log('DELETE');
|
// Delete the existing subscription
|
||||||
this.subscriptionService.deleteSubscription(currentSubscription.id).subscribe(console.log);
|
this.subscriptionService.deleteSubscription(currentSubscription.id).subscribe(console.log);
|
||||||
|
// TODO handle notifications
|
||||||
} else if (someCheckboxSelected) {
|
} else if (someCheckboxSelected) {
|
||||||
console.log('CREATE');
|
// Create a new subscription
|
||||||
this.subscriptionService.createSubscription(body, this.ePersonId, this.dso.uuid).subscribe(console.log);
|
this.subscriptionService.createSubscription(body, this.ePersonId, this.dso.uuid).subscribe(console.log);
|
||||||
|
// TODO handle notifications
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
<ds-pagination
|
<ds-pagination
|
||||||
*ngIf="subscriptions?.pageInfo?.totalElements > 0 && !(loading$ | async)"
|
*ngIf="subscriptions?.pageInfo?.totalElements > 0 && !(loading$ | async)"
|
||||||
[paginationOptions]="config"
|
[paginationOptions]="config"
|
||||||
[pageInfoState]="subscriptions?.pageInfo"
|
[pageInfoState]="obs(subscriptions?.pageInfo)"
|
||||||
[collectionSize]="subscriptions?.pageInfo?.totalPages"
|
[collectionSize]="subscriptions?.pageInfo?.totalPages"
|
||||||
[hideGear]="true"
|
[hideGear]="true"
|
||||||
[hidePagerWhenSinglePage]="true">
|
[hidePagerWhenSinglePage]="true">
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { BehaviorSubject, Subscription as rxSubscription } from 'rxjs';
|
import { BehaviorSubject, combineLatestWith, Observable, of, shareReplay, Subscription as rxSubscription } from 'rxjs';
|
||||||
import { switchMap, take } from 'rxjs/operators';
|
import { combineLatest, map, switchMap, take, tap } from 'rxjs/operators';
|
||||||
import { Subscription } from '../shared/subscriptions/models/subscription.model';
|
import { Subscription } from '../shared/subscriptions/models/subscription.model';
|
||||||
import { buildPaginatedList, PaginatedList } from '../core/data/paginated-list.model';
|
import { buildPaginatedList, PaginatedList } from '../core/data/paginated-list.model';
|
||||||
import { SubscriptionService } from '../shared/subscriptions/subscription.service';
|
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 { PageInfo } from '../core/shared/page-info.model';
|
||||||
import { AuthService } from '../core/auth/auth.service';
|
import { AuthService } from '../core/auth/auth.service';
|
||||||
import { EPerson } from '../core/eperson/models/eperson.model';
|
import { EPerson } from '../core/eperson/models/eperson.model';
|
||||||
|
import { getFirstSucceededRemoteDataPayload } from '../core/shared/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-subscriptions-page',
|
selector: 'ds-subscriptions-page',
|
||||||
@@ -42,10 +43,12 @@ export class SubscriptionsPageComponent implements OnInit, OnDestroy {
|
|||||||
*/
|
*/
|
||||||
loading$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
loading$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||||
|
|
||||||
|
ePersonId$: Observable<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EPerson id of the logged in user
|
* EPerson id of the logged in user
|
||||||
*/
|
*/
|
||||||
eperson: string;
|
// ePersonId: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private paginationService: PaginationService,
|
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
|
* When page is changed it will request the new subscriptions for the new page config
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.authService.getAuthenticatedUserFromStore().pipe(take(1)).subscribe( (eperson: EPerson) => {
|
this.ePersonId$ = this.authService.getAuthenticatedUserFromStore().pipe(
|
||||||
this.eperson = eperson.id;
|
take(1),
|
||||||
|
map((ePerson: EPerson) => ePerson.id),
|
||||||
this.sub = this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
|
shareReplay(),
|
||||||
switchMap((findListOptions) => {
|
/*tap((ePersonId: string) => { // TODO unused
|
||||||
this.loading$.next(true);
|
this.ePersonId = ePersonId;
|
||||||
return this.subscriptionService.findByEPerson(this.eperson,{
|
}),*/
|
||||||
currentPage: findListOptions.currentPage,
|
);
|
||||||
elementsPerPage: findListOptions.pageSize
|
const currentPagination$ = this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
|
||||||
});
|
tap(console.log),
|
||||||
}
|
combineLatestWith(this.ePersonId$),
|
||||||
)
|
tap(() => {this.loading$.next(true);}),
|
||||||
).subscribe({
|
switchMap(([currentPagination, ePersonId]) => this.subscriptionService.findByEPerson(ePersonId,{
|
||||||
next: (res: any) => {
|
currentPage: currentPagination.currentPage,
|
||||||
this.subscriptions$.next(res);
|
elementsPerPage: currentPagination.pageSize
|
||||||
this.loading$.next(false);
|
})),
|
||||||
},
|
tap((x) => console.log('find', x)),
|
||||||
error: () => {
|
// getFirstSucceededRemoteDataPayload(),
|
||||||
this.loading$.next(false);
|
).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
|
* When an action is made and the information is changed refresh the information
|
||||||
*/
|
*/
|
||||||
refresh(): void {
|
refresh(): void {
|
||||||
this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
|
/*this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
|
||||||
take(1),
|
take(1),
|
||||||
switchMap((findListOptions) => {
|
switchMap((findListOptions) => {
|
||||||
this.loading$.next(true);
|
this.loading$.next(true);
|
||||||
return this.subscriptionService.findByEPerson(this.eperson,{
|
return this.subscriptionService.findByEPerson(this.ePersonId,{
|
||||||
currentPage: findListOptions.currentPage,
|
currentPage: findListOptions.currentPage,
|
||||||
elementsPerPage: findListOptions.pageSize
|
elementsPerPage: findListOptions.pageSize
|
||||||
});
|
});
|
||||||
@@ -104,7 +112,7 @@ export class SubscriptionsPageComponent implements OnInit, OnDestroy {
|
|||||||
error: () => {
|
error: () => {
|
||||||
this.loading$.next(false);
|
this.loading$.next(false);
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,4 +122,8 @@ export class SubscriptionsPageComponent implements OnInit, OnDestroy {
|
|||||||
this.sub.unsubscribe();
|
this.sub.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obs(v) {
|
||||||
|
return of(v);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2915,6 +2915,8 @@
|
|||||||
|
|
||||||
"nav.stop-impersonating": "Stop impersonating EPerson",
|
"nav.stop-impersonating": "Stop impersonating EPerson",
|
||||||
|
|
||||||
|
"nav.subscriptions" : "Subscriptions",
|
||||||
|
|
||||||
"nav.toggle" : "Toggle navigation",
|
"nav.toggle" : "Toggle navigation",
|
||||||
|
|
||||||
"nav.user.description" : "User profile bar",
|
"nav.user.description" : "User profile bar",
|
||||||
@@ -4492,6 +4494,36 @@
|
|||||||
"submission.workspace.generic.view-help": "Select this option to view the item's metadata.",
|
"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.alt": "Thumbnail Image",
|
||||||
|
|
||||||
"thumbnail.default.placeholder": "No Thumbnail Available",
|
"thumbnail.default.placeholder": "No Thumbnail Available",
|
||||||
|
Reference in New Issue
Block a user