[no issue number] fix unsubscribing in documentlist (#2740)

* fix unsubscribing in documentlist

* fix tslint errors
This commit is contained in:
Eugenio Romano
2017-11-27 17:51:18 +00:00
committed by GitHub
parent 6843a6adfd
commit 9b7e018f93
32 changed files with 180 additions and 148 deletions

View File

@@ -15,7 +15,16 @@
* limitations under the License.
*/
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, TemplateRef, ViewEncapsulation } from '@angular/core';
import {
Component,
ElementRef,
EventEmitter,
Input,
OnInit,
Output,
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
@@ -39,7 +48,7 @@ enum LoginSteps {
selector: 'adf-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'],
host: {'(blur)': 'onBlur($event)'},
host: { '(blur)': 'onBlur($event)' },
encapsulation: ViewEncapsulation.None
})
export class LoginComponent implements OnInit {
@@ -137,9 +146,11 @@ export class LoginComponent implements OnInit {
* @param event
*/
onSubmit(values: any) {
if (!this.checkRequiredParams()) {
return false;
}
this.settingsService.setProviders(this.providers);
this.settingsService.csrfDisabled = this.disableCsrf;
@@ -195,10 +206,7 @@ export class LoginComponent implements OnInit {
if (redirectUrl) {
this.authService.setRedirectUrl(null);
this.router.navigate([redirectUrl]);
return false;
}
if (this.successRoute) {
} else if (this.successRoute) {
this.router.navigate([this.successRoute]);
}
},
@@ -216,22 +224,17 @@ export class LoginComponent implements OnInit {
* Check and display the right error message in the UI
*/
private displayErrorMessage(err: any): void {
if (err.error && err.error.crossDomain && err.error.message.indexOf('Access-Control-Allow-Origin') !== -1) {
this.errorMsg = err.error.message;
return;
}
if (err.status === 403 && err.message.indexOf('Invalid CSRF-token') !== -1) {
} else if (err.status === 403 && err.message.indexOf('Invalid CSRF-token') !== -1) {
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-CSRF';
return;
}
if (err.status === 403 && err.message.indexOf('The system is currently in read-only mode') !== -1) {
} else if (err.status === 403 && err.message.indexOf('The system is currently in read-only mode') !== -1) {
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ECM-LICENSE';
return;
}
} else {
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS';
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS';
}
}
/**
@@ -239,15 +242,19 @@ export class LoginComponent implements OnInit {
* @returns {boolean}
*/
private checkRequiredParams(): boolean {
let isAllParamPresent: boolean = true;
if (this.providers === undefined || this.providers === null || this.providers === '') {
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS';
this.enableError();
let messageProviders: any;
messageProviders = this.translateService.get(this.errorMsg);
this.error.emit(new LoginErrorEvent(messageProviders.value));
return false;
isAllParamPresent = false;
}
return true;
return isAllParamPresent;
}
/**
@@ -332,7 +339,7 @@ export class LoginComponent implements OnInit {
}
};
this.translateService.get('LOGIN.MESSAGES.USERNAME-MIN', {minLength: this.minLength}).subscribe((res: string) => {
this.translateService.get('LOGIN.MESSAGES.USERNAME-MIN', { minLength: this.minLength }).subscribe((res: string) => {
this._message['username']['minlength'] = res;
});
}

View File

@@ -23,22 +23,24 @@ import {
OnInit,
Output,
ViewEncapsulation,
ChangeDetectorRef
ChangeDetectorRef,
OnDestroy
} from '@angular/core';
import { Pagination } from 'alfresco-js-api';
import { PaginationQueryParams } from './pagination-query-params.interface';
import { PaginatedComponent } from './paginated-component.interface';
import { Subscription } from 'rxjs/Subscription';
@Component({
selector: 'adf-pagination',
host: { 'class': 'adf-pagination' },
templateUrl: './pagination.component.html',
styleUrls: [ './pagination.component.scss' ],
styleUrls: ['./pagination.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
})
export class PaginationComponent implements OnInit {
export class PaginationComponent implements OnInit, OnDestroy {
static DEFAULT_PAGE_SIZE: number = 25;
@@ -59,7 +61,7 @@ export class PaginationComponent implements OnInit {
target: PaginatedComponent;
@Input()
supportedPageSizes: number[] = [ 25, 50, 100 ];
supportedPageSizes: number[] = [5, 25, 50, 100];
@Input()
pagination: Pagination;
@@ -79,16 +81,20 @@ export class PaginationComponent implements OnInit {
@Output()
prevPage: EventEmitter<Pagination> = new EventEmitter<Pagination>();
private paginationSubscription: Subscription;
constructor(private cdr: ChangeDetectorRef) {
}
ngOnInit() {
if (this.target) {
this.target.pagination.subscribe(page => {
this.paginationSubscription = this.target.pagination.subscribe(page => {
this.pagination = page;
this.cdr.detectChanges();
});
}
if (!this.pagination) {
this.pagination = PaginationComponent.DEFAULT_PAGINATION;
}
@@ -136,7 +142,7 @@ export class PaginationComponent implements OnInit {
const start = totalItems ? skipCount + 1 : 0;
const end = isLastPage ? totalItems : skipCount + maxItems;
return [ start, end ];
return [start, end];
}
get pages(): number[] {
@@ -220,4 +226,10 @@ export class PaginationComponent implements OnInit {
this.target.updatePagination(params);
}
}
ngOnDestroy() {
if (this.paginationSubscription) {
this.paginationSubscription.unsubscribe();
}
}
}