Skip to content

Commit 9f39303

Browse files
authored
Merge 1d40b7d into 53d3f35
2 parents 53d3f35 + 1d40b7d commit 9f39303

19 files changed

+410
-46
lines changed

src/app/app.component.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1+
<app-internet-connection-status listen="true">
2+
3+
<ng-container *fast>
4+
</ng-container>
5+
6+
<ng-container *slow>
7+
</ng-container>
8+
9+
<ng-container *offline>
10+
</ng-container>
11+
12+
</app-internet-connection-status>
113
<router-outlet></router-outlet>

src/app/app.module.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ import { SearchUserComponent } from './modules/shared/components/search-user/sea
9595
import { TimeRangeCustomComponent } from './modules/reports/components/time-range-custom/time-range-custom.component';
9696
import { TimeRangeHeaderComponent } from './modules/reports/components/time-range-custom/time-range-header/time-range-header.component';
9797
import { TimeRangeOptionsComponent } from './modules/reports/components/time-range-custom/time-range-options/time-range-options.component';
98+
import { InternetConnectionStatusComponent } from './modules/internet-connection-status/internet-connection-status.component';
99+
import { FastDirective} from './modules/internet-connection-status/internet-connection-directives/fast.directive';
100+
import { SlowDirective} from './modules/internet-connection-status/internet-connection-directives/slow.directive';
101+
import { OfflineDirective} from './modules/internet-connection-status/internet-connection-directives/offline.directive';
102+
import { ConnectionDirective } from './modules/internet-connection-status/internet-connection-directives/connection.directive';
103+
import { ToastrService } from 'ngx-toastr';
98104

99105
const maskConfig: Partial<IConfig> = {
100106
validation: false,
@@ -154,6 +160,11 @@ const maskConfig: Partial<IConfig> = {
154160
TimeRangeCustomComponent,
155161
TimeRangeHeaderComponent,
156162
TimeRangeOptionsComponent,
163+
InternetConnectionStatusComponent,
164+
SlowDirective,
165+
FastDirective,
166+
OfflineDirective,
167+
ConnectionDirective
157168
],
158169
imports: [
159170
NgxMaskModule.forRoot(maskConfig),
@@ -208,6 +219,7 @@ const maskConfig: Partial<IConfig> = {
208219
},
209220
DatePipe,
210221
CookieService,
222+
ToastrService,
211223
{provide: Window, useValue: window}
212224
],
213225
bootstrap: [AppComponent],

src/app/modules/activities-management/store/activity-management.effects.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr';
99
import * as actions from './activity-management.actions';
1010
import { Activity, ActivityStatus } from './../../shared/models/activity.model';
1111
import { ActivityService } from './../services/activity.service';
12+
import { StatusNetworkService } from '../../shared/services/status-network.service';
1213

1314
@Injectable()
1415
export class ActivityEffects {
1516
constructor(
1617
private actions$: Actions,
1718
private activityService: ActivityService,
18-
private toastrService: ToastrService
19+
private toastrService: ToastrService,
20+
private statusNetworkService: StatusNetworkService
1921
) { }
2022

2123
@Effect()
@@ -27,7 +29,7 @@ export class ActivityEffects {
2729
return new actions.LoadActivitiesSuccess(activities);
2830
}),
2931
catchError((error) => {
30-
this.toastrService.error(error.error.message);
32+
this.statusNetworkService.checkTypeError({error, isError: true});
3133
return of(new actions.LoadActivitiesFail(error));
3234
})
3335
)
@@ -45,7 +47,7 @@ export class ActivityEffects {
4547
return new actions.CreateActivitySuccess(activityData);
4648
}),
4749
catchError((error) => {
48-
this.toastrService.error(error.error.message);
50+
this.statusNetworkService.checkTypeError({error, isError: true});
4951
return of(new actions.CreateActivityFail(error));
5052
})
5153
)
@@ -66,7 +68,7 @@ export class ActivityEffects {
6668
return new actions.ArchiveActivitySuccess(activity);
6769
}),
6870
catchError((error) => {
69-
this.toastrService.error(error.error.message);
71+
this.statusNetworkService.checkTypeError({error, isError: true});
7072
return of(new actions.ArchiveActivityFail(error));
7173
})
7274
)
@@ -84,7 +86,7 @@ export class ActivityEffects {
8486
return new actions.UpdateActivitySuccess(activityData);
8587
}),
8688
catchError((error) => {
87-
this.toastrService.error(error.error.message);
89+
this.statusNetworkService.checkTypeError({error, isError: true});
8890
return of(new actions.UpdateActivityFail(error));
8991
})
9092
)
@@ -106,7 +108,7 @@ export class ActivityEffects {
106108
return new actions.UnarchiveActivitySuccess(activityData);
107109
}),
108110
catchError((error) => {
109-
this.toastrService.error(error.error.message);
111+
this.statusNetworkService.checkTypeError({error, isError: true});
110112
return of(new actions.UnarchiveActivityFail(error));
111113
})
112114
)

