├── .gitignore ├── APM-Final ├── .angular-cli.json ├── .editorconfig ├── .gitignore ├── .vscode │ └── settings.json ├── README.md ├── e2e │ ├── app.e2e-spec.ts │ ├── app.po.ts │ └── tsconfig.e2e.json ├── karma.conf.js ├── package.json ├── protractor.conf.js ├── src │ ├── api │ │ ├── customers │ │ │ └── customers.json │ │ └── products │ │ │ └── products.json │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── core │ │ │ ├── core.module.ts │ │ │ ├── data.service.ts │ │ │ └── message.service.ts │ │ ├── customers │ │ │ ├── customer-detail.component.css │ │ │ ├── customer-detail.component.html │ │ │ ├── customer-detail.component.ts │ │ │ ├── customer-list.component.css │ │ │ ├── customer-list.component.html │ │ │ ├── customer-list.component.ts │ │ │ ├── customer.module.ts │ │ │ ├── customer.service.ts │ │ │ └── customer.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 │ │ ├── messages │ │ │ ├── message.component.html │ │ │ ├── message.component.ts │ │ │ └── message.module.ts │ │ ├── products │ │ │ ├── product-detail.component.css │ │ │ ├── product-detail.component.html │ │ │ ├── product-detail.component.ts │ │ │ ├── product-list.component.css │ │ │ ├── product-list.component.html │ │ │ ├── product-list.component.ts │ │ │ ├── product.module.ts │ │ │ ├── product.service.ts │ │ │ └── product.ts │ │ ├── selective-strategy.service.ts │ │ ├── shared │ │ │ ├── convert-to-spaces.pipe.ts │ │ │ ├── shared.module.ts │ │ │ ├── star.component.css │ │ │ ├── star.component.html │ │ │ └── star.component.ts │ │ └── user │ │ │ ├── auth-guard.service.ts │ │ │ ├── auth.service.ts │ │ │ ├── login.component.css │ │ │ ├── login.component.html │ │ │ ├── login.component.ts │ │ │ ├── user.module.ts │ │ │ └── user.ts │ ├── assets │ │ └── 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.spec.json │ └── typings.d.ts ├── tsconfig.json └── tslint.json └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | typings 2 | **/app/**/*.js 3 | **/app/**/*.map 4 | **/*.log 5 | **/*.log/* 6 | node_modules 7 | jspm_packages 8 | bower_components 9 | 10 | .vs 11 | **/*.sou 12 | **/*.user 13 | bin 14 | obj 15 | packages 16 | -------------------------------------------------------------------------------- /APM-Final/.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "apm" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "api", 13 | "favicon.ico" 14 | ], 15 | "index": "index.html", 16 | "main": "main.ts", 17 | "polyfills": "polyfills.ts", 18 | "test": "test.ts", 19 | "tsconfig": "tsconfig.app.json", 20 | "testTsconfig": "tsconfig.spec.json", 21 | "prefix": "pm", 22 | "styles": [ 23 | "styles.css", 24 | "../node_modules/bootstrap/dist/css/bootstrap.css" 25 | ], 26 | "scripts": [], 27 | "environmentSource": "environments/environment.ts", 28 | "environments": { 29 | "dev": "environments/environment.ts", 30 | "prod": "environments/environment.prod.ts" 31 | } 32 | } 33 | ], 34 | "e2e": { 35 | "protractor": { 36 | "config": "./protractor.conf.js" 37 | } 38 | }, 39 | "lint": [ 40 | { 41 | "project": "src/tsconfig.app.json", 42 | "exclude": "**/node_modules/**" 43 | }, 44 | { 45 | "project": "src/tsconfig.spec.json", 46 | "exclude": "**/node_modules/**" 47 | }, 48 | { 49 | "project": "e2e/tsconfig.e2e.json", 50 | "exclude": "**/node_modules/**" 51 | } 52 | ], 53 | "test": { 54 | "karma": { 55 | "config": "./karma.conf.js" 56 | } 57 | }, 58 | "defaults": { 59 | "styleExt": "css", 60 | "component": {} 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /APM-Final/.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-Final/.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 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /APM-Final/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.autoSave": "afterDelay" 4 | } -------------------------------------------------------------------------------- /APM-Final/README.md: -------------------------------------------------------------------------------- 1 | # APM 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.2.4. 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|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 | Before running the tests make sure you are serving the app via `ng serve`. 25 | 26 | ## Further help 27 | 28 | 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). 29 | -------------------------------------------------------------------------------- /APM-Final/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { APMPage } from './app.po'; 2 | 3 | describe('apm App', () => { 4 | let page: APMPage; 5 | 6 | beforeEach(() => { 7 | page = new APMPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to Angular: Getting Started!!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /APM-Final/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class APMPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('pm-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /APM-Final/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /APM-Final/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 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/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | angularCli: { 23 | environment: 'dev' 24 | }, 25 | reporters: ['progress', 'kjhtml'], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ['Chrome'], 31 | singleRun: false 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /APM-Final/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apm", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve -o", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint --type-check", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^4.0.0", 16 | "@angular/common": "^4.0.0", 17 | "@angular/compiler": "^4.0.0", 18 | "@angular/core": "^4.0.0", 19 | "@angular/forms": "^4.0.0", 20 | "@angular/http": "^4.0.0", 21 | "@angular/platform-browser": "^4.0.0", 22 | "@angular/platform-browser-dynamic": "^4.0.0", 23 | "@angular/router": "^4.0.0", 24 | "bootstrap": "^3.3.7", 25 | "core-js": "^2.4.1", 26 | "rxjs": "^5.4.1", 27 | "zone.js": "^0.8.14" 28 | }, 29 | "devDependencies": { 30 | "@angular/cli": "1.2.4", 31 | "@angular/compiler-cli": "^4.0.0", 32 | "@angular/language-service": "^4.0.0", 33 | "@types/jasmine": "~2.5.53", 34 | "@types/jasminewd2": "~2.0.2", 35 | "@types/node": "~6.0.60", 36 | "codelyzer": "~3.0.1", 37 | "jasmine-core": "~2.6.2", 38 | "jasmine-spec-reporter": "~4.1.0", 39 | "karma": "~1.7.0", 40 | "karma-chrome-launcher": "~2.1.1", 41 | "karma-cli": "~1.0.1", 42 | "karma-coverage-istanbul-reporter": "^1.2.1", 43 | "karma-jasmine": "~1.1.0", 44 | "karma-jasmine-html-reporter": "^0.2.2", 45 | "protractor": "~5.1.2", 46 | "ts-node": "~3.0.4", 47 | "tslint": "~5.3.2", 48 | "typescript": "~2.3.3" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /APM-Final/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 | './e2e/**/*.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: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /APM-Final/src/api/customers/customers.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "firstName": "Jack", 5 | "lastName": "Harkness", 6 | "occupation": "Captain" 7 | }, 8 | { 9 | "id": 2, 10 | "firstName": "Portia", 11 | "lastName": "Lin", 12 | "occupation": "Captain" 13 | }, 14 | { 15 | "id": 5, 16 | "firstName": "Irena", 17 | "lastName": "Shaw", 18 | "occupation": "Scientist" 19 | }, 20 | { 21 | "id": 10, 22 | "firstName": "Marcus", 23 | "lastName": "Boone", 24 | "occupation": "Mercenary" 25 | }, 26 | { 27 | "id": 22, 28 | "firstName": "Gwen", 29 | "lastName": "Cooper", 30 | "occupation": "Constable" 31 | }, 32 | { 33 | "id": 25, 34 | "firstName": "Malcolm", 35 | "lastName": "Reynolds", 36 | "occupation": "Captain" 37 | } 38 | ] -------------------------------------------------------------------------------- /APM-Final/src/api/products/products.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "productName": "Leaf Rake", 5 | "productCode": "GDN-0011", 6 | "releaseDate": "March 19, 2016", 7 | "description": "Leaf rake with 48-inch wooden handle.", 8 | "price": 19.95, 9 | "starRating": 3.2, 10 | "imageUrl": "http://openclipart.org/image/300px/svg_to_png/26215/Anonymous_Leaf_Rake.png" 11 | }, 12 | { 13 | "id": 2, 14 | "productName": "Garden Cart", 15 | "productCode": "GDN-0023", 16 | "releaseDate": "March 18, 2016", 17 | "description": "15 gallon capacity rolling garden cart", 18 | "price": 32.99, 19 | "starRating": 4.2, 20 | "imageUrl": "http://openclipart.org/image/300px/svg_to_png/58471/garden_cart.png" 21 | }, 22 | { 23 | "id": 5, 24 | "productName": "Hammer", 25 | "productCode": "TBX-0048", 26 | "releaseDate": "May 21, 2016", 27 | "description": "Curved claw steel hammer", 28 | "price": 8.9, 29 | "starRating": 4.8, 30 | "imageUrl": "http://openclipart.org/image/300px/svg_to_png/73/rejon_Hammer.png" 31 | }, 32 | { 33 | "id": 8, 34 | "productName": "Saw", 35 | "productCode": "TBX-0022", 36 | "releaseDate": "May 15, 2016", 37 | "description": "15-inch steel blade hand saw", 38 | "price": 11.55, 39 | "starRating": 3.7, 40 | "imageUrl": "http://openclipart.org/image/300px/svg_to_png/27070/egore911_saw.png" 41 | }, 42 | { 43 | "id": 10, 44 | "productName": "Video Game Controller", 45 | "productCode": "GMG-0042", 46 | "releaseDate": "October 15, 2015", 47 | "description": "Standard two-button video game controller", 48 | "price": 35.95, 49 | "starRating": 4.6, 50 | "imageUrl": "http://openclipart.org/image/300px/svg_to_png/120337/xbox-controller_01.png" 51 | } 52 | ] -------------------------------------------------------------------------------- /APM-Final/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | 4 | import { AuthGuard } from './user/auth-guard.service'; 5 | import { SelectiveStrategy } from './selective-strategy.service'; 6 | 7 | import { ShellComponent } from './home/shell.component'; 8 | import { WelcomeComponent } from './home/welcome.component'; 9 | import { PageNotFoundComponent } from './home/page-not-found.component'; 10 | 11 | @NgModule({ 12 | imports: [ 13 | RouterModule.forRoot([ 14 | { 15 | path: '', 16 | component: ShellComponent, 17 | children: [ 18 | { path: 'welcome', component: WelcomeComponent }, 19 | { 20 | path: 'customers', 21 | canActivate: [AuthGuard], 22 | data: { preload: true }, 23 | loadChildren: 'app/customers/customer.module#CustomerModule' 24 | }, 25 | { 26 | path: 'products', 27 | canActivate: [AuthGuard], 28 | data: { preload: true }, 29 | loadChildren: 'app/products/product.module#ProductModule' 30 | }, 31 | { path: '', redirectTo: 'welcome', pathMatch: 'full' }, 32 | ] 33 | }, 34 | { path: '**', component: PageNotFoundComponent } 35 | ], { preloadingStrategy: SelectiveStrategy }) // , { enableTracing: true }) 36 | ], 37 | providers: [SelectiveStrategy], 38 | exports: [RouterModule] 39 | }) 40 | export class AppRoutingModule { } 41 | -------------------------------------------------------------------------------- /APM-Final/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Modules/f56925658869cdbec8a6bc7bb08a0a9f096d6b0d/APM-Final/src/app/app.component.css -------------------------------------------------------------------------------- /APM-Final/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /APM-Final/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | }).compileComponents(); 12 | })); 13 | 14 | it('should create the app', async(() => { 15 | const fixture = TestBed.createComponent(AppComponent); 16 | const app = fixture.debugElement.componentInstance; 17 | expect(app).toBeTruthy(); 18 | })); 19 | 20 | it(`should have as title 'Angular: Getting Started'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('Angular: Getting Started'); 24 | })); 25 | 26 | it('should render title in a h1 tag', async(() => { 27 | const fixture = TestBed.createComponent(AppComponent); 28 | fixture.detectChanges(); 29 | const compiled = fixture.debugElement.nativeElement; 30 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to Angular: Getting Started!!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /APM-Final/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'pm-root', 5 | templateUrl: './app.component.html' 6 | }) 7 | export class AppComponent { 8 | pageTitle: string = 'Acme Product Management'; 9 | } 10 | -------------------------------------------------------------------------------- /APM-Final/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | import { RouterModule } from '@angular/router'; 5 | 6 | import { AppComponent } from './app.component'; 7 | import { WelcomeComponent } from './home/welcome.component'; 8 | import { PageNotFoundComponent } from './home/page-not-found.component'; 9 | import { MenuComponent } from './home/menu.component'; 10 | 11 | import { AppRoutingModule } from './app-routing.module'; 12 | 13 | /* Feature Modules */ 14 | import { UserModule } from './user/user.module'; 15 | import { MessageModule } from './messages/message.module'; 16 | import { ShellComponent } from './home/shell.component'; 17 | import { CoreModule } from './core/core.module'; 18 | 19 | @NgModule({ 20 | declarations: [ 21 | AppComponent, 22 | WelcomeComponent, 23 | MenuComponent, 24 | PageNotFoundComponent, 25 | ShellComponent 26 | ], 27 | imports: [ 28 | BrowserModule, 29 | HttpClientModule, 30 | UserModule, 31 | MessageModule, 32 | AppRoutingModule, 33 | CoreModule 34 | ], 35 | bootstrap: [AppComponent] 36 | }) 37 | export class AppModule { } 38 | -------------------------------------------------------------------------------- /APM-Final/src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, ModuleWithProviders, Optional, SkipSelf } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { DataService } from './data.service'; 5 | import { MessageService } from './message.service'; 6 | 7 | @NgModule({ 8 | imports: [ 9 | CommonModule 10 | ], 11 | declarations: [], 12 | providers: [ 13 | DataService, 14 | MessageService 15 | ] 16 | }) 17 | export class CoreModule { 18 | 19 | // Prevent reimport of this module 20 | constructor (@Optional() @SkipSelf() currentModule: CoreModule) { 21 | if (currentModule) { 22 | throw new Error( 23 | 'CoreModule is already loaded. Add it to the Imports array of the AppModule only'); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /APM-Final/src/app/core/data.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpErrorResponse } from '@angular/common/http'; 3 | import { Observable } from 'rxjs/Observable'; 4 | import 'rxjs/add/observable/throw'; 5 | import 'rxjs/add/operator/catch'; 6 | import 'rxjs/add/operator/do'; 7 | import 'rxjs/add/operator/map'; 8 | 9 | @Injectable() 10 | export class DataService { 11 | 12 | constructor(private http: HttpClient) { } 13 | 14 | getItems(url: string): Observable { 15 | return this.http.get(url) 16 | .do(data => console.log('All: ' + JSON.stringify(data))) 17 | .catch(this.handleError); 18 | } 19 | 20 | getItem(url: string): Observable { 21 | return this.http.get(url) 22 | .do(data => console.log('All: ' + JSON.stringify(data))) 23 | .catch(this.handleError); 24 | } 25 | 26 | private handleError(err: HttpErrorResponse) { 27 | // in a real world app, we may send the server to some remote logging infrastructure 28 | // instead of just logging it to the console 29 | let errorMessage = ''; 30 | if (err.error instanceof Error) { 31 | // A client-side or network error occurred. Handle it accordingly. 32 | errorMessage = `An error occurred: ${err.error.message}`; 33 | } else { 34 | // The backend returned an unsuccessful response code. 35 | // The response body may contain clues as to what went wrong, 36 | errorMessage = `Server returned code: ${err.status}, error message is: ${err.message}`; 37 | } 38 | console.error(errorMessage); 39 | return Observable.throw(errorMessage); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /APM-Final/src/app/core/message.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | @Injectable() 4 | export class MessageService { 5 | private messages: string[] = []; 6 | displayMessages = false; 7 | 8 | constructor() { } 9 | 10 | addMessage(message: string): void { 11 | const currentDate = new Date(); 12 | this.messages.unshift(message + '\n at ' + currentDate.toLocaleString()); 13 | } 14 | 15 | getMessages(): string[] { 16 | return this.messages; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer-detail.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Modules/f56925658869cdbec8a6bc7bb08a0a9f096d6b0d/APM-Final/src/app/customers/customer-detail.component.css -------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer-detail.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle + ': ' + customer.firstName + ' ' + customer.lastName}} 4 |
5 | 6 |
7 |
8 |
First Name:
9 |
{{customer.firstName}}
10 |
11 |
12 |
Last Name:
13 |
{{customer.lastName}}
14 |
15 |
16 |
Occupation:
17 |
{{customer.occupation}}
18 |
19 |
20 | 21 | 26 |
-------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | 4 | import { ICustomer } from './customer'; 5 | import { CustomerService } from './customer.service'; 6 | 7 | @Component({ 8 | templateUrl: './customer-detail.component.html', 9 | styleUrls: ['./customer-detail.component.css'] 10 | }) 11 | export class CustomerDetailComponent implements OnInit { 12 | pageTitle: string = 'Customer Detail'; 13 | errorMessage: string; 14 | customer: ICustomer; 15 | 16 | constructor(private route: ActivatedRoute, 17 | private router: Router, 18 | private customerService: CustomerService) { 19 | } 20 | 21 | ngOnInit() { 22 | const id = +this.route.snapshot.paramMap.get('id'); 23 | this.getCustomer(id); 24 | } 25 | 26 | getCustomer(id: number) { 27 | this.customerService.getCustomer(id).subscribe( 28 | customer => this.customer = customer, 29 | error => this.errorMessage = error); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer-list.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Modules/f56925658869cdbec8a6bc7bb08a0a9f096d6b0d/APM-Final/src/app/customers/customer-list.component.css -------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 |
6 |
7 |
Filter by:
8 |
9 | 10 |
11 |
12 |
13 |
14 |

Filtered by: {{listFilter}}

15 |
16 |
17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 34 |
Full NameOccupation
28 | {{ customer.lastName }}, {{ customer.firstName}} 29 | 30 | {{ customer.occupation }}
35 |
36 |
37 |
38 |
39 | Error: {{ errorMessage }} 40 |
-------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { ICustomer } from './customer'; 4 | import { CustomerService } from './customer.service'; 5 | 6 | @Component({ 7 | templateUrl: './customer-list.component.html', 8 | styleUrls: ['./customer-list.component.css'] 9 | }) 10 | export class CustomerListComponent implements OnInit { 11 | pageTitle: string = 'Customer List'; 12 | errorMessage: string; 13 | 14 | private _listFilter: string; 15 | get listFilter(): string { 16 | return this._listFilter; 17 | } 18 | set listFilter(value: string) { 19 | this._listFilter = value; 20 | this.filteredCustomers = this.listFilter ? this.performFilter(this.listFilter) : this.customers; 21 | } 22 | 23 | filteredCustomers: ICustomer[]; 24 | customers: ICustomer[] = []; 25 | 26 | constructor(private customerService: CustomerService) { 27 | 28 | } 29 | 30 | performFilter(filterBy: string): ICustomer[] { 31 | filterBy = filterBy.toLocaleLowerCase(); 32 | return this.customers.filter((customer: ICustomer) => 33 | customer.lastName.toLocaleLowerCase().indexOf(filterBy) !== -1 || 34 | customer.firstName.toLocaleLowerCase().indexOf(filterBy) !== -1 ); 35 | } 36 | 37 | ngOnInit(): void { 38 | this.customerService.getCustomers() 39 | .subscribe(customers => { 40 | this.customers = customers; 41 | this.filteredCustomers = this.customers; 42 | }, 43 | error => this.errorMessage = error); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | 4 | import { SharedModule } from './../shared/shared.module'; 5 | 6 | import { CustomerListComponent } from './customer-list.component'; 7 | import { CustomerDetailComponent } from './customer-detail.component'; 8 | 9 | import { CustomerService } from './customer.service'; 10 | 11 | @NgModule({ 12 | imports: [ 13 | SharedModule, 14 | RouterModule.forChild([ 15 | { path: '', component: CustomerListComponent }, 16 | { path: ':id', component: CustomerDetailComponent } 17 | ]) 18 | ], 19 | declarations: [ 20 | CustomerListComponent, 21 | CustomerDetailComponent 22 | ], 23 | providers: [ 24 | CustomerService 25 | ] 26 | }) 27 | export class CustomerModule { } 28 | -------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Observable } from 'rxjs/Observable'; 3 | 4 | import { ICustomer } from './customer'; 5 | import { DataService } from '../core/data.service'; 6 | import { MessageService } from '../core/message.service'; 7 | 8 | @Injectable() 9 | export class CustomerService { 10 | private customerUrl = './api/customers/customers.json'; 11 | 12 | constructor(private dataService: DataService, 13 | private messageService: MessageService) { } 14 | 15 | getCustomers(): Observable { 16 | return this.dataService.getItems(this.customerUrl); 17 | } 18 | 19 | getCustomer(id: number): Observable { 20 | // return this.dataService.getItem(this.customerUrl); 21 | return this.dataService.getItems(this.customerUrl) 22 | .map(data => data.find(d => d.id === id)) 23 | .do(c => this.messageService.addMessage(`Viewed customer: ${c.lastName}, ${c.firstName}`)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /APM-Final/src/app/customers/customer.ts: -------------------------------------------------------------------------------- 1 | export interface ICustomer { 2 | id: number; 3 | firstName: string; 4 | lastName: string; 5 | occupation: string; 6 | } 7 | -------------------------------------------------------------------------------- /APM-Final/src/app/home/menu.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /APM-Final/src/app/home/menu.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | 4 | import { AuthService } from '../user/auth.service'; 5 | import { MessageService } from '../core/message.service'; 6 | 7 | @Component({ 8 | selector: 'pm-menu', 9 | templateUrl: './menu.component.html' 10 | }) 11 | export class MenuComponent implements OnInit { 12 | get displayMessages(): boolean { 13 | return this.messageService.displayMessages; 14 | } 15 | 16 | constructor(private router: Router, 17 | private authService: AuthService, 18 | private messageService: MessageService) { } 19 | 20 | ngOnInit() { 21 | } 22 | 23 | showMessages(): void { 24 | this.messageService.displayMessages = true; 25 | } 26 | 27 | hideMessages(): void { 28 | this.messageService.displayMessages = false; 29 | } 30 | 31 | logOut(): void { 32 | this.authService.logout(); 33 | this.router.navigate(['/welcome']); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /APM-Final/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-Final/src/app/home/shell.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Modules/f56925658869cdbec8a6bc7bb08a0a9f096d6b0d/APM-Final/src/app/home/shell.component.css -------------------------------------------------------------------------------- /APM-Final/src/app/home/shell.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | 6 |
7 |
8 |
9 | 10 |
11 |
12 | 13 |
14 |
15 |
-------------------------------------------------------------------------------- /APM-Final/src/app/home/shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { MessageService } from '../core/message.service'; 3 | 4 | @Component({ 5 | selector: 'pm-shell', 6 | templateUrl: './shell.component.html', 7 | styleUrls: ['./shell.component.css'] 8 | }) 9 | export class ShellComponent implements OnInit { 10 | get displayMessages(): boolean { 11 | return this.messageService.displayMessages; 12 | } 13 | 14 | constructor(private messageService: MessageService) { } 15 | 16 | ngOnInit() { 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /APM-Final/src/app/home/welcome.component.html: -------------------------------------------------------------------------------- 1 | 
2 |
3 | {{pageTitle}} 4 |
5 |
6 |
7 | 10 |
11 |
12 |
Developed by:
13 |

Deborah Kurata

14 | 15 |
@deborahkurata
16 | 19 |
20 |
21 |
-------------------------------------------------------------------------------- /APM-Final/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: string = 'Welcome to Acme Product Management'; 8 | } 9 | -------------------------------------------------------------------------------- /APM-Final/src/app/messages/message.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

{{pageTitle}}

5 | 6 | 8 | x 9 | 10 | 11 |
12 |
13 | 14 |
15 |
16 |
17 |
{{ message }}
18 |
19 |
20 |
21 |
22 | {{ noMessages }} 23 |
24 |
25 |
26 |
-------------------------------------------------------------------------------- /APM-Final/src/app/messages/message.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | 4 | import { MessageService } from '../core/message.service'; 5 | 6 | @Component({ 7 | selector: 'pm-messages', 8 | templateUrl: './message.component.html', 9 | styles: [ 10 | '.message-row { margin-bottom: 10px }' 11 | ] 12 | }) 13 | export class MessageComponent { 14 | pageTitle = 'Message Log'; 15 | noMessages = 'No messages'; 16 | get messages(): string[] { 17 | return this.messageService.getMessages(); 18 | } 19 | 20 | constructor(private messageService: MessageService, 21 | private router: Router) { } 22 | 23 | close(): void { 24 | this.messageService.displayMessages = false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /APM-Final/src/app/messages/message.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | 3 | import { SharedModule } from '../shared/shared.module'; 4 | 5 | import { MessageComponent } from './message.component'; 6 | 7 | @NgModule({ 8 | imports: [ 9 | SharedModule 10 | ], 11 | declarations: [ 12 | MessageComponent 13 | ], 14 | exports: [ 15 | MessageComponent 16 | ] 17 | }) 18 | export class MessageModule { } 19 | -------------------------------------------------------------------------------- /APM-Final/src/app/products/product-detail.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Modules/f56925658869cdbec8a6bc7bb08a0a9f096d6b0d/APM-Final/src/app/products/product-detail.component.css -------------------------------------------------------------------------------- /APM-Final/src/app/products/product-detail.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle + ': ' + product.productName}} 4 |
5 | 6 |
7 |
8 |
9 |
10 |
Name:
11 |
{{product.productName}}
12 |
13 |
14 |
Code:
15 |
{{product.productCode | lowercase | convertToSpaces: '-'}}
16 |
17 |
18 |
Description:
19 |
{{product.description}}
20 |
21 |
22 |
Availability:
23 |
{{product.releaseDate}}
24 |
25 |
26 |
Price:
27 |
{{product.price|currency:'USD':true}}
28 |
29 |
30 |
5 Star Rating:
31 |
32 | 33 | 34 |
35 |
36 |
37 | 38 |
39 | 44 |
45 |
46 |
47 | 48 | 53 |
-------------------------------------------------------------------------------- /APM-Final/src/app/products/product-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | 4 | import { IProduct } from './product'; 5 | import { ProductService } from './product.service'; 6 | 7 | @Component({ 8 | templateUrl: './product-detail.component.html', 9 | styleUrls: ['./product-detail.component.css'] 10 | }) 11 | export class ProductDetailComponent implements OnInit { 12 | pageTitle: string = 'Product Detail'; 13 | errorMessage: string; 14 | product: IProduct; 15 | 16 | constructor(private route: ActivatedRoute, 17 | private router: Router, 18 | private productService: ProductService) { 19 | } 20 | 21 | ngOnInit() { 22 | const id = +this.route.snapshot.paramMap.get('id'); 23 | this.getProduct(id); 24 | } 25 | 26 | getProduct(id: number) { 27 | this.productService.getProduct(id).subscribe( 28 | product => this.product = product, 29 | error => this.errorMessage = error); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /APM-Final/src/app/products/product-list.component.css: -------------------------------------------------------------------------------- 1 | thead { 2 | color: #337AB7; 3 | } -------------------------------------------------------------------------------- /APM-Final/src/app/products/product-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 |
6 |
7 |
Filter by:
8 |
9 | 10 |
11 |
12 |
13 |
14 |

Filtered by: {{listFilter}}

15 |
16 |
17 |
18 | 20 | 21 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 44 | 48 | 49 | 50 | 51 | 56 | 57 | 58 |
23 | 27 | ProductCodeAvailablePrice5 Star Rating
38 | 43 | 45 | {{ product.productName }} 46 | 47 | {{ product.productCode | lowercase | convertToSpaces: '-' }}{{ product.releaseDate }}{{ product.price | currency:'USD':true:'1.2-2'}} 52 | 54 | 55 |
59 |
60 |
61 |
62 |
63 | Error: {{ errorMessage }} 64 |
-------------------------------------------------------------------------------- /APM-Final/src/app/products/product-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { IProduct } from './product'; 4 | import { ProductService } from './product.service'; 5 | 6 | @Component({ 7 | templateUrl: './product-list.component.html', 8 | styleUrls: ['./product-list.component.css'] 9 | }) 10 | export class ProductListComponent implements OnInit { 11 | pageTitle: string = 'Product List'; 12 | imageWidth: number = 50; 13 | imageMargin: number = 2; 14 | showImage: boolean = false; 15 | errorMessage: string; 16 | 17 | private _listFilter: string; 18 | get listFilter(): string { 19 | return this._listFilter; 20 | } 21 | set listFilter(value: string) { 22 | this._listFilter = value; 23 | this.filteredProducts = this.listFilter ? this.performFilter(this.listFilter) : this.products; 24 | } 25 | 26 | filteredProducts: IProduct[]; 27 | products: IProduct[] = []; 28 | 29 | constructor(private productService: ProductService) { 30 | 31 | } 32 | 33 | onRatingClicked(message: string): void { 34 | this.pageTitle = 'Product List: ' + message; 35 | } 36 | 37 | performFilter(filterBy: string): IProduct[] { 38 | filterBy = filterBy.toLocaleLowerCase(); 39 | return this.products.filter((product: IProduct) => 40 | product.productName.toLocaleLowerCase().indexOf(filterBy) !== -1); 41 | } 42 | 43 | toggleImage(): void { 44 | this.showImage = !this.showImage; 45 | } 46 | 47 | ngOnInit(): void { 48 | this.productService.getProducts() 49 | .subscribe(products => { 50 | this.products = products; 51 | this.filteredProducts = this.products; 52 | }, 53 | error => this.errorMessage = error); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /APM-Final/src/app/products/product.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | 4 | import { SharedModule } from './../shared/shared.module'; 5 | 6 | import { ProductListComponent } from './product-list.component'; 7 | import { ProductDetailComponent } from './product-detail.component'; 8 | 9 | import { ProductService } from './product.service'; 10 | 11 | @NgModule({ 12 | imports: [ 13 | SharedModule, 14 | RouterModule.forChild([ 15 | { path: '', component: ProductListComponent }, 16 | { path: ':id', component: ProductDetailComponent } 17 | ]) 18 | ], 19 | declarations: [ 20 | ProductListComponent, 21 | ProductDetailComponent 22 | ], 23 | providers: [ 24 | ProductService 25 | ] 26 | }) 27 | export class ProductModule { } 28 | -------------------------------------------------------------------------------- /APM-Final/src/app/products/product.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Observable } from 'rxjs/Observable'; 3 | import 'rxjs/add/operator/do'; 4 | 5 | import { IProduct } from './product'; 6 | import { DataService } from '../core/data.service'; 7 | import { MessageService } from '../core/message.service'; 8 | 9 | @Injectable() 10 | export class ProductService { 11 | private productUrl = './api/products/products.json'; 12 | 13 | constructor(private dataService: DataService, 14 | private messageService: MessageService) { } 15 | 16 | getProducts(): Observable { 17 | return this.dataService.getItems(this.productUrl); 18 | } 19 | 20 | getProduct(id: number): Observable { 21 | // return this.dataService.getItem(this.productUrl); 22 | return this.dataService.getItems(this.productUrl) 23 | .map(data => data.find(d => d.id === id)) 24 | .do(p => this.messageService.addMessage(`Viewed product: ${p.productName}`)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /APM-Final/src/app/products/product.ts: -------------------------------------------------------------------------------- 1 | export interface IProduct { 2 | id: number; 3 | productName: string; 4 | productCode: string; 5 | releaseDate: string; 6 | price: number; 7 | description: string; 8 | starRating: number; 9 | imageUrl: string; 10 | } 11 | -------------------------------------------------------------------------------- /APM-Final/src/app/selective-strategy.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Route, PreloadingStrategy } from '@angular/router'; 3 | 4 | import { Observable } from 'rxjs/Observable'; 5 | import 'rxjs/add/observable/of'; 6 | 7 | @Injectable() 8 | export class SelectiveStrategy implements PreloadingStrategy { 9 | 10 | preload(route: Route, load: Function): Observable { 11 | if (route.data && route.data['preload']) { 12 | return load(); 13 | } 14 | return Observable.of(null); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /APM-Final/src/app/shared/convert-to-spaces.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | 3 | @Pipe({ 4 | name: 'convertToSpaces' 5 | }) 6 | export class ConvertToSpacesPipe implements PipeTransform { 7 | 8 | transform(value: string, character: string): string { 9 | return value.replace(character, ' '); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /APM-Final/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 | import { StarComponent } from './star.component'; 6 | import { ConvertToSpacesPipe } from './convert-to-spaces.pipe'; 7 | 8 | @NgModule({ 9 | imports: [ 10 | CommonModule 11 | ], 12 | declarations: [ 13 | StarComponent, 14 | ConvertToSpacesPipe 15 | ], 16 | exports: [ 17 | StarComponent, 18 | ConvertToSpacesPipe, 19 | CommonModule, 20 | FormsModule 21 | ] 22 | }) 23 | export class SharedModule { } 24 | -------------------------------------------------------------------------------- /APM-Final/src/app/shared/star.component.css: -------------------------------------------------------------------------------- 1 | .crop { 2 | overflow: hidden; 3 | } 4 | div { 5 | cursor: pointer; 6 | } -------------------------------------------------------------------------------- /APM-Final/src/app/shared/star.component.html: -------------------------------------------------------------------------------- 1 |
5 |
6 | 7 | 8 | 9 | 10 | 11 |
12 |
-------------------------------------------------------------------------------- /APM-Final/src/app/shared/star.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnChanges, Input, EventEmitter, Output } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'pm-star', 5 | templateUrl: './star.component.html', 6 | styleUrls: ['./star.component.css'] 7 | }) 8 | export class StarComponent implements OnChanges { 9 | @Input() rating: number; 10 | starWidth: number; 11 | @Output() ratingClicked: EventEmitter = 12 | new EventEmitter(); 13 | 14 | ngOnChanges(): void { 15 | this.starWidth = this.rating * 86 / 5; 16 | } 17 | 18 | onClick(): void { 19 | this.ratingClicked.emit(`The rating ${this.rating} was clicked!`); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /APM-Final/src/app/user/auth-guard.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { ActivatedRouteSnapshot, RouterStateSnapshot, Router, Route, 3 | CanActivate, CanActivateChild } from '@angular/router'; 4 | 5 | import { AuthService } from './auth.service'; 6 | 7 | @Injectable() 8 | export  class AuthGuard implements CanActivate, CanActivateChild { 9 | 10 | constructor(private authService: AuthService, 11 | private router: Router) { } 12 | 13 | canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { 14 | console.log('In canActivate: ' + state.url); 15 | return this.checkLoggedIn(state.url); 16 | } 17 | 18 | canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { 19 | console.log('In canActivateChild: ' + state.url); 20 | return this.checkLoggedIn(state.url); 21 | } 22 | 23 | checkLoggedIn(url: string): boolean { 24 | if (this.authService.isLoggedIn()) { 25 | return true; 26 | } 27 | 28 | // Retain the attempted URL for redirection 29 | this.authService.redirectUrl = url; 30 | this.router.navigate(['/login']); 31 | return false; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /APM-Final/src/app/user/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | import { IUser } from './user'; 4 | import { MessageService } from '../core/message.service'; 5 | 6 | @Injectable() 7 | export class AuthService { 8 | currentUser: IUser; 9 | redirectUrl: string; 10 | 11 | constructor(private messageService: MessageService) { } 12 | 13 | isLoggedIn(): boolean { 14 | return !!this.currentUser; 15 | } 16 | 17 | login(userName: string, password: string): void { 18 | // Code here would log into a back end service 19 | // and return user information 20 | // This is just hard-coded here. 21 | this.currentUser = { 22 | id: 2, 23 | userName: userName, 24 | isAdmin: false 25 | }; 26 | this.messageService.addMessage(`User: ${this.currentUser.userName} logged in`); 27 | } 28 | 29 | logout(): void { 30 | this.currentUser = null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /APM-Final/src/app/user/login.component.css: -------------------------------------------------------------------------------- 1 | div.panel { 2 | margin: 40px 0; 3 | width: 700px; 4 | } -------------------------------------------------------------------------------- /APM-Final/src/app/user/login.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | {{pageTitle}} 5 |
6 | 7 |
8 |
9 |
10 |
13 | 14 | 15 |
16 | 18 | 21 | 22 | User name is required. 23 | 24 | 25 |
26 |
27 | 28 |
31 | 32 | 33 |
34 | 36 | 39 | 40 | Password is required. 41 | 42 | 43 |
44 |
45 | 46 |
47 |
48 | 49 | 55 | 56 | 57 | 59 | Cancel 60 | 61 | 62 |
63 |
64 |
65 |
66 |
{{errorMessage}}
67 |
68 | 69 |
70 |
-------------------------------------------------------------------------------- /APM-Final/src/app/user/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { NgForm } from '@angular/forms'; 3 | import { Router, ActivatedRoute } from '@angular/router'; 4 | 5 | import { AuthService } from './auth.service'; 6 | 7 | @Component({ 8 | templateUrl: './login.component.html', 9 | styleUrls: ['./login.component.css'] 10 | }) 11 | export class LoginComponent { 12 | errorMessage: string; 13 | pageTitle = 'Log In'; 14 | 15 | constructor(private authService: AuthService, 16 | private router: Router) { 17 | } 18 | 19 | cancel(): void { 20 | this.router.navigate(['welcome']); 21 | } 22 | 23 | login(loginForm: NgForm): void { 24 | if (loginForm && loginForm.valid) { 25 | const userName = loginForm.form.value.userName; 26 | const password = loginForm.form.value.password; 27 | this.authService.login(userName, password); 28 | 29 | if (this.authService.redirectUrl) { 30 | this.router.navigateByUrl(this.authService.redirectUrl); 31 | } else { 32 | this.router.navigate(['/products']); 33 | } 34 | } else { 35 | this.errorMessage = 'Please enter a user name and password.'; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /APM-Final/src/app/user/user.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | 4 | import { LoginComponent } from './login.component'; 5 | import { AuthService } from './auth.service'; 6 | import { AuthGuard } from './auth-guard.service'; 7 | 8 | import { SharedModule } from '../shared/shared.module'; 9 | 10 | @NgModule({ 11 | imports: [ 12 | SharedModule, 13 | RouterModule.forChild([ 14 | { path: 'login', component: LoginComponent } 15 | ]) 16 | ], 17 | declarations: [ 18 | LoginComponent 19 | ], 20 | providers: [ 21 | AuthService, 22 | AuthGuard 23 | ] 24 | }) 25 | export class UserModule { } 26 | -------------------------------------------------------------------------------- /APM-Final/src/app/user/user.ts: -------------------------------------------------------------------------------- 1 | /* Defines the user entity */ 2 | export interface IUser { 3 | id: number; 4 | userName: string; 5 | isAdmin: boolean; 6 | } 7 | -------------------------------------------------------------------------------- /APM-Final/src/assets/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Modules/f56925658869cdbec8a6bc7bb08a0a9f096d6b0d/APM-Final/src/assets/images/logo.jpg -------------------------------------------------------------------------------- /APM-Final/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /APM-Final/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /APM-Final/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeborahK/Angular-Modules/f56925658869cdbec8a6bc7bb08a0a9f096d6b0d/APM-Final/src/favicon.ico -------------------------------------------------------------------------------- /APM-Final/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Acme Product Management 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /APM-Final/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 | -------------------------------------------------------------------------------- /APM-Final/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/docs/ts/latest/guide/browser-support.html 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 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** Evergreen browsers require these. **/ 41 | import 'core-js/es6/reflect'; 42 | import 'core-js/es7/reflect'; 43 | 44 | 45 | /** 46 | * Required to support Web Animations `@angular/animation`. 47 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 48 | **/ 49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 50 | 51 | 52 | 53 | /*************************************************************************************************** 54 | * Zone JS is required by Angular itself. 55 | */ 56 | import 'zone.js/dist/zone'; // Included with Angular CLI. 57 | 58 | 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | 64 | /** 65 | * Date, currency, decimal and percent pipes. 66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 67 | */ 68 | // import 'intl'; // Run `npm install --save intl`. 69 | /** 70 | * Need to import at least one locale-data with intl. 71 | */ 72 | // import 'intl/locale-data/jsonp/en'; 73 | -------------------------------------------------------------------------------- /APM-Final/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | li { 3 | font-size: large; 4 | } 5 | 6 | div.panel-heading { 7 | font-size: x-large; 8 | } -------------------------------------------------------------------------------- /APM-Final/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/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare const __karma__: any; 17 | declare const require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /APM-Final/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /APM-Final/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /APM-Final/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /APM-Final/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "typeRoots": [ 12 | "node_modules/@types" 13 | ], 14 | "lib": [ 15 | "es2016", 16 | "dom" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /APM-Final/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 | "eofline": true, 15 | "forin": true, 16 | "import-blacklist": [ 17 | true, 18 | "rxjs" 19 | ], 20 | "import-spacing": true, 21 | "indent": [ 22 | true, 23 | "spaces" 24 | ], 25 | "interface-over-type-literal": true, 26 | "label-position": true, 27 | "max-line-length": [ 28 | true, 29 | 140 30 | ], 31 | "member-access": false, 32 | "member-ordering": [ 33 | true, 34 | { 35 | "order": [ 36 | "static-field", 37 | "instance-field", 38 | "static-method", 39 | "instance-method" 40 | ] 41 | } 42 | ], 43 | "no-arg": true, 44 | "no-bitwise": true, 45 | "no-console": [ 46 | true, 47 | "debug", 48 | "info", 49 | "time", 50 | "timeEnd", 51 | "trace" 52 | ], 53 | "no-construct": true, 54 | "no-debugger": true, 55 | "no-duplicate-super": true, 56 | "no-empty": false, 57 | "no-empty-interface": true, 58 | "no-eval": true, 59 | "no-inferrable-types": [ 60 | false, 61 | "ignore-params" 62 | ], 63 | "no-misused-new": true, 64 | "no-non-null-assertion": true, 65 | "no-shadowed-variable": true, 66 | "no-string-literal": false, 67 | "no-string-throw": true, 68 | "no-switch-case-fall-through": true, 69 | "no-trailing-whitespace": true, 70 | "no-unnecessary-initializer": true, 71 | "no-unused-expression": true, 72 | "no-use-before-declare": true, 73 | "no-var-keyword": true, 74 | "object-literal-sort-keys": false, 75 | "one-line": [ 76 | true, 77 | "check-open-brace", 78 | "check-catch", 79 | "check-else", 80 | "check-whitespace" 81 | ], 82 | "prefer-const": true, 83 | "quotemark": [ 84 | true, 85 | "single" 86 | ], 87 | "radix": true, 88 | "semicolon": [ 89 | true, 90 | "always" 91 | ], 92 | "triple-equals": [ 93 | true, 94 | "allow-null-check" 95 | ], 96 | "typedef-whitespace": [ 97 | true, 98 | { 99 | "call-signature": "nospace", 100 | "index-signature": "nospace", 101 | "parameter": "nospace", 102 | "property-declaration": "nospace", 103 | "variable-declaration": "nospace" 104 | } 105 | ], 106 | "typeof-compare": true, 107 | "unified-signatures": true, 108 | "variable-name": false, 109 | "whitespace": [ 110 | true, 111 | "check-branch", 112 | "check-decl", 113 | "check-operator", 114 | "check-separator", 115 | "check-type" 116 | ], 117 | "directive-selector": [ 118 | true, 119 | "attribute", 120 | "pm", 121 | "camelCase" 122 | ], 123 | "component-selector": [ 124 | true, 125 | "element", 126 | "pm", 127 | "kebab-case" 128 | ], 129 | "use-input-property-decorator": true, 130 | "use-output-property-decorator": true, 131 | "use-host-property-decorator": true, 132 | "no-input-rename": true, 133 | "no-output-rename": true, 134 | "use-life-cycle-interface": true, 135 | "use-pipe-transform-interface": true, 136 | "component-class-suffix": true, 137 | "directive-class-suffix": true, 138 | "no-access-missing-member": true, 139 | "templates-use-public": true, 140 | "invoke-injectable": true 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 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 | --------------------------------------------------------------------------------