Commit 67096fbf by Ali Arshad

TSLint fixes

parent 6d835fb6
<div [class]="'form-control-wrapper ' + class" *ngIf='fcn' [ngClass]="{ 'has-error': isHighlighted }">
<ng-content></ng-content>
<span class="error-msg" *ngIf='isHighlighted'>{{ getError() }}</span>
</div>
div([class]="'form-control-wrapper ' + class", *ngIf='fcn', [ngClass]="{ 'has-error': isHighlighted }")
ng-content
span.error-msg(*ngIf='isHighlighted') {{ getError() }}
...@@ -5,7 +5,7 @@ import { FocusBlurDirective } from '../../directives/focus-blur.directive'; ...@@ -5,7 +5,7 @@ import { FocusBlurDirective } from '../../directives/focus-blur.directive';
@Component({ @Component({
selector: 'app-form-control', selector: 'app-form-control',
templateUrl: './form-control.component.pug' templateUrl: './form-control.component.html'
}) })
export class FormControlComponent { export class FormControlComponent {
......
...@@ -11,7 +11,7 @@ export class TruncatePipe implements PipeTransform { ...@@ -11,7 +11,7 @@ export class TruncatePipe implements PipeTransform {
} }
let newValue = ''; let newValue = '';
if (value.length > length) { if (value.length > length) {
newValue = `${value.substring(0, length - 3)} ...` ; newValue = `${value.substring(0, length - 3)} ...`;
} }
return newValue; return newValue;
......
/* tslint:disable */
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Subject } from 'rxjs'; import { Observable, Subject } from 'rxjs';
import { map, share } from 'rxjs/operators'; import { map } from 'rxjs/operators';
@Injectable() @Injectable()
...@@ -13,7 +12,7 @@ export class HttpService { ...@@ -13,7 +12,7 @@ export class HttpService {
private headers; private headers;
private api; private api;
private sendAuthMsg; private sendAuthMsg;
private logoutNotification = new Subject(); private logoutNotification: Subject<string> = new Subject();
constructor( constructor(
private http: HttpClient, private http: HttpClient,
...@@ -22,40 +21,42 @@ export class HttpService { ...@@ -22,40 +21,42 @@ export class HttpService {
this.sendAuthMsg = true; this.sendAuthMsg = true;
} }
setAPIURL(url) { setAPIURL(url): void {
this.api = url; this.api = url;
} }
setTokken(value) { setTokken(value): void {
this.accessTokken = value; this.accessTokken = value;
} }
getToken() { getToken(): string {
return this.accessTokken; return this.accessTokken;
} }
getAPIURL() { getAPIURL(): string {
return this.api; return this.api;
} }
onLogout() { onLogout(): Observable<string> {
return this.logoutNotification.asObservable(); return this.logoutNotification.asObservable();
} }
createHeader(extraHeaders = {}) { createHeader(extraHeaders = {}): void {
const headers = { const headers = {
'Content-Type': 'application/json', ...extraHeaders}; Authorization: '',
'Content-Type': 'application/json', ...extraHeaders
};
if (extraHeaders['Content-Type'] === null) { if (extraHeaders['Content-Type'] === null) {
delete headers['Content-Type']; delete headers['Content-Type'];
} }
if (this.accessTokken) { if (this.accessTokken) {
headers[`Authorization`] = 'Bearer ' + this.accessTokken; headers.Authorization = `Bearer ${this.accessTokken}`;
} }
this.headers = new HttpHeaders(headers); this.headers = new HttpHeaders(headers);
} }
sendUnAuthorizedMessage(message) { sendUnAuthorizedMessage(msg): void {
message = message || 'You need to login first.'; const message = msg || 'You need to login first.';
this.sendAuthMsg = false; this.sendAuthMsg = false;
// this.toastr.error(message, null, {showCloseButton: true}); // this.toastr.error(message, null, {showCloseButton: true});
setTimeout(() => { setTimeout(() => {
...@@ -64,54 +65,58 @@ export class HttpService { ...@@ -64,54 +65,58 @@ export class HttpService {
this.logoutNotification.next('user_logout'); this.logoutNotification.next('user_logout');
} }
mapResponse(resp, returnHeaders = false) { mapResponse(resp, returnHeaders = false): {} {
if (returnHeaders === false) { if (returnHeaders === false) {
return resp.body; return resp.body;
} else { }
return { return {
body: resp.body, body: resp.body,
headers: resp.headers headers: resp.headers
}; };
} }
}
get(method, value = '', showErrors = {}, returnHeaders = false, absoluteUrl = false, extraHeaders = {}) { get(method, value = '', showErrors = {}, returnHeaders = false, absoluteUrl = false, extraHeaders = {}): Observable<{}> {
this.createHeader(extraHeaders); this.createHeader(extraHeaders);
const url = (absoluteUrl ? '' : this.api) + method + value; const url = (absoluteUrl ? '' : this.api) + method + value;
return this.http.get(url, { return this.http.get(url, {
headers: this.headers, headers: this.headers,
observe: 'response' observe: 'response'
}).pipe(map(resp => this.mapResponse(resp, returnHeaders))); })
.pipe(map(resp => this.mapResponse(resp, returnHeaders)));
} }
post(method, value, showErrors = {}, returnHeaders = false, absoluteUrl = false, extraHeaders = {}) { post(method, value, showErrors = {}, returnHeaders = false, absoluteUrl = false, extraHeaders = {}): Observable<{}> {
this.createHeader(extraHeaders); this.createHeader(extraHeaders);
const url = (absoluteUrl ? '' : this.api) + method; const url = (absoluteUrl ? '' : this.api) + method;
return this.http.post(url, value, { return this.http.post(url, value, {
headers: this.headers, headers: this.headers,
observe: 'response' observe: 'response'
}).pipe(map(resp => this.mapResponse(resp, returnHeaders))); })
.pipe(map(resp => this.mapResponse(resp, returnHeaders)));
} }
put(method, value, showErrors = {}, returnHeaders = false) { put(method, value, showErrors = {}, returnHeaders = false): Observable<{}> {
this.createHeader(); this.createHeader();
const url = this.api + method; const url = this.api + method;
return this.http.put(url, value, { return this.http.put(url, value, {
headers: this.headers, headers: this.headers,
observe: 'response' observe: 'response'
}).pipe(map(resp => this.mapResponse(resp, returnHeaders))); })
.pipe(map(resp => this.mapResponse(resp, returnHeaders)));
} }
delete(method, value = '', showErrors = {}, returnHeaders = false) { delete(method, value = '', showErrors = {}, returnHeaders = false): Observable<{}> {
this.createHeader(); this.createHeader();
const url = this.api + method + value; const url = this.api + method + value;
return this.http.delete(url, { return this.http.delete(url, {
headers: this.headers, headers: this.headers,
observe: 'response' observe: 'response'
}).pipe(map(resp => this.mapResponse(resp, returnHeaders))); })
.pipe(map(resp => this.mapResponse(resp, returnHeaders)));
} }
} }
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 { SHOW_ERRORS } from '../config';
@Injectable() @Injectable()
...@@ -13,13 +11,13 @@ export class UtilsService { ...@@ -13,13 +11,13 @@ export class UtilsService {
.forEach(field => { .forEach(field => {
const control = formGroup.get(field); const control = formGroup.get(field);
if (control instanceof FormControl) { if (control instanceof FormControl) {
control.markAsDirty({ onlySelf: true }); control.markAsDirty({onlySelf: true});
} else if (control instanceof FormGroup) { } else if (control instanceof FormGroup) {
this.validateAllFormFields(control); this.validateAllFormFields(control);
} else if (control instanceof FormArray) { } else if (control instanceof FormArray) {
control.controls.forEach(ctrl => { control.controls.forEach(ctrl => {
if (ctrl instanceof FormControl) { if (ctrl instanceof FormControl) {
ctrl.markAsDirty({ onlySelf: true }); ctrl.markAsDirty({onlySelf: true});
} else if (ctrl instanceof FormGroup) { } else if (ctrl instanceof FormGroup) {
this.validateAllFormFields(ctrl); this.validateAllFormFields(ctrl);
} }
...@@ -27,40 +25,4 @@ export class UtilsService { ...@@ -27,40 +25,4 @@ export class UtilsService {
} }
}); });
} }
handleHttpError(error: HttpErrorResponse): any {
switch (error.status) {
case 401:
if (SHOW_ERRORS.e401) {
console.log(`Error ${error.status}`);
}
break;
case 400:
if (SHOW_ERRORS.e400) {
console.log(`Error ${error.status}`);
}
break;
case 500:
if (SHOW_ERRORS.e500) {
console.log(`Error ${error.status}`);
}
break;
case 404:
if (SHOW_ERRORS.e404) {
console.log(`Error ${error.status}`);
}
break;
case 422:
if (SHOW_ERRORS.e422) {
console.log(`Error ${error.status}`);
}
break;
case 403:
if (SHOW_ERRORS.e403) {
console.log(`Error ${error.status}`);
}
break;
default:
}
}
} }
...@@ -18,7 +18,7 @@ export class ConfirmPasswordValidator { ...@@ -18,7 +18,7 @@ export class ConfirmPasswordValidator {
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 ? undefined : {invalidPassword: true};
}; };
} }
......
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core'; 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 { FocusBlurDirective } from './directives/focus-blur.directive'; import { FocusBlurDirective } from './directives/focus-blur.directive';
import { PasswordDirective } from './directives/password.directive'; import { PasswordDirective } from './directives/password.directive';
import { TruncatePipe } from './pipes/truncate.pipe'; import { TruncatePipe } from './pipes/truncate.pipe';
import { HttpService } from './services/http.service'; import { HttpService } from './services/http.service';
import { IconsService } from './services/icons.service';
import { UtilsService } from './services/utils.service'; import { UtilsService } from './services/utils.service';
const PIPES = [ const PIPES = [
...@@ -25,12 +23,10 @@ const DIRECTIVES = [ ...@@ -25,12 +23,10 @@ const DIRECTIVES = [
const PROVIDERS = [ const PROVIDERS = [
HttpService, HttpService,
UtilsService, UtilsService
IconsService
]; ];
const MODULES = [ const MODULES = [
AngularSvgIconModule,
HttpClientModule HttpClientModule
]; ];
...@@ -48,4 +44,5 @@ const MODULES = [ ...@@ -48,4 +44,5 @@ const MODULES = [
...DIRECTIVES ...DIRECTIVES
] ]
}) })
export class VqodeModule { } export class VqodeModule {
}
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