├── APM-WithRefresh ├── .editorconfig ├── .gitignore ├── .vscode │ └── settings.json ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app-data.ts │ │ ├── app-routing.module.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── home │ │ │ ├── menu.component.html │ │ │ ├── menu.component.ts │ │ │ ├── page-not-found.component.ts │ │ │ ├── shell.component.css │ │ │ ├── shell.component.html │ │ │ ├── shell.component.ts │ │ │ ├── welcome.component.html │ │ │ └── welcome.component.ts │ │ ├── page-not-found.component.ts │ │ ├── product-categories │ │ │ ├── product-category-data.ts │ │ │ ├── product-category.service.ts │ │ │ └── product-category.ts │ │ ├── products │ │ │ ├── product-data.ts │ │ │ ├── product-detail │ │ │ │ ├── product-detail.component.html │ │ │ │ └── product-detail.component.ts │ │ │ ├── product-list │ │ │ │ ├── product-list.component.css │ │ │ │ ├── product-list.component.html │ │ │ │ └── product-list.component.ts │ │ │ ├── product-shell │ │ │ │ ├── product-shell.component.html │ │ │ │ └── product-shell.component.ts │ │ │ ├── product.module.ts │ │ │ ├── product.service.ts │ │ │ └── product.ts │ │ ├── shared │ │ │ └── shared.module.ts │ │ └── suppliers │ │ │ ├── supplier-data.ts │ │ │ ├── supplier.service.ts │ │ │ └── supplier.ts │ ├── assets │ │ ├── .gitkeep │ │ └── images │ │ │ └── logo.jpg │ ├── browserslist │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── karma.conf.js │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json ├── tsconfig.json ├── tslint.json └── yarn.lock ├── APM ├── .editorconfig ├── .gitignore ├── .vscode │ └── settings.json ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app-data.ts │ │ ├── app-routing.module.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── home │ │ │ ├── menu.component.html │ │ │ ├── menu.component.ts │ │ │ ├── page-not-found.component.ts │ │ │ ├── shell.component.css │ │ │ ├── shell.component.html │ │ │ ├── shell.component.ts │ │ │ ├── welcome.component.html │ │ │ └── welcome.component.ts │ │ ├── page-not-found.component.ts │ │ ├── product-categories │ │ │ ├── product-category-data.ts │ │ │ ├── product-category.service.ts │ │ │ └── product-category.ts │ │ ├── products │ │ │ ├── product-data.ts │ │ │ ├── product-detail │ │ │ │ ├── product-detail.component.html │ │ │ │ └── product-detail.component.ts │ │ │ ├── product-list │ │ │ │ ├── product-list.component.css │ │ │ │ ├── product-list.component.html │ │ │ │ └── product-list.component.ts │ │ │ ├── product-shell │ │ │ │ ├── product-shell.component.html │ │ │ │ └── product-shell.component.ts │ │ │ ├── product.module.ts │ │ │ ├── product.service.ts │ │ │ └── product.ts │ │ ├── shared │ │ │ └── shared.module.ts │ │ └── suppliers │ │ │ ├── supplier-data.ts │ │ │ ├── supplier.service.ts │ │ │ └── supplier.ts │ ├── assets │ │ ├── .gitkeep │ │ └── images │ │ │ └── logo.jpg │ ├── browserslist │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── karma.conf.js │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json ├── tsconfig.json ├── tslint.json └── yarn.lock ├── LICENSE └── README.md /APM-WithRefresh/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://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 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /APM-WithRefresh/.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 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | -------------------------------------------------------------------------------- /APM-WithRefresh/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.autoSave": "afterDelay", 3 | "html.format.wrapAttributes": "force-aligned" 4 | } -------------------------------------------------------------------------------- /APM-WithRefresh/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "APM": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "pm", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/APM", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "fileReplacements": [ 33 | { 34 | "replace": "src/environments/environment.ts", 35 | "with": "src/environments/environment.prod.ts" 36 | } 37 | ], 38 | "optimization": true, 39 | "outputHashing": "all", 40 | "sourceMap": false, 41 | "extractCss": true, 42 | "namedChunks": false, 43 | "aot": true, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | } 53 | ] 54 | } 55 | } 56 | }, 57 | "serve": { 58 | "builder": "@angular-devkit/build-angular:dev-server", 59 | "options": { 60 | "browserTarget": "APM:build" 61 | }, 62 | "configurations": { 63 | "production": { 64 | "browserTarget": "APM:build:production" 65 | } 66 | } 67 | }, 68 | "extract-i18n": { 69 | "builder": "@angular-devkit/build-angular:extract-i18n", 70 | "options": { 71 | "browserTarget": "APM:build" 72 | } 73 | }, 74 | "test": { 75 | "builder": "@angular-devkit/build-angular:karma", 76 | "options": { 77 | "main": "src/test.ts", 78 | "polyfills": "src/polyfills.ts", 79 | "tsConfig": "src/tsconfig.spec.json", 80 | "karmaConfig": "src/karma.conf.js", 81 | "styles": [ 82 | "src/styles.css" 83 | ], 84 | "scripts": [], 85 | "assets": [ 86 | "src/favicon.ico", 87 | "src/assets" 88 | ] 89 | } 90 | }, 91 | "lint": { 92 | "builder": "@angular-devkit/build-angular:tslint", 93 | "options": { 94 | "tsConfig": [ 95 | "src/tsconfig.app.json", 96 | "src/tsconfig.spec.json" 97 | ], 98 | "exclude": [ 99 | "**/node_modules/**" 100 | ] 101 | } 102 | } 103 | } 104 | }, 105 | "APM-e2e": { 106 | "root": "e2e/", 107 | "projectType": "application", 108 | "architect": { 109 | "e2e": { 110 | "builder": "@angular-devkit/build-angular:protractor", 111 | "options": { 112 | "protractorConfig": "e2e/protractor.conf.js", 113 | "devServerTarget": "APM:serve" 114 | }, 115 | "configurations": { 116 | "production": { 117 | "devServerTarget": "APM:serve:production" 118 | } 119 | } 120 | }, 121 | "lint": { 122 | "builder": "@angular-devkit/build-angular:tslint", 123 | "options": { 124 | "tsConfig": "e2e/tsconfig.e2e.json", 125 | "exclude": [ 126 | "**/node_modules/**" 127 | ] 128 | } 129 | } 130 | } 131 | } 132 | }, 133 | "defaultProject": "APM" 134 | } -------------------------------------------------------------------------------- /APM-WithRefresh/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /APM-WithRefresh/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to APM!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /APM-WithRefresh/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('pm-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /APM-WithRefresh/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /APM-WithRefresh/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apm", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve -o", 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": "~7.0.0", 15 | "@angular/common": "~7.0.0", 16 | "@angular/compiler": "~7.0.0", 17 | "@angular/core": "~7.0.0", 18 | "@angular/forms": "~7.0.0", 19 | "@angular/http": "~7.0.0", 20 | "@angular/platform-browser": "~7.0.0", 21 | "@angular/platform-browser-dynamic": "~7.0.0", 22 | "@angular/router": "~7.0.0", 23 | "bootstrap": "^4.1.3", 24 | "core-js": "^2.5.4", 25 | "font-awesome": "^4.7.0", 26 | "rxjs": "~6.4.0", 27 | "zone.js": "~0.8.26" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.10.0", 31 | "@angular/cli": "~7.0.3", 32 | "@angular/compiler-cli": "~7.0.0", 33 | "@angular/language-service": "~7.0.0", 34 | "@types/node": "~8.9.4", 35 | "@types/jasmine": "~2.8.8", 36 | "@types/jasminewd2": "~2.0.3", 37 | "angular-in-memory-web-api": "^0.7.0", 38 | "codelyzer": "~4.5.0", 39 | "jasmine-core": "~2.99.1", 40 | "jasmine-spec-reporter": "~4.2.1", 41 | "karma": "~3.0.0", 42 | "karma-chrome-launcher": "~2.2.0", 43 | "karma-coverage-istanbul-reporter": "~2.0.1", 44 | "karma-jasmine": "~1.1.2", 45 | "karma-jasmine-html-reporter": "^0.2.2", 46 | "protractor": "~5.4.0", 47 | "ts-node": "~7.0.0", 48 | "tslint": "~5.11.0", 49 | "typescript": "~3.1.1" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/app-data.ts: -------------------------------------------------------------------------------- 1 | import { InMemoryDbService } from 'angular-in-memory-web-api'; 2 | 3 | import { ProductData } from './products/product-data'; 4 | import { ProductCategoryData } from './product-categories/product-category-data'; 5 | import { SupplierData } from './suppliers/supplier-data'; 6 | 7 | export class AppData implements InMemoryDbService { 8 | 9 | createDb() { 10 | const products = ProductData.products; 11 | const productCategories = ProductCategoryData.categories; 12 | const suppliers = SupplierData.suppliers; 13 | return { products, productCategories, suppliers }; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | 4 | import { ShellComponent } from './home/shell.component'; 5 | import { WelcomeComponent } from './home/welcome.component'; 6 | import { PageNotFoundComponent } from './page-not-found.component'; 7 | 8 | @NgModule({ 9 | imports: [ 10 | RouterModule.forRoot([ 11 | { 12 | path: '', 13 | component: ShellComponent, 14 | children: [ 15 | { path: 'welcome', component: WelcomeComponent }, 16 | { 17 | path: 'products', 18 | loadChildren: './products/product.module#ProductModule' 19 | }, 20 | { path: '', redirectTo: 'welcome', pathMatch: 'full' } 21 | ] 22 | }, 23 | { path: '**', component: PageNotFoundComponent } 24 | ]) 25 | ], 26 | exports: [RouterModule] 27 | }) 28 | export class AppRoutingModule { } 29 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .nav-link { 2 | font-size: large; 3 | cursor: pointer; 4 | } 5 | 6 | .navbar-light .navbar-nav .nav-link.active { 7 | color: #007ACC 8 | } 9 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'pm-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | pageTitle = 'Acme Product Management'; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /APM-WithRefresh/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 | // Imports for loading & configuring the in-memory web api 6 | import { InMemoryWebApiModule } from 'angular-in-memory-web-api'; 7 | import { AppData } from './app-data'; 8 | 9 | import { AppRoutingModule } from './app-routing.module'; 10 | import { AppComponent } from './app.component'; 11 | import { ShellComponent } from './home/shell.component'; 12 | import { MenuComponent } from './home/menu.component'; 13 | import { WelcomeComponent } from './home/welcome.component'; 14 | import { PageNotFoundComponent } from './page-not-found.component'; 15 | 16 | @NgModule({ 17 | imports: [ 18 | BrowserModule, 19 | HttpClientModule, 20 | InMemoryWebApiModule.forRoot(AppData, { delay: 1000 }), 21 | AppRoutingModule 22 | ], 23 | declarations: [ 24 | AppComponent, 25 | ShellComponent, 26 | MenuComponent, 27 | WelcomeComponent, 28 | PageNotFoundComponent 29 | ], 30 | bootstrap: [AppComponent] 31 | }) 32 | export class AppModule { } 33 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/home/menu.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/home/menu.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'pm-menu', 5 | templateUrl: './menu.component.html' 6 | }) 7 | export class MenuComponent { 8 | pageTitle = 'Acme Product Management'; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/home/page-not-found.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | template: ` 5 |

