Skip to content

Commit

Permalink
OMKR-1 | Visitor profile added
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavsingh4522 committed Dec 14, 2023
1 parent d2b4c59 commit 34e996a
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 4 deletions.
31 changes: 29 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Component, OnInit } from '@angular/core';
import { Title, Meta } from '@angular/platform-browser';
import { NavigationEnd, Router } from '@angular/router';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Location } from '@angular/common';


import * as AOS from 'aos';
import { VisitorDetail } from './models/admin/visitor/visitor-detail';
import { SessionService } from './services/session/session.service';

@Component({
selector: 'app-root',
Expand All @@ -14,14 +16,26 @@ import * as AOS from 'aos';
})
export class AppComponent implements OnInit {
title = 'Keshav Singh Portfolio';
visitorData: VisitorDetail={
userAgent: '',
browserName: '',
browserVersion: '',
cookiesEnabled: false,
platform: '',
language: ''
};

constructor(private router: Router, private titleService: Title,
private metaService: Meta,
private translateService: TranslateService,
private location: Location) {
private location: Location,
private sessionService: SessionService) {
translateService.setDefaultLang('en');
// or
translateService.use('en');

this.visitorData = this.getVisitorInfo();
sessionService.setLocalStorageIdentifier();
}

ngOnInit(): void {
Expand All @@ -33,5 +47,18 @@ export class AppComponent implements OnInit {
// });

AOS.init();

console.log('Visitor Data: ' + JSON.stringify(this.visitorData));
}

getVisitorInfo(): VisitorDetail {
return {
userAgent: navigator.userAgent,
browserName: navigator.appName,
browserVersion: navigator.appVersion,
cookiesEnabled: navigator.cookieEnabled,
platform: navigator.platform,
language: navigator.language,
};
}
}
6 changes: 4 additions & 2 deletions src/app/components/admin/admin-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { AdminComponent } from './admin.component';
import { AddOrganizationComponent } from './organization/add-organization/add-organization.component';
import { ListOrganizationComponent } from './organization/list-organization/list-organization.component';
import { OrganizationComponent } from './organization/organization.component';
import { VisitorComponent } from './visitor/visitor.component';

const routes: Routes = [ {
const routes: Routes = [{
path: "", component: AdminComponent, children: [
{ path: "add-organization", component: AddOrganizationComponent },
{ path: "list-organization", component: ListOrganizationComponent },
{ path: "organization", component:OrganizationComponent}
{ path: "organization", component: OrganizationComponent },
{ path: "visitor", component: VisitorComponent }
]
}];

Expand Down
12 changes: 12 additions & 0 deletions src/app/models/admin/navbar/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ export const menu: NavItem[] = [
route: '/admin/organization'
}
]
},
{
displayName: 'Visitor',
iconName: 'person_outline',
route: 'visitor',
// children: [
// {
// displayName: 'Account Info',
// iconName: 'account_box',
// route: '/admin/organization'
// }
// ]
}
];
8 changes: 8 additions & 0 deletions src/app/models/admin/visitor/visitor-detail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface VisitorDetail {
userAgent: string;
browserName: string;
browserVersion: string;
cookiesEnabled: boolean;
platform: string;
language: string;
}
16 changes: 16 additions & 0 deletions src/app/services/session/session.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { SessionService } from './session.service';

describe('SessionService', () => {
let service: SessionService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SessionService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
25 changes: 25 additions & 0 deletions src/app/services/session/session.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class SessionService {

constructor() { }

setSessionCookie() {
const sessionId = this.generateUniqueToken(); // You need to implement this function
document.cookie = `session_id=${sessionId}; path=/;`;
}

setLocalStorageIdentifier() {
const uniqueId = localStorage.getItem('uniqueId');
if (!uniqueId) {
localStorage.setItem('uniqueId', this.generateUniqueToken());
}
}

generateUniqueToken() {
return crypto.randomUUID(); // This generates a UUID (universally unique identifier)
}
}
16 changes: 16 additions & 0 deletions src/app/services/visitor/visitor.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { VisitorService } from './visitor.service';

describe('VisitorService', () => {
let service: VisitorService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(VisitorService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions src/app/services/visitor/visitor.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { VisitorDetail } from 'src/app/models/admin/visitor/visitor-detail';
import { environment } from 'src/environments/environment';

@Injectable({
providedIn: 'root'
})
export class VisitorService {
apiUrl="";
constructor(private http: HttpClient) { }

getAll(): Observable<VisitorDetail[]> {
this.apiUrl = `${environment.awsUserApiBaseUrl}${environment.visitorApiEndpoints.visitors}`;

console.log('getUserVisitors endpoint: ' + this.apiUrl);
return this.http.get<VisitorDetail[]>(this.apiUrl);
}
}

0 comments on commit 34e996a

Please sign in to comment.