mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 14:03:06 +00:00
[CST-5674] Enable ePerson/Group editing; prevent switching between ePerson and Group
This commit is contained in:
@@ -7,16 +7,16 @@
|
||||
[displayCancel]="false"></ds-form>
|
||||
<div class="container-fluid">
|
||||
<label for="ResourcePolicyObject">{{'resource-policies.form.eperson-group-list.label' | translate}}</label>
|
||||
<input id="ResourcePolicyObject" class="form-control mb-3" type="text" readonly [value]="resourcePolicyTargetName$ | async">
|
||||
<ng-container *ngIf="canSetGrant()">
|
||||
<ul ngbNav #nav="ngbNav" class="nav-pills">
|
||||
<li ngbNavItem>
|
||||
<input id="ResourcePolicyObject" class="form-control mb-3" type="text" [value]="resourcePolicyTargetName$ | async">
|
||||
<ng-container>
|
||||
<ul ngbNav #nav="ngbNav" class="nav-pills" [(activeId)]="navActiveId" (navChange)="onNavChange($event)">
|
||||
<li [ngbNavItem]="'eperson'">
|
||||
<a ngbNavLink>{{'resource-policies.form.eperson-group-list.tab.eperson' | translate}}</a>
|
||||
<ng-template ngbNavContent>
|
||||
<ds-eperson-group-list (select)="updateObjectSelected($event, true)"></ds-eperson-group-list>
|
||||
</ng-template>
|
||||
</li>
|
||||
<li ngbNavItem>
|
||||
<li [ngbNavItem]="'group'">
|
||||
<a ngbNavLink>{{'resource-policies.form.eperson-group-list.tab.group' | translate}}</a>
|
||||
<ng-template ngbNavContent>
|
||||
<ds-eperson-group-list [isListOfEPerson]="false"
|
||||
|
@@ -266,7 +266,7 @@ describe('ResourcePolicyFormComponent test suite', () => {
|
||||
});
|
||||
|
||||
it('should can set grant', () => {
|
||||
expect(comp.canSetGrant()).toBeTruthy();
|
||||
expect(comp.isBeingEdited()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not have a target name', () => {
|
||||
@@ -344,7 +344,7 @@ describe('ResourcePolicyFormComponent test suite', () => {
|
||||
});
|
||||
|
||||
it('should not can set grant', () => {
|
||||
expect(comp.canSetGrant()).toBeFalsy();
|
||||
expect(comp.isBeingEdited()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should have a target name', () => {
|
||||
|
@@ -41,6 +41,7 @@ import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
|
||||
import { GroupDataService } from '../../../core/eperson/group-data.service';
|
||||
import { getFirstSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
import { NgbNavChangeEvent } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
export interface ResourcePolicyEvent {
|
||||
object: ResourcePolicy;
|
||||
@@ -125,6 +126,8 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
private subs: Subscription[] = [];
|
||||
|
||||
navActiveId: string;
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
*
|
||||
@@ -151,7 +154,6 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
|
||||
this.formId = this.formService.getUniqueId('resource-policy-form');
|
||||
this.formModel = this.buildResourcePolicyForm();
|
||||
|
||||
if (!this.canSetGrant()) {
|
||||
const epersonRD$ = this.ePersonService.findByHref(this.resourcePolicy._links.eperson.href, false).pipe(
|
||||
getFirstSucceededRemoteData()
|
||||
);
|
||||
@@ -169,11 +171,11 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
|
||||
filter(() => this.isActive),
|
||||
).subscribe((dsoRD: RemoteData<DSpaceObject>) => {
|
||||
this.resourcePolicyGrant = dsoRD.payload;
|
||||
this.navActiveId = String(dsoRD.payload.type);
|
||||
this.resourcePolicyTargetName$.next(this.getResourcePolicyTargetName());
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if the form status is valid or not
|
||||
@@ -255,8 +257,8 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
|
||||
*
|
||||
* @return true if is possible, false otherwise
|
||||
*/
|
||||
canSetGrant(): boolean {
|
||||
return isEmpty(this.resourcePolicy);
|
||||
isBeingEdited(): boolean {
|
||||
return !isEmpty(this.resourcePolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,4 +332,14 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
|
||||
.filter((subscription) => hasValue(subscription))
|
||||
.forEach((subscription) => subscription.unsubscribe());
|
||||
}
|
||||
|
||||
onNavChange(changeEvent: NgbNavChangeEvent) {
|
||||
console.log(`CHANGE ${changeEvent.activeId} -> ${changeEvent.nextId}`);
|
||||
|
||||
if (this.isBeingEdited()) {
|
||||
// if a policy is being edited it should not be possible to switch between group and eperson
|
||||
changeEvent.preventDefault();
|
||||
// TODO add informative modal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user