This is not the page you were looking for!

6 | ` 7 | }) 8 | export class PageNotFoundComponent { } 9 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/home/shell.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-DD/17098510c7cc1fbeecb894bb41aa4215068e6ba7/APM-WithRefresh/src/app/home/shell.component.css -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/home/shell.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
-------------------------------------------------------------------------------- /APM-WithRefresh/src/app/home/shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'pm-shell', 5 | templateUrl: './shell.component.html', 6 | styleUrls: ['./shell.component.css'] 7 | }) 8 | export class ShellComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/home/welcome.component.html: -------------------------------------------------------------------------------- 1 | 
2 |
3 | {{pageTitle}} 4 |
5 |
6 |
7 |
8 | 11 |
12 | 13 |
Developed by:
14 |
15 |

Deborah Kurata

16 |
17 | 18 |
@deborahkurata
19 | 22 |
23 |
24 |
-------------------------------------------------------------------------------- /APM-WithRefresh/src/app/home/welcome.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | templateUrl: './welcome.component.html' 5 | }) 6 | export class WelcomeComponent { 7 | public pageTitle = 'Welcome'; 8 | } 9 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/page-not-found.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | template: ` 5 |

This is not the page you were looking for!

6 | ` 7 | }) 8 | export class PageNotFoundComponent { } 9 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/product-categories/product-category-data.ts: -------------------------------------------------------------------------------- 1 | import { ProductCategory } from './product-category'; 2 | 3 | export class ProductCategoryData { 4 | 5 | static categories: ProductCategory[] = [ 6 | { 7 | 'id': 1, 8 | 'name': 'Garden' 9 | }, 10 | { 11 | 'id': 3, 12 | 'name': 'Toolbox' 13 | }, 14 | { 15 | 'id': 5, 16 | 'name': 'Gaming' 17 | } 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/product-categories/product-category.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable, ReplaySubject, throwError } from 'rxjs'; 4 | import { catchError, mergeMap, take, tap } from 'rxjs/operators'; 5 | import { ProductCategory } from './product-category'; 6 | 7 | @Injectable({ 8 | providedIn: 'root' 9 | }) 10 | export class ProductCategoryService { 11 | private productCategoriesUrl = 'api/productCategories'; 12 | 13 | // Getting started and refresh ... not a data stream so therefore use ReplaySubject to retain the values 14 | // "Reactive" way to control flow. 15 | // Not ever actually putting any data into it. 16 | private refresh = new ReplaySubject(); 17 | 18 | // All product categories 19 | // Refresh is used as a starter here. 20 | // [Object reference to a function] 21 | // HTTP: One and done eg. Autocomplete 22 | // Using refresh here instead of reassigning the value ensures that 23 | // no references are lost. 24 | productCategories$: Observable = this.refresh.pipe( 25 | /** any xxxMap will do, merge is the safest. */ 26 | mergeMap(() => this.http.get(this.productCategoriesUrl)), 27 | tap({ 28 | next: data => console.log('getCategories', JSON.stringify(data)), 29 | complete: () => console.log('competed request!') 30 | }), 31 | catchError((this.handleError)) 32 | ); 33 | 34 | constructor(private http: HttpClient) { } 35 | 36 | // Refresh the data. 37 | refreshData(): void { 38 | this.refresh.next(); 39 | } 40 | 41 | start() { 42 | this.refreshData(); 43 | } 44 | 45 | private handleError(err) { 46 | // in a real world app, we may send the server to some remote logging infrastructure 47 | // instead of just logging it to the console 48 | let errorMessage: string; 49 | if (err.error instanceof ErrorEvent) { 50 | // A client-side or network error occurred. Handle it accordingly. 51 | errorMessage = `An error occurred: ${err.error.message}`; 52 | } else { 53 | // The backend returned an unsuccessful response code. 54 | // The response body may contain clues as to what went wrong, 55 | errorMessage = `Backend returned code ${err.status}: ${err.body.error}`; 56 | } 57 | console.error(err); 58 | return throwError(errorMessage); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/product-categories/product-category.ts: -------------------------------------------------------------------------------- 1 | export interface ProductCategory { 2 | id: number; 3 | name: string; 4 | } 5 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product-data.ts: -------------------------------------------------------------------------------- 1 | import { Product } from './product'; 2 | 3 | export class ProductData { 4 | 5 | static products: Product[] = [ 6 | { 7 | 'id': 1, 8 | 'productName': 'Leaf Rake', 9 | 'productCode': 'GDN-0011', 10 | 'description': 'Leaf rake with 48-inch wooden handle', 11 | 'price': 19.95, 12 | 'categoryId': 1, 13 | 'supplierIds': [1, 2] 14 | }, 15 | { 16 | 'id': 2, 17 | 'productName': 'Garden Cart', 18 | 'productCode': 'GDN-0023', 19 | 'description': '15 gallon capacity rolling garden cart', 20 | 'price': 32.99, 21 | 'categoryId': 1, 22 | 'supplierIds': [3, 4] 23 | }, 24 | { 25 | 'id': 5, 26 | 'productName': 'Hammer', 27 | 'productCode': 'TBX-0048', 28 | 'description': 'Curved claw steel hammer', 29 | 'price': 8.9, 30 | 'categoryId': 3, 31 | 'supplierIds': [5, 6] 32 | }, 33 | { 34 | 'id': 8, 35 | 'productName': 'Saw', 36 | 'productCode': 'TBX-0022', 37 | 'description': '15-inch steel blade hand saw', 38 | 'price': 11.55, 39 | 'categoryId': 3, 40 | 'supplierIds': [7, 8] 41 | }, 42 | { 43 | 'id': 10, 44 | 'productName': 'Video Game Controller', 45 | 'productCode': 'GMG-0042', 46 | 'description': 'Standard two-button video game controller', 47 | 'price': 35.95, 48 | 'categoryId': 5, 49 | 'supplierIds': [9, 10] 50 | } 51 | ]; 52 | } 53 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product-detail/product-detail.component.html: -------------------------------------------------------------------------------- 1 |
3 |
4 | {{pageTitle}} 5 |
6 | 7 |
8 | 9 |
10 |
Name:
11 |
{{vm.product.productName}}
12 |
13 |
14 |
Code:
15 |
{{vm.product.productCode}}
16 |
17 |
18 |
Description:
19 |
{{vm.product.description}}
20 |
21 |
22 |
Price:
23 |
{{vm.product.price|currency:"USD":"symbol"}}
24 |
25 |
26 |
Category:
27 |
{{vm.product.category}}
28 |
29 | 30 |
31 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
SupplierCostMinimum Quantity
{{ supplier.name }} {{ supplier.cost | currency:"USD":"symbol":"1.2-2" }}{{ supplier.minQuantity }}
48 |
49 | 50 |
51 | 52 |
{{errorMessage}} 54 |
-------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product-detail/product-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { tap, catchError, map, filter } from 'rxjs/operators'; 4 | 5 | import { ProductService } from '../product.service'; 6 | import { Product } from '../product'; 7 | import { combineLatest } from 'rxjs'; 8 | 9 | @Component({ 10 | selector: 'pm-product-detail', 11 | templateUrl: './product-detail.component.html' 12 | }) 13 | export class ProductDetailComponent implements OnInit { 14 | pageTitle = 'Product Detail'; 15 | errorMessage: string; 16 | 17 | selectedProductId$ = this.productService.selectedProductChanges$; 18 | product$ = this.productService.selectedProduct$.pipe( 19 | tap(product => this.displayProduct(product)), 20 | catchError(err => this.errorMessage = err) 21 | ); 22 | suppliers$ = this.productService.selectedProductSuppliers$; 23 | 24 | // Create another combined stream with all data used in the view 25 | vm$ = combineLatest([this.product$, this.suppliers$, this.selectedProductId$]).pipe( 26 | map(([product, suppliers, selectedProductId]) => ({ product, suppliers, selectedProductId })) 27 | ); 28 | 29 | constructor(private productService: ProductService) { } 30 | 31 | ngOnInit() { } 32 | 33 | displayProduct(product: Product): void { 34 | // Display the appropriate heading 35 | if (product) { 36 | this.pageTitle = `Product Detail for: ${product.productName}`; 37 | } else { 38 | this.pageTitle = 'No product found'; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product-list/product-list.component.css: -------------------------------------------------------------------------------- 1 | thead { 2 | color: #337AB7; 3 | } -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product-list/product-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 | 6 |
8 |
9 | 16 |
17 | 18 |
19 | 23 |
24 |
25 | 26 |
27 |
29 | Error: {{ errorMessage }} 30 |
-------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product-list/product-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router, ActivatedRoute } from '@angular/router'; 3 | 4 | import { of, Observable } from 'rxjs'; 5 | import { catchError, tap } from 'rxjs/operators'; 6 | 7 | import { Product } from '../product'; 8 | import { ProductService } from '../product.service'; 9 | 10 | @Component({ 11 | selector: 'pm-product-list', 12 | templateUrl: './product-list.component.html' 13 | }) 14 | export class ProductListComponent implements OnInit { 15 | pageTitle = 'Products'; 16 | errorMessage: string; 17 | products$ = this.productService.productsWithCategory$.pipe( 18 | catchError(error => { 19 | this.errorMessage = error; 20 | return of(null); 21 | }) 22 | ); 23 | selectedProductId$ = this.productService.selectedProductChanges$; 24 | 25 | constructor( 26 | private route: ActivatedRoute, 27 | private router: Router, 28 | private productService: ProductService 29 | ) {} 30 | 31 | ngOnInit(): void { 32 | // Read the parameter from the route - supports deep linking 33 | this.route.paramMap.subscribe(params => { 34 | const id = +params.get('id'); 35 | this.productService.changeSelectedProduct(id); 36 | }); 37 | } 38 | 39 | onRefresh(): void { 40 | this.productService.refreshData(); 41 | } 42 | 43 | onSelected(productId: number): void { 44 | // Modify the URL to support deep linking 45 | this.router.navigate(['/products', productId]); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product-shell/product-shell.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 |
6 | 7 |
8 |
-------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product-shell/product-shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { ProductService } from '../product.service'; 4 | import { ProductCategoryService } from 'src/app/product-categories/product-category.service'; 5 | 6 | @Component({ 7 | templateUrl: './product-shell.component.html' 8 | }) 9 | export class ProductShellComponent implements OnInit { 10 | pageTitle = 'Products'; 11 | 12 | constructor(private productService: ProductService) { } 13 | 14 | ngOnInit(): void { 15 | // Set up the product services 16 | this.productService.start(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | import { ReactiveFormsModule } from '@angular/forms'; 4 | 5 | import { ProductListComponent } from './product-list/product-list.component'; 6 | import { ProductDetailComponent } from './product-detail/product-detail.component'; 7 | import { ProductShellComponent } from './product-shell/product-shell.component'; 8 | 9 | import { SharedModule } from '../shared/shared.module'; 10 | 11 | @NgModule({ 12 | imports: [ 13 | SharedModule, 14 | ReactiveFormsModule, 15 | RouterModule.forChild([ 16 | { 17 | path: ':id', 18 | component: ProductShellComponent 19 | } 20 | ]) 21 | ], 22 | declarations: [ 23 | ProductShellComponent, 24 | ProductListComponent, 25 | ProductDetailComponent 26 | ] 27 | }) 28 | export class ProductModule { } 29 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | import { combineLatest, Observable, ReplaySubject, throwError } from 'rxjs'; 5 | import { catchError, filter, map, mergeMap, shareReplay, switchMap, tap } from 'rxjs/operators'; 6 | 7 | import { Product } from './product'; 8 | import { ProductCategoryService } from '../product-categories/product-category.service'; 9 | import { SupplierService } from '../suppliers/supplier.service'; 10 | 11 | @Injectable({ 12 | providedIn: 'root' 13 | }) 14 | export class ProductService { 15 | private productsUrl = 'api/products'; 16 | 17 | // Use ReplaySubject to "replay" values to new subscribers 18 | // It buffers the defined number of values, in these cases, 1. 19 | 20 | // Invalidates the cache and refreshes the data from the backend server 21 | // The generic parameter is void because it does not care what the value is, only that an item is emitted. 22 | private refresh = new ReplaySubject(1); 23 | // Retains the currently selected product Id 24 | // Uses 0 for no selected product (couldn't use null because it is used as a route parameter) 25 | private selectedProductSource = new ReplaySubject(1); 26 | // Expose the selectedProduct as an observable for use by any components 27 | selectedProductChanges$ = this.selectedProductSource.asObservable(); 28 | 29 | // LIST OF STREAMS 30 | 31 | // All products 32 | // Instead of defining the http.get in a method in the service, 33 | // set the observable directly 34 | // Use shareReplay to "replay" the data from the observable 35 | // Subscription remains even if there are no subscribers (navigating to the Welcome page for example) 36 | products$ = this.http.get(this.productsUrl) 37 | .pipe( 38 | tap(data => console.log('getProducts: ', JSON.stringify(data))), 39 | shareReplay(), 40 | catchError(this.handleError) 41 | ); 42 | 43 | // All products 44 | // Same as above, but set up with `refresh` to allow for invalidating the cache 45 | // Must then `mergeMap` to flatten the inner observable. 46 | // products$ = this.refresh.pipe( 47 | // mergeMap(() => this.http.get(this.productsUrl)), 48 | // tap(data => console.log('getProducts: ', JSON.stringify(data))), 49 | // shareReplay(), 50 | // catchError(this.handleError) 51 | // ); 52 | 53 | // All products with category id mapped to category name 54 | // Be sure to specify the type to ensure after the map that it knows the correct type 55 | productsWithCategory$ = combineLatest( 56 | this.products$, 57 | this.productCategoryService.productCategories$ 58 | ).pipe( 59 | map(([products, categories]) => 60 | products.map( 61 | p => 62 | ({ 63 | ...p, 64 | category: categories.find(c => p.categoryId === c.id).name 65 | } as Product) // <-- note the type here! 66 | ) 67 | ), 68 | shareReplay() 69 | ); 70 | 71 | // Currently selected product 72 | // Subscribed to in both List and Detail pages, 73 | // so use the shareReply to share it with any component that uses it 74 | // Location of the shareReplay matters ... won't share anything *after* the shareReplay 75 | selectedProduct$ = combineLatest( 76 | this.selectedProductChanges$, 77 | this.productsWithCategory$ 78 | ).pipe( 79 | map(([selectedProductId, products]) => 80 | products.find(product => product.id === selectedProductId) 81 | ), 82 | tap(product => console.log('changeSelectedProduct', product)), 83 | shareReplay({ bufferSize: 1, refCount: false }) 84 | ); 85 | 86 | // filter(Boolean) checks for nulls, which casts anything it gets to a Boolean. 87 | // Filter(Boolean) of an undefined value returns false 88 | // filter(Boolean) -> filter(value => !!value) 89 | // SwitchMap here instead of mergeMap so quickly clicking on 90 | // the items cancels prior requests. 91 | selectedProductSuppliers$ = this.selectedProduct$.pipe( 92 | filter(value => !!value), 93 | switchMap(product => 94 | this.supplierService.getSuppliersByIds(product.supplierIds) 95 | ) 96 | ); 97 | 98 | constructor( 99 | private http: HttpClient, 100 | private productCategoryService: ProductCategoryService, 101 | private supplierService: SupplierService 102 | ) { } 103 | 104 | // Change the selected product 105 | changeSelectedProduct(selectedProductId: number | null): void { 106 | this.selectedProductSource.next(selectedProductId); 107 | } 108 | 109 | // AntiPattern: Nested (or chained) http calls results in nested observables 110 | // that are difficult to process 111 | // First, get the product 112 | // For each supplier for that product, get the supplier info 113 | // getProductSuppliers(id: number) { 114 | // const productUrl = `${this.productsUrl}/${id}`; 115 | // return this.http.get(productUrl) 116 | // .pipe( 117 | // map(product => 118 | // product.supplierIds.map(supplierId => { 119 | // const supplierUrl = `${this.suppliersUrl}/${supplierId}`; 120 | // return this.http.get(supplierUrl); 121 | // }) 122 | // ), 123 | // catchError(this.handleError) 124 | // ); 125 | // } 126 | 127 | // Refresh the data. 128 | refreshData(): void { 129 | this.start(); 130 | } 131 | 132 | start() { 133 | // Start the related services 134 | this.productCategoryService.start(); 135 | this.refresh.next(); 136 | } 137 | 138 | // Gets a single product by id 139 | // Using the existing list of products. 140 | // This could instead get the data directly 141 | // if required, such as on an edit. 142 | private getProduct(id: number): Observable { 143 | return this.products$.pipe( 144 | map(productlist => productlist.find(row => row.id === id)), 145 | tap(data => console.log('getProduct: ', JSON.stringify(data))), 146 | catchError(this.handleError) 147 | ); 148 | } 149 | 150 | private handleError(err) { 151 | // in a real world app, we may send the server to some remote logging infrastructure 152 | // instead of just logging it to the console 153 | let errorMessage: string; 154 | if (err.error instanceof ErrorEvent) { 155 | // A client-side or network error occurred. Handle it accordingly. 156 | errorMessage = `An error occurred: ${err.error.message}`; 157 | } else { 158 | // The backend returned an unsuccessful response code. 159 | // The response body may contain clues as to what went wrong, 160 | errorMessage = `Backend returned code ${err.status}: ${err.body.error}`; 161 | } 162 | console.error(err); 163 | return throwError(errorMessage); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/products/product.ts: -------------------------------------------------------------------------------- 1 | import { Supplier } from '../suppliers/supplier'; 2 | 3 | /* 4 | Defines the product entity 5 | This shape includes both the categoryId and the category string 6 | This shape includes both the supplierIds and the supplier objects 7 | */ 8 | export interface Product { 9 | id: number; 10 | productName: string; 11 | productCode: string; 12 | categoryId: number; 13 | category?: string; 14 | description: string; 15 | price: number; 16 | supplierIds?: number[]; 17 | suppliers?: Supplier[]; 18 | } 19 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | @NgModule({ 6 | imports: [ 7 | CommonModule 8 | ], 9 | exports: [ 10 | CommonModule, 11 | FormsModule 12 | ] 13 | }) 14 | export class SharedModule { } 15 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/suppliers/supplier-data.ts: -------------------------------------------------------------------------------- 1 | import { Supplier } from './supplier'; 2 | 3 | export class SupplierData { 4 | 5 | static suppliers: Supplier[] = [ 6 | { 7 | 'id': 1, 8 | 'name': 'Acme Gardening Supply', 9 | 'cost': 16.95, 10 | 'minQuantity': 12 11 | }, 12 | { 13 | 'id': 2, 14 | 'name': 'Standard Gardening', 15 | 'cost': 15.95, 16 | 'minQuantity': 24 17 | }, 18 | 19 | { 20 | 'id': 3, 21 | 'name': 'Acme Gardening Supply', 22 | 'cost': 12, 23 | 'minQuantity': 6 24 | }, 25 | { 26 | 'id': 4, 27 | 'name': 'Acme General Supply', 28 | 'cost': 25, 29 | 'minQuantity': 2 30 | }, 31 | { 32 | 'id': 5, 33 | 'name': 'Acme General Supply', 34 | 'cost': 2, 35 | 'minQuantity': 24 36 | }, 37 | { 38 | 'id': 6, 39 | 'name': 'Acme Tool Supply', 40 | 'cost': 4, 41 | 'minQuantity': 12 42 | }, 43 | { 44 | 'id': 7, 45 | 'name': 'Tools Are Us', 46 | 'cost': 8, 47 | 'minQuantity': 8 48 | }, 49 | { 50 | 'id': 8, 51 | 'name': 'Acme Tool Supply', 52 | 'cost': 4, 53 | 'minQuantity': 12 54 | }, 55 | { 56 | 'id': 9, 57 | 'name': 'Acme Game Supply', 58 | 'cost': 20, 59 | 'minQuantity': 6 60 | }, 61 | { 62 | 'id': 10, 63 | 'name': 'Acme General Supply', 64 | 'cost': 12, 65 | 'minQuantity': 12 66 | } 67 | ]; 68 | } 69 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/suppliers/supplier.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | import { Observable, throwError, forkJoin } from 'rxjs'; 5 | import { catchError, tap } from 'rxjs/operators'; 6 | 7 | import { Supplier } from './supplier'; 8 | 9 | @Injectable({ 10 | providedIn: 'root' 11 | }) 12 | export class SupplierService { 13 | private suppliersUrl = 'api/suppliers'; 14 | 15 | constructor(private http: HttpClient) { } 16 | 17 | // Gets all suppliers 18 | private getSuppliers(): Observable { 19 | return this.http.get(this.suppliersUrl) 20 | .pipe( 21 | tap(data => console.log('getSuppliers: ', JSON.stringify(data))), 22 | catchError(this.handleError) 23 | ); 24 | } 25 | 26 | // Gets set of suppliers given a set of ids 27 | getSuppliersByIds(ids: number[]): Observable { 28 | // Build the list of http calls 29 | const calls: Observable[] = []; 30 | ids.map(id => { 31 | const url = `${this.suppliersUrl}/${id}`; 32 | calls.push(this.http.get(url)); 33 | }); 34 | // Join the calls 35 | return forkJoin(calls).pipe( 36 | tap(data => console.log('getSuppliersByIds: ', JSON.stringify(data))), 37 | catchError(this.handleError) 38 | ); 39 | } 40 | 41 | // Gets a single supplier by id 42 | private getSupplier(id: number): Observable { 43 | const url = `${this.suppliersUrl}/${id}`; 44 | return this.http.get(url) 45 | .pipe( 46 | tap(data => console.log('getSupplier: ', JSON.stringify(data))), 47 | catchError(this.handleError) 48 | ); 49 | } 50 | 51 | private handleError(err) { 52 | // in a real world app, we may send the server to some remote logging infrastructure 53 | // instead of just logging it to the console 54 | let errorMessage: string; 55 | if (err.error instanceof ErrorEvent) { 56 | // A client-side or network error occurred. Handle it accordingly. 57 | errorMessage = `An error occurred: ${err.error.message}`; 58 | } else { 59 | // The backend returned an unsuccessful response code. 60 | // The response body may contain clues as to what went wrong, 61 | errorMessage = `Backend returned code ${err.status}: ${err.body.error}`; 62 | } 63 | console.error(err); 64 | return throwError(errorMessage); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/app/suppliers/supplier.ts: -------------------------------------------------------------------------------- 1 | /* Defines the supplier entity */ 2 | export interface Supplier { 3 | id: number; 4 | name: string; 5 | cost: number; 6 | minQuantity: number; 7 | } 8 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-DD/17098510c7cc1fbeecb894bb41aa4215068e6ba7/APM-WithRefresh/src/assets/.gitkeep -------------------------------------------------------------------------------- /APM-WithRefresh/src/assets/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-DD/17098510c7cc1fbeecb894bb41aa4215068e6ba7/APM-WithRefresh/src/assets/images/logo.jpg -------------------------------------------------------------------------------- /APM-WithRefresh/src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /APM-WithRefresh/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /APM-WithRefresh/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/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-DD/17098510c7cc1fbeecb894bb41aa4215068e6ba7/APM-WithRefresh/src/favicon.ico -------------------------------------------------------------------------------- /APM-WithRefresh/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | APM 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/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-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /APM-WithRefresh/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 | -------------------------------------------------------------------------------- /APM-WithRefresh/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 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** 38 | * If the application will be indexed by Google Search, the following is required. 39 | * Googlebot uses a renderer based on Chrome 41. 40 | * https://developers.google.com/search/docs/guides/rendering 41 | **/ 42 | // import 'core-js/es6/array'; 43 | 44 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 45 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 46 | 47 | /** IE10 and IE11 requires the following for the Reflect API. */ 48 | // import 'core-js/es6/reflect'; 49 | 50 | /** 51 | * Web Animations `@angular/platform-browser/animations` 52 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 53 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 54 | **/ 55 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 56 | 57 | /** 58 | * By default, zone.js will patch all possible macroTask and DomEvents 59 | * user can disable parts of macroTask/DomEvents patch by setting following flags 60 | */ 61 | 62 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 63 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 64 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 65 | 66 | /* 67 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 68 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 69 | */ 70 | // (window as any).__Zone_enable_cross_context_check = true; 71 | 72 | /*************************************************************************************************** 73 | * Zone JS is required by default for Angular itself. 74 | */ 75 | import 'zone.js/dist/zone'; // Included with Angular CLI. 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import "~bootstrap/dist/css/bootstrap.min.css"; 3 | @import "~font-awesome/css/font-awesome.min.css"; 4 | 5 | div.card-header { 6 | font-size: large; 7 | } 8 | 9 | div.card { 10 | margin-top: 10px 11 | } 12 | 13 | .table { 14 | margin-top: 10px 15 | } 16 | -------------------------------------------------------------------------------- /APM-WithRefresh/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/dist/zone-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: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /APM-WithRefresh/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "pm", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "pm", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /APM-WithRefresh/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "target": "es5", 13 | "typeRoots": [ 14 | "node_modules/@types" 15 | ], 16 | "lib": [ 17 | "es2018", 18 | "dom" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /APM-WithRefresh/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 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-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "component-class-suffix": true, 129 | "directive-class-suffix": true 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /APM/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://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 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /APM/.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 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | -------------------------------------------------------------------------------- /APM/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.autoSave": "afterDelay", 3 | "html.format.wrapAttributes": "force-aligned" 4 | } -------------------------------------------------------------------------------- /APM/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "APM": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "pm", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/APM", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "fileReplacements": [ 33 | { 34 | "replace": "src/environments/environment.ts", 35 | "with": "src/environments/environment.prod.ts" 36 | } 37 | ], 38 | "optimization": true, 39 | "outputHashing": "all", 40 | "sourceMap": false, 41 | "extractCss": true, 42 | "namedChunks": false, 43 | "aot": true, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | } 53 | ] 54 | } 55 | } 56 | }, 57 | "serve": { 58 | "builder": "@angular-devkit/build-angular:dev-server", 59 | "options": { 60 | "browserTarget": "APM:build" 61 | }, 62 | "configurations": { 63 | "production": { 64 | "browserTarget": "APM:build:production" 65 | } 66 | } 67 | }, 68 | "extract-i18n": { 69 | "builder": "@angular-devkit/build-angular:extract-i18n", 70 | "options": { 71 | "browserTarget": "APM:build" 72 | } 73 | }, 74 | "test": { 75 | "builder": "@angular-devkit/build-angular:karma", 76 | "options": { 77 | "main": "src/test.ts", 78 | "polyfills": "src/polyfills.ts", 79 | "tsConfig": "src/tsconfig.spec.json", 80 | "karmaConfig": "src/karma.conf.js", 81 | "styles": [ 82 | "src/styles.css" 83 | ], 84 | "scripts": [], 85 | "assets": [ 86 | "src/favicon.ico", 87 | "src/assets" 88 | ] 89 | } 90 | }, 91 | "lint": { 92 | "builder": "@angular-devkit/build-angular:tslint", 93 | "options": { 94 | "tsConfig": [ 95 | "src/tsconfig.app.json", 96 | "src/tsconfig.spec.json" 97 | ], 98 | "exclude": [ 99 | "**/node_modules/**" 100 | ] 101 | } 102 | } 103 | } 104 | }, 105 | "APM-e2e": { 106 | "root": "e2e/", 107 | "projectType": "application", 108 | "architect": { 109 | "e2e": { 110 | "builder": "@angular-devkit/build-angular:protractor", 111 | "options": { 112 | "protractorConfig": "e2e/protractor.conf.js", 113 | "devServerTarget": "APM:serve" 114 | }, 115 | "configurations": { 116 | "production": { 117 | "devServerTarget": "APM:serve:production" 118 | } 119 | } 120 | }, 121 | "lint": { 122 | "builder": "@angular-devkit/build-angular:tslint", 123 | "options": { 124 | "tsConfig": "e2e/tsconfig.e2e.json", 125 | "exclude": [ 126 | "**/node_modules/**" 127 | ] 128 | } 129 | } 130 | } 131 | } 132 | }, 133 | "defaultProject": "APM" 134 | } -------------------------------------------------------------------------------- /APM/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /APM/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to APM!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /APM/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('pm-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /APM/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /APM/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apm", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve -o", 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": "~7.0.0", 15 | "@angular/common": "~7.0.0", 16 | "@angular/compiler": "~7.0.0", 17 | "@angular/core": "~7.0.0", 18 | "@angular/forms": "~7.0.0", 19 | "@angular/http": "~7.0.0", 20 | "@angular/platform-browser": "~7.0.0", 21 | "@angular/platform-browser-dynamic": "~7.0.0", 22 | "@angular/router": "~7.0.0", 23 | "bootstrap": "^4.1.3", 24 | "core-js": "^2.5.4", 25 | "font-awesome": "^4.7.0", 26 | "rxjs": "~6.4.0", 27 | "zone.js": "~0.8.26" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.10.0", 31 | "@angular/cli": "~7.0.3", 32 | "@angular/compiler-cli": "~7.0.0", 33 | "@angular/language-service": "~7.0.0", 34 | "@types/node": "~8.9.4", 35 | "@types/jasmine": "~2.8.8", 36 | "@types/jasminewd2": "~2.0.3", 37 | "angular-in-memory-web-api": "^0.7.0", 38 | "codelyzer": "~4.5.0", 39 | "jasmine-core": "~2.99.1", 40 | "jasmine-spec-reporter": "~4.2.1", 41 | "karma": "~3.0.0", 42 | "karma-chrome-launcher": "~2.2.0", 43 | "karma-coverage-istanbul-reporter": "~2.0.1", 44 | "karma-jasmine": "~1.1.2", 45 | "karma-jasmine-html-reporter": "^0.2.2", 46 | "protractor": "~5.4.0", 47 | "ts-node": "~7.0.0", 48 | "tslint": "~5.11.0", 49 | "typescript": "~3.1.1" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /APM/src/app/app-data.ts: -------------------------------------------------------------------------------- 1 | import { InMemoryDbService } from 'angular-in-memory-web-api'; 2 | 3 | import { ProductData } from './products/product-data'; 4 | import { ProductCategoryData } from './product-categories/product-category-data'; 5 | import { SupplierData } from './suppliers/supplier-data'; 6 | 7 | export class AppData implements InMemoryDbService { 8 | 9 | createDb() { 10 | const products = ProductData.products; 11 | const productCategories = ProductCategoryData.categories; 12 | const suppliers = SupplierData.suppliers; 13 | return { products, productCategories, suppliers }; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /APM/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | 4 | import { ShellComponent } from './home/shell.component'; 5 | import { WelcomeComponent } from './home/welcome.component'; 6 | import { PageNotFoundComponent } from './page-not-found.component'; 7 | 8 | @NgModule({ 9 | imports: [ 10 | RouterModule.forRoot([ 11 | { 12 | path: '', 13 | component: ShellComponent, 14 | children: [ 15 | { path: 'welcome', component: WelcomeComponent }, 16 | { 17 | path: 'products', 18 | loadChildren: './products/product.module#ProductModule' 19 | }, 20 | { path: '', redirectTo: 'welcome', pathMatch: 'full' } 21 | ] 22 | }, 23 | { path: '**', component: PageNotFoundComponent } 24 | ]) 25 | ], 26 | exports: [RouterModule] 27 | }) 28 | export class AppRoutingModule { } 29 | -------------------------------------------------------------------------------- /APM/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .nav-link { 2 | font-size: large; 3 | cursor: pointer; 4 | } 5 | 6 | .navbar-light .navbar-nav .nav-link.active { 7 | color: #007ACC 8 | } 9 | -------------------------------------------------------------------------------- /APM/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /APM/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'pm-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | pageTitle = 'Acme Product Management'; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /APM/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 | // Imports for loading & configuring the in-memory web api 6 | import { InMemoryWebApiModule } from 'angular-in-memory-web-api'; 7 | import { AppData } from './app-data'; 8 | 9 | import { AppRoutingModule } from './app-routing.module'; 10 | import { AppComponent } from './app.component'; 11 | import { ShellComponent } from './home/shell.component'; 12 | import { MenuComponent } from './home/menu.component'; 13 | import { WelcomeComponent } from './home/welcome.component'; 14 | import { PageNotFoundComponent } from './page-not-found.component'; 15 | 16 | @NgModule({ 17 | imports: [ 18 | BrowserModule, 19 | HttpClientModule, 20 | InMemoryWebApiModule.forRoot(AppData, { delay: 1000 }), 21 | AppRoutingModule 22 | ], 23 | declarations: [ 24 | AppComponent, 25 | ShellComponent, 26 | MenuComponent, 27 | WelcomeComponent, 28 | PageNotFoundComponent 29 | ], 30 | bootstrap: [AppComponent] 31 | }) 32 | export class AppModule { } 33 | -------------------------------------------------------------------------------- /APM/src/app/home/menu.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /APM/src/app/home/menu.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'pm-menu', 5 | templateUrl: './menu.component.html' 6 | }) 7 | export class MenuComponent { 8 | pageTitle = 'Acme Product Management'; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /APM/src/app/home/page-not-found.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | template: ` 5 |

