Skip to content

Commit e4edf4f

Browse files
Merge pull request #5 from HackTzi/Login-screen
Login screen updated
2 parents 447e25d + 8b9da7c commit e4edf4f

17 files changed

+153
-15
lines changed

src/app/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import { HomeModule } from './home/home.module';
1717

1818
import { AppComponent } from './app.component';
1919

20+
// Services
21+
import { IconSanitizerService } from './services/icon-sanitizer.service';
22+
2023
// AoT requires an exported function for factories
2124
export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
2225
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
@@ -48,7 +51,9 @@ import { MenuComponent } from './menu/menu.component';
4851
}
4952
})
5053
],
51-
providers: [],
54+
providers: [
55+
IconSanitizerService
56+
],
5257
bootstrap: [AppComponent]
5358
})
5459
export class AppModule {}

src/app/auth/auth.component.html

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1+
<!-- TODO: Here we need to add style to this component -->
2+
<app-login-banner></app-login-banner>
13
<form [formGroup]="authForm">
24
<mat-card>
35
<mat-card-header>
4-
<img mat-card-image src="" alt="Photo of platzi logo">
5-
<mat-card-title>{{'PAGES.AUTH.TITLE' | translate}}</mat-card-title>
6+
<img mat-card-image src="assets/paltzilogo.png" alt="Photo of platzi logo">
7+
<mat-card-title>{{ pageName.concat('TITLE') | translate}}</mat-card-title>
68
</mat-card-header>
79
<mat-card-content style="margin:auto;">
810
<mat-form-field>
9-
<input formControlName="username" matInput placeholder="{{'PAGES.AUTH.EMAIL'|translate}}" type="email">
11+
<input formControlName="username" matInput placeholder="{{pageName.concat('EMAIL') | translate}}" type="email">
12+
<mat-icon matSuffix svgIcon="metro-mail"></mat-icon>
1013
</mat-form-field>
1114
<mat-form-field>
12-
<input formControlName="password" matInput placeholder="{{'PAGES.AUTH.PASSWORD'|translate}}" type="password">
15+
<input formControlName="password" matInput placeholder="{{pageName.concat('PASSWORD') | translate}}" [type]="hidePassword ? 'password' : 'text'">
16+
<button mat-icon-button matSuffix (click)="hidePassword = !hidePassword" [attr.aria-label]="'Hide password'" [attr.aria-pressed]="hidePassword">
17+
<mat-icon svgIcon="{{ hidePassword ? 'visibility-filled' : 'visibility-filled' }}"></mat-icon>
18+
</button>
1319
</mat-form-field>
14-
<button [disabled]="!authForm.valid" color="accent" mat-raised-button (click)="login()">{{'PAGES.AUTH.START'|translate}}</button>
20+
<button [disabled]="!authForm.valid" color="accent" mat-raised-button (click)="login()">{{pageName.concat('START') | translate}}</button>
21+
<p>{{ pageName.concat('START_WITH') | translate}}</p>
22+
<button mat-icon-button>
23+
<mat-icon svgIcon="metro-facebook"></mat-icon>
24+
</button>
25+
<button mat-icon-button>
26+
<mat-icon svgIcon="metro-twitter"></mat-icon>
27+
</button>
28+
<p> {{ pageName.concat('NO_ACCOUNT') | translate}} <strong><a>{{pageName.concat('REGISTER') | translate}}</a></strong></p>
29+
<p><a>{{ pageName.concat('ENTERPRISE_ACCOUNT') | translate}}</a></p>
1530
</mat-card-content>
1631
</mat-card>
1732
</form>
18-

src/app/auth/auth.component.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
import { Component, Inject, OnInit } from '@angular/core';
33
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
4+
import { MatIconRegistry } from '@angular/material/icon';
5+
import { DomSanitizer } from '@angular/platform-browser';
46
import { Router } from '@angular/router';
7+
import { IconSanitizerService } from '../services/icon-sanitizer.service';
8+
import { Svg } from '../shared/interfaces/svg.interface';
59

