Skip to content

Commit 95f0976

Browse files
authored
Merge pull request DSpace#1942 from atmire/w2p-96062_theme-external-source-entry-import-modal-component
make the ExternalSourceEntryImportModalComponent themeable by default
2 parents 7b1a8f8 + efd3600 commit 95f0976

9 files changed

Lines changed: 89 additions & 23 deletions

File tree

src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/dynamic-lookup-relation-external-source-tab.component.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { DsDynamicLookupRelationExternalSourceTabComponent } from './dynamic-lookup-relation-external-source-tab.component';
1+
import {
2+
DsDynamicLookupRelationExternalSourceTabComponent
3+
} from './dynamic-lookup-relation-external-source-tab.component';
24
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
35
import { VarDirective } from '../../../../../utils/var.directive';
46
import { TranslateModule } from '@ngx-translate/core';
57
import { RouterTestingModule } from '@angular/router/testing';
68
import { EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core';
79
import { PaginatedSearchOptions } from '../../../../../search/models/paginated-search-options.model';
810
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
9-
import { of as observableOf } from 'rxjs';
11+
import { of as observableOf, EMPTY } from 'rxjs';
1012
import {
1113
createFailedRemoteDataObject$,
1214
createPendingRemoteDataObject$,
@@ -22,11 +24,13 @@ import { SelectableListService } from '../../../../../object-list/selectable-lis
2224
import { Item } from '../../../../../../core/shared/item.model';
2325
import { Collection } from '../../../../../../core/shared/collection.model';
2426
import { RelationshipOptions } from '../../../models/relationship-options.model';
25-
import { ExternalSourceEntryImportModalComponent } from './external-source-entry-import-modal/external-source-entry-import-modal.component';
2627
import { createPaginatedList } from '../../../../../testing/utils.test';
2728
import { PaginationService } from '../../../../../../core/pagination/pagination.service';
2829
import { PaginationServiceStub } from '../../../../../testing/pagination-service.stub';
2930
import { ItemType } from '../../../../../../core/shared/item-relationships/item-type.model';
31+
import {
32+
ThemedExternalSourceEntryImportModalComponent
33+
} from './external-source-entry-import-modal/themed-external-source-entry-import-modal.component';
3034

3135
describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
3236
let component: DsDynamicLookupRelationExternalSourceTabComponent;
@@ -187,12 +191,13 @@ describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
187191

188192
describe('import', () => {
189193
beforeEach(() => {
190-
spyOn(modalService, 'open').and.returnValue(Object.assign({ componentInstance: Object.assign({ importedObject: new EventEmitter<any>() }) }));
194+
spyOn(modalService, 'open').and.returnValue(Object.assign({ componentInstance: Object.assign({ importedObject: new EventEmitter<any>(), compRef$: EMPTY }) }));
195+
component.modalRef = modalService.open(ThemedExternalSourceEntryImportModalComponent, { size: 'lg', container: 'ds-dynamic-lookup-relation-modal' });
191196
component.import(externalEntries[0]);
192197
});
193198

194199
it('should open a new ExternalSourceEntryImportModalComponent', () => {
195-
expect(modalService.open).toHaveBeenCalledWith(ExternalSourceEntryImportModalComponent, jasmine.any(Object));
200+
expect(modalService.open).toHaveBeenCalledWith(ThemedExternalSourceEntryImportModalComponent, jasmine.any(Object));
196201
});
197202
});
198203
});

src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/dynamic-lookup-relation-external-source-tab.component.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
1+
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, ComponentRef } from '@angular/core';
22
import { SEARCH_CONFIG_SERVICE } from '../../../../../../my-dspace-page/my-dspace-page.component';
33
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
44
import { Router } from '@angular/router';
@@ -16,7 +16,8 @@ import { PaginationComponentOptions } from '../../../../../pagination/pagination
1616
import { RelationshipOptions } from '../../../models/relationship-options.model';
1717
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
1818
import { ExternalSourceEntryImportModalComponent } from './external-source-entry-import-modal/external-source-entry-import-modal.component';
19-
import { hasValue } from '../../../../../empty.util';
19+
import { ThemedExternalSourceEntryImportModalComponent } from './external-source-entry-import-modal/themed-external-source-entry-import-modal.component';
20+
import { hasValue, hasValueOperator } from '../../../../../empty.util';
2021
import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service';
2122
import { Item } from '../../../../../../core/shared/item.model';
2223
import { Collection } from '../../../../../../core/shared/collection.model';
@@ -114,9 +115,9 @@ export class DsDynamicLookupRelationExternalSourceTabComponent implements OnInit
114115
modalRef: NgbModalRef;
115116

