├── .browserslistrc ├── .editorconfig ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json └── tasks.json ├── README.md ├── angular.json ├── course-outline.md ├── karma.conf.js ├── package-lock.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── component │ │ ├── userdetail │ │ │ ├── userdetail.component.css │ │ │ ├── userdetail.component.html │ │ │ └── userdetail.component.ts │ │ └── users │ │ │ ├── users.component.css │ │ │ ├── users.component.html │ │ │ └── users.component.ts │ ├── interface │ │ ├── coordinate.interface.ts │ │ ├── info.interface.ts │ │ ├── response.interface.ts │ │ └── user.interface.ts │ └── service │ │ ├── user.resolver.ts │ │ └── user.service.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.css └── test.ts ├── tsconfig.app.json ├── tsconfig.json └── tsconfig.spec.json /.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # Compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | /bazel-out 8 | 9 | # Node 10 | /node_modules 11 | npm-debug.log 12 | yarn-error.log 13 | 14 | # IDEs and editors 15 | .idea/ 16 | .project 17 | .classpath 18 | .c9/ 19 | *.launch 20 | .settings/ 21 | *.sublime-workspace 22 | 23 | # Visual Studio Code 24 | .vscode/* 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | .history/* 30 | 31 | # Miscellaneous 32 | /.angular/cache 33 | .sass-cache/ 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | testem.log 38 | /typings 39 | 40 | # System files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 3 | "recommendations": ["angular.ng-template"] 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "name": "ng serve", 7 | "type": "pwa-chrome", 8 | "request": "launch", 9 | "preLaunchTask": "npm: start", 10 | "url": "http://localhost:4200/" 11 | }, 12 | { 13 | "name": "ng test", 14 | "type": "chrome", 15 | "request": "launch", 16 | "preLaunchTask": "npm: test", 17 | "url": "http://localhost:9876/debug.html" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558 3 | "version": "2.0.0", 4 | "tasks": [ 5 | { 6 | "type": "npm", 7 | "script": "start", 8 | "isBackground": true, 9 | "problemMatcher": { 10 | "owner": "typescript", 11 | "pattern": "$tsc", 12 | "background": { 13 | "activeOnStart": true, 14 | "beginsPattern": { 15 | "regexp": "(.*?)" 16 | }, 17 | "endsPattern": { 18 | "regexp": "bundle generation complete" 19 | } 20 | } 21 | } 22 | }, 23 | { 24 | "type": "npm", 25 | "script": "test", 26 | "isBackground": true, 27 | "problemMatcher": { 28 | "owner": "typescript", 29 | "pattern": "$tsc", 30 | "background": { 31 | "activeOnStart": true, 32 | "beginsPattern": { 33 | "regexp": "(.*?)" 34 | }, 35 | "endsPattern": { 36 | "regexp": "bundle generation complete" 37 | } 38 | } 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Userapicatalog 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.1. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "cli": { 4 | "analytics": "543b7de2-f34a-481d-9e40-d658554772db" 5 | }, 6 | "version": 1, 7 | "newProjectRoot": "projects", 8 | "projects": { 9 | "userapicatalog": { 10 | "projectType": "application", 11 | "schematics": { 12 | "@schematics/angular:application": { 13 | "strict": true 14 | } 15 | }, 16 | "root": "", 17 | "sourceRoot": "src", 18 | "prefix": "app", 19 | "architect": { 20 | "build": { 21 | "builder": "@angular-devkit/build-angular:browser", 22 | "options": { 23 | "outputPath": "dist/userapicatalog", 24 | "index": "src/index.html", 25 | "main": "src/main.ts", 26 | "polyfills": "src/polyfills.ts", 27 | "tsConfig": "tsconfig.app.json", 28 | "assets": [ 29 | "src/favicon.ico", 30 | "src/assets" 31 | ], 32 | "styles": [ 33 | "node_modules/bootstrap/dist/css/bootstrap.min.css", 34 | "src/styles.css" 35 | ], 36 | "scripts": [ 37 | "node_modules/bootstrap/dist/js/bootstrap.min.js" 38 | ] 39 | }, 40 | "configurations": { 41 | "production": { 42 | "budgets": [ 43 | { 44 | "type": "initial", 45 | "maximumWarning": "500kb", 46 | "maximumError": "1mb" 47 | }, 48 | { 49 | "type": "anyComponentStyle", 50 | "maximumWarning": "2kb", 51 | "maximumError": "4kb" 52 | } 53 | ], 54 | "fileReplacements": [ 55 | { 56 | "replace": "src/environments/environment.ts", 57 | "with": "src/environments/environment.prod.ts" 58 | } 59 | ], 60 | "outputHashing": "all" 61 | }, 62 | "development": { 63 | "buildOptimizer": false, 64 | "optimization": false, 65 | "vendorChunk": true, 66 | "extractLicenses": false, 67 | "sourceMap": true, 68 | "namedChunks": true 69 | } 70 | }, 71 | "defaultConfiguration": "production" 72 | }, 73 | "serve": { 74 | "builder": "@angular-devkit/build-angular:dev-server", 75 | "configurations": { 76 | "production": { 77 | "browserTarget": "userapicatalog:build:production" 78 | }, 79 | "development": { 80 | "browserTarget": "userapicatalog:build:development" 81 | } 82 | }, 83 | "defaultConfiguration": "development" 84 | }, 85 | "extract-i18n": { 86 | "builder": "@angular-devkit/build-angular:extract-i18n", 87 | "options": { 88 | "browserTarget": "userapicatalog:build" 89 | } 90 | }, 91 | "test": { 92 | "builder": "@angular-devkit/build-angular:karma", 93 | "options": { 94 | "main": "src/test.ts", 95 | "polyfills": "src/polyfills.ts", 96 | "tsConfig": "tsconfig.spec.json", 97 | "karmaConfig": "karma.conf.js", 98 | "assets": [ 99 | "src/favicon.ico", 100 | "src/assets" 101 | ], 102 | "styles": [ 103 | "src/styles.css" 104 | ], 105 | "scripts": [] 106 | } 107 | } 108 | } 109 | } 110 | }, 111 | "defaultProject": "userapicatalog" 112 | } 113 | -------------------------------------------------------------------------------- /course-outline.md: -------------------------------------------------------------------------------- 1 | Course Outline 2 | ============== 3 | 4 | **Author:** *Junior RT* 5 | 6 | **Date:** *04-22-2022* 7 | 8 | ### Introduction 9 | 1. What is this course? 10 | 2. Prerequisites 11 | * HTML, CSS, JavaScript 12 | * WWW 13 | * Client / Server communication 14 | * Web APIs 15 | * TypeScript 16 | * Interfaces 17 | * Classes 18 | * Generics 19 | * Modules 20 | * ... 21 | 22 | ### Setup 23 | 1. Software requirements 24 | 2. Text editor / IDE 25 | 3. Web browser 26 | 4. Terminal / command line 27 | 28 | ### Angular components 29 | 1. What are Angular components? 30 | 2. Components Data binding 31 | * String interpolation 32 | * Property binding 33 | * Event binding 34 | 3. Components lifecycle 35 | 36 | ### Angular services 37 | 1. What are Angular services 38 | 2. When to use Angular services 39 | 3. Fetch users using a service 40 | 41 | ### Angular directives 42 | 1. What are Angular directives? 43 | 2. Structural directives 44 | 3. Built-in directives 45 | 5. Angular directives in action 46 | 47 | ### Angular routing 48 | 1. What is Angular routing? 49 | 2. Angular routes in action 50 | * Router outlet 51 | * Configuring routes 52 | * Activated routes 53 | * Router parameters 54 | 55 | ### Angular resolver 56 | 1. What are Angular resolver? 57 | 2. When to use Angular resolver 58 | 3. Pre-fetching data before routing 59 | 60 | ### Angular pipes 61 | 1. What are Angular pipes? 62 | 2. When to use Angular pipes 63 | 3. Angular pipes in action 64 | 65 | ### RxJs 66 | 1. What is RxJs 67 | 2. Using RxJx to transform API data 68 | 69 | ### Map 70 | 1. Leaflet 71 | 2. Display Map 72 | 3. Show Marker 73 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/userapicatalog'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "userapicatalog", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "watch": "ng build --watch --configuration development", 9 | "test": "ng test" 10 | }, 11 | "private": true, 12 | "dependencies": { 13 | "@angular/animations": "~13.2.0", 14 | "@angular/common": "~13.2.0", 15 | "@angular/compiler": "~13.2.0", 16 | "@angular/core": "~13.2.0", 17 | "@angular/forms": "~13.2.0", 18 | "@angular/platform-browser": "~13.2.0", 19 | "@angular/platform-browser-dynamic": "~13.2.0", 20 | "@angular/router": "~13.2.0", 21 | "bootstrap": "^5.1.3", 22 | "leaflet": "^1.8.0", 23 | "rxjs": "~7.5.0", 24 | "tslib": "^2.3.0", 25 | "zone.js": "~0.11.4" 26 | }, 27 | "devDependencies": { 28 | "@angular-devkit/build-angular": "~13.2.1", 29 | "@angular/cli": "~13.2.1", 30 | "@angular/compiler-cli": "~13.2.0", 31 | "@types/jasmine": "~3.10.0", 32 | "@types/leaflet": "^1.7.9", 33 | "@types/node": "^12.11.1", 34 | "jasmine-core": "~4.0.0", 35 | "karma": "~6.3.0", 36 | "karma-chrome-launcher": "~3.1.0", 37 | "karma-coverage": "~2.1.0", 38 | "karma-jasmine": "~4.0.0", 39 | "karma-jasmine-html-reporter": "~1.7.0", 40 | "typescript": "~4.5.2" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { UserdetailComponent } from './component/userdetail/userdetail.component'; 4 | import { UsersComponent } from './component/users/users.component'; 5 | import { UserResolver } from './service/user.resolver'; 6 | 7 | const routes: Routes = [ 8 | { path: 'users', component: UsersComponent }, 9 | { path: 'user/:uuid', component: UserdetailComponent, resolve: { resolvedResponse: UserResolver } }, 10 | { path: '**', redirectTo: 'users' } 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [RouterModule.forRoot(routes)], 15 | exports: [RouterModule] 16 | }) 17 | export class AppRoutingModule { } 18 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/getarrays/usercatalog/82efde30384bb030b6acfec5e1776d57a90be5e8/src/app/app.component.css -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

