├── .angular-cli.json ├── .editorconfig ├── .firebaserc ├── .gitignore ├── README.md ├── e2e ├── app.e2e-spec.ts ├── app.po.ts └── tsconfig.e2e.json ├── firebase.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── protractor.conf.js ├── src ├── app │ ├── admin │ │ ├── admin.module.ts │ │ ├── components │ │ │ ├── admin-orders │ │ │ │ ├── admin-orders.component.css │ │ │ │ ├── admin-orders.component.html │ │ │ │ ├── admin-orders.component.spec.ts │ │ │ │ └── admin-orders.component.ts │ │ │ ├── admin-products │ │ │ │ ├── admin-products.component.css │ │ │ │ ├── admin-products.component.html │ │ │ │ ├── admin-products.component.spec.ts │ │ │ │ └── admin-products.component.ts │ │ │ └── product-form │ │ │ │ ├── product-form.component.css │ │ │ │ ├── product-form.component.html │ │ │ │ ├── product-form.component.spec.ts │ │ │ │ └── product-form.component.ts │ │ └── services │ │ │ ├── admin-auth-guard.service.spec.ts │ │ │ └── admin-auth-guard.service.ts │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── core │ │ ├── components │ │ │ ├── bs-navbar │ │ │ │ ├── bs-navbar.component.css │ │ │ │ ├── bs-navbar.component.html │ │ │ │ ├── bs-navbar.component.spec.ts │ │ │ │ └── bs-navbar.component.ts │ │ │ ├── home │ │ │ │ ├── home.component.css │ │ │ │ ├── home.component.html │ │ │ │ ├── home.component.spec.ts │ │ │ │ └── home.component.ts │ │ │ └── login │ │ │ │ ├── login.component.css │ │ │ │ ├── login.component.html │ │ │ │ ├── login.component.spec.ts │ │ │ │ └── login.component.ts │ │ └── core.module.ts │ ├── shared │ │ ├── components │ │ │ ├── product-card │ │ │ │ ├── product-card.component.css │ │ │ │ ├── product-card.component.html │ │ │ │ ├── product-card.component.spec.ts │ │ │ │ └── product-card.component.ts │ │ │ └── product-quantity │ │ │ │ ├── product-quantity.component.css │ │ │ │ ├── product-quantity.component.html │ │ │ │ ├── product-quantity.component.spec.ts │ │ │ │ └── product-quantity.component.ts │ │ ├── models │ │ │ ├── app-user.ts │ │ │ ├── order.ts │ │ │ ├── product.ts │ │ │ ├── shopping-cart-item.ts │ │ │ └── shopping-cart.ts │ │ ├── services │ │ │ ├── auth-guard.service.spec.ts │ │ │ ├── auth-guard.service.ts │ │ │ ├── auth.service.spec.ts │ │ │ ├── auth.service.ts │ │ │ ├── category.service.spec.ts │ │ │ ├── category.service.ts │ │ │ ├── order.service.spec.ts │ │ │ ├── order.service.ts │ │ │ ├── product.service.spec.ts │ │ │ ├── product.service.ts │ │ │ ├── shopping-cart.service.spec.ts │ │ │ ├── shopping-cart.service.ts │ │ │ ├── user.service.spec.ts │ │ │ └── user.service.ts │ │ └── shared.module.ts │ └── shopping │ │ ├── components │ │ ├── check-out │ │ │ ├── check-out.component.css │ │ │ ├── check-out.component.html │ │ │ ├── check-out.component.spec.ts │ │ │ └── check-out.component.ts │ │ ├── my-orders │ │ │ ├── my-orders.component.css │ │ │ ├── my-orders.component.html │ │ │ ├── my-orders.component.spec.ts │ │ │ └── my-orders.component.ts │ │ ├── order-success │ │ │ ├── order-success.component.css │ │ │ ├── order-success.component.html │ │ │ ├── order-success.component.spec.ts │ │ │ └── order-success.component.ts │ │ ├── products │ │ │ ├── product-filter │ │ │ │ ├── product-filter.component.css │ │ │ │ ├── product-filter.component.html │ │ │ │ ├── product-filter.component.spec.ts │ │ │ │ └── product-filter.component.ts │ │ │ ├── products.component.css │ │ │ ├── products.component.html │ │ │ ├── products.component.spec.ts │ │ │ └── products.component.ts │ │ ├── shipping-form │ │ │ ├── shipping-form.component.css │ │ │ ├── shipping-form.component.html │ │ │ ├── shipping-form.component.spec.ts │ │ │ └── shipping-form.component.ts │ │ ├── shopping-cart-summary │ │ │ ├── shopping-cart-summary.component.css │ │ │ ├── shopping-cart-summary.component.html │ │ │ ├── shopping-cart-summary.component.spec.ts │ │ │ └── shopping-cart-summary.component.ts │ │ └── shopping-cart │ │ │ ├── shopping-cart.component.css │ │ │ ├── shopping-cart.component.html │ │ │ ├── shopping-cart.component.spec.ts │ │ │ └── shopping-cart.component.ts │ │ └── shopping.module.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.scss ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── typings.d.ts ├── tsconfig.json └── tslint.json /.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "oshop" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.scss" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json", 40 | "exclude": "**/node_modules/**" 41 | }, 42 | { 43 | "project": "src/tsconfig.spec.json", 44 | "exclude": "**/node_modules/**" 45 | }, 46 | { 47 | "project": "e2e/tsconfig.e2e.json", 48 | "exclude": "**/node_modules/**" 49 | } 50 | ], 51 | "test": { 52 | "karma": { 53 | "config": "./karma.conf.js" 54 | } 55 | }, 56 | "defaults": { 57 | "styleExt": "css", 58 | "component": {} 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "oshop-f3445" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Organic Shop 2 | 3 | This project demonstrates a simple e-commerce application for an imaginary organic shop. It is built with Angular, Firebase and Bootstrap 4 as the final project in my complete Angular course: 4 | 5 | http://programmingwithmosh.com/courses/complete-angular-master-class/ 6 | 7 | In this course, you'll see how I've built this application, step-by-step. 8 | 9 | By the end of watching course, you'll be able to: 10 | 11 | - Use Angular and Firebase to build real-time serverless applications 12 | - Think like a software engineer 13 | - Write clean and testable code 14 | - Refactor bad code into good code 15 | - Design classes and modules with proper boundaries 16 | 17 | 18 | ## Important 19 | 20 | Before running this application on your machine, create a Firebase project. You need to replace the Firebase settings I've defined in /src/environments with the settings of your own Firebase project. 21 | 22 | ## Running the Application 23 | 24 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { OshopPage } from './app.po'; 2 | 3 | describe('oshop App', () => { 4 | let page: OshopPage; 5 | 6 | beforeEach(() => { 7 | page = new OshopPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class OshopPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "public": "dist" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "oshop", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 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 | "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.1", 25 | "angular-4-data-table": "^0.2.3", 26 | "angularfire2": "^4.0.0-rc.1", 27 | "bootstrap": "^4.0.0-beta", 28 | "core-js": "^2.4.1", 29 | "firebase": "^4.2.0", 30 | "font-awesome": "^4.7.0", 31 | "ng2-validation": "^4.2.0", 32 | "rxjs": "^5.4.1", 33 | "zone.js": "^0.8.14" 34 | }, 35 | "devDependencies": { 36 | "@angular/cli": "1.2.4", 37 | "@angular/compiler-cli": "^4.0.0", 38 | "@angular/language-service": "^4.0.0", 39 | "@types/jasmine": "~2.5.53", 40 | "@types/jasminewd2": "~2.0.2", 41 | "@types/node": "~6.0.60", 42 | "codelyzer": "~3.0.1", 43 | "jasmine-core": "~2.6.2", 44 | "jasmine-spec-reporter": "~4.1.0", 45 | "karma": "~1.7.0", 46 | "karma-chrome-launcher": "~2.1.1", 47 | "karma-cli": "~1.0.1", 48 | "karma-coverage-istanbul-reporter": "^1.2.1", 49 | "karma-jasmine": "~1.1.0", 50 | "karma-jasmine-html-reporter": "^0.2.2", 51 | "protractor": "~5.1.2", 52 | "ts-node": "~3.0.4", 53 | "tslint": "~5.3.2", 54 | "typescript": "~2.3.3" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/app/admin/admin.module.ts: -------------------------------------------------------------------------------- 1 | import { AdminAuthGuard } from './services/admin-auth-guard.service'; 2 | import { RouterModule } from '@angular/router'; 3 | import { DataTableModule } from 'angular-4-data-table'; 4 | import { SharedModule } from './../shared/shared.module'; 5 | import { FormsModule } from '@angular/forms'; 6 | import { ProductFormComponent } from './components/product-form/product-form.component'; 7 | import { AdminProductsComponent } from './components/admin-products/admin-products.component'; 8 | import { AdminOrdersComponent } from './components/admin-orders/admin-orders.component'; 9 | import { NgModule } from '@angular/core'; 10 | import { CommonModule } from '@angular/common'; 11 | import { AuthGuard } from "shared/services/auth-guard.service"; 12 | 13 | @NgModule({ 14 | imports: [ 15 | SharedModule, 16 | RouterModule.forChild([ 17 | { 18 | path: 'admin/products/new', 19 | component: ProductFormComponent, 20 | canActivate: [AuthGuard, AdminAuthGuard] 21 | }, 22 | { 23 | path: 'admin/products/:id', 24 | component: ProductFormComponent, 25 | canActivate: [AuthGuard, AdminAuthGuard] 26 | }, 27 | { 28 | path: 'admin/products', 29 | component: AdminProductsComponent, 30 | canActivate: [AuthGuard, AdminAuthGuard] 31 | }, 32 | { 33 | path: 'admin/orders', 34 | component: AdminOrdersComponent, 35 | canActivate: [AuthGuard, AdminAuthGuard] 36 | } 37 | ]) 38 | ], 39 | declarations: [ 40 | ProductFormComponent, 41 | AdminProductsComponent, 42 | AdminOrdersComponent, 43 | ] 44 | }) 45 | export class AdminModule { } 46 | -------------------------------------------------------------------------------- /src/app/admin/components/admin-orders/admin-orders.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/admin/components/admin-orders/admin-orders.component.css -------------------------------------------------------------------------------- /src/app/admin/components/admin-orders/admin-orders.component.html: -------------------------------------------------------------------------------- 1 |

Orders

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 |
CustomerDate
{{ order.shipping.name }}{{ order.datePlaced | date}} 15 | View 16 |
-------------------------------------------------------------------------------- /src/app/admin/components/admin-orders/admin-orders.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AdminOrdersComponent } from './admin-orders.component'; 4 | 5 | describe('AdminOrdersComponent', () => { 6 | let component: AdminOrdersComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AdminOrdersComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AdminOrdersComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/admin/components/admin-orders/admin-orders.component.ts: -------------------------------------------------------------------------------- 1 | import { Order } from '../../../shared/models/order'; 2 | import { OrderService } from '../../../shared/services/order.service'; 3 | import { Component, OnInit } from '@angular/core'; 4 | 5 | @Component({ 6 | selector: 'app-admin-orders', 7 | templateUrl: './admin-orders.component.html', 8 | styleUrls: ['./admin-orders.component.css'] 9 | }) 10 | export class AdminOrdersComponent { 11 | orders$; 12 | 13 | constructor(private orderService: OrderService) { 14 | this.orders$ = orderService.getOrders(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/app/admin/components/admin-products/admin-products.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/admin/components/admin-products/admin-products.component.css -------------------------------------------------------------------------------- /src/app/admin/components/admin-products/admin-products.component.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | New Product 4 |

5 |

6 | 10 |

11 | 12 | 16 | 22 | 23 | 24 | 30 | 31 | {{ item.price | currency:'USD':true }} 32 | 33 | 34 | 35 | 38 | 39 | Edit 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/app/admin/components/admin-products/admin-products.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AdminProductsComponent } from './admin-products.component'; 4 | 5 | describe('AdminProductsComponent', () => { 6 | let component: AdminProductsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AdminProductsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AdminProductsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/admin/components/admin-products/admin-products.component.ts: -------------------------------------------------------------------------------- 1 | import { Product } from '../../../shared/models/product'; 2 | import { Subscription } from 'rxjs/Subscription'; 3 | import { ProductService } from '../../../shared/services/product.service'; 4 | import { Component, OnInit, OnDestroy } from '@angular/core'; 5 | import { DataTableResource } from 'angular-4-data-table'; 6 | 7 | @Component({ 8 | selector: 'app-admin-products', 9 | templateUrl: './admin-products.component.html', 10 | styleUrls: ['./admin-products.component.css'] 11 | }) 12 | export class AdminProductsComponent implements OnInit, OnDestroy { 13 | products: Product[]; 14 | subscription: Subscription; 15 | tableResource: DataTableResource; 16 | items: Product[] = []; 17 | itemCount: number; 18 | 19 | constructor(private productService: ProductService) { 20 | this.subscription = this.productService.getAll() 21 | .subscribe(products => { 22 | this.products = products; 23 | this.initializeTable(products); 24 | }); 25 | } 26 | 27 | private initializeTable(products: Product[]) { 28 | this.tableResource = new DataTableResource(products); 29 | this.tableResource.query({ offset: 0 }) 30 | .then(items => this.items = items); 31 | this.tableResource.count() 32 | .then(count => this.itemCount = count); 33 | } 34 | 35 | reloadItems(params) { 36 | if (!this.tableResource) return; 37 | 38 | this.tableResource.query(params) 39 | .then(items => this.items = items); 40 | } 41 | 42 | filter(query: string) { 43 | let filteredProducts = (query) ? 44 | this.products.filter(p => p.title.toLowerCase().includes(query.toLowerCase())) : 45 | this.products; 46 | 47 | this.initializeTable(filteredProducts); 48 | } 49 | 50 | ngOnDestroy() { 51 | this.subscription.unsubscribe(); 52 | } 53 | 54 | ngOnInit() { 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/app/admin/components/product-form/product-form.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/admin/components/product-form/product-form.component.css -------------------------------------------------------------------------------- /src/app/admin/components/product-form/product-form.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |
6 | 7 | 8 |
9 | Title is required. 10 |
11 |
12 |
13 | 14 |
15 | $ 16 | 17 |
18 |
19 |
Price is required.
20 |
Price should be 0 or higher.
21 |
22 |
23 |
24 | 25 | 31 |
32 | Category is required. 33 |
34 |
35 |
36 | 37 | 38 |
39 |
Image URL is required.
40 |
Please enter a valid URL.
41 |
42 |
43 | 44 | 45 |
46 |
47 |
48 | 49 |
50 |
51 | -------------------------------------------------------------------------------- /src/app/admin/components/product-form/product-form.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ProductFormComponent } from './product-form.component'; 4 | 5 | describe('ProductFormComponent', () => { 6 | let component: ProductFormComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ProductFormComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ProductFormComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/admin/components/product-form/product-form.component.ts: -------------------------------------------------------------------------------- 1 | import { ActivatedRoute } from '@angular/router'; 2 | import { Router } from '@angular/router'; 3 | import { ProductService } from '../../../shared/services/product.service'; 4 | import { CategoryService } from '../../../shared/services/category.service'; 5 | import { Component, OnInit } from '@angular/core'; 6 | import 'rxjs/add/operator/take'; 7 | 8 | @Component({ 9 | selector: 'app-product-form', 10 | templateUrl: './product-form.component.html', 11 | styleUrls: ['./product-form.component.css'] 12 | }) 13 | export class ProductFormComponent implements OnInit { 14 | categories$; 15 | product = {}; 16 | id; 17 | 18 | constructor( 19 | private router: Router, 20 | private route: ActivatedRoute, 21 | private categoryService: CategoryService, 22 | private productService: ProductService) { 23 | this.categories$ = categoryService.getAll(); 24 | 25 | this.id = this.route.snapshot.paramMap.get('id'); 26 | if (this.id) this.productService.get(this.id).take(1).subscribe(p => this.product = p); 27 | } 28 | 29 | save(product) { 30 | if (this.id) this.productService.update(this.id, product); 31 | else this.productService.create(product); 32 | 33 | this.router.navigate(['/admin/products']); 34 | } 35 | 36 | delete() { 37 | if (!confirm('Are you sure you want to delete this product?')) return; 38 | 39 | this.productService.delete(this.id); 40 | this.router.navigate(['/admin/products']); 41 | } 42 | 43 | ngOnInit() { 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/app/admin/services/admin-auth-guard.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { AdminAuthGuard } from './admin-auth-guard.service'; 4 | 5 | describe('AdminAuthGuardService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [AdminAuthGuard] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([AdminAuthGuard], (service: AdminAuthGuard) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/admin/services/admin-auth-guard.service.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs/Observable'; 2 | import { UserService } from '../../shared/services/user.service'; 3 | import { AuthService } from '../../shared/services/auth.service'; 4 | import { CanActivate } from '@angular/router'; 5 | import { Injectable } from '@angular/core'; 6 | import 'rxjs/add/operator/map'; 7 | 8 | @Injectable() 9 | export class AdminAuthGuard implements CanActivate { 10 | 11 | constructor(private auth: AuthService, private userService: UserService) { } 12 | 13 | canActivate(): Observable { 14 | return this.auth.appUser$ 15 | .map(appUser => appUser.isAdmin); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/app.component.css -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
-------------------------------------------------------------------------------- /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 'app'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('app'); 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 app!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { UserService } from './shared/services/user.service'; 2 | import { Router } from '@angular/router'; 3 | import { AuthService } from './shared/services/auth.service'; 4 | import { Component } from '@angular/core'; 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | templateUrl: './app.component.html', 9 | styleUrls: ['./app.component.css'] 10 | }) 11 | export class AppComponent { 12 | constructor(private userService: UserService, private auth: AuthService, router: Router) { 13 | auth.user$.subscribe(user => { 14 | if (!user) return; 15 | 16 | userService.save(user); 17 | 18 | let returnUrl = localStorage.getItem('returnUrl'); 19 | if (!returnUrl) return; 20 | 21 | localStorage.removeItem('returnUrl'); 22 | router.navigateByUrl(returnUrl); 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { RouterModule } from '@angular/router'; 4 | import { AngularFireModule } from 'angularfire2'; 5 | 6 | import { environment } from './../environments/environment'; 7 | import { AdminModule } from './admin/admin.module'; 8 | import { AdminAuthGuard } from './admin/services/admin-auth-guard.service'; 9 | import { AppComponent } from './app.component'; 10 | import { LoginComponent } from './core/components/login/login.component'; 11 | import { CoreModule } from './core/core.module'; 12 | import { SharedModule } from './shared/shared.module'; 13 | import { ProductsComponent } from './shopping/components/products/products.component'; 14 | import { ShoppingModule } from './shopping/shopping.module'; 15 | 16 | @NgModule({ 17 | declarations: [ 18 | AppComponent 19 | ], 20 | imports: [ 21 | BrowserModule, 22 | SharedModule, 23 | AdminModule, 24 | ShoppingModule, 25 | CoreModule, 26 | AngularFireModule.initializeApp(environment.firebase), 27 | RouterModule.forRoot([ 28 | { path: '', component: ProductsComponent }, 29 | { path: 'login', component: LoginComponent }, 30 | ]) 31 | ], 32 | providers: [ 33 | AdminAuthGuard, 34 | ], 35 | bootstrap: [AppComponent] 36 | }) 37 | export class AppModule { } 38 | -------------------------------------------------------------------------------- /src/app/core/components/bs-navbar/bs-navbar.component.css: -------------------------------------------------------------------------------- 1 | 2 | .dropdown-toggle { 3 | cursor: pointer; 4 | } -------------------------------------------------------------------------------- /src/app/core/components/bs-navbar/bs-navbar.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/core/components/bs-navbar/bs-navbar.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BsNavbarComponent } from './bs-navbar.component'; 4 | 5 | describe('BsNavbarComponent', () => { 6 | let component: BsNavbarComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BsNavbarComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BsNavbarComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/core/components/bs-navbar/bs-navbar.component.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCart } from '../../../shared/models/shopping-cart'; 2 | import { Observable } from 'rxjs/Observable'; 3 | import { ShoppingCartService } from '../../../shared/services/shopping-cart.service'; 4 | import { AppUser } from '../../../shared/models/app-user'; 5 | import { AuthService } from '../../../shared/services/auth.service'; 6 | import { Component, OnInit } from '@angular/core'; 7 | 8 | @Component({ 9 | selector: 'bs-navbar', 10 | templateUrl: './bs-navbar.component.html', 11 | styleUrls: ['./bs-navbar.component.css'] 12 | }) 13 | export class BsNavbarComponent implements OnInit { 14 | appUser: AppUser; 15 | cart$: Observable; 16 | 17 | constructor(private auth: AuthService, private shoppingCartService: ShoppingCartService) { 18 | } 19 | 20 | async ngOnInit() { 21 | this.auth.appUser$.subscribe(appUser => this.appUser = appUser); 22 | this.cart$ = await this.shoppingCartService.getCart(); 23 | } 24 | 25 | logout() { 26 | this.auth.logout(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/app/core/components/home/home.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/core/components/home/home.component.css -------------------------------------------------------------------------------- /src/app/core/components/home/home.component.html: -------------------------------------------------------------------------------- 1 |

2 | home works! 3 |

4 | -------------------------------------------------------------------------------- /src/app/core/components/home/home.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeComponent } from './home.component'; 4 | 5 | describe('HomeComponent', () => { 6 | let component: HomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HomeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/core/components/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-home', 5 | templateUrl: './home.component.html', 6 | styleUrls: ['./home.component.css'] 7 | }) 8 | export class HomeComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/core/components/login/login.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/core/components/login/login.component.css -------------------------------------------------------------------------------- /src/app/core/components/login/login.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/core/components/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/core/components/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { AuthService } from 'shared/services/auth.service'; 2 | import { Component, OnInit } from '@angular/core'; 3 | 4 | @Component({ 5 | selector: 'app-login', 6 | templateUrl: './login.component.html', 7 | styleUrls: ['./login.component.css'] 8 | }) 9 | export class LoginComponent { 10 | constructor(private auth: AuthService) { 11 | } 12 | 13 | login() { 14 | this.auth.login(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { SharedModule } from '../shared/shared.module'; 2 | import { RouterModule } from '@angular/router'; 3 | import { LoginComponent } from './components/login/login.component'; 4 | import { HomeComponent } from './components/home/home.component'; 5 | import { BsNavbarComponent } from './components/bs-navbar/bs-navbar.component'; 6 | import { NgModule } from '@angular/core'; 7 | import { CommonModule } from '@angular/common'; 8 | 9 | @NgModule({ 10 | imports: [ 11 | SharedModule, 12 | RouterModule.forChild([]) 13 | ], 14 | declarations: [ 15 | BsNavbarComponent, 16 | HomeComponent, 17 | LoginComponent, 18 | ], 19 | exports: [ 20 | BsNavbarComponent 21 | ] 22 | }) 23 | export class CoreModule { } 24 | -------------------------------------------------------------------------------- /src/app/shared/components/product-card/product-card.component.css: -------------------------------------------------------------------------------- 1 | 2 | .card { 3 | margin-bottom: 30px; 4 | } 5 | 6 | .card-img-top { 7 | height: 200px; 8 | } 9 | 10 | .card-footer { 11 | padding: 0; 12 | background: #fff; 13 | } 14 | 15 | .card-footer button { 16 | cursor: pointer; 17 | text-transform: uppercase; 18 | } -------------------------------------------------------------------------------- /src/app/shared/components/product-card/product-card.component.html: -------------------------------------------------------------------------------- 1 |
2 | {{ product.title }} 3 |
4 |

{{ product.title }}

5 |

{{ product.price | currency:'USD':true }}

6 |
7 | 17 |
18 | -------------------------------------------------------------------------------- /src/app/shared/components/product-card/product-card.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ProductCardComponent } from './product-card.component'; 4 | 5 | describe('ProductCardComponent', () => { 6 | let component: ProductCardComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ProductCardComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ProductCardComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shared/components/product-card/product-card.component.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCart } from '../../models/shopping-cart'; 2 | import { ShoppingCartService } from '../../services/shopping-cart.service'; 3 | import { Product } from '../../models/product'; 4 | import { Component, OnInit, Input } from '@angular/core'; 5 | 6 | @Component({ 7 | selector: 'product-card', 8 | templateUrl: './product-card.component.html', 9 | styleUrls: ['./product-card.component.css'] 10 | }) 11 | export class ProductCardComponent { 12 | @Input('product') product: Product; 13 | @Input('show-actions') showActions = true; 14 | @Input('shopping-cart') shoppingCart: ShoppingCart; 15 | 16 | constructor(private cartService: ShoppingCartService) { } 17 | 18 | addToCart() { 19 | this.cartService.addToCart(this.product); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app/shared/components/product-quantity/product-quantity.component.css: -------------------------------------------------------------------------------- 1 | 2 | .quantity { 3 | height: 37px; 4 | line-height: 37px; 5 | } -------------------------------------------------------------------------------- /src/app/shared/components/product-quantity/product-quantity.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 6 |
7 |
8 | {{ shoppingCart.getQuantity(product) }} in cart 9 |
10 |
11 | 14 |
15 |
-------------------------------------------------------------------------------- /src/app/shared/components/product-quantity/product-quantity.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ProductQuantityComponent } from './product-quantity.component'; 4 | 5 | describe('ProductQuantityComponent', () => { 6 | let component: ProductQuantityComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ProductQuantityComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ProductQuantityComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shared/components/product-quantity/product-quantity.component.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCartService } from '../../services/shopping-cart.service'; 2 | import { Product } from '../../models/product'; 3 | import { Component, OnInit, Input } from '@angular/core'; 4 | 5 | @Component({ 6 | selector: 'product-quantity', 7 | templateUrl: './product-quantity.component.html', 8 | styleUrls: ['./product-quantity.component.css'] 9 | }) 10 | export class ProductQuantityComponent { 11 | @Input('product') product: Product; 12 | @Input('shopping-cart') shoppingCart; 13 | 14 | constructor(private cartService: ShoppingCartService) { } 15 | 16 | addToCart() { 17 | this.cartService.addToCart(this.product); 18 | } 19 | 20 | removeFromCart() { 21 | this.cartService.removeFromCart(this.product); 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/app/shared/models/app-user.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface AppUser { 3 | name: string; 4 | email: string; 5 | isAdmin: boolean; 6 | } -------------------------------------------------------------------------------- /src/app/shared/models/order.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCart } from './shopping-cart'; 2 | 3 | export class Order { 4 | datePlaced: number; 5 | items: any[]; 6 | 7 | constructor(public userId: string, public shipping: any, shoppingCart: ShoppingCart) { 8 | this.datePlaced = new Date().getTime(); 9 | 10 | this.items = shoppingCart.items.map(i => { 11 | return { 12 | product: { 13 | title: i.title, 14 | imageUrl: i.imageUrl, 15 | price: i.price 16 | }, 17 | quantity: i.quantity, 18 | totalPrice: i.totalPrice 19 | } 20 | }) 21 | } 22 | } -------------------------------------------------------------------------------- /src/app/shared/models/product.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface Product { 3 | $key: string; 4 | title: string; 5 | price: number; 6 | category: string; 7 | imageUrl: string; 8 | } -------------------------------------------------------------------------------- /src/app/shared/models/shopping-cart-item.ts: -------------------------------------------------------------------------------- 1 | import { Product } from './product'; 2 | 3 | export class ShoppingCartItem { 4 | $key: string; 5 | title: string; 6 | imageUrl: string; 7 | price: number; 8 | quantity: number; 9 | 10 | constructor(init?: Partial) { 11 | Object.assign(this, init); 12 | } 13 | 14 | get totalPrice() { return this.price * this.quantity; } 15 | } -------------------------------------------------------------------------------- /src/app/shared/models/shopping-cart.ts: -------------------------------------------------------------------------------- 1 | import { Product } from './product'; 2 | import { ShoppingCartItem } from './shopping-cart-item'; 3 | 4 | export class ShoppingCart { 5 | items: ShoppingCartItem[] = []; 6 | 7 | constructor(private itemsMap: { [productId: string]: ShoppingCartItem }) { 8 | this.itemsMap = itemsMap || {}; 9 | 10 | for (let productId in itemsMap) { 11 | let item = itemsMap[productId]; 12 | this.items.push(new ShoppingCartItem({ ...item, $key: productId })); 13 | } 14 | } 15 | 16 | getQuantity(product: Product) { 17 | let item = this.itemsMap[product.$key]; 18 | return item ? item.quantity : 0; 19 | } 20 | 21 | get totalPrice() { 22 | let sum = 0; 23 | for (let productId in this.items) 24 | sum += this.items[productId].totalPrice; 25 | return sum; 26 | } 27 | 28 | get totalItemsCount() { 29 | let count = 0; 30 | for (let productId in this.itemsMap) 31 | count += this.itemsMap[productId].quantity; 32 | return count; 33 | } 34 | } -------------------------------------------------------------------------------- /src/app/shared/services/auth-guard.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { AuthGuard } from './auth-guard.service'; 4 | 5 | describe('AuthGuardService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [AuthGuard] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([AuthGuard], (service: AuthGuard) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/shared/services/auth-guard.service.ts: -------------------------------------------------------------------------------- 1 | import { Router } from '@angular/router'; 2 | import { AuthService } from './auth.service'; 3 | import { CanActivate, RouterStateSnapshot } from '@angular/router'; 4 | import { Injectable } from '@angular/core'; 5 | import 'rxjs/add/operator/map'; 6 | 7 | @Injectable() 8 | export class AuthGuard implements CanActivate { 9 | 10 | constructor(private auth: AuthService, private router: Router) { } 11 | 12 | canActivate(route, state: RouterStateSnapshot) { 13 | return this.auth.user$.map(user => { 14 | if (user) return true; 15 | 16 | this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }}); 17 | return false; 18 | }); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/app/shared/services/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { AuthService } from './auth.service'; 4 | 5 | describe('AuthService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [AuthService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([AuthService], (service: AuthService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/shared/services/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { UserService } from './user.service'; 2 | import { AppUser } from '../models/app-user'; 3 | import { ActivatedRoute } from '@angular/router'; 4 | import { Observable } from 'rxjs/Observable'; 5 | import { AngularFireAuth } from 'angularfire2/auth'; 6 | import { Injectable } from '@angular/core'; 7 | import 'rxjs/add/operator/switchMap'; 8 | import 'rxjs/add/observable/of'; 9 | import * as firebase from 'firebase'; 10 | 11 | @Injectable() 12 | export class AuthService { 13 | user$: Observable; 14 | 15 | constructor( 16 | private userService: UserService, 17 | private afAuth: AngularFireAuth, 18 | private route: ActivatedRoute) { 19 | this.user$ = afAuth.authState; 20 | } 21 | 22 | login() { 23 | let returnUrl = this.route.snapshot.queryParamMap.get('returnUrl') || '/'; 24 | localStorage.setItem('returnUrl', returnUrl); 25 | 26 | this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider()); 27 | } 28 | 29 | logout() { 30 | this.afAuth.auth.signOut(); 31 | } 32 | 33 | get appUser$() : Observable { 34 | return this.user$ 35 | .switchMap(user => { 36 | if (user) return this.userService.get(user.uid); 37 | 38 | return Observable.of(null); 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/app/shared/services/category.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { CategoryService } from './category.service'; 4 | 5 | describe('CategoryService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [CategoryService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([CategoryService], (service: CategoryService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/shared/services/category.service.ts: -------------------------------------------------------------------------------- 1 | import { AngularFireDatabase } from 'angularfire2/database'; 2 | import { Injectable } from '@angular/core'; 3 | 4 | @Injectable() 5 | export class CategoryService { 6 | 7 | constructor(private db: AngularFireDatabase) { } 8 | 9 | getAll() { 10 | return this.db.list('/categories', { 11 | query: { 12 | orderByChild: 'name' 13 | } 14 | }); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/app/shared/services/order.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { OrderService } from './order.service'; 4 | 5 | describe('OrderService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [OrderService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([OrderService], (service: OrderService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/shared/services/order.service.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCartService } from './shopping-cart.service'; 2 | import { AngularFireDatabase } from 'angularfire2/database'; 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable() 6 | export class OrderService { 7 | 8 | constructor(private db: AngularFireDatabase, private shoppingCartService: ShoppingCartService) { } 9 | 10 | async placeOrder(order) { 11 | let result = await this.db.list('/orders').push(order); 12 | this.shoppingCartService.clearCart(); 13 | return result; 14 | } 15 | 16 | getOrders() { 17 | return this.db.list('/orders'); 18 | } 19 | 20 | getOrdersByUser(userId: string) { 21 | return this.db.list('/orders', { 22 | query: { 23 | orderByChild: 'userId', 24 | equalTo: userId 25 | } 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/app/shared/services/product.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { ProductService } from './product.service'; 4 | 5 | describe('ProductService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [ProductService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([ProductService], (service: ProductService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/shared/services/product.service.ts: -------------------------------------------------------------------------------- 1 | import { AngularFireDatabase } from 'angularfire2/database'; 2 | import { Injectable } from '@angular/core'; 3 | 4 | @Injectable() 5 | export class ProductService { 6 | 7 | constructor(private db: AngularFireDatabase) { } 8 | 9 | create(product) { 10 | return this.db.list('/products').push(product); 11 | } 12 | 13 | getAll() { 14 | return this.db.list('/products'); 15 | } 16 | 17 | get(productId) { 18 | return this.db.object('/products/' + productId); 19 | } 20 | 21 | update(productId, product) { 22 | return this.db.object('/products/' + productId).update(product); 23 | } 24 | 25 | delete(productId) { 26 | return this.db.object('/products/' + productId).remove(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/app/shared/services/shopping-cart.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { ShoppingCartService } from './shopping-cart.service'; 4 | 5 | describe('ShoppingCartService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [ShoppingCartService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([ShoppingCartService], (service: ShoppingCartService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/shared/services/shopping-cart.service.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs/Observable'; 2 | import { ShoppingCart } from '../models/shopping-cart'; 3 | import { Product } from '../models/product'; 4 | import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database'; 5 | import { Injectable } from '@angular/core'; 6 | import 'rxjs/add/operator/take'; 7 | import 'rxjs/add/operator/map'; 8 | 9 | @Injectable() 10 | export class ShoppingCartService { 11 | 12 | constructor(private db: AngularFireDatabase) { } 13 | 14 | async getCart(): Promise> { 15 | let cartId = await this.getOrCreateCartId(); 16 | return this.db.object('/shopping-carts/' + cartId) 17 | .map(x => new ShoppingCart(x.items)); 18 | } 19 | 20 | async addToCart(product: Product) { 21 | this.updateItem(product, 1); 22 | } 23 | 24 | async removeFromCart(product: Product) { 25 | this.updateItem(product, -1); 26 | } 27 | 28 | async clearCart() { 29 | let cartId = await this.getOrCreateCartId(); 30 | this.db.object('/shopping-carts/' + cartId + '/items').remove(); 31 | } 32 | 33 | 34 | private create() { 35 | return this.db.list('/shopping-carts').push({ 36 | dateCreated: new Date().getTime() 37 | }); 38 | } 39 | 40 | private getItem(cartId: string, productId: string) { 41 | return this.db.object('/shopping-carts/' + cartId + '/items/' + productId); 42 | } 43 | 44 | private async getOrCreateCartId(): Promise { 45 | let cartId = localStorage.getItem('cartId'); 46 | if (cartId) return cartId; 47 | 48 | let result = await this.create(); 49 | localStorage.setItem('cartId', result.key); 50 | return result.key; 51 | } 52 | 53 | private async updateItem(product: Product, change: number) { 54 | let cartId = await this.getOrCreateCartId(); 55 | let item$ = this.getItem(cartId, product.$key); 56 | item$.take(1).subscribe(item => { 57 | let quantity = (item.quantity || 0) + change; 58 | if (quantity === 0) item$.remove(); 59 | else item$.update({ 60 | title: product.title, 61 | imageUrl: product.imageUrl, 62 | price: product.price, 63 | quantity: quantity 64 | }); 65 | }); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/app/shared/services/user.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { UserService } from './user.service'; 4 | 5 | describe('UserService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [UserService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([UserService], (service: UserService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/shared/services/user.service.ts: -------------------------------------------------------------------------------- 1 | import { AppUser } from '../models/app-user'; 2 | import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database'; 3 | import { Injectable } from '@angular/core'; 4 | import * as firebase from 'firebase'; 5 | 6 | @Injectable() 7 | export class UserService { 8 | 9 | constructor(private db: AngularFireDatabase) { } 10 | 11 | save(user: firebase.User) { 12 | this.db.object('/users/' + user.uid).update({ 13 | name: user.displayName, 14 | email: user.email 15 | }); 16 | } 17 | 18 | get(uid: string): FirebaseObjectObservable { 19 | return this.db.object('/users/' + uid); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; 2 | import { AngularFireAuthModule } from 'angularfire2/auth'; 3 | import { AngularFireDatabaseModule } from 'angularfire2/database'; 4 | import { DataTableModule } from 'angular-4-data-table/dist'; 5 | import { CustomFormsModule } from 'ng2-validation'; 6 | import { FormsModule } from '@angular/forms'; 7 | import { CommonModule } from '@angular/common'; 8 | import { NgModule } from '@angular/core'; 9 | 10 | import { ProductCardComponent } from './components/product-card/product-card.component'; 11 | import { ProductQuantityComponent } from './components/product-quantity/product-quantity.component'; 12 | import { AuthGuard } from './services/auth-guard.service'; 13 | import { AuthService } from './services/auth.service'; 14 | import { CategoryService } from './services/category.service'; 15 | import { OrderService } from './services/order.service'; 16 | import { ProductService } from './services/product.service'; 17 | import { ShoppingCartService } from './services/shopping-cart.service'; 18 | import { UserService } from './services/user.service'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | CommonModule, 23 | FormsModule, 24 | CustomFormsModule, 25 | DataTableModule, 26 | AngularFireDatabaseModule, 27 | AngularFireAuthModule, 28 | NgbModule.forRoot(), 29 | ], 30 | declarations: [ 31 | ProductCardComponent, 32 | ProductQuantityComponent, 33 | ], 34 | exports: [ 35 | ProductCardComponent, 36 | ProductQuantityComponent, 37 | CommonModule, 38 | FormsModule, 39 | CustomFormsModule, 40 | DataTableModule, 41 | AngularFireDatabaseModule, 42 | AngularFireAuthModule, 43 | NgbModule.forRoot().ngModule, 44 | ], 45 | providers: [ 46 | AuthService, 47 | AuthGuard, 48 | UserService, 49 | CategoryService, 50 | ProductService, 51 | ShoppingCartService, 52 | OrderService 53 | ] 54 | }) 55 | export class SharedModule { } 56 | -------------------------------------------------------------------------------- /src/app/shopping/components/check-out/check-out.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/shopping/components/check-out/check-out.component.css -------------------------------------------------------------------------------- /src/app/shopping/components/check-out/check-out.component.html: -------------------------------------------------------------------------------- 1 |

Shipping

2 |
3 |
4 | 5 |
6 |
7 | 8 |
9 |
10 | -------------------------------------------------------------------------------- /src/app/shopping/components/check-out/check-out.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CheckOutComponent } from './check-out.component'; 4 | 5 | describe('CheckOutComponent', () => { 6 | let component: CheckOutComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CheckOutComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CheckOutComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shopping/components/check-out/check-out.component.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs/Observable'; 2 | import { ShoppingCart } from '../../../shared/models/shopping-cart'; 3 | import { ShoppingCartService } from '../../../shared/services/shopping-cart.service'; 4 | import { Component, OnInit } from '@angular/core'; 5 | 6 | @Component({ 7 | selector: 'app-check-out', 8 | templateUrl: './check-out.component.html', 9 | styleUrls: ['./check-out.component.css'] 10 | }) 11 | export class CheckOutComponent implements OnInit{ 12 | cart$: Observable; 13 | 14 | constructor(private shoppingCartService: ShoppingCartService) {} 15 | 16 | async ngOnInit() { 17 | this.cart$ = await this.shoppingCartService.getCart(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/app/shopping/components/my-orders/my-orders.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/shopping/components/my-orders/my-orders.component.css -------------------------------------------------------------------------------- /src/app/shopping/components/my-orders/my-orders.component.html: -------------------------------------------------------------------------------- 1 |

Orders

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 |
CustomerDate
{{ order.shipping.name }}{{ order.datePlaced | date}} 15 | View 16 |
-------------------------------------------------------------------------------- /src/app/shopping/components/my-orders/my-orders.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { MyOrdersComponent } from './my-orders.component'; 4 | 5 | describe('MyOrdersComponent', () => { 6 | let component: MyOrdersComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ MyOrdersComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(MyOrdersComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shopping/components/my-orders/my-orders.component.ts: -------------------------------------------------------------------------------- 1 | import { AuthService } from 'shared/services/auth.service'; 2 | import { OrderService } from '../../../shared/services/order.service'; 3 | import { Component, OnInit } from '@angular/core'; 4 | import 'rxjs/add/operator/switchMap'; 5 | 6 | @Component({ 7 | selector: 'app-my-orders', 8 | templateUrl: './my-orders.component.html', 9 | styleUrls: ['./my-orders.component.css'] 10 | }) 11 | export class MyOrdersComponent { 12 | orders$; 13 | 14 | constructor( 15 | private authService: AuthService, 16 | private orderService: OrderService) { 17 | 18 | this.orders$ = authService.user$.switchMap(u => orderService.getOrdersByUser(u.uid)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/app/shopping/components/order-success/order-success.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/shopping/components/order-success/order-success.component.css -------------------------------------------------------------------------------- /src/app/shopping/components/order-success/order-success.component.html: -------------------------------------------------------------------------------- 1 |

Thank you!

2 |

We received your order and will process it within the next 24 hours!

-------------------------------------------------------------------------------- /src/app/shopping/components/order-success/order-success.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { OrderSuccessComponent } from './order-success.component'; 4 | 5 | describe('OrderSuccessComponent', () => { 6 | let component: OrderSuccessComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ OrderSuccessComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(OrderSuccessComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shopping/components/order-success/order-success.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-order-success', 5 | templateUrl: './order-success.component.html', 6 | styleUrls: ['./order-success.component.css'] 7 | }) 8 | export class OrderSuccessComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/shopping/components/products/product-filter/product-filter.component.css: -------------------------------------------------------------------------------- 1 | 2 | .sticky-top { 3 | top: 80px; 4 | } -------------------------------------------------------------------------------- /src/app/shopping/components/products/product-filter/product-filter.component.html: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /src/app/shopping/components/products/product-filter/product-filter.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ProductFilterComponent } from './product-filter.component'; 4 | 5 | describe('ProductFilterComponent', () => { 6 | let component: ProductFilterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ProductFilterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ProductFilterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shopping/components/products/product-filter/product-filter.component.ts: -------------------------------------------------------------------------------- 1 | import { CategoryService } from '../../../../shared/services/category.service'; 2 | import { Component, OnInit, Input } from '@angular/core'; 3 | 4 | @Component({ 5 | selector: 'product-filter', 6 | templateUrl: './product-filter.component.html', 7 | styleUrls: ['./product-filter.component.css'] 8 | }) 9 | export class ProductFilterComponent implements OnInit { 10 | categories$; 11 | @Input('category') category; 12 | 13 | constructor(categoryService: CategoryService) { 14 | this.categories$ = categoryService.getAll(); 15 | } 16 | 17 | ngOnInit() { 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/app/shopping/components/products/products.component.css: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/shopping/components/products/products.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | 5 |
6 |
7 |
8 | 9 |
10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 | 18 | -------------------------------------------------------------------------------- /src/app/shopping/components/products/products.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ProductsComponent } from './products.component'; 4 | 5 | describe('ProductsComponent', () => { 6 | let component: ProductsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ProductsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ProductsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shopping/components/products/products.component.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCart } from '../../../shared/models/shopping-cart'; 2 | import { Observable } from 'rxjs/Observable'; 3 | import { ShoppingCartService } from '../../../shared/services/shopping-cart.service'; 4 | import { Product } from '../../../shared/models/product'; 5 | import { ActivatedRoute } from '@angular/router'; 6 | import { ProductService } from '../../../shared/services/product.service'; 7 | import { Component, OnInit } from '@angular/core'; 8 | import 'rxjs/add/operator/switchMap'; 9 | 10 | @Component({ 11 | selector: 'app-products', 12 | templateUrl: './products.component.html', 13 | styleUrls: ['./products.component.css'] 14 | }) 15 | export class ProductsComponent implements OnInit { 16 | products: Product[] = []; 17 | filteredProducts: Product[] = []; 18 | category: string; 19 | cart$: Observable; 20 | 21 | constructor( 22 | private route: ActivatedRoute, 23 | private productService: ProductService, 24 | private shoppingCartService: ShoppingCartService 25 | ) { 26 | } 27 | 28 | async ngOnInit() { 29 | this.cart$ = await this.shoppingCartService.getCart(); 30 | this.populateProducts(); 31 | } 32 | 33 | private populateProducts() { 34 | this.productService 35 | .getAll() 36 | .switchMap(products => { 37 | this.products = products; 38 | return this.route.queryParamMap; 39 | }) 40 | .subscribe(params => { 41 | this.category = params.get('category'); 42 | this.applyFilter(); 43 | }); 44 | } 45 | 46 | 47 | private applyFilter() { 48 | this.filteredProducts = (this.category) ? 49 | this.products.filter(p => p.category === this.category) : 50 | this.products; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/app/shopping/components/shipping-form/shipping-form.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/shopping/components/shipping-form/shipping-form.component.css -------------------------------------------------------------------------------- /src/app/shopping/components/shipping-form/shipping-form.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 |
6 |
Name is required.
7 |
8 |
9 |
10 | 11 | 12 |
13 |
Address Line 1 is required.
14 |
15 |
16 |
17 | 18 | 19 |
20 |
Address Line 2 is required.
21 |
22 |
23 |
24 | 25 | 26 |
27 |
City is required.
28 |
29 |
30 | 34 |
35 | -------------------------------------------------------------------------------- /src/app/shopping/components/shipping-form/shipping-form.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ShippingFormComponent } from './shipping-form.component'; 4 | 5 | describe('ShippingFormComponent', () => { 6 | let component: ShippingFormComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ShippingFormComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ShippingFormComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shopping/components/shipping-form/shipping-form.component.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCart } from '../../../shared/models/shopping-cart'; 2 | import { OrderService } from '../../../shared/services/order.service'; 3 | import { AuthService } from '../../../shared/services/auth.service'; 4 | import { Router } from '@angular/router'; 5 | import { Subscription } from 'rxjs/Subscription'; 6 | import { Component, OnInit, OnDestroy, Input } from '@angular/core'; 7 | import { Order } from "../../../shared/models/order"; 8 | 9 | @Component({ 10 | selector: 'shipping-form', 11 | templateUrl: './shipping-form.component.html', 12 | styleUrls: ['./shipping-form.component.css'] 13 | }) 14 | export class ShippingFormComponent implements OnInit, OnDestroy { 15 | @Input('cart') cart: ShoppingCart; 16 | shipping = {}; 17 | userSubscription: Subscription; 18 | userId: string; 19 | 20 | constructor( 21 | private router: Router, 22 | private authService: AuthService, 23 | private orderService: OrderService) { 24 | } 25 | 26 | ngOnInit() { 27 | this.userSubscription = this.authService.user$.subscribe(user => this.userId = user.uid); 28 | } 29 | 30 | ngOnDestroy() { 31 | this.userSubscription.unsubscribe(); 32 | } 33 | 34 | async placeOrder() { 35 | let order = new Order(this.userId, this.shipping, this.cart); 36 | let result = await this.orderService.placeOrder(order); 37 | this.router.navigate(['/order-success', result.key]); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/app/shopping/components/shopping-cart-summary/shopping-cart-summary.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/app/shopping/components/shopping-cart-summary/shopping-cart-summary.component.css -------------------------------------------------------------------------------- /src/app/shopping/components/shopping-cart-summary/shopping-cart-summary.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Order Summary

4 |

You have {{ cart.totalItemsCount }} items in your shopping cart.

5 |
    6 |
  • 7 | {{ item.quantity }} x {{ item.title }} 8 |
    9 | {{ item.totalPrice | currency:'USD':true }} 10 |
    11 |
  • 12 |
  • 13 | Total 14 |
    15 | {{ cart.totalPrice | currency:'USD':true }} 16 |
    17 |
  • 18 |
19 |
20 |
-------------------------------------------------------------------------------- /src/app/shopping/components/shopping-cart-summary/shopping-cart-summary.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ShoppingCartSummaryComponent } from './shopping-cart-summary.component'; 4 | 5 | describe('ShoppingCartSummaryComponent', () => { 6 | let component: ShoppingCartSummaryComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ShoppingCartSummaryComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ShoppingCartSummaryComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shopping/components/shopping-cart-summary/shopping-cart-summary.component.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCart } from '../../../shared/models/shopping-cart'; 2 | import { Component, OnInit, Input } from '@angular/core'; 3 | 4 | @Component({ 5 | selector: 'shopping-cart-summary', 6 | templateUrl: './shopping-cart-summary.component.html', 7 | styleUrls: ['./shopping-cart-summary.component.css'] 8 | }) 9 | export class ShoppingCartSummaryComponent { 10 | @Input('cart') cart: ShoppingCart; 11 | } 12 | -------------------------------------------------------------------------------- /src/app/shopping/components/shopping-cart/shopping-cart.component.css: -------------------------------------------------------------------------------- 1 | 2 | .thumbnail { 3 | width: 80px; 4 | height: 80px; 5 | border-radius: 100%; 6 | background-size: cover; 7 | } 8 | 9 | .card { 10 | margin-bottom: 80px; 11 | } -------------------------------------------------------------------------------- /src/app/shopping/components/shopping-cart/shopping-cart.component.html: -------------------------------------------------------------------------------- 1 |

Shopping Cart

2 |
3 |
4 |

5 | You have {{ cart.totalItemsCount }} items in your shopping cart. 6 | 7 | 8 |

9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 28 | 32 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 48 | 49 | 50 |
ProductQuantityPrice
22 |
23 |
24 |
26 | {{ item.title }} 27 | 29 | 30 | 31 | 33 | {{ item.totalPrice | currency:'USD':true }} 34 |
{{ cart.totalPrice | currency:'USD':true }}
46 | Check Out 47 |
51 |
-------------------------------------------------------------------------------- /src/app/shopping/components/shopping-cart/shopping-cart.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ShoppingCartComponent } from './shopping-cart.component'; 4 | 5 | describe('ShoppingCartComponent', () => { 6 | let component: ShoppingCartComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ShoppingCartComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ShoppingCartComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shopping/components/shopping-cart/shopping-cart.component.ts: -------------------------------------------------------------------------------- 1 | import { ShoppingCartService } from '../../../shared/services/shopping-cart.service'; 2 | import { Component, OnInit } from '@angular/core'; 3 | 4 | @Component({ 5 | selector: 'app-shopping-cart', 6 | templateUrl: './shopping-cart.component.html', 7 | styleUrls: ['./shopping-cart.component.css'] 8 | }) 9 | export class ShoppingCartComponent implements OnInit { 10 | cart$; 11 | 12 | constructor(private shoppingCartService: ShoppingCartService) { } 13 | 14 | async ngOnInit() { 15 | this.cart$ = await this.shoppingCartService.getCart(); 16 | } 17 | 18 | clearCart() { 19 | this.shoppingCartService.clearCart(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app/shopping/shopping.module.ts: -------------------------------------------------------------------------------- 1 | import { SharedModule } from './../shared/shared.module'; 2 | import { AuthGuard } from 'shared/services/auth-guard.service'; 3 | import { RouterModule } from '@angular/router'; 4 | import { FormsModule } from '@angular/forms'; 5 | import { CommonModule } from '@angular/common'; 6 | import { NgModule } from '@angular/core'; 7 | 8 | import { CheckOutComponent } from './components/check-out/check-out.component'; 9 | import { MyOrdersComponent } from './components/my-orders/my-orders.component'; 10 | import { OrderSuccessComponent } from './components/order-success/order-success.component'; 11 | import { ProductFilterComponent } from './components/products/product-filter/product-filter.component'; 12 | import { ProductsComponent } from './components/products/products.component'; 13 | import { ShippingFormComponent } from './components/shipping-form/shipping-form.component'; 14 | import { ShoppingCartSummaryComponent } from './components/shopping-cart-summary/shopping-cart-summary.component'; 15 | import { ShoppingCartComponent } from './components/shopping-cart/shopping-cart.component'; 16 | 17 | @NgModule({ 18 | imports: [ 19 | SharedModule, 20 | RouterModule.forChild([ 21 | { path: 'products', component: ProductsComponent }, 22 | { path: 'shopping-cart', component: ShoppingCartComponent }, 23 | { path: 'check-out', component: CheckOutComponent, canActivate: [AuthGuard] }, 24 | { path: 'order-success/:id', component: OrderSuccessComponent, canActivate: [AuthGuard] }, 25 | { path: 'my/orders', component: MyOrdersComponent, canActivate: [AuthGuard] }, 26 | ]) 27 | ], 28 | declarations: [ 29 | ProductsComponent, 30 | ShoppingCartComponent, 31 | CheckOutComponent, 32 | OrderSuccessComponent, 33 | MyOrdersComponent, 34 | ProductFilterComponent, 35 | ShoppingCartSummaryComponent, 36 | ShippingFormComponent 37 | ] 38 | }) 39 | export class ShoppingModule { } 40 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | firebase: { 4 | apiKey: "AIzaSyAwxo8Bt7ZeYfFLI5WrakbNGtJsskBv3wA", 5 | authDomain: "oshop-f3445.firebaseapp.com", 6 | databaseURL: "https://oshop-f3445.firebaseio.com", 7 | projectId: "oshop-f3445", 8 | storageBucket: "oshop-f3445.appspot.com", 9 | messagingSenderId: "223112932947" 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /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 | firebase: { 9 | apiKey: "AIzaSyAwxo8Bt7ZeYfFLI5WrakbNGtJsskBv3wA", 10 | authDomain: "oshop-f3445.firebaseapp.com", 11 | databaseURL: "https://oshop-f3445.firebaseio.com", 12 | projectId: "oshop-f3445", 13 | storageBucket: "oshop-f3445.appspot.com", 14 | messagingSenderId: "223112932947" 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mosh-hamedani/organic-shop/260f5acee75db60c76d5ce007b7bf371b4d59400/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Oshop 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import "~bootstrap/dist/css/bootstrap.css"; 3 | @import "~font-awesome/css/font-awesome.css"; 4 | 5 | $primary-color: #c1d62e; 6 | $primary-color-hover: #b1c522; 7 | 8 | body { 9 | padding-top: 80px; 10 | } 11 | 12 | h1, h2, h3 { 13 | margin-bottom: 1.5rem; 14 | } 15 | 16 | .navbar { 17 | border-bottom: 3px solid #e7e7e7; 18 | } 19 | 20 | .navbar-light .navbar-brand { 21 | color: $primary-color; 22 | } 23 | 24 | .navbar-light .navbar-brand:focus, .navbar-light .navbar-brand:hover { 25 | color: $primary-color-hover; 26 | } 27 | 28 | .list-group-item.active { 29 | background-color: $primary-color; 30 | border-color: $primary-color; 31 | } 32 | 33 | .btn-primary { 34 | background-color: $primary-color; 35 | border-color: $primary-color; 36 | } 37 | 38 | .btn-primary:hover { 39 | background-color: $primary-color-hover; 40 | border-color: $primary-color-hover; 41 | } 42 | 43 | .btn-primary.disabled, .btn-primary:disabled { 44 | background-color: $primary-color; 45 | border-color: $primary-color; 46 | } 47 | 48 | .form-control:focus { 49 | border-color: $primary-color; 50 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /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 | "baseUrl": "./src", 19 | "paths": { 20 | "shared/*": [ 21 | "app/shared/*" 22 | ] 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /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 | true, 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 | "app", 121 | "camelCase" 122 | ], 123 | "component-selector": [ 124 | true, 125 | "element", 126 | "app", 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 | --------------------------------------------------------------------------------