mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge branch 'memory-leak-fixes_contribute-7.6' into generify-component-loaders_contribute-main
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, ComponentFactoryResolver, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { Component, ComponentRef, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||
import { Item } from '../../../../../core/shared/item.model';
|
||||
import { ViewMode } from '../../../../../core/shared/view-mode.model';
|
||||
import {
|
||||
@@ -14,6 +14,7 @@ import { GenericConstructor } from '../../../../../core/shared/generic-construct
|
||||
import { DynamicComponentLoaderDirective } from '../../../../../shared/abstract-component-loader/dynamic-component-loader.directive';
|
||||
import { ThemeService } from '../../../../../shared/theme-support/theme.service';
|
||||
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
|
||||
import { hasValue } from '../../../../../shared/empty.util';
|
||||
|
||||
@listableObjectComponent(ItemSearchResult, ViewMode.GridElement, Context.AdminSearch)
|
||||
@Component({
|
||||
@@ -24,17 +25,18 @@ import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service
|
||||
/**
|
||||
* The component for displaying a list element for an item search result on the admin search page
|
||||
*/
|
||||
export class ItemAdminSearchResultGridElementComponent extends SearchResultGridElementComponent<ItemSearchResult, Item> implements OnInit {
|
||||
export class ItemAdminSearchResultGridElementComponent extends SearchResultGridElementComponent<ItemSearchResult, Item> implements OnDestroy, OnInit {
|
||||
@ViewChild(DynamicComponentLoaderDirective, { static: true }) dynamicComponentLoaderDirective: DynamicComponentLoaderDirective;
|
||||
@ViewChild('badges', { static: true }) badges: ElementRef;
|
||||
@ViewChild('buttons', { static: true }) buttons: ElementRef;
|
||||
|
||||
protected compRef: ComponentRef<Component>;
|
||||
|
||||
constructor(
|
||||
public dsoNameService: DSONameService,
|
||||
protected truncatableService: TruncatableService,
|
||||
protected bitstreamDataService: BitstreamDataService,
|
||||
private themeService: ThemeService,
|
||||
private componentFactoryResolver: ComponentFactoryResolver,
|
||||
) {
|
||||
super(dsoNameService, truncatableService, bitstreamDataService);
|
||||
}
|
||||
@@ -44,23 +46,32 @@ export class ItemAdminSearchResultGridElementComponent extends SearchResultGridE
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.getComponent());
|
||||
const component: GenericConstructor<Component> = this.getComponent();
|
||||
|
||||
const viewContainerRef = this.dynamicComponentLoaderDirective.viewContainerRef;
|
||||
viewContainerRef.clear();
|
||||
|
||||
const componentRef = viewContainerRef.createComponent(
|
||||
componentFactory,
|
||||
0,
|
||||
undefined,
|
||||
[
|
||||
this.compRef = viewContainerRef.createComponent(
|
||||
component, {
|
||||
index: 0,
|
||||
injector: undefined,
|
||||
projectableNodes: [
|
||||
[this.badges.nativeElement],
|
||||
[this.buttons.nativeElement]
|
||||
]);
|
||||
(componentRef.instance as any).object = this.object;
|
||||
(componentRef.instance as any).index = this.index;
|
||||
(componentRef.instance as any).linkType = this.linkType;
|
||||
(componentRef.instance as any).listID = this.listID;
|
||||
[this.buttons.nativeElement],
|
||||
],
|
||||
},
|
||||
);
|
||||
this.compRef.setInput('object',this.object);
|
||||
this.compRef.setInput('index', this.index);
|
||||
this.compRef.setInput('linkType', this.linkType);
|
||||
this.compRef.setInput('listID', this.listID);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (hasValue(this.compRef)) {
|
||||
this.compRef.destroy();
|
||||
this.compRef = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Component, ComponentFactoryResolver, ElementRef, ViewChild } from '@angular/core';
|
||||
import { Component, ElementRef, ViewChild, ComponentRef, OnDestroy, OnInit } from '@angular/core';
|
||||
import { Item } from '../../../../../core/shared/item.model';
|
||||
import { ViewMode } from '../../../../../core/shared/view-mode.model';
|
||||
import {
|
||||
@@ -24,6 +24,7 @@ import { take } from 'rxjs/operators';
|
||||
import { WorkflowItemSearchResult } from '../../../../../shared/object-collection/shared/workflow-item-search-result.model';
|
||||
import { ThemeService } from '../../../../../shared/theme-support/theme.service';
|
||||
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
|
||||
import { hasValue } from '../../../../../shared/empty.util';
|
||||
|
||||
@listableObjectComponent(WorkflowItemSearchResult, ViewMode.GridElement, Context.AdminWorkflowSearch)
|
||||
@Component({
|
||||
@@ -34,7 +35,7 @@ import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service
|
||||
/**
|
||||
* The component for displaying a grid element for an workflow item on the admin workflow search page
|
||||
*/
|
||||
export class WorkflowItemSearchResultAdminWorkflowGridElementComponent extends SearchResultGridElementComponent<WorkflowItemSearchResult, WorkflowItem> {
|
||||
export class WorkflowItemSearchResultAdminWorkflowGridElementComponent extends SearchResultGridElementComponent<WorkflowItemSearchResult, WorkflowItem> implements OnDestroy, OnInit {
|
||||
/**
|
||||
* Directive used to render the dynamic component in
|
||||
*/
|
||||
@@ -55,9 +56,10 @@ export class WorkflowItemSearchResultAdminWorkflowGridElementComponent extends S
|
||||
*/
|
||||
public item$: Observable<Item>;
|
||||
|
||||
protected compRef: ComponentRef<Component>;
|
||||
|
||||
constructor(
|
||||
public dsoNameService: DSONameService,
|
||||
private componentFactoryResolver: ComponentFactoryResolver,
|
||||
private linkService: LinkService,
|
||||
protected truncatableService: TruncatableService,
|
||||
private themeService: ThemeService,
|
||||
@@ -75,26 +77,34 @@ export class WorkflowItemSearchResultAdminWorkflowGridElementComponent extends S
|
||||
this.dso = this.linkService.resolveLink(this.dso, followLink('item'));
|
||||
this.item$ = (this.dso.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload());
|
||||
this.item$.pipe(take(1)).subscribe((item: Item) => {
|
||||
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.getComponent(item));
|
||||
const component: GenericConstructor<Component> = this.getComponent(item);
|
||||
|
||||
const viewContainerRef = this.dynamicComponentLoaderDirective.viewContainerRef;
|
||||
viewContainerRef.clear();
|
||||
|
||||
const componentRef = viewContainerRef.createComponent(
|
||||
componentFactory,
|
||||
0,
|
||||
undefined,
|
||||
[
|
||||
this.compRef = viewContainerRef.createComponent(
|
||||
component, {
|
||||
index: 0,
|
||||
injector: undefined,
|
||||
projectableNodes: [
|
||||
[this.badges.nativeElement],
|
||||
[this.buttons.nativeElement]
|
||||
]);
|
||||
(componentRef.instance as any).object = item;
|
||||
(componentRef.instance as any).index = this.index;
|
||||
(componentRef.instance as any).linkType = this.linkType;
|
||||
(componentRef.instance as any).listID = this.listID;
|
||||
componentRef.changeDetectorRef.detectChanges();
|
||||
}
|
||||
[this.buttons.nativeElement],
|
||||
],
|
||||
},
|
||||
);
|
||||
this.compRef.setInput('object', item);
|
||||
this.compRef.setInput('index', this.index);
|
||||
this.compRef.setInput('linkType', this.linkType);
|
||||
this.compRef.setInput('listID', this.listID);
|
||||
this.compRef.changeDetectorRef.detectChanges();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (hasValue(this.compRef)) {
|
||||
this.compRef.destroy();
|
||||
this.compRef = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Component, ComponentFactoryResolver, ElementRef, ViewChild, OnInit } from '@angular/core';
|
||||
import { Component, ElementRef, ViewChild, OnInit, OnDestroy, ComponentRef } from '@angular/core';
|
||||
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { map, mergeMap, take, tap } from 'rxjs/operators';
|
||||
@@ -35,6 +35,7 @@ import { SupervisionOrder } from '../../../../../core/supervision-order/models/s
|
||||
import { PaginatedList } from '../../../../../core/data/paginated-list.model';
|
||||
import { SupervisionOrderDataService } from '../../../../../core/supervision-order/supervision-order-data.service';
|
||||
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
|
||||
import { hasValue } from '../../../../../shared/empty.util';
|
||||
|
||||
@listableObjectComponent(WorkspaceItemSearchResult, ViewMode.GridElement, Context.AdminWorkflowSearch)
|
||||
@Component({
|
||||
@@ -45,7 +46,7 @@ import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service
|
||||
/**
|
||||
* The component for displaying a grid element for an workflow item on the admin workflow search page
|
||||
*/
|
||||
export class WorkspaceItemSearchResultAdminWorkflowGridElementComponent extends SearchResultGridElementComponent<WorkspaceItemSearchResult, WorkspaceItem> implements OnInit {
|
||||
export class WorkspaceItemSearchResultAdminWorkflowGridElementComponent extends SearchResultGridElementComponent<WorkspaceItemSearchResult, WorkspaceItem> implements OnDestroy, OnInit {
|
||||
|
||||
/**
|
||||
* The item linked to the workspace item
|
||||
@@ -77,9 +78,13 @@ export class WorkspaceItemSearchResultAdminWorkflowGridElementComponent extends
|
||||
*/
|
||||
@ViewChild('buttons', { static: true }) buttons: ElementRef;
|
||||
|
||||
/**
|
||||
* The reference to the dynamic component
|
||||
*/
|
||||
protected compRef: ComponentRef<Component>;
|
||||
|
||||
constructor(
|
||||
public dsoNameService: DSONameService,
|
||||
private componentFactoryResolver: ComponentFactoryResolver,
|
||||
private linkService: LinkService,
|
||||
protected truncatableService: TruncatableService,
|
||||
private themeService: ThemeService,
|
||||
@@ -98,24 +103,24 @@ export class WorkspaceItemSearchResultAdminWorkflowGridElementComponent extends
|
||||
this.dso = this.linkService.resolveLink(this.dso, followLink('item'));
|
||||
this.item$ = (this.dso.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload());
|
||||
this.item$.pipe(take(1)).subscribe((item: Item) => {
|
||||
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.getComponent(item));
|
||||
const component: GenericConstructor<Component> = this.getComponent(item);
|
||||
|
||||
const viewContainerRef = this.dynamicComponentLoaderDirective.viewContainerRef;
|
||||
viewContainerRef.clear();
|
||||
|
||||
const componentRef = viewContainerRef.createComponent(
|
||||
componentFactory,
|
||||
0,
|
||||
undefined,
|
||||
[
|
||||
this.compRef = viewContainerRef.createComponent(
|
||||
component, {
|
||||
index: 0,
|
||||
projectableNodes: [
|
||||
[this.badges.nativeElement],
|
||||
[this.buttons.nativeElement]
|
||||
]);
|
||||
(componentRef.instance as any).object = item;
|
||||
(componentRef.instance as any).index = this.index;
|
||||
(componentRef.instance as any).linkType = this.linkType;
|
||||
(componentRef.instance as any).listID = this.listID;
|
||||
componentRef.changeDetectorRef.detectChanges();
|
||||
],
|
||||
});
|
||||
this.compRef.setInput('object', item);
|
||||
this.compRef.setInput('index', this.index);
|
||||
this.compRef.setInput('linkType', this.linkType);
|
||||
this.compRef.setInput('listID', this.listID);
|
||||
this.compRef.changeDetectorRef.detectChanges();
|
||||
}
|
||||
);
|
||||
|
||||
@@ -128,6 +133,13 @@ export class WorkspaceItemSearchResultAdminWorkflowGridElementComponent extends
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (hasValue(this.compRef)) {
|
||||
this.compRef.destroy();
|
||||
this.compRef = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the component depending on the item's entity type, view mode and context
|
||||
* @returns {GenericConstructor<Component>}
|
||||
|
@@ -85,6 +85,7 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC
|
||||
this.subs
|
||||
.filter((subscription: Subscription) => hasValue(subscription))
|
||||
.forEach((subscription: Subscription) => subscription.unsubscribe());
|
||||
this.destroyComponentInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
ComponentFactoryResolver,
|
||||
ComponentRef,
|
||||
Directive,
|
||||
Input,
|
||||
@@ -12,6 +11,7 @@ import { PlacementArray } from '@ng-bootstrap/ng-bootstrap/util/positioning';
|
||||
import { ContextHelpWrapperComponent } from './context-help-wrapper/context-help-wrapper.component';
|
||||
import { PlacementDir } from './context-help-wrapper/placement-dir.model';
|
||||
import { ContextHelpService } from './context-help.service';
|
||||
import { hasValue } from './empty.util';
|
||||
|
||||
export interface ContextHelpDirectiveInput {
|
||||
content: string;
|
||||
@@ -43,7 +43,6 @@ export class ContextHelpDirective implements OnChanges, OnDestroy {
|
||||
constructor(
|
||||
private templateRef: TemplateRef<any>,
|
||||
private viewContainerRef: ViewContainerRef,
|
||||
private componentFactoryResolver: ComponentFactoryResolver,
|
||||
private contextHelpService: ContextHelpService
|
||||
) {}
|
||||
|
||||
@@ -53,19 +52,21 @@ export class ContextHelpDirective implements OnChanges, OnDestroy {
|
||||
this.contextHelpService.add({id: this.dsContextHelp.id, isTooltipVisible: false});
|
||||
|
||||
if (this.wrapper === undefined) {
|
||||
const factory
|
||||
= this.componentFactoryResolver.resolveComponentFactory(ContextHelpWrapperComponent);
|
||||
this.wrapper = this.viewContainerRef.createComponent(factory);
|
||||
this.wrapper = this.viewContainerRef.createComponent(ContextHelpWrapperComponent);
|
||||
}
|
||||
this.wrapper.instance.templateRef = this.templateRef;
|
||||
this.wrapper.instance.content = this.dsContextHelp.content;
|
||||
this.wrapper.instance.id = this.dsContextHelp.id;
|
||||
this.wrapper.instance.tooltipPlacement = this.dsContextHelp.tooltipPlacement;
|
||||
this.wrapper.instance.iconPlacement = this.dsContextHelp.iconPlacement;
|
||||
this.wrapper.setInput('templateRef', this.templateRef);
|
||||
this.wrapper.setInput('content', this.dsContextHelp.content);
|
||||
this.wrapper.setInput('id', this.dsContextHelp.id);
|
||||
this.wrapper.setInput('tooltipPlacement', this.dsContextHelp.tooltipPlacement);
|
||||
this.wrapper.setInput('iconPlacement', this.dsContextHelp.iconPlacement);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.clearMostRecentId();
|
||||
if (hasValue(this.wrapper)) {
|
||||
this.wrapper.destroy();
|
||||
this.wrapper = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private clearMostRecentId(): void {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Component, Input, ComponentFactoryResolver, ChangeDetectorRef } from '@angular/core';
|
||||
import { Component, Input, ChangeDetectorRef } from '@angular/core';
|
||||
import { ThemedComponent } from '../theme-support/themed.component';
|
||||
import { LoadingComponent } from './loading.component';
|
||||
import { ThemeService } from '../theme-support/theme.service';
|
||||
@@ -20,11 +20,10 @@ export class ThemedLoadingComponent extends ThemedComponent<LoadingComponent> {
|
||||
protected inAndOutputNames: (keyof LoadingComponent & keyof this)[] = ['message', 'showMessage', 'spinner'];
|
||||
|
||||
constructor(
|
||||
protected resolver: ComponentFactoryResolver,
|
||||
protected cdr: ChangeDetectorRef,
|
||||
protected themeService: ThemeService
|
||||
) {
|
||||
super(resolver, cdr, themeService);
|
||||
super(cdr, themeService);
|
||||
}
|
||||
|
||||
protected getComponentName(): string {
|
||||
|
@@ -6,7 +6,6 @@ import {
|
||||
ComponentRef,
|
||||
SimpleChanges,
|
||||
OnDestroy,
|
||||
ComponentFactoryResolver,
|
||||
ChangeDetectorRef,
|
||||
OnChanges,
|
||||
HostBinding,
|
||||
@@ -47,7 +46,6 @@ export abstract class ThemedComponent<T> implements AfterViewInit, OnDestroy, On
|
||||
@HostBinding('attr.data-used-theme') usedTheme: string;
|
||||
|
||||
constructor(
|
||||
protected resolver: ComponentFactoryResolver,
|
||||
protected cdr: ChangeDetectorRef,
|
||||
protected themeService: ThemeService,
|
||||
) {
|
||||
@@ -118,8 +116,9 @@ export abstract class ThemedComponent<T> implements AfterViewInit, OnDestroy, On
|
||||
|
||||
this.lazyLoadSub = this.lazyLoadObs.subscribe(([simpleChanges, constructor]: [SimpleChanges, GenericConstructor<T>]) => {
|
||||
this.destroyComponentInstance();
|
||||
const factory = this.resolver.resolveComponentFactory(constructor);
|
||||
this.compRef = this.vcr.createComponent(factory, undefined, undefined, [this.themedElementContent.nativeElement.childNodes]);
|
||||
this.compRef = this.vcr.createComponent(constructor, {
|
||||
projectableNodes: [this.themedElementContent.nativeElement.childNodes],
|
||||
});
|
||||
if (hasValue(simpleChanges)) {
|
||||
this.ngOnChanges(simpleChanges);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user