├── .editorconfig
├── .gitignore
├── README.md
├── TestRunnerGUI.png
├── angular.json
├── cypress.json
├── cypress
├── fixtures
│ └── example.json
├── integration
│ └── test.spec.js
├── plugins
│ └── index.js
└── support
│ ├── commands.js
│ └── index.js
├── logo.png
├── package.json
├── src
├── app
│ ├── app-routing.module.ts
│ ├── app.component.html
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── article
│ │ ├── article-comment.component.html
│ │ ├── article-comment.component.ts
│ │ ├── article-resolver.service.ts
│ │ ├── article-routing.module.ts
│ │ ├── article.component.html
│ │ ├── article.component.ts
│ │ ├── article.module.ts
│ │ └── markdown.pipe.ts
│ ├── auth
│ │ ├── auth-routing.module.ts
│ │ ├── auth.component.html
│ │ ├── auth.component.ts
│ │ ├── auth.module.ts
│ │ └── no-auth-guard.service.ts
│ ├── core
│ │ ├── core.module.ts
│ │ ├── index.ts
│ │ ├── interceptors
│ │ │ ├── http.token.interceptor.ts
│ │ │ └── index.ts
│ │ ├── models
│ │ │ ├── article-list-config.model.ts
│ │ │ ├── article.model.ts
│ │ │ ├── comment.model.ts
│ │ │ ├── errors.model.ts
│ │ │ ├── index.ts
│ │ │ ├── profile.model.ts
│ │ │ └── user.model.ts
│ │ └── services
│ │ │ ├── api.service.ts
│ │ │ ├── articles.service.ts
│ │ │ ├── auth-guard.service.ts
│ │ │ ├── comments.service.ts
│ │ │ ├── index.ts
│ │ │ ├── jwt.service.ts
│ │ │ ├── profiles.service.ts
│ │ │ ├── tags.service.ts
│ │ │ └── user.service.ts
│ ├── editor
│ │ ├── editable-article-resolver.service.ts
│ │ ├── editor-routing.module.ts
│ │ ├── editor.component.html
│ │ ├── editor.component.ts
│ │ └── editor.module.ts
│ ├── home
│ │ ├── home-auth-resolver.service.ts
│ │ ├── home-routing.module.ts
│ │ ├── home.component.css
│ │ ├── home.component.html
│ │ ├── home.component.ts
│ │ └── home.module.ts
│ ├── index.ts
│ ├── profile
│ │ ├── profile-articles.component.html
│ │ ├── profile-articles.component.ts
│ │ ├── profile-favorites.component.html
│ │ ├── profile-favorites.component.ts
│ │ ├── profile-resolver.service.ts
│ │ ├── profile-routing.module.ts
│ │ ├── profile.component.html
│ │ ├── profile.component.ts
│ │ └── profile.module.ts
│ ├── settings
│ │ ├── settings-routing.module.ts
│ │ ├── settings.component.html
│ │ ├── settings.component.ts
│ │ └── settings.module.ts
│ └── shared
│ │ ├── article-helpers
│ │ ├── article-list.component.css
│ │ ├── article-list.component.html
│ │ ├── article-list.component.ts
│ │ ├── article-meta.component.html
│ │ ├── article-meta.component.ts
│ │ ├── article-preview.component.html
│ │ ├── article-preview.component.ts
│ │ └── index.ts
│ │ ├── buttons
│ │ ├── favorite-button.component.html
│ │ ├── favorite-button.component.ts
│ │ ├── follow-button.component.html
│ │ ├── follow-button.component.ts
│ │ └── index.ts
│ │ ├── index.ts
│ │ ├── layout
│ │ ├── footer.component.html
│ │ ├── footer.component.ts
│ │ ├── header.component.html
│ │ ├── header.component.ts
│ │ └── index.ts
│ │ ├── list-errors.component.html
│ │ ├── list-errors.component.ts
│ │ ├── shared.module.ts
│ │ └── show-authed.directive.ts
├── assets
│ ├── .gitkeep
│ └── .npmignore
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── main.ts
├── polyfills.ts
├── styles.css
├── test.ts
├── tsconfig.app.json
├── tsconfig.spec.json
└── typings.d.ts
├── tsconfig.json
├── tslint.json
└── 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 |
--------------------------------------------------------------------------------
/.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 | .vscode/
13 | /.idea
14 | .project
15 | .classpath
16 | .c9/
17 | *.launch
18 | .settings/
19 | *.sublime-workspace
20 |
21 | # IDE - VSCode
22 | .vscode/*
23 | !.vscode/settings.json
24 | !.vscode/tasks.json
25 | !.vscode/launch.json
26 | !.vscode/extensions.json
27 |
28 | # misc
29 | /.sass-cache
30 | /connect.lock
31 | /coverage
32 | /libpeerconnection.log
33 | npm-debug.log
34 | testem.log
35 | /typings
36 | yarn-error.log
37 |
38 | # e2e
39 | /e2e/*.js
40 | /e2e/*.map
41 |
42 | # System Files
43 | .DS_Store
44 | Thumbs.db
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Testing Angular Applications with Cypress Workshop
2 |
3 | ### Welcome to ngConf Enterprise!
4 |
5 | ## WORKSHOP SETUP
6 |
7 | Please complete the following steps to prepare for the workshop. It may take a few minutes to install all the dependencies on your system.
8 |
9 | ### System Requirements
10 |
11 | Please check the [Cypress system requirements](https://docs.cypress.io/guides/getting-started/installing-cypress.html#System-requirements) here to ensure you have all the dependencies needed.
12 |
13 | Additionally, you'll need the following:
14 |
15 | - An IDE or Code Editor (VS Code recommended)
16 | - NPM or Yarn (Yarn recommended)
17 | - Angular CLI (recommended, not required)
18 |
19 | ### Installation
20 |
21 | 1. Clone the repository locally. Make sure you are on the `starter` branch.
22 | 2. Run `yarn install` or `npm install` in the project directory.
23 | 3. If you have the Angular CLI installed, run `ng serve`. Otherwise, run `yarn run start` to start the dev server. Confirm the application runs locally.
24 | 4. In a new terminal, run `yarn run cypress open` or `npx cypress open`
25 | 5. Confirm the Cypress Test Runner opens on your machine. You should see a Graphical User Interface (GUI) like the screenshot below:
26 |
27 | 
28 |
29 | 6. If the application runs and the Test Runner appears, you are ready for the workshop! You can stop both servers.
30 |
31 | ## APPLICATION
32 |
33 | The Application Under Test is a fork of [gothinkster/angular-realworld-example-app](https://github.com/gothinkster/angular-realworld-example-app).
34 |
35 | ### About
36 |
37 | Below is the application description from its README. Check out the repository directly for more details about the application.
38 |
39 | > Angular codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the [RealWorld](https://github.com/gothinkster/realworld-example-apps) spec and API.
40 |
41 | ### Demo
42 |
43 | [Demo](https://angular.realworld.io)
44 |
45 | > This codebase was created to demonstrate a fully fledged application built with Angular that interacts with an actual backend server including CRUD operations, authentication, routing, pagination, and more. We've gone to great lengths to adhere to the [Angular Styleguide](https://angular.io/styleguide) & best practices.
46 |
47 | ### API
48 |
49 | > For convenience, we have a live API server running at https://conduit.productionready.io/api for the application to make requests against. You can view [the API spec here](https://github.com/GoThinkster/productionready/blob/master/api) which contains all routes & responses for the server.
50 |
51 | ### Functionality overview
52 |
53 | The example application is a social blogging site (i.e. a Medium.com clone) called "Conduit". It uses a custom API for all requests, including authentication. You can view a live demo over at https://angular.realworld.io
54 |
55 | #### General functionality:
56 |
57 | - Authenticate users via JWT (login/signup pages + logout button on settings page)
58 | - CRU\* users (sign up & settings page - no deleting required)
59 | - CRUD Articles
60 | - CR\*D Comments on articles (no updating required)
61 | - GET and display paginated lists of articles
62 | - Favorite articles
63 | - Follow other users
64 |
65 | #### The general page breakdown looks like this:
66 |
67 | - Home page (URL: /#/ )
68 | - List of tags
69 | - List of articles pulled from either Feed, Global, or by Tag
70 | - Pagination for list of articles
71 | - Sign in/Sign up pages (URL: /#/login, /#/register )
72 | - Uses JWT (store the token in localStorage)
73 | - Authentication can be easily switched to session/cookie based
74 | - Settings page (URL: /#/settings )
75 | - Editor page to create/edit articles (URL: /#/editor, /#/editor/article-slug-here )
76 | - Article page (URL: /#/article/article-slug-here )
77 | - Delete article button (only shown to article's author)
78 | - Render markdown from server client side
79 | - Comments section at bottom of page
80 | - Delete comment button (only shown to comment's author)
81 | - Profile page (URL: /#/profile/:username, /#/profile/:username/favorites )
82 | - Show basic user info
83 | - List of articles populated from author's created articles or author's favorited articles
84 |
85 | ## WORKSHOP OUTLINE
86 |
87 | [Workshop Slides](https://cypress.slides.com/cecelia/testing-angular-applications-with-cypress)
88 |
89 | This workshop contains seven interactive activities.
90 |
91 | You can see potential solutions for these activities by navigating to the various branches:
92 |
93 | - [Activity One Solution](https://github.com/CypressCecelia/cypress-testing-angular-workshop/tree/activity-one)
94 | - [Activity Two Solution](https://github.com/CypressCecelia/cypress-testing-angular-workshop/tree/activity-two)
95 | - [Activity Three Solution](https://github.com/CypressCecelia/cypress-testing-angular-workshop/tree/activity-three)
96 | - [Activity Four Solution](https://github.com/CypressCecelia/cypress-testing-angular-workshop/tree/activity-four)
97 | - [Activity Five Solution](https://github.com/CypressCecelia/cypress-testing-angular-workshop/tree/activity-five)
98 | - [Activity Six Solution](https://github.com/CypressCecelia/cypress-testing-angular-workshop/tree/activity-six)
99 | - [Activity Seven Solution](https://github.com/CypressCecelia/cypress-testing-angular-workshop/tree/activity-seven)
100 |
--------------------------------------------------------------------------------
/TestRunnerGUI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CypressCecelia/cypress-testing-angular-workshop/fdfee921a37bb087a99edf0f179c03db8fddedb0/TestRunnerGUI.png
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "ang2-conduit": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "architect": {
11 | "build": {
12 | "builder": "@angular-devkit/build-angular:browser",
13 | "options": {
14 | "outputPath": "dist",
15 | "index": "src/index.html",
16 | "main": "src/main.ts",
17 | "tsConfig": "src/tsconfig.app.json",
18 | "polyfills": "src/polyfills.ts",
19 | "assets": [
20 | "src/assets",
21 | "src/favicon.ico"
22 | ],
23 | "styles": [
24 | "src/styles.css"
25 | ],
26 | "scripts": []
27 | },
28 | "configurations": {
29 | "production": {
30 | "optimization": true,
31 | "outputHashing": "all",
32 | "sourceMap": false,
33 | "extractCss": true,
34 | "namedChunks": false,
35 | "aot": true,
36 | "extractLicenses": true,
37 | "vendorChunk": false,
38 | "buildOptimizer": true,
39 | "fileReplacements": [
40 | {
41 | "replace": "src/environments/environment.ts",
42 | "with": "src/environments/environment.prod.ts"
43 | }
44 | ]
45 | }
46 | }
47 | },
48 | "serve": {
49 | "builder": "@angular-devkit/build-angular:dev-server",
50 | "options": {
51 | "browserTarget": "ang2-conduit:build"
52 | },
53 | "configurations": {
54 | "production": {
55 | "browserTarget": "ang2-conduit:build:production"
56 | }
57 | }
58 | },
59 | "extract-i18n": {
60 | "builder": "@angular-devkit/build-angular:extract-i18n",
61 | "options": {
62 | "browserTarget": "ang2-conduit:build"
63 | }
64 | },
65 | "test": {
66 | "builder": "@angular-devkit/build-angular:karma",
67 | "options": {
68 | "main": "src/test.ts",
69 | "karmaConfig": "./karma.conf.js",
70 | "polyfills": "src/polyfills.ts",
71 | "tsConfig": "src/tsconfig.spec.json",
72 | "scripts": [],
73 | "styles": [
74 | "src/styles.css"
75 | ],
76 | "assets": [
77 | "src/assets",
78 | "src/favicon.ico"
79 | ]
80 | }
81 | },
82 | "lint": {
83 | "builder": "@angular-devkit/build-angular:tslint",
84 | "options": {
85 | "tsConfig": [
86 | "src/tsconfig.app.json",
87 | "src/tsconfig.spec.json"
88 | ],
89 | "exclude": [
90 | "**/node_modules/**"
91 | ]
92 | }
93 | }
94 | }
95 | },
96 | "ang2-conduit-e2e": {
97 | "root": "e2e",
98 | "sourceRoot": "e2e",
99 | "projectType": "application",
100 | "architect": {
101 | "e2e": {
102 | "builder": "@angular-devkit/build-angular:protractor",
103 | "options": {
104 | "protractorConfig": "./protractor.conf.js",
105 | "devServerTarget": "ang2-conduit:serve"
106 | }
107 | },
108 | "lint": {
109 | "builder": "@angular-devkit/build-angular:tslint",
110 | "options": {
111 | "tsConfig": [
112 | "e2e/tsconfig.e2e.json"
113 | ],
114 | "exclude": [
115 | "**/node_modules/**"
116 | ]
117 | }
118 | }
119 | }
120 | }
121 | },
122 | "defaultProject": "ang2-conduit",
123 | "schematics": {
124 | "@schematics/angular:component": {
125 | "prefix": "app",
126 | "styleext": "css"
127 | },
128 | "@schematics/angular:directive": {
129 | "prefix": "app"
130 | }
131 | }
132 | }
--------------------------------------------------------------------------------
/cypress.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/cypress/fixtures/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Using fixtures to represent data",
3 | "email": "hello@cypress.io",
4 | "body": "Fixtures are a great way to mock data for responses to routes"
5 | }
--------------------------------------------------------------------------------
/cypress/integration/test.spec.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CypressCecelia/cypress-testing-angular-workshop/fdfee921a37bb087a99edf0f179c03db8fddedb0/cypress/integration/test.spec.js
--------------------------------------------------------------------------------
/cypress/plugins/index.js:
--------------------------------------------------------------------------------
1 | ///
2 | // ***********************************************************
3 | // This example plugins/index.js can be used to load plugins
4 | //
5 | // You can change the location of this file or turn off loading
6 | // the plugins file with the 'pluginsFile' configuration option.
7 | //
8 | // You can read more here:
9 | // https://on.cypress.io/plugins-guide
10 | // ***********************************************************
11 |
12 | // This function is called when a project is opened or re-opened (e.g. due to
13 | // the project's config changing)
14 |
15 | /**
16 | * @type {Cypress.PluginConfig}
17 | */
18 | module.exports = (on, config) => {
19 | // `on` is used to hook into various events Cypress emits
20 | // `config` is the resolved Cypress config
21 | }
22 |
--------------------------------------------------------------------------------
/cypress/support/commands.js:
--------------------------------------------------------------------------------
1 | // ***********************************************
2 | // This example commands.js shows you how to
3 | // create various custom commands and overwrite
4 | // existing commands.
5 | //
6 | // For more comprehensive examples of custom
7 | // commands please read more here:
8 | // https://on.cypress.io/custom-commands
9 | // ***********************************************
10 | //
11 | //
12 | // -- This is a parent command --
13 | // Cypress.Commands.add("login", (email, password) => { ... })
14 | //
15 | //
16 | // -- This is a child command --
17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18 | //
19 | //
20 | // -- This is a dual command --
21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22 | //
23 | //
24 | // -- This will overwrite an existing command --
25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
26 |
--------------------------------------------------------------------------------
/cypress/support/index.js:
--------------------------------------------------------------------------------
1 | // ***********************************************************
2 | // This example support/index.js is processed and
3 | // loaded automatically before your test files.
4 | //
5 | // This is a great place to put global configuration and
6 | // behavior that modifies Cypress.
7 | //
8 | // You can change the location of this file or turn off
9 | // automatically serving support files with the
10 | // 'supportFile' configuration option.
11 | //
12 | // You can read more here:
13 | // https://on.cypress.io/configuration
14 | // ***********************************************************
15 |
16 | // Import commands.js using ES2015 syntax:
17 | import './commands'
18 |
19 | // Alternatively you can use CommonJS syntax:
20 | // require('./commands')
21 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CypressCecelia/cypress-testing-angular-workshop/fdfee921a37bb087a99edf0f179c03db8fddedb0/logo.png
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ang2-conduit",
3 | "version": "0.0.0",
4 | "license": "MIT",
5 | "scripts": {
6 | "ng": "ng",
7 | "start": "ng serve"
8 | },
9 | "private": true,
10 | "dependencies": {
11 | "@angular/animations": "7.2.4",
12 | "@angular/common": "7.2.4",
13 | "@angular/compiler": "7.2.4",
14 | "@angular/core": "7.2.4",
15 | "@angular/forms": "7.2.4",
16 | "@angular/platform-browser": "7.2.4",
17 | "@angular/platform-browser-dynamic": "7.2.4",
18 | "@angular/router": "7.2.4",
19 | "core-js": "^2.4.1",
20 | "cypress": "^5.6.0",
21 | "marked": "^0.3.9",
22 | "rxjs": "^6.4.0",
23 | "tslib": "^1.9.0",
24 | "zone.js": "^0.8.29"
25 | },
26 | "devDependencies": {
27 | "@angular-devkit/build-angular": "~0.13.0",
28 | "@angular/cli": "^7.3.1",
29 | "@angular/compiler-cli": "7.2.4",
30 | "@angular/language-service": "7.2.4",
31 | "@types/jasmine": "~2.5.53",
32 | "@types/jasminewd2": "~2.0.2",
33 | "@types/node": "^9.4.0",
34 | "codelyzer": "^4.5.0",
35 | "ts-node": "~4.1.0",
36 | "tslint": "~5.9.1",
37 | "typescript": "3.2.4"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule, PreloadAllModules } from '@angular/router';
3 |
4 | const routes: Routes = [
5 | {
6 | path: 'settings',
7 | loadChildren: './settings/settings.module#SettingsModule'
8 | },
9 | {
10 | path: 'profile',
11 | loadChildren: './profile/profile.module#ProfileModule'
12 | },
13 | {
14 | path: 'editor',
15 | loadChildren: './editor/editor.module#EditorModule'
16 | },
17 | {
18 | path: 'article',
19 | loadChildren: './article/article.module#ArticleModule'
20 | }
21 | ];
22 |
23 | @NgModule({
24 | imports: [RouterModule.forRoot(routes, {
25 | // preload all modules; optionally we could
26 | // implement a custom preloading strategy for just some
27 | // of the modules (PRs welcome 😉)
28 | preloadingStrategy: PreloadAllModules
29 | })],
30 | exports: [RouterModule]
31 | })
32 | export class AppRoutingModule {}
33 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | import { UserService } from './core';
4 |
5 | @Component({
6 | selector: 'app-root',
7 | templateUrl: './app.component.html'
8 | })
9 | export class AppComponent implements OnInit {
10 | constructor (
11 | private userService: UserService
12 | ) {}
13 |
14 | ngOnInit() {
15 | this.userService.populate();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { BrowserModule } from '@angular/platform-browser';
3 |
4 | import { AppComponent } from './app.component';
5 | import { AuthModule } from './auth/auth.module';
6 | import { HomeModule } from './home/home.module';
7 | import {
8 | FooterComponent,
9 | HeaderComponent,
10 | SharedModule
11 | } from './shared';
12 | import { AppRoutingModule } from './app-routing.module';
13 | import { CoreModule } from './core/core.module';
14 |
15 | @NgModule({
16 | declarations: [AppComponent, FooterComponent, HeaderComponent],
17 | imports: [
18 | BrowserModule,
19 | CoreModule,
20 | SharedModule,
21 | HomeModule,
22 | AuthModule,
23 | AppRoutingModule
24 | ],
25 | providers: [],
26 | bootstrap: [AppComponent]
27 | })
28 | export class AppModule {}
29 |
--------------------------------------------------------------------------------
/src/app/article/article-comment.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{ comment.body }}
5 |
6 |
7 |
22 |
23 |
--------------------------------------------------------------------------------
/src/app/article/article-comment.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, Output, OnInit, OnDestroy } from '@angular/core';
2 |
3 | import { Comment, User, UserService } from '../core';
4 | import { Subscription } from 'rxjs';
5 |
6 | @Component({
7 | selector: 'app-article-comment',
8 | templateUrl: './article-comment.component.html'
9 | })
10 | export class ArticleCommentComponent implements OnInit, OnDestroy {
11 | constructor(
12 | private userService: UserService
13 | ) {}
14 |
15 | private subscription: Subscription;
16 |
17 | @Input() comment: Comment;
18 | @Output() deleteComment = new EventEmitter();
19 |
20 | canModify: boolean;
21 |
22 | ngOnInit() {
23 | // Load the current user's data
24 | this.subscription = this.userService.currentUser.subscribe(
25 | (userData: User) => {
26 | this.canModify = (userData.username === this.comment.author.username);
27 | }
28 | );
29 | }
30 |
31 | ngOnDestroy() {
32 | this.subscription.unsubscribe();
33 | }
34 |
35 | deleteClicked() {
36 | this.deleteComment.emit(true);
37 | }
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/app/article/article-resolver.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable, } from '@angular/core';
2 | import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
3 | import { Observable } from 'rxjs';
4 |
5 | import { Article, ArticlesService, UserService } from '../core';
6 | import { catchError } from 'rxjs/operators';
7 |
8 | @Injectable()
9 | export class ArticleResolver implements Resolve {
10 | constructor(
11 | private articlesService: ArticlesService,
12 | private router: Router,
13 | private userService: UserService
14 | ) {}
15 |
16 | resolve(
17 | route: ActivatedRouteSnapshot,
18 | state: RouterStateSnapshot
19 | ): Observable {
20 |
21 | return this.articlesService.get(route.params['slug'])
22 | .pipe(catchError((err) => this.router.navigateByUrl('/')));
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/app/article/article-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { ArticleComponent } from './article.component';
4 | import { ArticleResolver } from './article-resolver.service';
5 |
6 | const routes: Routes = [
7 | {
8 | path: ':slug',
9 | component: ArticleComponent,
10 | resolve: {
11 | article: ArticleResolver
12 | }
13 | }
14 | ];
15 |
16 | @NgModule({
17 | imports: [RouterModule.forChild(routes)],
18 | exports: [RouterModule]
19 | })
20 | export class ArticleRoutingModule {}
21 |
--------------------------------------------------------------------------------
/src/app/article/article.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
{{ article.title }}
6 |
7 |
8 |
9 |
10 |
12 | Edit Article
13 |
14 |
15 |
20 |
21 |
22 |
23 |
26 |
27 |
28 |
31 | {{ article.favorited ? 'Unfavorite' : 'Favorite' }} Article ({{ article.favoritesCount }})
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | -
49 | {{ tag }}
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
64 | Edit Article
65 |
66 |
67 |
72 |
73 |
74 |
75 |
78 |
79 |
80 |
83 | {{ article.favorited ? 'Unfavorite' : 'Favorite' }} Article ({{ article.favoritesCount }})
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
113 |
114 |
117 |
118 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/src/app/article/article.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { FormControl } from '@angular/forms';
3 | import { ActivatedRoute, Router } from '@angular/router';
4 |
5 | import {
6 | Article,
7 | ArticlesService,
8 | Comment,
9 | CommentsService,
10 | User,
11 | UserService
12 | } from '../core';
13 |
14 | @Component({
15 | selector: 'app-article-page',
16 | templateUrl: './article.component.html'
17 | })
18 | export class ArticleComponent implements OnInit {
19 | article: Article;
20 | currentUser: User;
21 | canModify: boolean;
22 | comments: Comment[];
23 | commentControl = new FormControl();
24 | commentFormErrors = {};
25 | isSubmitting = false;
26 | isDeleting = false;
27 |
28 | constructor(
29 | private route: ActivatedRoute,
30 | private articlesService: ArticlesService,
31 | private commentsService: CommentsService,
32 | private router: Router,
33 | private userService: UserService,
34 | ) { }
35 |
36 | ngOnInit() {
37 | // Retreive the prefetched article
38 | this.route.data.subscribe(
39 | (data: { article: Article }) => {
40 | this.article = data.article;
41 |
42 | // Load the comments on this article
43 | this.populateComments();
44 | }
45 | );
46 |
47 | // Load the current user's data
48 | this.userService.currentUser.subscribe(
49 | (userData: User) => {
50 | this.currentUser = userData;
51 |
52 | this.canModify = (this.currentUser.username === this.article.author.username);
53 | }
54 | );
55 | }
56 |
57 | onToggleFavorite(favorited: boolean) {
58 | this.article.favorited = favorited;
59 |
60 | if (favorited) {
61 | this.article.favoritesCount++;
62 | } else {
63 | this.article.favoritesCount--;
64 | }
65 | }
66 |
67 | onToggleFollowing(following: boolean) {
68 | this.article.author.following = following;
69 | }
70 |
71 | deleteArticle() {
72 | this.isDeleting = true;
73 |
74 | this.articlesService.destroy(this.article.slug)
75 | .subscribe(
76 | success => {
77 | this.router.navigateByUrl('/');
78 | }
79 | );
80 | }
81 |
82 | populateComments() {
83 | this.commentsService.getAll(this.article.slug)
84 | .subscribe(comments => this.comments = comments);
85 | }
86 |
87 | addComment() {
88 | this.isSubmitting = true;
89 | this.commentFormErrors = {};
90 |
91 | const commentBody = this.commentControl.value;
92 | this.commentsService
93 | .add(this.article.slug, commentBody)
94 | .subscribe(
95 | comment => {
96 | this.comments.unshift(comment);
97 | this.commentControl.reset('');
98 | this.isSubmitting = false;
99 | },
100 | errors => {
101 | this.isSubmitting = false;
102 | this.commentFormErrors = errors;
103 | }
104 | );
105 | }
106 |
107 | onDeleteComment(comment) {
108 | this.commentsService.destroy(comment.id, this.article.slug)
109 | .subscribe(
110 | success => {
111 | this.comments = this.comments.filter((item) => item !== comment);
112 | }
113 | );
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/src/app/article/article.module.ts:
--------------------------------------------------------------------------------
1 | import { ModuleWithProviders, NgModule } from '@angular/core';
2 | import { RouterModule } from '@angular/router';
3 |
4 | import { ArticleComponent } from './article.component';
5 | import { ArticleCommentComponent } from './article-comment.component';
6 | import { ArticleResolver } from './article-resolver.service';
7 | import { MarkdownPipe } from './markdown.pipe';
8 | import { SharedModule } from '../shared';
9 | import { ArticleRoutingModule } from './article-routing.module';
10 |
11 | @NgModule({
12 | imports: [
13 | SharedModule,
14 | ArticleRoutingModule
15 | ],
16 | declarations: [
17 | ArticleComponent,
18 | ArticleCommentComponent,
19 | MarkdownPipe
20 | ],
21 |
22 | providers: [
23 | ArticleResolver
24 | ]
25 | })
26 | export class ArticleModule {}
27 |
--------------------------------------------------------------------------------
/src/app/article/markdown.pipe.ts:
--------------------------------------------------------------------------------
1 | import { Pipe, PipeTransform } from '@angular/core';
2 | import * as marked from 'marked';
3 |
4 | @Pipe({name: 'markdown'})
5 | export class MarkdownPipe implements PipeTransform {
6 | transform(content: string): string {
7 | return marked(content, { sanitize: true });
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/app/auth/auth-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { AuthComponent } from './auth.component';
4 | import { NoAuthGuard } from './no-auth-guard.service';
5 |
6 | const routes: Routes = [
7 | {
8 | path: 'login',
9 | component: AuthComponent,
10 | canActivate: [NoAuthGuard]
11 | },
12 | {
13 | path: 'register',
14 | component: AuthComponent,
15 | canActivate: [NoAuthGuard]
16 | }
17 | ];
18 |
19 | @NgModule({
20 | imports: [RouterModule.forChild(routes)],
21 | exports: [RouterModule]
22 | })
23 | export class AuthRoutingModule {}
24 |
--------------------------------------------------------------------------------
/src/app/auth/auth.component.html:
--------------------------------------------------------------------------------
1 |
46 |
--------------------------------------------------------------------------------
/src/app/auth/auth.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
3 | import { ActivatedRoute, Router } from '@angular/router';
4 |
5 | import { Errors, UserService } from '../core';
6 |
7 | @Component({
8 | selector: 'app-auth-page',
9 | templateUrl: './auth.component.html'
10 | })
11 | export class AuthComponent implements OnInit {
12 | authType: String = '';
13 | title: String = '';
14 | errors: Errors = {errors: {}};
15 | isSubmitting = false;
16 | authForm: FormGroup;
17 |
18 | constructor(
19 | private route: ActivatedRoute,
20 | private router: Router,
21 | private userService: UserService,
22 | private fb: FormBuilder
23 | ) {
24 | // use FormBuilder to create a form group
25 | this.authForm = this.fb.group({
26 | 'email': ['', Validators.required],
27 | 'password': ['', Validators.required]
28 | });
29 | }
30 |
31 | ngOnInit() {
32 | this.route.url.subscribe(data => {
33 | // Get the last piece of the URL (it's either 'login' or 'register')
34 | this.authType = data[data.length - 1].path;
35 | // Set a title for the page accordingly
36 | this.title = (this.authType === 'login') ? 'Sign in' : 'Sign up';
37 | // add form control for username if this is the register page
38 | if (this.authType === 'register') {
39 | this.authForm.addControl('username', new FormControl());
40 | }
41 | });
42 | }
43 |
44 | submitForm() {
45 | this.isSubmitting = true;
46 | this.errors = {errors: {}};
47 |
48 | const credentials = this.authForm.value;
49 | this.userService
50 | .attemptAuth(this.authType, credentials)
51 | .subscribe(
52 | data => this.router.navigateByUrl('/'),
53 | err => {
54 | this.errors = err;
55 | this.isSubmitting = false;
56 | }
57 | );
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/app/auth/auth.module.ts:
--------------------------------------------------------------------------------
1 | import { ModuleWithProviders, NgModule } from '@angular/core';
2 | import { RouterModule } from '@angular/router';
3 |
4 | import { AuthComponent } from './auth.component';
5 | import { NoAuthGuard } from './no-auth-guard.service';
6 | import { SharedModule } from '../shared';
7 | import { AuthRoutingModule } from './auth-routing.module';
8 |
9 | @NgModule({
10 | imports: [
11 | SharedModule,
12 | AuthRoutingModule
13 | ],
14 | declarations: [
15 | AuthComponent
16 | ],
17 | providers: [
18 | NoAuthGuard
19 | ]
20 | })
21 | export class AuthModule {}
22 |
--------------------------------------------------------------------------------
/src/app/auth/no-auth-guard.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
3 | import { Observable } from 'rxjs';
4 |
5 | import { UserService } from '../core';
6 | import { map , take } from 'rxjs/operators';
7 |
8 | @Injectable()
9 | export class NoAuthGuard implements CanActivate {
10 | constructor(
11 | private router: Router,
12 | private userService: UserService
13 | ) {}
14 |
15 | canActivate(
16 | route: ActivatedRouteSnapshot,
17 | state: RouterStateSnapshot
18 | ): Observable {
19 |
20 | return this.userService.isAuthenticated.pipe(take(1), map(isAuth => !isAuth));
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/app/core/core.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { HTTP_INTERCEPTORS } from '@angular/common/http';
4 | import { HttpTokenInterceptor } from './interceptors/http.token.interceptor';
5 |
6 | import {
7 | ApiService,
8 | ArticlesService,
9 | AuthGuard,
10 | CommentsService,
11 | JwtService,
12 | ProfilesService,
13 | TagsService,
14 | UserService
15 | } from './services';
16 |
17 | @NgModule({
18 | imports: [
19 | CommonModule
20 | ],
21 | providers: [
22 | { provide: HTTP_INTERCEPTORS, useClass: HttpTokenInterceptor, multi: true },
23 | ApiService,
24 | ArticlesService,
25 | AuthGuard,
26 | CommentsService,
27 | JwtService,
28 | ProfilesService,
29 | TagsService,
30 | UserService
31 | ],
32 | declarations: []
33 | })
34 | export class CoreModule { }
35 |
--------------------------------------------------------------------------------
/src/app/core/index.ts:
--------------------------------------------------------------------------------
1 | export * from './core.module';
2 | export * from './services';
3 | export * from './models';
4 | export * from './interceptors';
5 |
--------------------------------------------------------------------------------
/src/app/core/interceptors/http.token.interceptor.ts:
--------------------------------------------------------------------------------
1 | import { Injectable, Injector } from '@angular/core';
2 | import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
3 | import { Observable } from 'rxjs';
4 |
5 | import { JwtService } from '../services';
6 |
7 | @Injectable()
8 | export class HttpTokenInterceptor implements HttpInterceptor {
9 | constructor(private jwtService: JwtService) {}
10 |
11 | intercept(req: HttpRequest, next: HttpHandler): Observable> {
12 | const headersConfig = {
13 | 'Content-Type': 'application/json',
14 | 'Accept': 'application/json'
15 | };
16 |
17 | const token = this.jwtService.getToken();
18 |
19 | if (token) {
20 | headersConfig['Authorization'] = `Token ${token}`;
21 | }
22 |
23 | const request = req.clone({ setHeaders: headersConfig });
24 | return next.handle(request);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/app/core/interceptors/index.ts:
--------------------------------------------------------------------------------
1 | export * from './http.token.interceptor';
2 |
--------------------------------------------------------------------------------
/src/app/core/models/article-list-config.model.ts:
--------------------------------------------------------------------------------
1 | export interface ArticleListConfig {
2 | type: string;
3 |
4 | filters: {
5 | tag?: string,
6 | author?: string,
7 | favorited?: string,
8 | limit?: number,
9 | offset?: number
10 | };
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/core/models/article.model.ts:
--------------------------------------------------------------------------------
1 | import { Profile } from './profile.model';
2 |
3 | export interface Article {
4 | slug: string;
5 | title: string;
6 | description: string;
7 | body: string;
8 | tagList: string[];
9 | createdAt: string;
10 | updatedAt: string;
11 | favorited: boolean;
12 | favoritesCount: number;
13 | author: Profile;
14 | }
15 |
--------------------------------------------------------------------------------
/src/app/core/models/comment.model.ts:
--------------------------------------------------------------------------------
1 | import { Profile } from './profile.model';
2 |
3 | export interface Comment {
4 | id: number;
5 | body: string;
6 | createdAt: string;
7 | author: Profile;
8 | }
9 |
--------------------------------------------------------------------------------
/src/app/core/models/errors.model.ts:
--------------------------------------------------------------------------------
1 | export interface Errors {
2 | errors: {[key: string]: string};
3 | }
4 |
--------------------------------------------------------------------------------
/src/app/core/models/index.ts:
--------------------------------------------------------------------------------
1 | export * from './article.model';
2 | export * from './article-list-config.model';
3 | export * from './comment.model';
4 | export * from './errors.model';
5 | export * from './profile.model';
6 | export * from './user.model';
7 |
--------------------------------------------------------------------------------
/src/app/core/models/profile.model.ts:
--------------------------------------------------------------------------------
1 | export interface Profile {
2 | username: string;
3 | bio: string;
4 | image: string;
5 | following: boolean;
6 | }
7 |
--------------------------------------------------------------------------------
/src/app/core/models/user.model.ts:
--------------------------------------------------------------------------------
1 | export interface User {
2 | email: string;
3 | token: string;
4 | username: string;
5 | bio: string;
6 | image: string;
7 | }
8 |
--------------------------------------------------------------------------------
/src/app/core/services/api.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { environment } from '../../../environments/environment';
3 | import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';
4 | import { Observable , throwError } from 'rxjs';
5 |
6 | import { JwtService } from './jwt.service';
7 | import { catchError } from 'rxjs/operators';
8 |
9 | @Injectable()
10 | export class ApiService {
11 | constructor(
12 | private http: HttpClient,
13 | private jwtService: JwtService
14 | ) {}
15 |
16 | private formatErrors(error: any) {
17 | return throwError(error.error);
18 | }
19 |
20 | get(path: string, params: HttpParams = new HttpParams()): Observable {
21 | return this.http.get(`${environment.api_url}${path}`, { params })
22 | .pipe(catchError(this.formatErrors));
23 | }
24 |
25 | put(path: string, body: Object = {}): Observable {
26 | return this.http.put(
27 | `${environment.api_url}${path}`,
28 | JSON.stringify(body)
29 | ).pipe(catchError(this.formatErrors));
30 | }
31 |
32 | post(path: string, body: Object = {}): Observable {
33 | return this.http.post(
34 | `${environment.api_url}${path}`,
35 | JSON.stringify(body)
36 | ).pipe(catchError(this.formatErrors));
37 | }
38 |
39 | delete(path): Observable {
40 | return this.http.delete(
41 | `${environment.api_url}${path}`
42 | ).pipe(catchError(this.formatErrors));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/app/core/services/articles.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpParams } from '@angular/common/http';
3 | import { Observable } from 'rxjs';
4 |
5 | import { ApiService } from './api.service';
6 | import { Article, ArticleListConfig } from '../models';
7 | import { map } from 'rxjs/operators';
8 |
9 | @Injectable()
10 | export class ArticlesService {
11 | constructor (
12 | private apiService: ApiService
13 | ) {}
14 |
15 | query(config: ArticleListConfig): Observable<{articles: Article[], articlesCount: number}> {
16 | // Convert any filters over to Angular's URLSearchParams
17 | const params = {};
18 |
19 | Object.keys(config.filters)
20 | .forEach((key) => {
21 | params[key] = config.filters[key];
22 | });
23 |
24 | return this.apiService
25 | .get(
26 | '/articles' + ((config.type === 'feed') ? '/feed' : ''),
27 | new HttpParams({ fromObject: params })
28 | );
29 | }
30 |
31 | get(slug): Observable {
32 | return this.apiService.get('/articles/' + slug)
33 | .pipe(map(data => data.article));
34 | }
35 |
36 | destroy(slug) {
37 | return this.apiService.delete('/articles/' + slug);
38 | }
39 |
40 | save(article): Observable {
41 | // If we're updating an existing article
42 | if (article.slug) {
43 | return this.apiService.put('/articles/' + article.slug, {article: article})
44 | .pipe(map(data => data.article));
45 |
46 | // Otherwise, create a new article
47 | } else {
48 | return this.apiService.post('/articles/', {article: article})
49 | .pipe(map(data => data.article));
50 | }
51 | }
52 |
53 | favorite(slug): Observable {
54 | return this.apiService.post('/articles/' + slug + '/favorite');
55 | }
56 |
57 | unfavorite(slug): Observable {
58 | return this.apiService.delete('/articles/' + slug + '/favorite');
59 | }
60 |
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/app/core/services/auth-guard.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
3 | import { Observable } from 'rxjs';
4 |
5 | import { UserService } from './user.service';
6 | import { take } from 'rxjs/operators';
7 |
8 | @Injectable()
9 | export class AuthGuard implements CanActivate {
10 | constructor(
11 | private router: Router,
12 | private userService: UserService
13 | ) {}
14 |
15 | canActivate(
16 | route: ActivatedRouteSnapshot,
17 | state: RouterStateSnapshot
18 | ): Observable {
19 |
20 | return this.userService.isAuthenticated.pipe(take(1));
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/app/core/services/comments.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Observable } from 'rxjs';
3 |
4 | import { ApiService } from './api.service';
5 | import { Comment } from '../models';
6 | import { map } from 'rxjs/operators';
7 |
8 |
9 | @Injectable()
10 | export class CommentsService {
11 | constructor (
12 | private apiService: ApiService
13 | ) {}
14 |
15 | add(slug, payload): Observable {
16 | return this.apiService
17 | .post(
18 | `/articles/${slug}/comments`,
19 | { comment: { body: payload } }
20 | ).pipe(map(data => data.comment));
21 | }
22 |
23 | getAll(slug): Observable {
24 | return this.apiService.get(`/articles/${slug}/comments`)
25 | .pipe(map(data => data.comments));
26 | }
27 |
28 | destroy(commentId, articleSlug) {
29 | return this.apiService
30 | .delete(`/articles/${articleSlug}/comments/${commentId}`);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/app/core/services/index.ts:
--------------------------------------------------------------------------------
1 | export * from './api.service';
2 | export * from './articles.service';
3 | export * from './auth-guard.service';
4 | export * from './comments.service';
5 | export * from './jwt.service';
6 | export * from './profiles.service';
7 | export * from './tags.service';
8 | export * from './user.service';
9 |
--------------------------------------------------------------------------------
/src/app/core/services/jwt.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 |
3 |
4 | @Injectable()
5 | export class JwtService {
6 |
7 | getToken(): String {
8 | return window.localStorage['jwtToken'];
9 | }
10 |
11 | saveToken(token: String) {
12 | window.localStorage['jwtToken'] = token;
13 | }
14 |
15 | destroyToken() {
16 | window.localStorage.removeItem('jwtToken');
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/app/core/services/profiles.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Observable } from 'rxjs';
3 |
4 | import { ApiService } from './api.service';
5 | import { Profile } from '../models';
6 | import { map } from 'rxjs/operators';
7 |
8 | @Injectable()
9 | export class ProfilesService {
10 | constructor (
11 | private apiService: ApiService
12 | ) {}
13 |
14 | get(username: string): Observable {
15 | return this.apiService.get('/profiles/' + username)
16 | .pipe(map((data: {profile: Profile}) => data.profile));
17 | }
18 |
19 | follow(username: string): Observable {
20 | return this.apiService.post('/profiles/' + username + '/follow');
21 | }
22 |
23 | unfollow(username: string): Observable {
24 | return this.apiService.delete('/profiles/' + username + '/follow');
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/app/core/services/tags.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Observable } from 'rxjs';
3 |
4 | import { ApiService } from './api.service';
5 | import { map } from 'rxjs/operators';
6 |
7 | @Injectable()
8 | export class TagsService {
9 | constructor (
10 | private apiService: ApiService
11 | ) {}
12 |
13 | getAll(): Observable<[string]> {
14 | return this.apiService.get('/tags')
15 | .pipe(map(data => data.tags));
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/app/core/services/user.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient } from '@angular/common/http';
3 | import { Observable , BehaviorSubject , ReplaySubject } from 'rxjs';
4 |
5 | import { ApiService } from './api.service';
6 | import { JwtService } from './jwt.service';
7 | import { User } from '../models';
8 | import { map , distinctUntilChanged } from 'rxjs/operators';
9 |
10 |
11 | @Injectable()
12 | export class UserService {
13 | private currentUserSubject = new BehaviorSubject({} as User);
14 | public currentUser = this.currentUserSubject.asObservable().pipe(distinctUntilChanged());
15 |
16 | private isAuthenticatedSubject = new ReplaySubject(1);
17 | public isAuthenticated = this.isAuthenticatedSubject.asObservable();
18 |
19 | constructor (
20 | private apiService: ApiService,
21 | private http: HttpClient,
22 | private jwtService: JwtService
23 | ) {}
24 |
25 | // Verify JWT in localstorage with server & load user's info.
26 | // This runs once on application startup.
27 | populate() {
28 | // If JWT detected, attempt to get & store user's info
29 | if (this.jwtService.getToken()) {
30 | this.apiService.get('/user')
31 | .subscribe(
32 | data => this.setAuth(data.user),
33 | err => this.purgeAuth()
34 | );
35 | } else {
36 | // Remove any potential remnants of previous auth states
37 | this.purgeAuth();
38 | }
39 | }
40 |
41 | setAuth(user: User) {
42 | // Save JWT sent from server in localstorage
43 | this.jwtService.saveToken(user.token);
44 | // Set current user data into observable
45 | this.currentUserSubject.next(user);
46 | // Set isAuthenticated to true
47 | this.isAuthenticatedSubject.next(true);
48 | }
49 |
50 | purgeAuth() {
51 | // Remove JWT from localstorage
52 | this.jwtService.destroyToken();
53 | // Set current user to an empty object
54 | this.currentUserSubject.next({} as User);
55 | // Set auth status to false
56 | this.isAuthenticatedSubject.next(false);
57 | }
58 |
59 | attemptAuth(type, credentials): Observable {
60 | const route = (type === 'login') ? '/login' : '';
61 | return this.apiService.post('/users' + route, {user: credentials})
62 | .pipe(map(
63 | data => {
64 | this.setAuth(data.user);
65 | return data;
66 | }
67 | ));
68 | }
69 |
70 | getCurrentUser(): User {
71 | return this.currentUserSubject.value;
72 | }
73 |
74 | // Update the user on the server (email, pass, etc)
75 | update(user): Observable {
76 | return this.apiService
77 | .put('/user', { user })
78 | .pipe(map(data => {
79 | // Update the currentUser observable
80 | this.currentUserSubject.next(data.user);
81 | return data.user;
82 | }));
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/app/editor/editable-article-resolver.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
3 | import { Observable } from 'rxjs';
4 |
5 | import { Article, ArticlesService, UserService } from '../core';
6 | import { catchError , map } from 'rxjs/operators';
7 |
8 | @Injectable()
9 | export class EditableArticleResolver implements Resolve {
10 | constructor(
11 | private articlesService: ArticlesService,
12 | private router: Router,
13 | private userService: UserService
14 | ) { }
15 |
16 | resolve(
17 | route: ActivatedRouteSnapshot,
18 | state: RouterStateSnapshot
19 | ): Observable {
20 |
21 | return this.articlesService.get(route.params['slug'])
22 | .pipe(
23 | map(
24 | article => {
25 | if (this.userService.getCurrentUser().username === article.author.username) {
26 | return article;
27 | } else {
28 | this.router.navigateByUrl('/');
29 | }
30 | }
31 | ),
32 | catchError((err) => this.router.navigateByUrl('/'))
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/app/editor/editor-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { EditorComponent } from './editor.component';
4 | import { EditableArticleResolver } from './editable-article-resolver.service';
5 | import { AuthGuard } from '../core';
6 | import { SharedModule } from '../shared';
7 |
8 | const routes: Routes = [
9 | {
10 | path: '',
11 | component: EditorComponent,
12 | canActivate: [AuthGuard]
13 | },
14 | {
15 | path: ':slug',
16 | component: EditorComponent,
17 | canActivate: [AuthGuard],
18 | resolve: {
19 | article: EditableArticleResolver
20 | }
21 | }
22 | ];
23 |
24 | @NgModule({
25 | imports: [RouterModule.forChild(routes)],
26 | exports: [RouterModule]
27 | })
28 | export class EditorRoutingModule {}
29 |
--------------------------------------------------------------------------------
/src/app/editor/editor.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/app/editor/editor.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { FormBuilder, FormGroup, FormControl } from '@angular/forms';
3 | import { ActivatedRoute, Router } from '@angular/router';
4 |
5 | import { Article, ArticlesService } from '../core';
6 |
7 | @Component({
8 | selector: 'app-editor-page',
9 | templateUrl: './editor.component.html'
10 | })
11 | export class EditorComponent implements OnInit {
12 | article: Article = {} as Article;
13 | articleForm: FormGroup;
14 | tagField = new FormControl();
15 | errors: Object = {};
16 | isSubmitting = false;
17 |
18 | constructor(
19 | private articlesService: ArticlesService,
20 | private route: ActivatedRoute,
21 | private router: Router,
22 | private fb: FormBuilder
23 | ) {
24 | // use the FormBuilder to create a form group
25 | this.articleForm = this.fb.group({
26 | title: '',
27 | description: '',
28 | body: ''
29 | });
30 |
31 | // Initialized tagList as empty array
32 | this.article.tagList = [];
33 |
34 | // Optional: subscribe to value changes on the form
35 | // this.articleForm.valueChanges.subscribe(value => this.updateArticle(value));
36 | }
37 |
38 | ngOnInit() {
39 | // If there's an article prefetched, load it
40 | this.route.data.subscribe((data: { article: Article }) => {
41 | if (data.article) {
42 | this.article = data.article;
43 | this.articleForm.patchValue(data.article);
44 | }
45 | });
46 | }
47 |
48 | addTag() {
49 | // retrieve tag control
50 | const tag = this.tagField.value;
51 | // only add tag if it does not exist yet
52 | if (this.article.tagList.indexOf(tag) < 0) {
53 | this.article.tagList.push(tag);
54 | }
55 | // clear the input
56 | this.tagField.reset('');
57 | }
58 |
59 | removeTag(tagName: string) {
60 | this.article.tagList = this.article.tagList.filter(tag => tag !== tagName);
61 | }
62 |
63 | submitForm() {
64 | this.isSubmitting = true;
65 |
66 | // update the model
67 | this.updateArticle(this.articleForm.value);
68 |
69 | // post the changes
70 | this.articlesService.save(this.article).subscribe(
71 | article => this.router.navigateByUrl('/article/' + article.slug),
72 | err => {
73 | this.errors = err;
74 | this.isSubmitting = false;
75 | }
76 | );
77 | }
78 |
79 | updateArticle(values: Object) {
80 | Object.assign(this.article, values);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/app/editor/editor.module.ts:
--------------------------------------------------------------------------------
1 | import { ModuleWithProviders, NgModule } from '@angular/core';
2 | import { RouterModule } from '@angular/router';
3 |
4 | import { EditorComponent } from './editor.component';
5 | import { EditableArticleResolver } from './editable-article-resolver.service';
6 | import { AuthGuard } from '../core';
7 | import { SharedModule } from '../shared';
8 | import { EditorRoutingModule } from './editor-routing.module';
9 |
10 | @NgModule({
11 | imports: [SharedModule, EditorRoutingModule],
12 | declarations: [EditorComponent],
13 | providers: [EditableArticleResolver]
14 | })
15 | export class EditorModule {}
16 |
--------------------------------------------------------------------------------
/src/app/home/home-auth-resolver.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
3 | import { Observable } from 'rxjs';
4 |
5 | import { UserService } from '../core';
6 | import { take } from 'rxjs/operators';
7 |
8 | @Injectable()
9 | export class HomeAuthResolver implements Resolve {
10 | constructor(
11 | private router: Router,
12 | private userService: UserService
13 | ) {}
14 |
15 | resolve(
16 | route: ActivatedRouteSnapshot,
17 | state: RouterStateSnapshot
18 | ): Observable {
19 |
20 | return this.userService.isAuthenticated.pipe(take(1));
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/app/home/home-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { HomeComponent } from './home.component';
4 | import { HomeAuthResolver } from './home-auth-resolver.service';
5 |
6 | const routes: Routes = [
7 | {
8 | path: '',
9 | component: HomeComponent,
10 | resolve: {
11 | isAuthenticated: HomeAuthResolver
12 | }
13 | }
14 | ];
15 |
16 | @NgModule({
17 | imports: [RouterModule.forChild(routes)],
18 | exports: [RouterModule]
19 | })
20 | export class HomeRoutingModule {}
21 |
--------------------------------------------------------------------------------
/src/app/home/home.component.css:
--------------------------------------------------------------------------------
1 | .nav-link {
2 | cursor:pointer;
3 | }
4 |
5 | .tag-pill{
6 | cursor:pointer;
7 | }
8 |
--------------------------------------------------------------------------------
/src/app/home/home.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
conduit
6 |
A place to share your Angular knowledge.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
40 |
41 |
42 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/src/app/home/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { Router } from '@angular/router';
3 |
4 | import { ArticleListConfig, TagsService, UserService } from '../core';
5 |
6 | @Component({
7 | selector: 'app-home-page',
8 | templateUrl: './home.component.html',
9 | styleUrls: ['./home.component.css']
10 | })
11 | export class HomeComponent implements OnInit {
12 | constructor(
13 | private router: Router,
14 | private tagsService: TagsService,
15 | private userService: UserService
16 | ) {}
17 |
18 | isAuthenticated: boolean;
19 | listConfig: ArticleListConfig = {
20 | type: 'all',
21 | filters: {}
22 | };
23 | tags: Array = [];
24 | tagsLoaded = false;
25 |
26 | ngOnInit() {
27 | this.userService.isAuthenticated.subscribe(
28 | (authenticated) => {
29 | this.isAuthenticated = authenticated;
30 |
31 | // set the article list accordingly
32 | if (authenticated) {
33 | this.setListTo('feed');
34 | } else {
35 | this.setListTo('all');
36 | }
37 | }
38 | );
39 |
40 | this.tagsService.getAll()
41 | .subscribe(tags => {
42 | this.tags = tags;
43 | this.tagsLoaded = true;
44 | });
45 | }
46 |
47 | setListTo(type: string = '', filters: Object = {}) {
48 | // If feed is requested but user is not authenticated, redirect to login
49 | if (type === 'feed' && !this.isAuthenticated) {
50 | this.router.navigateByUrl('/login');
51 | return;
52 | }
53 |
54 | // Otherwise, set the list object
55 | this.listConfig = {type: type, filters: filters};
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/app/home/home.module.ts:
--------------------------------------------------------------------------------
1 | import { ModuleWithProviders, NgModule } from '@angular/core';
2 | import { RouterModule } from '@angular/router';
3 |
4 | import { HomeComponent } from './home.component';
5 | import { HomeAuthResolver } from './home-auth-resolver.service';
6 | import { SharedModule } from '../shared';
7 | import { HomeRoutingModule } from './home-routing.module';
8 |
9 | @NgModule({
10 | imports: [
11 | SharedModule,
12 | HomeRoutingModule
13 | ],
14 | declarations: [
15 | HomeComponent
16 | ],
17 | providers: [
18 | HomeAuthResolver
19 | ]
20 | })
21 | export class HomeModule {}
22 |
--------------------------------------------------------------------------------
/src/app/index.ts:
--------------------------------------------------------------------------------
1 | export * from './app.component';
2 | export * from './app.module';
3 |
--------------------------------------------------------------------------------
/src/app/profile/profile-articles.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/app/profile/profile-articles.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ActivatedRoute, Router } from '@angular/router';
3 |
4 | import { ArticleListConfig, Profile } from '../core';
5 |
6 | @Component({
7 | selector: 'app-profile-articles',
8 | templateUrl: './profile-articles.component.html'
9 | })
10 | export class ProfileArticlesComponent implements OnInit {
11 | constructor(
12 | private route: ActivatedRoute,
13 | private router: Router
14 | ) {}
15 |
16 | profile: Profile;
17 | articlesConfig: ArticleListConfig = {
18 | type: 'all',
19 | filters: {}
20 | };
21 |
22 | ngOnInit() {
23 | this.route.parent.data.subscribe(
24 | (data: {profile: Profile}) => {
25 | this.profile = data.profile;
26 | this.articlesConfig = {
27 | type: 'all',
28 | filters: {}
29 | }; // Only method I found to refresh article load on swap
30 | this.articlesConfig.filters.author = this.profile.username;
31 | }
32 | );
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/app/profile/profile-favorites.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/app/profile/profile-favorites.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ActivatedRoute, Router } from '@angular/router';
3 |
4 | import { ArticleListConfig, Profile } from '../core';
5 |
6 | @Component({
7 | selector: 'app-profile-favorites',
8 | templateUrl: './profile-favorites.component.html'
9 | })
10 | export class ProfileFavoritesComponent implements OnInit {
11 | constructor(
12 | private route: ActivatedRoute,
13 | private router: Router
14 | ) {}
15 |
16 | profile: Profile;
17 | favoritesConfig: ArticleListConfig = {
18 | type: 'all',
19 | filters: {}
20 | };
21 |
22 | ngOnInit() {
23 | this.route.parent.data.subscribe(
24 | (data: {profile: Profile}) => {
25 | this.profile = data.profile;
26 | this.favoritesConfig.filters.favorited = this.profile.username;
27 | }
28 | );
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/app/profile/profile-resolver.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable, } from '@angular/core';
2 | import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
3 | import { Observable } from 'rxjs';
4 |
5 | import { Profile, ProfilesService } from '../core';
6 | import { catchError } from 'rxjs/operators';
7 |
8 | @Injectable()
9 | export class ProfileResolver implements Resolve {
10 | constructor(
11 | private profilesService: ProfilesService,
12 | private router: Router
13 | ) {}
14 |
15 | resolve(
16 | route: ActivatedRouteSnapshot,
17 | state: RouterStateSnapshot
18 | ): Observable {
19 |
20 | return this.profilesService.get(route.params['username'])
21 | .pipe(catchError((err) => this.router.navigateByUrl('/')));
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/app/profile/profile-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { RouterModule, Routes } from '@angular/router';
3 | import { ProfileArticlesComponent } from './profile-articles.component';
4 | import { ProfileFavoritesComponent } from './profile-favorites.component';
5 | import { ProfileResolver } from './profile-resolver.service';
6 | import { ProfileComponent } from './profile.component';
7 |
8 |
9 | const routes: Routes = [
10 | {
11 | path: ':username',
12 | component: ProfileComponent,
13 | resolve: {
14 | profile: ProfileResolver
15 | },
16 | children: [
17 | {
18 | path: '',
19 | component: ProfileArticlesComponent
20 | },
21 | {
22 | path: 'favorites',
23 | component: ProfileFavoritesComponent
24 | }
25 | ]
26 | }
27 | ];
28 |
29 | @NgModule({
30 | imports: [RouterModule.forChild(routes)],
31 | exports: [RouterModule]
32 | })
33 | export class ProfileRoutingModule {}
34 |
--------------------------------------------------------------------------------
/src/app/profile/profile.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
26 |
27 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/src/app/profile/profile.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ActivatedRoute } from '@angular/router';
3 |
4 | import { User, UserService, Profile } from '../core';
5 | import { concatMap , tap } from 'rxjs/operators';
6 |
7 | @Component({
8 | selector: 'app-profile-page',
9 | templateUrl: './profile.component.html'
10 | })
11 | export class ProfileComponent implements OnInit {
12 | constructor(
13 | private route: ActivatedRoute,
14 | private userService: UserService
15 | ) { }
16 |
17 | profile: Profile;
18 | currentUser: User;
19 | isUser: boolean;
20 |
21 | ngOnInit() {
22 | this.route.data.pipe(
23 | concatMap((data: { profile: Profile }) => {
24 | this.profile = data.profile;
25 | // Load the current user's data.
26 | return this.userService.currentUser.pipe(tap(
27 | (userData: User) => {
28 | this.currentUser = userData;
29 | this.isUser = (this.currentUser.username === this.profile.username);
30 | }
31 | ));
32 | })
33 | ).subscribe();
34 | }
35 |
36 | onToggleFollowing(following: boolean) {
37 | this.profile.following = following;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/app/profile/profile.module.ts:
--------------------------------------------------------------------------------
1 | import { ModuleWithProviders, NgModule } from '@angular/core';
2 | import { RouterModule } from '@angular/router';
3 |
4 | import { ProfileArticlesComponent } from './profile-articles.component';
5 | import { ProfileComponent } from './profile.component';
6 | import { ProfileFavoritesComponent } from './profile-favorites.component';
7 | import { ProfileResolver } from './profile-resolver.service';
8 | import { SharedModule } from '../shared';
9 | import { ProfileRoutingModule } from './profile-routing.module';
10 |
11 | @NgModule({
12 | imports: [
13 | SharedModule,
14 | ProfileRoutingModule
15 | ],
16 | declarations: [
17 | ProfileArticlesComponent,
18 | ProfileComponent,
19 | ProfileFavoritesComponent
20 | ],
21 | providers: [
22 | ProfileResolver
23 | ]
24 | })
25 | export class ProfileModule {}
26 |
--------------------------------------------------------------------------------
/src/app/settings/settings-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { RouterModule, Routes } from '@angular/router';
3 | import { AuthGuard } from '../core';
4 | import { SettingsComponent } from './settings.component';
5 |
6 | const routes: Routes = [
7 | {
8 | path: '',
9 | component: SettingsComponent,
10 | canActivate: [AuthGuard]
11 | }
12 | ];
13 |
14 | @NgModule({
15 | imports: [RouterModule.forChild(routes)],
16 | exports: [RouterModule]
17 | })
18 | export class SettingsRoutingModule {}
19 |
--------------------------------------------------------------------------------
/src/app/settings/settings.component.html:
--------------------------------------------------------------------------------
1 |
69 |
--------------------------------------------------------------------------------
/src/app/settings/settings.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { FormBuilder, FormGroup } from '@angular/forms';
3 | import { Router } from '@angular/router';
4 |
5 | import { User, UserService } from '../core';
6 |
7 | @Component({
8 | selector: 'app-settings-page',
9 | templateUrl: './settings.component.html'
10 | })
11 | export class SettingsComponent implements OnInit {
12 | user: User = {} as User;
13 | settingsForm: FormGroup;
14 | errors: Object = {};
15 | isSubmitting = false;
16 |
17 | constructor(
18 | private router: Router,
19 | private userService: UserService,
20 | private fb: FormBuilder
21 | ) {
22 | // create form group using the form builder
23 | this.settingsForm = this.fb.group({
24 | image: '',
25 | username: '',
26 | bio: '',
27 | email: '',
28 | password: ''
29 | });
30 | // Optional: subscribe to changes on the form
31 | // this.settingsForm.valueChanges.subscribe(values => this.updateUser(values));
32 | }
33 |
34 | ngOnInit() {
35 | // Make a fresh copy of the current user's object to place in editable form fields
36 | Object.assign(this.user, this.userService.getCurrentUser());
37 | // Fill the form
38 | this.settingsForm.patchValue(this.user);
39 | }
40 |
41 | logout() {
42 | this.userService.purgeAuth();
43 | this.router.navigateByUrl('/');
44 | }
45 |
46 | submitForm() {
47 | this.isSubmitting = true;
48 |
49 | // update the model
50 | this.updateUser(this.settingsForm.value);
51 |
52 | this.userService
53 | .update(this.user)
54 | .subscribe(
55 | updatedUser => this.router.navigateByUrl('/profile/' + updatedUser.username),
56 | err => {
57 | this.errors = err;
58 | this.isSubmitting = false;
59 | }
60 | );
61 | }
62 |
63 | updateUser(values: Object) {
64 | Object.assign(this.user, values);
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/app/settings/settings.module.ts:
--------------------------------------------------------------------------------
1 | import { ModuleWithProviders, NgModule } from '@angular/core';
2 | import { RouterModule } from '@angular/router';
3 |
4 | import { SettingsComponent } from './settings.component';
5 | import { AuthGuard } from '../core';
6 | import { SharedModule } from '../shared';
7 | import { SettingsRoutingModule } from './settings-routing.module';
8 |
9 | @NgModule({
10 | imports: [
11 | SharedModule,
12 | SettingsRoutingModule
13 | ],
14 | declarations: [
15 | SettingsComponent
16 | ]
17 | })
18 | export class SettingsModule {}
19 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-list.component.css:
--------------------------------------------------------------------------------
1 | .page-link {
2 | cursor: pointer;
3 | }
4 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-list.component.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
8 | Loading articles...
9 |
10 |
11 |
13 | No articles are here... yet.
14 |
15 |
16 |
30 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input } from '@angular/core';
2 |
3 | import { Article, ArticleListConfig, ArticlesService } from '../../core';
4 | @Component({
5 | selector: 'app-article-list',
6 | styleUrls: ['article-list.component.css'],
7 | templateUrl: './article-list.component.html'
8 | })
9 | export class ArticleListComponent {
10 | constructor (
11 | private articlesService: ArticlesService
12 | ) {}
13 |
14 | @Input() limit: number;
15 | @Input()
16 | set config(config: ArticleListConfig) {
17 | if (config) {
18 | this.query = config;
19 | this.currentPage = 1;
20 | this.runQuery();
21 | }
22 | }
23 |
24 | query: ArticleListConfig;
25 | results: Article[];
26 | loading = false;
27 | currentPage = 1;
28 | totalPages: Array = [1];
29 |
30 | setPageTo(pageNumber) {
31 | this.currentPage = pageNumber;
32 | this.runQuery();
33 | }
34 |
35 | runQuery() {
36 | this.loading = true;
37 | this.results = [];
38 |
39 | // Create limit and offset filter (if necessary)
40 | if (this.limit) {
41 | this.query.filters.limit = this.limit;
42 | this.query.filters.offset = (this.limit * (this.currentPage - 1));
43 | }
44 |
45 | this.articlesService.query(this.query)
46 | .subscribe(data => {
47 | this.loading = false;
48 | this.results = data.articles;
49 |
50 | // Used from http://www.jstips.co/en/create-range-0...n-easily-using-one-line/
51 | this.totalPages = Array.from(new Array(Math.ceil(data.articlesCount / this.limit)), (val, index) => index + 1);
52 | });
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-meta.component.html:
--------------------------------------------------------------------------------
1 |
18 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-meta.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input } from '@angular/core';
2 |
3 | import { Article } from '../../core';
4 |
5 | @Component({
6 | selector: 'app-article-meta',
7 | templateUrl: './article-meta.component.html'
8 | })
9 | export class ArticleMetaComponent {
10 | @Input() article: Article;
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-preview.component.html:
--------------------------------------------------------------------------------
1 |
23 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-preview.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input } from '@angular/core';
2 |
3 | import { Article } from '../../core';
4 |
5 | @Component({
6 | selector: 'app-article-preview',
7 | templateUrl: './article-preview.component.html'
8 | })
9 | export class ArticlePreviewComponent {
10 | @Input() article: Article;
11 |
12 | onToggleFavorite(favorited: boolean) {
13 | this.article['favorited'] = favorited;
14 |
15 | if (favorited) {
16 | this.article['favoritesCount']++;
17 | } else {
18 | this.article['favoritesCount']--;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/index.ts:
--------------------------------------------------------------------------------
1 | export * from './article-list.component';
2 | export * from './article-meta.component';
3 | export * from './article-preview.component';
4 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/favorite-button.component.html:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/favorite-button.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, Output } from '@angular/core';
2 | import { Router } from '@angular/router';
3 |
4 | import { Article, ArticlesService, UserService } from '../../core';
5 | import { of } from 'rxjs';
6 | import { concatMap , tap } from 'rxjs/operators';
7 |
8 | @Component({
9 | selector: 'app-favorite-button',
10 | templateUrl: './favorite-button.component.html'
11 | })
12 | export class FavoriteButtonComponent {
13 | constructor(
14 | private articlesService: ArticlesService,
15 | private router: Router,
16 | private userService: UserService
17 | ) {}
18 |
19 | @Input() article: Article;
20 | @Output() toggle = new EventEmitter();
21 | isSubmitting = false;
22 |
23 | toggleFavorite() {
24 | this.isSubmitting = true;
25 |
26 | this.userService.isAuthenticated.pipe(concatMap(
27 | (authenticated) => {
28 | // Not authenticated? Push to login screen
29 | if (!authenticated) {
30 | this.router.navigateByUrl('/login');
31 | return of(null);
32 | }
33 |
34 | // Favorite the article if it isn't favorited yet
35 | if (!this.article.favorited) {
36 | return this.articlesService.favorite(this.article.slug)
37 | .pipe(tap(
38 | data => {
39 | this.isSubmitting = false;
40 | this.toggle.emit(true);
41 | },
42 | err => this.isSubmitting = false
43 | ));
44 |
45 | // Otherwise, unfavorite the article
46 | } else {
47 | return this.articlesService.unfavorite(this.article.slug)
48 | .pipe(tap(
49 | data => {
50 | this.isSubmitting = false;
51 | this.toggle.emit(false);
52 | },
53 | err => this.isSubmitting = false
54 | ));
55 | }
56 |
57 | }
58 | )).subscribe();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/follow-button.component.html:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/follow-button.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, Output } from '@angular/core';
2 | import { Router } from '@angular/router';
3 |
4 | import { Profile, ProfilesService, UserService } from '../../core';
5 | import { concatMap , tap } from 'rxjs/operators';
6 | import { of } from 'rxjs';
7 |
8 | @Component({
9 | selector: 'app-follow-button',
10 | templateUrl: './follow-button.component.html'
11 | })
12 | export class FollowButtonComponent {
13 | constructor(
14 | private profilesService: ProfilesService,
15 | private router: Router,
16 | private userService: UserService
17 | ) {}
18 |
19 | @Input() profile: Profile;
20 | @Output() toggle = new EventEmitter();
21 | isSubmitting = false;
22 |
23 | toggleFollowing() {
24 | this.isSubmitting = true;
25 | // TODO: remove nested subscribes, use mergeMap
26 |
27 | this.userService.isAuthenticated.pipe(concatMap(
28 | (authenticated) => {
29 | // Not authenticated? Push to login screen
30 | if (!authenticated) {
31 | this.router.navigateByUrl('/login');
32 | return of(null);
33 | }
34 |
35 | // Follow this profile if we aren't already
36 | if (!this.profile.following) {
37 | return this.profilesService.follow(this.profile.username)
38 | .pipe(tap(
39 | data => {
40 | this.isSubmitting = false;
41 | this.toggle.emit(true);
42 | },
43 | err => this.isSubmitting = false
44 | ));
45 |
46 | // Otherwise, unfollow this profile
47 | } else {
48 | return this.profilesService.unfollow(this.profile.username)
49 | .pipe(tap(
50 | data => {
51 | this.isSubmitting = false;
52 | this.toggle.emit(false);
53 | },
54 | err => this.isSubmitting = false
55 | ));
56 | }
57 | }
58 | )).subscribe();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/index.ts:
--------------------------------------------------------------------------------
1 | export * from './favorite-button.component';
2 | export * from './follow-button.component';
3 |
--------------------------------------------------------------------------------
/src/app/shared/index.ts:
--------------------------------------------------------------------------------
1 | export * from './article-helpers';
2 | export * from './buttons';
3 | export * from './layout';
4 | export * from './list-errors.component';
5 | export * from './shared.module';
6 | export * from './show-authed.directive';
7 |
--------------------------------------------------------------------------------
/src/app/shared/layout/footer.component.html:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/src/app/shared/layout/footer.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-layout-footer',
5 | templateUrl: './footer.component.html'
6 | })
7 | export class FooterComponent {
8 | today: number = Date.now();
9 | }
10 |
--------------------------------------------------------------------------------
/src/app/shared/layout/header.component.html:
--------------------------------------------------------------------------------
1 |
76 |
--------------------------------------------------------------------------------
/src/app/shared/layout/header.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | import { User, UserService } from '../../core';
4 |
5 | @Component({
6 | selector: 'app-layout-header',
7 | templateUrl: './header.component.html'
8 | })
9 | export class HeaderComponent implements OnInit {
10 | constructor(
11 | private userService: UserService
12 | ) {}
13 |
14 | currentUser: User;
15 |
16 | ngOnInit() {
17 | this.userService.currentUser.subscribe(
18 | (userData) => {
19 | this.currentUser = userData;
20 | }
21 | );
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/app/shared/layout/index.ts:
--------------------------------------------------------------------------------
1 | export * from './footer.component';
2 | export * from './header.component';
3 |
--------------------------------------------------------------------------------
/src/app/shared/list-errors.component.html:
--------------------------------------------------------------------------------
1 |
2 | -
3 | {{ error }}
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/app/shared/list-errors.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input } from '@angular/core';
2 |
3 | import { Errors } from '../core';
4 |
5 | @Component({
6 | selector: 'app-list-errors',
7 | templateUrl: './list-errors.component.html'
8 | })
9 | export class ListErrorsComponent {
10 | formattedErrors: Array = [];
11 |
12 | @Input()
13 | set errors(errorList: Errors) {
14 | this.formattedErrors = Object.keys(errorList.errors || {})
15 | .map(key => `${key} ${errorList.errors[key]}`);
16 | }
17 |
18 | get errorList() { return this.formattedErrors; }
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/app/shared/shared.module.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { NgModule } from '@angular/core';
3 | import { FormsModule, ReactiveFormsModule } from '@angular/forms';
4 | import { HttpClientModule } from '@angular/common/http';
5 | import { RouterModule } from '@angular/router';
6 |
7 | import { ArticleListComponent, ArticleMetaComponent, ArticlePreviewComponent } from './article-helpers';
8 | import { FavoriteButtonComponent, FollowButtonComponent } from './buttons';
9 | import { ListErrorsComponent } from './list-errors.component';
10 | import { ShowAuthedDirective } from './show-authed.directive';
11 |
12 | @NgModule({
13 | imports: [
14 | CommonModule,
15 | FormsModule,
16 | ReactiveFormsModule,
17 | HttpClientModule,
18 | RouterModule
19 | ],
20 | declarations: [
21 | ArticleListComponent,
22 | ArticleMetaComponent,
23 | ArticlePreviewComponent,
24 | FavoriteButtonComponent,
25 | FollowButtonComponent,
26 | ListErrorsComponent,
27 | ShowAuthedDirective
28 | ],
29 | exports: [
30 | ArticleListComponent,
31 | ArticleMetaComponent,
32 | ArticlePreviewComponent,
33 | CommonModule,
34 | FavoriteButtonComponent,
35 | FollowButtonComponent,
36 | FormsModule,
37 | ReactiveFormsModule,
38 | HttpClientModule,
39 | ListErrorsComponent,
40 | RouterModule,
41 | ShowAuthedDirective
42 | ]
43 | })
44 | export class SharedModule {}
45 |
--------------------------------------------------------------------------------
/src/app/shared/show-authed.directive.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Directive,
3 | Input,
4 | OnInit,
5 | TemplateRef,
6 | ViewContainerRef
7 | } from '@angular/core';
8 |
9 | import { UserService } from '../core';
10 |
11 | @Directive({ selector: '[appShowAuthed]' })
12 | export class ShowAuthedDirective implements OnInit {
13 | constructor(
14 | private templateRef: TemplateRef,
15 | private userService: UserService,
16 | private viewContainer: ViewContainerRef
17 | ) {}
18 |
19 | condition: boolean;
20 |
21 | ngOnInit() {
22 | this.userService.isAuthenticated.subscribe(
23 | (isAuthenticated) => {
24 | if (isAuthenticated && this.condition || !isAuthenticated && !this.condition) {
25 | this.viewContainer.createEmbeddedView(this.templateRef);
26 | } else {
27 | this.viewContainer.clear();
28 | }
29 | }
30 | );
31 | }
32 |
33 | @Input() set appShowAuthed(condition: boolean) {
34 | this.condition = condition;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CypressCecelia/cypress-testing-angular-workshop/fdfee921a37bb087a99edf0f179c03db8fddedb0/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/assets/.npmignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CypressCecelia/cypress-testing-angular-workshop/fdfee921a37bb087a99edf0f179c03db8fddedb0/src/assets/.npmignore
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true,
3 | api_url: 'https://conduit.productionready.io/api'
4 | };
5 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false,
8 | api_url: 'https://conduit.productionready.io/api'
9 | };
10 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CypressCecelia/cypress-testing-angular-workshop/fdfee921a37bb087a99edf0f179c03db8fddedb0/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Conduit
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Loading...
16 |
17 |
18 |
--------------------------------------------------------------------------------
/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 | const bootstrapPromise = platformBrowserDynamic().bootstrapModule(AppModule);
12 |
13 | // Logging bootstrap information
14 | bootstrapPromise.then(success => console.log(`Bootstrap success`))
15 | .catch(err => console.error(err));
16 |
--------------------------------------------------------------------------------
/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 | /** Evergreen browsers require these. **/
44 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
45 | import 'core-js/es7/reflect';
46 |
47 | /**
48 | * Required to support Web Animations `@angular/platform-browser/animations`.
49 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
50 | **/
51 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
52 |
53 | /***************************************************************************************************
54 | * Zone JS is required by default for Angular itself.
55 | */
56 | import 'zone.js/dist/zone'; // Included with Angular CLI.
57 |
58 | /***************************************************************************************************
59 | * APPLICATION IMPORTS
60 | */
61 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "baseUrl": "./",
6 | "module": "es2015",
7 | "types": []
8 | },
9 | "exclude": [
10 | "test.ts",
11 | "**/*.spec.ts"
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "baseUrl": "./",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": [
9 | "jasmine",
10 | "node"
11 | ]
12 | },
13 | "files": [
14 | "test.ts",
15 | "polyfills.ts"
16 | ],
17 | "include": [
18 | "**/*.spec.ts",
19 | "**/*.d.ts"
20 | ]
21 | }
22 |
--------------------------------------------------------------------------------
/src/typings.d.ts:
--------------------------------------------------------------------------------
1 | /* SystemJS module definition */
2 | declare var module: NodeModule;
3 | interface NodeModule {
4 | id: string;
5 | }
6 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "importHelpers": true,
5 | "outDir": "./dist/out-tsc",
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 | "es2017",
17 | "dom"
18 | ]
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/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": false,
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-shadowed-variable": true,
69 | "no-string-literal": false,
70 | "no-string-throw": true,
71 | "no-switch-case-fall-through": true,
72 | "no-trailing-whitespace": true,
73 | "no-unnecessary-initializer": true,
74 | "no-unused-expression": true,
75 | "no-use-before-declare": true,
76 | "no-var-keyword": true,
77 | "object-literal-sort-keys": false,
78 | "one-line": [
79 | true,
80 | "check-open-brace",
81 | "check-catch",
82 | "check-else",
83 | "check-whitespace"
84 | ],
85 | "prefer-const": true,
86 | "quotemark": [
87 | true,
88 | "single"
89 | ],
90 | "radix": true,
91 | "semicolon": [
92 | true,
93 | "always"
94 | ],
95 | "triple-equals": [
96 | true,
97 | "allow-null-check"
98 | ],
99 | "typedef-whitespace": [
100 | true,
101 | {
102 | "call-signature": "nospace",
103 | "index-signature": "nospace",
104 | "parameter": "nospace",
105 | "property-declaration": "nospace",
106 | "variable-declaration": "nospace"
107 | }
108 | ],
109 | "unified-signatures": true,
110 | "variable-name": false,
111 | "whitespace": [
112 | true,
113 | "check-branch",
114 | "check-decl",
115 | "check-operator",
116 | "check-separator",
117 | "check-type"
118 | ],
119 | "directive-selector": [
120 | true,
121 | "attribute",
122 | "app",
123 | "camelCase"
124 | ],
125 | "component-selector": [
126 | true,
127 | "element",
128 | "app",
129 | "kebab-case"
130 | ],
131 | "no-output-on-prefix": true,
132 | "use-input-property-decorator": true,
133 | "use-output-property-decorator": true,
134 | "use-host-property-decorator": true,
135 | "no-input-rename": true,
136 | "no-output-rename": true,
137 | "use-life-cycle-interface": true,
138 | "use-pipe-transform-interface": true,
139 | "component-class-suffix": true,
140 | "directive-class-suffix": true
141 | }
142 | }
143 |
--------------------------------------------------------------------------------