src/app/modules/customer-management/components/projects-type/services/project-type.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@angular/core';
22
import { HttpClient, HttpParams } from '@angular/common/http';
33
import { Observable } from 'rxjs';
4-
4+
import { map, catchError } from 'rxjs/operators';
55
import { environment } from '../../../../../../environments/environment';
66
import { ProjectType } from '../../../../shared/models';
77

@@ -29,6 +29,6 @@ export class ProjectTypeService {
2929

3030
updateProjectType(projectTypeData): Observable<any> {
3131
const url = `${this.baseUrl}/${projectTypeData.id}`;
32-
return this.http.put(url, projectTypeData);
32+
return this.http.put(url, projectTypeData)
3333
}
3434
}

src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import * as actions from './project-type.actions';
99
import { ProjectType } from '../../../../shared/models';
1010
import { ProjectTypeService } from '../services/project-type.service';
1111
import { ToastrService } from 'ngx-toastr';
12+
import { StatusNetworkService } from '../../../../shared/services/status-network.service';
1213

1314
@Injectable()
1415
export class ProjectTypeEffects {
1516
constructor(
1617
private actions$: Actions,
1718
private projectTypeService: ProjectTypeService,
18-
private toastrService: ToastrService
19+
private toastrService: ToastrService,
20+
private statusNetworkService: StatusNetworkService
1921
) { }
2022

2123
@Effect()
@@ -27,7 +29,7 @@ export class ProjectTypeEffects {
2729
return new actions.LoadProjectTypesSuccess(projectTypes);
2830
}),
2931
catchError((error) => {
30-
this.toastrService.error(error.error.message);
32+
this.statusNetworkService.checkTypeError({error, isError: true});
3133
return of(new actions.LoadProjectTypesFail(error));
3234
})
3335
)
@@ -45,7 +47,7 @@ export class ProjectTypeEffects {
4547
return new actions.CreateProjectTypeSuccess(projectTypeData);
4648
}),
4749
catchError((error) => {
48-
this.toastrService.error(error.error.message);
50+
this.statusNetworkService.checkTypeError({error, isError: true});
4951
return of(new actions.CreateProjectTypeFail(error));
5052
})
5153
)
@@ -63,7 +65,7 @@ export class ProjectTypeEffects {
6365
return new actions.DeleteProjectTypeSuccess(protectTypeId);
6466
}),
6567
catchError((error) => {
66-
this.toastrService.error(error.error.message);
68+
this.statusNetworkService.checkTypeError({error, isError: true});
6769
return of(new actions.DeleteProjectTypeFail(error));
6870
})
6971
)
@@ -81,7 +83,7 @@ export class ProjectTypeEffects {
8183
return new actions.UpdateProjectTypeSuccess(projectTypeData);
8284
}),
8385
catchError((error) => {
84-
this.toastrService.error(error.error.message);
86+
this.statusNetworkService.checkTypeError({error, isError: true});
8587
return of(new actions.UpdateProjectTypeFail(error));
8688
})
8789
)

