mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 19:43:04 +00:00
Implemented resource policies component
This commit is contained in:
@@ -1657,6 +1657,36 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"resource-policies.add.for.": "Add a new policy",
|
||||||
|
|
||||||
|
"resource-policies.add.for.bitstream": "Add a new Bitstream policy",
|
||||||
|
|
||||||
|
"resource-policies.add.for.bundle": "Add a new Bundle policy",
|
||||||
|
|
||||||
|
"resource-policies.add.for.item": "Add a new Item policy",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.action": "Action",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.date.end": "End Date",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.date.start": "Start Date",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.group": "Group",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.group.edit": "Edit",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.name": "Name",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.id": "ID",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.title.for.bitstream": "Policies for Bitstream",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.title.for.bundle": "Policies for Bundle",
|
||||||
|
|
||||||
|
"resource-policies.table.headers.title.for.item": "Policies for Item",
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"search.description": "",
|
"search.description": "",
|
||||||
|
|
||||||
"search.switch-configuration.title": "Show",
|
"search.switch-configuration.title": "Show",
|
||||||
|
@@ -0,0 +1,40 @@
|
|||||||
|
<div *ngIf="(getResourcePolicies() | async)?.hasSucceeded">
|
||||||
|
<table class="table table-striped table-bordered table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="6">
|
||||||
|
<p class="d-flex justify-content-between align-items-center m-0">
|
||||||
|
{{ 'resource-policies.table.headers.title.for.' + resourceKey | translate }} {{resourceUUID}}
|
||||||
|
<button class="btn btn-outline-primary float-right">
|
||||||
|
{{'resource-policies.add.for.' + resourceKey | translate}}
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
<tr class="text-center">
|
||||||
|
<th>{{'resource-policies.table.headers.id' | translate}}</th>
|
||||||
|
<th>{{'resource-policies.table.headers.name' | translate}}</th>
|
||||||
|
<th>{{'resource-policies.table.headers.action' | translate}}</th>
|
||||||
|
<th>{{'resource-policies.table.headers.group' | translate}}</th>
|
||||||
|
<th>{{'resource-policies.table.headers.date.start' | translate}}</th>
|
||||||
|
<th>{{'resource-policies.table.headers.date.end' | translate}}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr *ngFor="let policy of (getResourcePolicies() | async)?.payload?.page; trackById">
|
||||||
|
<th scope="row">{{policy.id}}</th>
|
||||||
|
<td>{{policy.name}}</td>
|
||||||
|
<td>{{policy.action}}</td>
|
||||||
|
<td *ngIf="(hasGroup(policy) | async)">
|
||||||
|
{{getGroupName(policy) | async}}
|
||||||
|
<button class="btn btn-link pt-0 pb-0" (click)="redirectToGroupEditPage(policy)">
|
||||||
|
{{'resource-policies.table.headers.group.edit' | translate}}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
<td *ngIf="!(hasGroup(policy) | async)"></td>
|
||||||
|
<td>{{policy.startDate}}</td>
|
||||||
|
<td>{{policy.endDate}}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
@@ -0,0 +1,3 @@
|
|||||||
|
td .btn-link:focus {
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
134
src/app/shared/resource-policies/resource-policies.component.ts
Normal file
134
src/app/shared/resource-policies/resource-policies.component.ts
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
import { Observable, Subscription } from 'rxjs';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
|
import { ResourcePolicyService } from '../../core/resource-policy/resource-policy.service';
|
||||||
|
import { PaginatedList } from '../../core/data/paginated-list';
|
||||||
|
import { getFirstSucceededRemoteDataPayload, getSucceededRemoteData } from '../../core/shared/operators';
|
||||||
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
|
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, isNotEmpty } from '../empty.util';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ds-resource-policies',
|
||||||
|
styleUrls: ['./resource-policies.component.scss'],
|
||||||
|
templateUrl: './resource-policies.component.html'
|
||||||
|
})
|
||||||
|
/**
|
||||||
|
* Component that shows the policies for given resource
|
||||||
|
*/
|
||||||
|
export class ResourcePoliciesComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The resource UUID
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
@Input() public resourceUUID: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The resource type (e.g. 'item', 'bundle' etc) used as key to build automatically translation label
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
@Input() public resourceKey: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of policies for given resource
|
||||||
|
* @type {Observable<RemoteData<PaginatedList<ResourcePolicy>>>}
|
||||||
|
*/
|
||||||
|
private resourcePolicies$: Observable<RemoteData<PaginatedList<ResourcePolicy>>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||||
|
* @type {Array}
|
||||||
|
*/
|
||||||
|
private subs: Subscription[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize instance variables
|
||||||
|
*
|
||||||
|
* @param {DSONameService} dsoNameService
|
||||||
|
* @param {GroupDataService} groupService
|
||||||
|
* @param {ResourcePolicyService} resourcePolicyService
|
||||||
|
* @param {Router} router
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
private dsoNameService: DSONameService,
|
||||||
|
private groupService: GroupDataService,
|
||||||
|
private resourcePolicyService: ResourcePolicyService,
|
||||||
|
private router: Router
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the component, setting up the resource's policies
|
||||||
|
*/
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.resourcePolicies$ = this.resourcePolicyService.searchByResource(this.resourceUUID).pipe(
|
||||||
|
getSucceededRemoteData()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the group's name which the given policy is linked to
|
||||||
|
*
|
||||||
|
* @param policy The resource policy
|
||||||
|
*/
|
||||||
|
getGroupName(policy: ResourcePolicy): Observable<string> {
|
||||||
|
return this.groupService.findByHref(policy._links.group.href).pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
// A group has not dc.title metadata so is not possible to use DSONameService to retrieve name
|
||||||
|
map((group: Group) => group.name)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all resource's policies
|
||||||
|
*
|
||||||
|
* @return an observable that emits all resource's policies
|
||||||
|
*/
|
||||||
|
getResourcePolicies(): Observable<RemoteData<PaginatedList<ResourcePolicy>>> {
|
||||||
|
return this.resourcePolicies$;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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> {
|
||||||
|
return this.groupService.findByHref(policy._links.group.href).pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
map((group: Group) => isNotEmpty(group))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirect to group edit page
|
||||||
|
*
|
||||||
|
* @param policy The resource policy
|
||||||
|
*/
|
||||||
|
redirectToGroupEditPage(policy: ResourcePolicy): void {
|
||||||
|
this.subs.push(
|
||||||
|
this.groupService.findByHref(policy._links.group.href).pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
map((group: Group) => group.id)
|
||||||
|
).subscribe((groupUUID) => this.router.navigate(['groups', groupUUID, 'edit']))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsubscribe from all subscriptions
|
||||||
|
*/
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.subs
|
||||||
|
.filter((subscription) => hasValue(subscription))
|
||||||
|
.forEach((subscription) => subscription.unsubscribe())
|
||||||
|
}
|
||||||
|
}
|
@@ -179,6 +179,8 @@ import { ExistingMetadataListElementComponent } from './form/builder/ds-dynamic-
|
|||||||
import { ItemVersionsComponent } from './item/item-versions/item-versions.component';
|
import { ItemVersionsComponent } from './item/item-versions/item-versions.component';
|
||||||
import { SortablejsModule } from 'ngx-sortablejs';
|
import { SortablejsModule } from 'ngx-sortablejs';
|
||||||
import { MissingTranslationHelper } from './translate/missing-translation.helper';
|
import { MissingTranslationHelper } from './translate/missing-translation.helper';
|
||||||
|
import { ResourcePoliciesComponent } from './resource-policies/resource-policies.component';
|
||||||
|
import { NgForTrackByIdDirective } from './ng-for-track-by-id.directive';
|
||||||
|
|
||||||
const MODULES = [
|
const MODULES = [
|
||||||
// Do NOT include UniversalModule, HttpModule, or JsonpModule here
|
// Do NOT include UniversalModule, HttpModule, or JsonpModule here
|
||||||
@@ -347,6 +349,7 @@ const COMPONENTS = [
|
|||||||
ExistingMetadataListElementComponent,
|
ExistingMetadataListElementComponent,
|
||||||
ItemVersionsComponent,
|
ItemVersionsComponent,
|
||||||
PublicationSearchResultListElementComponent,
|
PublicationSearchResultListElementComponent,
|
||||||
|
ResourcePoliciesComponent
|
||||||
];
|
];
|
||||||
|
|
||||||
const ENTRY_COMPONENTS = [
|
const ENTRY_COMPONENTS = [
|
||||||
@@ -438,7 +441,8 @@ const DIRECTIVES = [
|
|||||||
AutoFocusDirective,
|
AutoFocusDirective,
|
||||||
RoleDirective,
|
RoleDirective,
|
||||||
MetadataRepresentationDirective,
|
MetadataRepresentationDirective,
|
||||||
ListableObjectDirective
|
ListableObjectDirective,
|
||||||
|
NgForTrackByIdDirective
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
Reference in New Issue
Block a user