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

View File

@ -1,6 +1,6 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { ReactiveFormsModule } from '@angular/forms';
import { MatDialogModule } from '@angular/material/dialog';
import { RouterTestingModule } from '@angular/router/testing';
import { EmployeeDetailComponent } from './employee-detail.component';

View File

@ -76,7 +76,9 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
setTimeout(() => {
if (this.nameElement) this.nameElement.nativeElement.focus();
if (this.nameElement) {
this.nameElement.nativeElement.focus();
}
}, 0);
}

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 { EmployeeListResolver } from './employee-list-resolver.service';

View File

@ -8,9 +8,7 @@ import { map, tap } from 'rxjs/operators';
import { Employee } from '../employee';
/** 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 EmployeeListDataSource extends DataSource<Employee> {
private filterValue = '';
@ -35,14 +33,20 @@ export class EmployeeListDataSource extends DataSource<Employee> {
| EventEmitter<PageEvent>
| EventEmitter<Sort>
)[] = [observableOf(this.data), this.filter];
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);
}
return merge(...dataMutations)
.pipe(
map(() => this.getFilteredData([...this.data])),
tap((x: Employee[]) => {
if (this.paginator) this.paginator.length = x.length;
if (this.paginator) {
this.paginator.length = x.length;
}
}),
)
.pipe(map((x: Employee[]) => this.getPagedData(this.getSortedData(x))));
@ -64,13 +68,17 @@ export class EmployeeListDataSource extends DataSource<Employee> {
}
private getPagedData(data: Employee[]) {
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: Employee[]) {
if (this.sort === undefined) return data;
if (this.sort === undefined) {
return data;
}
if (!this.sort.active || this.sort.direction === '') {
return data;
}

View File

@ -60,7 +60,9 @@ export class EmployeeListComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
setTimeout(() => {
if (this.filterElement) this.filterElement.nativeElement.focus();
if (this.filterElement) {
this.filterElement.nativeElement.focus();
}
}, 0);
}

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 { RouterTestingModule } from '@angular/router/testing';
import { EmployeeResolver } from './employee-resolver.service';

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 { EmployeeService } from './employee.service';

View File

@ -7,10 +7,6 @@ import { ErrorLoggerService } from '../core/error-logger.service';
import { Employee } from './employee';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/employees';
const serviceName = 'EmployeeService';
@ -20,35 +16,27 @@ export class EmployeeService {
get(id: string | null): Observable<Employee> {
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return <Observable<Employee>>(
this.http
.get<Employee>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
);
return this.http
.get<Employee>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id as Observable<Employee>=${id}`))) as Observable<Employee>;
}
list(): Observable<Employee[]> {
return <Observable<Employee[]>>(
this.http
.get<Employee[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
return this.http
.get<Employee[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Employee[]>;
}
save(employee: Employee): Observable<Employee> {
return <Observable<Employee>>(
this.http
.post<Employee>(`${url}`, employee, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save')))
);
return this.http
.post<Employee>(`${url}`, employee)
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<Employee>;
}
update(employee: Employee): Observable<Employee> {
return <Observable<Employee>>(
this.http
.put<Employee>(`${url}/${employee.id}`, employee, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update')))
);
return this.http
.put<Employee>(`${url}/${employee.id}`, employee)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<Employee>;
}
saveOrUpdate(employee: Employee): Observable<Employee> {
@ -59,19 +47,17 @@ export class EmployeeService {
}
delete(id: string): Observable<Employee> {
return <Observable<Employee>>(
this.http
.delete<Employee>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
);
return this.http
.delete<Employee>(`${url}/${id}`)
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Employee>;
}
autocomplete(term: string): Observable<Employee[]> {
const options = { params: new HttpParams().set('q', term) };
return <Observable<Employee[]>>(
this.http
.get<Employee[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete')))
);
return this.http
.get<Employee[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable<
Employee[]
>;
}
}