[ADF-4745] memory leak fixes (#4931)

* fix app-layout component

* fix card-view component

* fix cloud-layout service

* code fixes

* code fixes

* even more fixes

* even more fixes

* lint fixes

* test fixes

* fix code

* remove useless pipes

* fix code owners

* enable spellcheck for cloud components

* update test

* update test
This commit is contained in:
Denys Vuika
2019-07-16 15:56:00 +01:00
committed by Eugenio Romano
parent e2311ab045
commit 1abb9bfc89
98 changed files with 1581 additions and 1066 deletions

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { Component, Input, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material';
import { MatDatetimepicker, DatetimeAdapter, MAT_DATETIME_FORMATS } from '@mat-datetimepicker/core';
import { MomentDatetimeAdapter, MAT_MOMENT_DATETIME_FORMATS } from '@mat-datetimepicker/moment';
@@ -27,6 +27,8 @@ import { UserPreferencesService, UserPreferenceValues } from '../../../services/
import { MomentDateAdapter } from '../../../utils/momentDateAdapter';
import { MOMENT_DATE_FORMATS } from '../../../utils/moment-date-formats.model';
import { AppConfigService } from '../../../app-config/app-config.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
providers: [
@@ -39,7 +41,7 @@ import { AppConfigService } from '../../../app-config/app-config.service';
templateUrl: './card-view-dateitem.component.html',
styleUrls: ['./card-view-dateitem.component.scss']
})
export class CardViewDateItemComponent implements OnInit {
export class CardViewDateItemComponent implements OnInit, OnDestroy {
@Input()
property: CardViewDateItemModel;
@@ -56,6 +58,8 @@ export class CardViewDateItemComponent implements OnInit {
valueDate: Moment;
dateFormat: string;
private onDestroy$ = new Subject<boolean>();
constructor(private cardViewUpdateService: CardViewUpdateService,
private dateAdapter: DateAdapter<Moment>,
private userPreferencesService: UserPreferencesService,
@@ -64,9 +68,10 @@ export class CardViewDateItemComponent implements OnInit {
}
ngOnInit() {
this.userPreferencesService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.dateAdapter.setLocale(locale);
});
this.userPreferencesService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.dateAdapter.setLocale(locale));
(<MomentDateAdapter> this.dateAdapter).overrideDisplayFormat = 'MMM DD';
@@ -75,6 +80,11 @@ export class CardViewDateItemComponent implements OnInit {
}
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
showProperty() {
return this.displayEmpty || !this.property.isEmpty();
}

View File

@@ -15,11 +15,13 @@
* limitations under the License.
*/
import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
import { Component, EventEmitter, Input, Output, ViewEncapsulation, OnInit, OnDestroy } from '@angular/core';
import { CommentModel } from '../models/comment.model';
import { EcmUserService } from '../userinfo/services/ecm-user.service';
import { PeopleProcessService } from '../services/people-process.service';
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-comment-list',
@@ -28,7 +30,7 @@ import { UserPreferencesService, UserPreferenceValues } from '../services/user-p
encapsulation: ViewEncapsulation.None
})
export class CommentListComponent {
export class CommentListComponent implements OnInit, OnDestroy {
/** The comments data used to populate the list. */
@Input()
@@ -39,15 +41,24 @@ export class CommentListComponent {
clickRow: EventEmitter<CommentModel> = new EventEmitter<CommentModel>();
selectedComment: CommentModel;
currentLocale;
private onDestroy$ = new Subject<boolean>();
constructor(public peopleProcessService: PeopleProcessService,
public ecmUserService: EcmUserService,
public userPreferenceService: UserPreferencesService) {
userPreferenceService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.currentLocale = locale;
});
}
ngOnInit() {
this.userPreferenceService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.currentLocale = locale);
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
selectComment(comment: CommentModel): void {

View File

@@ -27,8 +27,8 @@ import { DataColumn } from '../../data/data-column.model';
import { DataRow } from '../../data/data-row.model';
import { DataTableAdapter } from '../../data/datatable-adapter';
import { AlfrescoApiService } from '../../../services/alfresco-api.service';
import { Subscription, BehaviorSubject } from 'rxjs';
import { Node } from '@alfresco/js-api';
import { BehaviorSubject, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-datatable-cell',
@@ -77,21 +77,23 @@ export class DataTableCellComponent implements OnInit, OnDestroy {
@Input()
tooltip: string;
private sub: Subscription;
protected onDestroy$ = new Subject<boolean>();
constructor(protected alfrescoApiService: AlfrescoApiService) {}
ngOnInit() {
this.updateValue();
this.sub = this.alfrescoApiService.nodeUpdated.subscribe((node: Node) => {
if (this.row) {
if (this.row['node'].entry.id === node.id) {
this.row['node'].entry = node;
this.row['cache'][this.column.key] = this.column.key.split('.').reduce((source, key) => source[key], node);
this.updateValue();
this.alfrescoApiService.nodeUpdated
.pipe(takeUntil(this.onDestroy$))
.subscribe(node => {
if (this.row) {
if (this.row['node'].entry.id === node.id) {
this.row['node'].entry = node;
this.row['cache'][this.column.key] = this.column.key.split('.').reduce((source, key) => source[key], node);
this.updateValue();
}
}
}
});
});
}
protected updateValue() {
@@ -107,9 +109,7 @@ export class DataTableCellComponent implements OnInit, OnDestroy {
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
this.sub = null;
}
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
}

View File

@@ -23,6 +23,7 @@ import {
} from '../../../services/user-preferences.service';
import { AlfrescoApiService } from '../../../services/alfresco-api.service';
import { AppConfigService } from '../../../app-config/app-config.service';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-date-cell',
@@ -75,9 +76,8 @@ export class DateCellComponent extends DataTableCellComponent {
if (userPreferenceService) {
userPreferenceService
.select(UserPreferenceValues.Locale)
.subscribe((locale) => {
this.currentLocale = locale;
});
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.currentLocale = locale);
}
}
}

View File

@@ -17,7 +17,7 @@
/* tslint:disable:component-selector */
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, OnInit, ViewEncapsulation, OnDestroy } from '@angular/core';
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material';
import { DatetimeAdapter, MAT_DATETIME_FORMATS } from '@mat-datetimepicker/core';
import { MomentDatetimeAdapter, MAT_MOMENT_DATETIME_FORMATS } from '@mat-datetimepicker/moment';
@@ -28,6 +28,8 @@ import { MomentDateAdapter } from '../../../../utils/momentDateAdapter';
import { MOMENT_DATE_FORMATS } from '../../../../utils/moment-date-formats.model';
import { FormService } from './../../../services/form.service';
import { WidgetComponent } from './../widget.component';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
providers: [
@@ -41,12 +43,14 @@ import { WidgetComponent } from './../widget.component';
styleUrls: ['./date-time.widget.scss'],
encapsulation: ViewEncapsulation.None
})
export class DateTimeWidgetComponent extends WidgetComponent implements OnInit {
export class DateTimeWidgetComponent extends WidgetComponent implements OnInit, OnDestroy {
minDate: Moment;
maxDate: Moment;
displayDate: Moment;
private onDestroy$ = new Subject<boolean>();
constructor(public formService: FormService,
private dateAdapter: DateAdapter<Moment>,
private userPreferencesService: UserPreferencesService) {
@@ -54,9 +58,10 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit {
}
ngOnInit() {
this.userPreferencesService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.dateAdapter.setLocale(locale);
});
this.userPreferencesService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.dateAdapter.setLocale(locale));
const momentDateAdapter = <MomentDateAdapter> this.dateAdapter;
momentDateAdapter.overrideDisplayFormat = this.field.dateDisplayFormat;
@@ -73,6 +78,11 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit {
this.displayDate = moment(this.field.value);
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
onDateChanged(newDateValue) {
if (newDateValue && newDateValue.value) {
this.field.value = newDateValue.value.format(this.field.dateDisplayFormat);

View File

@@ -20,12 +20,14 @@
import { UserPreferencesService, UserPreferenceValues } from '../../../../services/user-preferences.service';
import { MomentDateAdapter } from '../../../../utils/momentDateAdapter';
import { MOMENT_DATE_FORMATS } from '../../../../utils/moment-date-formats.model';
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, OnInit, ViewEncapsulation, OnDestroy } from '@angular/core';
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material';
import moment from 'moment-es6';
import { Moment } from 'moment';
import { FormService } from './../../../services/form.service';
import { baseHost, WidgetComponent } from './../widget.component';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'date-widget',
@@ -37,7 +39,7 @@ import { baseHost, WidgetComponent } from './../widget.component';
host: baseHost,
encapsulation: ViewEncapsulation.None
})
export class DateWidgetComponent extends WidgetComponent implements OnInit {
export class DateWidgetComponent extends WidgetComponent implements OnInit, OnDestroy {
DATE_FORMAT = 'DD/MM/YYYY';
@@ -45,6 +47,8 @@ export class DateWidgetComponent extends WidgetComponent implements OnInit {
maxDate: Moment;
displayDate: Moment;
private onDestroy$ = new Subject<boolean>();
constructor(public formService: FormService,
private dateAdapter: DateAdapter<Moment>,
private userPreferencesService: UserPreferencesService) {
@@ -52,9 +56,10 @@ export class DateWidgetComponent extends WidgetComponent implements OnInit {
}
ngOnInit() {
this.userPreferencesService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.dateAdapter.setLocale(locale);
});
this.userPreferencesService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.dateAdapter.setLocale(locale));
const momentDateAdapter = <MomentDateAdapter> this.dateAdapter;
momentDateAdapter.overrideDisplayFormat = this.field.dateDisplayFormat;
@@ -71,6 +76,11 @@ export class DateWidgetComponent extends WidgetComponent implements OnInit {
this.displayDate = moment(this.field.value);
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
onDateChanged(newDateValue) {
if (newDateValue && newDateValue.value) {
this.field.value = newDateValue.value.format(this.field.dateDisplayFormat);

View File

@@ -21,13 +21,15 @@ import { UserPreferencesService, UserPreferenceValues } from '../../../../../../
import { MomentDateAdapter } from '../../../../../../utils/momentDateAdapter';
import { MOMENT_DATE_FORMATS } from '../../../../../../utils/moment-date-formats.model';
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { DateAdapter, MAT_DATE_FORMATS, MatDatepickerInputEvent } from '@angular/material';
import moment from 'moment-es6';
import { Moment } from 'moment';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-date-editor',
@@ -37,7 +39,7 @@ import { DynamicTableModel } from './../../dynamic-table.widget.model';
{provide: MAT_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS}],
styleUrls: ['./date.editor.scss']
})
export class DateEditorComponent implements OnInit {
export class DateEditorComponent implements OnInit, OnDestroy {
DATE_FORMAT: string = 'DD-MM-YYYY';
@@ -55,14 +57,17 @@ export class DateEditorComponent implements OnInit {
minDate: Moment;
maxDate: Moment;
private onDestroy$ = new Subject<boolean>();
constructor(private dateAdapter: DateAdapter<Moment>,
private userPreferencesService: UserPreferencesService) {
}
ngOnInit() {
this.userPreferencesService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.dateAdapter.setLocale(locale);
});
this.userPreferencesService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.dateAdapter.setLocale(locale));
const momentDateAdapter = <MomentDateAdapter> this.dateAdapter;
momentDateAdapter.overrideDisplayFormat = this.DATE_FORMAT;
@@ -70,6 +75,11 @@ export class DateEditorComponent implements OnInit {
this.value = moment(this.table.getCellValue(this.row, this.column), this.DATE_FORMAT);
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
onDateChanged(newDateValue: MatDatepickerInputEvent<any> | HTMLInputElement) {
if (newDateValue && newDateValue.value) {
/* validates the user inputs */

View File

@@ -20,7 +20,7 @@
import { UserPreferencesService, UserPreferenceValues } from '../../../../../../services/user-preferences.service';
import { MomentDateAdapter } from '../../../../../../utils/momentDateAdapter';
import { MOMENT_DATE_FORMATS } from '../../../../../../utils/moment-date-formats.model';
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material';
import moment from 'moment-es6';
import { Moment } from 'moment';
@@ -29,6 +29,8 @@ import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
import { DatetimeAdapter, MAT_DATETIME_FORMATS } from '@mat-datetimepicker/core';
import { MomentDatetimeAdapter, MAT_MOMENT_DATETIME_FORMATS } from '@mat-datetimepicker/moment';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-datetime-editor',
@@ -41,7 +43,7 @@ import { MomentDatetimeAdapter, MAT_MOMENT_DATETIME_FORMATS } from '@mat-datetim
],
styleUrls: ['./datetime.editor.scss']
})
export class DateTimeEditorComponent implements OnInit {
export class DateTimeEditorComponent implements OnInit, OnDestroy {
DATE_TIME_FORMAT: string = 'DD/MM/YYYY HH:mm';
@@ -59,14 +61,17 @@ export class DateTimeEditorComponent implements OnInit {
minDate: Moment;
maxDate: Moment;
private onDestroy$ = new Subject<boolean>();
constructor(private dateAdapter: DateAdapter<Moment>,
private userPreferencesService: UserPreferencesService) {
}
ngOnInit() {
this.userPreferencesService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.dateAdapter.setLocale(locale);
});
this.userPreferencesService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.dateAdapter.setLocale(locale));
const momentDateAdapter = <MomentDateAdapter> this.dateAdapter;
momentDateAdapter.overrideDisplayFormat = this.DATE_TIME_FORMAT;
@@ -74,6 +79,11 @@ export class DateTimeEditorComponent implements OnInit {
this.value = moment(this.table.getCellValue(this.row, this.column), this.DATE_TIME_FORMAT);
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
onDateChanged(newDateValue) {
if (newDateValue && newDateValue.value) {
const newValue = moment(newDateValue.value, this.DATE_TIME_FORMAT);

View File

@@ -57,50 +57,50 @@ export class TypeaheadWidgetComponent extends WidgetComponent implements OnInit
getValuesByTaskId() {
this.formService
.getRestFieldValues(
this.field.form.taskId,
this.field.id
this.field.form.taskId,
this.field.id
)
.subscribe(
(formFieldOption: FormFieldOption[]) => {
const options = formFieldOption || [];
this.field.options = options;
(formFieldOption: FormFieldOption[]) => {
const options = formFieldOption || [];
this.field.options = options;
const fieldValue = this.field.value;
if (fieldValue) {
const toSelect = options.find((item) => item.id === fieldValue || item.name.toLocaleLowerCase() === fieldValue.toLocaleLowerCase());
if (toSelect) {
this.value = toSelect.name;
const fieldValue = this.field.value;
if (fieldValue) {
const toSelect = options.find((item) => item.id === fieldValue || item.name.toLocaleLowerCase() === fieldValue.toLocaleLowerCase());
if (toSelect) {
this.value = toSelect.name;
}
}
}
this.onFieldChanged(this.field);
this.field.updateForm();
},
(err) => this.handleError(err)
this.onFieldChanged(this.field);
this.field.updateForm();
},
(err) => this.handleError(err)
);
}
getValuesByProcessDefinitionId() {
this.formService
.getRestFieldValuesByProcessId(
this.field.form.processDefinitionId,
this.field.id
this.field.form.processDefinitionId,
this.field.id
)
.subscribe(
(formFieldOption: FormFieldOption[]) => {
const options = formFieldOption || [];
this.field.options = options;
(formFieldOption: FormFieldOption[]) => {
const options = formFieldOption || [];
this.field.options = options;
const fieldValue = this.field.value;
if (fieldValue) {
const toSelect = options.find((item) => item.id === fieldValue);
if (toSelect) {
this.value = toSelect.name;
const fieldValue = this.field.value;
if (fieldValue) {
const toSelect = options.find((item) => item.id === fieldValue);
if (toSelect) {
this.value = toSelect.name;
}
}
}
this.onFieldChanged(this.field);
this.field.updateForm();
},
(err) => this.handleError(err)
this.onFieldChanged(this.field);
this.field.updateForm();
},
(err) => this.handleError(err)
);
}

View File

@@ -17,7 +17,7 @@
import {
Component, EventEmitter,
Input, OnInit, Output, TemplateRef, ViewEncapsulation
Input, OnInit, Output, TemplateRef, ViewEncapsulation, OnDestroy
} from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router, ActivatedRoute, Params } from '@angular/router';
@@ -36,6 +36,8 @@ import {
} from '../../app-config/app-config.service';
import { OauthConfigModel } from '../../models/oauth-config.model';
import { DomSanitizer } from '@angular/platform-browser';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
enum LoginSteps {
Landing = 0,
@@ -57,7 +59,7 @@ interface ValidationMessage {
class: 'adf-login'
}
})
export class LoginComponent implements OnInit {
export class LoginComponent implements OnInit, OnDestroy {
isPasswordShow: boolean = false;
/**
@@ -127,6 +129,7 @@ export class LoginComponent implements OnInit {
data: any;
private _message: { [id: string]: { [id: string]: ValidationMessage } };
private onDestroy$ = new Subject<boolean>();
/**
* Constructor
@@ -175,7 +178,14 @@ export class LoginComponent implements OnInit {
this.initFormFieldsDefault();
this.initFormFieldsMessagesDefault();
}
this.form.valueChanges.subscribe((data) => this.onValueChanged(data));
this.form.valueChanges
.pipe(takeUntil(this.onDestroy$))
.subscribe(data => this.onValueChanged(data));
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
submit() {

View File

@@ -24,12 +24,13 @@ import {
} from '@angular/core';
import { PaginatedComponent } from './paginated-component.interface';
import { Subscription } from 'rxjs';
import { Subject } from 'rxjs';
import { PaginationComponentInterface } from './pagination-component.interface';
import { PaginationModel } from '../models/pagination.model';
import { RequestPaginationModel } from '../models/request-pagination.model';
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
import { Pagination } from '@alfresco/js-api';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-infinite-pagination',
@@ -48,22 +49,25 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
});
_target: PaginatedComponent;
private onDestroy$ = new Subject<boolean>();
/** Component that provides custom pagination support. */
@Input()
set target(target: PaginatedComponent) {
if (target) {
this._target = target;
this.paginationSubscription = target.pagination.subscribe((pagination: PaginationModel) => {
this.isLoading = false;
this.pagination = pagination;
target.pagination
.pipe(takeUntil(this.onDestroy$))
.subscribe(pagination => {
this.isLoading = false;
this.pagination = pagination;
if (!this.pagination.hasMoreItems) {
this.pagination.hasMoreItems = false;
}
if (!this.pagination.hasMoreItems) {
this.pagination.hasMoreItems = false;
}
this.cdr.detectChanges();
});
this.cdr.detectChanges();
});
}
}
@@ -90,17 +94,18 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
merge: true
};
private paginationSubscription: Subscription;
constructor(private cdr: ChangeDetectorRef,
private userPreferencesService: UserPreferencesService) {
}
ngOnInit() {
this.userPreferencesService.select(UserPreferenceValues.PaginationSize).subscribe((pageSize: number) => {
this.pageSize = this.pageSize || pageSize;
this.requestPaginationModel.maxItems = this.pageSize;
});
this.userPreferencesService
.select(UserPreferenceValues.PaginationSize)
.pipe(takeUntil(this.onDestroy$))
.subscribe((pageSize: number) => {
this.pageSize = this.pageSize || pageSize;
this.requestPaginationModel.maxItems = this.pageSize;
});
}
onLoadMore() {
@@ -127,8 +132,7 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
}
ngOnDestroy() {
if (this.paginationSubscription) {
this.paginationSubscription.unsubscribe();
}
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
}

View File

@@ -23,9 +23,10 @@ import {
import { Pagination } from '@alfresco/js-api';
import { PaginatedComponent } from './paginated-component.interface';
import { PaginationComponentInterface } from './pagination-component.interface';
import { Subscription } from 'rxjs';
import { Subject } from 'rxjs';
import { PaginationModel } from '../models/pagination.model';
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-pagination',
@@ -82,29 +83,32 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
@Output()
prevPage: EventEmitter<PaginationModel> = new EventEmitter<PaginationModel>();
private paginationSubscription: Subscription;
private onDestroy$ = new Subject<boolean>();
constructor(private cdr: ChangeDetectorRef, private userPreferencesService: UserPreferencesService) {
this.userPreferencesService.select(UserPreferenceValues.PaginationSize).subscribe((pagSize) => {
this.pagination.maxItems = pagSize;
});
}
ngOnInit() {
this.userPreferencesService
.select(UserPreferenceValues.PaginationSize)
.pipe(takeUntil(this.onDestroy$))
.subscribe(pagSize => this.pagination.maxItems = pagSize);
if (!this.supportedPageSizes) {
this.supportedPageSizes = this.userPreferencesService.supportedPageSizes;
}
if (this.target) {
this.paginationSubscription = this.target.pagination.subscribe((pagination: PaginationModel) => {
this.target.pagination
.pipe(takeUntil(this.onDestroy$))
.subscribe(pagination => {
if (pagination.count === 0 && !this.isFirstPage) {
this.goPrevious();
}
if (pagination.count === 0 && !this.isFirstPage) {
this.goPrevious();
}
this.pagination = pagination;
this.cdr.detectChanges();
});
this.pagination = pagination;
this.cdr.detectChanges();
});
}
if (!this.pagination) {
@@ -217,6 +221,11 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
});
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
handlePaginationEvent(action: string, params: PaginationModel) {
const {
NEXT_PAGE,
@@ -258,10 +267,4 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
this.target.updatePagination(params);
}
}
ngOnDestroy() {
if (this.paginationSubscription) {
this.paginationSubscription.unsubscribe();
}
}
}

View File

@@ -16,15 +16,17 @@
*/
import { DatePipe } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
import { Pipe, PipeTransform, OnDestroy } from '@angular/core';
import { AppConfigService } from '../app-config/app-config.service';
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Pipe({
name: 'adfLocalizedDate',
pure: false
})
export class LocalizedDatePipe implements PipeTransform {
export class LocalizedDatePipe implements PipeTransform, OnDestroy {
static DEFAULT_LOCALE = 'en-US';
static DEFAULT_DATE_FORMAT = 'mediumDate';
@@ -32,15 +34,20 @@ export class LocalizedDatePipe implements PipeTransform {
defaultLocale: string = LocalizedDatePipe.DEFAULT_LOCALE;
defaultFormat: string = LocalizedDatePipe.DEFAULT_DATE_FORMAT;
private onDestroy$ = new Subject<boolean>();
constructor(public userPreferenceService?: UserPreferencesService,
public appConfig?: AppConfigService) {
if (this.userPreferenceService) {
this.userPreferenceService.select(UserPreferenceValues.Locale).subscribe((locale) => {
if (locale) {
this.defaultLocale = locale;
}
});
this.userPreferenceService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => {
if (locale) {
this.defaultLocale = locale;
}
});
}
if (this.appConfig) {
@@ -55,4 +62,9 @@ export class LocalizedDatePipe implements PipeTransform {
return datePipe.transform(value, actualFormat);
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
}

View File

@@ -16,15 +16,17 @@
*/
import moment from 'moment-es6';
import { Pipe, PipeTransform } from '@angular/core';
import { Pipe, PipeTransform, OnDestroy } from '@angular/core';
import { AppConfigService } from '../app-config/app-config.service';
import { UserPreferenceValues, UserPreferencesService } from '../services/user-preferences.service';
import { DatePipe } from '@angular/common';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Pipe({
name: 'adfTimeAgo'
})
export class TimeAgoPipe implements PipeTransform {
export class TimeAgoPipe implements PipeTransform, OnDestroy {
static DEFAULT_LOCALE = 'en-US';
static DEFAULT_DATE_TIME_FORMAT = 'dd/MM/yyyy HH:mm';
@@ -32,11 +34,16 @@ export class TimeAgoPipe implements PipeTransform {
defaultLocale: string;
defaultDateTimeFormat: string;
private onDestroy$ = new Subject<boolean>();
constructor(public userPreferenceService: UserPreferencesService,
public appConfig: AppConfigService) {
this.userPreferenceService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.defaultLocale = locale || TimeAgoPipe.DEFAULT_LOCALE;
});
this.userPreferenceService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => {
this.defaultLocale = locale || TimeAgoPipe.DEFAULT_LOCALE;
});
this.defaultDateTimeFormat = this.appConfig.get<string>('dateValues.defaultDateTimeFormat', TimeAgoPipe.DEFAULT_DATE_TIME_FORMAT);
}
@@ -54,4 +61,9 @@ export class TimeAgoPipe implements PipeTransform {
}
return '';
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
}

View File

@@ -15,13 +15,15 @@
* limitations under the License.
*/
import { AfterContentInit, ContentChild, Directive, Input, TemplateRef } from '@angular/core';
import { AfterContentInit, ContentChild, Directive, Input, TemplateRef, OnDestroy } from '@angular/core';
import { ViewerComponent } from '../components/viewer.component';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Directive({
selector: 'adf-viewer-extension'
})
export class ViewerExtensionDirective implements AfterContentInit {
export class ViewerExtensionDirective implements AfterContentInit, OnDestroy {
@ContentChild(TemplateRef)
template: any;
@@ -37,6 +39,8 @@ export class ViewerExtensionDirective implements AfterContentInit {
templateModel: any;
private onDestroy$ = new Subject<boolean>();
constructor(private viewerComponent: ViewerComponent) {
}
@@ -45,9 +49,11 @@ export class ViewerExtensionDirective implements AfterContentInit {
this.viewerComponent.extensionTemplates.push(this.templateModel);
this.viewerComponent.extensionChange.subscribe((fileExtension) => {
this.templateModel.isVisible = this.isVisible(fileExtension);
});
this.viewerComponent.extensionChange
.pipe(takeUntil(this.onDestroy$))
.subscribe(fileExtension => {
this.templateModel.isVisible = this.isVisible(fileExtension);
});
if (this.supportedExtensions instanceof Array) {
this.supportedExtensions.forEach((extension) => {
@@ -56,6 +62,11 @@ export class ViewerExtensionDirective implements AfterContentInit {
}
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
/**
* check if the current extension in the viewer is compatible with this extension checking against supportedExtensions
*/