Skip to content

Commit a6ef67c

Browse files
committed
update block ui and interceptor
1 parent 2cdc69c commit a6ef67c

File tree

10 files changed

+57
-12
lines changed

10 files changed

+57
-12
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"ngx-embed-video": "^0.3.0",
3737
"ngx-mask": "^6.1.2",
3838
"ngx-social-login": "^6.0.1",
39+
"ngx-spinner": "^6.1.2",
3940
"ngx-toastr": "^8.10.0",
4041
"primeicons": "1.0.0-beta.9",
4142
"primeng": "^6.0.2",

src/app/Providers/my-http-interceptor.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { RequestError } from './../shared/models/index';
2+
import { ToastrService } from 'ngx-toastr';
13
import { Injectable } from "@angular/core";
24
import { HttpRequest, HttpHandler, HttpEvent } from "@angular/common/http";
35
import { Observable } from "rxjs/Rx";
@@ -6,23 +8,31 @@ import { Observable } from "rxjs/Rx";
68
@Injectable()
79
export class MyHttpInterceptor {
810
constructor(
11+
private toastr: ToastrService,
912
) { }
1013

11-
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
14+
intercept(
15+
req: HttpRequest<any>,
16+
next: HttpHandler
17+
): Observable<HttpEvent<any>> {
1218

13-
console.log("intercepted request ... ");
19+
// console.log("intercepted request ... ");
1420

1521
// Clone the request to add the new header.
1622
const authReq = req.clone({ headers: req.headers.set("headerName", "headerValue") });
17-
18-
console.log("Sending request with new header now ...");
23+
24+
// console.log("Sending request with new header now ...");
1925

2026
//send the newly created request
2127
return next.handle(authReq)
2228
.catch((error, caught) => {
2329
//intercept the respons error and displace it to the console
24-
console.log("Error Occurred");
25-
console.log(error);
30+
let requestError: RequestError = error;
31+
if (requestError.status === 404) {
32+
this.toastr.error("Request " + requestError.statusText, "Error");
33+
} else {
34+
this.toastr.error("Api Failled", "Error");
35+
}
2636
//return the error to the method that called it
2737
return Observable.throw(error);
2838
}) as any;

src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class AppComponent {
1818
private router: Router
1919
) {
2020
setTheme('bs3');
21-
this.redirection()
21+
this.redirection();
2222
}
2323

2424
redirection() {

src/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { MyHttpInterceptor } from './Providers/my-http-interceptor';
2727
],
2828
exports: [
2929
ToastrModule,
30-
AppRoutingModule
30+
AppRoutingModule,
3131
],
3232
providers: [
3333
HttpClient,
@@ -36,7 +36,7 @@ import { MyHttpInterceptor } from './Providers/my-http-interceptor';
3636
AlwaysAuthGuard,
3737
OnlyLoggedInUsersGuard,
3838
{ provide: LocationStrategy, useClass: HashLocationStrategy },
39-
{ provide: HTTP_INTERCEPTORS, useClass: MyHttpInterceptor, multi: true }
39+
{ provide: HTTP_INTERCEPTORS, useClass: MyHttpInterceptor, multi: true }
4040
],
4141
bootstrap: [AppComponent],
4242
schemas: [

src/app/private/home/home.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<p-blockUI [blocked]="blocked"></p-blockUI>
12
<div id="home" class="row">
23
<div class="col-lg-12 col-md-12 col-xl-12">
34
<h2 class="pull-left"><i class="fa fa-table"></i> All Cities</h2>

src/app/private/home/home.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ export class PrivateHomeComponent implements OnInit {
1717
public totalRecords: number;
1818
public loading: boolean;
1919
public bsModalRef: BsModalRef;
20+
public blocked: boolean;
2021
constructor(
2122
private api: HTTPService,
2223
private modalService: BsModalService
23-
) { }
24+
) {
25+
this.blocked = true;
26+
}
2427

2528

2629
ngOnInit() {
2730
this.api.getData()
2831
.subscribe((response: any) => {
2932
this.data = response.city || [];
3033
this.totalRecords = this.data.length;
34+
this.blocked = false;
3135
// console.log(this.data);
3236
}, (e) => {
3337
console.log(e);

src/app/private/private.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { AboutComponent } from './about/about.component';
1919
import { GalleryComponent } from './gallery/gallery.component';
2020
import { DemoChartsComponent } from './demo-charts/demo-charts.component';
2121
import { FeatureComponent } from './feature/feature.component';
22+
import {BlockUIModule} from 'primeng/blockui';
2223

2324

2425
@NgModule({
@@ -44,7 +45,8 @@ import { FeatureComponent } from './feature/feature.component';
4445
}
4546
}
4647
}
47-
)
48+
),
49+
BlockUIModule
4850
],
4951
declarations: [
5052
PrivateComponent,

src/app/shared/enums/enums.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export enum ErrorMessages{
2+
ApiFailled = "Api has failled",
3+
Saved = "data has been saved",
4+
NotSaved = "data has been saved",
5+
Deleted = "data has been deleted",
6+
FillMandatoryField = "Please Fill All Mandataory Field(s)",
7+
InvalidCredencials = "Invalid Credentials"
8+
}

src/app/shared/models/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11

2-
export * from './user';
2+
export * from './user';
3+
4+
export interface RequestError {
5+
error?: string;
6+
headers?:any;
7+
message?:string;
8+
name:string;
9+
ok:boolean;
10+
status:number;
11+
statusText:string;
12+
url:string;
13+
}

0 commit comments

Comments
 (0)