mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
strongly typed events, removed deprecations (#2525)
This commit is contained in:
parent
4d9591c76c
commit
9ac0c06acd
@ -45,7 +45,7 @@
|
||||
<mat-icon>settings</mat-icon>
|
||||
</a>
|
||||
|
||||
<alfresco-login
|
||||
<adf-login
|
||||
#alfrescologin
|
||||
[providers]="providers"
|
||||
[fieldsValidation]="customValidation"
|
||||
@ -93,4 +93,4 @@
|
||||
</mat-slide-toggle>
|
||||
</p>
|
||||
</div>
|
||||
</alfresco-login>
|
||||
</adf-login>
|
||||
|
@ -28,18 +28,17 @@ export { LoginHeaderDirective } from './src/directives/login-header.directive';
|
||||
export { LoginFooterDirective } from './src/directives/login-footer.directive';
|
||||
export { LoginComponent } from './src/components/login.component';
|
||||
|
||||
// Old Deprecated export
|
||||
import { LoginComponent as AlfrescoLoginComponent } from './src/components/login.component';
|
||||
export { LoginComponent as AlfrescoLoginComponent } from './src/components/login.component';
|
||||
export { LoginErrorEvent } from './src/models/login-error.event';
|
||||
export { LoginSubmitEvent } from './src/models/login-submit.event';
|
||||
export { LoginSuccessEvent } from './src/models/login-success.event';
|
||||
|
||||
export const ALFRESCO_LOGIN_DIRECTIVES: any[] = [
|
||||
LoginComponent,
|
||||
LoginFooterDirective,
|
||||
LoginHeaderDirective,
|
||||
|
||||
// Old Deprecated export
|
||||
AlfrescoLoginComponent
|
||||
];
|
||||
export function declarations() {
|
||||
return [
|
||||
LoginComponent,
|
||||
LoginFooterDirective,
|
||||
LoginHeaderDirective
|
||||
];
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@ -47,9 +46,7 @@ export const ALFRESCO_LOGIN_DIRECTIVES: any[] = [
|
||||
CoreModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
...ALFRESCO_LOGIN_DIRECTIVES
|
||||
],
|
||||
declarations: declarations(),
|
||||
providers: [
|
||||
{
|
||||
provide: TRANSLATION_PROVIDER,
|
||||
@ -61,7 +58,7 @@ export const ALFRESCO_LOGIN_DIRECTIVES: any[] = [
|
||||
}
|
||||
],
|
||||
exports: [
|
||||
...ALFRESCO_LOGIN_DIRECTIVES,
|
||||
...declarations(),
|
||||
MaterialModule
|
||||
]
|
||||
})
|
||||
|
@ -21,9 +21,9 @@ import { Observable } from 'rxjs/Rx';
|
||||
export class AuthenticationMock /*extends AlfrescoAuthenticationService*/ {
|
||||
|
||||
// TODO: real auth service returns Observable<string>
|
||||
login(username: string, password: string): Observable<boolean> {
|
||||
login(username: string, password: string): Observable<{ type: string, ticket: any }> {
|
||||
if (username === 'fake-username' && password === 'fake-password') {
|
||||
return Observable.of(true);
|
||||
return Observable.of({ type: 'type', ticket: 'ticket'});
|
||||
}
|
||||
|
||||
if (username === 'fake-username-CORS-error' && password === 'fake-password') {
|
||||
|
@ -48,7 +48,7 @@
|
||||
</div>
|
||||
|
||||
<!--PASSWORD FIELD-->
|
||||
<div class="adf-login__field alfresco-login__password">
|
||||
<div class="adf-login__field">
|
||||
<mat-form-field class="adf-full-width" floatPlaceholder="never" color="primary">
|
||||
<input matInput placeholder="{{'LOGIN.LABEL.PASSWORD' | translate }}"
|
||||
type="password"
|
||||
|
@ -25,11 +25,13 @@ import { AlfrescoAuthenticationService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { LoginErrorEvent } from '../models/login-error.event';
|
||||
import { LoginSuccessEvent } from '../models/login-success.event';
|
||||
import { AuthenticationMock } from './../assets/authentication.service.mock';
|
||||
import { TranslationMock } from './../assets/translation.service.mock';
|
||||
import { LoginComponent } from './login.component';
|
||||
|
||||
describe('AlfrescoLogin', () => {
|
||||
describe('LoginComponent', () => {
|
||||
let component: LoginComponent;
|
||||
let fixture: ComponentFixture<LoginComponent>;
|
||||
let debug: DebugElement;
|
||||
@ -523,11 +525,9 @@ describe('AlfrescoLogin', () => {
|
||||
|
||||
expect(component.error).toBe(false);
|
||||
expect(component.success).toBe(true);
|
||||
expect(component.onSuccess.emit).toHaveBeenCalledWith({
|
||||
token: true,
|
||||
username: 'fake-username',
|
||||
password: 'fake-password'
|
||||
});
|
||||
expect(component.onSuccess.emit).toHaveBeenCalledWith(
|
||||
new LoginSuccessEvent({ type: 'type', ticket: 'ticket' }, 'fake-username', 'fake-password')
|
||||
);
|
||||
});
|
||||
|
||||
it('should emit onError event after the login has failed', () => {
|
||||
@ -553,7 +553,9 @@ describe('AlfrescoLogin', () => {
|
||||
expect(component.success).toBe(false);
|
||||
expect(getLoginErrorElement()).toBeDefined();
|
||||
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
|
||||
expect(component.onError.emit).toHaveBeenCalledWith('Fake server error');
|
||||
expect(component.onError.emit).toHaveBeenCalledWith(
|
||||
new LoginErrorEvent('Fake server error')
|
||||
);
|
||||
});
|
||||
|
||||
it('should render the password in clear when the toggleShowPassword is call', () => {
|
||||
@ -598,6 +600,6 @@ describe('AlfrescoLogin', () => {
|
||||
expect(component.success).toBe(false);
|
||||
expect(getLoginErrorElement()).toBeDefined();
|
||||
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS');
|
||||
expect(component.onError.emit).toHaveBeenCalledWith('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS');
|
||||
expect(component.onError.emit).toHaveBeenCalledWith(new LoginErrorEvent('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS'));
|
||||
});
|
||||
});
|
||||
|
@ -19,7 +19,10 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, Output, TemplateRef
|
||||
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoTranslationService, LogService } from 'ng2-alfresco-core';
|
||||
import { FormSubmitEvent } from '../models/form-submit-event.model';
|
||||
|
||||
import { LoginErrorEvent } from '../models/login-error.event';
|
||||
import { LoginSubmitEvent } from '../models/login-submit.event';
|
||||
import { LoginSuccessEvent } from '../models/login-success.event';
|
||||
|
||||
declare var require: any;
|
||||
|
||||
@ -30,7 +33,7 @@ enum LoginSteps {
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'adf-login, alfresco-login',
|
||||
selector: 'adf-login',
|
||||
templateUrl: './login.component.html',
|
||||
styleUrls: ['./login.component.scss'],
|
||||
host: {'(blur)': 'onBlur($event)'},
|
||||
@ -74,13 +77,13 @@ export class LoginComponent implements OnInit {
|
||||
successRoute: string = null;
|
||||
|
||||
@Output()
|
||||
onSuccess = new EventEmitter();
|
||||
onSuccess = new EventEmitter<LoginSuccessEvent>();
|
||||
|
||||
@Output()
|
||||
onError = new EventEmitter();
|
||||
onError = new EventEmitter<LoginErrorEvent>();
|
||||
|
||||
@Output()
|
||||
executeSubmit: EventEmitter<FormSubmitEvent> = new EventEmitter<FormSubmitEvent>();
|
||||
executeSubmit = new EventEmitter<LoginSubmitEvent>();
|
||||
|
||||
form: FormGroup;
|
||||
error: boolean = false;
|
||||
@ -139,7 +142,7 @@ export class LoginComponent implements OnInit {
|
||||
|
||||
this.disableError();
|
||||
|
||||
let args = new FormSubmitEvent(this.form);
|
||||
const args = new LoginSubmitEvent(this.form);
|
||||
this.executeSubmit.emit(args);
|
||||
|
||||
if (args.defaultPrevented) {
|
||||
@ -183,7 +186,7 @@ export class LoginComponent implements OnInit {
|
||||
(token: any) => {
|
||||
this.actualLoginStep = LoginSteps.Welcome;
|
||||
this.success = true;
|
||||
this.onSuccess.emit({token: token, username: values.username, password: values.password});
|
||||
this.onSuccess.emit(new LoginSuccessEvent(token, values.username, values.password));
|
||||
if (this.successRoute) {
|
||||
this.router.navigate([this.successRoute]);
|
||||
}
|
||||
@ -192,7 +195,7 @@ export class LoginComponent implements OnInit {
|
||||
this.actualLoginStep = LoginSteps.Landing;
|
||||
this.displayErrorMessage(err);
|
||||
this.enableError();
|
||||
this.onError.emit(err);
|
||||
this.onError.emit(new LoginErrorEvent(err));
|
||||
},
|
||||
() => this.logService.info('Login done')
|
||||
);
|
||||
@ -230,7 +233,7 @@ export class LoginComponent implements OnInit {
|
||||
this.enableError();
|
||||
let messageProviders: any;
|
||||
messageProviders = this.translateService.get(this.errorMsg);
|
||||
this.onError.emit(messageProviders.value);
|
||||
this.onError.emit(new LoginErrorEvent(messageProviders.value));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -251,7 +254,7 @@ export class LoginComponent implements OnInit {
|
||||
* @param ruleId - i.e. required | minlength | maxlength
|
||||
* @param msg
|
||||
*/
|
||||
public addCustomValidationError(field: string, ruleId: string, msg: string, params?: any) {
|
||||
addCustomValidationError(field: string, ruleId: string, msg: string, params?: any) {
|
||||
if (params) {
|
||||
this.translateService.get(msg, params).subscribe((res: string) => {
|
||||
this._message[field][ruleId] = res;
|
||||
|
@ -0,0 +1,20 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export class LoginErrorEvent {
|
||||
constructor(public err: any) {}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export class FormSubmitEvent {
|
||||
export class LoginSubmitEvent {
|
||||
|
||||
private _values: any;
|
||||
private _defaultPrevented: boolean = false;
|
@ -0,0 +1,24 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export class LoginSuccessEvent {
|
||||
constructor(
|
||||
public token: any,
|
||||
public username: string,
|
||||
public password: string) {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user