mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
add QA breadcrumb resolver and service
This commit is contained in:
@@ -1,20 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { ItemDataService } from '../data/item-data.service';
|
|
||||||
import {QABreadcrumbsService} from "./qa-breadcrumbs.service";
|
|
||||||
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from "@angular/router";
|
|
||||||
import {BreadcrumbConfig} from "../../breadcrumbs/breadcrumb/breadcrumb-config.model";
|
|
||||||
import {currentPathFromSnapshot} from "../../shared/utils/route.utils";
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class QABreadcrumbResolver implements Resolve<BreadcrumbConfig<string>> {
|
|
||||||
constructor(protected breadcrumbService: QABreadcrumbsService, protected dataService: ItemDataService) {}
|
|
||||||
|
|
||||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): BreadcrumbConfig<string> {
|
|
||||||
const key = "testKey";
|
|
||||||
const fullPath = currentPathFromSnapshot(route);
|
|
||||||
console.log(key, fullPath)
|
|
||||||
return { provider: this.breadcrumbService, key: key, url: fullPath };
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
|
|
||||||
import { BreadcrumbsProviderService } from './breadcrumbsProviderService';
|
|
||||||
import { Observable, of as observableOf } from 'rxjs';
|
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service to calculate QA breadcrumbs for a single part of the route
|
|
||||||
*/
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class QABreadcrumbsService implements BreadcrumbsProviderService<string> {
|
|
||||||
|
|
||||||
getBreadcrumbs(key: string, url: string): Observable<Breadcrumb[]> {
|
|
||||||
return observableOf([new Breadcrumb(key + "test", url)]);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,31 @@
|
|||||||
|
import {QualityAssuranceBreadcrumbResolver} from './quality-assurance-breadcrumb.resolver';
|
||||||
|
|
||||||
|
describe('QualityAssuranceBreadcrumbResolver', () => {
|
||||||
|
describe('resolve', () => {
|
||||||
|
let resolver: QualityAssuranceBreadcrumbResolver;
|
||||||
|
let qualityAssuranceBreadcrumbService: any;
|
||||||
|
let route: any;
|
||||||
|
const fullPath = '/test/quality-assurance/';
|
||||||
|
const expectedKey = 'testSourceId:testTopicId';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
route = {
|
||||||
|
paramMap: {
|
||||||
|
get: function () {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
sourceId: 'testSourceId',
|
||||||
|
topicId: 'testSourceId:testTopicId'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
qualityAssuranceBreadcrumbService = {};
|
||||||
|
resolver = new QualityAssuranceBreadcrumbResolver(qualityAssuranceBreadcrumbService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve the breadcrumb config', () => {
|
||||||
|
const resolvedConfig = resolver.resolve(route, {url: fullPath} as any);
|
||||||
|
const expectedConfig = { provider: qualityAssuranceBreadcrumbService, key: expectedKey, url: fullPath };
|
||||||
|
expect(resolvedConfig).toEqual(expectedConfig);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -0,0 +1,28 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {QualityAssuranceBreadcrumbService} from './quality-assurance-breadcrumb.service';
|
||||||
|
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
|
||||||
|
import {BreadcrumbConfig} from '../../breadcrumbs/breadcrumb/breadcrumb-config.model';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class QualityAssuranceBreadcrumbResolver implements Resolve<BreadcrumbConfig<string>> {
|
||||||
|
constructor(protected breadcrumbService: QualityAssuranceBreadcrumbService) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that resolve QA item into a breadcrumb
|
||||||
|
* The parameter are retrieved by the url since part of the QA route config
|
||||||
|
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
|
||||||
|
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
|
||||||
|
* @returns BreadcrumbConfig object
|
||||||
|
*/
|
||||||
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): BreadcrumbConfig<string> {
|
||||||
|
const sourceId = route.paramMap.get('sourceId');
|
||||||
|
const topicId = route.paramMap.get('topicId');
|
||||||
|
const key = topicId ?? sourceId;
|
||||||
|
const fullPath = state.url;
|
||||||
|
const url = fullPath.substr(0, fullPath.indexOf(sourceId));
|
||||||
|
|
||||||
|
return { provider: this.breadcrumbService, key, url };
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
|
||||||
|
import { getTestScheduler } from 'jasmine-marbles';
|
||||||
|
import {QualityAssuranceBreadcrumbService} from './quality-assurance-breadcrumb.service';
|
||||||
|
|
||||||
|
describe('QualityAssuranceBreadcrumbService', () => {
|
||||||
|
let service: QualityAssuranceBreadcrumbService;
|
||||||
|
let dataService: any;
|
||||||
|
let translateService: any;
|
||||||
|
|
||||||
|
let exampleString;
|
||||||
|
let exampleURL;
|
||||||
|
let exampleQaKey;
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
exampleString = 'sourceId';
|
||||||
|
exampleURL = '/test/quality-assurance/';
|
||||||
|
exampleQaKey = 'admin.quality-assurance.breadcrumbs';
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
init();
|
||||||
|
TestBed.configureTestingModule({}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
service = new QualityAssuranceBreadcrumbService(dataService,translateService);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getBreadcrumbs', () => {
|
||||||
|
it('should return a breadcrumb based on a string', () => {
|
||||||
|
const breadcrumbs = service.getBreadcrumbs(exampleString, exampleURL);
|
||||||
|
getTestScheduler().expectObservable(breadcrumbs).toBe('(a|)', { a: [new Breadcrumb(exampleQaKey, exampleURL),
|
||||||
|
new Breadcrumb(exampleString, exampleURL + exampleString)]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -0,0 +1,52 @@
|
|||||||
|
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
|
||||||
|
import { BreadcrumbsProviderService } from './breadcrumbsProviderService';
|
||||||
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {map} from 'rxjs/operators';
|
||||||
|
import {getFirstCompletedRemoteData} from '../shared/operators';
|
||||||
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
|
import {QualityAssuranceTopicRestService} from "../notifications/qa/topics/quality-assurance-topic-rest.service";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service to calculate QA breadcrumbs for a single part of the route
|
||||||
|
*/
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class QualityAssuranceBreadcrumbService implements BreadcrumbsProviderService<string> {
|
||||||
|
|
||||||
|
private QUALITY_ASSURANCE_BREADCRUMB_KEY = 'admin.quality-assurance.breadcrumbs';
|
||||||
|
constructor(
|
||||||
|
protected qualityAssuranceService: QualityAssuranceTopicRestService,
|
||||||
|
private translationService: TranslateService,
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to calculate the breadcrumbs
|
||||||
|
* @param key The key used to resolve the breadcrumb
|
||||||
|
* @param url The url to use as a link for this breadcrumb
|
||||||
|
*/
|
||||||
|
getBreadcrumbs(key: string, url: string): Observable<Breadcrumb[]> {
|
||||||
|
const sourceId = key.split(':')[0];
|
||||||
|
const topicId = key.split(':')[1];
|
||||||
|
|
||||||
|
if (topicId) {
|
||||||
|
return this.qualityAssuranceService.getTopic(`${sourceId}:${topicId}`).pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
map((topic) => {
|
||||||
|
return [new Breadcrumb(this.translationService.instant(this.QUALITY_ASSURANCE_BREADCRUMB_KEY), url),
|
||||||
|
new Breadcrumb(sourceId, `${url}${sourceId}`),
|
||||||
|
new Breadcrumb(topic.payload.name, undefined)];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return observableOf([new Breadcrumb(this.translationService.instant(this.QUALITY_ASSURANCE_BREADCRUMB_KEY), url),
|
||||||
|
new Breadcrumb(sourceId, `${url}${sourceId}`)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user