Fix: Login deleting old clients was conflicting with login history

Chore: Moved to angular linting using the recommended plugins / settings
This commit is contained in:
2020-12-08 12:09:19 +05:30
parent d5048bc455
commit 57ef355170
176 changed files with 940 additions and 831 deletions
@@ -63,7 +63,9 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
setTimeout(() => {
if (this.nameElement) this.nameElement.nativeElement.focus();
if (this.nameElement) {
this.nameElement.nativeElement.focus();
}
}, 0);
}
@@ -1,5 +1,5 @@
import { inject, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { UserListResolver } from './user-list-resolver.service';
@@ -8,9 +8,7 @@ import { map } from 'rxjs/operators';
import { User } from '../../core/user';
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
function compare(a: string | number, b: string | number, isAsc: boolean) {
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}
const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1);
export class UserListDataSource extends DataSource<User> {
constructor(public data: User[], private paginator?: MatPaginator, private sort?: MatSort) {
@@ -21,11 +19,17 @@ export class UserListDataSource extends DataSource<User> {
const dataMutations: (Observable<User[]> | EventEmitter<PageEvent> | EventEmitter<Sort>)[] = [
observableOf(this.data),
];
if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page);
if (this.sort) dataMutations.push((this.sort as MatSort).sortChange);
if (this.paginator) {
dataMutations.push((this.paginator as MatPaginator).page);
}
if (this.sort) {
dataMutations.push((this.sort as MatSort).sortChange);
}
// Set the paginators length
if (this.paginator) this.paginator.length = this.data.length;
if (this.paginator) {
this.paginator.length = this.data.length;
}
return merge(...dataMutations).pipe(
map(() => this.getPagedData(this.getSortedData([...this.data]))),
@@ -35,13 +39,17 @@ export class UserListDataSource extends DataSource<User> {
disconnect() {}
private getPagedData(data: User[]) {
if (this.paginator === undefined) return data;
if (this.paginator === undefined) {
return data;
}
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
return data.splice(startIndex, this.paginator.pageSize);
}
private getSortedData(data: User[]) {
if (this.sort === undefined) return data;
if (this.sort === undefined) {
return data;
}
if (!this.sort.active || this.sort.direction === '') {
return data;
}
@@ -1,5 +1,5 @@
import { inject, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { UserResolver } from './user-resolver.service';
+1 -1
View File
@@ -1,5 +1,5 @@
import { inject, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { UserService } from './user.service';
+22 -39
View File
@@ -1,4 +1,4 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
@@ -6,9 +6,6 @@ import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
import { User } from '../core/user';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/users';
const serviceName = 'UserService';
@@ -20,51 +17,39 @@ export class UserService {
get(id: string | null): Observable<User> {
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return <Observable<User>>(
this.http
.get<User>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
);
return this.http
.get<User>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<User>;
}
list(): Observable<User[]> {
return <Observable<User[]>>(
this.http
.get<User[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
return this.http
.get<User[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<User[]>;
}
listOfNames(): Observable<string[]> {
return <Observable<string[]>>(
this.http
.get<string[]>(`${url}/active`)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
return this.http
.get<string[]>(`${url}/active`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<string[]>;
}
save(user: User): Observable<User> {
return <Observable<User>>(
this.http
.post<User>(`${url}`, user, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save')))
);
return this.http
.post<User>(`${url}`, user)
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<User>;
}
update(user: User): Observable<User> {
return <Observable<User>>(
this.http
.put<User>(`${url}/${user.id}`, user, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update')))
);
return this.http
.put<User>(`${url}/${user.id}`, user)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<User>;
}
updateMe(user: User): Observable<User> {
return <Observable<User>>(
this.http
.put<User>(`${url}/me`, user, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update')))
);
return this.http
.put<User>(`${url}/me`, user)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<User>;
}
saveOrUpdate(user: User): Observable<User> {
@@ -75,10 +60,8 @@ export class UserService {
}
delete(id: string): Observable<User> {
return <Observable<User>>(
this.http
.delete<User>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
);
return this.http
.delete<User>(`${url}/${id}`)
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<User>;
}
}