Skip to content

Commit

Permalink
Merge branch 'dspace-cris-2023_02_x' into export_issue
Browse files Browse the repository at this point in the history
* dspace-cris-2023_02_x: (65 commits)
  [DSC-397] fix issue that lead to failing e2e
  [DSC-1653] removed comments
  [DSC-1653] Defined a mixin for vertical ellipsis
  [DSC-1637] resolve conflicts
  [DSC-1601] - Added test case
  [DSC-1601] - Adjusted code for fixing requested
  [DSC-1601] - Added new implementation when bitstream is restricted
  [DSC-1601] - Removed old implementation
  [DSC-1575] Fixed labels name
  [CST-9683] Fix visualization order of the metrics boxes in the item page
  [DSC-1524] Use ngOnChanges to detect changes on input variable
  [DSC-1655] Configure person icon to be visible without authority
  [DSC-1628] change icon color in config
  [DSC-1524] Adjusted test for End User Agreement not shown
  [DSC-1524] Fixing End User Agreement not shown
  [DSC-1652] fix lint
  [DSC-1652] refactor translateService calls, change default values for timeouts
  [DSC-1575] Added labels required
  [DSC-1652] add warning and error messages to loader component
  [DSC-1601] Fixed issue with icon visibility in FileDownloadLinkComponent
  ...

# Conflicts:
#	package.json
#	src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.scss
#	src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.ts
  • Loading branch information
oye816 committed May 6, 2024
2 parents bd1da6b + 4d840b5 commit 97c09a6
Show file tree
Hide file tree
Showing 132 changed files with 1,451 additions and 518 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/search-navbar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const page = {
}
};

