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:
1 parent
d5048bc455
commit
57ef355170
176 files changed
+940
-831
No files matched your search
@@ -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 { ClientDetailComponent } from './client-detail.component';
|
||||
|
||||
@@ -54,7 +54,9 @@ export class ClientDetailComponent 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 { ClientListResolver } from './client-list-resolver.service';
|
||||
|
||||
@@ -8,9 +8,7 @@ import { map } from 'rxjs/operators';
|
||||
import { Client } from '../client';
|
||||
|
||||
/** 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 ClientListDataSource extends DataSource<Client> {
|
||||
constructor(public data: Client[], private paginator?: MatPaginator, private sort?: MatSort) {
|
||||
super();
|
||||
@@ -20,11 +18,17 @@ export class ClientListDataSource extends DataSource<Client> {
|
||||
const dataMutations: (Observable<Client[]> | 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]))),
|
||||
@@ -34,13 +38,17 @@ export class ClientListDataSource extends DataSource<Client> {
|
||||
disconnect() {}
|
||||
|
||||
private getPagedData(data: Client[]) {
|
||||
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: Client[]) {
|
||||
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 { ClientResolver } from './client-resolver.service';
|
||||
|
||||
@@ -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 { ClientService } from './client.service';
|
||||
|
||||
|
||||
@@ -7,9 +7,6 @@ import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
import { Client } from './client';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
const url = '/api/clients';
|
||||
const serviceName = 'ClientService';
|
||||
|
||||
@@ -21,34 +18,26 @@ export class ClientService {
|
||||
|
||||
get(id: string | null): Observable<Client> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return <Observable<Client>>(
|
||||
this.http
|
||||
.get<Client>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
);
|
||||
return this.http
|
||||
.get<Client>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id as Observable<Client>=${id}`))) as Observable<Client>;
|
||||
}
|
||||
|
||||
list(): Observable<Client[]> {
|
||||
return <Observable<Client[]>>(
|
||||
this.http
|
||||
.get<Client[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
return this.http
|
||||
.get<Client[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Client[]>;
|
||||
}
|
||||
|
||||
update(client: Client): Observable<Client> {
|
||||
return <Observable<Client>>(
|
||||
this.http
|
||||
.put<Client>(`${url}/${client.id}`, client, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update')))
|
||||
);
|
||||
return this.http
|
||||
.put<Client>(`${url}/${client.id}`, client)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<Client>;
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Client> {
|
||||
return <Observable<Client>>(
|
||||
this.http
|
||||
.delete<Client>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
|
||||
);
|
||||
return this.http
|
||||
.delete<Client>(`${url}/${id}`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Client>;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user