mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Display the access status badges
This commit is contained in:
@@ -13,6 +13,8 @@ ui:
|
||||
rateLimiter:
|
||||
windowMs: 60000 # 1 minute
|
||||
max: 500 # limit each IP to 500 requests per windowMs
|
||||
# Show the file access status in items lists
|
||||
showAccessStatuses: false
|
||||
|
||||
# The REST API server settings
|
||||
# NOTE: these must be 'synced' with the 'dspace.server.url' setting in your backend's local.cfg.
|
||||
|
@@ -163,6 +163,7 @@ import { SequenceService } from './shared/sequence.service';
|
||||
import { CoreState } from './core-state.model';
|
||||
import { GroupDataService } from './eperson/group-data.service';
|
||||
import { SubmissionAccessesModel } from './config/models/config-submission-accesses.model';
|
||||
import { AccessStatusObject } from '../shared/object-list/access-status-badge/access-status.model';
|
||||
|
||||
/**
|
||||
* When not in production, endpoint responses can be mocked for testing purposes
|
||||
@@ -346,7 +347,8 @@ export const models =
|
||||
UsageReport,
|
||||
Root,
|
||||
SearchConfig,
|
||||
SubmissionAccessesModel
|
||||
SubmissionAccessesModel,
|
||||
AccessStatusObject
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
@@ -36,6 +36,7 @@ import { sendRequest } from '../shared/request.operators';
|
||||
import { RestRequest } from './rest-request.model';
|
||||
import { CoreState } from '../core-state.model';
|
||||
import { FindListOptions } from './find-list-options.model';
|
||||
import { AccessStatusObject } from 'src/app/shared/object-list/access-status-badge/access-status.model';
|
||||
|
||||
@Injectable()
|
||||
@dataService(ITEM)
|
||||
@@ -291,6 +292,27 @@ export class ItemDataService extends DataService<Item> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the the access status
|
||||
* @param itemId
|
||||
*/
|
||||
public getAccessStatus(itemId: string): Observable<RemoteData<AccessStatusObject>> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const href$ = this.halService.getEndpoint('accessStatus').pipe(
|
||||
map((href) => href.replace('{?uuid}', `?uuid=${itemId}`))
|
||||
);
|
||||
|
||||
href$.pipe(
|
||||
find((href: string) => hasValue(href)),
|
||||
map((href: string) => {
|
||||
const request = new GetRequest(requestId, href);
|
||||
this.requestService.send(request);
|
||||
})
|
||||
).subscribe();
|
||||
|
||||
return this.rdbService.buildFromRequestUUID(requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate the cache of the item
|
||||
* @param itemUUID
|
||||
|
@@ -0,0 +1,3 @@
|
||||
<div *ngIf="accessStatus$ | async as status" class="pl-1">
|
||||
<span class="badge badge-secondary">{{ status | translate }}</span>
|
||||
</div>
|
@@ -0,0 +1,160 @@
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { TruncatePipe } from '../../utils/truncate.pipe';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { AccessStatusBadgeComponent } from './access-status-badge.component';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { ItemDataService } from 'src/app/core/data/item-data.service';
|
||||
import { AccessStatusObject } from './access-status.model';
|
||||
|
||||
describe('ItemAccessStatusBadgeComponent', () => {
|
||||
let component: AccessStatusBadgeComponent;
|
||||
let fixture: ComponentFixture<AccessStatusBadgeComponent>;
|
||||
|
||||
let unknownStatus: AccessStatusObject;
|
||||
let metadataOnlyStatus: AccessStatusObject;
|
||||
let openAccessStatus: AccessStatusObject;
|
||||
let embargoStatus: AccessStatusObject;
|
||||
let restrictedStatus: AccessStatusObject;
|
||||
|
||||
let itemDataService: ItemDataService;
|
||||
|
||||
let item: Item;
|
||||
|
||||
function init() {
|
||||
unknownStatus = Object.assign(new AccessStatusObject(), {
|
||||
status: 'unknown'
|
||||
});
|
||||
|
||||
metadataOnlyStatus = Object.assign(new AccessStatusObject(), {
|
||||
status: 'metadata.only'
|
||||
});
|
||||
|
||||
openAccessStatus = Object.assign(new AccessStatusObject(), {
|
||||
status: 'open.access'
|
||||
});
|
||||
|
||||
embargoStatus = Object.assign(new AccessStatusObject(), {
|
||||
status: 'embargo'
|
||||
});
|
||||
|
||||
restrictedStatus = Object.assign(new AccessStatusObject(), {
|
||||
status: 'restricted'
|
||||
});
|
||||
|
||||
itemDataService = jasmine.createSpyObj('itemDataService', {
|
||||
getAccessStatus: createSuccessfulRemoteDataObject$(unknownStatus)
|
||||
});
|
||||
|
||||
item = Object.assign(new Item(), {
|
||||
uuid: 'item-uuid'
|
||||
});
|
||||
}
|
||||
|
||||
function initTestBed() {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [AccessStatusBadgeComponent, TruncatePipe],
|
||||
schemas: [NO_ERRORS_SCHEMA],
|
||||
providers: [
|
||||
{provide: ItemDataService, useValue: itemDataService}
|
||||
]
|
||||
}).compileComponents();
|
||||
}
|
||||
|
||||
function initFixtureAndComponent() {
|
||||
fixture = TestBed.createComponent(AccessStatusBadgeComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.uuid = item.uuid;
|
||||
fixture.detectChanges();
|
||||
}
|
||||
|
||||
function lookForAccessStatusBadge(status: string) {
|
||||
const badge = fixture.debugElement.query(By.css('span.badge'));
|
||||
expect(badge.nativeElement.textContent).toEqual(`access-status.${status.toLowerCase()}.listelement.badge`);
|
||||
}
|
||||
|
||||
describe('init', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
init();
|
||||
initTestBed();
|
||||
}));
|
||||
beforeEach(() => {
|
||||
initFixtureAndComponent();
|
||||
});
|
||||
it('should init the component', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the getAccessStatus method returns unknown', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
init();
|
||||
initTestBed();
|
||||
}));
|
||||
beforeEach(() => {
|
||||
initFixtureAndComponent();
|
||||
});
|
||||
it('should show the unknown badge', () => {
|
||||
lookForAccessStatusBadge('unknown');
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the getAccessStatus method returns metadata.only', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
init();
|
||||
(itemDataService.getAccessStatus as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(metadataOnlyStatus));
|
||||
initTestBed();
|
||||
}));
|
||||
beforeEach(() => {
|
||||
initFixtureAndComponent();
|
||||
});
|
||||
it('should show the metadata only badge', () => {
|
||||
lookForAccessStatusBadge('metadata.only');
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the getAccessStatus method returns open.access', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
init();
|
||||
(itemDataService.getAccessStatus as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(openAccessStatus));
|
||||
initTestBed();
|
||||
}));
|
||||
beforeEach(() => {
|
||||
initFixtureAndComponent();
|
||||
});
|
||||
it('should show the open access badge', () => {
|
||||
lookForAccessStatusBadge('open.access');
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the getAccessStatus method returns embargo', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
init();
|
||||
(itemDataService.getAccessStatus as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(embargoStatus));
|
||||
initTestBed();
|
||||
}));
|
||||
beforeEach(() => {
|
||||
initFixtureAndComponent();
|
||||
});
|
||||
it('should show the embargo badge', () => {
|
||||
lookForAccessStatusBadge('embargo');
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the getAccessStatus method returns restricted', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
init();
|
||||
(itemDataService.getAccessStatus as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(restrictedStatus));
|
||||
initTestBed();
|
||||
}));
|
||||
beforeEach(() => {
|
||||
initFixtureAndComponent();
|
||||
});
|
||||
it('should show the restricted badge', () => {
|
||||
lookForAccessStatusBadge('restricted');
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,45 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
import { getFirstSucceededRemoteDataPayload } from 'src/app/core/shared/operators';
|
||||
import { ItemDataService } from 'src/app/core/data/item-data.service';
|
||||
import { AccessStatusObject } from './access-status.model';
|
||||
import { hasValue } from '../../empty.util';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-access-status-badge',
|
||||
templateUrl: './access-status-badge.component.html'
|
||||
})
|
||||
/**
|
||||
* Component rendering the access status of an item as a badge
|
||||
*/
|
||||
export class AccessStatusBadgeComponent {
|
||||
|
||||
private _uuid: string;
|
||||
private _accessStatus$: Observable<string>;
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
*
|
||||
* @param {ItemDataService} itemDataService
|
||||
*/
|
||||
constructor(private itemDataService: ItemDataService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this._accessStatus$ = this.itemDataService
|
||||
.getAccessStatus(this._uuid)
|
||||
.pipe(
|
||||
getFirstSucceededRemoteDataPayload(),
|
||||
map((accessStatus: AccessStatusObject) => hasValue(accessStatus.status) ? accessStatus.status : 'unknown'),
|
||||
map((status: string) => `access-status.${status.toLowerCase()}.listelement.badge`)
|
||||
);
|
||||
}
|
||||
|
||||
@Input() set uuid(uuid: string) {
|
||||
this._uuid = uuid;
|
||||
}
|
||||
|
||||
get accessStatus$(): Observable<string> {
|
||||
return this._accessStatus$;
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
import { autoserialize } from 'cerialize';
|
||||
import { typedObject } from 'src/app/core/cache/builders/build-decorators';
|
||||
import { ResourceType } from 'src/app/core/shared/resource-type';
|
||||
import { excludeFromEquals } from 'src/app/core/utilities/equals.decorators';
|
||||
import { ACCESS_STATUS } from './access-status.resource-type';
|
||||
|
||||
@typedObject
|
||||
export class AccessStatusObject {
|
||||
static type = ACCESS_STATUS;
|
||||
|
||||
/**
|
||||
* The type for this AccessStatusObject
|
||||
*/
|
||||
@excludeFromEquals
|
||||
@autoserialize
|
||||
type: ResourceType;
|
||||
|
||||
/**
|
||||
* The access status value
|
||||
*/
|
||||
@autoserialize
|
||||
status: string;
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
import { ResourceType } from 'src/app/core/shared/resource-type';
|
||||
|
||||
/**
|
||||
* The resource type for Access Status
|
||||
*
|
||||
* Needs to be in a separate file to prevent circular
|
||||
* dependencies in webpack.
|
||||
*/
|
||||
export const ACCESS_STATUS = new ResourceType('accessStatus');
|
@@ -1,4 +1,7 @@
|
||||
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
|
||||
<div class="d-flex">
|
||||
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
|
||||
<ds-access-status-badge *ngIf="showAccessStatus" [uuid]="dso.uuid"></ds-access-status-badge>
|
||||
</div>
|
||||
|
||||
<ds-truncatable [id]="dso.id" *ngIf="object !== undefined && object !== null">
|
||||
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer"
|
||||
|
@@ -5,6 +5,7 @@ import { ItemSearchResult } from '../../../../../object-collection/shared/item-s
|
||||
import { SearchResultListElementComponent } from '../../../search-result-list-element.component';
|
||||
import { Item } from '../../../../../../core/shared/item.model';
|
||||
import { getItemPageRoute } from '../../../../../../item-page/item-page-routing-paths';
|
||||
import { environment } from '../../../../../../../environments/environment';
|
||||
|
||||
@listableObjectComponent('PublicationSearchResult', ViewMode.ListElement)
|
||||
@listableObjectComponent(ItemSearchResult, ViewMode.ListElement)
|
||||
@@ -21,9 +22,14 @@ export class ItemSearchResultListElementComponent extends SearchResultListElemen
|
||||
* Route to the item's page
|
||||
*/
|
||||
itemPageRoute: string;
|
||||
/**
|
||||
* Whether to show the access status badge or not
|
||||
*/
|
||||
showAccessStatus: boolean;
|
||||
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
this.itemPageRoute = getItemPageRoute(this.dso);
|
||||
this.showAccessStatus = environment.ui.showAccessStatuses;
|
||||
}
|
||||
}
|
||||
|
@@ -111,6 +111,7 @@ import { FilterInputSuggestionsComponent } from './input-suggestions/filter-sugg
|
||||
import { DsoInputSuggestionsComponent } from './input-suggestions/dso-input-suggestions/dso-input-suggestions.component';
|
||||
import { ItemGridElementComponent } from './object-grid/item-grid-element/item-types/item/item-grid-element.component';
|
||||
import { TypeBadgeComponent } from './object-list/type-badge/type-badge.component';
|
||||
import { AccessStatusBadgeComponent } from './object-list/access-status-badge/access-status-badge.component';
|
||||
import { MetadataRepresentationLoaderComponent } from './metadata-representation/metadata-representation-loader.component';
|
||||
import { MetadataRepresentationDirective } from './metadata-representation/metadata-representation.directive';
|
||||
import { ListableObjectComponentLoaderComponent } from './object-collection/shared/listable-object/listable-object-component-loader.component';
|
||||
@@ -292,6 +293,7 @@ const COMPONENTS = [
|
||||
AbstractTrackableComponent,
|
||||
ComcolMetadataComponent,
|
||||
TypeBadgeComponent,
|
||||
AccessStatusBadgeComponent,
|
||||
BrowseByComponent,
|
||||
AbstractTrackableComponent,
|
||||
|
||||
|
@@ -27,6 +27,16 @@
|
||||
|
||||
"404.page-not-found": "page not found",
|
||||
|
||||
"access-status.embargo.listelement.badge": "Embargo",
|
||||
|
||||
"access-status.metadata.only.listelement.badge": "Metadata only",
|
||||
|
||||
"access-status.open.access.listelement.badge": "Open Access",
|
||||
|
||||
"access-status.restricted.listelement.badge": "Restricted",
|
||||
|
||||
"access-status.unknown.listelement.badge": "Unknown",
|
||||
|
||||
"admin.curation-tasks.breadcrumbs": "System curation tasks",
|
||||
|
||||
"admin.curation-tasks.title": "System curation tasks",
|
||||
|
@@ -36,6 +36,21 @@
|
||||
// "404.page-not-found": "page not found",
|
||||
"404.page-not-found": "Page introuvable",
|
||||
|
||||
// "access-status.embargo.listelement.badge": "Embargo",
|
||||
"access-status.embargo.listelement.badge": "Restriction temporaire",
|
||||
|
||||
// "access-status.metadata.only.listelement.badge": "Metadata only",
|
||||
"access-status.metadata.only.listelement.badge": "Métadonnées seulement",
|
||||
|
||||
// "access-status.open.access.listelement.badge": "Open Access",
|
||||
"access-status.open.access.listelement.badge": "Accès libre",
|
||||
|
||||
// "access-status.restricted.listelement.badge": "Restricted",
|
||||
"access-status.restricted.listelement.badge": "Restreint",
|
||||
|
||||
// "access-status.unknown.listelement.badge": "Unknown",
|
||||
"access-status.unknown.listelement.badge": "Inconnu",
|
||||
|
||||
// "admin.curation-tasks.breadcrumbs": "System curation tasks",
|
||||
"admin.curation-tasks.breadcrumbs": "Tâches de conservation système",
|
||||
|
||||
|
@@ -34,7 +34,10 @@ export class DefaultAppConfig implements AppConfig {
|
||||
rateLimiter: {
|
||||
windowMs: 1 * 60 * 1000, // 1 minute
|
||||
max: 500 // limit each IP to 500 requests per windowMs
|
||||
}
|
||||
},
|
||||
|
||||
// Show the file access status in items lists
|
||||
showAccessStatuses: false
|
||||
};
|
||||
|
||||
// The REST API server settings
|
||||
|
@@ -10,5 +10,7 @@ export class UIServerConfig extends ServerConfig {
|
||||
windowMs: number;
|
||||
max: number;
|
||||
};
|
||||
// This section is used to show the access status of items in results lists
|
||||
showAccessStatuses: boolean;
|
||||
|
||||
}
|
||||
|
@@ -25,7 +25,9 @@ export const environment: BuildConfig = {
|
||||
rateLimiter: {
|
||||
windowMs: 1 * 60 * 1000, // 1 minute
|
||||
max: 500 // limit each IP to 500 requests per windowMs
|
||||
}
|
||||
},
|
||||
// Show the file access status in items lists
|
||||
showAccessStatuses: false
|
||||
},
|
||||
|
||||
// The REST API server settings.
|
||||
|
Reference in New Issue
Block a user