Skip to content

Commit da98bc5

Browse files
committed
Merged ux-plus-2023_02_x into UXP-132
2 parents 03644e0 + bbc336a commit da98bc5

27 files changed

Lines changed: 335 additions & 85 deletions

src/app/core/shared/client-math.service.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
import { Injectable } from '@angular/core';
1+
import { DOCUMENT } from '@angular/common';
2+
import {
3+
Inject,
4+
Injectable,
5+
} from '@angular/core';
26
import { Observable, ReplaySubject, Subject } from 'rxjs';
37
import { environment } from 'src/environments/environment';
4-
import { MathJaxConfig, MathService } from './math.service';
8+
import {
9+
NativeWindowRef,
10+
NativeWindowService,
11+
} from '../services/window.service';import { MathJaxConfig, MathService } from './math.service';
512

613
@Injectable({
714
providedIn: 'root'
815
})
16+
/**
17+
* Provide the MathService for CSR
18+
*/
919
export class ClientMathService extends MathService {
1020

1121
protected isReady$: Subject<boolean>;
@@ -31,7 +41,10 @@ export class ClientMathService extends MathService {
3141
id: 'MathJaxBackupScript'
3242
};
3343

34-
constructor() {
44+
constructor(
45+
@Inject(DOCUMENT) private _document: Document,
46+
@Inject(NativeWindowService) protected _window: NativeWindowRef,
47+
) {
3548
super();
3649

3750
this.isReady$ = new ReplaySubject<boolean>();
@@ -44,36 +57,49 @@ export class ClientMathService extends MathService {
4457
});
4558
}
4659

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

51-
const optionsScript: HTMLScriptElement = document.createElement('script');
69+
const optionsScript: HTMLScriptElement = this._document.createElement('script');
5270
optionsScript.type = 'text/javascript';
5371
optionsScript.text = `MathJax = ${JSON.stringify(this.mathJaxOptions)};`;
54-
document.head.appendChild(optionsScript);
72+
this._document.head.appendChild(optionsScript);
5573

56-
const script: HTMLScriptElement = document.createElement('script');
74+
const script: HTMLScriptElement = this._document.createElement('script');
5775
script.id = config.id;
5876
script.type = 'text/javascript';
5977
script.src = config.source;
6078
script.crossOrigin = 'anonymous';
6179
script.async = true;
6280
script.onload = () => resolve();
6381
script.onerror = error => reject(error);
64-
document.head.appendChild(script);
82+
this._document.head.appendChild(script);
6583
});
6684
}
6785
return Promise.resolve();
6886
}
6987

88+
/**
89+
* Return the status of the script registration
90+
*/
7091
ready(): Observable<boolean> {
7192
return this.isReady$;
7293
}
7394

95+
/**
96+
* Render the specified element using the MathJax JavaScript
97+
*
98+
* @param element The element to render with MathJax
99+
*/
74100
render(element: HTMLElement) {
75101
if (environment.markdown.mathjax) {
76-
(window as any).MathJax.typesetPromise([element]);
102+
this._window.nativeWindow.MathJax.typesetPromise([element]);
77103
}
78104
}
79105
}

src/app/core/shared/math.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export interface MathJaxConfig {
55
id: string;
66
}
77

