├── .browserslistrc ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── 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 │ ├── pais │ │ ├── components │ │ │ ├── pais-input │ │ │ │ ├── pais-input.component.html │ │ │ │ └── pais-input.component.ts │ │ │ └── pais-tabla │ │ │ │ ├── pais-tabla.component.html │ │ │ │ └── pais-tabla.component.ts │ │ ├── interfaces │ │ │ └── pais.interface.ts │ │ ├── pages │ │ │ ├── por-capital │ │ │ │ ├── por-capital.component.html │ │ │ │ └── por-capital.component.ts │ │ │ ├── por-pais │ │ │ │ ├── por-pais.component.html │ │ │ │ └── por-pais.component.ts │ │ │ ├── por-region │ │ │ │ ├── por-region.component.html │ │ │ │ └── por-region.component.ts │ │ │ └── ver-pais │ │ │ │ ├── ver-pais.component.html │ │ │ │ └── ver-pais.component.ts │ │ ├── pais.module.ts │ │ └── services │ │ │ └── pais.service.ts │ └── shared │ │ ├── shared.module.ts │ │ └── sidebar │ │ ├── sidebar.component.html │ │ └── sidebar.component.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 └── tslint.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 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. 18 | -------------------------------------------------------------------------------- /.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 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.angular/cache 36 | /.sass-cache 37 | /connect.lock 38 | /coverage 39 | /libpeerconnection.log 40 | npm-debug.log 41 | yarn-error.log 42 | testem.log 43 | /typings 44 | 45 | # System Files 46 | .DS_Store 47 | Thumbs.db 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PaisesApp 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.0.2. 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. Use the `--prod` flag for a production build. 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 [Protractor](http://www.protractortest.org/). 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 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "paisesApp": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:application": { 10 | "strict": true 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/paisesApp", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "assets": [ 26 | "src/favicon.ico", 27 | "src/assets" 28 | ], 29 | "styles": [ 30 | "src/styles.css" 31 | ], 32 | "scripts": [], 33 | "vendorChunk": true, 34 | "extractLicenses": false, 35 | "buildOptimizer": false, 36 | "sourceMap": true, 37 | "optimization": false, 38 | "namedChunks": true 39 | }, 40 | "configurations": { 41 | "production": { 42 | "fileReplacements": [ 43 | { 44 | "replace": "src/environments/environment.ts", 45 | "with": "src/environments/environment.prod.ts" 46 | } 47 | ], 48 | "optimization": true, 49 | "outputHashing": "all", 50 | "sourceMap": false, 51 | "namedChunks": false, 52 | "extractLicenses": true, 53 | "vendorChunk": false, 54 | "buildOptimizer": true, 55 | "budgets": [ 56 | { 57 | "type": "initial", 58 | "maximumWarning": "500kb", 59 | "maximumError": "1mb" 60 | }, 61 | { 62 | "type": "anyComponentStyle", 63 | "maximumWarning": "2kb", 64 | "maximumError": "4kb" 65 | } 66 | ] 67 | } 68 | }, 69 | "defaultConfiguration": "" 70 | }, 71 | "serve": { 72 | "builder": "@angular-devkit/build-angular:dev-server", 73 | "options": { 74 | "browserTarget": "paisesApp:build" 75 | }, 76 | "configurations": { 77 | "production": { 78 | "browserTarget": "paisesApp:build:production" 79 | } 80 | } 81 | }, 82 | "extract-i18n": { 83 | "builder": "@angular-devkit/build-angular:extract-i18n", 84 | "options": { 85 | "browserTarget": "paisesApp:build" 86 | } 87 | }, 88 | "test": { 89 | "builder": "@angular-devkit/build-angular:karma", 90 | "options": { 91 | "main": "src/test.ts", 92 | "polyfills": "src/polyfills.ts", 93 | "tsConfig": "tsconfig.spec.json", 94 | "karmaConfig": "karma.conf.js", 95 | "assets": [ 96 | "src/favicon.ico", 97 | "src/assets" 98 | ], 99 | "styles": [ 100 | "src/styles.css" 101 | ], 102 | "scripts": [] 103 | } 104 | }, 105 | "e2e": { 106 | "builder": "@angular-devkit/build-angular:protractor", 107 | "options": { 108 | "protractorConfig": "e2e/protractor.conf.js", 109 | "devServerTarget": "paisesApp:serve" 110 | }, 111 | "configurations": { 112 | "production": { 113 | "devServerTarget": "paisesApp:serve:production" 114 | } 115 | } 116 | } 117 | } 118 | } 119 | }, 120 | "defaultProject": "paisesApp" 121 | } 122 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | SELENIUM_PROMISE_MANAGER: false, 20 | baseUrl: 'http://localhost:4200/', 21 | framework: 'jasmine', 22 | jasmineNodeOpts: { 23 | showColors: true, 24 | defaultTimeoutInterval: 30000, 25 | print: function() {} 26 | }, 27 | onPrepare() { 28 | require('ts-node').register({ 29 | project: require('path').join(__dirname, './tsconfig.json') 30 | }); 31 | jasmine.getEnv().addReporter(new SpecReporter({ 32 | spec: { 33 | displayStacktrace: StacktraceOption.PRETTY 34 | } 35 | })); 36 | } 37 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', async () => { 12 | await page.navigateTo(); 13 | expect(await page.getTitleText()).toEqual('paisesApp app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | async navigateTo(): Promise { 5 | return browser.get(browser.baseUrl); 6 | } 7 | 8 | async getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.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/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | jasmineHtmlReporter: { 19 | suppressAll: true // removes the duplicated traces 20 | }, 21 | coverageReporter: { 22 | dir: require('path').join(__dirname, './coverage/paisesApp'), 23 | subdir: '.', 24 | reporters: [ 25 | { type: 'html' }, 26 | { type: 'text-summary' } 27 | ] 28 | }, 29 | reporters: ['progress', 'kjhtml'], 30 | port: 9876, 31 | colors: true, 32 | logLevel: config.LOG_INFO, 33 | autoWatch: true, 34 | browsers: ['Chrome'], 35 | singleRun: false, 36 | restartOnFileChange: true 37 | }); 38 | }; 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "paises-app", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~13.0.1", 15 | "@angular/common": "~13.0.1", 16 | "@angular/compiler": "~13.0.1", 17 | "@angular/core": "~13.0.1", 18 | "@angular/forms": "~13.0.1", 19 | "@angular/platform-browser": "~13.0.1", 20 | "@angular/platform-browser-dynamic": "~13.0.1", 21 | "@angular/router": "~13.0.1", 22 | "rxjs": "~6.6.0", 23 | "tslib": "^2.0.0", 24 | "zone.js": "~0.11.4" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "^13.0.2", 28 | "@angular/cli": "~13.0.2", 29 | "@angular/compiler-cli": "~13.0.1", 30 | "@types/jasmine": "~3.6.0", 31 | "@types/node": "^12.11.1", 32 | "codelyzer": "^6.0.0", 33 | "jasmine-core": "~3.6.0", 34 | "jasmine-spec-reporter": "~5.0.0", 35 | "karma": "^6.3.8", 36 | "karma-chrome-launcher": "~3.1.0", 37 | "karma-coverage": "~2.0.3", 38 | "karma-jasmine": "~4.0.0", 39 | "karma-jasmine-html-reporter": "^1.5.0", 40 | "protractor": "~7.0.0", 41 | "ts-node": "~8.3.0", 42 | "tslint": "~6.1.0", 43 | "typescript": "~4.4.4" 44 | } 45 | } -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | 4 | import { PorPaisComponent } from './pais/pages/por-pais/por-pais.component'; 5 | import { PorRegionComponent } from './pais/pages/por-region/por-region.component'; 6 | import { PorCapitalComponent } from './pais/pages/por-capital/por-capital.component'; 7 | import { VerPaisComponent } from './pais/pages/ver-pais/ver-pais.component'; 8 | 9 | 10 | const routes: Routes = [ 11 | { 12 | path: '', 13 | component: PorPaisComponent, 14 | pathMatch: 'full' 15 | }, 16 | { 17 | path: 'region', 18 | component: PorRegionComponent 19 | }, 20 | { 21 | path: 'capital', 22 | component: PorCapitalComponent 23 | }, 24 | { 25 | path: 'pais/:id', 26 | component: VerPaisComponent 27 | }, 28 | { 29 | path: '**', 30 | redirectTo: '' 31 | } 32 | ]; 33 | 34 | 35 | 36 | 37 | @NgModule({ 38 | imports: [ 39 | RouterModule.forRoot( routes ) 40 | ], 41 | exports: [ 42 | RouterModule 43 | ] 44 | }) 45 | export class AppRoutingModule {} 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Klerith/angular-paises/88da0cf761737d73cb6adbfd67fa1d0385a288c2/src/app/app.component.css -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 |
7 | 8 |
9 | 10 |
11 | 12 |
13 | 14 |
15 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async () => { 6 | await TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | }); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'paisesApp'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.componentInstance; 22 | expect(app.title).toEqual('paisesApp'); 23 | }); 24 | 25 | it('should render title', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.nativeElement; 29 | expect(compiled.querySelector('.content span').textContent).toContain('paisesApp app is running!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /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 = 'paisesApp'; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | 5 | import { AppComponent } from './app.component'; 6 | import { PaisModule } from './pais/pais.module'; 7 | import { SharedModule } from './shared/shared.module'; 8 | 9 | import { AppRoutingModule } from './app-routing.module'; 10 | 11 | @NgModule({ 12 | declarations: [ 13 | AppComponent 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | AppRoutingModule, 18 | HttpClientModule, 19 | PaisModule, 20 | SharedModule 21 | ], 22 | bootstrap: [AppComponent] 23 | }) 24 | export class AppModule { } 25 | -------------------------------------------------------------------------------- /src/app/pais/components/pais-input/pais-input.component.html: -------------------------------------------------------------------------------- 1 |
2 | 8 |
-------------------------------------------------------------------------------- /src/app/pais/components/pais-input/pais-input.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Output, OnInit, Input } from '@angular/core'; 2 | import { Subject } from 'rxjs'; 3 | import { debounceTime } from 'rxjs/operators'; 4 | 5 | @Component({ 6 | selector: 'app-pais-input', 7 | templateUrl: './pais-input.component.html', 8 | styles: [ 9 | ] 10 | }) 11 | export class PaisInputComponent implements OnInit { 12 | 13 | 14 | @Output() onEnter : EventEmitter = new EventEmitter(); 15 | @Output() onDebounce: EventEmitter = new EventEmitter(); 16 | 17 | @Input() placeholder: string = ''; 18 | 19 | debouncer: Subject = new Subject(); 20 | 21 | termino: string = ''; 22 | 23 | ngOnInit() { 24 | this.debouncer 25 | .pipe(debounceTime(300)) 26 | .subscribe( valor => { 27 | this.onDebounce.emit( valor ); 28 | }); 29 | } 30 | 31 | buscar() { 32 | this.onEnter.emit( this.termino ); 33 | } 34 | 35 | teclaPresionada() { 36 | this.debouncer.next( this.termino ); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/app/pais/components/pais-tabla/pais-tabla.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 18 | 19 | 20 | 23 | 24 | 25 |
# Bandera Nombre Población
{{ i + 1 }} 16 | 17 | {{ pais.capital }}, {{ pais.name }}{{ pais.population | number }} 21 | Ver... 22 |
-------------------------------------------------------------------------------- /src/app/pais/components/pais-tabla/pais-tabla.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, OnInit } from '@angular/core'; 2 | 3 | import { Country } from '../../interfaces/pais.interface'; 4 | 5 | @Component({ 6 | selector: 'app-pais-tabla', 7 | templateUrl: './pais-tabla.component.html', 8 | styles: [ 9 | ] 10 | }) 11 | export class PaisTablaComponent implements OnInit { 12 | 13 | @Input() paises: Country[] =[]; 14 | 15 | constructor() { } 16 | 17 | ngOnInit(): void { 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/app/pais/interfaces/pais.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Country { 2 | name: string; 3 | topLevelDomain: string[]; 4 | alpha2Code: string; 5 | alpha3Code: string; 6 | callingCodes: string[]; 7 | capital: string; 8 | altSpellings: string[]; 9 | region: string; 10 | subregion: string; 11 | population: number; 12 | latlng: number[]; 13 | demonym: string; 14 | area: number; 15 | gini: number; 16 | timezones: string[]; 17 | borders: string[]; 18 | nativeName: string; 19 | numericCode: string; 20 | currencies: Currency[]; 21 | languages: Language[]; 22 | translations: Translations; 23 | flag: string; 24 | regionalBlocs: RegionalBloc[]; 25 | cioc: string; 26 | } 27 | 28 | export interface Currency { 29 | code: string; 30 | name: string; 31 | symbol: string; 32 | } 33 | 34 | export interface Language { 35 | iso639_1: string; 36 | iso639_2: string; 37 | name: string; 38 | nativeName: string; 39 | } 40 | 41 | export interface RegionalBloc { 42 | acronym: string; 43 | name: string; 44 | otherAcronyms: any[]; 45 | otherNames: any[]; 46 | } 47 | 48 | export interface Translations { 49 | de: string; 50 | es: string; 51 | fr: string; 52 | ja: string; 53 | it: string; 54 | br: string; 55 | pt: string; 56 | nl: string; 57 | hr: string; 58 | fa: string; 59 | } 60 | -------------------------------------------------------------------------------- /src/app/pais/pages/por-capital/por-capital.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Por Capital

3 |
4 | 5 |
6 |
7 | 10 | 11 |
12 |
13 | 14 |
15 |
16 | 17 |
19 | No se encontró nada con el término {{ termino }} 20 |
21 | 22 |
23 |
24 | 25 | 26 | 27 | 28 |
29 |
-------------------------------------------------------------------------------- /src/app/pais/pages/por-capital/por-capital.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Country } from '../../interfaces/pais.interface'; 3 | import { PaisService } from '../../services/pais.service'; 4 | 5 | @Component({ 6 | selector: 'app-por-capital', 7 | templateUrl: './por-capital.component.html', 8 | styles: [ 9 | ] 10 | }) 11 | export class PorCapitalComponent { 12 | 13 | termino : string = ''; 14 | hayError: boolean = false; 15 | paises : Country[] = []; 16 | 17 | constructor( private paisService: PaisService ) { } 18 | 19 | buscar( termino: string ) { 20 | 21 | this.hayError = false; 22 | this.termino = termino; 23 | 24 | this.paisService.buscarCapital( termino ) 25 | .subscribe( (paises) => { 26 | this.paises = paises; 27 | }, (err) => { 28 | this.hayError = true; 29 | this.paises = []; 30 | }); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/app/pais/pages/por-pais/por-pais.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Por País

3 |
4 | 5 |
6 |
7 | 11 | 12 |
13 |
14 | 15 | 31 | 32 | 33 |
34 | 35 |
36 | 37 |
39 | No se encontró nada con el término {{ termino }} 40 |
41 | 42 |
43 |
44 | 45 | 46 | 47 | 48 |
49 |
-------------------------------------------------------------------------------- /src/app/pais/pages/por-pais/por-pais.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { PaisService } from '../../services/pais.service'; 3 | 4 | import { Country } from '../../interfaces/pais.interface'; 5 | 6 | @Component({ 7 | selector: 'app-por-pais', 8 | templateUrl: './por-pais.component.html', 9 | styles: [ 10 | ` 11 | li { 12 | cursor: pointer; 13 | } 14 | ` 15 | ] 16 | }) 17 | export class PorPaisComponent { 18 | 19 | termino : string = ''; 20 | hayError: boolean = false; 21 | paises : Country[] = []; 22 | 23 | paisesSugeridos : Country[] = []; 24 | mostrarSugerencias: boolean = false; 25 | 26 | constructor( private paisService: PaisService ) { } 27 | 28 | buscar( termino: string ) { 29 | 30 | this.mostrarSugerencias = false; 31 | this.hayError = false; 32 | this.termino = termino; 33 | 34 | this.paisService.buscarPais( termino ) 35 | .subscribe( (paises) => { 36 | console.log(paises); 37 | this.paises = paises; 38 | 39 | }, (err) => { 40 | this.hayError = true; 41 | this.paises = []; 42 | }); 43 | 44 | } 45 | 46 | sugerencias( termino: string ) { 47 | this.hayError = false; 48 | this.termino = termino; 49 | this.mostrarSugerencias = true; 50 | 51 | this.paisService.buscarPais( termino ) 52 | .subscribe( 53 | paises => this.paisesSugeridos = paises.splice(0,5), 54 | (err) => this.paisesSugeridos = [] 55 | ); 56 | 57 | } 58 | 59 | buscarSugerido( termino: string ) { 60 | this.buscar( termino ); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/app/pais/pages/por-region/por-region.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Buscar por region {{ regionActiva | titlecase }}

3 |
4 | 5 |
Seleccione la region
6 | 7 |
8 |
9 | 10 | 11 | 15 | 16 | 21 | 22 |
23 |
24 | 25 |
26 | 27 |
28 |
29 | 30 |
31 |
-------------------------------------------------------------------------------- /src/app/pais/pages/por-region/por-region.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | import { Country } from '../../interfaces/pais.interface'; 4 | import { PaisService } from '../../services/pais.service'; 5 | 6 | @Component({ 7 | selector: 'app-por-region', 8 | templateUrl: './por-region.component.html', 9 | styles: [ ` 10 | button { 11 | margin-right: 5px; 12 | } 13 | 14 | ` 15 | ] 16 | }) 17 | export class PorRegionComponent { 18 | 19 | regiones: string[] = ['EU', 'EFTA', 'CARICOM', 'PA', 'AU', 'USAN', 'EEU', 'AL', 'ASEAN', 'CAIS', 'CEFTA', 'NAFTA', 'SAARC',]; 20 | regionActiva: string = ''; 21 | paises: Country[] = []; 22 | 23 | 24 | constructor( private paisService: PaisService ) { } 25 | 26 | getClaseCSS( region: string ): string { 27 | return (region === this.regionActiva) 28 | ? 'btn btn-primary' 29 | : 'btn btn-outline-primary'; 30 | } 31 | 32 | activarRegion( region: string ) { 33 | 34 | if ( region === this.regionActiva ) { return; } 35 | 36 | this.regionActiva = region; 37 | this.paises = []; 38 | 39 | this.paisService.buscarRegion( region ) 40 | .subscribe( paises => this.paises = paises ); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/app/pais/pages/ver-pais/ver-pais.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
5 | Espere por favor... 6 |
7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |

País: {{ pais.name }}

15 |
16 |
17 | 18 |
19 | 20 |
21 |

Bandera

22 | 23 |
24 | 25 |
26 |

Información

27 |
    28 |
  • 29 | Población {{ pais.population | number }} 30 |
  • 31 |
  • 32 | Código numérico {{ pais.numericCode }} 33 |
  • 34 |
  • 35 | Código alpha3 {{ pais.alpha3Code }} 36 |
  • 37 |
38 |
39 | 40 | 41 |
42 | 43 |

Traducciones

44 |
45 |
46 | 47 | {{ pais.translations.de }} 48 | {{ pais.translations.es }} 49 | {{ pais.translations.fr }} 50 | {{ pais.translations.ja }} 51 | {{ pais.translations.it }} 52 | {{ pais.translations.br }} 53 | {{ pais.translations.pt }} 54 | {{ pais.translations.nl }} 55 | {{ pais.translations.hr }} 56 | {{ pais.translations.fa }} 57 | 58 |
59 |
60 | 61 | 62 | 65 | 66 | 67 |
68 | 69 | -------------------------------------------------------------------------------- /src/app/pais/pages/ver-pais/ver-pais.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | import { switchMap, tap } from 'rxjs/operators'; 4 | 5 | import { PaisService } from '../../services/pais.service'; 6 | import { Country } from '../../interfaces/pais.interface'; 7 | 8 | @Component({ 9 | selector: 'app-ver-pais', 10 | templateUrl: './ver-pais.component.html', 11 | styles: [ 12 | ] 13 | }) 14 | export class VerPaisComponent implements OnInit { 15 | 16 | pais!: Country; 17 | 18 | constructor( 19 | private activatedRoute: ActivatedRoute, 20 | private paisService: PaisService 21 | ) { } 22 | 23 | ngOnInit(): void { 24 | 25 | this.activatedRoute.params 26 | .pipe( 27 | switchMap( ({ id }) => this.paisService.getPaisPorAlpha( id ) ), 28 | tap( console.log ) 29 | ) 30 | .subscribe( pais => this.pais = pais ); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/app/pais/pais.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { RouterModule } from '@angular/router'; 5 | 6 | import { PorCapitalComponent } from './pages/por-capital/por-capital.component'; 7 | import { PorPaisComponent } from './pages/por-pais/por-pais.component'; 8 | import { PorRegionComponent } from './pages/por-region/por-region.component'; 9 | import { VerPaisComponent } from './pages/ver-pais/ver-pais.component'; 10 | import { PaisTablaComponent } from './components/pais-tabla/pais-tabla.component'; 11 | import { PaisInputComponent } from './components/pais-input/pais-input.component'; 12 | 13 | 14 | 15 | @NgModule({ 16 | declarations: [ 17 | PorCapitalComponent, 18 | PorPaisComponent, 19 | PorRegionComponent, 20 | VerPaisComponent, 21 | PaisTablaComponent, 22 | PaisInputComponent 23 | ], 24 | exports: [ 25 | PorCapitalComponent, 26 | PorPaisComponent, 27 | PorRegionComponent, 28 | VerPaisComponent 29 | ], 30 | imports: [ 31 | CommonModule, 32 | FormsModule, 33 | RouterModule 34 | ] 35 | }) 36 | export class PaisModule { } 37 | -------------------------------------------------------------------------------- /src/app/pais/services/pais.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpParams } from '@angular/common/http'; 3 | import { Observable } from 'rxjs'; 4 | 5 | import { Country } from '../interfaces/pais.interface'; 6 | import { tap } from 'rxjs/operators'; 7 | 8 | @Injectable({ 9 | providedIn: 'root' 10 | }) 11 | export class PaisService { 12 | 13 | private apiUrl: string = 'https://restcountries.com/v2'; 14 | 15 | get httpParams () { 16 | return new HttpParams().set( 'fields', 'name,capital,alpha2Code,flag,population' ); 17 | } 18 | 19 | constructor( private http: HttpClient ) { } 20 | 21 | buscarPais( termino: string ): Observable { 22 | const url = `${ this.apiUrl }/name/${ termino }`; 23 | 24 | return this.http.get( url, { params: this.httpParams } ); 25 | } 26 | 27 | buscarCapital( termino: string ):Observable{ 28 | const url = `${ this.apiUrl }/capital/${ termino }`; 29 | return this.http.get( url, { params: this.httpParams } ); 30 | } 31 | 32 | getPaisPorAlpha( id: string ):Observable{ 33 | const url = `${ this.apiUrl }/alpha/${ id }`; 34 | return this.http.get( url ); 35 | } 36 | 37 | buscarRegion( region: string ): Observable { 38 | 39 | const url = `${ this.apiUrl }/regionalbloc/${ region }`; 40 | 41 | return this.http.get( url, { params: this.httpParams } ) 42 | .pipe( 43 | tap( console.log ) 44 | ) 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { RouterModule } from '@angular/router'; 4 | 5 | import { SidebarComponent } from './sidebar/sidebar.component'; 6 | 7 | 8 | @NgModule({ 9 | declarations: [ 10 | SidebarComponent 11 | ], 12 | exports: [ 13 | SidebarComponent 14 | ], 15 | imports: [ 16 | CommonModule, 17 | RouterModule 18 | ] 19 | }) 20 | export class SharedModule { } 21 | -------------------------------------------------------------------------------- /src/app/shared/sidebar/sidebar.component.html: -------------------------------------------------------------------------------- 1 |

Busquedas

2 |
3 |
    4 |
  • 8 | Buscar país 9 |
  • 10 | 11 |
  • 14 | Por region 15 |
  • 16 | 17 |
  • 20 | Por capital 21 |
  • 22 |
-------------------------------------------------------------------------------- /src/app/shared/sidebar/sidebar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-sidebar', 5 | templateUrl: './sidebar.component.html', 6 | styles: [ 7 | ` 8 | li { 9 | cursor: pointer; 10 | } 11 | ` 12 | ] 13 | }) 14 | export class SidebarComponent implements OnInit { 15 | 16 | constructor() { } 17 | 18 | ngOnInit(): void { 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Klerith/angular-paises/88da0cf761737d73cb6adbfd67fa1d0385a288c2/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 --prod` 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/Klerith/angular-paises/88da0cf761737d73cb6adbfd67fa1d0385a288c2/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PaisesApp 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /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 Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 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 | 2 | .small-flag { 3 | width: 50px; 4 | } 5 | 6 | .mr-1 { 7 | margin-right: 5px; 8 | } -------------------------------------------------------------------------------- /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 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting(), { 21 | teardown: { destroyAfterEach: false } 22 | } 23 | ); 24 | // Then we find all the tests. 25 | const context = require.context('./', true, /\.spec\.ts$/); 26 | // And load the modules. 27 | context.keys().map(context); 28 | -------------------------------------------------------------------------------- /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 | "noImplicitReturns": true, 10 | "noFallthroughCasesInSwitch": true, 11 | "sourceMap": true, 12 | "declaration": false, 13 | "downlevelIteration": true, 14 | "experimentalDecorators": true, 15 | "moduleResolution": "node", 16 | "importHelpers": true, 17 | "target": "es2015", 18 | "module": "es2020", 19 | "lib": [ 20 | "es2018", 21 | "dom" 22 | ] 23 | }, 24 | "angularCompilerOptions": { 25 | "strictInjectionParameters": true, 26 | "strictInputAccessModifiers": true, 27 | "strictTemplates": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": [ 4 | "codelyzer" 5 | ], 6 | "rules": { 7 | "align": { 8 | "options": [ 9 | "parameters", 10 | "statements" 11 | ] 12 | }, 13 | "array-type": false, 14 | "arrow-return-shorthand": true, 15 | "curly": true, 16 | "deprecation": { 17 | "severity": "warning" 18 | }, 19 | "eofline": true, 20 | "import-blacklist": [ 21 | true, 22 | "rxjs/Rx" 23 | ], 24 | "import-spacing": true, 25 | "indent": { 26 | "options": [ 27 | "spaces" 28 | ] 29 | }, 30 | "max-classes-per-file": false, 31 | "max-line-length": [ 32 | true, 33 | 140 34 | ], 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-console": [ 47 | true, 48 | "debug", 49 | "info", 50 | "time", 51 | "timeEnd", 52 | "trace" 53 | ], 54 | "no-empty": false, 55 | "no-inferrable-types": [ 56 | true, 57 | "ignore-params" 58 | ], 59 | "no-non-null-assertion": true, 60 | "no-redundant-jsdoc": true, 61 | "no-switch-case-fall-through": true, 62 | "no-var-requires": false, 63 | "object-literal-key-quotes": [ 64 | true, 65 | "as-needed" 66 | ], 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "semicolon": { 72 | "options": [ 73 | "always" 74 | ] 75 | }, 76 | "space-before-function-paren": { 77 | "options": { 78 | "anonymous": "never", 79 | "asyncArrow": "always", 80 | "constructor": "never", 81 | "method": "never", 82 | "named": "never" 83 | } 84 | }, 85 | "typedef": [ 86 | true, 87 | "call-signature" 88 | ], 89 | "typedef-whitespace": { 90 | "options": [ 91 | { 92 | "call-signature": "nospace", 93 | "index-signature": "nospace", 94 | "parameter": "nospace", 95 | "property-declaration": "nospace", 96 | "variable-declaration": "nospace" 97 | }, 98 | { 99 | "call-signature": "onespace", 100 | "index-signature": "onespace", 101 | "parameter": "onespace", 102 | "property-declaration": "onespace", 103 | "variable-declaration": "onespace" 104 | } 105 | ] 106 | }, 107 | "variable-name": { 108 | "options": [ 109 | "ban-keywords", 110 | "check-format", 111 | "allow-pascal-case" 112 | ] 113 | }, 114 | "whitespace": { 115 | "options": [ 116 | "check-branch", 117 | "check-decl", 118 | "check-operator", 119 | "check-separator", 120 | "check-type", 121 | "check-typecast" 122 | ] 123 | }, 124 | "component-class-suffix": true, 125 | "contextual-lifecycle": true, 126 | "directive-class-suffix": true, 127 | "no-conflicting-lifecycle": true, 128 | "no-host-metadata-property": true, 129 | "no-input-rename": true, 130 | "no-inputs-metadata-property": true, 131 | "no-output-native": true, 132 | "no-output-on-prefix": true, 133 | "no-output-rename": true, 134 | "no-outputs-metadata-property": true, 135 | "template-banana-in-box": true, 136 | "template-no-negated-async": true, 137 | "use-lifecycle-interface": true, 138 | "use-pipe-transform-interface": true, 139 | "directive-selector": [ 140 | true, 141 | "attribute", 142 | "app", 143 | "camelCase" 144 | ], 145 | "component-selector": [ 146 | true, 147 | "element", 148 | "app", 149 | "kebab-case" 150 | ] 151 | } 152 | } 153 | --------------------------------------------------------------------------------