Commit 6d835fb6 by Muhammad Usman

Icon service added, pug & config file

parent 3fdfbb10
<div
[class]="'form-control-wrapper ' + class"
*ngIf="fcn"
[ngClass]="{
'-highlighted': isHighlighted,
'-err-tooltip': isShowErrorTooltip
}"
>
<ng-content></ng-content>
<div
class="form-control-wrapper__error"
*ngIf="isShowErrorTooltip"
>
{{ getError() }}
</div>
</div>
div([class]="'form-control-wrapper ' + class", *ngIf='fcn', [ngClass]="{ 'has-error': isHighlighted }")
ng-content
span.error-msg(*ngIf='isHighlighted') {{ getError() }}
import { Component, ContentChild, Input } from '@angular/core'; import { Component, ContentChild, Input } from '@angular/core';
import { FocusBlurDirective } from '../../directives/focus-blur.directive';
import { AbstractControl, FormControlName } from '@angular/forms'; import { AbstractControl, FormControlName } from '@angular/forms';
import { CONFIG } from '../../config'; import { CONFIG } from '../../config';
import { FocusBlurDirective } from '../../directives/focus-blur.directive';
@Component({ @Component({
selector: 'app-form-control', selector: 'app-form-control',
templateUrl: './form-control.component.html' templateUrl: './form-control.component.pug'
}) })
export class FormControlComponent { export class FormControlComponent {
...@@ -43,12 +43,4 @@ export class FormControlComponent { ...@@ -43,12 +43,4 @@ export class FormControlComponent {
return this.control.invalid && (this.control.dirty || this.control.touched); return this.control.invalid && (this.control.dirty || this.control.touched);
} }
get isShowErrorTooltip(): boolean {
if (!this.focusBlur) {
return;
}
return this.control.invalid && this.focusBlur.isFocused;
}
} }
...@@ -9,12 +9,11 @@ export const CONFIG = { ...@@ -9,12 +9,11 @@ export const CONFIG = {
} }
}; };
export const SHOW_ERRORS = { export const SHOW_ERRORS = {
e400: false, e400: false,
e401: false, e401: false,
e500: false, e500: false,
e404: false, e404: false,
e422: false, e422: false,
e403: false, e403: false
}; };
import {Directive, HostListener} from '@angular/core'; import { Directive, HostListener } from '@angular/core';
@Directive({ @Directive({
selector: '[appFocusBlur]' selector: '[appFocusBlur]'
......
import { Directive, ElementRef, OnInit } from '@angular/core';
@Directive({
selector: '[appPassword]'
})
export class PasswordDirective implements OnInit {
private readonly element: HTMLInputElement;
constructor(
private elRef: ElementRef
) {
this.element = elRef.nativeElement;
}
ngOnInit(): void {
const img = document.createElement('img');
img.classList.add('password-eye');
img.src = '/assets/svgs/eye.svg';
img.addEventListener('click', () => {
const type = this.element.getAttribute('type');
type === 'password' ? this.element.setAttribute('type', 'text') : this.element.setAttribute('type', 'password');
});
setTimeout(() => {
this.element.parentElement.appendChild(img);
this.element.classList.add('password-field');
}, 0);
}
}
...@@ -9,10 +9,12 @@ export class TruncatePipe implements PipeTransform { ...@@ -9,10 +9,12 @@ export class TruncatePipe implements PipeTransform {
if (!value) { if (!value) {
return ''; return '';
} }
let newValue = '';
if (value.length > length) { if (value.length > length) {
value = value.substring(0, length - 3) + ' ...'; newValue = `${value.substring(0, length - 3)} ...` ;
} }
return value;
return newValue;
} }
} }
import { Injectable } from '@angular/core'; /* tslint:disable */
import { Subject } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Subject } from 'rxjs';
import { map, share } from 'rxjs/operators'; import { map, share } from 'rxjs/operators';
@Injectable() @Injectable()
...@@ -42,9 +43,8 @@ export class HttpService { ...@@ -42,9 +43,8 @@ export class HttpService {
} }
createHeader(extraHeaders = {}) { createHeader(extraHeaders = {}) {
const headers = Object.assign({ const headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json', ...extraHeaders};
}, extraHeaders);
if (extraHeaders['Content-Type'] === null) { if (extraHeaders['Content-Type'] === null) {
delete headers['Content-Type']; delete headers['Content-Type'];
} }
......
import { Injectable } from '@angular/core';
import { SvgIconRegistryService } from 'angular-svg-icon';
import { forkJoin } from 'rxjs';
import { retry } from 'rxjs/operators';
import { ICONS } from '../../config/icon-list';
@Injectable()
export class IconsService {
icons = ICONS;
constructor(
private iconReg: SvgIconRegistryService
) {
}
async loadSvgIcons(): Promise<any> {
return new Promise<any>(resolve => {
forkJoin(this.icons.map(icon => this.iconReg.loadSvg(icon.url, icon.name).pipe(retry(3))))
.subscribe(() => {
resolve();
});
});
}
}
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FormArray, FormControl, FormGroup } from '@angular/forms'; import { FormArray, FormControl, FormGroup } from '@angular/forms';
import { HttpErrorResponse } from '@angular/common/http';
import { SHOW_ERRORS } from '../config'; import { SHOW_ERRORS } from '../config';
@Injectable() @Injectable()
export class UtilsService { export class UtilsService {
constructor() { }
validateAllFormFields(formGroup?: FormGroup): void { validateAllFormFields(formGroup?: FormGroup): void {
Object Object
.keys(formGroup.controls) .keys(formGroup.controls)
...@@ -33,29 +31,36 @@ export class UtilsService { ...@@ -33,29 +31,36 @@ export class UtilsService {
handleHttpError(error: HttpErrorResponse): any { handleHttpError(error: HttpErrorResponse): any {
switch (error.status) { switch (error.status) {
case 401: case 401:
if (SHOW_ERRORS.e401 !== false) { if (SHOW_ERRORS.e401) {
console.log(`Error ${error.status}`);
} }
break; break;
case 400: case 400:
if (SHOW_ERRORS.e400 !== false) { if (SHOW_ERRORS.e400) {
console.log(`Error ${error.status}`);
} }
break; break;
case 500: case 500:
if (SHOW_ERRORS.e500 !== false) { if (SHOW_ERRORS.e500) {
console.log(`Error ${error.status}`);
} }
break; break;
case 404: case 404:
if (SHOW_ERRORS.e404 !== false) { if (SHOW_ERRORS.e404) {
console.log(`Error ${error.status}`);
} }
break; break;
case 422: case 422:
if (SHOW_ERRORS.e422 !== false) { if (SHOW_ERRORS.e422) {
console.log(`Error ${error.status}`);
} }
break; break;
case 403: case 403:
if (SHOW_ERRORS.e403 !== false) { if (SHOW_ERRORS.e403) {
console.log(`Error ${error.status}`);
} }
break; break;
default:
} }
} }
} }
...@@ -8,15 +8,16 @@ export class ConfirmPasswordValidator { ...@@ -8,15 +8,16 @@ export class ConfirmPasswordValidator {
if (!fieldValue || fieldValue !== comparisonValue) { if (!fieldValue || fieldValue !== comparisonValue) {
return {notMatch: true}; return {notMatch: true};
} }
return null; return null;
}; };
} }
static ValidPassword(): ValidatorFn { static ValidPassword(): ValidatorFn {
return (c: FormControl): { [key: string]: boolean } | null => { return (c: FormControl): { [key: string]: boolean } | null => {
const fieldValue = c.value; const fieldValue = c.value;
const isValid = (fieldValue.length >= 8 && /[A-Z]/.test(fieldValue) && /[a-z]/.test(fieldValue) && /[0-9]/.test(fieldValue)); const isValid = (fieldValue.length >= 8 && /[A-Z]/.test(fieldValue) && /[a-z]/.test(fieldValue) && /[0-9]/.test(fieldValue));
return isValid ? null : {invalidPassword: true}; return isValid ? null : {invalidPassword: true};
}; };
} }
......
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { AngularSvgIconModule } from 'angular-svg-icon';
import { FormControlComponent } from './components/form-control/form-control.component'; import { FormControlComponent } from './components/form-control/form-control.component';
import {HttpService} from './services/http.service'; import { FocusBlurDirective } from './directives/focus-blur.directive';
import {UtilsService} from './services/utils.service'; import { PasswordDirective } from './directives/password.directive';
import {FocusBlurDirective} from './directives/focus-blur.directive';
import { TruncatePipe } from './pipes/truncate.pipe'; import { TruncatePipe } from './pipes/truncate.pipe';
import { HttpService } from './services/http.service';
import { IconsService } from './services/icons.service';
import { UtilsService } from './services/utils.service';
const PIPES = [ const PIPES = [
TruncatePipe TruncatePipe
...@@ -15,21 +19,30 @@ const COMPONENTS = [ ...@@ -15,21 +19,30 @@ const COMPONENTS = [
]; ];
const DIRECTIVES = [ const DIRECTIVES = [
FocusBlurDirective FocusBlurDirective,
PasswordDirective
]; ];
const PROVIDERS = [ const PROVIDERS = [
HttpService, HttpService,
UtilsService UtilsService,
IconsService
];
const MODULES = [
AngularSvgIconModule,
HttpClientModule
]; ];
@NgModule({ @NgModule({
declarations: [...COMPONENTS, ...DIRECTIVES, ...PIPES], declarations: [...COMPONENTS, ...DIRECTIVES, ...PIPES],
imports: [ imports: [
CommonModule CommonModule,
...MODULES
], ],
providers: PROVIDERS, providers: PROVIDERS,
exports: [ exports: [
...MODULES,
...COMPONENTS, ...COMPONENTS,
...PIPES, ...PIPES,
...DIRECTIVES ...DIRECTIVES
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment