Skip to content

Commit

Permalink
Get sample data fixed (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjimenez77 committed Nov 30, 2017
1 parent a00d554 commit b28f38e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
24 changes: 5 additions & 19 deletions src/app/core/security/httpRequestInterceptor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,18 @@ export class HttpRequestInterceptorService implements HttpInterceptor {
constructor(private router: Router,
private auth: AuthService) {
this.headers = new HttpHeaders();
this.headers.append('Content-Type', 'application/json');
}

setHeaderToken(name, value) {
this.headers.delete(name);
this.headers.append(name, value);
}

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Get the auth header from the service.
const authHeader: string = this.auth.getToken();
if (authHeader) {
this.setHeaderToken('x-csrf-token', authHeader);
const authReq: HttpRequest<any> = req.clone({withCredentials: true, headers: this.headers});

next.handle(authReq).subscribe((data: any) => {
console.log(data);
return Observable.of(data);
}, (error: any) => {
if (error.status === 400 || error.status === 500) {
this.auth.setLogged(false);
this.headers.delete('x-csrf-token');
this.router.navigate(['/login']);
}
return Observable.throw(error);
const authReq: HttpRequest<any> = req.clone({
withCredentials: true,
setHeaders: { 'x-csrf-token': authHeader }
});

return next.handle(authReq);
} else {
return next.handle(req);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</form>
<mat-divider></mat-divider>
<td-data-table #dataTable
[data]="orders"
[data]="data"
[columns]="columns"
[sortable]="true"
clickable="true"
Expand All @@ -55,7 +55,7 @@
<div class="mat-padding" *ngIf="!dataTable.hasData" layout="row" layout-align="center center">
<h3>No results to display.</h3>
</div>
<td-paging-bar #pagingBar [pageSize]="pageSize" [total]="totalIems" (change)="page($event)">
<td-paging-bar #pagingBar [pageSize]="pageSize" [total]="totalItems" (change)="page($event)">
<span hide-xs>Rows per page:</span>
<mat-select [style.width.px]="50" [(ngModel)]="pageSize">
<mat-option *ngFor="let size of pageSizes" [value]="size">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ export class SampleDataGridComponent implements OnInit {
.subscribe((res: any) => {
this.data = res.result;
this.totalItems = res.pagination.total;
this.dataTable.refresh();
},
(error: any) => {
console.error(error);
this._dialogService.openAlert({
message: error.message,
title: this.getTranslation('ERROR'),
closeButton: 'CLOSE'
setTimeout(() => {
this._dialogService.openAlert({
message: error.message,
title: this.getTranslation('ERROR'),
closeButton: 'CLOSE'
});
});
});
}
Expand Down Expand Up @@ -104,8 +106,8 @@ export class SampleDataGridComponent implements OnInit {
}

sort(sortEvent: ITdDataTableSortChangeEvent): void {
this.sorting = _.reject(this.sorting, { 'name': sortEvent.name });
this.sorting.push({ 'name': sortEvent.name, 'direction': sortEvent.order });
this.sorting = [];
this.sorting.push({ 'name': sortEvent.name.split('.').pop(), 'direction': '' + sortEvent.order });
this.getData();
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/sample-data/services/sample-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SampleDataDataGridService {
sort: sort
};

return this.http.post(this.urlService + 'search', pageData);
return this.http.post<any>(this.urlService + 'search', pageData);
}

saveData(data) {
Expand Down

0 comments on commit b28f38e

Please sign in to comment.