8+
/**
9+
* This service is used to provide the MathJax library with the ability to render markdown code
10+
*/
811
export abstract class MathService {
912
protected abstract mathJaxOptions: any;
1013
protected abstract mathJax: MathJaxConfig;

src/app/core/shared/server-math.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { MathJaxConfig, MathService } from './math.service';
55
@Injectable({
66
providedIn: 'root'
77
})
8+
/**
9+
* Provide the MathService for SSR
10+
*/
811
export class ServerMathService extends MathService {
912

1013
protected signal: Subject<boolean>;

src/app/cris-layout/enums/layout-box.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export enum LayoutBox {
1616
IIIFTOOLBAR = 'IIIFTOOLBAR',
1717
VIDEOVIEWER = 'VIDEOVIEWER',
1818
COLLECTIONS = 'COLLECTIONS',
19+
VERSIONING = 'VERSIONING',
1920
}

src/app/item-page/item-page.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ import { ThemedItemAlertsComponent } from './alerts/themed-item-alerts.component
6161
import {
6262
ThemedFullFileSectionComponent
6363
} from './full/field-components/file-section/themed-full-file-section.component';
64-
import { UnpaywallVersionsComponent } from './unpaywall-versions/unpaywall-versions.component';
6564
import { MarkdownViewerModule } from '../shared/markdown-viewer/markdown-viewer.module';
65+
import { UnpaywallVersionsComponent } from './unpaywall-versions/unpaywall-versions.component';
6666

6767

6868
const ENTRY_COMPONENTS = [

src/app/item-page/simple/item-page.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<div
33
[ngClass]="{'container': (itemRD?.hasSucceeded && !itemRD?.hasNoContent) && tabsRD?.payload?.pageInfo?.totalElements < 1}"
44
*ngVar="(itemRD$ | async) as itemRD">
5+
<div class="py-1" [ngClass]="{'container': (itemRD?.hasSucceeded && !itemRD?.hasNoContent) && tabsRD?.payload?.pageInfo?.totalElements > 0}">
6+
<ds-item-versions-notice [item]="itemRD?.payload" ></ds-item-versions-notice>
7+
</div>
58
<div class="item-page" *ngIf="(itemRD?.hasSucceeded && !itemRD?.hasNoContent) && tabsRD?.payload?.pageInfo?.totalElements < 1" @fadeInOut>
69
<div *ngIf="itemRD?.payload as item">
710
<ds-themed-item-alerts [item]="item"></ds-themed-item-alerts>

src/app/item-page/versions/item-versions.component.spec.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Version } from '../../core/shared/version.model';
1010
import { VersionHistory } from '../../core/shared/version-history.model';
1111
import { VersionHistoryDataService } from '../../core/data/version-history-data.service';
1212
import { BrowserModule, By } from '@angular/platform-browser';
13-
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
13+
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
1414
import { createPaginatedList } from '../../shared/testing/utils.test';
1515
import { EMPTY, of, of as observableOf } from 'rxjs';
1616
import { PaginationService } from '../../core/pagination/pagination.service';
@@ -26,7 +26,7 @@ import { FeatureID } from '../../core/data/feature-authorization/feature-id';
2626
import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-data.service';
2727
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
2828
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
29-
import { Router } from '@angular/router';
29+
import { ActivatedRoute, Router } from '@angular/router';
3030
import { CommonModule } from '@angular/common';
3131
import { ItemSharedModule } from '../item-shared.module';
3232
import { UUIDService } from '../../core/shared/uuid.service';
@@ -135,6 +135,25 @@ describe('ItemVersionsComponent', () => {
135135
navigateByUrl: null,
136136
});
137137

138+
const mockItem = Object.assign(new Item(), {
139+
id: 'fake-id',
140+
uuid: 'fake-id',
141+
handle: 'fake/handle',
142+
lastModified: '2018',
143+
_links: {
144+
self: {
145+
href: 'https://localhost:8000/items/fake-id'
146+
}
147+
}
148+
});
149+
150+
const routeStub = {
151+
data: observableOf({
152+
dso: createSuccessfulRemoteDataObject(mockItem)
153+
}),
154+
children: []
155+
};
156+
138157
beforeEach(waitForAsync(() => {
139158

140159
TestBed.configureTestingModule({
@@ -153,7 +172,8 @@ describe('ItemVersionsComponent', () => {
153172
{provide: WorkflowItemDataService, useValue: workflowItemDataServiceSpy},
154173
{provide: ConfigurationDataService, useValue: configurationServiceSpy},
155174
{ provide: Router, useValue: routerSpy },
156-
{ provide: UUIDService, useValue: getMockUUIDService() }
175+
{ provide: UUIDService, useValue: getMockUUIDService() },
176+
{ provide: ActivatedRoute, useValue: routeStub },
157177
],
158178
schemas: [NO_ERRORS_SCHEMA]
159179
}).compileComponents();

src/app/item-page/versions/item-versions.component.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { TranslateService } from '@ngx-translate/core';
4040
import { ItemVersionsDeleteModalComponent } from './item-versions-delete-modal/item-versions-delete-modal.component';
4141
import { VersionDataService } from '../../core/data/version-data.service';
4242
import { ItemDataService } from '../../core/data/item-data.service';
43-
import { Router } from '@angular/router';
43+
import { ActivatedRoute, Router } from '@angular/router';
4444
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
4545
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
4646
import { ItemVersionsSharedService } from './item-versions-shared.service';
@@ -49,7 +49,11 @@ import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-da
4949
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
5050
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
5151
import { UUIDService } from '../../core/shared/uuid.service';
52+
import { RenderCrisLayoutBoxFor } from '../../cris-layout/decorators/cris-layout-box.decorator';
53+
import { LayoutBox } from '../../cris-layout/enums/layout-box.enum';
5254

55+
56+
@RenderCrisLayoutBoxFor(LayoutBox.VERSIONING)
5357
@Component({
5458
selector: 'ds-item-versions',
5559
templateUrl: './item-versions.component.html',
@@ -182,7 +186,8 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
182186
private workspaceItemDataService: WorkspaceitemDataService,
183187
private workflowItemDataService: WorkflowItemDataService,
184188
private configurationService: ConfigurationDataService,
185-
private uuidService: UUIDService
189+
private uuidService: UUIDService,
190+
private route: ActivatedRoute,
186191
) {
187192
}
188193

@@ -488,6 +493,21 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
488493
* Initialize all observables
489494
*/
490495
ngOnInit(): void {
496+
if (!hasValue(this.item)) {
497+
this.subs.push(this.route.data.pipe(
498+
map((data) => {
499+
return data.dso as RemoteData<Item>;
500+
}),
501+
getFirstCompletedRemoteData(),
502+
map(data => data.payload)
503+
).subscribe((item) => {
504+
this.item = item;
505+
this.ngOnInit();
506+
}));
507+
508+
return;
509+
}
510+
491511
if (hasValue(this.item.version)) {
492512
this.versionRD$ = this.item.version;
493513
this.versionHistoryRD$ = this.versionRD$.pipe(

src/app/shared/explore/explore.module.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import { ThemedSearchSectionComponent } from './section-component/search-section
2020
import { TextSectionComponent } from './section-component/text-section/text-section.component';
2121
import { ThemedTextSectionComponent } from './section-component/text-section/themed-text-section.component';
2222
import { SharedModule } from '../shared.module';
23+
import { MarkdownViewerModule } from '../markdown-viewer/markdown-viewer.module';
2324
import { CarouselSectionComponent } from './section-component/carousel-section/carousel-section.component';
2425
import { ThemedCarouselSectionComponent } from './section-component/carousel-section/themed-carousel-section.component';
2526
import { CarouselModule } from '../carousel/carousel.module';
26-
import { MarkdownViewerModule } from '../markdown-viewer/markdown-viewer.module';
2727
import { GridSectionComponent } from './section-component/grid-section/grid-section.component';
2828
import { ThemedGridSectionComponent } from './section-component/grid-section/themed-grid-section.component';
2929
import { TwitterSectionComponent } from './section-component/twitter-section/twitter-section.component';
@@ -56,12 +56,12 @@ const COMPONENTS = [
5656
declarations: [
5757
...COMPONENTS
5858
],
59-
imports: [
60-
CommonModule,
61-
SharedModule,
62-
CarouselModule,
63-
MarkdownViewerModule
64-
],
59+
imports: [
60+
CommonModule,
61+
SharedModule,
62+
MarkdownViewerModule,
63+
CarouselModule,
64+
],
6565
exports: [
6666
...COMPONENTS
6767
]
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
<div *ngIf="!spinner">
2-
<label *ngIf="showMessage && message">{{ message }}</label>
3-
<div class="loader">
4-
<span class="l-1"></span>
5-
<span class="l-2"></span>
6-
<span class="l-3"></span>
7-
<span class="l-4"></span>
8-
<span class="l-5"></span>
9-
<span class="l-6"></span>
10-
<span class="l-7"></span>
11-
<span class="l-8"></span>
12-
<span class="l-9"></span>
13-
<span class="l-10"></span>
14-
</div>
15-
</div>
16-
<div *ngIf='spinner' class="spinner spinner-border" role="status">
17-
<span class="sr-only">{{ message }}</span>
1+
<div [ngSwitch]="messageToShow">
2+
<ng-container *ngSwitchCase="MessageType.LOADING">
3+
<label *ngIf="message">{{ message }}</label>
4+
</ng-container>
5+
<ng-container *ngSwitchCase="MessageType.WARNING">
6+
<label *ngIf="warningMessage">{{ warningMessage }}</label>
7+
</ng-container>
8+
<ng-container *ngSwitchCase="MessageType.ERROR">
9+
<ds-alert *ngIf="errorMessage" [type]="AlertTypeEnum.Error" [content]="errorMessage"></ds-alert>
10+
</ng-container>
11+
<ng-container *ngIf="!spinner && messageToShow !== MessageType.ERROR">
12+
<div class="loader">
13+
<span class="l-1"></span>
14+
<span class="l-2"></span>
15+
<span class="l-3"></span>
16+
<span class="l-4"></span>
17+
<span class="l-5"></span>
18+
<span class="l-6"></span>
19+
<span class="l-7"></span>
20+
<span class="l-8"></span>
21+
<span class="l-9"></span>
22+
<span class="l-10"></span>
23+
</div>
24+
</ng-container>
25+
<ng-container *ngIf="spinner && messageToShow !== MessageType.ERROR" class="spinner spinner-border" role="status">
26+
<span class="sr-only">{{ message }}</span>
27+
</ng-container>
1828
</div>

0 commit comments

Comments
 (0)