[CST-5674] Enable ePerson/Group editing; prevent switching between ePerson and Group

This commit is contained in:
Davide Negretti
2022-04-29 12:17:48 +02:00
parent e94454be97
commit 342a62081c
3 changed files with 43 additions and 31 deletions

View File

@@ -7,16 +7,16 @@
[displayCancel]="false"></ds-form> [displayCancel]="false"></ds-form>
<div class="container-fluid"> <div class="container-fluid">
<label for="ResourcePolicyObject">{{'resource-policies.form.eperson-group-list.label' | translate}}</label> <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"> <input id="ResourcePolicyObject" class="form-control mb-3" type="text" [value]="resourcePolicyTargetName$ | async">
<ng-container *ngIf="canSetGrant()"> <ng-container>
<ul ngbNav #nav="ngbNav" class="nav-pills"> <ul ngbNav #nav="ngbNav" class="nav-pills" [(activeId)]="navActiveId" (navChange)="onNavChange($event)">
<li ngbNavItem> <li [ngbNavItem]="'eperson'">
<a ngbNavLink>{{'resource-policies.form.eperson-group-list.tab.eperson' | translate}}</a> <a ngbNavLink>{{'resource-policies.form.eperson-group-list.tab.eperson' | translate}}</a>
<ng-template ngbNavContent> <ng-template ngbNavContent>
<ds-eperson-group-list (select)="updateObjectSelected($event, true)"></ds-eperson-group-list> <ds-eperson-group-list (select)="updateObjectSelected($event, true)"></ds-eperson-group-list>
</ng-template> </ng-template>
</li> </li>
<li ngbNavItem> <li [ngbNavItem]="'group'">
<a ngbNavLink>{{'resource-policies.form.eperson-group-list.tab.group' | translate}}</a> <a ngbNavLink>{{'resource-policies.form.eperson-group-list.tab.group' | translate}}</a>
<ng-template ngbNavContent> <ng-template ngbNavContent>
<ds-eperson-group-list [isListOfEPerson]="false" <ds-eperson-group-list [isListOfEPerson]="false"

View File

@@ -266,7 +266,7 @@ describe('ResourcePolicyFormComponent test suite', () => {
}); });
it('should can set grant', () => { it('should can set grant', () => {
expect(comp.canSetGrant()).toBeTruthy(); expect(comp.isBeingEdited()).toBeTruthy();
}); });
it('should not have a target name', () => { it('should not have a target name', () => {
@@ -344,7 +344,7 @@ describe('ResourcePolicyFormComponent test suite', () => {
}); });
it('should not can set grant', () => { it('should not can set grant', () => {
expect(comp.canSetGrant()).toBeFalsy(); expect(comp.isBeingEdited()).toBeFalsy();
}); });
it('should have a target name', () => { it('should have a target name', () => {

View File

@@ -41,6 +41,7 @@ import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
import { GroupDataService } from '../../../core/eperson/group-data.service'; import { GroupDataService } from '../../../core/eperson/group-data.service';
import { getFirstSucceededRemoteData } from '../../../core/shared/operators'; import { getFirstSucceededRemoteData } from '../../../core/shared/operators';
import { RequestService } from '../../../core/data/request.service'; import { RequestService } from '../../../core/data/request.service';
import { NgbNavChangeEvent } from '@ng-bootstrap/ng-bootstrap';
export interface ResourcePolicyEvent { export interface ResourcePolicyEvent {
object: ResourcePolicy; object: ResourcePolicy;
@@ -125,6 +126,8 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
*/ */
private subs: Subscription[] = []; private subs: Subscription[] = [];
navActiveId: string;
/** /**
* Initialize instance variables * Initialize instance variables
* *
@@ -151,7 +154,6 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
this.formId = this.formService.getUniqueId('resource-policy-form'); this.formId = this.formService.getUniqueId('resource-policy-form');
this.formModel = this.buildResourcePolicyForm(); this.formModel = this.buildResourcePolicyForm();
if (!this.canSetGrant()) {
const epersonRD$ = this.ePersonService.findByHref(this.resourcePolicy._links.eperson.href, false).pipe( const epersonRD$ = this.ePersonService.findByHref(this.resourcePolicy._links.eperson.href, false).pipe(
getFirstSucceededRemoteData() getFirstSucceededRemoteData()
); );
@@ -169,11 +171,11 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
filter(() => this.isActive), filter(() => this.isActive),
).subscribe((dsoRD: RemoteData<DSpaceObject>) => { ).subscribe((dsoRD: RemoteData<DSpaceObject>) => {
this.resourcePolicyGrant = dsoRD.payload; this.resourcePolicyGrant = dsoRD.payload;
this.navActiveId = String(dsoRD.payload.type);
this.resourcePolicyTargetName$.next(this.getResourcePolicyTargetName()); this.resourcePolicyTargetName$.next(this.getResourcePolicyTargetName());
}) })
); );
} }
}
/** /**
* Method to check if the form status is valid or not * 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 * @return true if is possible, false otherwise
*/ */
canSetGrant(): boolean { isBeingEdited(): boolean {
return isEmpty(this.resourcePolicy); return !isEmpty(this.resourcePolicy);
} }
/** /**
@@ -330,4 +332,14 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
.filter((subscription) => hasValue(subscription)) .filter((subscription) => hasValue(subscription))
.forEach((subscription) => subscription.unsubscribe()); .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
}
}
} }