This is not the page you were looking for!

6 | ` 7 | }) 8 | export class PageNotFoundComponent { } 9 | -------------------------------------------------------------------------------- /APM/src/app/home/shell.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-DD/17098510c7cc1fbeecb894bb41aa4215068e6ba7/APM/src/app/home/shell.component.css -------------------------------------------------------------------------------- /APM/src/app/home/shell.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
-------------------------------------------------------------------------------- /APM/src/app/home/shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'pm-shell', 5 | templateUrl: './shell.component.html', 6 | styleUrls: ['./shell.component.css'] 7 | }) 8 | export class ShellComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /APM/src/app/home/welcome.component.html: -------------------------------------------------------------------------------- 1 | 
2 |
3 | {{pageTitle}} 4 |
5 |
6 |
7 |
8 | 11 |
12 | 13 |
Developed by:
14 |
15 |

Deborah Kurata

16 |
17 | 18 |
@deborahkurata
19 | 22 |
23 |
24 |
-------------------------------------------------------------------------------- /APM/src/app/home/welcome.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | templateUrl: './welcome.component.html' 5 | }) 6 | export class WelcomeComponent { 7 | public pageTitle = 'Welcome'; 8 | } 9 | -------------------------------------------------------------------------------- /APM/src/app/page-not-found.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | template: ` 5 |

