Skip to content
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
<app-internet-connection-status listen="true">

<ng-container *fast>
</ng-container>

<ng-container *slow>
</ng-container>

<ng-container *offline>
</ng-container>

</app-internet-connection-status>
<router-outlet></router-outlet>
10 changes: 10 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ import { SearchUserComponent } from './modules/shared/components/search-user/sea
import { TimeRangeCustomComponent } from './modules/reports/components/time-range-custom/time-range-custom.component';
import { TimeRangeHeaderComponent } from './modules/reports/components/time-range-custom/time-range-header/time-range-header.component';
import { TimeRangeOptionsComponent } from './modules/reports/components/time-range-custom/time-range-options/time-range-options.component';
import { InternetConnectionStatusComponent } from './modules/internet-connection-status/internet-connection-status.component';
import { FastDirective} from './modules/internet-connection-status/internet-connection-directives/fast.directive';
import { SlowDirective} from './modules/internet-connection-status/internet-connection-directives/slow.directive';
import { OfflineDirective} from './modules/internet-connection-status/internet-connection-directives/offline.directive';
import { ConnectionDirective } from './modules/internet-connection-status/internet-connection-directives/connection.directive';

const maskConfig: Partial<IConfig> = {
validation: false,
Expand Down Expand Up @@ -154,6 +159,11 @@ const maskConfig: Partial<IConfig> = {
TimeRangeCustomComponent,
TimeRangeHeaderComponent,
TimeRangeOptionsComponent,
InternetConnectionStatusComponent,
SlowDirective,
FastDirective,
OfflineDirective,
ConnectionDirective
],
imports: [
NgxMaskModule.forRoot(maskConfig),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr';
import * as actions from './activity-management.actions';
import { Activity, ActivityStatus } from './../../shared/models/activity.model';
import { ActivityService } from './../services/activity.service';
import { StatusNetworkService } from '../../shared/services/status-network.service';

@Injectable()
export class ActivityEffects {
constructor(
private actions$: Actions,
private activityService: ActivityService,
private toastrService: ToastrService
private toastrService: ToastrService,
private statusNetworkService: StatusNetworkService
) { }

@Effect()
Expand All @@ -27,7 +29,7 @@ export class ActivityEffects {
return new actions.LoadActivitiesSuccess(activities);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadActivitiesFail(error));
})
)
Expand All @@ -45,7 +47,7 @@ export class ActivityEffects {
return new actions.CreateActivitySuccess(activityData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.CreateActivityFail(error));
})
)
Expand All @@ -66,7 +68,7 @@ export class ActivityEffects {
return new actions.ArchiveActivitySuccess(activity);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.ArchiveActivityFail(error));
})
)
Expand All @@ -84,7 +86,7 @@ export class ActivityEffects {
return new actions.UpdateActivitySuccess(activityData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateActivityFail(error));
})
)
Expand All @@ -106,7 +108,7 @@ export class ActivityEffects {
return new actions.UnarchiveActivitySuccess(activityData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UnarchiveActivityFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { Observable } from 'rxjs';
import { Observable } from 'rxjs';

creo q esa linea en blanco estaba bien porque separa las importaciones externas de los modulos internos


import { environment } from '../../../../../../environments/environment';
import { ProjectType } from '../../../../shared/models';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import * as actions from './project-type.actions';
import { ProjectType } from '../../../../shared/models';
import { ProjectTypeService } from '../services/project-type.service';
import { ToastrService } from 'ngx-toastr';
import { StatusNetworkService } from '../../../../shared/services/status-network.service';

@Injectable()
export class ProjectTypeEffects {
constructor(
private actions$: Actions,
private projectTypeService: ProjectTypeService,
private toastrService: ToastrService
private toastrService: ToastrService,
private statusNetworkService: StatusNetworkService
) { }

@Effect()
Expand All @@ -27,7 +29,7 @@ export class ProjectTypeEffects {
return new actions.LoadProjectTypesSuccess(projectTypes);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadProjectTypesFail(error));
})
)
Expand All @@ -45,7 +47,7 @@ export class ProjectTypeEffects {
return new actions.CreateProjectTypeSuccess(projectTypeData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.CreateProjectTypeFail(error));
})
)
Expand All @@ -63,7 +65,7 @@ export class ProjectTypeEffects {
return new actions.DeleteProjectTypeSuccess(protectTypeId);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.DeleteProjectTypeFail(error));
})
)
Expand All @@ -81,7 +83,7 @@ export class ProjectTypeEffects {
return new actions.UpdateProjectTypeSuccess(projectTypeData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateProjectTypeFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { ProjectService } from '../services/project.service';
import * as actions from './project.actions';
import { ToastrService } from 'ngx-toastr';
import { Status } from 'src/app/modules/shared/models';
import { StatusNetworkService } from '../../../../../shared/services/status-network.service';

@Injectable()
export class ProjectEffects {
constructor(
private actions$: Actions,
private projectService: ProjectService,
private toastrService: ToastrService
private toastrService: ToastrService,
private statusNetworkService: StatusNetworkService
) { }

@Effect()
Expand All @@ -26,7 +28,7 @@ export class ProjectEffects {
return new actions.LoadProjectsSuccess(projects);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadProjectsFail(error));
})
)
Expand All @@ -42,7 +44,7 @@ export class ProjectEffects {
return new actions.LoadCustomerProjectsSuccess(project);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadCustomerProjectsFail(error));
})
)
Expand All @@ -58,7 +60,7 @@ export class ProjectEffects {
return new actions.LoadRecentProjectsSuccess(projects);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadRecentProjectsFail(error));
})
)
Expand All @@ -76,7 +78,7 @@ export class ProjectEffects {
return new actions.CreateProjectSuccess(projectData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.CreateProjectFail(error));
})
)
Expand All @@ -94,7 +96,7 @@ export class ProjectEffects {
return new actions.UpdateProjectSuccess(projectData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateProjectFail(error));
})
)
Expand All @@ -112,7 +114,7 @@ export class ProjectEffects {
return new actions.DeleteProjectSuccess(projectId);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.DeleteProjectFail(error));
})
)
Expand All @@ -133,7 +135,7 @@ export class ProjectEffects {
return new actions.UnarchiveProjectSuccess(projectData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UnarchiveProjectFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr';
import { CustomerService } from '../services/customer.service';
import * as actions from './customer-management.actions';
import { Status } from '../../shared/models/customer.model';
import { StatusNetworkService } from '../../shared/services/status-network.service';

@Injectable()
export class CustomerEffects {
constructor(
private actions$: Actions,
private customerService: CustomerService,
private toastrService: ToastrService
private toastrService: ToastrService,
private statusNetworkService: StatusNetworkService
) { }

@Effect()
Expand All @@ -27,7 +29,7 @@ export class CustomerEffects {
return new actions.LoadCustomersSuccess(customers);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadCustomersFail(error));
}
)
Expand All @@ -46,7 +48,7 @@ export class CustomerEffects {
return new actions.CreateCustomerSuccess(customerData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.CreateCustomerFail(error));
})
)
Expand All @@ -64,7 +66,7 @@ export class CustomerEffects {
return new actions.DeleteCustomerSuccesss(customerId);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.DeleteCustomerFail(error));
})
)
Expand All @@ -82,7 +84,7 @@ export class CustomerEffects {
return new actions.UpdateCustomerSuccess(customerData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateCustomerFail(error));
})
)
Expand All @@ -104,7 +106,7 @@ export class CustomerEffects {
return new actions.UpdateCustomerSuccess(customerData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateCustomerFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TestBed } from '@angular/core/testing';
import { ConnectionDirective } from './connection.directive';

describe('ConnectionDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ConnectionDirective]
});
});

