├── .editorconfig
├── .gitattributes
├── .gitignore
├── .prettierrc
├── .vscode
└── settings.json
├── LICENSE
├── README.md
├── angular.json
├── e2e
├── protractor.conf.js
├── src
│ ├── app.e2e-spec.ts
│ └── app.po.ts
└── tsconfig.e2e.json
├── package.json
├── screenshots
├── completed-todos.PNG
└── todos.PNG
├── server
├── assets
│ └── i18n
│ │ ├── da-lang.json
│ │ └── en-lang.json
└── index.js
├── src
├── app
│ ├── app-init.service.spec.ts
│ ├── app-init.service.ts
│ ├── app-routing.module.ts
│ ├── app.component.css
│ ├── app.component.html
│ ├── app.component.scss
│ ├── app.component.spec.ts
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── app.routes.ts
│ ├── core
│ │ ├── core.module.ts
│ │ ├── spinner-overlay
│ │ │ ├── spinner-overlay.component.html
│ │ │ ├── spinner-overlay.component.scss
│ │ │ ├── spinner-overlay.component.spec.ts
│ │ │ ├── spinner-overlay.component.ts
│ │ │ ├── spinner-overlay.module.ts
│ │ │ ├── spinner-overlay.service.spec.ts
│ │ │ └── spinner-overlay.service.ts
│ │ └── todo-list
│ │ │ ├── todo-list.service.spec.ts
│ │ │ └── todo-list.service.ts
│ ├── footer
│ │ ├── footer.component.css
│ │ ├── footer.component.html
│ │ ├── footer.component.spec.ts
│ │ └── footer.component.ts
│ ├── helpers
│ │ └── spy-helper.ts
│ ├── navbar
│ │ ├── navbar.component.css
│ │ ├── navbar.component.html
│ │ ├── navbar.component.spec.ts
│ │ └── navbar.component.ts
│ ├── shared
│ │ ├── app-material
│ │ │ └── app-material.module.ts
│ │ ├── cards-list
│ │ │ ├── cards-list.component.html
│ │ │ ├── cards-list.component.scss
│ │ │ ├── cards-list.component.ts
│ │ │ ├── cards-list.module.ts
│ │ │ ├── cards
│ │ │ │ ├── cards.component.html
│ │ │ │ ├── cards.component.scss
│ │ │ │ ├── cards.component.spec.ts
│ │ │ │ └── cards.component.ts
│ │ │ └── list
│ │ │ │ ├── list.component.html
│ │ │ │ ├── list.component.scss
│ │ │ │ ├── list.component.spec.ts
│ │ │ │ └── list.component.ts
│ │ ├── invalid-date.directive.ts
│ │ ├── models
│ │ │ ├── guid.ts
│ │ │ └── todo-item.ts
│ │ ├── shared.module.ts
│ │ ├── spinner-overlay-wrapper
│ │ │ ├── spinner-overlay-wrapper.component.html
│ │ │ ├── spinner-overlay-wrapper.component.scss
│ │ │ ├── spinner-overlay-wrapper.component.spec.ts
│ │ │ ├── spinner-overlay-wrapper.component.ts
│ │ │ └── spinner-overlay-wrapper.module.ts
│ │ ├── spinner
│ │ │ ├── spinner.component.html
│ │ │ ├── spinner.component.mock.ts
│ │ │ ├── spinner.component.scss
│ │ │ ├── spinner.component.spec.ts
│ │ │ ├── spinner.component.ts
│ │ │ └── spinner.module.ts
│ │ ├── todo-item-card
│ │ │ ├── todo-item-card.component.html
│ │ │ ├── todo-item-card.component.mock.ts
│ │ │ ├── todo-item-card.component.scss
│ │ │ ├── todo-item-card.component.spec.ts
│ │ │ └── todo-item-card.component.ts
│ │ └── todo-item-list-row
│ │ │ ├── todo-item-list-row.component.html
│ │ │ ├── todo-item-list-row.component.mock.ts
│ │ │ ├── todo-item-list-row.component.scss
│ │ │ ├── todo-item-list-row.component.spec.ts
│ │ │ └── todo-item-list-row.component.ts
│ ├── todo-list-completed
│ │ ├── todo-list-completed.component.css
│ │ ├── todo-list-completed.component.html
│ │ ├── todo-list-completed.component.spec.ts
│ │ ├── todo-list-completed.component.ts
│ │ └── todo-list-completed.module.ts
│ └── todo-list
│ │ ├── add-todo
│ │ ├── add-todo.component.css
│ │ ├── add-todo.component.html
│ │ ├── add-todo.component.mock.ts
│ │ ├── add-todo.component.spec.ts
│ │ ├── add-todo.component.ts
│ │ └── add-todo.module.ts
│ │ ├── todo-list.component.css
│ │ ├── todo-list.component.html
│ │ ├── todo-list.component.spec.ts
│ │ ├── todo-list.component.ts
│ │ └── todo-list.module.ts
├── assets
│ ├── .gitkeep
│ └── app-config.json
├── browserslist
├── environments
│ ├── dynamic-environment.ts
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── karma.conf.js
├── main.ts
├── polyfills.ts
├── styles.scss
├── styles
│ ├── positioning.scss
│ └── spinner.scss
├── test.ts
├── tsconfig.app.json
├── tsconfig.spec.json
└── tslint.json
├── tsconfig.json
├── tslint.json
└── yarn.lock
/.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 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | yarn-error.log
34 | testem.log
35 | /typings
36 |
37 | # System Files
38 | .DS_Store
39 | Thumbs.db
40 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "semi": true
4 | }
5 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.codeActionsOnSave": {
3 | "source.organizeImports": true
4 | },
5 | "tslint.autoFixOnSave": true,
6 | "editor.formatOnSave": true,
7 | "typescript.tsdk": "node_modules\\typescript\\lib"
8 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Christian Lüdemann
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.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AngularBestPracticesDemo
2 | A demo of Angular best practices including:
3 |
4 | - VSCode config for fix on saving and organize imports
5 | - Spinners
6 | - Auto formating and styling using TSLint and Prettier
7 | - A server to serve Todos and translations
8 | - ngx-translate for dynamic translations
9 |
10 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.1.1.
11 |
12 | ## Development server
13 |
14 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
15 |
16 | ## Code scaffolding
17 |
18 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
19 |
20 | ## Build
21 |
22 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
23 |
24 | ## Running unit tests
25 |
26 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
27 |
28 | ## Running end-to-end tests
29 |
30 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
31 |
32 | ## Further help
33 |
34 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
35 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "angular-demo-with-best-practices": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "prefix": "app",
11 | "schematics": {
12 | "@schematics/angular:component": {
13 | "styleext": "scss"
14 | }
15 | },
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-devkit/build-angular:browser",
19 | "options": {
20 | "outputPath": "dist/angular-demo-with-best-practices",
21 | "index": "src/index.html",
22 | "main": "src/main.ts",
23 | "polyfills": "src/polyfills.ts",
24 | "tsConfig": "src/tsconfig.app.json",
25 | "assets": [
26 | "src/favicon.ico",
27 | "src/assets"
28 | ],
29 | "styles": [
30 | "src/styles.scss"
31 | ],
32 | "scripts": []
33 | },
34 | "configurations": {
35 | "production": {
36 | "fileReplacements": [
37 | {
38 | "replace": "src/environments/environment.ts",
39 | "with": "src/environments/environment.prod.ts"
40 | }
41 | ],
42 | "optimization": true,
43 | "outputHashing": "all",
44 | "sourceMap": false,
45 | "extractCss": true,
46 | "namedChunks": false,
47 | "aot": true,
48 | "extractLicenses": true,
49 | "vendorChunk": false,
50 | "buildOptimizer": true,
51 | "budgets": [
52 | {
53 | "type": "initial",
54 | "maximumWarning": "2mb",
55 | "maximumError": "5mb"
56 | }
57 | ]
58 | }
59 | }
60 | },
61 | "serve": {
62 | "builder": "@angular-devkit/build-angular:dev-server",
63 | "options": {
64 | "browserTarget": "angular-demo-with-best-practices:build"
65 | },
66 | "configurations": {
67 | "production": {
68 | "browserTarget": "angular-demo-with-best-practices:build:production"
69 | }
70 | }
71 | },
72 | "extract-i18n": {
73 | "builder": "@angular-devkit/build-angular:extract-i18n",
74 | "options": {
75 | "browserTarget": "angular-demo-with-best-practices:build"
76 | }
77 | },
78 | "test": {
79 | "builder": "@angular-devkit/build-angular:karma",
80 | "options": {
81 | "main": "src/test.ts",
82 | "polyfills": "src/polyfills.ts",
83 | "tsConfig": "src/tsconfig.spec.json",
84 | "karmaConfig": "src/karma.conf.js",
85 | "styles": [
86 | "src/styles.scss"
87 | ],
88 | "scripts": [],
89 | "assets": [
90 | "src/favicon.ico",
91 | "src/assets"
92 | ]
93 | }
94 | },
95 | "lint": {
96 | "builder": "@angular-devkit/build-angular:tslint",
97 | "options": {
98 | "tsConfig": [
99 | "src/tsconfig.app.json",
100 | "src/tsconfig.spec.json"
101 | ],
102 | "exclude": [
103 | "**/node_modules/**"
104 | ]
105 | }
106 | }
107 | }
108 | },
109 | "angular-demo-with-best-practices-e2e": {
110 | "root": "e2e/",
111 | "projectType": "application",
112 | "prefix": "",
113 | "architect": {
114 | "e2e": {
115 | "builder": "@angular-devkit/build-angular:protractor",
116 | "options": {
117 | "protractorConfig": "e2e/protractor.conf.js",
118 | "devServerTarget": "angular-demo-with-best-practices:serve"
119 | },
120 | "configurations": {
121 | "production": {
122 | "devServerTarget": "angular-demo-with-best-practices:serve:production"
123 | }
124 | }
125 | },
126 | "lint": {
127 | "builder": "@angular-devkit/build-angular:tslint",
128 | "options": {
129 | "tsConfig": "e2e/tsconfig.e2e.json",
130 | "exclude": [
131 | "**/node_modules/**"
132 | ]
133 | }
134 | }
135 | }
136 | }
137 | },
138 | "defaultProject": "angular-demo-with-best-practices"
139 | }
--------------------------------------------------------------------------------
/e2e/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 | './src/**/*.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: require('path').join(__dirname, './tsconfig.e2e.json')
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('workspace-project App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to spinners-demo!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
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/app",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-demo-with-best-practices",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "nodemon server | ng serve",
7 | "start:server": "nodemon server",
8 | "build": "ng build",
9 | "test": "ng test",
10 | "lint": "ng lint",
11 | "e2e": "ng e2e"
12 | },
13 | "prettier": {
14 | "singleQuote": true,
15 | "printWidth": 100,
16 | "semi": true,
17 | "bracketSpacing": true,
18 | "arrowParens": "always",
19 | "parser": "typescript"
20 | },
21 | "private": true,
22 | "dependencies": {
23 | "@angular/animations": "~7.0.0",
24 | "@angular/cdk": "~7.0.3",
25 | "@angular/common": "~7.0.0",
26 | "@angular/compiler": "~7.0.0",
27 | "@angular/core": "~7.0.0",
28 | "@angular/forms": "~7.0.0",
29 | "@angular/http": "~7.0.0",
30 | "@angular/material": "^7.0.3",
31 | "@ng-bootstrap/ng-bootstrap": "^2.2.1",
32 | "@angular/platform-browser": "~7.0.0",
33 | "@angular/platform-browser-dynamic": "~7.0.0",
34 | "@angular/router": "~7.0.0",
35 | "@ngx-translate/core": "^10.0.2",
36 | "@ngx-translate/http-loader": "^3.0.1",
37 | "bootstrap": "^4.0.0",
38 | "core-js": "^2.5.4",
39 | "hammerjs": "^2.0.8",
40 | "cors": "^2.8.4",
41 | "rxjs": "~6.3.3",
42 | "zone.js": "~0.8.26"
43 | },
44 | "devDependencies": {
45 | "@angular-devkit/build-angular": "~0.10.0",
46 | "@angular/cli": "~7.0.5",
47 | "@angular/compiler-cli": "~7.0.0",
48 | "@angular/language-service": "~7.0.0",
49 | "@types/jasmine": "~2.8.8",
50 | "@types/jasminewd2": "~2.0.3",
51 | "@types/node": "~8.9.4",
52 | "codelyzer": "~4.5.0",
53 | "jasmine-core": "~2.99.1",
54 | "jasmine-spec-reporter": "~4.2.1",
55 | "karma": "~3.0.0",
56 | "karma-chrome-launcher": "~2.2.0",
57 | "nodemon": "^1.17.1",
58 | "karma-coverage-istanbul-reporter": "~2.0.1",
59 | "karma-jasmine": "~1.1.2",
60 | "karma-jasmine-html-reporter": "^0.2.2",
61 | "protractor": "~5.4.0",
62 | "ts-node": "~7.0.0",
63 | "tslint": "~5.11.0",
64 | "typescript": "~3.1.6"
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/screenshots/completed-todos.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/screenshots/completed-todos.PNG
--------------------------------------------------------------------------------
/screenshots/todos.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/screenshots/todos.PNG
--------------------------------------------------------------------------------
/server/assets/i18n/da-lang.json:
--------------------------------------------------------------------------------
1 | {
2 | "app-title": "TODO app",
3 | "choose-language": "Vælg sprog",
4 | "todo-list": "TODO liste",
5 | "completed-todos": "Udførte TODOs",
6 | "errors": {
7 | "invalid-form": "Ugyldig form"
8 | },
9 | "todo-item": {
10 | "completed": "Udført",
11 | "edit": "Redigér",
12 | "delete": "Slet"
13 | },
14 | "todo-list-section": {
15 | "show-cards": "Vis kort",
16 | "show-list": "Vis liste"
17 | },
18 | "add-todo": {
19 | "headline": "Tilføj TODO",
20 | "title": "Titel",
21 | "description": "Beskrivelse",
22 | "due-date": "Forfaldsdato",
23 | "create": "Opret"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/server/assets/i18n/en-lang.json:
--------------------------------------------------------------------------------
1 | {
2 | "app-title": "TODO app",
3 | "choose-language": "Choose language",
4 | "todo-list": "TODO list",
5 | "completed-todos": "Completed TODOs",
6 | "errors": {
7 | "invalid-form": "Invalid form"
8 | },
9 | "todo-item": {
10 | "complete": "Complete",
11 | "edit": "Edit",
12 | "delete": "Delete"
13 | },
14 | "todo-list-section": {
15 | "show-cards": "Show cards",
16 | "show-list": "Show list"
17 | },
18 | "add-todo": {
19 | "headline": "Add TODO",
20 | "title": "Title",
21 | "description": "Description",
22 | "due-date": "Due date",
23 | "create": "Create"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/server/index.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | const express = require('express');
3 | var cors = require('cors')
4 | var app = express();
5 |
6 | app.use(cors());
7 |
8 | app.use('/assets', express.static(path.resolve(__dirname, 'assets')));
9 | app.get('/todo-list', (req, res) => {
10 |
11 | const todoList = [
12 | { id: 'task1', title: 'Buy Milk', description: 'Remember to buy milk' },
13 | { id: 'task2', title: 'Go to the gym', description: 'Remember to work out' }
14 | ];
15 | return res.json(todoList);
16 | });
17 |
18 | const port = 8080;
19 | app.listen(port, () => console.log(`Example app listening on port ${port}!`));
20 |
--------------------------------------------------------------------------------
/src/app/app-init.service.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 |
3 | import { TestBed, async, inject } from '@angular/core/testing';
4 | import { AppInitService } from './app-init.service';
5 |
6 | describe('Service: AppInit', () => {
7 | beforeEach(() => {
8 | TestBed.configureTestingModule({
9 | providers: [AppInitService]
10 | });
11 | });
12 |
13 | it('should ...', inject([AppInitService], (service: AppInitService) => {
14 | expect(service).toBeTruthy();
15 | }));
16 | });
17 |
--------------------------------------------------------------------------------
/src/app/app-init.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { from } from 'rxjs';
3 | import { map } from 'rxjs/operators';
4 | declare var window: any;
5 |
6 | @Injectable()
7 | export class AppInitService {
8 |
9 | // This is the method you want to call at bootstrap
10 | // Important: It should return a Promise
11 | public init() {
12 | return from(
13 | fetch('assets/app-config.json').then(function (response) {
14 | return response.json();
15 | })
16 | ).pipe(
17 | map((config) => {
18 | window.config = config;
19 | return config;
20 | })).toPromise();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 |
4 | const routes: Routes = [];
5 |
6 | @NgModule({
7 | imports: [RouterModule.forRoot(routes)],
8 | exports: [RouterModule]
9 | })
10 | export class AppRoutingModule { }
11 |
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/src/app/app.component.css
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/app/app.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/src/app/app.component.scss
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { APP_BASE_HREF } from '@angular/common';
2 | import { HttpClientModule } from '@angular/common/http';
3 | import { async, TestBed } from '@angular/core/testing';
4 | import { FormsModule } from '@angular/forms';
5 | import { BrowserModule } from '@angular/platform-browser';
6 | import { AppComponent } from '@app/app.component';
7 | import { appRouterModule } from '@app/app.routes';
8 | import { CoreModule } from '@app/core/core.module';
9 | import { FooterComponent } from '@app/footer/footer.component';
10 | import { NavbarComponent } from '@app/navbar/navbar.component';
11 | import { InvalidDateValidatorDirective } from '@app/shared/invalid-date.directive';
12 | import { SpinnerModule } from '@app/shared/spinner/spinner.module';
13 | import { TodoListCompletedComponent } from '@app/todo-list-completed/todo-list-completed.component';
14 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
15 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
16 | import { TranslateModule } from '@ngx-translate/core';
17 | import { TodoItemListRowComponent } from './shared/todo-item-list-row/todo-item-list-row.component';
18 | import { AddTodoComponent } from './todo-list/add-todo/add-todo.component';
19 | describe('AppComponent', () => {
20 | beforeEach(async(() => {
21 | TestBed.configureTestingModule({
22 | declarations: [
23 | AppComponent,
24 | NavbarComponent,
25 | TodoListComponent,
26 | TodoItemListRowComponent,
27 | FooterComponent,
28 | AddTodoComponent,
29 | TodoListCompletedComponent,
30 | InvalidDateValidatorDirective
31 | ],
32 | imports: [
33 | BrowserModule,
34 | NgbModule.forRoot(),
35 | TranslateModule.forRoot(),
36 | FormsModule,
37 | CoreModule,
38 | SpinnerModule,
39 | HttpClientModule,
40 | appRouterModule
41 | ],
42 | providers: [{ provide: APP_BASE_HREF, useValue: '/' }]
43 | }).compileComponents();
44 | }));
45 | it('should create the app', async(() => {
46 | const fixture = TestBed.createComponent(AppComponent);
47 | const app = fixture.debugElement.componentInstance;
48 | expect(app).toBeTruthy();
49 | }));
50 | });
51 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { TranslateService } from '@ngx-translate/core';
3 |
4 | @Component({
5 | selector: 'app-root',
6 | templateUrl: './app.component.html',
7 | styleUrls: ['./app.component.css']
8 | })
9 | export class AppComponent {
10 | constructor(translate: TranslateService) {
11 | translate.addLangs(['en', 'da']);
12 | translate.setDefaultLang('en');
13 |
14 | const browserLang = translate.getBrowserLang();
15 | translate.use(browserLang.match(/en|da/) ? browserLang : 'en');
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { HttpClient, HttpClientModule } from '@angular/common/http';
2 | import { APP_INITIALIZER, NgModule } from '@angular/core';
3 | import { FormsModule } from '@angular/forms';
4 | import { BrowserModule } from '@angular/platform-browser';
5 | import { AppInitService } from '@app/app-init.service';
6 | import { AppComponent } from '@app/app.component';
7 | import { appRouterModule } from '@app/app.routes';
8 | import { CoreModule } from '@app/core/core.module';
9 | import { FooterComponent } from '@app/footer/footer.component';
10 | import { NavbarComponent } from '@app/navbar/navbar.component';
11 | import { SharedModule } from '@app/shared/shared.module';
12 | import { TodoListCompletedModule } from '@app/todo-list-completed/todo-list-completed.module';
13 | import { TodoListModule } from '@app/todo-list/todo-list.module';
14 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
15 | import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
16 | import { TranslateHttpLoader } from '@ngx-translate/http-loader';
17 | import { environment } from 'environments/environment';
18 |
19 | export function init_app(appLoadService: AppInitService) {
20 | return () => appLoadService.init();
21 | }
22 | export function HttpLoaderFactory(httpClient: HttpClient) {
23 | return new TranslateHttpLoader(
24 | httpClient,
25 | environment.feServerUrl + '/assets/i18n/',
26 | '-lang.json'
27 | );
28 | }
29 | @NgModule({
30 | declarations: [AppComponent, NavbarComponent, FooterComponent],
31 | imports: [
32 | BrowserModule,
33 | NgbModule.forRoot(),
34 | FormsModule,
35 | CoreModule,
36 | SharedModule,
37 | HttpClientModule,
38 | appRouterModule,
39 | TodoListCompletedModule,
40 | TodoListModule,
41 | TranslateModule.forRoot({
42 | loader: {
43 | provide: TranslateLoader,
44 | useFactory: HttpLoaderFactory,
45 | deps: [HttpClient]
46 | }
47 | })
48 | ],
49 | providers: [
50 | AppInitService,
51 | AppInitService,
52 | {
53 | provide: APP_INITIALIZER,
54 | useFactory: init_app,
55 | deps: [AppInitService],
56 | multi: true
57 | }
58 | ],
59 | bootstrap: [AppComponent]
60 | })
61 | export class AppModule {}
62 |
--------------------------------------------------------------------------------
/src/app/app.routes.ts:
--------------------------------------------------------------------------------
1 | import { Routes, RouterModule } from '@angular/router';
2 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
3 | import { TodoListCompletedComponent } from '@app/todo-list-completed/todo-list-completed.component';
4 |
5 | export const rootPath = '';
6 | export const completedTodoPath = 'completed-todos';
7 |
8 | const appRoutes: Routes = [
9 | {
10 | path: rootPath,
11 | component: TodoListComponent,
12 | pathMatch: 'full'
13 | },
14 | {
15 | path: completedTodoPath,
16 | component: TodoListCompletedComponent
17 | },
18 | ];
19 |
20 | export const appRouterModule = RouterModule.forRoot(appRoutes);
21 |
--------------------------------------------------------------------------------
/src/app/core/core.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { OverlayModule } from '@angular/cdk/overlay';
3 | import { SpinnerOverlayModule } from '@app/core/spinner-overlay/spinner-overlay.module';
4 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
5 |
6 | @NgModule({
7 | imports: [
8 | OverlayModule,
9 | SpinnerOverlayModule
10 | ],
11 | declarations: [],
12 | providers: [TodoListService]
13 | })
14 | export class CoreModule { }
15 |
--------------------------------------------------------------------------------
/src/app/core/spinner-overlay/spinner-overlay.component.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/app/core/spinner-overlay/spinner-overlay.component.scss:
--------------------------------------------------------------------------------
1 | .spinner-wrapper {
2 | position: fixed;
3 | width: 100%;
4 | height: 100%;
5 | display: flex;
6 | justify-content: center;
7 | align-items: center;
8 | top: 0;
9 | left: 0;
10 | background-color: rgba(255, 255, 255, 0.5);
11 | z-index: 998;
12 | app-spinner {
13 | width: 6rem;
14 | height: 6rem;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/core/spinner-overlay/spinner-overlay.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { SpinnerComponent } from '@app/shared/spinner/spinner.component';
4 | import { SpinnerOverlayComponent } from '@app/core/spinner-overlay/spinner-overlay.component';
5 |
6 | describe('SpinnerOverlayComponent', () => {
7 | let component: SpinnerOverlayComponent;
8 | let fixture: ComponentFixture;
9 |
10 | beforeEach(async(() => {
11 | TestBed.configureTestingModule({
12 | declarations: [SpinnerOverlayComponent, SpinnerComponent]
13 | }).compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(SpinnerOverlayComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/core/spinner-overlay/spinner-overlay.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-spinner-overlay',
5 | templateUrl: './spinner-overlay.component.html',
6 | styleUrls: ['./spinner-overlay.component.scss']
7 | })
8 | export class SpinnerOverlayComponent implements OnInit {
9 | @Input() public message: string;
10 | constructor() {}
11 |
12 | public ngOnInit() {}
13 | }
14 |
--------------------------------------------------------------------------------
/src/app/core/spinner-overlay/spinner-overlay.module.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { NgModule } from '@angular/core';
3 | import { SpinnerOverlayService } from '@app/core/spinner-overlay/spinner-overlay.service';
4 | import { SpinnerOverlayComponent } from '@app/core/spinner-overlay/spinner-overlay.component';
5 | import { SpinnerModule } from '@app/shared/spinner/spinner.module';
6 |
7 | @NgModule({
8 | imports: [CommonModule, SpinnerModule],
9 | declarations: [SpinnerOverlayComponent],
10 | entryComponents: [SpinnerOverlayComponent],
11 | providers: [SpinnerOverlayService],
12 | exports: []
13 | })
14 | export class SpinnerOverlayModule {}
15 |
--------------------------------------------------------------------------------
/src/app/core/spinner-overlay/spinner-overlay.service.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 |
3 | import { Overlay } from '@angular/cdk/overlay';
4 | import { inject, TestBed } from '@angular/core/testing';
5 | import { SpinnerOverlayService } from '@app/core/spinner-overlay/spinner-overlay.service';
6 |
7 | describe('Service: SpinnerOverlay', () => {
8 | beforeEach(() => {
9 | TestBed.configureTestingModule({
10 | providers: [SpinnerOverlayService, Overlay]
11 | });
12 | });
13 |
14 | it(
15 | 'should ...',
16 | inject([SpinnerOverlayService], (service: SpinnerOverlayService) => {
17 | expect(service).toBeTruthy();
18 | })
19 | );
20 | });
21 |
--------------------------------------------------------------------------------
/src/app/core/spinner-overlay/spinner-overlay.service.ts:
--------------------------------------------------------------------------------
1 | import { Overlay, OverlayRef } from '@angular/cdk/overlay';
2 | import { ComponentPortal } from '@angular/cdk/portal';
3 | import { Injectable } from '@angular/core';
4 | import { SpinnerOverlayWrapperComponent } from '@app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.component';
5 | import { SpinnerOverlayComponent } from '@app/core/spinner-overlay/spinner-overlay.component';
6 |
7 | @Injectable({
8 | providedIn: 'root'
9 | })
10 | export class SpinnerOverlayService {
11 | private overlayRef: OverlayRef = null;
12 |
13 | constructor(private overlay: Overlay) {}
14 |
15 | public show(message = '') {
16 | // Returns an OverlayRef (which is a PortalHost)
17 |
18 | if (!this.overlayRef) {
19 | this.overlayRef = this.overlay.create();
20 | }
21 |
22 | // Create ComponentPortal that can be attached to a PortalHost
23 | const spinnerOverlayPortal = new ComponentPortal(SpinnerOverlayComponent);
24 |
25 | // run in async context for triggering "tick", thus avoid ExpressionChangedAfterItHasBeenCheckedError
26 | setTimeout(() => {
27 | const component = this.overlayRef.attach(spinnerOverlayPortal); // Attach ComponentPortal to PortalHost
28 |
29 | // TODO: set message
30 | // component.instance.message = message;
31 | });
32 | }
33 |
34 | public hide() {
35 | if (!!this.overlayRef) {
36 | this.overlayRef.detach();
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/app/core/todo-list/todo-list.service.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 |
3 | import { HttpClient } from '@angular/common/http';
4 | import { inject, TestBed } from '@angular/core/testing';
5 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
6 | import { TODOItem } from '@app/shared/models/todo-item';
7 | import { of } from 'rxjs';
8 |
9 | describe('Service: TodoList', () => {
10 | let todoListService: TodoListService;
11 | const httpClientSpy: jasmine.SpyObj = jasmine.createSpyObj('httpClient', ['get']);
12 | httpClientSpy.get.and.returnValue(of([new TODOItem('Buy Milk', 'Lala')]));
13 | beforeEach(() => {
14 | TestBed.configureTestingModule({
15 | providers: [TodoListService,
16 | {
17 | provide: HttpClient,
18 | useValue: httpClientSpy
19 | }]
20 | });
21 | });
22 |
23 |
24 | beforeEach(inject([TodoListService], (service: TodoListService) => {
25 | todoListService = service;
26 | }));
27 |
28 | it('should be defined', () => {
29 | expect(todoListService).toBeTruthy();
30 | });
31 |
32 | it('should make a http get request', () => {
33 |
34 | expect(httpClientSpy.get).toHaveBeenCalled();
35 | expect(todoListService.todoList.length).toBe(1);
36 | });
37 | });
38 |
--------------------------------------------------------------------------------
/src/app/core/todo-list/todo-list.service.ts:
--------------------------------------------------------------------------------
1 | import { HttpClient } from '@angular/common/http';
2 | import { Injectable } from '@angular/core';
3 | import { TODOItem } from '@app/shared/models/todo-item';
4 | import { of } from 'rxjs';
5 | import { delay } from 'rxjs/operators';
6 |
7 | @Injectable()
8 | export class TodoListService {
9 |
10 | private _todoList: TODOItem[] = [];
11 |
12 | public get todoList(): TODOItem[] {
13 | return this._todoList;
14 | }
15 |
16 | private todoListUrl = '//localhost:8080/todo-list';
17 |
18 | constructor(httpClient: HttpClient) {
19 | httpClient.get>(this.todoListUrl).subscribe(data => {
20 | this._todoList = data;
21 | });
22 | }
23 |
24 | public addTodo(todo: TODOItem) {
25 | return of(null).pipe(delay(2000));
26 | }
27 |
28 | public updateTodo(todo: TODOItem) {
29 | return of(null).pipe(delay(2000));
30 | }
31 |
32 | public deleteTodo(id: string) {
33 | return of(null).pipe(delay(2000));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/app/footer/footer.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/src/app/footer/footer.component.css
--------------------------------------------------------------------------------
/src/app/footer/footer.component.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/app/footer/footer.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { By } from '@angular/platform-browser';
4 | import { DebugElement } from '@angular/core';
5 |
6 | import { FooterComponent } from '@app/footer/footer.component';
7 |
8 | describe('FooterComponent', () => {
9 | let component: FooterComponent;
10 | let fixture: ComponentFixture;
11 |
12 | beforeEach(async(() => {
13 | TestBed.configureTestingModule({
14 | declarations: [ FooterComponent ]
15 | })
16 | .compileComponents();
17 | }));
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(FooterComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/src/app/footer/footer.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-footer',
5 | templateUrl: './footer.component.html',
6 | styleUrls: ['./footer.component.css']
7 | })
8 | export class FooterComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit() {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/helpers/spy-helper.ts:
--------------------------------------------------------------------------------
1 | import { Provider, Type } from '@angular/core';
2 | export type Mock = T & { [P in keyof T]: T[P] & jasmine.Spy };
3 | export class SpyHelper {
4 |
5 | public static createMagicalMock(type: Type): Mock {
6 | const target: any = {};
7 |
8 | function installProtoMethods(proto: any) {
9 | if (proto === null || proto === Object.prototype) {
10 | return;
11 | }
12 |
13 | for (let key of Object.getOwnPropertyNames(proto)) {
14 | const descriptor = Object.getOwnPropertyDescriptor(proto, key)!;
15 |
16 | if (typeof descriptor.value === 'function' && key !== 'constructor') {
17 | target[key] = jasmine.createSpy(key);
18 | }
19 | }
20 |
21 | installProtoMethods(Object.getPrototypeOf(proto));
22 | }
23 |
24 | installProtoMethods(type.prototype);
25 |
26 | return target;
27 | }
28 |
29 | public static provideMagicalMock(type: Type): Provider {
30 | return {
31 | provide: type,
32 | useFactory: () => SpyHelper.createMagicalMock(type),
33 | };
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/app/navbar/navbar.component.css:
--------------------------------------------------------------------------------
1 | .nav-active {
2 | background-color: #dae0e5;
3 | }
4 |
5 | a:hover {
6 | background-color: #eef4f9
7 | }
--------------------------------------------------------------------------------
/src/app/navbar/navbar.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/navbar/navbar.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { APP_BASE_HREF } from '@angular/common';
2 | import { HttpClientModule } from '@angular/common/http';
3 | import { NO_ERRORS_SCHEMA } from '@angular/core';
4 | /* tslint:disable:no-unused-variable */
5 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
6 | import { FormsModule } from '@angular/forms';
7 | import { BrowserModule } from '@angular/platform-browser';
8 | import { AppComponent } from '@app/app.component';
9 | import { appRouterModule } from '@app/app.routes';
10 | import { CoreModule } from '@app/core/core.module';
11 | import { FooterComponent } from '@app/footer/footer.component';
12 | import { NavbarComponent } from '@app/navbar/navbar.component';
13 | import { TodoItemListRowComponent } from '@app/shared/todo-item-list-row/todo-item-list-row.component';
14 | import { TodoListCompletedComponent } from '@app/todo-list-completed/todo-list-completed.component';
15 | import { AddTodoComponent } from '@app/todo-list/add-todo/add-todo.component';
16 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
17 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
18 | import { TranslateModule } from '@ngx-translate/core';
19 |
20 | describe('NavbarComponent', () => {
21 | let component: NavbarComponent;
22 | let fixture: ComponentFixture;
23 |
24 | beforeEach(async(() => {
25 | TestBed.configureTestingModule({
26 | declarations: [
27 | AppComponent,
28 | NavbarComponent,
29 | TodoListComponent,
30 | TodoItemListRowComponent,
31 | FooterComponent,
32 | AddTodoComponent,
33 | TodoListCompletedComponent
34 | ],
35 | imports: [
36 | BrowserModule,
37 | NgbModule.forRoot(),
38 | TranslateModule.forRoot(),
39 | FormsModule,
40 | CoreModule,
41 | HttpClientModule,
42 | appRouterModule
43 | ],
44 | providers: [{ provide: APP_BASE_HREF, useValue: '/' }],
45 | schemas: [NO_ERRORS_SCHEMA]
46 | }).compileComponents();
47 | }));
48 |
49 | beforeEach(() => {
50 | fixture = TestBed.createComponent(NavbarComponent);
51 | component = fixture.componentInstance;
52 | fixture.detectChanges();
53 | });
54 |
55 | it('should create', () => {
56 | expect(component).toBeTruthy();
57 | });
58 | });
59 |
--------------------------------------------------------------------------------
/src/app/navbar/navbar.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { TranslateService } from '@ngx-translate/core';
3 |
4 | @Component({
5 | selector: 'app-navbar',
6 | templateUrl: './navbar.component.html',
7 | styleUrls: ['./navbar.component.css']
8 | })
9 | export class NavbarComponent implements OnInit {
10 |
11 | constructor(public translate: TranslateService) {
12 | }
13 |
14 | public ngOnInit() {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/shared/app-material/app-material.module.ts:
--------------------------------------------------------------------------------
1 | import { DragDropModule } from '@angular/cdk/drag-drop';
2 | import { ScrollingModule } from '@angular/cdk/scrolling';
3 | import { CdkTableModule } from '@angular/cdk/table';
4 | import { CdkTreeModule } from '@angular/cdk/tree';
5 | import { NgModule } from '@angular/core';
6 | import {
7 | MatAutocompleteModule,
8 | MatBadgeModule,
9 | MatBottomSheetModule,
10 | MatButtonModule,
11 | MatButtonToggleModule,
12 | MatCardModule,
13 | MatCheckboxModule,
14 | MatChipsModule,
15 | MatDatepickerModule,
16 | MatDialogModule,
17 | MatDividerModule,
18 | MatExpansionModule,
19 | MatGridListModule,
20 | MatIconModule,
21 | MatInputModule,
22 | MatListModule,
23 | MatMenuModule,
24 | MatNativeDateModule,
25 | MatPaginatorModule,
26 | MatProgressBarModule,
27 | MatProgressSpinnerModule,
28 | MatRadioModule,
29 | MatRippleModule,
30 | MatSelectModule,
31 | MatSidenavModule,
32 | MatSliderModule,
33 | MatSlideToggleModule,
34 | MatSnackBarModule,
35 | MatSortModule,
36 | MatStepperModule,
37 | MatTableModule,
38 | MatTabsModule,
39 | MatToolbarModule,
40 | MatTooltipModule,
41 | MatTreeModule
42 | } from '@angular/material';
43 |
44 | @NgModule({
45 | exports: [
46 | CdkTableModule,
47 | CdkTreeModule,
48 | DragDropModule,
49 | MatAutocompleteModule,
50 | MatBadgeModule,
51 | MatBottomSheetModule,
52 | MatButtonModule,
53 | MatButtonToggleModule,
54 | MatCardModule,
55 | MatCheckboxModule,
56 | MatChipsModule,
57 | MatStepperModule,
58 | MatDatepickerModule,
59 | MatDialogModule,
60 | MatDividerModule,
61 | MatExpansionModule,
62 | MatGridListModule,
63 | MatIconModule,
64 | MatInputModule,
65 | MatListModule,
66 | MatMenuModule,
67 | MatNativeDateModule,
68 | MatPaginatorModule,
69 | MatProgressBarModule,
70 | MatProgressSpinnerModule,
71 | MatRadioModule,
72 | MatRippleModule,
73 | MatSelectModule,
74 | MatSidenavModule,
75 | MatSliderModule,
76 | MatSlideToggleModule,
77 | MatSnackBarModule,
78 | MatSortModule,
79 | MatTableModule,
80 | MatTabsModule,
81 | MatToolbarModule,
82 | MatTooltipModule,
83 | MatTreeModule,
84 | ScrollingModule
85 | ]
86 | })
87 | export class AppMaterialModule {}
88 |
89 | /** Copyright 2018 Google Inc. All Rights Reserved.
90 | Use of this source code is governed by an MIT-style license that
91 | can be found in the LICENSE file at http://angular.io/license */
92 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/cards-list.component.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/cards-list.component.scss:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/cards-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-cards-list',
5 | templateUrl: './cards-list.component.html',
6 | styleUrls: ['./cards-list.component.scss']
7 | })
8 | export class CardsTableComponent implements OnInit {
9 | @Input() public data: any;
10 | @Input() public cardRef: any;
11 | @Input() public listRef: any;
12 |
13 | private preferedShowModeKey = 'typeToShow';
14 | public get typeToShow(): string {
15 | return window.localStorage.getItem(this.preferedShowModeKey) || 'table';
16 | }
17 | public set typeToShow(showMode: string) {
18 | window.localStorage.setItem(this.preferedShowModeKey, showMode);
19 | }
20 |
21 | constructor() {}
22 |
23 | public ngOnInit() {}
24 |
25 | public showCards() {
26 | this.typeToShow = 'cards';
27 | }
28 |
29 | public showTable() {
30 | this.typeToShow = 'table';
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/cards-list.module.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { NgModule } from '@angular/core';
3 | import { TranslateModule } from '@ngx-translate/core';
4 | import { AppMaterialModule } from '../app-material/app-material.module';
5 | import { CardsTableComponent } from './cards-list.component';
6 | import { CardsComponent } from './cards/cards.component';
7 | import { ListComponent } from './list/list.component';
8 |
9 | @NgModule({
10 | imports: [CommonModule, AppMaterialModule, TranslateModule],
11 | declarations: [CardsTableComponent, ListComponent, CardsComponent],
12 | exports: [CardsTableComponent]
13 | })
14 | export class CardListModule {}
15 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/cards/cards.component.html:
--------------------------------------------------------------------------------
1 | 0; else noContent">
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | {{'taskCards.noData' | translate}}
11 |
12 |
13 |
14 |
15 | {{'taskCards.noCardRef' | translate}}
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/cards/cards.component.scss:
--------------------------------------------------------------------------------
1 | .cards-wrapper {
2 | display: flex;
3 | flex-wrap: wrap;
4 | flex-direction: row;
5 | }
6 |
7 | .card-item {
8 | min-width: 280px;
9 | margin: 5px;
10 | flex-basis: 280px;
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/cards/cards.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { By } from '@angular/platform-browser';
4 | import { DebugElement } from '@angular/core';
5 |
6 | import { CardsComponent } from './cards.component';
7 |
8 | describe('CardsComponent', () => {
9 | let component: CardsComponent;
10 | let fixture: ComponentFixture;
11 |
12 | beforeEach(async(() => {
13 | TestBed.configureTestingModule({
14 | declarations: [ CardsComponent ]
15 | })
16 | .compileComponents();
17 | }));
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(CardsComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/cards/cards.component.ts:
--------------------------------------------------------------------------------
1 | import { ChangeDetectionStrategy, Component, Input, OnInit, TemplateRef } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-cards',
5 | templateUrl: './cards.component.html',
6 | styleUrls: ['./cards.component.scss'],
7 | changeDetection: ChangeDetectionStrategy.OnPush
8 | })
9 | export class CardsComponent implements OnInit {
10 | @Input() public cardRef: TemplateRef;
11 | @Input() public data: any;
12 |
13 | constructor() {}
14 |
15 | public ngOnInit() {}
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/list/list.component.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/list/list.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/src/app/shared/cards-list/list/list.component.scss
--------------------------------------------------------------------------------
/src/app/shared/cards-list/list/list.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { ListComponent } from './list.component';
4 |
5 | describe('TableComponent', () => {
6 | let component: ListComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ListComponent]
12 | }).compileComponents();
13 | }));
14 |
15 | beforeEach(() => {
16 | fixture = TestBed.createComponent(ListComponent);
17 | component = fixture.componentInstance;
18 | fixture.detectChanges();
19 | });
20 |
21 | it('should create', () => {
22 | expect(component).toBeTruthy();
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/src/app/shared/cards-list/list/list.component.ts:
--------------------------------------------------------------------------------
1 | import { ChangeDetectionStrategy, Component, Input, OnInit, TemplateRef } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-list',
5 | templateUrl: './list.component.html',
6 | styleUrls: ['./list.component.scss'],
7 | changeDetection: ChangeDetectionStrategy.OnPush
8 | })
9 | export class ListComponent implements OnInit {
10 | @Input() public listRef: TemplateRef;
11 | @Input() public data: any;
12 |
13 | constructor() {}
14 |
15 | public ngOnInit() {}
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/shared/invalid-date.directive.ts:
--------------------------------------------------------------------------------
1 | import { ValidatorFn, AbstractControl, NG_VALIDATORS, Validator } from '@angular/forms';
2 | import { Directive, Input } from '@angular/core';
3 |
4 | export function InvalidDateValidator(): ValidatorFn {
5 | return (control: AbstractControl): { [key: string]: any } => {
6 | const date = new Date(control.value);
7 | const invalidDate = !control.value || date.getMonth === undefined;
8 | return invalidDate ? { 'invalidDate': { value: control.value } } : null;
9 | };
10 | }
11 |
12 | @Directive({
13 | selector: '[appInvalidDate]',
14 | providers: [{ provide: NG_VALIDATORS, useExisting: InvalidDateValidatorDirective, multi: true }]
15 | })
16 | export class InvalidDateValidatorDirective implements Validator {
17 | // tslint:disable-next-line:no-input-rename
18 | @Input('appInvalidDate') invalidDate: string;
19 | validate(control: AbstractControl): { [key: string]: any } {
20 | return this.invalidDate ? InvalidDateValidator()(control)
21 | : null;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/app/shared/models/guid.ts:
--------------------------------------------------------------------------------
1 |
2 | /*tslint:disable:no-bitwise*/
3 | // Class for creating Guids: https://github.com/Steve-Fenton/TypeScriptUtilities/blob/master/Guid
4 |
5 | export class Guid {
6 | static newGuid() {
7 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
8 | const r = Math.random() * 16, v = c === 'x' ? r : (r & 0x3 | 0x8);
9 | return v.toString(16);
10 | });
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/app/shared/models/todo-item.ts:
--------------------------------------------------------------------------------
1 | import { Guid } from '@app/shared/models/guid';
2 |
3 | export class TODOItem {
4 | constructor(title: string, description: string, dueDate: string = null) {
5 | this.id = Guid.newGuid();
6 | this.title = title;
7 | this.description = description;
8 | this.dueDate = dueDate;
9 | }
10 |
11 | public id: string;
12 | public title: string;
13 | public description: string;
14 | public dueDate?: string;
15 | public completed?: boolean;
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/shared/shared.module.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { NgModule } from '@angular/core';
3 | import { InvalidDateValidatorDirective } from '@app/shared/invalid-date.directive';
4 | import { SpinnerOverlayWrapperModule } from '@app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.module';
5 | import { SpinnerModule } from '@app/shared/spinner/spinner.module';
6 | import { TranslateModule } from '@ngx-translate/core';
7 | import { AppMaterialModule } from './app-material/app-material.module';
8 | import { CardListModule } from './cards-list/cards-list.module';
9 | import { TodoItemCardComponent } from './todo-item-card/todo-item-card.component';
10 | import { TodoItemListRowComponent } from './todo-item-list-row/todo-item-list-row.component';
11 |
12 | @NgModule({
13 | imports: [
14 | CommonModule,
15 | SpinnerModule,
16 | SpinnerOverlayWrapperModule,
17 | TranslateModule,
18 | CardListModule,
19 | AppMaterialModule
20 | ],
21 | declarations: [InvalidDateValidatorDirective, TodoItemListRowComponent, TodoItemCardComponent],
22 | exports: [
23 | InvalidDateValidatorDirective,
24 | SpinnerModule,
25 | SpinnerOverlayWrapperModule,
26 | TranslateModule,
27 | CardListModule,
28 | TodoItemListRowComponent,
29 | TodoItemCardComponent,
30 | AppMaterialModule
31 | ]
32 | })
33 | export class SharedModule {}
34 |
--------------------------------------------------------------------------------
/src/app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.component.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/src/app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.component.scss:
--------------------------------------------------------------------------------
1 | .wrapper {
2 | width: 100%;
3 | height: 100%;
4 | }
5 |
6 | .overlay {
7 | position: absolute;
8 | z-index: 1002;
9 | background-color: rgba(255, 255, 255, 0.5);
10 | width: 100%;
11 | height: 100%;
12 | }
13 |
14 | .spinner-wrapper {
15 | display: flex;
16 | justify-content: center;
17 | justify-items: center;
18 | }
19 |
--------------------------------------------------------------------------------
/src/app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { SpinnerOverlayWrapperComponent } from '@app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.component';
4 | import { SpinnerModule } from '@app/shared/spinner/spinner.module';
5 |
6 |
7 | describe('SpinnerOverlayWrapperComponent', () => {
8 | let component: SpinnerOverlayWrapperComponent;
9 | let fixture: ComponentFixture;
10 |
11 | beforeEach(async(() => {
12 | TestBed.configureTestingModule({
13 | declarations: [SpinnerOverlayWrapperComponent],
14 | imports: [SpinnerModule]
15 | })
16 | .compileComponents();
17 | }));
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(SpinnerOverlayWrapperComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/src/app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-spinner-overlay-wrapper',
5 | templateUrl: './spinner-overlay-wrapper.component.html',
6 | styleUrls: ['./spinner-overlay-wrapper.component.scss']
7 | })
8 | export class SpinnerOverlayWrapperComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit() {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.module.ts:
--------------------------------------------------------------------------------
1 | import { SpinnerModule } from '@app/shared/spinner/spinner.module';
2 | import { NgModule } from '@angular/core';
3 | import { SpinnerOverlayWrapperComponent } from '@app/shared/spinner-overlay-wrapper/spinner-overlay-wrapper.component';
4 |
5 | @NgModule({
6 | imports: [SpinnerModule],
7 | declarations: [SpinnerOverlayWrapperComponent],
8 | exports: [SpinnerOverlayWrapperComponent]
9 | })
10 | export class SpinnerOverlayWrapperModule {
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/shared/spinner/spinner.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | {{message}}
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/app/shared/spinner/spinner.component.mock.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, OnInit } from '@angular/core';
2 | import { SpinnerComponent } from '@app/shared/spinner/spinner.component';
3 |
4 | @Component({
5 | selector: 'app-spinner',
6 | template: '',
7 | })
8 | export class SpinnerComponentMock implements OnInit, SpinnerComponent {
9 |
10 | @Input() message = '';
11 |
12 | constructor() { }
13 |
14 | ngOnInit() {
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/app/shared/spinner/spinner.component.scss:
--------------------------------------------------------------------------------
1 | @import "~styles/spinner";
--------------------------------------------------------------------------------
/src/app/shared/spinner/spinner.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { By } from '@angular/platform-browser';
4 | import { DebugElement } from '@angular/core';
5 |
6 | import { SpinnerComponent } from '@app/shared/spinner/spinner.component';
7 |
8 | describe('SpinnerComponent', () => {
9 | let component: SpinnerComponent;
10 | let fixture: ComponentFixture;
11 |
12 | beforeEach(async(() => {
13 | TestBed.configureTestingModule({
14 | declarations: [ SpinnerComponent ]
15 | })
16 | .compileComponents();
17 | }));
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(SpinnerComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/src/app/shared/spinner/spinner.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, Input } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-spinner',
5 | templateUrl: './spinner.component.html',
6 | styleUrls: ['./spinner.component.scss']
7 | })
8 | export class SpinnerComponent implements OnInit {
9 |
10 | @Input() message = '';
11 |
12 | constructor() { }
13 |
14 | ngOnInit() {
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/app/shared/spinner/spinner.module.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { NgModule } from '@angular/core';
3 | import { SpinnerComponent } from '@app/shared/spinner/spinner.component';
4 |
5 | @NgModule({
6 | imports: [CommonModule],
7 | declarations: [SpinnerComponent],
8 | exports: [SpinnerComponent]
9 | })
10 | export class SpinnerModule {
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-card/todo-item-card.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{todoItem.title}}
5 | {{todoItem.description}}
6 |
7 |
8 |
9 | {{'add-todo.due-date' | translate}}:
10 | {{todoItem.dueDate}}
11 |
12 |
13 |
14 |
15 |
18 |
21 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-card/todo-item-card.component.mock.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 | import { TODOItem } from '@app/shared/models/todo-item';
3 | import { TodoItemCardComponent } from './todo-item-card.component';
4 |
5 | @Component({
6 | selector: 'app-todo-item-card',
7 | template: ''
8 | })
9 | // tslint:disable-next-line:component-class-suffix
10 | export class TodoItemCardComponentMock implements OnInit, TodoItemCardComponent {
11 | @Input() public todoItem: TODOItem;
12 | @Input() public readOnlyTODO: boolean;
13 | @Output() public todoDelete = new EventEmitter();
14 | @Output() public todoEdit = new EventEmitter();
15 |
16 | constructor() {}
17 |
18 | public ngOnInit() {}
19 |
20 | public completeClick() {
21 | this.todoItem.completed = !this.todoItem.completed;
22 | }
23 |
24 | public deleteClick() {
25 | this.todoDelete.emit(this.todoItem.id);
26 | }
27 |
28 | public editClick() {
29 | this.todoEdit.emit(this.todoItem);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-card/todo-item-card.component.scss:
--------------------------------------------------------------------------------
1 | .bg-completed {
2 | background-color: #85cc95;
3 | }
4 |
5 | .card-content {
6 | padding: 0 20px;
7 | }
8 |
9 | .card-actions {
10 | display: flex;
11 | justify-content: space-around;
12 | }
13 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-card/todo-item-card.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { APP_BASE_HREF } from '@angular/common';
3 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
4 | import { FormsModule } from '@angular/forms';
5 | import { BrowserModule } from '@angular/platform-browser';
6 | import { AppComponent } from '@app/app.component';
7 | import { appRouterModule, rootPath } from '@app/app.routes';
8 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
9 | import { FooterComponent } from '@app/footer/footer.component';
10 | import { NavbarComponent } from '@app/navbar/navbar.component';
11 | import { InvalidDateValidatorDirective } from '@app/shared/invalid-date.directive';
12 | import { TODOItem } from '@app/shared/models/todo-item';
13 | import { SpinnerModule } from '@app/shared/spinner/spinner.module';
14 | import { TodoListCompletedComponent } from '@app/todo-list-completed/todo-list-completed.component';
15 | import { AddTodoComponent } from '@app/todo-list/add-todo/add-todo.component';
16 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
17 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
18 | import { TranslateModule } from '@ngx-translate/core';
19 | import { TodoItemCardComponent } from './todo-item-card.component';
20 |
21 | describe('TodoItemListRowComponent', () => {
22 | let component: TodoItemCardComponent;
23 | let fixture: ComponentFixture;
24 |
25 | beforeEach(async(() => {
26 | TestBed.configureTestingModule({
27 | declarations: [
28 | AppComponent,
29 | NavbarComponent,
30 | TodoListComponent,
31 | TodoItemCardComponent,
32 | FooterComponent,
33 | AddTodoComponent,
34 | TodoListCompletedComponent,
35 | InvalidDateValidatorDirective
36 | ],
37 | imports: [
38 | BrowserModule,
39 | NgbModule.forRoot(),
40 | TranslateModule.forRoot(),
41 | FormsModule,
42 | appRouterModule,
43 | SpinnerModule
44 | ],
45 | providers: [
46 | { provide: APP_BASE_HREF, useValue: rootPath },
47 | {
48 | provide: TodoListService,
49 | useValue: { todoList: [new TODOItem('Buy milk', 'Remember to buy milk')] }
50 | }
51 | ]
52 | }).compileComponents();
53 | }));
54 |
55 | beforeEach(() => {
56 | fixture = TestBed.createComponent(TodoItemCardComponent);
57 | component = fixture.componentInstance;
58 | fixture.detectChanges();
59 | });
60 |
61 | it('should create', () => {
62 | expect(component).toBeTruthy();
63 | });
64 | });
65 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-card/todo-item-card.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 | import { TODOItem } from '@app/shared/models/todo-item';
3 |
4 | @Component({
5 | selector: 'app-todo-item-card',
6 | templateUrl: './todo-item-card.component.html',
7 | styleUrls: ['./todo-item-card.component.scss']
8 | })
9 | export class TodoItemCardComponent implements OnInit {
10 | @Input() public todoItem: TODOItem;
11 | @Input() public readOnlyTODO: boolean;
12 | @Output() public todoDelete = new EventEmitter();
13 | @Output() public todoEdit = new EventEmitter();
14 |
15 | constructor() {}
16 |
17 | public ngOnInit() {}
18 |
19 | public completeClick() {
20 | this.todoItem.completed = !this.todoItem.completed;
21 | }
22 |
23 | public deleteClick() {
24 | this.todoDelete.emit(this.todoItem.id);
25 | }
26 |
27 | public editClick() {
28 | this.todoEdit.emit(this.todoItem);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-list-row/todo-item-list-row.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
{{todoItem.title}}
5 |
{{todoItem.description}}
6 |
7 | {{'add-todo.due-date' | translate}}:
8 | {{todoItem.dueDate}}
9 |
10 |
11 |
12 |
13 |
14 |
17 |
20 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-list-row/todo-item-list-row.component.mock.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 | import { TODOItem } from '@app/shared/models/todo-item';
3 | import { TodoItemListRowComponent } from './todo-item-list-row.component';
4 |
5 | @Component({
6 | selector: 'app-todo-item',
7 | template: ''
8 | })
9 | // tslint:disable-next-line:component-class-suffix
10 | export class TodoItemListRowComponentMock implements OnInit, TodoItemListRowComponent {
11 | @Input() public todoItem: TODOItem;
12 | @Input() public readOnlyTODO: boolean;
13 | @Output() public todoDelete = new EventEmitter();
14 | @Output() public todoEdit = new EventEmitter();
15 |
16 | constructor() {}
17 |
18 | public ngOnInit() {}
19 |
20 | public completeClick() {
21 | this.todoItem.completed = !this.todoItem.completed;
22 | }
23 |
24 | public deleteClick() {
25 | this.todoDelete.emit(this.todoItem.id);
26 | }
27 |
28 | public editClick() {
29 | this.todoEdit.emit(this.todoItem);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-list-row/todo-item-list-row.component.scss:
--------------------------------------------------------------------------------
1 | .bg-completed {
2 | background-color: #85cc95;
3 | }
4 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-list-row/todo-item-list-row.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { APP_BASE_HREF } from '@angular/common';
3 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
4 | import { FormsModule } from '@angular/forms';
5 | import { BrowserModule } from '@angular/platform-browser';
6 | import { AppComponent } from '@app/app.component';
7 | import { appRouterModule, rootPath } from '@app/app.routes';
8 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
9 | import { FooterComponent } from '@app/footer/footer.component';
10 | import { NavbarComponent } from '@app/navbar/navbar.component';
11 | import { InvalidDateValidatorDirective } from '@app/shared/invalid-date.directive';
12 | import { TODOItem } from '@app/shared/models/todo-item';
13 | import { SpinnerModule } from '@app/shared/spinner/spinner.module';
14 | import { TodoListCompletedComponent } from '@app/todo-list-completed/todo-list-completed.component';
15 | import { AddTodoComponent } from '@app/todo-list/add-todo/add-todo.component';
16 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
17 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
18 | import { TranslateModule } from '@ngx-translate/core';
19 | import { TodoItemListRowComponent } from './todo-item-list-row.component';
20 |
21 | describe('TodoItemListRowComponent', () => {
22 | let component: TodoItemListRowComponent;
23 | let fixture: ComponentFixture;
24 |
25 | beforeEach(async(() => {
26 | TestBed.configureTestingModule({
27 | declarations: [
28 | AppComponent,
29 | NavbarComponent,
30 | TodoListComponent,
31 | TodoItemListRowComponent,
32 | FooterComponent,
33 | AddTodoComponent,
34 | TodoListCompletedComponent,
35 | InvalidDateValidatorDirective
36 | ],
37 | imports: [
38 | BrowserModule,
39 | NgbModule.forRoot(),
40 | TranslateModule.forRoot(),
41 | FormsModule,
42 | appRouterModule,
43 | SpinnerModule
44 | ],
45 | providers: [
46 | { provide: APP_BASE_HREF, useValue: rootPath },
47 | {
48 | provide: TodoListService,
49 | useValue: { todoList: [new TODOItem('Buy milk', 'Remember to buy milk')] }
50 | }
51 | ]
52 | }).compileComponents();
53 | }));
54 |
55 | beforeEach(() => {
56 | fixture = TestBed.createComponent(TodoItemListRowComponent);
57 | component = fixture.componentInstance;
58 | fixture.detectChanges();
59 | });
60 |
61 | it('should create', () => {
62 | expect(component).toBeTruthy();
63 | });
64 | });
65 |
--------------------------------------------------------------------------------
/src/app/shared/todo-item-list-row/todo-item-list-row.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 | import { TODOItem } from '@app/shared/models/todo-item';
3 |
4 | @Component({
5 | selector: 'app-todo-item-list-row',
6 | templateUrl: './todo-item-list-row.component.html',
7 | styleUrls: ['./todo-item-list-row.component.scss']
8 | })
9 | export class TodoItemListRowComponent implements OnInit {
10 | @Input() public todoItem: TODOItem;
11 | @Input() public readOnlyTODO: boolean;
12 | @Output() public todoDelete = new EventEmitter();
13 | @Output() public todoEdit = new EventEmitter();
14 |
15 | constructor() {}
16 |
17 | public ngOnInit() {}
18 |
19 | public completeClick() {
20 | this.todoItem.completed = !this.todoItem.completed;
21 | }
22 |
23 | public deleteClick() {
24 | this.todoDelete.emit(this.todoItem.id);
25 | }
26 |
27 | public editClick() {
28 | this.todoEdit.emit(this.todoItem);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/app/todo-list-completed/todo-list-completed.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/src/app/todo-list-completed/todo-list-completed.component.css
--------------------------------------------------------------------------------
/src/app/todo-list-completed/todo-list-completed.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{'todo-list' | translate}}
4 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/app/todo-list-completed/todo-list-completed.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { APP_BASE_HREF } from '@angular/common';
3 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
4 | import { FormsModule } from '@angular/forms';
5 | import { BrowserModule } from '@angular/platform-browser';
6 | import { AppComponent } from '@app/app.component';
7 | import { appRouterModule, completedTodoPath } from '@app/app.routes';
8 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
9 | import { FooterComponent } from '@app/footer/footer.component';
10 | import { NavbarComponent } from '@app/navbar/navbar.component';
11 | import { InvalidDateValidatorDirective } from '@app/shared/invalid-date.directive';
12 | import { TODOItem } from '@app/shared/models/todo-item';
13 | import { SpinnerModule } from '@app/shared/spinner/spinner.module';
14 | import { TodoItemListRowComponent } from '@app/shared/todo-item-list-row/todo-item-list-row.component';
15 | import { TodoListCompletedComponent } from '@app/todo-list-completed/todo-list-completed.component';
16 | import { AddTodoComponent } from '@app/todo-list/add-todo/add-todo.component';
17 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
18 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
19 | import { TranslateModule } from '@ngx-translate/core';
20 |
21 | describe('TodoListCompletedComponent', () => {
22 | let component: TodoListCompletedComponent;
23 | let fixture: ComponentFixture;
24 |
25 | beforeEach(async(() => {
26 | const todo1 = new TODOItem('Buy milk', 'Remember to buy milk');
27 | todo1.completed = true;
28 | const todoList = [todo1, new TODOItem('Buy flowers', 'Remember to buy flowers')];
29 |
30 | TestBed.configureTestingModule({
31 | declarations: [
32 | AppComponent,
33 | NavbarComponent,
34 | TodoListComponent,
35 | TodoItemListRowComponent,
36 | FooterComponent,
37 | AddTodoComponent,
38 | TodoListCompletedComponent,
39 | InvalidDateValidatorDirective
40 | ],
41 | imports: [
42 | BrowserModule,
43 | NgbModule.forRoot(),
44 | TranslateModule.forRoot(),
45 | SpinnerModule,
46 | FormsModule,
47 | appRouterModule
48 | ],
49 | providers: [
50 | { provide: APP_BASE_HREF, useValue: completedTodoPath },
51 | {
52 | provide: TodoListService,
53 | useValue: {
54 | todoList: todoList
55 | }
56 | }
57 | ]
58 | }).compileComponents();
59 | }));
60 |
61 | beforeEach(() => {
62 | fixture = TestBed.createComponent(TodoListCompletedComponent);
63 | component = fixture.componentInstance;
64 | fixture.detectChanges();
65 | });
66 |
67 | it('should create', () => {
68 | expect(component).toBeTruthy();
69 | });
70 |
71 | it('should have one completed TODO item', () => {
72 | expect(component.todoList.length).toBe(1);
73 | });
74 | });
75 |
--------------------------------------------------------------------------------
/src/app/todo-list-completed/todo-list-completed.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
3 |
4 | @Component({
5 | selector: 'app-todo-list-completed',
6 | templateUrl: './todo-list-completed.component.html',
7 | styleUrls: ['./todo-list-completed.component.css']
8 | })
9 | export class TodoListCompletedComponent {
10 |
11 | constructor(private todoListService: TodoListService) { }
12 |
13 | get todoList() {
14 | return this.todoListService.todoList.filter(todo => todo.completed);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/todo-list-completed/todo-list-completed.module.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { NgModule } from '@angular/core';
3 | import { FormsModule } from '@angular/forms';
4 | import { SharedModule } from '@app/shared/shared.module';
5 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
6 | import { TodoListCompletedComponent } from '@app/todo-list-completed/todo-list-completed.component';
7 |
8 | @NgModule({
9 | imports: [FormsModule, CommonModule, SharedModule],
10 | declarations: [TodoListCompletedComponent]
11 | })
12 | export class TodoListCompletedModule {}
13 |
--------------------------------------------------------------------------------
/src/app/todo-list/add-todo/add-todo.component.css:
--------------------------------------------------------------------------------
1 |
2 | .relative {
3 | position: relative;
4 | }
--------------------------------------------------------------------------------
/src/app/todo-list/add-todo/add-todo.component.html:
--------------------------------------------------------------------------------
1 |
2 |
{{'add-todo.headline' | translate}}
3 |
4 |
5 |
6 | {{'invalid-form' | translate}}
7 |
8 |
29 |
30 |
--------------------------------------------------------------------------------
/src/app/todo-list/add-todo/add-todo.component.mock.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-add-todo',
5 | template: '',
6 | })
7 | export class AddTodoComponentMock implements OnInit {
8 |
9 | public isLoading = false;
10 |
11 | @Input()
12 | public currentTODO;
13 |
14 | constructor() { }
15 |
16 | ngOnInit() { }
17 |
18 | save() {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/app/todo-list/add-todo/add-todo.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { NO_ERRORS_SCHEMA } from '@angular/core';
2 | /* tslint:disable:no-unused-variable */
3 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
4 | import { FormsModule, NgForm } from '@angular/forms';
5 | import { AddTodoComponent } from '@app/add-todo/add-todo.component';
6 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
7 | import { SpyHelper } from '@app/helpers/spy-helper';
8 | import { TranslateModule } from '@ngx-translate/core';
9 | import { of } from 'rxjs';
10 |
11 |
12 | describe('AddTodoComponent', () => {
13 | let component: AddTodoComponent;
14 | let fixture: ComponentFixture;
15 |
16 | beforeEach(async(() => {
17 | TestBed.configureTestingModule({
18 | declarations: [
19 | AddTodoComponent,
20 | ],
21 | imports: [
22 | FormsModule,
23 | TranslateModule.forRoot(),
24 | ],
25 | providers: [
26 | SpyHelper.provideMagicalMock(TodoListService)
27 | ],
28 | schemas: [NO_ERRORS_SCHEMA]
29 | })
30 | .compileComponents();
31 | }));
32 |
33 | let todoListServiceMock: jasmine.SpyObj;
34 | beforeEach(() => {
35 | todoListServiceMock = TestBed.get(TodoListService);
36 |
37 | fixture = TestBed.createComponent(AddTodoComponent);
38 | component = fixture.componentInstance;
39 | fixture.detectChanges();
40 | });
41 |
42 | it('should create', () => {
43 | expect(component).toBeTruthy();
44 | });
45 |
46 | it('should update todo item when todo item is in todo list', () => {
47 |
48 | // Arrange
49 | const todoList = [
50 | { id: 'task1', title: 'Buy Milk', description: 'Remember to buy milk' },
51 | { id: 'task2', title: 'Go to the gym', description: 'Remember to work out' }
52 | ];
53 | (todoListServiceMock as any).todoList = todoList;
54 | todoListServiceMock.updateTodo.and.returnValue(of([]));
55 |
56 | // Act
57 | component.currentTODO = todoList[0];
58 | const form = new NgForm([], []);
59 | component.save(form);
60 |
61 | // Assert
62 | expect(todoListServiceMock.updateTodo).toHaveBeenCalledWith(component.currentTODO);
63 | });
64 |
65 | it('should add new todo item when todo item is not in todo list', () => {
66 | // Arrange
67 | const newTodo = { id: 'lala1', title: 'Buy Milk', description: 'Remember to buy milk' };
68 |
69 | const todoList = [
70 | { id: 'task1', title: 'Buy Milk', description: 'Remember to buy milk' },
71 | { id: 'task2', title: 'Go to the gym', description: 'Remember to work out' }
72 | ];
73 | (todoListServiceMock as any).todoList = todoList;
74 | todoListServiceMock.addTodo.and.returnValue(of([]));
75 |
76 | // Act
77 | component.currentTODO = newTodo;
78 | const form = new NgForm([], []);
79 |
80 | debugger;
81 | component.save(form);
82 |
83 | // Assert
84 | expect(todoListServiceMock.addTodo).toHaveBeenCalledWith(newTodo);
85 | });
86 | });
87 |
--------------------------------------------------------------------------------
/src/app/todo-list/add-todo/add-todo.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, OnInit } from '@angular/core';
2 | import { NgForm } from '@angular/forms';
3 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
4 | import { TODOItem } from '@app/shared/models/todo-item';
5 | import { first } from 'rxjs/operators';
6 |
7 | @Component({
8 | selector: 'app-add-todo',
9 | templateUrl: './add-todo.component.html',
10 | styleUrls: ['./add-todo.component.css']
11 | })
12 | export class AddTodoComponent implements OnInit {
13 | private editingIndex = -1;
14 |
15 | public isLoading = false;
16 |
17 | private _currentTODO: TODOItem = new TODOItem('', '');
18 | public get currentTODO(): TODOItem {
19 | return this._currentTODO;
20 | }
21 | @Input()
22 | public set currentTODO(value: TODOItem) {
23 | this._currentTODO = Object.assign({}, value);
24 | this.editingIndex = this.todoListService.todoList.findIndex(
25 | todo => todo.id === value.id
26 | );
27 | }
28 |
29 | constructor(private todoListService: TodoListService) { }
30 |
31 | ngOnInit() { }
32 |
33 | save(form: NgForm) {
34 | if (!form.valid) {
35 | console.log('Invalid form!');
36 | // TODO: display form errors
37 | return;
38 | }
39 | this.isLoading = true;
40 |
41 | if (this.isEditing()) {
42 | this.todoListService.updateTodo(this.currentTODO).pipe(first()).subscribe(() => {
43 | this.isLoading = false;
44 | const currentTODOClone = Object.assign({}, this.currentTODO);
45 | this.todoListService.todoList[this.editingIndex] = currentTODOClone;
46 | this.setAdding();
47 | form.resetForm();
48 | })
49 | } else {
50 | this.todoListService.addTodo(this.currentTODO).pipe(first()).subscribe(() => {
51 | this.isLoading = false;
52 | const currentTODOClone = Object.assign({}, this.currentTODO);
53 | this.todoListService.todoList.push(currentTODOClone);
54 | this.currentTODO = new TODOItem('', '');
55 | form.resetForm();
56 | })
57 | }
58 | }
59 |
60 | private setAdding() {
61 | this.editingIndex = -1;
62 | }
63 |
64 | private isEditing() {
65 | return this.editingIndex !== -1;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/app/todo-list/add-todo/add-todo.module.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { NgModule } from '@angular/core';
3 | import { FormsModule } from '@angular/forms';
4 | import { SharedModule } from '@app/shared/shared.module';
5 | import { AddTodoComponent } from './add-todo.component';
6 |
7 | @NgModule({
8 | imports: [FormsModule, CommonModule, SharedModule],
9 | declarations: [AddTodoComponent],
10 | exports: [AddTodoComponent]
11 | })
12 | export class AddTodoModule {}
13 |
--------------------------------------------------------------------------------
/src/app/todo-list/todo-list.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/src/app/todo-list/todo-list.component.css
--------------------------------------------------------------------------------
/src/app/todo-list/todo-list.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{'todo-list' | translate}}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
--------------------------------------------------------------------------------
/src/app/todo-list/todo-list.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { APP_BASE_HREF } from '@angular/common';
3 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
4 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
5 | import { TODOItem } from '@app/shared/models/todo-item';
6 | import { TodoItemListRowComponentMock } from '@app/shared/todo-item-list-row/todo-item-list-row.component.mock';
7 | import { AddTodoComponentMock } from '@app/todo-list/add-todo/add-todo.component.mock';
8 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
9 | import { TranslateModule } from '@ngx-translate/core';
10 |
11 | describe('TodoListComponent', () => {
12 | let component: TodoListComponent;
13 | let fixture: ComponentFixture;
14 |
15 | beforeEach(async(() => {
16 | const todo1 = new TODOItem('Buy milk', 'Remember to buy milk');
17 | todo1.completed = true;
18 | const todoList = [todo1, new TODOItem('Buy flowers', 'Remember to buy flowers')];
19 |
20 | TestBed.configureTestingModule({
21 | declarations: [TodoListComponent, TodoItemListRowComponentMock, AddTodoComponentMock],
22 | imports: [TranslateModule.forRoot()],
23 | providers: [
24 | { provide: APP_BASE_HREF, useValue: '/' },
25 | {
26 | provide: TodoListService,
27 | useValue: { todoList: todoList }
28 | }
29 | ]
30 | }).compileComponents();
31 | }));
32 |
33 | beforeEach(() => {
34 | fixture = TestBed.createComponent(TodoListComponent);
35 | component = fixture.componentInstance;
36 | fixture.detectChanges();
37 | });
38 |
39 | it('should create', () => {
40 | expect(component).toBeTruthy();
41 | });
42 |
43 | it('should have two completed TODO item', () => {
44 | expect(component.todoList.length).toBe(2);
45 | });
46 | });
47 |
--------------------------------------------------------------------------------
/src/app/todo-list/todo-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { TodoListService } from '@app/core/todo-list/todo-list.service';
3 | import { TODOItem } from '@app/shared/models/todo-item';
4 |
5 | @Component({
6 | selector: 'app-todo-list',
7 | templateUrl: './todo-list.component.html',
8 | styleUrls: ['./todo-list.component.css']
9 | })
10 | export class TodoListComponent {
11 | public currentTODO: TODOItem = new TODOItem('', '');
12 |
13 | constructor(private todoListService: TodoListService) {}
14 |
15 | get todoList() {
16 | return this.todoListService.todoList;
17 | }
18 |
19 | public deleteTodo(id: string) {
20 | const deleteIndex = this.todoListService.todoList.findIndex((todo) => todo.id === id);
21 | this.todoListService.todoList.splice(deleteIndex, 1);
22 | }
23 |
24 | public editTodo(todoItem: TODOItem) {
25 | this.currentTODO = todoItem;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/app/todo-list/todo-list.module.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { NgModule } from '@angular/core';
3 | import { FormsModule } from '@angular/forms';
4 | import { SharedModule } from '@app/shared/shared.module';
5 | import { TodoListComponent } from '@app/todo-list/todo-list.component';
6 | import { AddTodoModule } from './add-todo/add-todo.module';
7 |
8 | @NgModule({
9 | imports: [FormsModule, CommonModule, SharedModule, AddTodoModule],
10 | declarations: [TodoListComponent]
11 | })
12 | export class TodoListModule {}
13 |
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/assets/app-config.json:
--------------------------------------------------------------------------------
1 | {
2 | "environment": "local"
3 | }
--------------------------------------------------------------------------------
/src/browserslist:
--------------------------------------------------------------------------------
1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed
5 | > 0.5%
6 | last 2 versions
7 | Firefox ESR
8 | not dead
9 | # IE 9-11
--------------------------------------------------------------------------------
/src/environments/dynamic-environment.ts:
--------------------------------------------------------------------------------
1 | declare var window: any;
2 |
3 | export class DynamicEnvironment {
4 | public get environment() {
5 | return window.config.environment;
6 | }
7 |
8 | public get feServerUrl() {
9 | return window.config.feServerUrl;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | import { DynamicEnvironment } from './dynamic-environment';
2 |
3 | class Environment extends DynamicEnvironment {
4 |
5 | public production: boolean;
6 | constructor() {
7 | super();
8 | this.production = true;
9 | }
10 | }
11 |
12 | export const environment = new Environment();
13 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | import { DynamicEnvironment } from './dynamic-environment';
2 |
3 | // This file can be replaced during build by using the `fileReplacements` array.
4 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
5 | // The list of file replacements can be found in `angular.json`.
6 |
7 | class Environment extends DynamicEnvironment {
8 |
9 | public production: boolean;
10 |
11 | public get feServerUrl() {
12 | return 'http://localhost:8080';
13 | }
14 | constructor() {
15 | super();
16 | this.production = false;
17 | }
18 | }
19 |
20 | export const environment = new Environment();
21 |
22 | /*
23 | * For easier debugging in development mode, you can import the following file
24 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
25 | *
26 | * This import should be commented out in production mode because it will have a negative impact
27 | * on performance if an error is thrown.
28 | */
29 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
30 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lydemann/Angular-reusable-components-demo/02294cbbb8015295dbe1485ca6848d3727e94445/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Angular demo with best practices
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, '../coverage'),
20 | reports: ['html', 'lcovonly'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false
30 | });
31 | };
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from '@app/app.module';
5 | import { environment } from 'environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.log(err));
13 |
--------------------------------------------------------------------------------
/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 | /** IE10 and IE11 requires the following for the Reflect API. */
41 | // import 'core-js/es6/reflect';
42 |
43 |
44 | /** Evergreen browsers require these. **/
45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
46 | import 'core-js/es7/reflect';
47 |
48 |
49 | /**
50 | * Web Animations `@angular/platform-browser/animations`
51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
53 | **/
54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
55 |
56 | /**
57 | * By default, zone.js will patch all possible macroTask and DomEvents
58 | * user can disable parts of macroTask/DomEvents patch by setting following flags
59 | */
60 |
61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
64 |
65 | /*
66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
68 | */
69 | // (window as any).__Zone_enable_cross_context_check = true;
70 |
71 | /***************************************************************************************************
72 | * Zone JS is required by default for Angular itself.
73 | */
74 | import 'zone.js/dist/zone'; // Included with Angular CLI.
75 |
76 |
77 |
78 | /***************************************************************************************************
79 | * APPLICATION IMPORTS
80 | */
81 |
--------------------------------------------------------------------------------
/src/styles.scss:
--------------------------------------------------------------------------------
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 |
4 | /* Bootstrap */
5 | @import '~bootstrap/scss/bootstrap';
6 |
7 | @import "styles/positioning";
8 | @import "styles/spinner";
9 |
--------------------------------------------------------------------------------
/src/styles/positioning.scss:
--------------------------------------------------------------------------------
1 | /*
2 | Helpers for setting position using padding and margin
3 | */
4 |
5 | .p-0 {
6 | padding: 0px;
7 | }
8 |
9 | .p-3 {
10 | padding: 3px;
11 | }
12 |
13 | .p-5 {
14 | padding: 5px;
15 | }
16 |
17 | .p-10 {
18 | padding: 10px;
19 | }
20 |
21 | .p-15 {
22 | padding: 15px;
23 | }
24 |
25 | .p-20 {
26 | padding: 20px;
27 | }
28 |
29 | .p-25 {
30 | padding: 25px;
31 | }
32 |
33 | .p-30 {
34 | padding: 30px;
35 | }
36 |
37 | .p-35 {
38 | padding: 35px;
39 | }
40 |
41 | .p-40 {
42 | padding: 40px;
43 | }
44 |
45 | .p-45 {
46 | padding: 45px;
47 | }
48 |
49 | .p-50 {
50 | padding: 50px;
51 | }
52 |
53 | .pt-0 {
54 | padding-top: 0px;
55 | }
56 |
57 | .pt-3 {
58 | padding-top: 3px;
59 | }
60 |
61 | .pt-5 {
62 | padding-top: 5px;
63 | }
64 |
65 | .pt-10 {
66 | padding-top: 10px;
67 | }
68 |
69 | .pt-15 {
70 | padding-top: 15px;
71 | }
72 |
73 | .pt-20 {
74 | padding-top: 20px;
75 | }
76 |
77 | .pt-25 {
78 | padding-top: 25px;
79 | }
80 |
81 | .pt-30 {
82 | padding-top: 30px;
83 | }
84 |
85 | .pt-35 {
86 | padding-top: 35px;
87 | }
88 |
89 | .pt-40 {
90 | padding-top: 40px;
91 | }
92 |
93 | .pt-45 {
94 | padding-top: 45px;
95 | }
96 |
97 | .pt-50 {
98 | padding-top: 50px;
99 | }
100 |
101 | .pr-0 {
102 | padding-right: 0px;
103 | }
104 |
105 | .pr-3 {
106 | padding-right: 3px;
107 | }
108 |
109 | .pr-5 {
110 | padding-right: 5px;
111 | }
112 |
113 | .pr-10 {
114 | padding-right: 10px;
115 | }
116 |
117 | .pr-15 {
118 | padding-right: 15px;
119 | }
120 |
121 | .pr-20 {
122 | padding-right: 20px;
123 | }
124 |
125 | .pr-25 {
126 | padding-right: 25px;
127 | }
128 |
129 | .pr-30 {
130 | padding-right: 30px;
131 | }
132 |
133 | .pr-35 {
134 | padding-right: 35px;
135 | }
136 |
137 | .pr-40 {
138 | padding-right: 40px;
139 | }
140 |
141 | .pr-45 {
142 | padding-right: 45px;
143 | }
144 |
145 | .pr-50 {
146 | padding-right: 50px;
147 | }
148 |
149 | .pb-0 {
150 | padding-bottom: 0px;
151 | }
152 |
153 | .pb-3 {
154 | padding-bottom: 3px;
155 | }
156 |
157 | .pb-5 {
158 | padding-bottom: 5px;
159 | }
160 |
161 | .pb-10 {
162 | padding-bottom: 10px;
163 | }
164 |
165 | .pb-15 {
166 | padding-bottom: 15px;
167 | }
168 |
169 | .pb-20 {
170 | padding-bottom: 20px;
171 | }
172 |
173 | .pb-25 {
174 | padding-bottom: 25px;
175 | }
176 |
177 | .pb-30 {
178 | padding-bottom: 30px;
179 | }
180 |
181 | .pb-35 {
182 | padding-bottom: 35px;
183 | }
184 |
185 | .pb-40 {
186 | padding-bottom: 40px;
187 | }
188 |
189 | .pb-45 {
190 | padding-bottom: 45px;
191 | }
192 |
193 | .pb-50 {
194 | padding-bottom: 50px;
195 | }
196 |
197 | .pl-0 {
198 | padding-left: 0px;
199 | }
200 |
201 | .pl-3 {
202 | padding-left: 3px;
203 | }
204 |
205 | .pl-5 {
206 | padding-left: 5px;
207 | }
208 |
209 | .pl-10 {
210 | padding-left: 10px;
211 | }
212 |
213 | .pl-15 {
214 | padding-left: 15px;
215 | }
216 |
217 | .pl-20 {
218 | padding-left: 20px;
219 | }
220 |
221 | .pl-25 {
222 | padding-left: 25px;
223 | }
224 |
225 | .pl-30 {
226 | padding-left: 30px;
227 | }
228 |
229 | .pl-35 {
230 | padding-left: 35px;
231 | }
232 |
233 | .pl-40 {
234 | padding-left: 40px;
235 | }
236 |
237 | .pl-45 {
238 | padding-left: 45px;
239 | }
240 |
241 | .pl-50 {
242 | padding-left: 50px;
243 | }
244 |
245 | .m-0 {
246 | margin: 0px;
247 | }
248 |
249 | .m-3 {
250 | margin: 3px;
251 | }
252 |
253 | .m-5 {
254 | margin: 5px;
255 | }
256 |
257 | .m-10 {
258 | margin: 10px;
259 | }
260 |
261 | .m-15 {
262 | margin: 15px;
263 | }
264 |
265 | .m-20 {
266 | margin: 20px;
267 | }
268 |
269 | .m-25 {
270 | margin: 25px;
271 | }
272 |
273 | .m-30 {
274 | margin: 30px;
275 | }
276 |
277 | .m-35 {
278 | margin: 35px;
279 | }
280 |
281 | .m-40 {
282 | margin: 40px;
283 | }
284 |
285 | .m-45 {
286 | margin: 45px;
287 | }
288 |
289 | .m-50 {
290 | margin: 50px;
291 | }
292 |
293 | .mt-0 {
294 | margin-top: 0px;
295 | }
296 |
297 | .mt-3 {
298 | margin-top: 3px;
299 | }
300 |
301 | .mt-5 {
302 | margin-top: 5px;
303 | }
304 |
305 | .mt-10 {
306 | margin-top: 10px;
307 | }
308 |
309 | .mt-15 {
310 | margin-top: 15px;
311 | }
312 |
313 | .mt-20 {
314 | margin-top: 20px;
315 | }
316 |
317 | .mt-25 {
318 | margin-top: 25px;
319 | }
320 |
321 | .mt-30 {
322 | margin-top: 30px;
323 | }
324 |
325 | .mt-35 {
326 | margin-top: 35px;
327 | }
328 |
329 | .mt-40 {
330 | margin-top: 40px;
331 | }
332 |
333 | .mt-45 {
334 | margin-top: 45px;
335 | }
336 |
337 | .mt-50 {
338 | margin-top: 50px;
339 | }
340 |
341 | .mr-0 {
342 | margin-right: 0px;
343 | }
344 |
345 | .mr-3 {
346 | margin-right: 3px;
347 | }
348 |
349 | .mr-5 {
350 | margin-right: 5px;
351 | }
352 |
353 | .mr-10 {
354 | margin-right: 10px;
355 | }
356 |
357 | .mr-15 {
358 | margin-right: 15px;
359 | }
360 |
361 | .mr-20 {
362 | margin-right: 20px;
363 | }
364 |
365 | .mr-25 {
366 | margin-right: 25px;
367 | }
368 |
369 | .mr-30 {
370 | margin-right: 30px;
371 | }
372 |
373 | .mr-35 {
374 | margin-right: 35px;
375 | }
376 |
377 | .mr-40 {
378 | margin-right: 40px;
379 | }
380 |
381 | .mr-45 {
382 | margin-right: 45px;
383 | }
384 |
385 | .mr-50 {
386 | margin-right: 50px;
387 | }
388 |
389 | .mb-0 {
390 | margin-bottom: 0px;
391 | }
392 |
393 | .mb-3 {
394 | margin-bottom: 3px;
395 | }
396 |
397 | .mb-5 {
398 | margin-bottom: 5px;
399 | }
400 |
401 | .mb-10 {
402 | margin-bottom: 10px;
403 | }
404 |
405 | .mb-15 {
406 | margin-bottom: 15px;
407 | }
408 |
409 | .mb-20 {
410 | margin-bottom: 20px;
411 | }
412 |
413 | .mb-25 {
414 | margin-bottom: 25px;
415 | }
416 |
417 | .mb-30 {
418 | margin-bottom: 30px;
419 | }
420 |
421 | .mb-35 {
422 | margin-bottom: 35px;
423 | }
424 |
425 | .mb-40 {
426 | margin-bottom: 40px;
427 | }
428 |
429 | .mb-45 {
430 | margin-bottom: 45px;
431 | }
432 |
433 | .mb-50 {
434 | margin-bottom: 50px;
435 | }
436 |
437 | .ml-0 {
438 | margin-left: 0px;
439 | }
440 |
441 | .ml-3 {
442 | margin-left: 3px;
443 | }
444 |
445 | .ml-5 {
446 | margin-left: 5px;
447 | }
448 |
449 | .ml-10 {
450 | margin-left: 10px;
451 | }
452 |
453 | .ml-15 {
454 | margin-left: 15px;
455 | }
456 |
457 | .ml-20 {
458 | margin-left: 20px;
459 | }
460 |
461 | .ml-25 {
462 | margin-left: 25px;
463 | }
464 |
465 | .ml-30 {
466 | margin-left: 30px;
467 | }
468 |
469 | .ml-35 {
470 | margin-left: 35px;
471 | }
472 |
473 | .ml-40 {
474 | margin-left: 40px;
475 | }
476 |
477 | .ml-45 {
478 | margin-left: 45px;
479 | }
480 |
481 | .ml-50 {
482 | margin-left: 50px;
483 | }
484 |
485 | .mh-a {
486 | margin: 0 auto;
487 | }
488 |
489 | .pull-right {
490 | margin-left: auto;
491 | }
492 |
--------------------------------------------------------------------------------
/src/styles/spinner.scss:
--------------------------------------------------------------------------------
1 | #loader {
2 | bottom: 0;
3 | height: 175px;
4 | left: 0;
5 | margin: auto;
6 | position: absolute;
7 | right: 0;
8 | top: 0;
9 | width: 175px;
10 | }
11 |
12 | #loader {
13 | bottom: 0;
14 | height: 175px;
15 | left: 0;
16 | margin: auto;
17 | position: absolute;
18 | right: 0;
19 | top: 0;
20 | width: 175px;
21 | }
22 |
23 | #loader .dot {
24 | bottom: 0;
25 | height: 100%;
26 | left: 0;
27 | margin: auto;
28 | position: absolute;
29 | right: 0;
30 | top: 0;
31 | width: 87.5px;
32 | }
33 |
34 | #loader .dot::before {
35 | border-radius: 100%;
36 | content: "";
37 | height: 87.5px;
38 | left: 0;
39 | position: absolute;
40 | right: 0;
41 | top: 0;
42 | transform: scale(0);
43 | width: 87.5px;
44 | }
45 |
46 | #loader .dot:nth-child(7n+1) {
47 | transform: rotate(45deg);
48 | }
49 |
50 | #loader .dot:nth-child(7n+1)::before {
51 | animation: 0.8s linear 0.1s normal none infinite running load;
52 | background: #00ff80 none repeat scroll 0 0;
53 | }
54 |
55 | #loader .dot:nth-child(7n+2) {
56 | transform: rotate(90deg);
57 | }
58 |
59 | #loader .dot:nth-child(7n+2)::before {
60 | animation: 0.8s linear 0.2s normal none infinite running load;
61 | background: #00ffea none repeat scroll 0 0;
62 | }
63 |
64 | #loader .dot:nth-child(7n+3) {
65 | transform: rotate(135deg);
66 | }
67 |
68 | #loader .dot:nth-child(7n+3)::before {
69 | animation: 0.8s linear 0.3s normal none infinite running load;
70 | background: #00aaff none repeat scroll 0 0;
71 | }
72 |
73 | #loader .dot:nth-child(7n+4) {
74 | transform: rotate(180deg);
75 | }
76 |
77 | #loader .dot:nth-child(7n+4)::before {
78 | animation: 0.8s linear 0.4s normal none infinite running load;
79 | background: #0040ff none repeat scroll 0 0;
80 | }
81 |
82 | #loader .dot:nth-child(7n+5) {
83 | transform: rotate(225deg);
84 | }
85 |
86 | #loader .dot:nth-child(7n+5)::before {
87 | animation: 0.8s linear 0.5s normal none infinite running load;
88 | background: #2a00ff none repeat scroll 0 0;
89 | }
90 |
91 | #loader .dot:nth-child(7n+6) {
92 | transform: rotate(270deg);
93 | }
94 |
95 | #loader .dot:nth-child(7n+6)::before {
96 | animation: 0.8s linear 0.6s normal none infinite running load;
97 | background: #9500ff none repeat scroll 0 0;
98 | }
99 |
100 | #loader .dot:nth-child(7n+7) {
101 | transform: rotate(315deg);
102 | }
103 |
104 | #loader .dot:nth-child(7n+7)::before {
105 | animation: 0.8s linear 0.7s normal none infinite running load;
106 | background: magenta none repeat scroll 0 0;
107 | }
108 |
109 | #loader .dot:nth-child(7n+8) {
110 | transform: rotate(360deg);
111 | }
112 |
113 | #loader .dot:nth-child(7n+8)::before {
114 | animation: 0.8s linear 0.8s normal none infinite running load;
115 | background: #ff0095 none repeat scroll 0 0;
116 | }
117 |
118 | #loader .loading {
119 | background-position: 50% 50%;
120 | background-repeat: no-repeat;
121 | bottom: -40px;
122 | height: 20px;
123 | left: 0;
124 | position: absolute;
125 | right: 0;
126 | width: 180px;
127 | }
128 |
129 | @keyframes load {
130 | 100% {
131 | opacity: 0;
132 | transform: scale(1);
133 | }
134 | }
135 |
136 | @keyframes load {
137 | 100% {
138 | opacity: 0;
139 | transform: scale(1);
140 | }
141 | }
142 |
143 | .spinner-message {
144 | text-align: center;
145 | }
146 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: any;
11 |
12 | // First, initialize the Angular testing environment.
13 | getTestBed().initTestEnvironment(
14 | BrowserDynamicTestingModule,
15 | platformBrowserDynamicTesting()
16 | );
17 | // Then we find all the tests.
18 | const context = require.context('./', true, /\.spec\.ts$/);
19 | // And load the modules.
20 | context.keys().map(context);
21 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "exclude": [
11 | "src/test.ts",
12 | "**/*.spec.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "test.ts",
12 | "polyfills.ts"
13 | ],
14 | "include": [
15 | "**/*.spec.ts",
16 | "**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/src/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint.json",
3 | "rules": {
4 | "directive-selector": [
5 | true,
6 | "attribute",
7 | "app",
8 | "camelCase"
9 | ],
10 | "component-selector": [
11 | true,
12 | "element",
13 | "app",
14 | "kebab-case"
15 | ]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "outDir": "./dist/out-tsc",
5 | "baseUrl": "src",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "moduleResolution": "node",
9 | "emitDecoratorMetadata": true,
10 | "experimentalDecorators": true,
11 | "target": "es5",
12 | "typeRoots": [
13 | "node_modules/@types"
14 | ],
15 | "lib": [
16 | "es2016",
17 | "dom"
18 | ],
19 | "paths": {
20 | "@app/*": [
21 | "app/*"
22 | ]
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "deprecation": {
15 | "severity": "warn"
16 | },
17 | "eofline": true,
18 | "forin": true,
19 | "import-blacklist": [
20 | true,
21 | "rxjs/Rx"
22 | ],
23 | "import-spacing": true,
24 | "indent": [
25 | true,
26 | "spaces"
27 | ],
28 | "interface-over-type-literal": true,
29 | "label-position": true,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": true,
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-arg": true,
47 | "no-bitwise": true,
48 | "no-console": [
49 | true,
50 | "debug",
51 | "info",
52 | "time",
53 | "timeEnd",
54 | "trace"
55 | ],
56 | "no-construct": true,
57 | "no-debugger": true,
58 | "no-duplicate-super": true,
59 | "no-empty": false,
60 | "no-empty-interface": true,
61 | "no-eval": true,
62 | "no-inferrable-types": [
63 | true,
64 | "ignore-params"
65 | ],
66 | "no-misused-new": true,
67 | "no-non-null-assertion": true,
68 | "no-redundant-jsdoc": true,
69 | "no-shadowed-variable": true,
70 | "no-string-literal": false,
71 | "no-string-throw": true,
72 | "no-switch-case-fall-through": true,
73 | "no-trailing-whitespace": true,
74 | "no-unnecessary-initializer": true,
75 | "no-unused-expression": true,
76 | "no-use-before-declare": true,
77 | "no-var-keyword": true,
78 | "object-literal-sort-keys": false,
79 | "one-line": [
80 | true,
81 | "check-open-brace",
82 | "check-catch",
83 | "check-else",
84 | "check-whitespace"
85 | ],
86 | "prefer-const": true,
87 | "quotemark": [
88 | true,
89 | "single"
90 | ],
91 | "radix": true,
92 | "semicolon": [
93 | true,
94 | "always"
95 | ],
96 | "triple-equals": [
97 | true,
98 | "allow-null-check"
99 | ],
100 | "typedef-whitespace": [
101 | true,
102 | {
103 | "call-signature": "nospace",
104 | "index-signature": "nospace",
105 | "parameter": "nospace",
106 | "property-declaration": "nospace",
107 | "variable-declaration": "nospace"
108 | }
109 | ],
110 | "unified-signatures": true,
111 | "variable-name": false,
112 | "whitespace": [
113 | true,
114 | "check-branch",
115 | "check-decl",
116 | "check-operator",
117 | "check-separator",
118 | "check-type"
119 | ],
120 | "no-output-on-prefix": true,
121 | "use-input-property-decorator": true,
122 | "use-output-property-decorator": true,
123 | "use-host-property-decorator": true,
124 | "no-input-rename": true,
125 | "no-output-rename": true,
126 | "use-life-cycle-interface": true,
127 | "use-pipe-transform-interface": true,
128 | "component-class-suffix": true,
129 | "directive-class-suffix": true
130 | }
131 | }
132 |
--------------------------------------------------------------------------------