src/app/modules/customer-management/components/projects/components/store/project.effects.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { ProjectService } from '../services/project.service';
88
import * as actions from './project.actions';
99
import { ToastrService } from 'ngx-toastr';
1010
import { Status } from 'src/app/modules/shared/models';
11+
import { StatusNetworkService } from '../../../../../shared/services/status-network.service';
1112

1213
@Injectable()
1314
export class ProjectEffects {
1415
constructor(
1516
private actions$: Actions,
1617
private projectService: ProjectService,
17-
private toastrService: ToastrService
18+
private toastrService: ToastrService,
19+
private statusNetworkService: StatusNetworkService
1820
) { }
1921

2022
@Effect()
@@ -26,7 +28,7 @@ export class ProjectEffects {
2628
return new actions.LoadProjectsSuccess(projects);
2729
}),
2830
catchError((error) => {
29-
this.toastrService.error(error.error.message);
31+
this.statusNetworkService.checkTypeError({error, isError: true});
3032
return of(new actions.LoadProjectsFail(error));
3133
})
3234
)
@@ -42,7 +44,7 @@ export class ProjectEffects {
4244
return new actions.LoadCustomerProjectsSuccess(project);
4345
}),
4446
catchError((error) => {
45-
this.toastrService.error(error.error.message);
47+
this.statusNetworkService.checkTypeError({error, isError: true});
4648
return of(new actions.LoadCustomerProjectsFail(error));
4749
})
4850
)
@@ -58,7 +60,7 @@ export class ProjectEffects {
5860
return new actions.LoadRecentProjectsSuccess(projects);
5961
}),
6062
catchError((error) => {
61-
this.toastrService.error(error.error.message);
63+
this.statusNetworkService.checkTypeError({error, isError: true});
6264
return of(new actions.LoadRecentProjectsFail(error));
6365
})
6466
)
@@ -76,7 +78,7 @@ export class ProjectEffects {
7678
return new actions.CreateProjectSuccess(projectData);
7779
}),
7880
catchError((error) => {
79-
this.toastrService.error(error.error.message);
81+
this.statusNetworkService.checkTypeError({error, isError: true});
8082
return of(new actions.CreateProjectFail(error));
8183
})
8284
)
@@ -94,7 +96,7 @@ export class ProjectEffects {
9496
return new actions.UpdateProjectSuccess(projectData);
9597
}),
9698
catchError((error) => {
97-
this.toastrService.error(error.error.message);
99+
this.statusNetworkService.checkTypeError({error, isError: true});
98100
return of(new actions.UpdateProjectFail(error));
99101
})
100102
)
@@ -112,7 +114,7 @@ export class ProjectEffects {
112114
return new actions.DeleteProjectSuccess(projectId);
113115
}),
114116
catchError((error) => {
115-
this.toastrService.error(error.error.message);
117+
this.statusNetworkService.checkTypeError({error, isError: true});
116118
return of(new actions.DeleteProjectFail(error));
117119
})
118120
)
@@ -133,7 +135,7 @@ export class ProjectEffects {
133135
return new actions.UnarchiveProjectSuccess(projectData);
134136
}),
135137
catchError((error) => {
136-
this.toastrService.error(error.error.message);
138+
this.statusNetworkService.checkTypeError({error, isError: true});
137139
return of(new actions.UnarchiveProjectFail(error));
138140
})
139141
)

src/app/modules/customer-management/store/customer-management.effects.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr';
99
import { CustomerService } from '../services/customer.service';
1010
import * as actions from './customer-management.actions';
1111
import { Status } from '../../shared/models/customer.model';
12+
import { StatusNetworkService } from '../../shared/services/status-network.service';
1213