it('should create an instance', () => {
const directive = new ConnectionDirective('slowSrc', 'fastSrc', 'offlineSrc', undefined);
expect(directive).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Directive, Attribute, ElementRef, OnInit } from '@angular/core';

@Directive({
selector: '[appConnection]'
})

export class ConnectionDirective implements OnInit {
constructor(
@Attribute('slowSrc') private slowSrc,
@Attribute('fastSrc') private fastSrc,
@Attribute('offlineSrc') private offlineSrc,
private host: ElementRef<HTMLImageElement>
) {
}

ngOnInit() {
const { effectiveType } = navigator.connection;
let networkSatus;
if (/\fast-5g|3g|4g/.test(effectiveType)) {
networkSatus = this.fastSrc;
return;
}
if (/\slow-2g|2g/.test(effectiveType)) {
networkSatus = this.slowSrc;
return;
}
networkSatus = this.offlineSrc;

this.host.nativeElement.setAttribute('src', networkSatus);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TestBed } from '@angular/core/testing';
import { FastDirective } from './fast.directive';

describe('FastDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [FastDirective]
});
});
it('should create an instance', () => {
const directive = new FastDirective(undefined);
expect(directive).toBeTruthy();
});
Comment on lines +10 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should create an instance', () => {
const directive = new FastDirective(undefined);
expect(directive).toBeTruthy();
});
it('should create an instance', () => {
const directive = new FastDirective(undefined);
expect(directive).toBeTruthy();
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Directive, TemplateRef } from '@angular/core';

@Directive({
selector: '[appFast]'
})

export class FastDirective {

constructor(public tpl: TemplateRef<any>) { }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TestBed } from '@angular/core/testing';
import { OfflineDirective } from './offline.directive';

describe('FastDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [OfflineDirective]
});
});
it('should create an instance', () => {
const directive = new OfflineDirective(undefined);
expect(directive).toBeTruthy();
});
Comment on lines +10 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should create an instance', () => {
const directive = new OfflineDirective(undefined);
expect(directive).toBeTruthy();
});
it('should create an instance', () => {
const directive = new OfflineDirective(undefined);
expect(directive).toBeTruthy();
});

});
Loading