xdescribe('Search from Navigation Bar', () => {
describe('Search from Navigation Bar', () => {
// NOTE: these tests currently assume this query will return results!
const query = TEST_SEARCH_TERM;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dspace-angular",
"version": "2024.01.00-SNAPSHOT",
"version": "2023.02.04-SNAPSHOT",
"scripts": {
"ng": "ng",
"config:watch": "nodemon",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class AdminEditUserAgreementComponent implements OnInit, OnDestroy {
this.subs.push(this.siteService.patch(this.site, operations).pipe(
getFirstCompletedRemoteData(),
).subscribe((restResponse) => {
if (restResponse.isSuccess) {
if (restResponse.hasSucceeded) {
this.notificationsService.success(this.translateService.get('admin.edit-user-agreement.success'));
if ( result === 'edit-with-reset' ) {
this.deleteAllUserAgreementMetadataValues();
Expand Down
14 changes: 11 additions & 3 deletions src/app/core/browse/search-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { map, switchMap } from 'rxjs/operators';
import { PaginatedList } from '../data/paginated-list.model';
import { RemoteData } from '../data/remote-data';
import { Item } from '../shared/item.model';
import { getFirstSucceededRemoteData } from '../shared/operators';
import { getFirstCompletedRemoteData } from '../shared/operators';
import { BrowseEntrySearchOptions } from './browse-entry-search-options.model';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { ItemDataService } from '../data/item-data.service';
Expand Down Expand Up @@ -107,8 +107,16 @@ export class SearchManager {
.filter((item) => hasValue(item));

const uuidList = this.extractUUID(items, environment.followAuthorityMetadata);

return uuidList.length > 0 ? this.itemService.findAllById(uuidList).pipe(getFirstSucceededRemoteData()) : of(null);
return uuidList.length > 0 ? this.itemService.findAllById(uuidList).pipe(
getFirstCompletedRemoteData(),
map(data => {
if (data.hasSucceeded) {
return of(data);
} else {
of(null);
}
})
) : of(null);
}

protected extractUUID(items: Item[], metadataToFollow: FollowAuthorityMetadata[]): string[] {
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ import { EditItemMode } from './submission/models/edititem-mode.model';
import { AuditDataService } from './audit/audit-data.service';
import { Audit } from './audit/model/audit.model';
import { ItemExportFormat } from './itemexportformat/model/item-export-format.model';
import { MetricsComponentsDataService } from './layout/metrics-components-data.service';
import { MetricsComponentsService } from './layout/metrics-components.service';
import { MetricsComponent } from './layout/models/metrics-component.model';
import { Metric } from './shared/metric.model';
import { MetricsDataService } from './data/metrics-data.service';
Expand Down Expand Up @@ -354,7 +354,7 @@ const PROVIDERS = [
FilteredDiscoveryPageResponseParsingService,
{ provide: NativeWindowService, useFactory: NativeWindowFactory },
TabDataService,
MetricsComponentsDataService,
MetricsComponentsService,
MetricsDataService,
VocabularyService,
VocabularyDataService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { VocabularyEntry } from '../../submission/vocabularies/models/vocabulary
import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model';
import { FormFieldLanguageValueObject } from '../../../shared/form/builder/models/form-field-language-value.model';
import { CoreState } from '../../core-state.model';
import { Metadata } from '../../shared/metadata.utils';
import { ConfidenceType } from '../../shared/confidence-type';

/**
* Provides methods to dispatch JsonPatch Operations Actions
Expand Down Expand Up @@ -148,6 +150,11 @@ export class JsonPatchOperationsBuilder {
} else {
operationValue = value;
}
//Update confidence if was added once the field was already created, value is set only in constructor of FormFieldMetadataValueObject
if (Metadata.hasValidAuthority(operationValue.authority) && (isEmpty(operationValue.confidence) || operationValue.confidence === -1)) {
operationValue.confidence = ConfidenceType.CF_ACCEPTED;
}

} else if (value instanceof Date) {
if (securityLevel != null) {
operationValue = new FormFieldMetadataValueObject(dateToISOFormat(value), null, securityLevel);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Metric } from '../shared/metric.model';
import { MetricsComponentsDataService } from './metrics-components-data.service';
import { MetricsComponentsService } from './metrics-components.service';

describe('MetricsComponentsDataService', () => {
describe('MetricsComponentsService', () => {

let service: MetricsComponentsDataService;
let service: MetricsComponentsService;

beforeEach(() => {
service = new MetricsComponentsDataService();
service = new MetricsComponentsService();

});

Expand Down Expand Up @@ -44,8 +44,8 @@ describe('MetricsComponentsDataService', () => {

expect(result.length).toBe(1);
expect(result[0].metrics.length).toBe(2);
expect(result[0].metrics[0].metricType).toBe('views');
expect(result[0].metrics[1].metricType).toBe('downloads');
expect(result[0].metrics[0].metricType).toBe('downloads');
expect(result[0].metrics[1].metricType).toBe('views');

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CrisLayoutMetricRow } from './models/tab.model';
/**
* A service responsible for managing metrics objects
*/
export class MetricsComponentsDataService {
export class MetricsComponentsService {

/**
* Get matching metrics for item.
Expand All @@ -20,17 +20,13 @@ export class MetricsComponentsDataService {

computeMetricsRows(itemMetrics: Metric[], maxColumn, metricTypes: string[]): CrisLayoutMetricRow[] {

// support
const typeMap = {};
metricTypes.forEach((type) => typeMap[type] = type);

// filter, enrich, order
const metrics = itemMetrics
.filter((metric) => typeMap[metric.metricType])
.map((metric) => {
return { ...metric, position: typeMap[metric.metricType].position };
const metrics: Metric[] = itemMetrics
.filter((metric: Metric) => metricTypes.includes(metric.metricType))
.map((metric: Metric) => {
return { ...metric, position: metricTypes.indexOf(metric.metricType) };
})
.sort((metric) => metric.position);
.sort((metricA, metricB ) => metricA.position - metricB.position);

// chunker
const totalRow = Math.ceil(metrics.length / maxColumn);
Expand Down
105 changes: 105 additions & 0 deletions src/app/core/shared/client-math.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { DOCUMENT } from '@angular/common';
import {
Inject,
Injectable,
} from '@angular/core';
import { Observable, ReplaySubject, Subject } from 'rxjs';
import { environment } from 'src/environments/environment';
import {
NativeWindowRef,
NativeWindowService,
} from '../services/window.service';import { MathJaxConfig, MathService } from './math.service';

@Injectable({
providedIn: 'root'
})
/**
* Provide the MathService for CSR
*/
export class ClientMathService extends MathService {

protected isReady$: Subject<boolean>;

protected mathJaxOptions = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
},
svg: {
fontCache: 'global'
},
startup: {
typeset: false
}
};

protected mathJax: MathJaxConfig = {
source: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js',
id: 'MathJaxScript'
};
protected mathJaxFallback: MathJaxConfig = {
source: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-chtml.min.js',
id: 'MathJaxBackupScript'
};

constructor(
@Inject(DOCUMENT) private _document: Document,
@Inject(NativeWindowService) protected _window: NativeWindowRef,
) {
super();

this.isReady$ = new ReplaySubject<boolean>();

void this.registerMathJaxAsync(this.mathJax)
.then(() => this.isReady$.next(true))
.catch(_ => {
void this.registerMathJaxAsync(this.mathJaxFallback)
.then(() => this.isReady$.next(true));
});
}

/**
* Register the specified MathJax script in the document
*
* @param config The configuration object for the script
*/
protected async registerMathJaxAsync(config: MathJaxConfig): Promise<any> {
if (environment.markdown.mathjax) {
return new Promise<void>((resolve, reject) => {

const optionsScript: HTMLScriptElement = this._document.createElement('script');
optionsScript.type = 'text/javascript';
optionsScript.text = `MathJax = ${JSON.stringify(this.mathJaxOptions)};`;
this._document.head.appendChild(optionsScript);

const script: HTMLScriptElement = this._document.createElement('script');
script.id = config.id;
script.type = 'text/javascript';
script.src = config.source;
script.crossOrigin = 'anonymous';
script.async = true;
script.onload = () => resolve();
script.onerror = error => reject(error);
this._document.head.appendChild(script);
});
}
return Promise.resolve();
}

/**
* Return the status of the script registration
*/
ready(): Observable<boolean> {
return this.isReady$;
}

/**
* Render the specified element using the MathJax JavaScript
*
* @param element The element to render with MathJax
*/
render(element: HTMLElement) {
if (environment.markdown.mathjax) {
this._window.nativeWindow.MathJax.typesetPromise([element]);
}
}
}
47 changes: 47 additions & 0 deletions src/app/core/shared/math.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { TestBed } from '@angular/core/testing';
import { Observable, of } from 'rxjs';
import { MathService, MathJaxConfig } from './math.service';

export class MockMathService extends MathService {
protected mathJaxOptions: any = {};
protected mathJax: MathJaxConfig = { source: '', id: '' };
protected mathJaxFallback: MathJaxConfig = { source: '', id: '' };

protected registerMathJaxAsync(config: MathJaxConfig): Promise<any> {
return Promise.resolve();
}

ready(): Observable<boolean> {
return of(true);
}

render(element: HTMLElement): void {
return;
}
}

describe('MathService', () => {
let service: MockMathService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = new MockMathService();
spyOn(service, 'render');
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('should be ready', (done) => {
service.ready().subscribe(isReady => {
expect(isReady).toBe(true);
done();
});
});

it('should render', () => {
service.render(document.createElement('div'));
expect(service.render).toHaveBeenCalled();
});
});
19 changes: 19 additions & 0 deletions src/app/core/shared/math.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Observable } from 'rxjs';

export interface MathJaxConfig {
source: string;
id: string;
}

/**
* This service is used to provide the MathJax library with the ability to render markdown code
*/
export abstract class MathService {
protected abstract mathJaxOptions: any;
protected abstract mathJax: MathJaxConfig;
protected abstract mathJaxFallback: MathJaxConfig;

protected abstract registerMathJaxAsync(config: MathJaxConfig): Promise<any>;
abstract ready(): Observable<boolean>;
abstract render(element: HTMLElement): void;
}
44 changes: 44 additions & 0 deletions src/app/core/shared/server-math.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Injectable } from '@angular/core';
import { Observable, ReplaySubject, Subject } from 'rxjs';
import { MathJaxConfig, MathService } from './math.service';

@Injectable({
providedIn: 'root'
})
/**
* Provide the MathService for SSR
*/
export class ServerMathService extends MathService {

protected signal: Subject<boolean>;

protected mathJaxOptions = {};

protected mathJax: MathJaxConfig = {
source: '',
id: ''
};
protected mathJaxFallback: MathJaxConfig = {
source: '',
id: ''
};

constructor() {
super();

this.signal = new ReplaySubject<boolean>();
this.signal.next(true);
}

protected async registerMathJaxAsync(config: MathJaxConfig): Promise<any> {
return Promise.resolve();
}

ready(): Observable<boolean> {
return this.signal;
}

render(element: HTMLElement) {
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('AdvancedAttachmentComponent', () => {
{ provide: 'fieldProvider', useValue: mockField },
{ provide: 'itemProvider', useValue: testItem },
{ provide: 'renderingSubTypeProvider', useValue: '' },
{ provide: 'tabNameProvider', useValue: '' },
{ provide: BitstreamDataService, useValue: mockBitstreamDataService },
{ provide: AuthorizationDataService, useValue: mockAuthorizedService },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export class AdvancedAttachmentComponent extends AttachmentComponent implements
@Inject('fieldProvider') public fieldProvider: LayoutField,
@Inject('itemProvider') public itemProvider: Item,
@Inject('renderingSubTypeProvider') public renderingSubTypeProvider: string,
@Inject('tabNameProvider') public tabNameProvider: string,
protected bitstreamDataService: BitstreamDataService,
protected translateService: TranslateService
) {
super(fieldProvider, itemProvider, renderingSubTypeProvider, bitstreamDataService, translateService);
super(fieldProvider, itemProvider, renderingSubTypeProvider, tabNameProvider, bitstreamDataService, translateService);
}

getBitstreamsByItem(options?: FindListOptions): Observable<PaginatedList<Bitstream>> {
Expand Down
Loading

0 comments on commit 97c09a6

Please sign in to comment.