116117
/**
117-
* Subscription to the modal's importedObject event-emitter
118+
* Array to track all subscriptions and unsubscribe them onDestroy
118119
*/
119-
importObjectSub: Subscription;
120+
protected subs: Subscription[] = [];
120121

121122
/**
122123
* The entity types compatible with the given external source
@@ -161,30 +162,40 @@ export class DsDynamicLookupRelationExternalSourceTabComponent implements OnInit
161162
* @param entry The entry to import
162163
*/
163164
import(entry) {
164-
this.modalRef = this.modalService.open(ExternalSourceEntryImportModalComponent, {
165+
this.modalRef = this.modalService.open(ThemedExternalSourceEntryImportModalComponent, {
165166
size: 'lg',
166167
container: 'ds-dynamic-lookup-relation-modal'
167168
});
168-
const modalComp = this.modalRef.componentInstance;
169-
modalComp.externalSourceEntry = entry;
170-
modalComp.item = this.item;
171-
modalComp.collection = this.collection;
172-
modalComp.relationship = this.relationship;
173-
modalComp.label = this.label;
174-
modalComp.relatedEntityType = this.relatedEntityType;
175-
this.importObjectSub = modalComp.importedObject.subscribe((object) => {
169+
170+
const modalComp$ = this.modalRef.componentInstance.compRef$.pipe(
171+
hasValueOperator(),
172+
map((compRef: ComponentRef<ExternalSourceEntryImportModalComponent>) => compRef.instance)
173+
);
174+
175+
this.subs.push(modalComp$.subscribe((modalComp: ExternalSourceEntryImportModalComponent) => {
176+
modalComp.externalSourceEntry = entry;
177+
modalComp.item = this.item;
178+
// modalComp.collection = this.collection;
179+
modalComp.relationship = this.relationship;
180+
modalComp.label = this.label;
181+
modalComp.relatedEntityType = this.relatedEntityType;
182+
}));
183+
184+
this.subs.push(modalComp$.pipe(
185+
switchMap((modalComp: ExternalSourceEntryImportModalComponent) => modalComp.importedObject)
186+
).subscribe((object) => {
176187
this.selectableListService.selectSingle(this.listId, object);
177188
this.importedObject.emit(object);
178-
});
189+
}));
179190
}
180191

181192
/**
182193
* Unsubscribe from open subscriptions
183194
*/
184195
ngOnDestroy(): void {
185-
if (hasValue(this.importObjectSub)) {
186-
this.importObjectSub.unsubscribe();
187-
}
196+
this.subs
197+
.filter((sub) => hasValue(sub))
198+
.forEach((sub) => sub.unsubscribe());
188199
}
189200

190201
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ExternalSourceEntryImportModalComponent } from './external-source-entry-import-modal.component';
2+
import { ThemedComponent } from '../../../../../../theme-support/themed.component';
3+
import { Component } from '@angular/core';
4+
5+
@Component({
6+
selector: 'ds-themed-external-source-entry-import-modal',
7+
styleUrls: [],
8+
templateUrl: '../../../../../../../shared/theme-support/themed.component.html',
9+
})
10+
export class ThemedExternalSourceEntryImportModalComponent extends ThemedComponent<ExternalSourceEntryImportModalComponent> {
11+
protected getComponentName(): string {
12+
return 'ExternalSourceEntryImportModalComponent';
13+
}
14+
15+
protected importThemedComponent(themeName: string): Promise<any> {
16+
return import(`../../../../../../../../themes/${themeName}/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component`);
17+
}
18+
19+
protected importUnthemedComponent(): Promise<any> {
20+
return import(`./external-source-entry-import-modal.component`);
21+
}
22+
}

src/app/shared/form/form.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { FormBuilderService } from './builder/form-builder.service';
3737
import { DsDynamicTypeBindRelationService } from './builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
3838
import { FormService } from './form.service';
3939
import { NgxMaskModule } from 'ngx-mask';
40+
import { ThemedExternalSourceEntryImportModalComponent } from './builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/themed-external-source-entry-import-modal.component';
4041

4142
const COMPONENTS = [
4243
CustomSwitchComponent,
@@ -64,6 +65,7 @@ const COMPONENTS = [
6465
ChipsComponent,
6566
NumberPickerComponent,
6667
VocabularyTreeviewComponent,
68+
ThemedExternalSourceEntryImportModalComponent
6769
];
6870

6971
const DIRECTIVES = [

src/app/shared/theme-support/themed.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
OnChanges
1212
} from '@angular/core';
1313
import { hasValue, isNotEmpty } from '../empty.util';
14-
import { from as fromPromise, Observable, of as observableOf, Subscription } from 'rxjs';
14+
import { from as fromPromise, Observable, of as observableOf, Subscription, BehaviorSubject } from 'rxjs';
1515
import { ThemeService } from './theme.service';
1616
import { catchError, switchMap, map } from 'rxjs/operators';
1717
import { GenericConstructor } from '../../core/shared/generic-constructor';
@@ -25,6 +25,12 @@ export abstract class ThemedComponent<T> implements OnInit, OnDestroy, OnChanges
2525
@ViewChild('vcr', { read: ViewContainerRef }) vcr: ViewContainerRef;
2626
protected compRef: ComponentRef<T>;
2727

28+
/**
29+
* A reference to the themed component. Will start as undefined and emit every time the themed
30+
* component is rendered
31+
*/
32+
public compRef$: BehaviorSubject<ComponentRef<T>> = new BehaviorSubject(undefined);
33+
2834
protected lazyLoadSub: Subscription;
2935
protected themeSub: Subscription;
3036

@@ -90,6 +96,7 @@ export abstract class ThemedComponent<T> implements OnInit, OnDestroy, OnChanges
9096
const factory = this.resolver.resolveComponentFactory(constructor);
9197
this.compRef = this.vcr.createComponent(factory);
9298
this.connectInputsAndOutputs();
99+
this.compRef$.next(this.compRef);
93100
this.cdr.markForCheck();
94101
});
95102
}