{{ title }}

5 |
6 | 7 |
8 |
9 |
-------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async () => { 7 | await TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | }); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'userapicatalog'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('userapicatalog'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement as HTMLElement; 33 | expect(compiled.querySelector('.content span')?.textContent).toContain('userapicatalog app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'User Catalog'; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | 5 | import { AppRoutingModule } from './app-routing.module'; 6 | import { AppComponent } from './app.component'; 7 | import { UsersComponent } from './component/users/users.component'; 8 | import { UserdetailComponent } from './component/userdetail/userdetail.component'; 9 | 10 | @NgModule({ 11 | declarations: [ 12 | AppComponent, 13 | UsersComponent, 14 | UserdetailComponent 15 | ], 16 | imports: [ 17 | BrowserModule, 18 | AppRoutingModule, 19 | HttpClientModule 20 | ], 21 | providers: [], 22 | bootstrap: [AppComponent] 23 | }) 24 | export class AppModule { } 25 | -------------------------------------------------------------------------------- /src/app/component/userdetail/userdetail.component.css: -------------------------------------------------------------------------------- 1 | .card { 2 | position: relative; 3 | display: flex; 4 | flex-direction: column; 5 | min-width: 0; 6 | word-wrap: break-word; 7 | background-color: #fff; 8 | background-clip: border-box; 9 | border: 0 solid transparent; 10 | border-radius: .25rem; 11 | margin-bottom: 1.5rem; 12 | box-shadow: 0 2px 6px 0 rgb(218 218 253 / 65%), 0 2px 6px 0 rgb(206 206 238 / 54%); 13 | } 14 | 15 | .me-2 { 16 | margin-right: .5rem !important; 17 | } 18 | 19 | .map-wrapper { 20 | position: relative; 21 | height: 500px; 22 | top: 0; 23 | left: 0; 24 | right: 0; 25 | bottom: 0; 26 | margin: 10px; 27 | } 28 | 29 | .map-border { 30 | border: 5px solid #0da323; 31 | height: 100%; 32 | } 33 | 34 | #map { 35 | height: 100%; 36 | } 37 | 38 | input:disabled { 39 | border: 0; 40 | outline: 0; 41 | background: #F4F6F7; 42 | } 43 | 44 | input:focus { 45 | outline: 0; 46 | border: 0; 47 | } -------------------------------------------------------------------------------- /src/app/component/userdetail/userdetail.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | ← Back to users 4 |
5 |
6 |
7 |
8 | Admin 10 |
11 |

{{ user.firstName }} {{ user.lastName }}

12 |

{{ user.username }}

13 |

ID: {{ user.uuid }}

14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
First Name
25 |
26 |
27 | 28 |
29 |
30 |
31 |
32 |
Last Name
33 |
34 |
35 | 36 |
37 |
38 |
39 |
40 |
Date of Birth
41 |
42 |
43 | 44 |
45 |
46 |
47 |
48 |
Email
49 |
50 |
51 | 52 |
53 |
54 |
55 |
56 |
Phone
57 |
58 |
59 | 60 |
61 |
62 |
63 |
64 |
Gender
65 |
66 |
67 | 68 |
69 |
70 |
71 |
72 |
Address
73 |
74 |
75 | 76 |
77 |
78 |
79 |
80 |
81 | 82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
User Location
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
-------------------------------------------------------------------------------- /src/app/component/userdetail/userdetail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, ParamMap } from '@angular/router'; 3 | import * as Leaflet from 'leaflet'; 4 | import { Coordinate } from 'src/app/interface/coordinate.interface'; 5 | import { User } from 'src/app/interface/user.interface'; 6 | import { UserService } from 'src/app/service/user.service'; 7 | 8 | @Component({ 9 | selector: 'app-userdetail', 10 | templateUrl: './userdetail.component.html', 11 | styleUrls: ['./userdetail.component.css'] 12 | }) 13 | export class UserdetailComponent implements OnInit { 14 | user: User; 15 | mode: 'edit' | 'locked' = 'locked'; 16 | buttonText: 'Save Changes' | 'Edit' = 'Edit'; 17 | marker = new Leaflet.Icon({ 18 | iconUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-icon.png', 19 | iconSize: [32, 41], 20 | iconAnchor: [12, 41], 21 | popupAnchor: [1, -34], 22 | shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png', 23 | shadowSize: [41, 41] 24 | }); 25 | 26 | constructor(private activatedRoute: ActivatedRoute, private userService: UserService) { } 27 | 28 | ngOnInit(): void { 29 | this.user = ((this.activatedRoute.snapshot.data['resolvedResponse'].results[0])); 30 | console.log(this.user); 31 | this.loadMap(this.user.coordinate); 32 | // this.activatedRoute.paramMap.subscribe((params: ParamMap) => { 33 | // console.log('User ID:', params.get('uuid')!); 34 | // this.userService.getUser(params.get('uuid')!).subscribe( 35 | // (response: any) => { 36 | // console.log(response); 37 | // this.response = response; 38 | // } 39 | // ); 40 | // }); 41 | } 42 | 43 | changeMode(mode?: 'edit' | 'locked'): void { 44 | console.log(mode); 45 | this.mode = this.mode === 'locked' ? 'edit' : 'locked'; 46 | this.buttonText = this.buttonText === 'Edit' ? 'Save Changes' : 'Edit'; 47 | if(mode === 'edit') { 48 | // Logic to update the user on the back end 49 | console.log('Updating using on the back end'); 50 | } 51 | } 52 | 53 | private loadMap(coordinate: Coordinate): void { 54 | const map = Leaflet.map('map', { 55 | center: [coordinate.latitude, coordinate.longitude], 56 | zoom: 8 57 | }); 58 | const mainLayer = Leaflet.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { 59 | tileSize: 512, 60 | zoomOffset: -1, 61 | minZoom: 1, 62 | maxZoom:30, 63 | crossOrigin: true, 64 | attribution: '© OpenStreetMap contributors' 65 | }); 66 | mainLayer.addTo(map); 67 | const marker = Leaflet.marker([coordinate.latitude, coordinate.longitude], { icon: this.marker }); 68 | marker.addTo(map).bindPopup(`${this.user.firstName}'s Location`).openPopup(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/app/component/users/users.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/getarrays/usercatalog/82efde30384bb030b6acfec5e1776d57a90be5e8/src/app/component/users/users.component.css -------------------------------------------------------------------------------- /src/app/component/users/users.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
Random User API
4 |

Seed: {{ response.info.seed }}

5 |

Results: {{ response.info.results }}

6 |

Version: {{ response.info.version }}

7 |
8 |
9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 |
IDImageNameEmailAddressPhoneAction
{{ user.uuid.substr(0, 6) }}user.firstName{{ user.firstName }} {{ user.lastName }}{{ user.email }}{{ user.address }}{{ user.phone }} 31 | 32 |
-------------------------------------------------------------------------------- /src/app/component/users/users.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Response } from 'src/app/interface/response.interface'; 3 | import { UserService } from 'src/app/service/user.service'; 4 | 5 | @Component({ 6 | selector: 'app-users', 7 | templateUrl: './users.component.html', 8 | styleUrls: ['./users.component.css'] 9 | }) 10 | export class UsersComponent implements OnInit { 11 | response: Response; 12 | 13 | constructor(private userService: UserService) { } 14 | 15 | ngOnInit(): void { 16 | this.userService.getUsers(15).subscribe( 17 | (results: Response) => { 18 | console.log(results); 19 | this.response = results; 20 | } 21 | ); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/app/interface/coordinate.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Coordinate { 2 | latitude: number; 3 | longitude: number; 4 | } -------------------------------------------------------------------------------- /src/app/interface/info.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Info { 2 | seed: string; 3 | results: number; 4 | page: number; 5 | version: string; 6 | } -------------------------------------------------------------------------------- /src/app/interface/response.interface.ts: -------------------------------------------------------------------------------- 1 | import { Info } from "./info.interface"; 2 | 3 | export interface Response { 4 | info: Info; 5 | results: any[]; 6 | } -------------------------------------------------------------------------------- /src/app/interface/user.interface.ts: -------------------------------------------------------------------------------- 1 | import { Coordinate } from "./coordinate.interface"; 2 | 3 | export interface User { 4 | uuid: string; 5 | firstName: string; 6 | lastName: string; 7 | email: string; 8 | username: string; 9 | gender: string; 10 | address: string; 11 | dateOfBirth: string; 12 | phone: string; 13 | imageUrl: string; 14 | coordinate: Coordinate; 15 | } -------------------------------------------------------------------------------- /src/app/service/user.resolver.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Resolve, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router'; 3 | import { Observable } from 'rxjs'; 4 | import { Response } from '../interface/response.interface'; 5 | import { UserService } from './user.service'; 6 | 7 | @Injectable({ providedIn: 'root' }) 8 | export class UserResolver implements Resolve { 9 | 10 | constructor(private userService: UserService){} 11 | 12 | resolve(route: ActivatedRouteSnapshot, _: RouterStateSnapshot): Observable { 13 | return this.userService.getUser(route.paramMap.get('uuid')!); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/app/service/user.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { map, Observable } from 'rxjs'; 4 | import { Response } from '../interface/response.interface'; 5 | import { User } from '../interface/user.interface'; 6 | 7 | @Injectable({ providedIn: 'root' }) 8 | export class UserService { 9 | private readonly apiUrl: string = 'https://randomuser.me/api'; 10 | 11 | constructor(private http: HttpClient) { } 12 | 13 | // Fetch users 14 | getUsers(size: number = 10): Observable { 15 | return this.http.get(`${this.apiUrl}/?results=${size}`).pipe( 16 | map(this.processResponse)); 17 | } 18 | 19 | // Fetch one user using the user UUID 20 | getUser(uuid: string): Observable { 21 | return this.http.get(`${this.apiUrl}/?uuid=${uuid}`).pipe( 22 | map(this.processResponse)); 23 | } 24 | 25 | private processResponse(response: Response): Response { 26 | return { 27 | info: { ...response.info }, 28 | results: response.results.map((user: any) => ({ 29 | uuid: user.login.uuid, 30 | firstName: user.name.first, 31 | lastName: user.name.last, 32 | email: user.email, 33 | username: user.login.username, 34 | gender: user.gender, 35 | address: `${user.location.street.number} ${user.location.street.name} ${user.location.city}, ${user.location.country}`, 36 | dateOfBirth: user.dob.date, 37 | phone: user.phone, 38 | imageUrl: user.picture.medium, 39 | coordinate: { latitude: +user.location.coordinates.latitude, longitude: +user.location.coordinates.longitude } 40 | })) 41 | }; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/getarrays/usercatalog/82efde30384bb030b6acfec5e1776d57a90be5e8/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/getarrays/usercatalog/82efde30384bb030b6acfec5e1776d57a90be5e8/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | User Catalog 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes recent versions of Safari, Chrome (including 12 | * Opera), Edge on the desktop, and iOS and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** 22 | * By default, zone.js will patch all possible macroTask and DomEvents 23 | * user can disable parts of macroTask/DomEvents patch by setting following flags 24 | * because those flags need to be set before `zone.js` being loaded, and webpack 25 | * will put import in the top of bundle, so user need to create a separate file 26 | * in this directory (for example: zone-flags.ts), and put the following flags 27 | * into that file, and then add the following code before importing zone.js. 28 | * import './zone-flags'; 29 | * 30 | * The flags allowed in zone-flags.ts are listed here. 31 | * 32 | * The following flags will work for all browsers. 33 | * 34 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 35 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 36 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 37 | * 38 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 39 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 40 | * 41 | * (window as any).__Zone_enable_cross_context_check = true; 42 | * 43 | */ 44 | 45 | /*************************************************************************************************** 46 | * Zone JS is required by default for Angular itself. 47 | */ 48 | import 'zone.js'; // Included with Angular CLI. 49 | 50 | 51 | /*************************************************************************************************** 52 | * APPLICATION IMPORTS 53 | */ 54 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import "~leaflet/dist/leaflet.css"; -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | (id: string): T; 13 | keys(): string[]; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting(), 21 | ); 22 | 23 | // Then we find all the tests. 24 | const context = require.context('./', true, /\.spec\.ts$/); 25 | // And load the modules. 26 | context.keys().map(context); 27 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "strictPropertyInitialization": false, 10 | "noImplicitOverride": true, 11 | "noPropertyAccessFromIndexSignature": true, 12 | "noImplicitReturns": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "sourceMap": true, 15 | "declaration": false, 16 | "downlevelIteration": true, 17 | "experimentalDecorators": true, 18 | "moduleResolution": "node", 19 | "importHelpers": true, 20 | "target": "es2017", 21 | "module": "es2020", 22 | "lib": [ 23 | "es2020", 24 | "dom" 25 | ] 26 | }, 27 | "angularCompilerOptions": { 28 | "enableI18nLegacyMessageIdFormat": false, 29 | "strictInjectionParameters": true, 30 | "strictInputAccessModifiers": true, 31 | "strictTemplates": true 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | --------------------------------------------------------------------------------