Skip to content

Commit de51261

Browse files
committed
Merge embargo badge with the existing access-status badge
1 parent 61576e9 commit de51261

11 files changed

Lines changed: 61 additions & 293 deletions

File tree

src/app/item-page/simple/field-components/file-section/file-section.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import { ThemedLoadingComponent } from '../../../../shared/loading/themed-loadin
2828
import { MetadataFieldWrapperComponent } from '../../../../shared/metadata-field-wrapper/metadata-field-wrapper.component';
2929
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
3030
import { FileSizePipe } from '../../../../shared/utils/file-size-pipe';
31-
import { VarDirective } from '../../../../shared/utils/var.directive';
3231
import { followLink } from '../../../../shared/utils/follow-link-config.model';
32+
import { VarDirective } from '../../../../shared/utils/var.directive';
3333

3434
/**
3535
* This component renders the file section of the item

src/app/shared/file-download-link/file-download-link.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ds-embargo-badge [bitstream]="bitstream"></ds-embargo-badge>
1+
<ds-access-status-badge [object]="bitstream"></ds-access-status-badge>
22
<a [routerLink]="(bitstreamPath$| async)?.routerLink" class="d-block dont-break-out mb-1"
33
[queryParams]="(bitstreamPath$| async)?.queryParams"
44
[target]="isBlank ? '_blank': '_self'"

src/app/shared/file-download-link/file-download-link.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ import {
3030
hasValue,
3131
isNotEmpty,
3232
} from '../empty.util';
33-
import { ThemedEmbargoBadgeComponent } from '../object-collection/shared/badges/embargo-badge/themed-embargo-badge.component';
33+
import { ThemedAccessStatusBadgeComponent } from '../object-collection/shared/badges/access-status-badge/themed-access-status-badge.component';
3434

3535
@Component({
3636
selector: 'ds-base-file-download-link',
3737
templateUrl: './file-download-link.component.html',
3838
styleUrls: ['./file-download-link.component.scss'],
3939
standalone: true,
40-
imports: [RouterLink, NgClass, NgTemplateOutlet, AsyncPipe, TranslateModule, ThemedEmbargoBadgeComponent],
40+
imports: [RouterLink, NgClass, NgTemplateOutlet, AsyncPipe, TranslateModule, ThemedAccessStatusBadgeComponent],
4141
})
4242
/**
4343
* Component displaying a download link
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
@if (showAccessStatus) {
2-
@if (accessStatus$ | async; as accessStatus) {
3-
<span>
4-
<span [class]="'badge bg-secondary access-status-list-element-badge ' + accessStatusClass">{{ accessStatus | translate }}</span>
5-
</span>
2+
@if ({ status: accessStatus$ | async, date: embargoDate$ | async }; as accessStatus) {
3+
<span [class]="'badge bg-secondary access-status-list-element-badge ' + accessStatusClass">{{ accessStatus.status | translate: {date: accessStatus.date} }}</span>
64
}
75
}

src/app/shared/object-collection/shared/badges/access-status-badge/access-status-badge.component.ts

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import {
1616
map,
1717
} from 'rxjs/operators';
1818
import { AccessStatusDataService } from 'src/app/core/data/access-status-data.service';
19+
import { Bitstream } from 'src/app/core/shared/bitstream.model';
20+
import { getFirstSucceededRemoteDataPayload } from 'src/app/core/shared/operators';
1921
import { environment } from 'src/environments/environment';
2022

2123
import { DSpaceObject } from '../../../../../core/shared/dspace-object.model';
2224
import { Item } from '../../../../../core/shared/item.model';
23-
import { ITEM } from '../../../../../core/shared/item.resource-type';
2425
import { hasValue } from '../../../../empty.util';
2526
import { AccessStatusObject } from './access-status.model';
2627

@@ -37,7 +38,9 @@ import { AccessStatusObject } from './access-status.model';
3738
export class AccessStatusBadgeComponent implements OnDestroy, OnInit {
3839

3940
@Input() object: DSpaceObject;
41+
4042
accessStatus$: Observable<string>;
43+
embargoDate$: Observable<string>;
4144

4245
/**
4346
* Whether to show the access status badge or not
@@ -62,12 +65,32 @@ export class AccessStatusBadgeComponent implements OnDestroy, OnInit {
6265
constructor(private accessStatusDataService: AccessStatusDataService) { }
6366

6467
ngOnInit(): void {
65-
this.showAccessStatus = environment.item.showAccessStatuses;
66-
if (this.object.type.toString() !== ITEM.value || !this.showAccessStatus || this.object == null) {
67-
// Do not show the badge if the feature is inactive or if the item is null.
68+
if (!hasValue(this.object)) {
6869
return;
6970
}
71+
switch ((this.object as any).type) {
72+
case Item.type.value:
73+
this.handleItem();
74+
break;
75+
case Bitstream.type.value:
76+
this.handleBitstream();
77+
break;
78+
}
79+
}
7080

81+
ngOnDestroy(): void {
82+
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
83+
}
84+
85+
/**
86+
* Method to handle the object type Item
87+
*/
88+
private handleItem() {
89+
this.showAccessStatus = environment.item.showAccessStatuses;
90+
if (!this.showAccessStatus) {
91+
// Do not show the badge if the feature is inactive.
92+
return;
93+
}
7194
const item = this.object as Item;
7295
if (item.accessStatus == null) {
7396
// In case the access status has not been loaded, do it individually.
@@ -85,7 +108,6 @@ export class AccessStatusBadgeComponent implements OnDestroy, OnInit {
85108
map((status: string) => `access-status.${status.toLowerCase()}.listelement.badge`),
86109
catchError(() => observableOf('access-status.unknown.listelement.badge')),
87110
);
88-
89111
// stylesheet based on the access status value
90112
this.subs.push(
91113
this.accessStatus$.pipe(
@@ -96,7 +118,31 @@ export class AccessStatusBadgeComponent implements OnDestroy, OnInit {
96118
);
97119
}
98120

99-
ngOnDestroy(): void {
100-
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
121+
/**
122+
* Method to handle the object type Bitstream
123+
*/
124+
private handleBitstream() {
125+
this.showAccessStatus = environment.item.bitstream.showAccessStatuses;
126+
if (!this.showAccessStatus) {
127+
// Do not show the badge if the feature is inactive.
128+
return;
129+
}
130+
const bitstream = this.object as Bitstream;
131+
if (bitstream.accessStatus == null) {
132+
return;
133+
}
134+
this.embargoDate$ = bitstream.accessStatus.pipe(
135+
getFirstSucceededRemoteDataPayload(),
136+
map((accessStatus: AccessStatusObject) => {
137+
if (hasValue(accessStatus.embargoDate)) {
138+
this.accessStatus$ = observableOf('embargo.listelement.badge');
139+
return accessStatus.embargoDate;
140+
} else {
141+
this.accessStatus$ = observableOf(null);
142+
return null;
143+
}
144+
}),
145+
catchError(() => observableOf(null)),
146+
);
101147
}
102148
}

src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.scss

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.spec.ts

Lines changed: 0 additions & 177 deletions
This file was deleted.

src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)