1314
@Injectable()
1415
export class CustomerEffects {
1516
constructor(
1617
private actions$: Actions,
1718
private customerService: CustomerService,
18-
private toastrService: ToastrService
19+
private toastrService: ToastrService,
20+
private statusNetworkService: StatusNetworkService
1921
) { }
2022

2123
@Effect()
@@ -27,7 +29,7 @@ export class CustomerEffects {
2729
return new actions.LoadCustomersSuccess(customers);
2830
}),
2931
catchError((error) => {
30-
this.toastrService.error(error.error.message);
32+
this.statusNetworkService.checkTypeError({error, isError: true});
3133
return of(new actions.LoadCustomersFail(error));
3234
}
3335
)
@@ -46,7 +48,7 @@ export class CustomerEffects {
4648
return new actions.CreateCustomerSuccess(customerData);
4749
}),
4850
catchError((error) => {
49-
this.toastrService.error(error.error.message);
51+
this.statusNetworkService.checkTypeError({error, isError: true});
5052
return of(new actions.CreateCustomerFail(error));
5153
})
5254
)
@@ -64,7 +66,7 @@ export class CustomerEffects {
6466
return new actions.DeleteCustomerSuccesss(customerId);
6567
}),
6668
catchError((error) => {
67-
this.toastrService.error(error.error.message);
69+
this.statusNetworkService.checkTypeError({error, isError: true});
6870
return of(new actions.DeleteCustomerFail(error));
6971
})
7072
)
@@ -82,7 +84,7 @@ export class CustomerEffects {
8284
return new actions.UpdateCustomerSuccess(customerData);
8385
}),
8486
catchError((error) => {
85-
this.toastrService.error(error.error.message);
87+
this.statusNetworkService.checkTypeError({error, isError: true});
8688
return of(new actions.UpdateCustomerFail(error));
8789
})
8890
)
@@ -104,7 +106,7 @@ export class CustomerEffects {
104106
return new actions.UpdateCustomerSuccess(customerData);
105107
}),
106108
catchError((error) => {
107-
this.toastrService.error(error.error.message);
109+
this.statusNetworkService.checkTypeError({error, isError: true});
108110
return of(new actions.UpdateCustomerFail(error));
109111
})
110112
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Directive, Attribute, ElementRef, OnInit } from '@angular/core';
2+
3+
@Directive({
4+
selector: '[appConnection]'
5+
})
6+
7+
export class ConnectionDirective implements OnInit {
8+
constructor(
9+
@Attribute('slowSrc') private slowSrc,
10+
@Attribute('fastSrc') private fastSrc,
11+
@Attribute('offlineSrc') private offlineSrc,
12+
private host: ElementRef<HTMLImageElement>
13+
) {
14+
}
15+
16+
ngOnInit() {
17+
const { effectiveType } = navigator.connection;
18+
let networkSatus;
19+
if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){
20+
networkSatus = this.offlineSrc;
21+
}
22+
23+
if (/\fast-5g|3g|4g/.test(effectiveType)) {
24+
networkSatus = this.fastSrc;
25+
}
26+
27+
if (/\slow-2g|2g/.test(effectiveType)) {
28+
networkSatus = this.slowSrc;
29+
}
30+
31+
this.host.nativeElement.setAttribute('src', networkSatus);
32+
}
33+
34+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Directive, TemplateRef } from '@angular/core';
2+
3+
@Directive({
4+
selector: '[appFast]'
5+
})
6+
7+
export class FastDirective {
8+
9+
constructor(public tpl: TemplateRef<any>) { }
10+
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Directive, TemplateRef } from '@angular/core';
2+
3+
@Directive({
4+
selector: '[appOffline]'
5+
})
6+
7+
export class OfflineDirective {
8+
9+
constructor(public tpl: TemplateRef<any>) { }
10+
11+
}

0 commit comments

Comments
 (0)