├── .angular-cli.json
├── .editorconfig
├── .gitignore
├── .vscode
└── settings.json
├── README.md
├── database.rules.json
├── e2e
├── app.e2e-spec.ts
├── app.po.ts
└── tsconfig.e2e.json
├── firebase.json
├── functions
├── index.js
└── package.json
├── karma.conf.js
├── package-lock.json
├── package.json
├── protractor.conf.js
├── src
├── app
│ ├── app-routing.module.ts
│ ├── app.component.css
│ ├── app.component.html
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── auth
│ │ ├── auth.guard.ts
│ │ ├── auth.service.spec.ts
│ │ └── auth.service.ts
│ ├── company
│ │ ├── company-edit
│ │ │ ├── company-edit.component.css
│ │ │ ├── company-edit.component.html
│ │ │ └── company-edit.component.ts
│ │ ├── company-list
│ │ │ ├── company-list.component.css
│ │ │ ├── company-list.component.html
│ │ │ └── company-list.component.ts
│ │ ├── company.service.ts
│ │ └── company.ts
│ ├── contact
│ │ ├── contact-edit
│ │ │ ├── contact-edit.component.css
│ │ │ ├── contact-edit.component.html
│ │ │ └── contact-edit.component.ts
│ │ ├── contact-list
│ │ │ ├── contact-list.component.css
│ │ │ ├── contact-list.component.html
│ │ │ └── contact-list.component.ts
│ │ ├── contact.service.ts
│ │ └── contact.ts
│ ├── home
│ │ ├── home.component.css
│ │ ├── home.component.html
│ │ └── home.component.ts
│ └── state
│ │ ├── appState.ts
│ │ ├── company.actions.ts
│ │ ├── company.effects.ts
│ │ └── company.reducers.ts
├── assets
│ ├── .gitkeep
│ └── branching-info.png
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── main.ts
├── polyfills.ts
├── styles.css
├── test.ts
├── tsconfig.app.json
├── tsconfig.spec.json
└── typings.d.ts
├── tsconfig.json
└── tslint.json
/.angular-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "project": {
4 | "name": "angularfire"
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.css"
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 | },
41 | {
42 | "project": "src/tsconfig.spec.json"
43 | },
44 | {
45 | "project": "e2e/tsconfig.e2e.json"
46 | }
47 | ],
48 | "test": {
49 | "karma": {
50 | "config": "./karma.conf.js"
51 | }
52 | },
53 | "defaults": {
54 | "styleExt": "css",
55 | "component": {}
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.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 | /functions/node_modules
11 |
12 | # IDEs and editors
13 | /.idea
14 | .project
15 | .classpath
16 | .c9/
17 | *.launch
18 | .settings/
19 | *.sublime-workspace
20 |
21 | # IDE - VSCode
22 | .vscode/*
23 | !.vscode/settings.json
24 | !.vscode/tasks.json
25 | !.vscode/launch.json
26 | !.vscode/extensions.json
27 |
28 | # misc
29 | /.sass-cache
30 | /connect.lock
31 | /coverage
32 | /libpeerconnection.log
33 | npm-debug.log
34 | testem.log
35 | /typings
36 |
37 | # e2e
38 | /e2e/*.js
39 | /e2e/*.map
40 |
41 | # System Files
42 | .DS_Store
43 | Thumbs.db
44 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "typescript.tsdk": "node_modules/typescript/lib"
3 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Building Apps With AngularFire Course
2 |
3 | > !!! IMPORTANT This course is for the previous version of Angularfire2 (v4). This course now is a good way to learn the concepts of Angularfire and the Realtime DB or if you are developing on V4 of Angularfire 2 this is a great course.
4 |
5 | > For those wanting to use the new Firestore database from Google or use the latest Angularfire2 v5+ then this code will need to be adapted. Due to the many syntactic changes in Angularfire2 (v5) a whole new course needs to be recorded for Pluralsight, which I aim to do in the future.
6 |
7 | ## How to install code for each course module
8 | > All before and after code demos are in branches you can clone and run.
9 | 
10 |
11 | To clone a branch from this GitHub repo run the following commands:
12 | 1. Clone the repo in to a directory of choice
13 | ```
14 | git clone "https://github.com/duncanhunter/AngularFireCourse"
15 | ```
16 | 2. Change directory into the project folder
17 | ```
18 | cd AngularFireCourse
19 | ```
20 | 3. Check out all branches for each part of the course
21 | ```
22 | git branch --all
23 | ```
24 | 4. Change to a particular part of the course code and install packages with npm install
25 | ```
26 | git checkout --quiet m4-start
27 |
28 | npm install
29 | ```
30 | 5. Run ng serve to run the code and open the broswer at localhost:4200
31 | ```
32 | ng serve --open
33 | ```
34 |
35 | ## Changes/Fixes
36 |
37 | #### 2/10/2017
38 | - Update material.angular.io install video and all code branches to show individual Material component modules being installed. In module Retrieving and Working with Firebase Objects > Adding Angular Material.
39 | - Update video showing old reference of how to import AngularFire vs AngularFireDatabase in module Installation and Setup > Configure and Install AngularFire.
40 | - Updated missing half screen in module Querying Firebase Lists With Observables > Multipath Updates Demo.
41 | - Added all code branches and info to this GitHub repo
42 |
--------------------------------------------------------------------------------
/database.rules.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | ".read": "auth != null",
4 | ".write": "auth != null"
5 | }
6 | }
--------------------------------------------------------------------------------
/e2e/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AngularfirePage } from './app.po';
2 |
3 | describe('angularfire App', () => {
4 | let page: AngularfirePage;
5 |
6 | beforeEach(() => {
7 | page = new AngularfirePage();
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 AngularfirePage {
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 | "database": {
3 | "rules": "database.rules.json"
4 | },
5 | "hosting": {
6 | "public": "dist",
7 | "rewrites": [
8 | {
9 | "source": "**",
10 | "destination": "/index.html"
11 | }
12 | ]
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/functions/index.js:
--------------------------------------------------------------------------------
1 | var functions = require('firebase-functions');
2 |
3 | // // Create and Deploy Your First Cloud Functions
4 | // // https://firebase.google.com/docs/functions/write-firebase-functions
5 | //
6 | // exports.helloWorld = functions.https.onRequest((request, response) => {
7 | // response.send("Hello from Firebase!");
8 | // });
9 |
--------------------------------------------------------------------------------
/functions/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "functions",
3 | "description": "Cloud Functions for Firebase",
4 | "dependencies": {
5 | "firebase-admin": "^4.1.2",
6 | "firebase-functions": "^0.5"
7 | },
8 | "private": true
9 | }
10 |
--------------------------------------------------------------------------------
/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": "angularfire",
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.4.4",
16 | "@angular/cdk": "^2.0.0-beta.11",
17 | "@angular/common": "^4.0.0",
18 | "@angular/compiler": "^4.0.0",
19 | "@angular/core": "^4.0.0",
20 | "@angular/flex-layout": "^2.0.0-beta.9",
21 | "@angular/forms": "^4.0.0",
22 | "@angular/http": "^4.0.0",
23 | "@angular/material": "^2.0.0-beta.11",
24 | "@angular/platform-browser": "^4.0.0",
25 | "@angular/platform-browser-dynamic": "^4.0.0",
26 | "@angular/router": "^4.0.0",
27 | "@ngrx/effects": "^4.0.1",
28 | "@ngrx/store": "^4.0.0",
29 | "@ngrx/store-devtools": "^4.0.0",
30 | "angularfire2": "^4.0.0-rc.1",
31 | "core-js": "^2.4.1",
32 | "firebase": "4.1.3",
33 | "hammerjs": "^2.0.8",
34 | "rxjs": "^5.1.0",
35 | "zone.js": "^0.8.4"
36 | },
37 | "devDependencies": {
38 | "@angular/cli": "1.2.1",
39 | "@angular/compiler-cli": "^4.0.0",
40 | "@angular/language-service": "^4.0.0",
41 | "@types/jasmine": "~2.5.53",
42 | "@types/jasminewd2": "~2.0.2",
43 | "@types/node": "~6.0.60",
44 | "codelyzer": "~3.0.1",
45 | "jasmine-core": "~2.6.2",
46 | "jasmine-spec-reporter": "~4.1.0",
47 | "karma": "~1.7.0",
48 | "karma-chrome-launcher": "~2.1.1",
49 | "karma-cli": "~1.0.1",
50 | "karma-coverage-istanbul-reporter": "^1.2.1",
51 | "karma-jasmine": "~1.1.0",
52 | "karma-jasmine-html-reporter": "^0.2.2",
53 | "protractor": "~5.1.2",
54 | "ts-node": "~3.0.4",
55 | "tslint": "~5.3.2",
56 | "typescript": "~2.3.3"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/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/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { CompanyListComponent } from './company/company-list/company-list.component';
4 | import { CompanyEditComponent } from './company/company-edit/company-edit.component';
5 | import { ContactListComponent } from './contact/contact-list/contact-list.component';
6 | import { ContactEditComponent } from './contact/contact-edit/contact-edit.component';
7 | import { HomeComponent } from './home/home.component';
8 | import { AuthGuard } from './auth/auth.guard';
9 |
10 | const routes: Routes = [
11 | { path: '', pathMatch: 'full', redirectTo: 'home' },
12 | { path: 'home', component: HomeComponent },
13 | { path: 'company-list', component: CompanyListComponent, canActivate: [AuthGuard] },
14 | { path: 'company-edit/:id', component: CompanyEditComponent, canActivate: [AuthGuard] },
15 | { path: 'contact-list', component: ContactListComponent, canActivate: [AuthGuard] },
16 | { path: 'contact-edit/:id', component: ContactEditComponent, canActivate: [AuthGuard] }
17 | ];
18 |
19 | @NgModule({
20 | imports: [RouterModule.forRoot(routes)],
21 | exports: [RouterModule]
22 | })
23 | export class AppRoutingModule { }
24 |
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
1 | .nav-buttons {
2 | width: 100%;
3 | }
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Output } from '@angular/core';
2 | import { AuthService } from './auth/auth.service';
3 |
4 | @Component({
5 | selector: 'app-root',
6 | templateUrl: './app.component.html',
7 | styleUrls: ['./app.component.css']
8 | })
9 | export class AppComponent {
10 |
11 | constructor(public authService: AuthService) {
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import 'hammerjs';
2 | import 'firebase/storage'; // global firebase storage js;
3 | import { BrowserModule } from '@angular/platform-browser';
4 | import { NgModule } from '@angular/core';
5 | import { FormsModule } from '@angular/forms';
6 | import { HttpModule } from '@angular/http';
7 | import { AppRoutingModule } from './app-routing.module';
8 | import { AngularFireModule } from 'angularfire2';
9 | import { AppComponent } from './app.component';
10 | import { environment } from '../environments/environment.prod';
11 | import { AngularFireDatabaseModule } from 'angularfire2/database';
12 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
13 | import { FlexLayoutModule } from '@angular/flex-layout';
14 | import { CompanyEditComponent } from './company/company-edit/company-edit.component';
15 | import { CompanyService } from './company/company.service';
16 | import { CompanyListComponent } from './company/company-list/company-list.component';
17 | import { ContactService } from './contact/contact.service';
18 | import { ContactEditComponent } from './contact/contact-edit/contact-edit.component';
19 | import { ContactListComponent } from './contact/contact-list/contact-list.component';
20 | import { AuthService } from './auth/auth.service';
21 | import { AngularFireAuthModule } from 'angularfire2/auth';
22 | import { HomeComponent } from './home/home.component';
23 | import { AuthGuard } from './auth/auth.guard';
24 | import {
25 | MdButtonModule,
26 | MdCardModule,
27 | MdInputModule,
28 | MdToolbarModule,
29 | MdProgressBarModule,
30 | MdSelectModule
31 | } from '@angular/material';
32 |
33 | import { StoreModule } from '@ngrx/store';
34 | import { EffectsModule } from '@ngrx/effects';
35 | import { StoreDevtoolsModule } from '@ngrx/store-devtools';
36 |
37 | import { CompanyEffects } from './state/company.effects';
38 | import { companyReducer } from './state/company.reducers';
39 |
40 | @NgModule({
41 | declarations: [
42 | AppComponent,
43 | CompanyEditComponent,
44 | CompanyListComponent,
45 | ContactEditComponent,
46 | ContactListComponent,
47 | HomeComponent
48 | ],
49 | imports: [
50 | BrowserModule,
51 | FormsModule,
52 | HttpModule,
53 | AppRoutingModule,
54 | AngularFireModule.initializeApp(environment.firebaseConfig),
55 | AngularFireDatabaseModule,
56 | AngularFireAuthModule,
57 | BrowserAnimationsModule,
58 | FlexLayoutModule,
59 | MdButtonModule,
60 | MdCardModule,
61 | MdInputModule,
62 | MdToolbarModule,
63 | MdProgressBarModule,
64 | MdSelectModule,
65 | StoreModule.forRoot({ companies: companyReducer }),
66 | EffectsModule.forRoot([CompanyEffects]),
67 | StoreDevtoolsModule.instrument({
68 | maxAge: 25
69 | })
70 | ],
71 | providers: [
72 | AuthGuard,
73 | CompanyService,
74 | ContactService,
75 | AuthService
76 | ],
77 | bootstrap: [AppComponent]
78 | })
79 | export class AppModule { }
80 |
--------------------------------------------------------------------------------
/src/app/auth/auth.guard.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
3 | import { Observable } from 'rxjs/Observable';
4 | import { AuthService } from './auth.service';
5 |
6 | @Injectable()
7 | export class AuthGuard implements CanActivate {
8 |
9 | constructor(
10 | private router: Router,
11 | private authService: AuthService) { }
12 |
13 | canActivate(): Observable {
14 | return this.authService.user$
15 | .map(user => {
16 | if (user && user.uid) {
17 | return true;
18 | } else {
19 | this.router.navigate([`/home`]);
20 | return false;
21 | }
22 | });
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/app/auth/auth.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, inject } from '@angular/core/testing';
2 | import * as firebase from 'firebase/app';
3 | import { AuthService } from './auth.service';
4 | import { Subject } from 'rxjs/Subject';
5 |
6 | describe('AuthService', () => {
7 | let authService: AuthService;
8 | let authSubject: Subject;
9 |
10 | beforeEach(() => {
11 | authSubject = new Subject();
12 |
13 | TestBed.configureTestingModule({
14 | providers: [AuthService],
15 | });
16 | });
17 |
18 | it(`should create an authService`, () => {
19 | expect(authService).toBeTruthy();
20 | });
21 |
22 | it(`should have a subscribe to auth state changes`, () => {
23 | const firebaseUser = { uid: '12345' } as firebase.User;
24 |
25 | authService.user$.subscribe(user => {
26 | expect(user.uid).toEqual(firebaseUser.uid);
27 | });
28 |
29 | authSubject.next(firebaseUser);
30 | });
31 |
32 | });
33 |
--------------------------------------------------------------------------------
/src/app/auth/auth.service.ts:
--------------------------------------------------------------------------------
1 | import * as firebase from 'firebase/app';
2 | import { Injectable } from '@angular/core';
3 | import { Router } from '@angular/router';
4 | import { AngularFireAuth } from 'angularfire2/auth';
5 | import { Observable } from 'rxjs/Observable';
6 |
7 |
8 | @Injectable()
9 | export class AuthService {
10 | user$: Observable;
11 |
12 | constructor(
13 | private router: Router,
14 | public afAuth: AngularFireAuth
15 | ) {
16 | this.user$ = this.afAuth.authState;
17 | }
18 |
19 | login() {
20 | this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider())
21 | .then(_ => this.router.navigate([`/company-list`]))
22 | .catch(error => console.log('auth error', error));
23 | }
24 |
25 | logout() {
26 | this.afAuth.auth.signOut();
27 | this.router.navigate([`/home`]);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/app/company/company-edit/company-edit.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-Angular-Fire-Course/166af8496b744ae2da25b3334bc77f53fe646c41/src/app/company/company-edit/company-edit.component.css
--------------------------------------------------------------------------------
/src/app/company/company-edit/company-edit.component.html:
--------------------------------------------------------------------------------
1 | Company Edit
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/app/company/company-edit/company-edit.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database';
3 | import { CompanyService } from '../company.service';
4 | import { Router, ActivatedRoute } from '@angular/router';
5 | import { Observable } from 'rxjs/Observable';
6 | import { Company } from '../company';
7 |
8 | @Component({
9 | selector: 'app-company-edit',
10 | templateUrl: './company-edit.component.html',
11 | styleUrls: ['./company-edit.component.css']
12 | })
13 | export class CompanyEditComponent implements OnInit {
14 | isNewCompany: boolean;
15 | companyKey: string;
16 | company$: Observable;
17 |
18 | constructor(
19 | private router: Router,
20 | private activatedRoute: ActivatedRoute,
21 | private companyService: CompanyService) { }
22 |
23 | ngOnInit() {
24 | this.companyKey = this.activatedRoute.snapshot.params['id'];
25 | this.isNewCompany = this.companyKey === 'new';
26 | !this.isNewCompany ? this.getCompany() : this.company$ = Observable.of({}) as FirebaseObjectObservable;
27 | }
28 |
29 | getCompany() {
30 | this.company$ = this.companyService.getCompany(this.companyKey);
31 | }
32 |
33 | saveCompany(company) {
34 | const save = this.isNewCompany
35 | ? this.companyService.saveCompany(company)
36 | : this.companyService.editCompany(company);
37 |
38 | save.then(_ => this.router.navigate([`company-list`]));
39 | }
40 |
41 | removeCompany(company) {
42 | this.companyService.removeCompany(company)
43 | .then(_ => this.router.navigate([`company-list`]));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/app/company/company-list/company-list.component.css:
--------------------------------------------------------------------------------
1 | button[md-fab] {
2 | position: fixed;
3 | bottom: 25px;
4 | right: 25px;
5 | }
6 |
7 | md-card {
8 | margin: 10px;
9 | }
--------------------------------------------------------------------------------
/src/app/company/company-list/company-list.component.html:
--------------------------------------------------------------------------------
1 | Companies
2 |
3 | {{company.name}}
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/app/company/company-list/company-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, OnDestroy } from '@angular/core';
2 | import { CompanyService } from '../company.service';
3 | import { FirebaseListObservable } from 'angularfire2/database';
4 | import { Observable } from 'rxjs/Observable';
5 | import { Company } from '../company';
6 |
7 | import { AppState } from '../../state/appState';
8 | import { Store } from '@ngrx/store';
9 | import * as CompanyActions from './../../state/company.actions';
10 |
11 | @Component({
12 | selector: 'app-company-list',
13 | templateUrl: './company-list.component.html',
14 | styleUrls: ['./company-list.component.css']
15 | })
16 | export class CompanyListComponent implements OnDestroy {
17 | companies$: Observable;
18 |
19 | constructor(private store: Store) {
20 | this.store.dispatch(new CompanyActions.ConnectCompaniesAction());
21 | this.companies$ = this.store.select(state => state.companies);
22 | }
23 |
24 | ngOnDestroy() {
25 | this.store.dispatch(new CompanyActions.DisconnectCompaniesAction());
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/app/company/company.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { AngularFireDatabase, FirebaseObjectObservable, FirebaseListObservable } from 'angularfire2/database';
3 | import { Observable } from 'rxjs/Observable';
4 | import { Subject } from 'rxjs/Subject';
5 | import * as firebase from 'firebase/app';
6 |
7 | import * as CompanyActions from './../state/company.actions';
8 | import { Company } from './company';
9 | import 'rxjs/add/observable/from';
10 | import 'rxjs/add/operator/catch';
11 | import 'rxjs/add/operator/take';
12 | import { Action } from '@ngrx/store';
13 | import { ConnectCompaniesSuccessAction, UpdatedCompanySyncedAction, RemovedCompanySyncedAction } from '../state/company.actions';
14 |
15 | @Injectable()
16 | export class CompanyService {
17 | companies$: FirebaseListObservable;
18 | company$: FirebaseObjectObservable;
19 | companiesEventsSubject: Subject;
20 | companiesRef: firebase.database.Reference;
21 |
22 | constructor(private db: AngularFireDatabase) {
23 | this.company$ = this.db.object(`company`);
24 | this.companies$ = this.db.list(`companies`);
25 |
26 | this.companiesRef = this.db.list(`companies`).$ref.ref;
27 | this.companiesEventsSubject = new Subject();
28 | }
29 |
30 | getCompaniesEvents(): Observable {
31 | this.initConnectCompanies();
32 | return this.companiesEventsSubject.asObservable();
33 | }
34 |
35 | initConnectCompanies(): void {
36 | let initialDataLoaded = false;
37 |
38 | this.companies$
39 | .first()
40 | .subscribe(companies => {
41 | initialDataLoaded = true;
42 | this.companiesEventsSubject.next(new CompanyActions.ConnectCompaniesSuccessAction(companies));
43 | });
44 |
45 | this.companiesRef.on('child_added', (company) => {
46 | if (initialDataLoaded) {
47 | this.companiesEventsSubject.next(new CompanyActions.AddedCompanySyncedAction(this.companyTransform(company)));
48 | } else { }
49 | });
50 |
51 | this.companiesRef.on('child_changed', (company) => {
52 | this.companiesEventsSubject.next(new CompanyActions.UpdatedCompanySyncedAction(this.companyTransform(company)));
53 | });
54 |
55 | this.companiesRef.on('child_removed', (company) => {
56 | this.companiesEventsSubject.next(new CompanyActions.RemovedCompanySyncedAction(this.companyTransform(company)));
57 | });
58 | }
59 |
60 | diconnectCompanies(): void {
61 | this.companiesRef.off();
62 | }
63 |
64 | private companyTransform(c): Company {
65 | const company: Company = c.val();
66 | company.$key = c.key;
67 | return company;
68 | }
69 |
70 | getCompany(companyKey: string) {
71 | return this.db.object(`companies/${companyKey}`)
72 | .catch(this.errorHandler);
73 | }
74 |
75 | getCompanies() {
76 | return this.companies$
77 | .catch(this.errorHandler);
78 | }
79 |
80 | saveCompany(company: Company) {
81 | return this.companies$.push(company)
82 | .then(_ => console.log('success'))
83 | .catch(error => console.log(error));
84 | }
85 |
86 | editCompany(company: Company) {
87 | return this.companies$.update(company.$key, company)
88 | .then(_ => console.log('success'))
89 | .catch(error => console.log(error));
90 | }
91 |
92 | removeCompany(company) {
93 | return this.companies$.remove(company.$key)
94 | .then(_ => console.log('success'))
95 | .catch(error => console.log(error));
96 | }
97 |
98 | private errorHandler(error) {
99 | console.log(error);
100 | return Observable.throw(error.message);
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/app/company/company.ts:
--------------------------------------------------------------------------------
1 | export interface Company {
2 | $key: string;
3 | name: string;
4 | phone: string;
5 | }
6 |
--------------------------------------------------------------------------------
/src/app/contact/contact-edit/contact-edit.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-Angular-Fire-Course/166af8496b744ae2da25b3334bc77f53fe646c41/src/app/contact/contact-edit/contact-edit.component.css
--------------------------------------------------------------------------------
/src/app/contact/contact-edit/contact-edit.component.html:
--------------------------------------------------------------------------------
1 | Contact Edit
2 |
3 |
4 |
![contact image profile]()
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | {{company.name}}
13 |
14 |
15 |
16 |
17 | {{company.name}}
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/app/contact/contact-edit/contact-edit.component.ts:
--------------------------------------------------------------------------------
1 | import * as firebase from 'firebase/app'; // typings only
2 | import { Component, OnInit } from '@angular/core';
3 | import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database';
4 | import { ContactService } from '../contact.service';
5 | import { Router, ActivatedRoute } from '@angular/router';
6 | import { Observable } from 'rxjs/Observable';
7 | import { Contact } from '../contact';
8 | import { CompanyService } from '../../company/company.service';
9 | import { Company } from '../../company/company';
10 |
11 | @Component({
12 | selector: 'app-contact-edit',
13 | templateUrl: './contact-edit.component.html',
14 | styleUrls: ['./contact-edit.component.css']
15 | })
16 | export class ContactEditComponent implements OnInit {
17 | companies$: Observable;
18 | isNewContact: boolean;
19 | contactKey: string;
20 | contact = {name: ''} as Contact;
21 | selectedCompany: Company;
22 | contactCompanies = [];
23 |
24 | constructor(
25 | private router: Router,
26 | private activatedRoute: ActivatedRoute,
27 | private contactService: ContactService,
28 | private companyService: CompanyService) { }
29 |
30 | ngOnInit() {
31 | this.companies$ = this.companyService.getCompanies();
32 | this.contactKey = this.activatedRoute.snapshot.params['id'];
33 | this.isNewContact = this.contactKey === 'new';
34 | if (!this.isNewContact) { this.getContact(); };
35 | }
36 |
37 | uploadFile(event: any) {
38 | const file = event.srcElement.files[0];
39 | const storageRef = firebase.storage().ref(`contacts/${this.contactKey}`);
40 | storageRef.put(file)
41 | .then(uploadTask => this.contact.imageUrl = uploadTask.downloadURL);
42 | }
43 |
44 | addCompany() {
45 | this.contact.contactCompanies[this.selectedCompany.$key] = { name: this.selectedCompany.name };
46 | this.setContactCompanies();
47 | }
48 |
49 | getContact() {
50 | this.contactService.getContact(this.contactKey)
51 | .subscribe(contact => {
52 | this.contact = contact;
53 | this.setContactCompanies();
54 | });
55 | }
56 |
57 | setContactCompanies() {
58 | if (this.contact.contactCompanies == null) { this.contact.contactCompanies = {}; };
59 | this.contactCompanies = Object.keys(this.contact.contactCompanies).map(key => this.contact.contactCompanies[key]);
60 | }
61 |
62 | saveContact(contact) {
63 | const save = this.isNewContact
64 | ? this.contactService.saveContact(contact)
65 | : this.contactService.editContact(contact);
66 |
67 | save.then(_ => this.router.navigate([`contact-list`]));
68 | }
69 |
70 | removeContact(contact) {
71 | this.contactService.removeContact(contact)
72 | .then(_ => this.router.navigate([`contact-list`]));
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/app/contact/contact-list/contact-list.component.css:
--------------------------------------------------------------------------------
1 | button[md-fab] {
2 | position: fixed;
3 | bottom: 25px;
4 | right: 25px;
5 | }
6 |
7 | md-card {
8 | margin: 10px;
9 | }
--------------------------------------------------------------------------------
/src/app/contact/contact-list/contact-list.component.html:
--------------------------------------------------------------------------------
1 |
2 |
Contacts
3 |
4 | All
5 | {{company.name}}
6 |
7 |
8 |
9 | {{contact.name}}
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/app/contact/contact-list/contact-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ContactService } from '../contact.service';
3 | import { FirebaseListObservable } from 'angularfire2/database';
4 | import { Observable } from 'rxjs/Observable';
5 | import { Contact } from '../contact';
6 | import { CompanyService } from '../../company/company.service';
7 | import { Company } from '../../company/company';
8 |
9 | @Component({
10 | selector: 'app-contact-list',
11 | templateUrl: './contact-list.component.html',
12 | styleUrls: ['./contact-list.component.css']
13 | })
14 | export class ContactListComponent implements OnInit {
15 | companies$: Observable;
16 | contacts$: FirebaseListObservable | Observable;
17 |
18 | constructor(
19 | private companyService: CompanyService,
20 | public contactService: ContactService) { }
21 |
22 | ngOnInit() {
23 | this.companies$ = this.companyService.getCompanies();
24 | this.getContacts();
25 | }
26 |
27 | getContacts() {
28 | this.contacts$ = this.contactService.getContacts();
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/app/contact/contact.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { AngularFireDatabase, FirebaseObjectObservable, FirebaseListObservable } from 'angularfire2/database';
3 | import { Observable } from 'rxjs/Observable';
4 | import 'rxjs/add/observable/from';
5 | import 'rxjs/add/observable/combineLatest';
6 | import 'rxjs/add/operator/catch';
7 | import 'rxjs/add/operator/switchMap';
8 |
9 | import { Contact } from './contact';
10 | import { BehaviorSubject } from 'rxjs/BehaviorSubject';
11 |
12 | @Injectable()
13 | export class ContactService {
14 | subject$ = new BehaviorSubject(undefined);
15 | contacts$: FirebaseListObservable;
16 | contact$: FirebaseObjectObservable;
17 |
18 | constructor(private db: AngularFireDatabase) {
19 | this.contact$ = this.db.object(`contact`);
20 | this.contacts$ = this.db.list(`contacts`);
21 | }
22 |
23 | getContact(contactKey: string) {
24 | return this.db.object(`contacts/${contactKey}`)
25 | .catch(this.errorHandler);
26 | }
27 |
28 | getContacts() {
29 | return this.subject$
30 | .switchMap(companyKey => companyKey === undefined
31 | ? this.contacts$
32 | : this.db.list(`companyContacts/${companyKey}`))
33 | .catch(this.errorHandler);
34 | }
35 |
36 | // obs$: Observable;
37 | companyContactsJoin(companyKey) {
38 | return this.db.list(`companyContacts/${companyKey}`)
39 | .map(contactKeys => contactKeys
40 | .map(contact => this.db.object(`contacts/${contact.$key}`)))
41 | .switchMap(contactObsArray => contactObsArray.length >= 1
42 | ? Observable.combineLatest(contactObsArray)
43 | : Observable.of([]))
44 | .catch(this.errorHandler);
45 | }
46 |
47 | saveContact(contact: Contact) {
48 | return this.contacts$.push(contact)
49 | .then(_ => console.log('success'))
50 | .catch(error => console.log(error));
51 | }
52 |
53 | editContact(contact: Contact) {
54 | const updateContact = {};
55 |
56 | updateContact[`contacts/${contact.$key}`] = contact;
57 | Object.keys(contact.contactCompanies).forEach(companyKey => {
58 | updateContact[`companyContacts/${companyKey}/${contact.$key}`] = {name: contact.name};
59 | });
60 |
61 | return this.db.object('/').update(updateContact)
62 | .then(_ => console.log('success'))
63 | .catch(error => console.log(error));
64 | }
65 |
66 | removeContact(contact) {
67 | const removeContact = {};
68 |
69 | removeContact[`contacts/${contact.$key}`] = null;
70 | Object.keys(contact.contactCompanies).forEach(companyKey => {
71 | removeContact[`companyContacts/${companyKey}/${contact.$key}`] = null;
72 | });
73 |
74 | return this.db.object('/').update(removeContact)
75 | .then(_ => console.log('success'))
76 | .catch(error => console.log(error));
77 | }
78 |
79 | private errorHandler(error) {
80 | console.log(error);
81 | return Observable.throw(error.message);
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/app/contact/contact.ts:
--------------------------------------------------------------------------------
1 | export interface Contact {
2 | $key: string;
3 | name: string;
4 | phone: string;
5 | contactCompanies: {[key: string]: {name: string}};
6 | imageUrl?: string;
7 | }
8 |
--------------------------------------------------------------------------------
/src/app/home/home.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-Angular-Fire-Course/166af8496b744ae2da25b3334bc77f53fe646c41/src/app/home/home.component.css
--------------------------------------------------------------------------------
/src/app/home/home.component.html:
--------------------------------------------------------------------------------
1 |
2 | home works!
3 |
4 |
--------------------------------------------------------------------------------
/src/app/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/state/appState.ts:
--------------------------------------------------------------------------------
1 | import { Company } from '../company/company';
2 | export interface AppState {
3 | companies: Company[];
4 | }
5 |
--------------------------------------------------------------------------------
/src/app/state/company.actions.ts:
--------------------------------------------------------------------------------
1 | import { Action } from '@ngrx/store';
2 | import { Company } from '../company/company';
3 |
4 | export const DISCONNECT_COMPANIES = 'DISCONNECT_COMPANIES';
5 | export const DISCONNECT_COMPANIES_SUCCESS = 'DISCONNECT_COMPANIES_SUCCESS';
6 | export const CONNECT_COMPANIES = 'CONNECT_COMPANIES';
7 | export const CONNECT_COMPANIES_SUCCESS = 'CONNECT_COMPANIES_SUCCESS';
8 | export const CONNECT_COMPANIES_FAILURE = 'CONNECT_COMPANIES_FAILURE';
9 | export const REMOVE_COMPANY = 'REMOVE_COMPANY';
10 | export const REMOVE_COMPANY_SUCCESS = 'REMOVE_COMPANY_SUCCESS';
11 | export const REMOVE_COMPANY_FAILURE = 'REMOVE_COMPANY_FAILURE';
12 | export const ADDED_COMPANY_SYNCED = 'ADDED_COMPANY_SYNCED';
13 | export const UPDATED_COMPANY_SYNCED = 'UPDATED_COMPANY_SYNCED';
14 | export const REMOVED_COMPANY_SYNCED = 'REMOVED_COMPANY_SYNCED';
15 |
16 | export class DisconnectCompaniesAction implements Action {
17 | readonly type = DISCONNECT_COMPANIES;
18 | }
19 |
20 | export class DisconnectCompaniesSuccessAction implements Action {
21 | readonly type = DISCONNECT_COMPANIES_SUCCESS;
22 | }
23 |
24 | export class ConnectCompaniesAction implements Action {
25 | readonly type = CONNECT_COMPANIES;
26 | }
27 |
28 | export class ConnectCompaniesSuccessAction implements Action {
29 | readonly type = CONNECT_COMPANIES_SUCCESS;
30 | constructor(public payload: Company[]) { }
31 | }
32 |
33 | export class ConnectCompaniesFailureAction implements Action {
34 | readonly type = CONNECT_COMPANIES_FAILURE;
35 | constructor(public payload: Error) { }
36 | }
37 |
38 | export class RemoveCompanyAction implements Action {
39 | readonly type = REMOVE_COMPANY;
40 | constructor(public payload: Company) { }
41 | }
42 |
43 | export class RemoveCompanySuccessAction implements Action {
44 | readonly type = REMOVE_COMPANY_SUCCESS;
45 | }
46 |
47 | export class RemoveCompanyFailureAction implements Action {
48 | readonly type = REMOVE_COMPANY_FAILURE;
49 | constructor(public payload: Error) { }
50 | }
51 |
52 | export class AddedCompanySyncedAction implements Action {
53 | readonly type = ADDED_COMPANY_SYNCED;
54 | constructor(public payload: Company) { }
55 | }
56 |
57 | export class UpdatedCompanySyncedAction implements Action {
58 | readonly type = UPDATED_COMPANY_SYNCED;
59 | constructor(public payload: Company) { }
60 | }
61 |
62 | export class RemovedCompanySyncedAction implements Action {
63 | readonly type = REMOVED_COMPANY_SYNCED;
64 | constructor(public payload: Company) { }
65 | }
66 |
67 | export type All
68 | = DisconnectCompaniesAction
69 | | DisconnectCompaniesSuccessAction
70 | | ConnectCompaniesAction
71 | | ConnectCompaniesSuccessAction
72 | | ConnectCompaniesFailureAction
73 | | RemoveCompanyAction
74 | | RemoveCompanySuccessAction
75 | | RemoveCompanyFailureAction
76 | | AddedCompanySyncedAction
77 | | UpdatedCompanySyncedAction
78 | | RemovedCompanySyncedAction;
79 |
80 |
81 |
--------------------------------------------------------------------------------
/src/app/state/company.effects.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Effect, Actions, toPayload } from '@ngrx/effects';
3 | import { Router } from '@angular/router';
4 | import { Observable } from 'rxjs/Observable';
5 | import { Action } from '@ngrx/store';
6 |
7 | import { CompanyService } from '../company/company.service';
8 | import * as CompanyActions from './company.actions';
9 |
10 | import 'rxjs/add/observable/of';
11 | import 'rxjs/add/operator/first';
12 | import 'rxjs/add/operator/switchMap';
13 | import 'rxjs/add/operator/map';
14 | import { DisconnectCompaniesSuccessAction } from './company.actions';
15 |
16 | @Injectable()
17 | export class CompanyEffects {
18 |
19 | @Effect() connectCompanies$ = this.actions$
20 | .ofType(CompanyActions.CONNECT_COMPANIES, CompanyActions.DISCONNECT_COMPANIES)
21 | .switchMap(action => {
22 | if (action.type === CompanyActions.CONNECT_COMPANIES) {
23 | return this.companyService.getCompaniesEvents()
24 | .catch(error => Observable.of(new CompanyActions.ConnectCompaniesFailureAction(error)));
25 | } else {
26 | this.companyService.diconnectCompanies();
27 | return Observable.of(new CompanyActions.DisconnectCompaniesSuccessAction());
28 | }
29 | });
30 |
31 | // @Effect() connectCompanies$ = this.actions$
32 | // .ofType(CompanyActions.CONNECT_COMPANIES, CompanyActions.DISCONNECT_COMPANIES)
33 | // .switchMap(action => {
34 | // if (action.type === CompanyActions.CONNECT_COMPANIES) {
35 | // return this.companyService.getCompanies()
36 | // .map(companies => (new CompanyActions. (companies)))
37 | // .catch(error => Observable.of(new CompanyActions.ConnectCompaniesFailureAction(error)));
38 | // } else {
39 | // return Observable.of(new CompanyActions.DisconnectCompaniesSuccessAction());
40 | // }
41 | // });
42 |
43 | constructor(
44 | private router: Router,
45 | private companyService: CompanyService,
46 | private actions$: Actions
47 | ) { }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/app/state/company.reducers.ts:
--------------------------------------------------------------------------------
1 | import * as CompanyActions from './company.actions';
2 | import { Company } from '../company/company';
3 |
4 | export function companyReducer(state = [], action) {
5 | switch (action.type) {
6 | case CompanyActions.CONNECT_COMPANIES_SUCCESS: {
7 | return action.payload;
8 | }
9 |
10 | case CompanyActions.ADDED_COMPANY_SYNCED:
11 | const exists = state.find(company => company.$key === action.payload.$key);
12 | return exists ? state : [...state, action.payload];
13 |
14 | case CompanyActions.UPDATED_COMPANY_SYNCED:
15 | return state.map(company => {
16 | return company.$key === action.payload.$key ? Object.assign({}, action.payload) : company;
17 | });
18 |
19 | case CompanyActions.REMOVED_COMPANY_SYNCED:
20 | return state.filter(company => company.$key !== action.payload.$key);
21 |
22 | default: {
23 | return state;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-Angular-Fire-Course/166af8496b744ae2da25b3334bc77f53fe646c41/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/assets/branching-info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-Angular-Fire-Course/166af8496b744ae2da25b3334bc77f53fe646c41/src/assets/branching-info.png
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true,
3 | firebaseConfig: {
4 | apiKey: 'AIzaSyBJsTnYKiu2mdLnwkSidQjw3THCty5sEm4',
5 | authDomain: 'buildingappswithangularf-ebcb5.firebaseapp.com',
6 | databaseURL: 'https://buildingappswithangularf-ebcb5.firebaseio.com',
7 | projectId: 'buildingappswithangularf-ebcb5',
8 | storageBucket: 'buildingappswithangularf-ebcb5.appspot.com',
9 | messagingSenderId: '957445559070'
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 | firebaseConfig: {
9 | apiKey: 'AIzaSyBJsTnYKiu2mdLnwkSidQjw3THCty5sEm4',
10 | authDomain: 'buildingappswithangularf-ebcb5.firebaseapp.com',
11 | databaseURL: 'https://buildingappswithangularf-ebcb5.firebaseio.com',
12 | projectId: 'buildingappswithangularf-ebcb5',
13 | storageBucket: 'buildingappswithangularf-ebcb5.appspot.com',
14 | messagingSenderId: '957445559070'
15 | },
16 | fakeFirebaseConfig: {
17 | apiKey: 'xxx',
18 | authDomain: 'xxx',
19 | databaseURL: 'https://xx.firebaseio.com',
20 | projectId: 'xxx'
21 | }
22 | };
23 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-Angular-Fire-Course/166af8496b744ae2da25b3334bc77f53fe646c41/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Angularfire
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.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 | @import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
3 | @import url(https://fonts.googleapis.com/css?family=Roboto);
4 | @import url(https://fonts.googleapis.com/icon?family=Material+Icons);
5 |
6 |
7 | body {
8 | margin: 0;
9 | font-family: Roboto, sans-serif;
10 | background-color: whitesmoke;
11 | }
--------------------------------------------------------------------------------
/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 | }
19 | }
20 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------