src/themes/custom/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.html

Whitespace-only changes.

src/themes/custom/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
ExternalSourceEntryImportModalComponent as BaseComponent
3+
} from '../../../../../../../../../../app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component';
4+
import { Component } from '@angular/core';
5+
6+
@Component({
7+
selector: 'ds-external-source-entry-import-modal',
8+
styleUrls: ['../../../../../../../../../../app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.scss'],
9+
// styleUrls: ['./external-source-entry-import-modal.component.scss'],
10+
templateUrl: '../../../../../../../../../../app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.html',
11+
// templateUrl: './external-source-entry-import-modal.component.html'
12+
})
13+
export class ExternalSourceEntryImportModalComponent extends BaseComponent {
14+
15+
}

src/themes/custom/lazy-theme.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ import { ObjectListComponent } from './app/shared/object-list/object-list.compon
114114
import { BrowseByMetadataPageComponent } from './app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component';
115115
import { BrowseByDatePageComponent } from './app/browse-by/browse-by-date-page/browse-by-date-page.component';
116116
import { BrowseByTitlePageComponent } from './app/browse-by/browse-by-title-page/browse-by-title-page.component';
117+
import {
118+
ExternalSourceEntryImportModalComponent
119+
} from './app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component';
117120

118121
const DECLARATIONS = [
119122
FileSectionComponent,
@@ -168,6 +171,7 @@ const DECLARATIONS = [
168171
BrowseByMetadataPageComponent,
169172
BrowseByDatePageComponent,
170173
BrowseByTitlePageComponent,
174+
ExternalSourceEntryImportModalComponent,
171175

172176

173177
];

0 commit comments

Comments
 (0)