mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
Intermediate commit
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { first, map, take } from 'rxjs/operators';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
import { ResourcePolicyService } from '../../../core/resource-policy/resource-policy.service';
|
||||
import { NotificationsService } from '../../notifications/notifications.service';
|
||||
@@ -9,6 +11,7 @@ import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { ResourcePolicy } from '../../../core/resource-policy/models/resource-policy.model';
|
||||
import { ResourcePolicyEvent } from '../form/resource-policy-form';
|
||||
import { ITEM_EDIT_AUTHORIZATIONS_PATH } from '../../../+item-page/edit-item-page/edit-item-page.routing.module';
|
||||
import { RESOURCE_POLICY } from '../../../core/resource-policy/models/resource-policy.resource-type';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-resource-policy-edit',
|
||||
@@ -21,11 +24,18 @@ export class ResourcePolicyEditComponent implements OnInit {
|
||||
*/
|
||||
public resourcePolicy: ResourcePolicy;
|
||||
|
||||
/**
|
||||
* A boolean representing if a submission editing operation is pending
|
||||
* @type {BehaviorSubject<boolean>}
|
||||
*/
|
||||
private processing$ = new BehaviorSubject<boolean>(false);
|
||||
|
||||
constructor(
|
||||
private notificationsService: NotificationsService,
|
||||
private resourcePolicyService: ResourcePolicyService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
private router: Router,
|
||||
private translate: TranslateService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -34,26 +44,33 @@ export class ResourcePolicyEditComponent implements OnInit {
|
||||
take(1)
|
||||
).subscribe((data: any) => {
|
||||
this.resourcePolicy = (data.resourcePolicy as RemoteData<ResourcePolicy>).payload;
|
||||
console.log(data)
|
||||
});
|
||||
}
|
||||
|
||||
isProcessing(): Observable<boolean> {
|
||||
return this.processing$.asObservable();
|
||||
}
|
||||
|
||||
redirectToAuthorizationsPage() {
|
||||
this.router.navigate([`../../${ITEM_EDIT_AUTHORIZATIONS_PATH}`], { relativeTo: this.route });
|
||||
}
|
||||
|
||||
updateResourcePolicy(event: ResourcePolicyEvent) {
|
||||
this.processing$.next(true);
|
||||
const updatedObject = Object.assign({}, event.object, {
|
||||
id: this.resourcePolicy.id,
|
||||
type: RESOURCE_POLICY.value,
|
||||
_links: this.resourcePolicy._links
|
||||
});
|
||||
this.resourcePolicyService.update(updatedObject).pipe(
|
||||
first((response: RemoteData<ResourcePolicy>) => !response.isResponsePending)
|
||||
).subscribe((responseRD: RemoteData<ResourcePolicy>) => {
|
||||
this.processing$.next(false);
|
||||
if (responseRD.hasSucceeded) {
|
||||
this.notificationsService.success(null, 'resource-policies.edit.page.success.content');
|
||||
this.notificationsService.success(null, this.translate.get('resource-policies.edit.page.success.content'));
|
||||
this.redirectToAuthorizationsPage();
|
||||
} else {
|
||||
this.notificationsService.error(null, 'resource-policies.edit.page.failure.content');
|
||||
this.notificationsService.error(null, this.translate.get('resource-policies.edit.page.failure.content'));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user