Limpieza
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: ApiError;
|
||||
readonly success: boolean;
|
||||
readonly data?: T;
|
||||
readonly error?: ApiError;
|
||||
}
|
||||
|
||||
export interface ApiError {
|
||||
|
||||
@@ -14,10 +14,12 @@ export class HeaderComponent implements OnInit {
|
||||
|
||||
async login(): Promise<void> {
|
||||
this.oauthService.configure(authConfig);
|
||||
await this.oauthService.loadDiscoveryDocument();
|
||||
sessionStorage.setItem('flow', 'code');
|
||||
|
||||
this.oauthService.initLoginFlow();
|
||||
await this.oauthService.loadDiscoveryDocumentAndTryLogin().then((_) => {
|
||||
console.log(
|
||||
'LOGGED=' + (this.oauthService.hasValidIdToken()
|
||||
&& this.oauthService.hasValidAccessToken())
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
|
||||
@@ -3,7 +3,6 @@ import { OAuthService } from 'angular-oauth2-oidc';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ApiService } from '../services/api.service';
|
||||
import { Travel } from '../entities/travel';
|
||||
import { ApiResponse } from '../entities/api-response';
|
||||
|
||||
@Component({
|
||||
templateUrl: './home.component.html',
|
||||
@@ -25,27 +24,6 @@ export class HomeComponent implements OnInit {
|
||||
this.route.params.subscribe((p) => {
|
||||
this.login = p['login'];
|
||||
});
|
||||
|
||||
this.apiService
|
||||
.call('/travel/list')
|
||||
.subscribe((res: ApiResponse<Travel[]>) => {
|
||||
if (res.success) {
|
||||
this.userTravels = res.data;
|
||||
console.log(res.data);
|
||||
} else {
|
||||
console.error(res.error.code + ' ' + res.error.msg);
|
||||
}
|
||||
});
|
||||
|
||||
// This would directly (w/o user interaction) redirect the user to the
|
||||
// login page if they are not already logged in.
|
||||
/*
|
||||
this.oauthService.loadDiscoveryDocumentAndTryLogin().then(_ => {
|
||||
if (!this.oauthService.hasValidIdToken() || !this.oauthService.hasValidAccessToken()) {
|
||||
this.oauthService.initImplicitFlow('some-state');
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
loadUserProfile(): void {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.lessons-table {
|
||||
.travel-table {
|
||||
min-height: 360px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="course">
|
||||
<mat-form-field>
|
||||
<input matInput placeholder="Search lessons" #input />
|
||||
<input matInput placeholder="Search travel" #input />
|
||||
</mat-form-field>
|
||||
|
||||
<div class="spinner-container" *ngIf="dataSource.loading$ | async">
|
||||
@@ -8,7 +8,7 @@
|
||||
</div>
|
||||
|
||||
<mat-table
|
||||
class="lessons-table mat-elevation-z8"
|
||||
class="travel-table mat-elevation-z8"
|
||||
[dataSource]="dataSource"
|
||||
matSort
|
||||
matSortActive="driver"
|
||||
|
||||
@@ -44,8 +44,7 @@ export class TravelListComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.dataSource = new TravelsDataSource(this.apiService);
|
||||
|
||||
this.dataSource.loadLessons(1, '', 'asc', 0, 3);
|
||||
this.loadTravels();
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
@@ -69,8 +68,7 @@ export class TravelListComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
loadTravels(): void {
|
||||
this.dataSource.loadLessons(
|
||||
1,
|
||||
this.dataSource.loadTravels(
|
||||
this.input.nativeElement.value,
|
||||
this.sort.direction,
|
||||
this.paginator.pageIndex,
|
||||
|
||||
@@ -6,7 +6,6 @@ import { Travel } from '../entities/travel';
|
||||
import { ApiService } from '../services/api.service';
|
||||
|
||||
export class TravelsDataSource implements DataSource<Travel> {
|
||||
numTravels = 0;
|
||||
private travelsSubject = new BehaviorSubject<Travel[]>([]);
|
||||
|
||||
private loadingSubject = new BehaviorSubject<boolean>(false);
|
||||
@@ -15,8 +14,7 @@ export class TravelsDataSource implements DataSource<Travel> {
|
||||
|
||||
constructor(private apiService: ApiService) {}
|
||||
|
||||
loadLessons(
|
||||
courseId: number,
|
||||
loadTravels(
|
||||
filter: string,
|
||||
sortDirection: string,
|
||||
pageIndex: number,
|
||||
@@ -32,17 +30,8 @@ export class TravelsDataSource implements DataSource<Travel> {
|
||||
)
|
||||
.subscribe((res) => {
|
||||
const data = (res as ApiResponse<Travel[]>).data;
|
||||
this.numTravels = data.length;
|
||||
this.travelsSubject.next(data);
|
||||
});
|
||||
|
||||
// this.apiService
|
||||
// .findLessons(courseId, filter, sortDirection, pageIndex, pageSize)
|
||||
// .pipe(
|
||||
// catchError(() => of([])),
|
||||
// finalize(() => this.loadingSubject.next(false))
|
||||
// )
|
||||
// .subscribe((lessons) => this.lessonsSubject.next(lessons));
|
||||
}
|
||||
|
||||
connect(collectionViewer: CollectionViewer): Observable<Travel[]> {
|
||||
|
||||
Reference in New Issue
Block a user