├── APM ├── .editorconfig ├── .gitignore ├── .vscode │ └── settings.json ├── README.md ├── angular.json ├── browserslist ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app-data.ts │ │ ├── app-routing.module.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── home │ │ │ ├── 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.css │ │ │ │ ├── product-detail.component.html │ │ │ │ ├── product-detail.component.ts │ │ │ │ └── product-resolver.service.ts │ │ │ ├── product-edit │ │ │ │ ├── product-edit.component.html │ │ │ │ ├── product-edit.component.ts │ │ │ │ └── product-edit.guard.ts │ │ │ ├── product-list │ │ │ │ ├── product-list-asyncPipe.component.html │ │ │ │ ├── product-list-asyncPipe.component.ts │ │ │ │ ├── product-list-category.component.html │ │ │ │ ├── product-list-category.component.ts │ │ │ │ ├── product-list-one.component.html │ │ │ │ ├── product-list-one.component.ts │ │ │ │ ├── product-list.component.css │ │ │ │ ├── product-list.component.html │ │ │ │ └── product-list.component.ts │ │ │ ├── product-suppliers │ │ │ │ ├── product-suppliers.component.html │ │ │ │ └── product-suppliers.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 │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json ├── LICENSE └── README.md /APM/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.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 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /APM/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.autoSave": "afterDelay", 3 | "html.format.wrapAttributes": "force-aligned" 4 | } -------------------------------------------------------------------------------- /APM/README.md: -------------------------------------------------------------------------------- 1 | # APM 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.3.2. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /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 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "pm", 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": "tsconfig.app.json", 21 | "aot": false, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "src/styles.css" 28 | ], 29 | "scripts": [] 30 | }, 31 | "configurations": { 32 | "production": { 33 | "fileReplacements": [ 34 | { 35 | "replace": "src/environments/environment.ts", 36 | "with": "src/environments/environment.prod.ts" 37 | } 38 | ], 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "aot": true, 45 | "extractLicenses": true, 46 | "vendorChunk": false, 47 | "buildOptimizer": true, 48 | "budgets": [ 49 | { 50 | "type": "initial", 51 | "maximumWarning": "2mb", 52 | "maximumError": "5mb" 53 | }, 54 | { 55 | "type": "anyComponentStyle", 56 | "maximumWarning": "6kb", 57 | "maximumError": "10kb" 58 | } 59 | ] 60 | } 61 | } 62 | }, 63 | "serve": { 64 | "builder": "@angular-devkit/build-angular:dev-server", 65 | "options": { 66 | "browserTarget": "APM:build" 67 | }, 68 | "configurations": { 69 | "production": { 70 | "browserTarget": "APM:build:production" 71 | } 72 | } 73 | }, 74 | "extract-i18n": { 75 | "builder": "@angular-devkit/build-angular:extract-i18n", 76 | "options": { 77 | "browserTarget": "APM:build" 78 | } 79 | }, 80 | "test": { 81 | "builder": "@angular-devkit/build-angular:karma", 82 | "options": { 83 | "main": "src/test.ts", 84 | "polyfills": "src/polyfills.ts", 85 | "tsConfig": "tsconfig.spec.json", 86 | "karmaConfig": "karma.conf.js", 87 | "assets": [ 88 | "src/favicon.ico", 89 | "src/assets" 90 | ], 91 | "styles": [ 92 | "src/styles.css" 93 | ], 94 | "scripts": [] 95 | } 96 | }, 97 | "lint": { 98 | "builder": "@angular-devkit/build-angular:tslint", 99 | "options": { 100 | "tsConfig": [ 101 | "tsconfig.app.json", 102 | "tsconfig.spec.json", 103 | "e2e/tsconfig.json" 104 | ], 105 | "exclude": [ 106 | "**/node_modules/**" 107 | ] 108 | } 109 | }, 110 | "e2e": { 111 | "builder": "@angular-devkit/build-angular:protractor", 112 | "options": { 113 | "protractorConfig": "e2e/protractor.conf.js", 114 | "devServerTarget": "APM:serve" 115 | }, 116 | "configurations": { 117 | "production": { 118 | "devServerTarget": "APM:serve:production" 119 | } 120 | } 121 | } 122 | } 123 | }}, 124 | "defaultProject": "APM" 125 | } -------------------------------------------------------------------------------- /APM/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /APM/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | 'browserName': 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /APM/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('APM app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /APM/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('pm-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /APM/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /APM/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/APM'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 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 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /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": "~8.2.4", 15 | "@angular/common": "~8.2.4", 16 | "@angular/compiler": "~8.2.4", 17 | "@angular/core": "~8.2.4", 18 | "@angular/forms": "~8.2.4", 19 | "@angular/platform-browser": "~8.2.4", 20 | "@angular/platform-browser-dynamic": "~8.2.4", 21 | "@angular/router": "~8.2.4", 22 | "bootstrap": "^4.3.1", 23 | "font-awesome": "^4.7.0", 24 | "rxjs": "~6.4.0", 25 | "tslib": "^1.10.0", 26 | "zone.js": "~0.9.1" 27 | }, 28 | "devDependencies": { 29 | "@angular-devkit/build-angular": "~0.803.2", 30 | "@angular/cli": "~8.3.2", 31 | "@angular/compiler-cli": "~8.2.4", 32 | "@angular/language-service": "~8.2.4", 33 | "@types/jasmine": "~3.3.8", 34 | "@types/jasminewd2": "~2.0.3", 35 | "@types/node": "~8.9.4", 36 | "angular-in-memory-web-api": "^0.9.0", 37 | "codelyzer": "^5.0.0", 38 | "jasmine-core": "~3.4.0", 39 | "jasmine-spec-reporter": "~4.2.1", 40 | "karma": "~4.1.0", 41 | "karma-chrome-launcher": "~2.2.0", 42 | "karma-coverage-istanbul-reporter": "~2.0.1", 43 | "karma-jasmine": "~2.0.1", 44 | "karma-jasmine-html-reporter": "^1.4.0", 45 | "protractor": "~5.4.0", 46 | "ts-node": "~7.0.0", 47 | "tslint": "~5.15.0", 48 | "typescript": "~3.5.3" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /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 { WelcomeComponent } from './home/welcome.component'; 5 | import { PageNotFoundComponent } from './page-not-found.component'; 6 | 7 | @NgModule({ 8 | imports: [ 9 | RouterModule.forRoot([ 10 | { path: 'welcome', component: WelcomeComponent }, 11 | { 12 | path: 'products', 13 | loadChildren: () => 14 | import('./products/product.module').then(m => m.ProductModule) 15 | }, 16 | { path: '', redirectTo: 'welcome', pathMatch: 'full' }, 17 | { path: '**', component: PageNotFoundComponent } 18 | ]) 19 | ], 20 | exports: [RouterModule] 21 | }) 22 | export class AppRoutingModule { } 23 | -------------------------------------------------------------------------------- /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 | 10 | /* Spinner */ 11 | .spinner { 12 | font-size:300%; 13 | position:absolute; 14 | top: 50%; 15 | left: 50%; 16 | z-index:10 17 | } 18 | 19 | .fa-spinner { 20 | -webkit-animation: spin 1000ms infinite linear; 21 | animation: spin 1000ms infinite linear; 22 | } 23 | @-webkit-keyframes spin { 24 | 0% { 25 | -webkit-transform: rotate(0deg); 26 | transform: rotate(0deg); 27 | } 28 | 100% { 29 | -webkit-transform: rotate(359deg); 30 | transform: rotate(359deg); 31 | } 32 | } 33 | @keyframes spin { 34 | 0% { 35 | -webkit-transform: rotate(0deg); 36 | transform: rotate(0deg); 37 | } 38 | 100% { 39 | -webkit-transform: rotate(359deg); 40 | transform: rotate(359deg); 41 | } 42 | } -------------------------------------------------------------------------------- /APM/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 38 | 39 |
40 | 41 |
-------------------------------------------------------------------------------- /APM/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Router, Event, NavigationStart, NavigationEnd, NavigationError, NavigationCancel } from '@angular/router'; 3 | 4 | @Component({ 5 | selector: 'pm-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent { 10 | pageTitle = 'Acme Product Management'; 11 | loading = true; 12 | 13 | constructor(private router: Router) { 14 | router.events.subscribe((routerEvent: Event) => { 15 | this.checkRouterEvent(routerEvent); 16 | }); 17 | } 18 | 19 | checkRouterEvent(routerEvent: Event): void { 20 | if (routerEvent instanceof NavigationStart) { 21 | this.loading = true; 22 | } 23 | 24 | if (routerEvent instanceof NavigationEnd || 25 | routerEvent instanceof NavigationCancel || 26 | routerEvent instanceof NavigationError) { 27 | this.loading = false; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /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 { WelcomeComponent } from './home/welcome.component'; 12 | import { PageNotFoundComponent } from './page-not-found.component'; 13 | 14 | @NgModule({ 15 | imports: [ 16 | BrowserModule, 17 | HttpClientModule, 18 | InMemoryWebApiModule.forRoot(AppData, { delay: 1000 }), 19 | AppRoutingModule 20 | ], 21 | declarations: [ 22 | AppComponent, 23 | WelcomeComponent, 24 | PageNotFoundComponent 25 | ], 26 | bootstrap: [AppComponent] 27 | }) 28 | export class AppModule { } 29 | -------------------------------------------------------------------------------- /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 { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | import { Observable, of, throwError } from 'rxjs'; 5 | import { catchError, tap, map } from 'rxjs/operators'; 6 | 7 | import { ProductCategory } from './product-category'; 8 | 9 | @Injectable({ 10 | providedIn: 'root' 11 | }) 12 | export class ProductCategoryService { 13 | private productsUrl = 'api/productCategories'; 14 | 15 | constructor(private http: HttpClient) { } 16 | 17 | getCategories(): Observable { 18 | return this.http.get(this.productsUrl) 19 | .pipe( 20 | tap(data => console.log(JSON.stringify(data))), 21 | catchError(this.handleError) 22 | ); 23 | } 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 | tags: ['rake', 'leaf', 'yard', 'home'], 14 | supplierIds: [1, 2] 15 | }, 16 | { 17 | id: 2, 18 | productName: 'Garden Cart', 19 | productCode: 'GDN-0023', 20 | description: '15 gallon capacity rolling garden cart', 21 | price: 32.99, 22 | categoryId: 1, 23 | supplierIds: [1, 3] 24 | }, 25 | { 26 | id: 5, 27 | productName: 'Hammer', 28 | productCode: 'TBX-0048', 29 | description: 'Curved claw steel hammer', 30 | price: 8.9, 31 | categoryId: 3, 32 | tags: ['tools', 'hammer', 'construction'], 33 | supplierIds: [3, 4] 34 | }, 35 | { 36 | id: 8, 37 | productName: 'Saw', 38 | productCode: 'TBX-0022', 39 | description: '15-inch steel blade hand saw', 40 | price: 11.55, 41 | categoryId: 3, 42 | supplierIds: [3, 4, 5] 43 | }, 44 | { 45 | id: 10, 46 | productName: 'Video Game Controller', 47 | productCode: 'GMG-0042', 48 | description: 'Standard two-button video game controller', 49 | price: 35.95, 50 | categoryId: 5, 51 | supplierIds: [3, 6] 52 | } 53 | ]; 54 | } 55 | -------------------------------------------------------------------------------- /APM/src/app/products/product-detail/product-detail.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Async-Data/7bf5620b1341c925e41404e3bd756a07d4cc2d8d/APM/src/app/products/product-detail/product-detail.component.css -------------------------------------------------------------------------------- /APM/src/app/products/product-detail/product-detail.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 | 6 |
8 | 9 |
10 | 11 |
12 |
13 |
Name:
14 |
{{product.productName}}
15 |
16 |
17 |
Code:
18 |
{{product.productCode}}
19 |
20 |
21 |
Description:
22 |
{{product.description}}
23 |
24 |
25 |
Price:
26 |
{{product.price|currency:"USD":"symbol"}}
27 |
28 |
29 |
Category:
30 |
{{product.categoryId}}
31 |
32 |
33 |
Tags:
34 |
{{product.tags}}
35 |
36 |
37 | 38 |
40 | 45 |
46 |
47 | 48 |
49 |
50 | 55 | 60 |
61 |
62 | 63 |
64 |
65 | 66 |
{{errorMessage}} 68 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-detail/product-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | 4 | import { Product, ProductResolved } from '../product'; 5 | 6 | @Component({ 7 | templateUrl: './product-detail.component.html', 8 | styleUrls: ['./product-detail.component.css'] 9 | }) 10 | export class ProductDetailComponent implements OnInit { 11 | pageTitle = 'Product Detail'; 12 | product: Product; 13 | errorMessage: string; 14 | 15 | constructor(private route: ActivatedRoute) { } 16 | 17 | ngOnInit(): void { 18 | // Long for without destructuring 19 | // const resolvedData: ProductResolved = this.route.snapshot.data['resolvedData']; 20 | // this.product = resolvedData.product; 21 | // this.errorMessage = resolvedData.error; 22 | 23 | // Use object destructuring to read the pieces of the resolved data. 24 | const {product, error} = this.route.snapshot.data['resolvedData']; 25 | this.product = product; 26 | this.errorMessage = error; 27 | 28 | // Display the appropriate page header 29 | if (this.product) { 30 | this.pageTitle = `Product Detail: ${this.product.productName}`; 31 | } else { 32 | this.pageTitle = 'No product found'; 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /APM/src/app/products/product-detail/product-resolver.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; 3 | 4 | import { Observable, of } from 'rxjs'; 5 | import { map, catchError } from 'rxjs/operators'; 6 | 7 | import { ProductResolved } from '../product'; 8 | import { ProductService } from '../product.service'; 9 | 10 | @Injectable({ 11 | providedIn: 'root' 12 | }) 13 | export class ProductResolver implements Resolve { 14 | 15 | constructor(private productService: ProductService) { } 16 | 17 | resolve(route: ActivatedRouteSnapshot, 18 | state: RouterStateSnapshot): Observable { 19 | const id = route.paramMap.get('id'); 20 | if (isNaN(+id)) { 21 | const message = `Product id was not a number: ${id}`; 22 | console.error(message); 23 | return of({ product: null, error: message }); 24 | } 25 | 26 | return this.productService.getProduct(+id) 27 | .pipe( 28 | map(product => ({ product: product })), 29 | catchError(error => { 30 | const message = `Retrieval error: ${error}`; 31 | console.error(message); 32 | return of({ product: null, error: message }); 33 | }) 34 | ); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /APM/src/app/products/product-edit/product-edit.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 | 6 |
8 |
11 | 12 |
13 | 15 |
16 | 24 | 25 | 26 | Please enter the product name. 27 | 28 | 29 | The product name must be at least 3 characters long. 30 | 31 | 32 | The product name cannot exceed 50 characters. 33 | 34 | 35 |
36 |
37 | 38 |
39 | 41 |
42 | 50 | 51 | 52 | Please enter the product code. 53 | 54 | 55 |
56 |
57 | 58 |
59 | 61 | 62 |
63 | 68 |
69 |
70 | 71 |
72 | 74 |
75 | 89 | 90 | 91 | A category must be selected. 92 | 93 | 94 |
95 |
96 | 97 |
98 |
99 | 106 | 113 | 120 |
121 |
122 |
123 |
124 | 125 |
{{errorMessage}} 127 |
128 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-edit/product-edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; 3 | import { ActivatedRoute, Router } from '@angular/router'; 4 | 5 | import { Product } from '.././product'; 6 | import { ProductService } from '.././product.service'; 7 | import { ProductCategory } from '../../product-categories/product-category'; 8 | import { ProductCategoryService } from '../../product-categories/product-category.service'; 9 | import { forkJoin } from 'rxjs'; 10 | 11 | @Component({ 12 | templateUrl: './product-edit.component.html' 13 | }) 14 | export class ProductEditComponent implements OnInit { 15 | pageTitle = 'Product Edit'; 16 | productForm: FormGroup; 17 | product: Product; 18 | categories: ProductCategory[]; 19 | errorMessage: string; 20 | 21 | constructor(private fb: FormBuilder, 22 | private route: ActivatedRoute, 23 | private router: Router, 24 | private productService: ProductService, 25 | private productCategoryService: ProductCategoryService) { 26 | } 27 | 28 | ngOnInit(): void { 29 | // Read the parameter from the route 30 | const id = +this.route.snapshot.paramMap.get('id'); 31 | const product$ = this.productService.getProduct(id); 32 | const categories$ = this.productCategoryService.getCategories(); 33 | 34 | // get the product and product category data in parallel 35 | forkJoin([product$, categories$]).subscribe({ 36 | next: ([product, categories]) => { 37 | this.product = product; 38 | this.categories = categories; 39 | this.displayProduct(); 40 | }, 41 | error: err => this.errorMessage = err 42 | }); 43 | } 44 | 45 | displayProduct(): void { 46 | if (this.product) { 47 | // Define the form 48 | this.productForm = this.fb.group({ 49 | productName: [this.product.productName, [Validators.required, Validators.minLength(3), Validators.maxLength(50)]], 50 | productCode: [this.product.productCode, Validators.required], 51 | description: this.product.description, 52 | categoryId: this.product.categoryId 53 | }); 54 | 55 | // Set tje appropriate page title 56 | if (this.product.id === 0) { 57 | this.pageTitle = 'Add Product'; 58 | } else { 59 | this.pageTitle = `Edit Product: ${this.product.productName}`; 60 | } 61 | } else { 62 | this.pageTitle = 'Product not found'; 63 | } 64 | } 65 | 66 | deleteProduct(): void { 67 | if (this.product.id === 0) { 68 | // Don't delete, it was never saved. 69 | this.onSaveComplete(); 70 | } else { 71 | if (confirm(`Really delete the product: ${this.product.productName}?`)) { 72 | this.productService.deleteProduct(this.product.id) 73 | .subscribe({ 74 | next: () => this.onSaveComplete(), 75 | error: err => this.errorMessage = err 76 | }); 77 | } 78 | } 79 | } 80 | 81 | saveProduct(): void { 82 | if (this.productForm.valid) { 83 | if (this.productForm.dirty) { 84 | const p = { ...this.product, ...this.productForm.value }; 85 | 86 | if (p.id === 0) { 87 | this.productService.createProduct(p) 88 | .subscribe({ 89 | next: () => this.onSaveComplete(), 90 | error: err => this.errorMessage = err 91 | }); 92 | } else { 93 | this.productService.updateProduct(p) 94 | .subscribe({ 95 | next: () => this.onSaveComplete(), 96 | error: err => this.errorMessage = err 97 | }); 98 | } 99 | } else { 100 | this.onSaveComplete(); 101 | } 102 | } else { 103 | this.errorMessage = 'Please correct the validation errors.'; 104 | } 105 | } 106 | 107 | onSaveComplete(): void { 108 | // Reset the form to clear the flags 109 | this.productForm.reset(); 110 | this.router.navigate(['/products']); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /APM/src/app/products/product-edit/product-edit.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; 3 | 4 | import { Observable } from 'rxjs'; 5 | 6 | import { ProductEditComponent } from './product-edit.component'; 7 | 8 | @Injectable({ 9 | providedIn: 'root' 10 | }) 11 | export class ProductEditGuard implements CanDeactivate { 12 | 13 | canDeactivate(component: ProductEditComponent, 14 | currentRoute: ActivatedRouteSnapshot, 15 | currentState: RouterStateSnapshot, 16 | nextState?: RouterStateSnapshot): boolean | Observable | Promise { 17 | 18 | if (component.productForm.dirty) { 19 | const productName = component.productForm.get('productName').value || 'New Product'; 20 | return confirm(`Navigate away and lose all changes to ${productName}?`); 21 | } 22 | return true; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list-asyncPipe.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 | 6 |
7 |
8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 33 | 34 | 35 |
ProductCodePrice
21 | 22 | {{ product.productName }} 23 | 24 | {{ product.productCode }}{{ product.price | currency:"USD":"symbol":"1.2-2" }} 28 | 32 |
36 |
37 | 38 |
39 |
40 | 41 |
43 | Error: {{ error }} 44 |
45 |
47 | Error: {{ errorMessage }} 48 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list-asyncPipe.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { Product } from '../product'; 4 | import { ProductService } from '../product.service'; 5 | 6 | import { Observable, Subject, of } from 'rxjs'; 7 | import { catchError } from 'rxjs/operators'; 8 | 9 | @Component({ 10 | templateUrl: './product-list-asyncPipe.component.html', 11 | styleUrls: ['./product-list.component.css'] 12 | }) 13 | export class ProductListAsyncPipeComponent implements OnInit { 14 | pageTitle = 'Product List'; 15 | products$: Observable; 16 | 17 | /* Use *either* error$ or errorMessage, not both */ 18 | error$ = new Subject(); 19 | errorMessage = ''; 20 | 21 | constructor(private productService: ProductService) { } 22 | 23 | ngOnInit(): void { 24 | this.products$ = this.productService.getProducts() 25 | .pipe( 26 | catchError(error => { 27 | /* Use *either* error$ or errorMessage, not both */ 28 | this.error$.next(error); 29 | // this.errorMessage = error; 30 | return of(null); 31 | }) 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list-category.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 | 6 |
7 |
8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 26 | 27 | 28 | 29 | 35 | 36 | 37 |
ProductCodeCategoryPrice
22 | 23 | {{ product.productName }} 24 | 25 | {{ product.productCode }}{{ product.categoryName }}{{ product.price | currency:"USD":"symbol":"1.2-2" }} 30 | 34 |
38 |
39 | 40 |
41 |
42 | 46 |
47 |
48 |
49 |
50 | 51 |
53 | Error: {{ errorMessage }} 54 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list-category.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { Product } from '../product'; 4 | import { ProductService } from '../product.service'; 5 | import { forkJoin } from 'rxjs'; 6 | import { ProductCategoryService } from '../../product-categories/product-category.service'; 7 | import { map } from 'rxjs/operators'; 8 | 9 | @Component({ 10 | templateUrl: './product-list-category.component.html' 11 | }) 12 | export class ProductListCategoryComponent implements OnInit { 13 | pageTitle = 'Product List'; 14 | errorMessage = ''; 15 | products: Product[]; 16 | 17 | constructor(private productService: ProductService, 18 | private productCategoryService: ProductCategoryService) { } 19 | 20 | ngOnInit(): void { 21 | // Get the product and product category data in parallel 22 | // Map the category Id to the category name 23 | // [products, categories] uses destructuring to unpack the values from the arrays 24 | const products$ = this.productService.getProducts(); 25 | const categories$ = this.productCategoryService.getCategories(); 26 | forkJoin([products$, categories$]).pipe( 27 | map(([products, categories]) => 28 | products.map(p => Object.assign({}, p, { categoryName: categories.find(c => p.categoryId === c.id).name })) 29 | ) 30 | ).subscribe({ 31 | next: result => { 32 | this.products = result; 33 | }, 34 | error: err => this.errorMessage = err 35 | }); 36 | 37 | // Without destructuring 38 | // It's not as clear what data[0] and data[1] are 39 | // forkJoin([products$, categories$]).pipe( 40 | // map((data) => 41 | // data[0].map(p => Object.assign({}, p, { categoryName: data[1].find(c => p.categoryId === c.id).name })) 42 | // ) 43 | // ).subscribe({ 44 | // next: result => { 45 | // this.products = result; 46 | // }, 47 | // error: err => this.errorMessage = err 48 | // }); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list-one.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 | 6 |
7 |
8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
ProductCodePrice
{{ product.productName }}{{ product.productCode }}{{ product.price | currency:"USD":"symbol":"1.2-2" }}
25 |
26 | 27 |
28 |
29 | 33 |
34 |
35 |
36 |
37 | 38 |
40 | Error: {{ errorMessage }} 41 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list-one.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { Product } from '../product'; 4 | import { ProductService } from '../product.service'; 5 | import { switchMap } from 'rxjs/operators'; 6 | import { Subject, Subscription } from 'rxjs'; 7 | 8 | @Component({ 9 | templateUrl: './product-list-one.component.html' 10 | }) 11 | export class ProductListOneAtATimeComponent implements OnInit { 12 | pageTitle = 'Product List'; 13 | errorMessage = ''; 14 | productIds = [1, 2, 5, 8, 10]; 15 | product: Product; 16 | currentIndex: number; 17 | 18 | constructor(private productService: ProductService) { } 19 | 20 | // Common Pattern for Retrieving Data 21 | // But pressing Next in quick succession processes unnecessary get requests. 22 | // ngOnInit(): void { 23 | // this.currentIndex = 0; 24 | // this.retrieveProduct(); 25 | // } 26 | 27 | // onNext(): void { 28 | // this.currentIndex += 1; 29 | // if (this.currentIndex >= this.productIds.length) { 30 | // this.currentIndex = 0; 31 | // } 32 | // this.retrieveProduct(); 33 | // } 34 | 35 | // retrieveProduct(): void { 36 | // this.productService.getProduct(this.productIds[this.currentIndex]).subscribe({ 37 | // next: product => this.product = product, 38 | // error: err => this.errorMessage = err 39 | // }); 40 | // } 41 | 42 | // Unsubscribe to stop processing of prior request 43 | private sub: Subscription; 44 | ngOnInit(): void { 45 | this.currentIndex = 0; 46 | this.retrieveProduct(); 47 | } 48 | 49 | onNext(): void { 50 | this.sub.unsubscribe(); 51 | this.currentIndex += 1; 52 | if (this.currentIndex >= this.productIds.length) { 53 | this.currentIndex = 0; 54 | } 55 | this.retrieveProduct(); 56 | } 57 | 58 | retrieveProduct(): void { 59 | this.sub = this.productService.getProduct(this.productIds[this.currentIndex]).subscribe({ 60 | next: product => this.product = product, 61 | error: err => this.errorMessage = err 62 | }); 63 | } 64 | 65 | // Cancels processing of prior request with switchMap 66 | // private product$: Subject; 67 | // ngOnInit(): void { 68 | // this.currentIndex = 0; 69 | 70 | // // Create a Subject 71 | // this.product$ = new Subject(); 72 | 73 | // // Define the switchMap 74 | // this.product$.pipe( 75 | // switchMap(() => 76 | // this.productService.getProduct(this.productIds[this.currentIndex]) 77 | // )).subscribe({ 78 | // next: product => { 79 | // this.product = product; 80 | // }, 81 | // error: err => this.errorMessage = err 82 | // }); 83 | 84 | // // Call Next to perform the first retrieve 85 | // this.product$.next(); 86 | // } 87 | 88 | // onNext(): void { 89 | // this.currentIndex += 1; 90 | // if (this.currentIndex >= this.productIds.length) { 91 | // this.currentIndex = 0; 92 | // } 93 | // // On each click, switch to the next item 94 | // this.product$.next(); 95 | // } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /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 |
7 |
8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 26 | 27 | 28 | 34 | 40 | 41 | 42 |
ProductCodePrice
22 | 23 | {{ product.productName }} 24 | 25 | {{ product.productCode }}{{ product.price | currency:"USD":"symbol":"1.2-2" }} 29 | 33 | 35 | 39 |
43 |
44 | 45 |
46 |
47 | 51 |
52 |
53 |
54 |
55 | 56 |
58 | Error: {{ errorMessage }} 59 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-list/product-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | 3 | import { Product } from '../product'; 4 | import { ProductService } from '../product.service'; 5 | import { Subscription } from 'rxjs'; 6 | 7 | @Component({ 8 | templateUrl: './product-list.component.html', 9 | styleUrls: ['./product-list.component.css'] 10 | }) 11 | export class ProductListComponent implements OnInit, OnDestroy { 12 | pageTitle = 'Product List'; 13 | errorMessage = ''; 14 | products: Product[]; 15 | private subscription: Subscription; 16 | 17 | constructor(private productService: ProductService) { } 18 | 19 | // Standard pattern 20 | // ngOnInit(): void { 21 | // this.productService.getProducts().subscribe({ 22 | // next: products => { 23 | // this.products = products; 24 | // console.log(this.products); 25 | // }, 26 | // error: err => this.errorMessage = err 27 | // }); 28 | // // This logs "undefined" 29 | // console.log(this.products); 30 | // } 31 | 32 | // Be sure to unsubscribe 33 | // Prevents processing the data if the user navigates away 34 | ngOnInit(): void { 35 | this.subscription = this.productService.getProducts().subscribe({ 36 | next: products => { 37 | this.products = products; 38 | console.log(this.products); 39 | }, 40 | error: err => this.errorMessage = err 41 | }); 42 | // This logs "undefined" 43 | // console.log(this.products); 44 | } 45 | 46 | ngOnDestroy(): void { 47 | this.subscription.unsubscribe(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /APM/src/app/products/product-suppliers/product-suppliers.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 | 6 |
7 | 8 |
9 |
10 |
Name:
11 |
{{product.productName}}
12 |
13 |
14 |
Code:
15 |
{{product.productCode}}
16 |
17 |
18 |
Description:
19 |
{{product.description}}
20 |
21 |
22 |
Price:
23 |
{{product.price|currency:"USD":"symbol"}}
24 |
25 |
26 | 27 |
28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
SupplierCostMinimum Quantity
{{ supplier.name }} {{ supplier.cost | currency:"USD":"symbol":"1.2-2" }}{{ supplier.minQuantity }}
45 |
46 | 47 |
48 |
49 | 54 | 59 |
60 |
61 | 62 |
63 |
64 | 65 |
{{errorMessage}} 67 |
-------------------------------------------------------------------------------- /APM/src/app/products/product-suppliers/product-suppliers.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | 4 | import { Product } from '../product'; 5 | import { ProductService } from '../product.service'; 6 | import { Supplier } from '../../suppliers/supplier'; 7 | import { SupplierService } from '../../suppliers/supplier.service'; 8 | 9 | import { mergeMap, tap, map, switchMap } from 'rxjs/operators'; 10 | import { forkJoin } from 'rxjs'; 11 | 12 | @Component({ 13 | templateUrl: './product-suppliers.component.html' 14 | }) 15 | export class ProductSuppliersComponent implements OnInit { 16 | pageTitle = 'Product Suppliers'; 17 | product: Product; 18 | suppliers: Supplier[] = []; 19 | errorMessage: string; 20 | 21 | constructor(private route: ActivatedRoute, 22 | private productService: ProductService, 23 | private supplierService: SupplierService) { } 24 | 25 | ngOnInit(): void { 26 | // Read the parameter from the route 27 | const id = +this.route.snapshot.paramMap.get('id'); 28 | 29 | // AntiPattern: Nested subscriptions 30 | // Get the product 31 | // For each supplier, get the supplier and add it to the array 32 | this.productService.getProduct(id).subscribe({ 33 | next: product => { 34 | this.product = product; 35 | this.displayProduct(product); 36 | product.supplierIds.map(supplierId => { 37 | this.supplierService.getSupplier(supplierId).subscribe({ 38 | next: suppliers => this.suppliers.push(suppliers), 39 | error: err => this.errorMessage = err 40 | }); 41 | }); 42 | }, 43 | error: err => this.errorMessage = err 44 | }); 45 | 46 | // Displays each type of data without waiting 47 | // this.productService.getProduct(id).pipe( 48 | // tap(product => this.product = product), 49 | // mergeMap(product => this.productService.getProductSuppliers(id)) 50 | // ).subscribe({ 51 | // next: suppliers => this.suppliers = suppliers, 52 | // error: err => this.errorMessage = err 53 | // }); 54 | 55 | // Displays each type of data without waiting 56 | // this.productService.getProduct(id).pipe( 57 | // tap(product => this.product = product), 58 | // mergeMap(() => this.productService.getProductSuppliersOneByOne(id)) 59 | // ).subscribe({ 60 | // next: supplier => this.suppliers.push(supplier), 61 | // error: err => this.errorMessage = err 62 | // }); 63 | 64 | // From BL 65 | // this.productService.getProduct(id).pipe( 66 | // tap(product => { 67 | // this.product = product; 68 | // this.displayProduct(product); 69 | // }), 70 | // mergeMap(() => this.supplierService.getSupplier(id)) 71 | // ).subscribe({ 72 | // next: supplier => { this.suppliers.push(supplier); }, 73 | // error: err => { this.errorMessage = err; }, 74 | // }); 75 | 76 | // Waits for all of the data before displaying any 77 | // const product$ = this.productService.getProduct(id); 78 | // const suppliers$ = this.productService.getProductSuppliers(id); 79 | // forkJoin([product$, suppliers$]) 80 | // .subscribe({ 81 | // next: ([product, suppliers]) => { 82 | // this.product = product; 83 | // this.suppliers = suppliers; 84 | // } 85 | // }); 86 | 87 | } 88 | 89 | displayProduct(product: Product): void { 90 | // Display the appropriate heading 91 | if (product) { 92 | this.pageTitle = `Product Suppliers for: ${product.productName}`; 93 | } else { 94 | this.pageTitle = 'No product found'; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /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 { ProductListAsyncPipeComponent } from './product-list/product-list-asyncPipe.component'; 7 | import { ProductDetailComponent } from './product-detail/product-detail.component'; 8 | import { ProductEditComponent } from './product-edit/product-edit.component'; 9 | import { ProductListCategoryComponent } from './product-list/product-list-category.component'; 10 | import { ProductSuppliersComponent } from './product-suppliers/product-suppliers.component'; 11 | 12 | import { ProductResolver } from './product-detail/product-resolver.service'; 13 | import { ProductEditGuard } from './product-edit/product-edit.guard'; 14 | import { ProductListOneAtATimeComponent } from './product-list/product-list-one.component'; 15 | 16 | import { SharedModule } from '../shared/shared.module'; 17 | 18 | @NgModule({ 19 | imports: [ 20 | SharedModule, 21 | ReactiveFormsModule, 22 | RouterModule.forChild([ 23 | { 24 | path: '', 25 | component: ProductListComponent 26 | }, 27 | { 28 | path: 'asyncPipe', 29 | component: ProductListAsyncPipeComponent 30 | }, 31 | { 32 | path: 'category', 33 | component: ProductListCategoryComponent 34 | }, 35 | { 36 | path: 'oneAtATime', 37 | component: ProductListOneAtATimeComponent 38 | }, 39 | { 40 | path: ':id', 41 | component: ProductDetailComponent, 42 | resolve: { resolvedData: ProductResolver } 43 | }, 44 | { 45 | path: ':id/suppliers', 46 | component: ProductSuppliersComponent 47 | }, 48 | { 49 | path: ':id/edit', 50 | component: ProductEditComponent, 51 | canDeactivate: [ProductEditGuard] 52 | } 53 | ]) 54 | ], 55 | declarations: [ 56 | ProductListComponent, 57 | ProductListAsyncPipeComponent, 58 | ProductListCategoryComponent, 59 | ProductListOneAtATimeComponent, 60 | ProductDetailComponent, 61 | ProductSuppliersComponent, 62 | ProductEditComponent 63 | ] 64 | }) 65 | export class ProductModule { } 66 | -------------------------------------------------------------------------------- /APM/src/app/products/product.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 3 | 4 | import { Observable, of, throwError, Subject, forkJoin, from } from 'rxjs'; 5 | import { catchError, tap, map, concatMap, mergeMap, first, take, concatAll, mergeAll, toArray, switchMap } from 'rxjs/operators'; 6 | 7 | import { Product } from './product'; 8 | import { Supplier } from '../suppliers/supplier'; 9 | 10 | @Injectable({ 11 | providedIn: 'root' 12 | }) 13 | export class ProductService { 14 | private productsUrl = 'api/products'; 15 | private suppliersUrl = 'api/suppliers'; 16 | 17 | constructor(private http: HttpClient) { } 18 | 19 | getProducts(): Observable { 20 | return this.http.get(this.productsUrl) 21 | .pipe( 22 | tap(data => console.log(JSON.stringify(data))), 23 | catchError(this.handleError) 24 | ); 25 | } 26 | 27 | // Gets a single product by id 28 | getProduct(id: number): Observable { 29 | if (id === 0) { 30 | return of(this.initializeProduct()); 31 | } 32 | const url = `${this.productsUrl}/${id}`; 33 | return this.http.get(url) 34 | .pipe( 35 | tap(data => console.log('getProduct: ' + JSON.stringify(data))), 36 | catchError(this.handleError) 37 | ); 38 | } 39 | 40 | // AntiPattern: Nested (or chained) http calls results in nested observables 41 | // that are difficult to process 42 | // First, get the product 43 | // For each supplier for that product, get the supplier info 44 | // getProductSuppliers(id: number) { 45 | // const productUrl = `${this.productsUrl}/${id}`; 46 | // return this.http.get(productUrl) 47 | // .pipe( 48 | // map(product => 49 | // product.supplierIds.map(supplierId => { 50 | // const supplierUrl = `${this.suppliersUrl}/${supplierId}`; 51 | // return this.http.get(supplierUrl); 52 | // }) 53 | // ), 54 | // catchError(this.handleError) 55 | // ); 56 | // } 57 | 58 | // Gets the first supplier. 59 | // getProductSuppliers(id: number): Observable { 60 | // const productUrl = `${this.productsUrl}/${id}`; 61 | // return this.http.get(productUrl) 62 | // .pipe( 63 | // tap(x => console.log(x)), 64 | // mergeMap(product => { 65 | // const supplierUrl = `${this.suppliersUrl}/${product.supplierIds[0]}`; 66 | // return this.http.get(supplierUrl); 67 | // } 68 | // ), 69 | // catchError(this.handleError) 70 | // ); 71 | // } 72 | 73 | // Gets all suppliers for a product using mergeMap and concatAll. 74 | // But this returns one supplier at a time. 75 | // getProductSuppliers(id: number): Observable { 76 | // const productUrl = `${this.productsUrl}/${id}`; 77 | // return this.http.get(productUrl) 78 | // .pipe( 79 | // mergeMap(product => 80 | // product.supplierIds.map(supplierId => { 81 | // const supplierUrl = `${this.suppliersUrl}/${supplierId}`; 82 | // return this.http.get(supplierUrl); 83 | // }) 84 | // ), 85 | // concatAll(), 86 | // catchError(this.handleError) 87 | // ); 88 | // } 89 | 90 | // Gets all suppliers for a product as an array. 91 | getProductSuppliers(id: number): Observable { 92 | const productUrl = `${this.productsUrl}/${id}`; 93 | return this.http.get(productUrl) 94 | .pipe( 95 | mergeMap(product => 96 | from(product.supplierIds).pipe( 97 | mergeMap(supplierId => { 98 | const supplierUrl = `${this.suppliersUrl}/${supplierId}`; 99 | return this.http.get(supplierUrl); 100 | }) 101 | )), 102 | toArray(), 103 | catchError(this.handleError) 104 | ); 105 | } 106 | 107 | // Gets all suppliers for a product one by one. 108 | // If the second mergeMap is changed to switchMap, only one value is displayed. 109 | getProductSuppliersOneByOne(id: number): Observable { 110 | const productUrl = `${this.productsUrl}/${id}`; 111 | return this.http.get(productUrl) 112 | .pipe( 113 | mergeMap(product => 114 | from(product.supplierIds).pipe( 115 | mergeMap(supplierId => { 116 | const supplierUrl = `${this.suppliersUrl}/${supplierId}`; 117 | return this.http.get(supplierUrl); 118 | }) 119 | )), 120 | catchError(this.handleError) 121 | ); 122 | } 123 | 124 | // Pass out both using concat?? 125 | 126 | createProduct(product: Product): Observable { 127 | const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); 128 | product.id = null; 129 | return this.http.post(this.productsUrl, product, { headers }) 130 | .pipe( 131 | tap(data => console.log('createProduct: ' + JSON.stringify(data))), 132 | catchError(this.handleError) 133 | ); 134 | } 135 | 136 | deleteProduct(id: number): Observable<{}> { 137 | const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); 138 | const url = `${this.productsUrl}/${id}`; 139 | return this.http.delete(url, { headers }) 140 | .pipe( 141 | tap(data => console.log('deleteProduct: ' + id)), 142 | catchError(this.handleError) 143 | ); 144 | } 145 | 146 | updateProduct(product: Product): Observable { 147 | const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); 148 | const url = `${this.productsUrl}/${product.id}`; 149 | return this.http.put(url, product, { headers }) 150 | .pipe( 151 | tap(() => console.log('updateProduct: ' + product.id)), 152 | // Return the product on an update 153 | map(() => product), 154 | catchError(this.handleError) 155 | ); 156 | } 157 | 158 | private handleError(err) { 159 | // in a real world app, we may send the server to some remote logging infrastructure 160 | // instead of just logging it to the console 161 | let errorMessage: string; 162 | if (err.error instanceof ErrorEvent) { 163 | // A client-side or network error occurred. Handle it accordingly. 164 | errorMessage = `An error occurred: ${err.error.message}`; 165 | } else { 166 | // The backend returned an unsuccessful response code. 167 | // The response body may contain clues as to what went wrong, 168 | errorMessage = `Backend returned code ${err.status}: ${err.body.error}`; 169 | } 170 | console.error(err); 171 | return throwError(errorMessage); 172 | } 173 | 174 | private initializeProduct(): Product { 175 | // Return an initialized object 176 | return { 177 | id: 0, 178 | productName: null, 179 | productCode: null, 180 | categoryId: null, 181 | tags: [], 182 | price: null, 183 | description: null 184 | }; 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /APM/src/app/products/product.ts: -------------------------------------------------------------------------------- 1 | /* Defines the product entity */ 2 | export interface Product { 3 | id: number; 4 | productName: string; 5 | productCode: string; 6 | categoryId: number; 7 | categoryName?: string; 8 | tags?: string[]; 9 | price: number; 10 | description: string; 11 | supplierIds?: number[]; 12 | } 13 | 14 | export interface ProductResolved { 15 | product: Product; 16 | error?: any; 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 | id: 3, 20 | name: 'Acme General Supply', 21 | cost: 25, 22 | minQuantity: 2 23 | }, 24 | { 25 | id: 4, 26 | name: 'Acme Tool Supply', 27 | cost: 4, 28 | minQuantity: 12 29 | }, 30 | { 31 | id: 5, 32 | name: 'Tools Are Us', 33 | cost: 8, 34 | minQuantity: 8 35 | }, 36 | { 37 | id: 6, 38 | name: 'Acme Game Supply', 39 | cost: 20, 40 | minQuantity: 6 41 | } 42 | ]; 43 | } 44 | -------------------------------------------------------------------------------- /APM/src/app/suppliers/supplier.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | import { Observable, throwError } 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 | getSuppliers(): Observable { 18 | return this.http.get(this.suppliersUrl) 19 | .pipe( 20 | tap(data => console.log(JSON.stringify(data))), 21 | catchError(this.handleError) 22 | ); 23 | } 24 | 25 | // Gets a single supplier by id 26 | getSupplier(id: number): Observable { 27 | const url = `${this.suppliersUrl}/${id}`; 28 | return this.http.get(url) 29 | .pipe( 30 | tap(data => console.log('getSupplier: ' + JSON.stringify(data))), 31 | catchError(this.handleError) 32 | ); 33 | } 34 | 35 | // To get the suppliers for a product 36 | // Given the product name 37 | // Gets the product to obtain the Id 38 | // The query returns an array, so maps to the first product in the array 39 | // Uses the id to get the suppliers 40 | // Only returns the suppliers (not the product) 41 | // getSuppliersForProductByName(productName: string): Observable { 42 | // const productUrl = `${this.productsUrl}?productName=^${productName}$`; 43 | // return this.http.get(productUrl) 44 | // .pipe( 45 | // map(products => products[0]), 46 | // mergeMap(product => { 47 | // const supplierUrl = `${this.suppliersUrl}?productId=^${product.id}$`; 48 | // return this.http.get(supplierUrl); 49 | // }), 50 | // tap(data => console.log(data)), 51 | // catchError(this.handleError) 52 | // ); 53 | // } 54 | 55 | private handleError(err) { 56 | // in a real world app, we may send the server to some remote logging infrastructure 57 | // instead of just logging it to the console 58 | let errorMessage: string; 59 | if (err.error instanceof ErrorEvent) { 60 | // A client-side or network error occurred. Handle it accordingly. 61 | errorMessage = `An error occurred: ${err.error.message}`; 62 | } else { 63 | // The backend returned an unsuccessful response code. 64 | // The response body may contain clues as to what went wrong, 65 | errorMessage = `Backend returned code ${err.status}: ${err.body.error}`; 66 | } 67 | console.error(err); 68 | return throwError(errorMessage); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /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-Async-Data/7bf5620b1341c925e41404e3bd756a07d4cc2d8d/APM/src/assets/.gitkeep -------------------------------------------------------------------------------- /APM/src/assets/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Async-Data/7bf5620b1341c925e41404e3bd756a07d4cc2d8d/APM/src/assets/images/logo.jpg -------------------------------------------------------------------------------- /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-Async-Data/7bf5620b1341c925e41404e3bd756a07d4cc2d8d/APM/src/favicon.ico -------------------------------------------------------------------------------- /APM/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | APM 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /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 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /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/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.ts" 13 | ], 14 | "exclude": [ 15 | "src/test.ts", 16 | "src/**/*.spec.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /APM/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "fullTemplateTypeCheck": true, 24 | "strictInjectionParameters": true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /APM/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 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /APM/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warning" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "pm", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "pm", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 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-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-use-before-declare": true, 64 | "no-var-requires": false, 65 | "object-literal-key-quotes": [ 66 | true, 67 | "as-needed" 68 | ], 69 | "object-literal-sort-keys": false, 70 | "ordered-imports": false, 71 | "quotemark": [ 72 | true, 73 | "single" 74 | ], 75 | "trailing-comma": false, 76 | "no-conflicting-lifecycle": true, 77 | "no-host-metadata-property": true, 78 | "no-input-rename": true, 79 | "no-inputs-metadata-property": true, 80 | "no-output-native": true, 81 | "no-output-on-prefix": true, 82 | "no-output-rename": true, 83 | "no-outputs-metadata-property": true, 84 | "template-banana-in-box": true, 85 | "template-no-negated-async": true, 86 | "use-lifecycle-interface": true, 87 | "use-pipe-transform-interface": true 88 | }, 89 | "rulesDirectory": [ 90 | "codelyzer" 91 | ] 92 | } -------------------------------------------------------------------------------- /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-Async-Data 2 | Code for my talks on managing async data in Angular 3 | --------------------------------------------------------------------------------