├── src ├── app │ ├── app.component.scss │ ├── tasks │ │ ├── index.ts │ │ ├── models │ │ │ ├── index.ts │ │ │ ├── task.spec.ts │ │ │ └── task.ts │ │ ├── components │ │ │ ├── tasks │ │ │ │ ├── index.ts │ │ │ │ └── tasks.component.ts │ │ │ ├── task-form │ │ │ │ ├── index.ts │ │ │ │ ├── task-form.component.ts │ │ │ │ └── task-form.component.scss │ │ │ ├── task-item │ │ │ │ ├── index.ts │ │ │ │ ├── task-item.component.ts │ │ │ │ ├── task-item.component.html │ │ │ │ └── task-item.component.scss │ │ │ └── task-list │ │ │ │ ├── index.ts │ │ │ │ ├── task-list.component.scss │ │ │ │ └── task-list.component.ts │ │ ├── directives │ │ │ ├── index.ts │ │ │ └── auto-focus.directive.ts │ │ ├── tasks.routes.ts │ │ ├── tasks.module.ts │ │ └── tasks.service.ts │ ├── auth │ │ ├── components │ │ │ └── sign-in │ │ │ │ ├── index.ts │ │ │ │ ├── sign-in.component.scss │ │ │ │ └── sign-in.component.ts │ │ ├── guards │ │ │ ├── index.ts │ │ │ ├── require-auth.guard.ts │ │ │ └── require-unauth.guard.ts │ │ ├── index.ts │ │ ├── auth.routes.ts │ │ ├── auth.module.ts │ │ └── auth.service.ts │ ├── firebase │ │ ├── index.ts │ │ └── firebase.module.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── app-header.component.ts │ └── app-header.component.scss ├── assets │ └── favicon.ico ├── styles │ ├── _base.scss │ ├── styles.scss │ ├── _grid.scss │ └── _settings.scss ├── environments │ ├── environment.ts │ ├── environment.prod.ts │ └── firebase.ts ├── tsconfig.app.json ├── tsconfig.spec.json ├── main.ts ├── index.html ├── test.ts └── polyfills.ts ├── .firebaserc ├── e2e ├── app.po.ts ├── tsconfig.e2e.json └── app.e2e-spec.ts ├── firebase.rules.json ├── circle.yml ├── tsconfig.json ├── .gitignore ├── sw-precache.config.js ├── firebase.json ├── karma.conf.js ├── protractor.conf.js ├── LICENSE ├── .angular-cli.json ├── README.md ├── package.json └── tslint.json /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | .main { 2 | padding-bottom: 90px; 3 | } 4 | -------------------------------------------------------------------------------- /src/app/tasks/index.ts: -------------------------------------------------------------------------------- 1 | export { TasksModule } from './tasks.module'; 2 | -------------------------------------------------------------------------------- /src/app/tasks/models/index.ts: -------------------------------------------------------------------------------- 1 | export { ITask, Task } from './task'; 2 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "ng2-todo-app" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/app/tasks/components/tasks/index.ts: -------------------------------------------------------------------------------- 1 | export { TasksComponent } from './tasks.component'; 2 | -------------------------------------------------------------------------------- /src/app/tasks/directives/index.ts: -------------------------------------------------------------------------------- 1 | export { AutoFocusDirective } from './auto-focus.directive'; 2 | -------------------------------------------------------------------------------- /src/app/auth/components/sign-in/index.ts: -------------------------------------------------------------------------------- 1 | export { SignInComponent } from './sign-in.component'; 2 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-form/index.ts: -------------------------------------------------------------------------------- 1 | export { TaskFormComponent } from './task-form.component'; 2 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-item/index.ts: -------------------------------------------------------------------------------- 1 | export { TaskItemComponent } from './task-item.component'; 2 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-list/index.ts: -------------------------------------------------------------------------------- 1 | export { TaskListComponent } from './task-list.component'; 2 | -------------------------------------------------------------------------------- /src/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-park/todo-angular-firebase/HEAD/src/assets/favicon.ico -------------------------------------------------------------------------------- /src/styles/_base.scss: -------------------------------------------------------------------------------- 1 | @import 2 | 'settings', 3 | '~minx/src/settings', 4 | '~minx/src/functions', 5 | '~minx/src/mixins'; 6 | -------------------------------------------------------------------------------- /src/app/auth/guards/index.ts: -------------------------------------------------------------------------------- 1 | export { RequireAuthGuard } from './require-auth.guard'; 2 | export { RequireUnauthGuard } from './require-unauth.guard'; 3 | -------------------------------------------------------------------------------- /src/app/firebase/index.ts: -------------------------------------------------------------------------------- 1 | import * as firebase from 'firebase/app'; 2 | 3 | export { firebase }; 4 | export { FirebaseModule } from './firebase.module'; 5 | -------------------------------------------------------------------------------- /src/app/auth/index.ts: -------------------------------------------------------------------------------- 1 | export { RequireAuthGuard } from './guards'; 2 | export { AuthModule } from './auth.module'; 3 | export { AuthService } from './auth.service'; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | import { firebaseConfig } from './firebase'; 2 | 3 | 4 | export const environment = { 5 | production: false, 6 | firebase: firebaseConfig 7 | }; 8 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | import { firebaseConfig } from './firebase'; 2 | 3 | 4 | export const environment = { 5 | production: true, 6 | firebase: firebaseConfig 7 | }; 8 | -------------------------------------------------------------------------------- /src/styles/styles.scss: -------------------------------------------------------------------------------- 1 | @import 2 | 'base', 3 | '~minx/src/reset', 4 | '~minx/src/elements', 5 | 'grid'; 6 | 7 | 8 | [hidden] { 9 | display: none !important; 10 | } 11 | 12 | ::selection { 13 | background: rgba(200,200,255,.1); 14 | } 15 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class TodoNgFirebasePage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /firebase.rules.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "tasks": { 4 | "$uid": { 5 | ".read": "auth !== null && auth.uid === $uid", 6 | ".write": "auth !== null && auth.uid === $uid", 7 | ".indexOn": ["completed"] 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/environments/firebase.ts: -------------------------------------------------------------------------------- 1 | export const firebaseConfig = { 2 | apiKey: 'AIzaSyDaEW83qAOozjJbbJP1YYbEHxxfFksdSHQ', 3 | authDomain: 'ng2-todo-app.firebaseapp.com', 4 | databaseURL: 'https://ng2-todo-app.firebaseio.com', 5 | storageBucket: 'ng2-todo-app.appspot.com' 6 | }; 7 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": "", 5 | "module": "es2015", 6 | "outDir": "../out-tsc/app", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/styles/_grid.scss: -------------------------------------------------------------------------------- 1 | //=================================================================== 2 | // GRID 3 | //=================================================================== 4 | 5 | .g-row { 6 | @include grid-row; 7 | } 8 | 9 | .g-col { 10 | @include grid-column; 11 | width: 100%; 12 | } 13 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | node: 3 | version: 8.1 4 | 5 | dependencies: 6 | pre: 7 | - rm -rf node_modules 8 | 9 | test: 10 | override: 11 | - npm run build 12 | 13 | deployment: 14 | production: 15 | branch: master 16 | commands: 17 | - ./node_modules/.bin/firebase deploy --token $FIREBASE_TOKEN 18 | -------------------------------------------------------------------------------- /src/app/tasks/directives/auto-focus.directive.ts: -------------------------------------------------------------------------------- 1 | import { Directive, ElementRef, OnInit } from '@angular/core'; 2 | 3 | 4 | @Directive({ 5 | selector: '[autoFocus]' 6 | }) 7 | export class AutoFocusDirective implements OnInit { 8 | constructor(public element: ElementRef) {} 9 | 10 | ngOnInit(): void { 11 | this.element.nativeElement.focus(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { TodoNgFirebasePage } from './app.po'; 2 | 3 | 4 | describe('App', () => { 5 | let page: TodoNgFirebasePage; 6 | 7 | beforeEach(() => { 8 | page = new TodoNgFirebasePage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getParagraphText()).toEqual('Todo Angular Firebase'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/tasks/models/task.spec.ts: -------------------------------------------------------------------------------- 1 | import { Task } from './task'; 2 | 3 | 4 | describe('Tasks', () => { 5 | describe('Task', () => { 6 | it('should set title', () => { 7 | expect(new Task('test').title).toBe('test'); 8 | }); 9 | 10 | it('should set completed to false by default', () => { 11 | expect(new Task('test').completed).toBe(false); 12 | }); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": "", 5 | "module": "commonjs", 6 | "outDir": "../out-tsc/spec", 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/app/tasks/models/task.ts: -------------------------------------------------------------------------------- 1 | import { firebase } from '../../firebase'; 2 | 3 | 4 | export interface ITask { 5 | $key?: string; 6 | completed: boolean; 7 | createdAt: Object; 8 | title: string; 9 | } 10 | 11 | 12 | export class Task implements ITask { 13 | completed = false; 14 | createdAt = firebase.database.ServerValue.TIMESTAMP; 15 | title; 16 | 17 | constructor(title: string) { 18 | this.title = title; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "src", 5 | "declaration": false, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "lib": [ 9 | "es2016", 10 | "dom" 11 | ], 12 | "moduleResolution": "node", 13 | "outDir": "./dist/out-tsc", 14 | "sourceMap": true, 15 | "target": "es5", 16 | "typeRoots": [ 17 | "node_modules/@types" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/app/auth/auth.routes.ts: -------------------------------------------------------------------------------- 1 | import { ModuleWithProviders } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | 4 | // components 5 | import { SignInComponent } from './components/sign-in'; 6 | 7 | // guards 8 | import { RequireUnauthGuard } from './guards'; 9 | 10 | 11 | export const AuthRoutesModule: ModuleWithProviders = RouterModule.forChild([ 12 | { 13 | path: '', 14 | component: SignInComponent, 15 | canActivate: [RequireUnauthGuard] 16 | } 17 | ]); 18 | -------------------------------------------------------------------------------- /src/app/tasks/tasks.routes.ts: -------------------------------------------------------------------------------- 1 | import { ModuleWithProviders } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | 4 | // components 5 | import { TasksComponent } from './components/tasks'; 6 | 7 | // guards 8 | import { RequireAuthGuard } from '../auth'; 9 | 10 | 11 | export const TasksRoutesModule: ModuleWithProviders = RouterModule.forChild([ 12 | { 13 | path: 'tasks', 14 | component: TasksComponent, 15 | canActivate: [RequireAuthGuard] 16 | } 17 | ]); 18 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { AuthService } from './auth'; 3 | 4 | 5 | @Component({ 6 | selector: 'app-root', 7 | styleUrls: ['./app.component.scss'], 8 | template: ` 9 | 12 | 13 |
14 | 15 |
16 | ` 17 | }) 18 | export class AppComponent { 19 | constructor(public auth: AuthService) {} 20 | } 21 | -------------------------------------------------------------------------------- /src/app/firebase/firebase.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { AngularFireModule } from 'angularfire2'; 3 | import { AngularFireAuthModule } from 'angularfire2/auth'; 4 | import { AngularFireDatabaseModule } from 'angularfire2/database'; 5 | import { environment } from '../../environments/environment'; 6 | 7 | 8 | @NgModule({ 9 | imports: [ 10 | AngularFireAuthModule, 11 | AngularFireDatabaseModule, 12 | AngularFireModule.initializeApp(environment.firebase) 13 | ] 14 | }) 15 | export class FirebaseModule { } 16 | -------------------------------------------------------------------------------- /src/styles/_settings.scss: -------------------------------------------------------------------------------- 1 | //=================================================================== 2 | // SETTINGS 3 | //=================================================================== 4 | 5 | $base-background-color: #222 !default; 6 | $base-font-color: #999 !default; 7 | $base-font-family: 'aktiv-grotesk-std', Helvetica Neue, Arial, sans-serif !default; 8 | $base-font-size: 18px !default; 9 | $base-line-height: 24px !default; 10 | 11 | 12 | //=============================================== 13 | // GRID 14 | //=============================================== 15 | $grid-max-width: 810px !default; 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #====================================== 2 | # Directories 3 | #-------------------------------------- 4 | coverage/ 5 | dist/ 6 | node_modules/ 7 | out-tsc/ 8 | tmp/ 9 | 10 | 11 | #====================================== 12 | # Extensions 13 | #-------------------------------------- 14 | *.gz 15 | *.log 16 | *.rar 17 | *.tar 18 | *.zip 19 | 20 | 21 | #====================================== 22 | # IDE generated 23 | #-------------------------------------- 24 | .idea/ 25 | .project 26 | *.iml 27 | 28 | 29 | #====================================== 30 | # System generated 31 | #-------------------------------------- 32 | __MACOSX/ 33 | .DS_Store 34 | Thumbs.db 35 | -------------------------------------------------------------------------------- /src/app/auth/auth.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | // components 5 | import { SignInComponent } from './components/sign-in'; 6 | 7 | // modules 8 | import { AuthRoutesModule } from './auth.routes'; 9 | 10 | // services 11 | import { RequireAuthGuard, RequireUnauthGuard } from './guards'; 12 | import { AuthService } from './auth.service'; 13 | 14 | 15 | @NgModule({ 16 | declarations: [ 17 | SignInComponent 18 | ], 19 | imports: [ 20 | CommonModule, 21 | AuthRoutesModule 22 | ], 23 | providers: [ 24 | AuthService, 25 | RequireAuthGuard, 26 | RequireUnauthGuard 27 | ] 28 | }) 29 | export class AuthModule { } 30 | -------------------------------------------------------------------------------- /src/app/auth/guards/require-auth.guard.ts: -------------------------------------------------------------------------------- 1 | import 'rxjs/add/operator/do'; 2 | import 'rxjs/add/operator/take'; 3 | 4 | import { Injectable } from '@angular/core'; 5 | import { CanActivate, Router } from '@angular/router'; 6 | import { Observable } from 'rxjs/Observable'; 7 | import { AuthService } from '../auth.service'; 8 | 9 | 10 | @Injectable() 11 | export class RequireAuthGuard implements CanActivate { 12 | constructor(private auth: AuthService, private router: Router) {} 13 | 14 | canActivate(): Observable { 15 | return this.auth.authenticated$ 16 | .take(1) 17 | .do(authenticated => { 18 | if (!authenticated) { 19 | this.router.navigate(['/']); 20 | } 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /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 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | 13 | platformBrowserDynamic().bootstrapModule(AppModule) 14 | .then(() => { 15 | if (environment.production && 'serviceWorker' in navigator) { 16 | navigator.serviceWorker 17 | .register('/service-worker.js') 18 | .then(registration => console.log('[Service Worker] registered with scope', registration.scope)); 19 | } 20 | }) 21 | .catch(error => console.error(error)); 22 | -------------------------------------------------------------------------------- /sw-precache.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | navigateFallback: '/index.html', 3 | 4 | // @see https://github.com/Polymer/polymer-build/issues/35 5 | navigateFallbackWhitelist: [ 6 | /^(?!\/__)/ 7 | ], 8 | 9 | root: 'dist', 10 | runtimeCaching: [ 11 | { 12 | urlPattern: /^https:\/\/fonts\.googleapis\.com\//, 13 | handler: 'cacheFirst' 14 | }, 15 | { 16 | urlPattern: /^https:\/\/maxcdn\.bootstrapcdn\.com\//, 17 | handler: 'cacheFirst' 18 | }, 19 | { 20 | urlPattern: /^https:\/\/use\.typekit\.net\//, 21 | handler: 'cacheFirst' 22 | } 23 | ], 24 | staticFileGlobs: [ 25 | 'dist/assets/**/*', 26 | 'dist/*.css', 27 | 'dist/*.html', 28 | 'dist/*.js' 29 | ], 30 | stripPrefix: 'dist/' 31 | }; 32 | -------------------------------------------------------------------------------- /src/app/auth/guards/require-unauth.guard.ts: -------------------------------------------------------------------------------- 1 | import 'rxjs/add/operator/do'; 2 | import 'rxjs/add/operator/take'; 3 | 4 | import { Injectable } from '@angular/core'; 5 | import { CanActivate, Router } from '@angular/router'; 6 | import { Observable } from 'rxjs/Observable'; 7 | import { AuthService } from '../auth.service'; 8 | 9 | 10 | @Injectable() 11 | export class RequireUnauthGuard implements CanActivate { 12 | constructor(private auth: AuthService, private router: Router) {} 13 | 14 | canActivate(): Observable { 15 | return this.auth.authenticated$ 16 | .take(1) 17 | .do(authenticated => { 18 | if (authenticated) { 19 | this.router.navigate(['/tasks']); 20 | } 21 | }) 22 | .map(authenticated => !authenticated); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "database": { 3 | "rules": "firebase.rules.json" 4 | }, 5 | 6 | "hosting": { 7 | "public": "dist", 8 | "headers": [ 9 | { 10 | "source": "**/*", 11 | "headers": [ 12 | {"key": "X-Content-Type-Options", "value": "nosniff"}, 13 | {"key": "X-Frame-Options", "value": "DENY"}, 14 | {"key": "X-UA-Compatible", "value": "ie=edge"}, 15 | {"key": "X-XSS-Protection", "value": "1; mode=block"} 16 | ] 17 | }, 18 | { 19 | "source": "**/*.@(css|html|js|map)", 20 | "headers": [ 21 | {"key": "Cache-Control", "value": "max-age=7200"} 22 | ] 23 | } 24 | ], 25 | "rewrites": [ 26 | {"source": "**", "destination": "/index.html"} 27 | ] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/app/auth/components/sign-in/sign-in.component.scss: -------------------------------------------------------------------------------- 1 | @import 2 | "~minx/src/settings", 3 | "~minx/src/functions", 4 | "~minx/src/mixins"; 5 | 6 | 7 | .sign-in { 8 | margin-top: 90px; 9 | max-width: 300px; 10 | } 11 | 12 | .sign-in__heading { 13 | margin-bottom: 36px; 14 | font-size: 30px; 15 | font-weight: 300; 16 | text-align: center; 17 | } 18 | 19 | .sign-in__button { 20 | @include button-base; 21 | margin-bottom: 10px; 22 | outline: none; 23 | border: 1px solid #555; 24 | padding: 0; 25 | width: 100%; 26 | height: 48px; 27 | font-family: inherit; 28 | font-size: rem(18px); 29 | line-height: 48px; 30 | color: #999; 31 | background: transparent; 32 | 33 | &:hover { 34 | border: 2px solid #aaa; 35 | line-height: 46px; 36 | //border-color: #aaa; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Todo Angular Firebase 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /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 | 5 | // components 6 | import { AppComponent } from './app.component'; 7 | import { AppHeaderComponent } from './app-header.component'; 8 | 9 | // modules 10 | import { AuthModule } from './auth'; 11 | import { FirebaseModule } from './firebase'; 12 | import { TasksModule } from './tasks'; 13 | 14 | 15 | @NgModule({ 16 | bootstrap: [ 17 | AppComponent 18 | ], 19 | declarations: [ 20 | AppComponent, 21 | AppHeaderComponent 22 | ], 23 | imports: [ 24 | BrowserModule, 25 | RouterModule.forRoot([], {useHash: false}), 26 | 27 | AuthModule, 28 | FirebaseModule, 29 | TasksModule 30 | ] 31 | }) 32 | export class AppModule { } 33 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-list/task-list.component.scss: -------------------------------------------------------------------------------- 1 | @import 2 | "~minx/src/settings", 3 | "~minx/src/functions", 4 | "~minx/src/mixins"; 5 | 6 | 7 | .task-filters { 8 | @include clearfix; 9 | margin-bottom: 45px; 10 | padding-left: 1px; 11 | font-size: rem(16px); 12 | line-height: 24px; 13 | list-style-type: none; 14 | 15 | @include media-query(540) { 16 | margin-bottom: 55px; 17 | } 18 | 19 | li { 20 | float: left; 21 | 22 | &:not(:first-child) { 23 | margin-left: 12px; 24 | } 25 | 26 | &:not(:first-child):before { 27 | padding-right: 12px; 28 | content: '/'; 29 | font-weight: 300; 30 | } 31 | } 32 | 33 | a { 34 | color: #999; 35 | text-decoration: none; 36 | 37 | &.active { 38 | color: #fff; 39 | } 40 | } 41 | } 42 | 43 | 44 | .task-list { 45 | border-top: 1px dotted #666; 46 | } 47 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function (config) { 2 | config.set({ 3 | basePath: '', 4 | 5 | frameworks: ['jasmine', '@angular/cli'], 6 | 7 | plugins: [ 8 | require('karma-jasmine'), 9 | require('karma-chrome-launcher'), 10 | require('karma-jasmine-html-reporter'), 11 | require('karma-coverage-istanbul-reporter'), 12 | require('@angular/cli/plugins/karma') 13 | ], 14 | 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | 19 | coverageIstanbulReporter: { 20 | reports: [ 'html', 'lcovonly' ], 21 | fixWebpackSourcePaths: true 22 | }, 23 | 24 | angularCli: { 25 | environment: 'dev' 26 | }, 27 | 28 | reporters: ['progress', 'kjhtml'], 29 | port: 9876, 30 | colors: true, 31 | logLevel: config.LOG_INFO, 32 | autoWatch: true, 33 | browsers: ['Chrome'], 34 | singleRun: false 35 | }); 36 | }; 37 | -------------------------------------------------------------------------------- /src/app/app-header.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; 2 | 3 | 4 | @Component({ 5 | changeDetection: ChangeDetectionStrategy.OnPush, 6 | selector: 'app-header', 7 | styleUrls: ['./app-header.component.scss'], 8 | template: ` 9 |
10 |
11 |
12 |

Todo Angular Firebase

13 | 14 | 18 |
19 |
20 |
21 | ` 22 | }) 23 | 24 | export class AppHeaderComponent { 25 | @Input() authenticated: boolean; 26 | @Output() signOut = new EventEmitter(false); 27 | } 28 | -------------------------------------------------------------------------------- /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 | // Timeouts have been set to a large value: 40000 5 | // @see https://github.com/angular/angularfire2/issues/779 6 | 7 | 8 | const { SpecReporter } = require('jasmine-spec-reporter'); 9 | 10 | 11 | exports.config = { 12 | allScriptsTimeout: 40000, 13 | specs: [ 14 | './e2e/**/*.e2e-spec.ts' 15 | ], 16 | capabilities: { 17 | 'browserName': 'chrome' 18 | }, 19 | directConnect: true, 20 | baseUrl: 'http://localhost:4200/', 21 | framework: 'jasmine', 22 | jasmineNodeOpts: { 23 | showColors: true, 24 | defaultTimeoutInterval: 40000, 25 | ScriptTimeoutError: 40000, 26 | print: function() {} 27 | }, 28 | onPrepare() { 29 | require('ts-node').register({ 30 | project: 'e2e/tsconfig.e2e.json' 31 | }); 32 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /src/app/tasks/tasks.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | // components 6 | import { TaskFormComponent } from './components/task-form'; 7 | import { TaskItemComponent } from './components/task-item'; 8 | import { TaskListComponent } from './components/task-list'; 9 | import { TasksComponent } from './components/tasks'; 10 | 11 | // directives 12 | import { AutoFocusDirective } from './directives'; 13 | 14 | // modules 15 | import { TasksRoutesModule } from './tasks.routes'; 16 | 17 | // services 18 | import { TasksService } from './tasks.service' 19 | 20 | 21 | @NgModule({ 22 | declarations: [ 23 | AutoFocusDirective, 24 | TaskFormComponent, 25 | TaskItemComponent, 26 | TaskListComponent, 27 | TasksComponent 28 | ], 29 | imports: [ 30 | CommonModule, 31 | FormsModule, 32 | TasksRoutesModule 33 | ], 34 | providers: [ 35 | TasksService 36 | ] 37 | }) 38 | export class TasksModule { } 39 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-form/task-form.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, Component, EventEmitter, Output } from '@angular/core'; 2 | 3 | 4 | @Component({ 5 | changeDetection: ChangeDetectionStrategy.OnPush, 6 | selector: 'app-task-form', 7 | styleUrls: ['./task-form.component.scss'], 8 | template: ` 9 |
10 | 20 |
21 | ` 22 | }) 23 | 24 | export class TaskFormComponent { 25 | @Output() createTask = new EventEmitter(false); 26 | 27 | title = ''; 28 | 29 | clear(): void { 30 | this.title = ''; 31 | } 32 | 33 | submit(): void { 34 | const title: string = this.title.trim(); 35 | if (title.length) { 36 | this.createTask.emit(title); 37 | } 38 | this.clear(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | import 'zone.js/dist/long-stack-trace-zone'; 2 | import 'zone.js/dist/proxy.js'; 3 | import 'zone.js/dist/sync-test'; 4 | import 'zone.js/dist/jasmine-patch'; 5 | import 'zone.js/dist/async-test'; 6 | import 'zone.js/dist/fake-async-test'; 7 | 8 | import { getTestBed } from '@angular/core/testing'; 9 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; 10 | 11 | 12 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 13 | declare const __karma__: any; 14 | declare const require: any; 15 | 16 | // Prevent Karma from running prematurely. 17 | __karma__.loaded = function () {}; 18 | 19 | // First, initialize the Angular testing environment. 20 | getTestBed().initTestEnvironment( 21 | BrowserDynamicTestingModule, 22 | platformBrowserDynamicTesting() 23 | ); 24 | 25 | // Then we find all the tests. 26 | const context = require.context('./', true, /\.spec\.ts$/); 27 | 28 | // And load the modules. 29 | context.keys().map(context); 30 | 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-form/task-form.component.scss: -------------------------------------------------------------------------------- 1 | @import 2 | "~minx/src/settings", 3 | "~minx/src/functions", 4 | "~minx/src/mixins"; 5 | 6 | 7 | .task-form { 8 | margin: 40px 0 10px; 9 | 10 | @include media-query(540) { 11 | margin: 80px 0 20px; 12 | } 13 | } 14 | 15 | 16 | .task-form__input { 17 | outline: none; 18 | border: 0; 19 | border-bottom: 1px dotted #666; 20 | border-radius: 0; 21 | padding: 0 0 5px 0; 22 | width: 100%; 23 | height: 50px; 24 | font-family: inherit; 25 | font-size: rem(24px); 26 | font-weight: 300; 27 | color: #fff; 28 | background: transparent; 29 | 30 | @include media-query(540) { 31 | height: 61px; 32 | font-size: rem(32px); 33 | } 34 | 35 | &::placeholder { 36 | color: #999; 37 | opacity: 1; // firefox native placeholder style has opacity < 1 38 | } 39 | 40 | &:focus::placeholder { 41 | color: #777; 42 | opacity: 1; 43 | } 44 | 45 | // webkit input doesn't inherit font-smoothing from ancestors 46 | -webkit-font-smoothing: antialiased; 47 | 48 | // remove `x` 49 | &::-ms-clear { 50 | display: none; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Richard Park 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-item/task-item.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; 2 | import { ITask } from '../../models'; 3 | 4 | 5 | @Component({ 6 | changeDetection: ChangeDetectionStrategy.OnPush, 7 | selector: 'app-task-item', 8 | styleUrls: ['./task-item.component.scss'], 9 | templateUrl: './task-item.component.html', 10 | }) 11 | 12 | export class TaskItemComponent { 13 | @Input() task: ITask; 14 | @Output() remove = new EventEmitter(false); 15 | @Output() update = new EventEmitter(false); 16 | 17 | editing = false; 18 | title = ''; 19 | 20 | editTitle(): void { 21 | this.editing = true; 22 | this.title = this.task.title; 23 | } 24 | 25 | saveTitle(): void { 26 | if (this.editing) { 27 | const title: string = this.title.trim(); 28 | if (title.length && title !== this.task.title) { 29 | this.update.emit({title}); 30 | } 31 | this.stopEditing(); 32 | } 33 | } 34 | 35 | stopEditing(): void { 36 | this.editing = false; 37 | } 38 | 39 | toggleStatus(): void { 40 | this.update.emit({ 41 | completed: !this.task.completed 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/app/tasks/components/tasks/tasks.component.ts: -------------------------------------------------------------------------------- 1 | import 'rxjs/add/operator/do'; 2 | import 'rxjs/add/operator/pluck'; 3 | 4 | import { Component, OnInit } from '@angular/core'; 5 | import { ActivatedRoute } from '@angular/router'; 6 | import { Observable } from 'rxjs/Observable'; 7 | import { TasksService } from '../../tasks.service'; 8 | 9 | 10 | @Component({ 11 | selector: 'app-tasks', 12 | template: ` 13 |
14 |
15 | 16 |
17 | 18 |
19 | 24 |
25 |
26 | ` 27 | }) 28 | export class TasksComponent implements OnInit { 29 | filter: Observable; 30 | 31 | constructor( 32 | public route: ActivatedRoute, 33 | public tasksService: TasksService 34 | ) {} 35 | 36 | ngOnInit() { 37 | this.filter = this.route.params 38 | .pluck('completed') 39 | .do((value: string) => this.tasksService.filterTasks(value)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-list/task-list.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; 2 | import { FirebaseListObservable } from 'angularfire2/database'; 3 | import { ITask } from '../../models'; 4 | 5 | 6 | @Component({ 7 | changeDetection: ChangeDetectionStrategy.OnPush, 8 | selector: 'app-task-list', 9 | styleUrls: ['./task-list.component.scss'], 10 | template: ` 11 | 16 | 17 |
18 | 23 |
24 | ` 25 | }) 26 | 27 | export class TaskListComponent { 28 | @Input() filter: string; 29 | @Input() tasks: FirebaseListObservable; 30 | 31 | @Output() remove = new EventEmitter(false); 32 | @Output() update = new EventEmitter(false); 33 | } 34 | -------------------------------------------------------------------------------- /.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "todo-angular-firebase" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets" 12 | ], 13 | "index": "index.html", 14 | "main": "main.ts", 15 | "polyfills": "polyfills.ts", 16 | "test": "test.ts", 17 | "tsconfig": "tsconfig.app.json", 18 | "testTsconfig": "tsconfig.spec.json", 19 | "prefix": "app", 20 | "styles": [ 21 | "styles/styles.scss" 22 | ], 23 | "scripts": [], 24 | "environmentSource": "environments/environment.ts", 25 | "environments": { 26 | "dev": "environments/environment.ts", 27 | "prod": "environments/environment.prod.ts" 28 | } 29 | } 30 | ], 31 | "e2e": { 32 | "protractor": { 33 | "config": "./protractor.conf.js" 34 | } 35 | }, 36 | "lint": [ 37 | { 38 | "project": "src/tsconfig.app.json" 39 | }, 40 | { 41 | "project": "src/tsconfig.spec.json" 42 | }, 43 | { 44 | "project": "e2e/tsconfig.e2e.json" 45 | } 46 | ], 47 | "test": { 48 | "karma": { 49 | "config": "./karma.conf.js" 50 | } 51 | }, 52 | "defaults": { 53 | "styleExt": "scss", 54 | "component": {} 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/app/app-header.component.scss: -------------------------------------------------------------------------------- 1 | @import 2 | "~minx/src/settings", 3 | "~minx/src/functions", 4 | "~minx/src/mixins"; 5 | 6 | 7 | .header { 8 | padding: 10px 0; 9 | height: 60px; 10 | overflow: hidden; 11 | line-height: 40px; 12 | } 13 | 14 | 15 | .header__title { 16 | @include fa-icon(circle-o); 17 | float: left; 18 | font-size: rem(14px); 19 | font-weight: 400; 20 | text-rendering: auto; 21 | transform: translate(0,0); 22 | 23 | &:before { 24 | padding-right: 5px; 25 | color: #fff; 26 | font-family: 'FontAwesome'; 27 | line-height: 20px; 28 | } 29 | } 30 | 31 | 32 | .header__links { 33 | @include clearfix; 34 | float: right; 35 | padding: 8px 0; 36 | line-height: 24px; 37 | 38 | li { 39 | float: left; 40 | list-style: none; 41 | 42 | &:last-child { 43 | margin-left: 12px; 44 | padding-left: 12px; 45 | border-left: 1px solid #333; 46 | } 47 | 48 | &:first-of-type { 49 | border: none; 50 | } 51 | } 52 | } 53 | 54 | 55 | .header__link { 56 | display: block; 57 | color: inherit; 58 | font-size: rem(14px); 59 | text-decoration: none; 60 | text-rendering: auto; 61 | transform: translate(0,0); 62 | } 63 | 64 | 65 | .header__link--github { 66 | @include fa-icon(github); 67 | font-size: rem(24px); 68 | 69 | &:before { 70 | font-family: 'FontAwesome'; 71 | line-height: 24px; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/app/auth/auth.service.ts: -------------------------------------------------------------------------------- 1 | import 'rxjs/add/operator/map'; 2 | 3 | import { Injectable } from '@angular/core'; 4 | import { AngularFireAuth } from 'angularfire2/auth'; 5 | import { firebase } from '../firebase'; 6 | import { Observable } from 'rxjs/Observable'; 7 | 8 | 9 | @Injectable() 10 | export class AuthService { 11 | authenticated$: Observable; 12 | uid$: Observable; 13 | 14 | constructor(public afAuth: AngularFireAuth) { 15 | this.authenticated$ = afAuth.authState.map(user => !!user); 16 | this.uid$ = afAuth.authState.map(user => user.uid); 17 | } 18 | 19 | signIn(provider: firebase.auth.AuthProvider): firebase.Promise { 20 | return this.afAuth.auth.signInWithPopup(provider) 21 | .catch(error => console.log('ERROR @ AuthService#signIn() :', error)); 22 | } 23 | 24 | signInAnonymously(): firebase.Promise { 25 | return this.afAuth.auth.signInAnonymously() 26 | .catch(error => console.log('ERROR @ AuthService#signInAnonymously() :', error)); 27 | } 28 | 29 | signInWithGithub(): firebase.Promise { 30 | return this.signIn(new firebase.auth.GithubAuthProvider()); 31 | } 32 | 33 | signInWithGoogle(): firebase.Promise { 34 | return this.signIn(new firebase.auth.GoogleAuthProvider()); 35 | } 36 | 37 | signInWithTwitter(): firebase.Promise { 38 | return this.signIn(new firebase.auth.TwitterAuthProvider()); 39 | } 40 | 41 | signInWithFacebook(): firebase.Promise { 42 | return this.signIn(new firebase.auth.FacebookAuthProvider()); 43 | } 44 | 45 | signOut(): void { 46 | this.afAuth.auth.signOut(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/auth/components/sign-in/sign-in.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { AuthService } from '../../auth.service'; 4 | 5 | 6 | @Component({ 7 | selector: 'app-sign-in', 8 | styleUrls: ['./sign-in.component.scss'], 9 | template: ` 10 | 20 | ` 21 | }) 22 | export class SignInComponent { 23 | constructor(private auth: AuthService, private router: Router) {} 24 | 25 | signInAnonymously(): void { 26 | this.auth.signInAnonymously() 27 | .then(() => this.postSignIn()); 28 | } 29 | 30 | signInWithFacebook(): void { 31 | this.auth.signInWithFacebook() 32 | .then(() => this.postSignIn()); 33 | } 34 | 35 | signInWithGithub(): void { 36 | this.auth.signInWithGithub() 37 | .then(() => this.postSignIn()); 38 | } 39 | 40 | signInWithGoogle(): void { 41 | this.auth.signInWithGoogle() 42 | .then(() => this.postSignIn()); 43 | } 44 | 45 | signInWithTwitter(): void { 46 | this.auth.signInWithTwitter() 47 | .then(() => this.postSignIn()); 48 | } 49 | 50 | private postSignIn(): void { 51 | this.router.navigate(['/tasks']); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-item/task-item.component.html: -------------------------------------------------------------------------------- 1 |
5 | 6 |
7 | 15 |
16 | 17 |
18 |
22 | {{ task.title }} 23 |
24 | 25 |
26 | 35 |
36 |
37 | 38 |
39 | 47 | 55 | 63 |
64 |
65 | -------------------------------------------------------------------------------- /src/app/tasks/tasks.service.ts: -------------------------------------------------------------------------------- 1 | import 'rxjs/add/observable/merge'; 2 | import 'rxjs/add/operator/switchMap'; 3 | 4 | import { Injectable } from '@angular/core'; 5 | import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database'; 6 | import { Observable } from 'rxjs/Observable'; 7 | import { ReplaySubject } from 'rxjs/ReplaySubject'; 8 | import { AuthService } from '../auth'; 9 | import { firebase } from '../firebase'; 10 | import { ITask, Task } from './models'; 11 | 12 | 13 | @Injectable() 14 | export class TasksService { 15 | visibleTasks$: Observable; 16 | 17 | private filter$: ReplaySubject = new ReplaySubject(1); 18 | private filteredTasks$: FirebaseListObservable; 19 | private tasks$: FirebaseListObservable; 20 | 21 | 22 | constructor(afDb: AngularFireDatabase, auth: AuthService) { 23 | auth.uid$ 24 | .take(1) 25 | .subscribe(uid => { 26 | const path = `/tasks/${uid}`; 27 | 28 | this.tasks$ = afDb.list(path); 29 | 30 | this.filteredTasks$ = afDb.list(path, {query: { 31 | orderByChild: 'completed', 32 | equalTo: this.filter$ 33 | }}); 34 | 35 | this.visibleTasks$ = this.filter$ 36 | .switchMap(filter => filter === null ? this.tasks$ : this.filteredTasks$); 37 | }); 38 | } 39 | 40 | 41 | filterTasks(filter: string): void { 42 | switch (filter) { 43 | case 'false': 44 | this.filter$.next(false); 45 | break; 46 | 47 | case 'true': 48 | this.filter$.next(true); 49 | break; 50 | 51 | default: 52 | this.filter$.next(null); 53 | break; 54 | } 55 | } 56 | 57 | createTask(title: string): firebase.Promise { 58 | return this.tasks$.push(new Task(title)); 59 | } 60 | 61 | removeTask(task: ITask): firebase.Promise { 62 | return this.tasks$.remove(task.$key); 63 | } 64 | 65 | updateTask(task: ITask, changes: any): firebase.Promise { 66 | return this.tasks$.update(task.$key, changes); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CircleCI](https://circleci.com/gh/r-park/todo-angular-firebase.svg?style=shield&circle-token=d1a31de32e5baabbf59aa8f78ba251254261fb3a)](https://circleci.com/gh/r-park/todo-angular-firebase) 2 | 3 | 4 | # Todo app with Angular, AngularFire2, and Firebase 5 | A simple Todo app example built with **Angular**, **Angular CLI** and **AngularFire2**. The app features a **Firebase** backend with **OAuth** authentication. Try the demo at ng2-todo-app.firebaseapp.com. 6 | 7 | 8 | Stack 9 | ----- 10 | 11 | - Angular 4 12 | - Angular CLI 13 | - AngularFire2 `4.0.0-rc.1` 14 | - Firebase 15 | - RxJS 16 | - SASS 17 | - Typescript 18 | 19 | 20 | Quick Start 21 | ----------- 22 | 23 | #### Install Angular CLI 24 | 25 | ```shell 26 | $ npm install -g @angular/cli 27 | ``` 28 | 29 | #### Clone the app, install package dependencies, and start the dev server @ `localhost:4200` 30 | 31 | ```shell 32 | $ git clone https://github.com/r-park/todo-angular-firebase.git 33 | $ cd todo-angular-firebase 34 | $ npm install 35 | $ npm start 36 | ``` 37 | 38 | 39 | ## Deploying to Firebase 40 | #### Prerequisites 41 | - Create a free Firebase account at https://firebase.google.com 42 | - Create a project from your [Firebase account console](https://console.firebase.google.com) 43 | - Configure the authentication providers for your Firebase project from your Firebase account console 44 | 45 | #### Configure this app with your project-specific details 46 | 47 | Edit `.firebaserc` in the project root: 48 | 49 | ```json 50 | { 51 | "projects": { 52 | "default": "your-project-id" 53 | } 54 | } 55 | ``` 56 | 57 | Edit the firebase configuration in `src/environments/firebase.ts` 58 | 59 | ```typescript 60 | export const firebaseConfig = { 61 | apiKey: 'your api key', 62 | authDomain: 'your-project-id.firebaseapp.com', 63 | databaseURL: 'https://your-project-id.firebaseio.com', 64 | storageBucket: 'your-project-id.appspot.com' 65 | }; 66 | ``` 67 | 68 | #### Install firebase-tools 69 | ```shell 70 | $ npm install -g firebase-tools 71 | ``` 72 | 73 | #### Build and deploy the app 74 | ```shell 75 | $ npm run build 76 | $ firebase login 77 | $ firebase use default 78 | $ firebase deploy 79 | ``` 80 | 81 | 82 | Commands 83 | -------- 84 | 85 | |Script|Description| 86 | |---|---| 87 | |`npm start`|Start development server @ `localhost:4200`| 88 | |`npm run build`|build the application to `./dist`| 89 | |`npm run lint`|Lint `.ts` files| 90 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todo-angular-firebase", 3 | "version": "0.8.0", 4 | "description": "Todo app with Angular, AngularFire2, and Firebase", 5 | "homepage": "https://github.com/r-park/todo-angular-firebase", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/r-park/todo-angular-firebase.git" 9 | }, 10 | "license": "MIT", 11 | "private": true, 12 | "engines": { 13 | "node": ">=8.1", 14 | "npm": ">= 5" 15 | }, 16 | "browserslist": [ 17 | "last 2 versions", 18 | "not ie <= 10", 19 | "not ie_mob <= 10" 20 | ], 21 | "scripts": { 22 | "build": "ng build --prod", 23 | "e2e": "ng e2e", 24 | "lint": "ng lint", 25 | "ng": "ng", 26 | "postbuild": "npm run precache", 27 | "precache": "sw-precache --config=sw-precache.config.js --verbose", 28 | "start": "ng serve", 29 | "test": "ng test" 30 | }, 31 | "dependencies": { 32 | "@angular/animations": "^4.2.6", 33 | "@angular/common": "^4.2.6", 34 | "@angular/compiler": "^4.2.6", 35 | "@angular/core": "^4.2.6", 36 | "@angular/forms": "^4.2.6", 37 | "@angular/http": "^4.2.6", 38 | "@angular/platform-browser": "^4.2.6", 39 | "@angular/platform-browser-dynamic": "^4.2.6", 40 | "@angular/router": "^4.2.6", 41 | "angularfire2": "^4.0.0-rc.1", 42 | "core-js": "^2.4.1", 43 | "firebase": "^4.1.3", 44 | "rxjs": "^5.4.2", 45 | "zone.js": "^0.8.12" 46 | }, 47 | "devDependencies": { 48 | "@angular/cli": "1.2.0", 49 | "@angular/compiler-cli": "^4.2.6", 50 | "@angular/language-service": "^4.2.6", 51 | "@types/jasmine": "^2.5.53", 52 | "@types/jasminewd2": "^2.0.2", 53 | "@types/node": "^8.0.9", 54 | "codelyzer": "^3.1.2", 55 | "firebase-tools": "^3.9.1", 56 | "jasmine-core": "^2.6.4", 57 | "jasmine-spec-reporter": "^4.1.1", 58 | "karma": "^1.7.0", 59 | "karma-chrome-launcher": "^2.2.0", 60 | "karma-cli": "^1.0.1", 61 | "karma-coverage-istanbul-reporter": "^1.3.0", 62 | "karma-jasmine": "^1.1.0", 63 | "karma-jasmine-html-reporter": "^0.2.2", 64 | "minx": "r-park/minx.git", 65 | "protractor": "^5.1.2", 66 | "sw-precache": "^5.2.0", 67 | "ts-node": "^3.2.0", 68 | "tslint": "^5.5.0", 69 | "typescript": "^2.4.1" 70 | }, 71 | "author": { 72 | "name": "Richard Park", 73 | "email": "objectiv@gmail.com" 74 | }, 75 | "contributors": [ 76 | { 77 | "name": "Cody Lundquist", 78 | "email": "cody.lundquist@gmail.com" 79 | }, 80 | { 81 | "name": "Jason Shultz", 82 | "email": "" 83 | }, 84 | { 85 | "name": "Luke Schlangen", 86 | "email": "luke@lukeschlangen.com" 87 | }, 88 | { 89 | "name": "Sinan Bolel", 90 | "email": "sinanbolel@gmail.com" 91 | }, 92 | { 93 | "name": "Yannick Koehler", 94 | "email": "yannick@koehler.name" 95 | } 96 | ] 97 | } 98 | -------------------------------------------------------------------------------- /src/app/tasks/components/task-item/task-item.component.scss: -------------------------------------------------------------------------------- 1 | @import 2 | "~minx/src/settings", 3 | "~minx/src/functions", 4 | "~minx/src/mixins"; 5 | 6 | 7 | .task-item { 8 | display: flex; 9 | outline: none; 10 | border-bottom: 1px dotted #666; 11 | height: 60px; 12 | overflow: hidden; 13 | color: #fff; 14 | font-size: rem(18px); 15 | font-weight: 300; 16 | 17 | @include media-query(540) { 18 | font-size: rem(24px); 19 | } 20 | } 21 | 22 | .task-item--editing { 23 | border-bottom: 1px dotted #ccc; 24 | } 25 | 26 | 27 | .cell { 28 | &:first-child, 29 | &:last-child { 30 | display: flex; 31 | flex: 0 0 auto; 32 | align-items: center; 33 | } 34 | 35 | &:first-child { 36 | padding-right: 20px; 37 | } 38 | 39 | &:nth-child(2) { 40 | flex: 1; 41 | padding-right: 30px; 42 | overflow: hidden; 43 | } 44 | } 45 | 46 | 47 | .task-item__button { 48 | @include button-base; 49 | margin-left: 5px; 50 | outline: none; 51 | border: 0; 52 | border-radius: 100px; 53 | padding: 0; 54 | width: 40px; 55 | height: 40px; 56 | overflow: hidden; 57 | background: #2a2a2a; 58 | transform: translate(0, 0); 59 | 60 | &:first-child { 61 | margin: 0; 62 | } 63 | } 64 | 65 | .icon { 66 | line-height: 40px !important; 67 | color: #555; 68 | 69 | .task-item__button:hover & { 70 | color: #999; 71 | } 72 | } 73 | 74 | .icon--active { 75 | &, .task-item__button:hover & { 76 | color: #85bf6b; 77 | } 78 | } 79 | 80 | 81 | @keyframes fade-title { 82 | from { color: #fff; } 83 | to { color: #666; } 84 | } 85 | 86 | @keyframes strike-title { 87 | from { width: 0; } 88 | to { width: 100%; } 89 | } 90 | 91 | .task-item__title { 92 | display: inline-block; 93 | position: relative; 94 | max-width: 100%; 95 | line-height: 60px; 96 | outline: none; 97 | overflow: hidden; 98 | text-overflow: ellipsis; 99 | white-space: nowrap; 100 | 101 | &:after { 102 | position: absolute; 103 | left: 0; 104 | bottom: 0; 105 | border-top: 2px solid #85bf6b; 106 | width: 0; 107 | height: 46%; 108 | content: ''; 109 | } 110 | 111 | .task-item--completed & { 112 | color: #666; 113 | } 114 | 115 | .task-item--completed &:after { 116 | width: 100%; 117 | } 118 | 119 | .task-item--completed.task-item--status-updated & { 120 | animation: fade-title 120ms ease-in-out; 121 | } 122 | 123 | .task-item--completed.task-item--status-updated &:after { 124 | animation: strike-title 180ms ease-in-out; 125 | } 126 | } 127 | 128 | 129 | .task-item__input { 130 | outline: none; 131 | border: 0; 132 | padding: 0; 133 | width: 100%; 134 | height: 60px; 135 | color: inherit; 136 | font: inherit; 137 | background: transparent; 138 | 139 | // remove `x` 140 | &::-ms-clear { 141 | display: none; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /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 | "static-before-instance", 35 | "variables-before-functions" 36 | ], 37 | "no-arg": true, 38 | "no-bitwise": true, 39 | "no-console": [ 40 | true, 41 | "debug", 42 | "info", 43 | "time", 44 | "timeEnd", 45 | "trace" 46 | ], 47 | "no-construct": true, 48 | "no-debugger": true, 49 | "no-duplicate-super": true, 50 | "no-empty": false, 51 | "no-empty-interface": true, 52 | "no-eval": true, 53 | "no-inferrable-types": [ 54 | true, 55 | "ignore-params" 56 | ], 57 | "no-misused-new": true, 58 | "no-non-null-assertion": true, 59 | "no-shadowed-variable": true, 60 | "no-string-literal": false, 61 | "no-string-throw": true, 62 | "no-switch-case-fall-through": true, 63 | "no-trailing-whitespace": true, 64 | "no-unnecessary-initializer": true, 65 | "no-unused-expression": true, 66 | "no-use-before-declare": true, 67 | "no-var-keyword": true, 68 | "object-literal-sort-keys": false, 69 | "one-line": [ 70 | true, 71 | "check-open-brace", 72 | "check-catch", 73 | "check-else", 74 | "check-whitespace" 75 | ], 76 | "prefer-const": true, 77 | "quotemark": [ 78 | true, 79 | "single" 80 | ], 81 | "radix": true, 82 | "semicolon": [ 83 | "always" 84 | ], 85 | "triple-equals": [ 86 | true, 87 | "allow-null-check" 88 | ], 89 | "typedef-whitespace": [ 90 | true, 91 | { 92 | "call-signature": "nospace", 93 | "index-signature": "nospace", 94 | "parameter": "nospace", 95 | "property-declaration": "nospace", 96 | "variable-declaration": "nospace" 97 | } 98 | ], 99 | "typeof-compare": true, 100 | "unified-signatures": true, 101 | "variable-name": false, 102 | "whitespace": [ 103 | true, 104 | "check-branch", 105 | "check-decl", 106 | "check-operator", 107 | "check-separator", 108 | "check-type" 109 | ], 110 | "directive-selector": [ 111 | true, 112 | "attribute", 113 | "", 114 | "camelCase" 115 | ], 116 | "component-selector": [ 117 | true, 118 | "element", 119 | "app", 120 | "kebab-case" 121 | ], 122 | "use-input-property-decorator": true, 123 | "use-output-property-decorator": true, 124 | "use-host-property-decorator": true, 125 | "no-input-rename": true, 126 | "no-output-rename": true, 127 | "use-life-cycle-interface": true, 128 | "use-pipe-transform-interface": true, 129 | "component-class-suffix": true, 130 | "directive-class-suffix": true, 131 | "no-access-missing-member": true, 132 | "templates-use-public": true, 133 | "invoke-injectable": true 134 | } 135 | } 136 | --------------------------------------------------------------------------------