This is not the page you were looking for!

6 | ` 7 | }) 8 | export class PageNotFoundComponent { } 9 | -------------------------------------------------------------------------------- /APM/src/app/product-categories/product-category-data.ts: -------------------------------------------------------------------------------- 1 | import { ProductCategory } from './product-category'; 2 | 3 | export class ProductCategoryData { 4 | 5 | static categories: ProductCategory[] = [ 6 | { 7 | 'id': 1, 8 | 'name': 'Garden' 9 | }, 10 | { 11 | 'id': 3, 12 | 'name': 'Toolbox' 13 | }, 14 | { 15 | 'id': 5, 16 | 'name': 'Gaming' 17 | } 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /APM/src/app/product-categories/product-category.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable, throwError } from 'rxjs'; 4 | import { catchError, tap } from 'rxjs/operators'; 5 | import { ProductCategory } from './product-category'; 6 | 7 | @Injectable({ 8 | providedIn: 'root' 9 | }) 10 | export class ProductCategoryService { 11 | private productCategoriesUrl = 'api/productCategories'; 12 | 13 | // All product categories 14 | // Instead of defining the http.get in a method in the service, 15 | // set the observable directly 16 | // These could also be cached by adding `shareReplay`. 17 | productCategories$ = this.http.get(this.productCategoriesUrl) 18 | .pipe( 19 | tap(console.table), 20 | catchError((this.handleError)) 21 | ); 22 | 23 | constructor(private http: HttpClient) { } 24 | 25 | private handleError(err) { 26 | // in a real world app, we may send the server to some remote logging infrastructure 27 | // instead of just logging it to the console 28 | let errorMessage: string; 29 | if (err.error instanceof ErrorEvent) { 30 | // A client-side or network error occurred. Handle it accordingly. 31 | errorMessage = `An error occurred: ${err.error.message}`; 32 | } else { 33 | // The backend returned an unsuccessful response code. 34 | // The response body may contain clues as to what went wrong, 35 | errorMessage = `Backend returned code ${err.status}: ${err.body.error}`; 36 | } 37 | console.error(err); 38 | return throwError(errorMessage); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /APM/src/app/product-categories/product-category.ts: -------------------------------------------------------------------------------- 1 | export interface ProductCategory { 2 | id: number; 3 | name: string; 4 | } 5 | -------------------------------------------------------------------------------- /APM/src/app/products/product-data.ts: -------------------------------------------------------------------------------- 1 | import { Product } from './product'; 2 | 3 | export class ProductData { 4 | 5 | static products: Product[] = [ 6 | { 7 | 'id': 1, 8 | 'productName': 'Leaf Rake', 9 | 'productCode': 'GDN-0011', 10 | 'description': 'Leaf rake with 48-inch wooden handle', 11 | 'price': 19.95, 12 | 'categoryId': 1, 13 | 'supplierIds': [1, 2] 14 | }, 15 | { 16 | 'id': 2, 17 | 'productName': 'Garden Cart', 18 | 'productCode': 'GDN-0023', 19 | 'description': '15 gallon capacity rolling garden cart', 20 | 'price': 32.99, 21 | 'categoryId': 1, 22 | 'supplierIds': [3, 4] 23 | }, 24 | { 25 | 'id': 5, 26 | 'productName': 'Hammer', 27 | 'productCode': 'TBX-0048', 28 | 'description': 'Curved claw steel hammer', 29 | 'price': 8.9, 30 | 'categoryId': 3, 31 | 'supplierIds': [5, 6] 32 | }, 33 | { 34 | 'id': 8, 35 | 'productName': 'Saw', 36 | 'productCode': 'TBX-0022', 37 | 'description': '15-inch steel blade hand saw', 38 | 'price': 11.55, 39 | 'categoryId': 3, 40 | 'supplierIds': [7, 8] 41 | }, 42 | { 43 | 'id': 10, 44 | 'productName': 'Video Game Controller', 45 | 'productCode': 'GMG-0042', 46 | 'description': 'Standard two-button video game controller', 47 | 'price': 35.95, 48 | 'categoryId': 5, 49 | 'supplierIds': [9, 10] 50 | } 51 | ]; 52 | } 53 | -------------------------------------------------------------------------------- /APM/src/app/products/product-detail/product-detail.component.html: -------------------------------------------------------------------------------- 1 |
3 |
4 | {{vm.pageTitle}} 5 |
6 | 7 |
8 | 9 |
10 |
Name:
11 |
{{vm.product.productName}}
12 |
13 |
14 |
Code:
15 |
{{vm.product.productCode}}
16 |
17 |
18 |
Description:
19 |
{{vm.product.description}}
20 |
21 |
22 |
Price:
23 |
{{vm.product.price|currency:"USD":"symbol"}}
24 |
25 |
26 |
Category:
27 |
{{vm.product.category}}
28 |
29 | 30 |
31 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
SupplierCostMinimum Quantity
{{ supplier.name }} {{ supplier.cost | currency:"USD":"symbol":"1.2-2" }}{{ supplier.minQuantity }}
48 |
49 | 50 |
51 |
52 | 53 |
{{error}} 55 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-detail/product-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ChangeDetectionStrategy } from '@angular/core'; 2 | 3 | import { catchError, map, filter } from 'rxjs/operators'; 4 | 5 | import { ProductService } from '../product.service'; 6 | import { Product } from '../product'; 7 | import { combineLatest, of, Subject, Observable } from 'rxjs'; 8 | 9 | @Component({ 10 | selector: 'pm-product-detail', 11 | templateUrl: './product-detail.component.html', 12 | changeDetection: ChangeDetectionStrategy.OnPush 13 | }) 14 | export class ProductDetailComponent { 15 | error$ = new Subject(); 16 | 17 | product$: Observable = this.productService.selectedProduct$ 18 | .pipe( 19 | catchError(error => { 20 | this.error$.next(error); 21 | return of(null); 22 | })); 23 | 24 | // Set the page title 25 | pageTitle$ = this.product$ 26 | .pipe( 27 | map((p: Product) => 28 | p ? `Product Detail for: ${p.productName}` : null) 29 | ); 30 | 31 | productSuppliers$ = this.productService.selectedProductSuppliers$ 32 | .pipe( 33 | catchError(error => { 34 | this.error$.next(error); 35 | return of(null); 36 | })); 37 | 38 | // Create a combined stream with the data used in the view 39 | // Use filter to skip if the product is null 40 | vm$ = combineLatest( 41 | [this.product$, 42 | this.productSuppliers$, 43 | this.pageTitle$]) 44 | .pipe( 45 | filter(([product]) => !!product), 46 | map(([product, productSuppliers, pageTitle]) => 47 | ({ product, productSuppliers, pageTitle })) 48 | ); 49 | 50 | constructor(private productService: ProductService) { } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list.component.css: -------------------------------------------------------------------------------- 1 | thead { 2 | color: #337AB7; 3 | } -------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 | 6 |
8 |
9 | 16 |
17 |
18 |
19 | 20 |
{{error}} 22 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; 2 | import { Router, ActivatedRoute } from '@angular/router'; 3 | 4 | import { of, Subject, Observable, combineLatest } from 'rxjs'; 5 | import { catchError, map } from 'rxjs/operators'; 6 | 7 | import { ProductService } from '../product.service'; 8 | import { Product } from '../product'; 9 | 10 | @Component({ 11 | selector: 'pm-product-list', 12 | templateUrl: './product-list.component.html', 13 | changeDetection: ChangeDetectionStrategy.OnPush 14 | }) 15 | export class ProductListComponent implements OnInit { 16 | pageTitle = 'Products'; 17 | error$ = new Subject(); 18 | 19 | products$: Observable = this.productService.productsWithCategory$ 20 | .pipe( 21 | catchError(error => { 22 | this.error$.next(error); 23 | return of(null); 24 | })); 25 | 26 | selectedProduct$ = this.productService.selectedProduct$; 27 | 28 | vm$ = combineLatest( 29 | [this.products$, this.selectedProduct$] 30 | ) 31 | .pipe( 32 | map(([products, product]: [Product[], Product]) => 33 | ({ products, productId: product ? product.id : 0 })) 34 | ); 35 | 36 | constructor( 37 | private route: ActivatedRoute, 38 | private router: Router, 39 | private productService: ProductService 40 | ) { } 41 | 42 | ngOnInit(): void { 43 | // Read the parameter from the route - supports deep linking 44 | this.route.paramMap.subscribe(params => { 45 | const id = +params.get('id'); 46 | this.productService.changeSelectedProduct(id); 47 | }); 48 | } 49 | 50 | onSelected(productId: number): void { 51 | // Modify the URL to support deep linking 52 | this.router.navigate(['/products', productId]); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /APM/src/app/products/product-shell/product-shell.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 |
6 | 7 |
8 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-shell/product-shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | templateUrl: './product-shell.component.html' 5 | }) 6 | export class ProductShellComponent { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /APM/src/app/products/product.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | import { ReactiveFormsModule } from '@angular/forms'; 4 | 5 | import { ProductListComponent } from './product-list/product-list.component'; 6 | import { ProductDetailComponent } from './product-detail/product-detail.component'; 7 | import { ProductShellComponent } from './product-shell/product-shell.component'; 8 | 9 | import { SharedModule } from '../shared/shared.module'; 10 | 11 | @NgModule({ 12 | imports: [ 13 | SharedModule, 14 | ReactiveFormsModule, 15 | RouterModule.forChild([ 16 | { 17 | path: ':id', 18 | component: ProductShellComponent 19 | } 20 | ]) 21 | ], 22 | declarations: [ 23 | ProductShellComponent, 24 | ProductListComponent, 25 | ProductDetailComponent 26 | ] 27 | }) 28 | export class ProductModule { } 29 | -------------------------------------------------------------------------------- /APM/src/app/products/product.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | import { combineLatest, throwError, of, BehaviorSubject } from 'rxjs'; 5 | import { catchError, map, shareReplay, tap } from 'rxjs/operators'; 6 | 7 | import { Product } from './product'; 8 | import { ProductCategory } from '../product-categories/product-category'; 9 | import { ProductCategoryService } from '../product-categories/product-category.service'; 10 | import { Supplier } from '../suppliers/supplier'; 11 | import { SupplierService } from '../suppliers/supplier.service'; 12 | 13 | @Injectable({ 14 | providedIn: 'root' 15 | }) 16 | export class ProductService { 17 | private productsUrl = 'api/products'; 18 | 19 | // All products 20 | // Instead of defining the http.get in a method in the service, 21 | // set the observable directly 22 | products$ = this.http.get(this.productsUrl) 23 | .pipe( 24 | tap(console.table), 25 | catchError(this.handleError) 26 | ); 27 | 28 | // All products with category id mapped to category name 29 | // Be sure to specify the type after the map to ensure that it knows the correct type 30 | // Use shareReplay to "replay" the data from the observable 31 | // Subscription remains even if there are no subscribers (navigating to the Welcome page for example) 32 | productsWithCategory$ = combineLatest( 33 | [this.products$, 34 | this.productCategoryService.productCategories$] 35 | ).pipe( 36 | map(([products, categories]: [Product[], ProductCategory[]]) => 37 | products.map( 38 | p => 39 | ({ 40 | ...p, 41 | category: categories.find(c => 42 | p.categoryId === c.id).name 43 | } as Product) // <-- note the type here! 44 | ) 45 | ), 46 | shareReplay(1) 47 | ); 48 | 49 | private productSelectedAction = new BehaviorSubject(0); 50 | 51 | // Currently selected product 52 | // Used in both List and Detail pages, 53 | // so use the shareReply to share it with any component that uses it 54 | // Location of the shareReplay matters ... won't share anything *after* the shareReplay 55 | selectedProduct$ = combineLatest( 56 | [this.productSelectedAction, 57 | this.productsWithCategory$] 58 | ).pipe( 59 | map(([selectedProductId, products]) => 60 | products.find(product => product.id === selectedProductId) 61 | ), 62 | tap(product => console.log('selectedProduct', product)), 63 | shareReplay(1), 64 | catchError(this.handleError) 65 | ); 66 | 67 | selectedProductSuppliers$ = combineLatest( 68 | [this.selectedProduct$, 69 | this.supplierService.suppliers$] 70 | ).pipe( 71 | map(([product, suppliers]: [Product, Supplier[]]) => 72 | suppliers.filter( 73 | supplier => product ? product.supplierIds.includes(supplier.id) : of(null) 74 | ) 75 | ) 76 | ); 77 | 78 | constructor( 79 | private http: HttpClient, 80 | private productCategoryService: ProductCategoryService, 81 | private supplierService: SupplierService 82 | ) { } 83 | 84 | // Change the selected product 85 | changeSelectedProduct(selectedProductId: number | null): void { 86 | this.productSelectedAction.next(selectedProductId); 87 | } 88 | 89 | private handleError(err) { 90 | // in a real world app, we may send the server to some remote logging infrastructure 91 | // instead of just logging it to the console 92 | let errorMessage: string; 93 | if (typeof (err) === 'string') { 94 | errorMessage = err; 95 | } else { 96 | if (err.error instanceof ErrorEvent) { 97 | // A client-side or network error occurred. Handle it accordingly. 98 | errorMessage = `An error occurred: ${err.error.message}`; 99 | } else { 100 | // The backend returned an unsuccessful response code. 101 | // The response body may contain clues as to what went wrong, 102 | errorMessage = `Backend returned code ${err.status}: ${err.body.error}`; 103 | } 104 | } 105 | console.error(err); 106 | return throwError(errorMessage); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /APM/src/app/products/product.ts: -------------------------------------------------------------------------------- 1 | import { Supplier } from '../suppliers/supplier'; 2 | 3 | /* 4 | Defines the product entity 5 | This shape includes both the categoryId and the category string 6 | This shape includes both the supplierIds and the supplier objects 7 | */ 8 | export interface Product { 9 | id: number; 10 | productName: string; 11 | productCode: string; 12 | categoryId: number; 13 | category?: string; 14 | description: string; 15 | price: number; 16 | supplierIds?: number[]; 17 | } 18 | -------------------------------------------------------------------------------- /APM/src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | @NgModule({ 6 | imports: [ 7 | CommonModule 8 | ], 9 | exports: [ 10 | CommonModule, 11 | FormsModule 12 | ] 13 | }) 14 | export class SharedModule { } 15 | -------------------------------------------------------------------------------- /APM/src/app/suppliers/supplier-data.ts: -------------------------------------------------------------------------------- 1 | import { Supplier } from './supplier'; 2 | 3 | export class SupplierData { 4 | 5 | static suppliers: Supplier[] = [ 6 | { 7 | 'id': 1, 8 | 'name': 'Acme Gardening Supply', 9 | 'cost': 16.95, 10 | 'minQuantity': 12 11 | }, 12 | { 13 | 'id': 2, 14 | 'name': 'Standard Gardening', 15 | 'cost': 15.95, 16 | 'minQuantity': 24 17 | }, 18 | 19 | { 20 | 'id': 3, 21 | 'name': 'Acme Gardening Supply', 22 | 'cost': 12, 23 | 'minQuantity': 6 24 | }, 25 | { 26 | 'id': 4, 27 | 'name': 'Acme General Supply', 28 | 'cost': 25, 29 | 'minQuantity': 2 30 | }, 31 | { 32 | 'id': 5, 33 | 'name': 'Acme General Supply', 34 | 'cost': 2, 35 | 'minQuantity': 24 36 | }, 37 | { 38 | 'id': 6, 39 | 'name': 'Acme Tool Supply', 40 | 'cost': 4, 41 | 'minQuantity': 12 42 | }, 43 | { 44 | 'id': 7, 45 | 'name': 'Tools Are Us', 46 | 'cost': 8, 47 | 'minQuantity': 8 48 | }, 49 | { 50 | 'id': 8, 51 | 'name': 'Acme Tool Supply', 52 | 'cost': 4, 53 | 'minQuantity': 12 54 | }, 55 | { 56 | 'id': 9, 57 | 'name': 'Acme Game Supply', 58 | 'cost': 20, 59 | 'minQuantity': 6 60 | }, 61 | { 62 | 'id': 10, 63 | 'name': 'Acme General Supply', 64 | 'cost': 12, 65 | 'minQuantity': 12 66 | } 67 | ]; 68 | } 69 | -------------------------------------------------------------------------------- /APM/src/app/suppliers/supplier.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | import { throwError, of } from 'rxjs'; 5 | import { catchError, tap, shareReplay, map, concatMap, mergeMap, switchMap } from 'rxjs/operators'; 6 | 7 | import { Supplier } from './supplier'; 8 | 9 | @Injectable({ 10 | providedIn: 'root' 11 | }) 12 | export class SupplierService { 13 | private suppliersUrl = 'api/suppliers'; 14 | 15 | suppliers$ = this.http.get(this.suppliersUrl) 16 | .pipe( 17 | tap(console.table), 18 | shareReplay(), 19 | catchError(this.handleError) 20 | ); 21 | 22 | suppliersWithMap$ = of(1, 5, 8) 23 | .pipe( 24 | map(id => this.http.get(`${this.suppliersUrl}/${id}`) 25 | ) 26 | ); 27 | 28 | suppliersWithConcatMap$ = of(1, 5, 8) 29 | .pipe( 30 | tap(id => console.log('concatMap source Observable:', id)), 31 | concatMap(id => this.http.get(`${this.suppliersUrl}/${id}`)) 32 | ); 33 | 34 | suppliersWithMergeMap$ = of(1, 5, 8) 35 | .pipe( 36 | tap(id => console.log('mergeMap source Observable:', id)), 37 | mergeMap(id => this.http.get(`${this.suppliersUrl}/${id}`)) 38 | ); 39 | 40 | suppliersWithSwitchMap$ = of(1, 5, 8) 41 | .pipe( 42 | tap(id => console.log('switchMap source Observable:', id)), 43 | switchMap(id => this.http.get(`${this.suppliersUrl}/${id}`)) 44 | ); 45 | 46 | constructor(private http: HttpClient) { 47 | // this.suppliersWithMap$ 48 | // .subscribe(o => o.subscribe( 49 | // item => console.log('map result:', item) 50 | // )); 51 | 52 | // this.suppliersWithConcatMap$.subscribe( 53 | // item => console.log('concatMap result:', item) 54 | // ) 55 | 56 | // this.suppliersWithMergeMap$.subscribe( 57 | // item => console.log('mergeMap result:', item) 58 | // ) 59 | 60 | // this.suppliersWithSwitchMap$.subscribe( 61 | // item => console.log('switchMap result:', item) 62 | // ) 63 | } 64 | 65 | private handleError(err) { 66 | // in a real world app, we may send the server to some remote logging infrastructure 67 | // instead of just logging it to the console 68 | let errorMessage: string; 69 | if (err.error instanceof ErrorEvent) { 70 | // A client-side or network error occurred. Handle it accordingly. 71 | errorMessage = `An error occurred: ${err.error.message}`; 72 | } else { 73 | // The backend returned an unsuccessful response code. 74 | // The response body may contain clues as to what went wrong, 75 | errorMessage = `Backend returned code ${err.status}: ${err.body.error}`; 76 | } 77 | console.error(err); 78 | return throwError(errorMessage); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /APM/src/app/suppliers/supplier.ts: -------------------------------------------------------------------------------- 1 | /* Defines the supplier entity */ 2 | export interface Supplier { 3 | id: number; 4 | name: string; 5 | cost: number; 6 | minQuantity: number; 7 | } 8 | -------------------------------------------------------------------------------- /APM/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-DD/17098510c7cc1fbeecb894bb41aa4215068e6ba7/APM/src/assets/.gitkeep -------------------------------------------------------------------------------- /APM/src/assets/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-DD/17098510c7cc1fbeecb894bb41aa4215068e6ba7/APM/src/assets/images/logo.jpg -------------------------------------------------------------------------------- /APM/src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /APM/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /APM/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/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /APM/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-DD/17098510c7cc1fbeecb894bb41aa4215068e6ba7/APM/src/favicon.ico -------------------------------------------------------------------------------- /APM/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | APM 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /APM/src/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-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /APM/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 | -------------------------------------------------------------------------------- /APM/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 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** 38 | * If the application will be indexed by Google Search, the following is required. 39 | * Googlebot uses a renderer based on Chrome 41. 40 | * https://developers.google.com/search/docs/guides/rendering 41 | **/ 42 | // import 'core-js/es6/array'; 43 | 44 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 45 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 46 | 47 | /** IE10 and IE11 requires the following for the Reflect API. */ 48 | // import 'core-js/es6/reflect'; 49 | 50 | /** 51 | * Web Animations `@angular/platform-browser/animations` 52 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 53 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 54 | **/ 55 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 56 | 57 | /** 58 | * By default, zone.js will patch all possible macroTask and DomEvents 59 | * user can disable parts of macroTask/DomEvents patch by setting following flags 60 | */ 61 | 62 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 63 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 64 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 65 | 66 | /* 67 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 68 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 69 | */ 70 | // (window as any).__Zone_enable_cross_context_check = true; 71 | 72 | /*************************************************************************************************** 73 | * Zone JS is required by default for Angular itself. 74 | */ 75 | import 'zone.js/dist/zone'; // Included with Angular CLI. 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /APM/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import "~bootstrap/dist/css/bootstrap.min.css"; 3 | @import "~font-awesome/css/font-awesome.min.css"; 4 | 5 | div.card-header { 6 | font-size: large; 7 | } 8 | 9 | div.card { 10 | margin-top: 10px 11 | } 12 | 13 | .table { 14 | margin-top: 10px 15 | } 16 | -------------------------------------------------------------------------------- /APM/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/dist/zone-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: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /APM/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /APM/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /APM/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "pm", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "pm", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /APM/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "target": "es5", 13 | "typeRoots": [ 14 | "node_modules/@types" 15 | ], 16 | "lib": [ 17 | "es2018", 18 | "dom" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /APM/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 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-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "component-class-suffix": true, 129 | "directive-class-suffix": true 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Deborah Kurata 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular-DD 2 | Angular: Working with Derivative Data using RxJS 3 | 4 | • Collecting data from a backend server 5 | 6 | • Combining data streams with other data streams to handle foreign key and aggregate relationships 7 | 8 | • Caching the streams in a service so they can be readily reused 9 | 10 | • Producing user - friendly data for display 11 | 12 | • All without a subscription 13 | --------------------------------------------------------------------------------