94207: Extract RP entries into a separate component

This commit is contained in:
Yura Bondarenko
2022-09-02 12:21:43 +02:00
parent 47b9b09139
commit 030b1c33db
7 changed files with 394 additions and 262 deletions

View File

@@ -2,48 +2,25 @@ import { ChangeDetectorRef, Component, Input, OnDestroy, OnInit } from '@angular
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, from as observableFrom, Observable, Subscription } from 'rxjs';
import {
concatMap,
distinctUntilChanged,
filter,
map,
reduce,
scan,
startWith,
take
} from 'rxjs/operators';
import { concatMap, distinctUntilChanged, filter, map, reduce, scan, take } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
import { ResourcePolicyService } from '../../core/resource-policy/resource-policy.service';
import {
getFirstSucceededRemoteDataPayload,
getFirstSucceededRemoteDataWithNotEmptyPayload,
getAllSucceededRemoteData
} from '../../core/shared/operators';
import { getAllSucceededRemoteData } from '../../core/shared/operators';
import { ResourcePolicy } from '../../core/resource-policy/models/resource-policy.model';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { Group } from '../../core/eperson/models/group.model';
import { GroupDataService } from '../../core/eperson/group-data.service';
import { hasValue, isEmpty, isNotEmpty } from '../empty.util';
import { EPerson } from '../../core/eperson/models/eperson.model';
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
import { RequestService } from '../../core/data/request.service';
import { NotificationsService } from '../notifications/notifications.service';
import { dateToString, stringToNgbDateStruct } from '../date.util';
import { followLink } from '../utils/follow-link-config.model';
import { ACCESS_CONTROL_MODULE_PATH } from '../../app-routing-paths';
import { GROUP_EDIT_PATH } from '../../access-control/access-control-routing-paths';
interface ResourcePolicyCheckboxEntry {
id: string;
policy: ResourcePolicy;
checked: boolean;
}
import { ResourcePolicyCheckboxEntry } from './entry/resource-policy-entry.component';
@Component({
selector: 'ds-resource-policies',
styleUrls: ['./resource-policies.component.scss'],
templateUrl: './resource-policies.component.html'
templateUrl: './resource-policies.component.html',
})
/**
* Component that shows the policies for given resource
@@ -126,7 +103,7 @@ export class ResourcePoliciesComponent implements OnInit, OnDestroy {
*/
ngOnInit(): void {
this.isActive = true;
this.initResourcePolicyLIst();
this.initResourcePolicyList();
}
/**
@@ -168,48 +145,6 @@ export class ResourcePoliciesComponent implements OnInit, OnDestroy {
);
}
/**
* Returns a date in simplified format (YYYY-MM-DD).
*
* @param date
* @return a string with formatted date
*/
formatDate(date: string): string {
return isNotEmpty(date) ? dateToString(stringToNgbDateStruct(date)) : '';
}
/**
* Return the ePerson's name which the given policy is linked to
*
* @param policy The resource policy
*/
getEPersonName(policy: ResourcePolicy): Observable<string> {
// TODO to be reviewed when https://github.com/DSpace/dspace-angular/issues/644 will be resolved
// return this.ePersonService.findByHref(policy._links.eperson.href).pipe(
return policy.eperson.pipe(
filter(() => this.isActive),
getFirstSucceededRemoteDataWithNotEmptyPayload(),
map((eperson: EPerson) => this.dsoNameService.getName(eperson)),
startWith('')
);
}
/**
* Return the group's name which the given policy is linked to
*
* @param policy The resource policy
*/
getGroupName(policy: ResourcePolicy): Observable<string> {
// TODO to be reviewed when https://github.com/DSpace/dspace-angular/issues/644 will be resolved
// return this.groupService.findByHref(policy._links.group.href).pipe(
return policy.group.pipe(
filter(() => this.isActive),
getFirstSucceededRemoteDataWithNotEmptyPayload(),
map((group: Group) => this.dsoNameService.getName(group)),
startWith('')
);
}
/**
* Return all resource's policies
*
@@ -219,46 +154,14 @@ export class ResourcePoliciesComponent implements OnInit, OnDestroy {
return this.resourcePoliciesEntries$.asObservable();
}
/**
* Check whether the given policy is linked to a ePerson
*
* @param policy The resource policy
* @return an observable that emits true when the policy is linked to a ePerson, false otherwise
*/
hasEPerson(policy): Observable<boolean> {
// TODO to be reviewed when https://github.com/DSpace/dspace-angular/issues/644 will be resolved
// return this.ePersonService.findByHref(policy._links.eperson.href).pipe(
return policy.eperson.pipe(
filter(() => this.isActive),
getFirstSucceededRemoteDataPayload(),
map((eperson: EPerson) => isNotEmpty(eperson)),
startWith(false)
);
}
/**
* Check whether the given policy is linked to a group
*
* @param policy The resource policy
* @return an observable that emits true when the policy is linked to a group, false otherwise
*/
hasGroup(policy): Observable<boolean> {
// TODO to be reviewed when https://github.com/DSpace/dspace-angular/issues/644 will be resolved
// return this.groupService.findByHref(policy._links.group.href).pipe(
return policy.group.pipe(
filter(() => this.isActive),
getFirstSucceededRemoteDataPayload(),
map((group: Group) => isNotEmpty(group)),
startWith(false)
);
}
/**
* Initialize the resource's policies list
*/
initResourcePolicyLIst() {
this.subs.push(this.resourcePolicyService.searchByResource(this.resourceUUID, null, false, true,
followLink('eperson'), followLink('group')).pipe(
initResourcePolicyList() {
this.subs.push(this.resourcePolicyService.searchByResource(
this.resourceUUID, null, false, true,
followLink('eperson'), followLink('group')
).pipe(
filter(() => this.isActive),
getAllSucceededRemoteData()
).subscribe((result) => {
@@ -295,37 +198,6 @@ export class ResourcePoliciesComponent implements OnInit, OnDestroy {
});
}
/**
* Redirect to resource policy editing page
*
* @param policy The resource policy
*/
redirectToResourcePolicyEditPage(policy: ResourcePolicy): void {
this.router.navigate([`./edit`], {
relativeTo: this.route,
queryParams: {
policyId: policy.id
}
});
}
/**
* Redirect to group edit page
*
* @param policy The resource policy
*/
redirectToGroupEditPage(policy: ResourcePolicy): void {
this.subs.push(
this.groupService.findByHref(policy._links.group.href, false).pipe(
filter(() => this.isActive),
getFirstSucceededRemoteDataPayload(),
map((group: Group) => group.id)
).subscribe((groupUUID) => {
this.router.navigate([ACCESS_CONTROL_MODULE_PATH, GROUP_EDIT_PATH, groupUUID]);
})
);
}
/**
* Select/unselect all checkbox in the list
*/