610
@Component({
7-
selector: 'app-auth',
8-
templateUrl: './auth.component.html',
9-
styleUrls: ['./auth.component.scss']
11+
selector: 'app-auth',
12+
templateUrl: './auth.component.html',
13+
styleUrls: ['./auth.component.scss']
1014
})
1115
export class AuthComponent implements OnInit {
1216
constructor(
13-
@Inject(FormBuilder) fb: FormBuilder,
14-
private router: Router
17+
@Inject(FormBuilder) fb: FormBuilder,
18+
private router: Router,
19+
private iconServ: IconSanitizerService
1520
) {
21+
22+
this.iconServ.setSvgIcons(this.icons);
23+
1624
this.authForm = fb.group({
1725
username: new FormControl({ value: '', disabled: false }, [Validators.required, Validators.email]),
1826
password: new FormControl({ value: '', disabled: false }, [Validators.required, Validators.pattern(this.passPattern)])
1927
});
2028
}
29+
private icons: Svg[] = [
30+
{ iconName: 'metro-facebook', url: 'assets/icons/icon-metro-facebook.svg' },
31+
{ iconName: 'metro-twitter', url: 'assets/icons/icon-metro-twitter.svg' },
32+
{ iconName: 'visibility-filled', url: 'assets/icons/icon-visibility-filled.svg' },
33+
{ iconName: 'metro-mail', url: 'assets/icons/icon-metro-mail.svg' },
34+
];
2135
authForm: FormGroup;
2236
passPattern: RegExp;
2337
loading = false;
38+
pageName = 'PAGES.AUTH.';
39+
hidePassword = true;
2440

2541
ngOnInit(): void { }
2642

@@ -31,6 +47,6 @@ export class AuthComponent implements OnInit {
3147

3248
this.router.navigate(['/app/home']);
3349
setTimeout(() => this.loading = false, 2000); // Quit loading timeout for test
34-
}
50+
}
3551

3652
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { IconSanitizerService } from './icon-sanitizer.service';
4+
5+
describe('IconSanitizerService', () => {
6+
let service: IconSanitizerService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(IconSanitizerService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Injectable } from '@angular/core';
2+
import { MatIconRegistry } from '@angular/material/icon';
3+
import { DomSanitizer } from '@angular/platform-browser';
4+
import { Svg } from '../shared/interfaces/svg.interface';
5+
@Injectable({
6+
providedIn: 'root'
7+
})
8+
/**
9+
* Service to register and display icons used by `<mat-icon>` component or another components.
10+
* - Registers icon set URLs by namespace.
11+
* - Registers aliases for CSS classes, for use with icon fonts.
12+
* - Loads icons from URLs and extracts individual icons from icon sets.
13+
*/
14+
export class IconSanitizerService {
15+
constructor(
16+
private iconRegistry: MatIconRegistry,
17+
private sanitizer: DomSanitizer
18+
) { }
19+
20+
setSvgIcons(svg: Svg[]) {
21+
svg.forEach(s => {
22+
this.iconRegistry.addSvgIcon(s.iconName, this.sanitizer.bypassSecurityTrustResourceUrl(s.url));
23+
});
24+
}
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>login-banner works!</p>

src/app/shared/components/login-banner/login-banner.component.scss

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { LoginBannerComponent } from './login-banner.component';
4+
5+
describe('LoginBannerComponent', () => {
6+
let component: LoginBannerComponent;
7+
let fixture: ComponentFixture<LoginBannerComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ LoginBannerComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(LoginBannerComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-login-banner',
5+
templateUrl: './login-banner.component.html',
6+
styleUrls: ['./login-banner.component.scss']
7+
})
8+
export class LoginBannerComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit(): void {
13+
}
14+
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Svg {
2+
iconName: string;
3+
url: string;
4+
}

0 commit comments

Comments
 (0)