Skip to content

Commit

Permalink
Merge pull request #2635 from DSpace/backport-2579-to-dspace-7_x
Browse files Browse the repository at this point in the history
[Port dspace-7_x] adding new access-status-list-element-badge css classes
  • Loading branch information
tdonohue authored Nov 13, 2023
2 parents 64364c9 + a276f41 commit 626cc30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-container *ngIf="showAccessStatus">
<span *ngIf="accessStatus$ | async as accessStatus">
<span class="badge badge-secondary">{{ accessStatus | translate }}</span>
<span [class]="'badge badge-secondary access-status-list-element-badge ' + accessStatusClass">{{ accessStatus | translate }}</span>
</span>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Input } from '@angular/core';
import { catchError, map } from 'rxjs/operators';
import { Observable, of as observableOf } from 'rxjs';
import { Observable, of as observableOf, Subscription } from 'rxjs';
import { AccessStatusObject } from './access-status.model';
import { hasValue } from '../../../../empty.util';
import { environment } from 'src/environments/environment';
Expand All @@ -11,7 +11,8 @@ import { ITEM } from '../../../../../core/shared/item.resource-type';

@Component({
selector: 'ds-access-status-badge',
templateUrl: './access-status-badge.component.html'
templateUrl: './access-status-badge.component.html',
styleUrls: ['./access-status-badge.component.scss']
})
/**
* Component rendering the access status of an item as a badge
Expand All @@ -26,6 +27,16 @@ export class AccessStatusBadgeComponent {
*/
showAccessStatus: boolean;

/**
* Value based stylesheet class for access status badge
*/
accessStatusClass: string;

/**
* List of subscriptions
*/
subs: Subscription[] = [];

/**
* Initialize instance variables
*
Expand Down Expand Up @@ -57,5 +68,18 @@ export class AccessStatusBadgeComponent {
map((status: string) => `access-status.${status.toLowerCase()}.listelement.badge`),
catchError(() => observableOf('access-status.unknown.listelement.badge'))
);

// stylesheet based on the access status value
this.subs.push(
this.accessStatus$.pipe(
map((accessStatusClass: string) => accessStatusClass.replace(/\./g, '-'))
).subscribe((accessStatusClass: string) => {
this.accessStatusClass = accessStatusClass;
})
);
}

ngOnDestroy(): void {
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
}
}

0 comments on commit 626cc30

Please sign in to comment.