├── src
├── assets
│ ├── .gitkeep
│ ├── .npmignore
│ └── icons
│ │ ├── icon-128x128.png
│ │ ├── icon-144x144.png
│ │ ├── icon-152x152.png
│ │ ├── icon-192x192.png
│ │ ├── icon-384x384.png
│ │ ├── icon-512x512.png
│ │ ├── icon-72x72.png
│ │ └── icon-96x96.png
├── app
│ ├── core
│ │ ├── interceptors
│ │ │ ├── index.ts
│ │ │ └── http.token.interceptor.ts
│ │ ├── models
│ │ │ ├── errors.model.ts
│ │ │ ├── profile.model.ts
│ │ │ ├── user.model.ts
│ │ │ ├── comment.model.ts
│ │ │ ├── index.ts
│ │ │ ├── article-list-config.model.ts
│ │ │ └── article.model.ts
│ │ ├── index.ts
│ │ ├── services
│ │ │ ├── index.ts
│ │ │ ├── jwt.service.ts
│ │ │ ├── tags.service.ts
│ │ │ ├── auth-guard.service.ts
│ │ │ ├── profiles.service.ts
│ │ │ ├── comments.service.ts
│ │ │ ├── api.service.ts
│ │ │ ├── articles.service.ts
│ │ │ └── user.service.ts
│ │ └── core.module.ts
│ ├── index.ts
│ ├── shared
│ │ ├── article-helpers
│ │ │ ├── article-list.component.css
│ │ │ ├── index.ts
│ │ │ ├── article-meta.component.ts
│ │ │ ├── article-meta.component.html
│ │ │ ├── article-preview.component.ts
│ │ │ ├── article-preview.component.html
│ │ │ ├── article-list.component.html
│ │ │ └── article-list.component.ts
│ │ ├── layout
│ │ │ ├── index.ts
│ │ │ ├── footer.component.ts
│ │ │ ├── footer.component.html
│ │ │ ├── header.component.ts
│ │ │ └── header.component.html
│ │ ├── buttons
│ │ │ ├── index.ts
│ │ │ ├── favorite-button.component.html
│ │ │ ├── follow-button.component.html
│ │ │ ├── favorite-button.component.ts
│ │ │ └── follow-button.component.ts
│ │ ├── list-errors.component.html
│ │ ├── index.ts
│ │ ├── list-errors.component.ts
│ │ ├── show-authed.directive.ts
│ │ └── shared.module.ts
│ ├── home
│ │ ├── home.component.css
│ │ ├── home.module.ts
│ │ ├── home-routing.module.ts
│ │ ├── home-auth-resolver.service.ts
│ │ ├── home.component.ts
│ │ └── home.component.html
│ ├── profile
│ │ ├── profile-articles.component.html
│ │ ├── profile-favorites.component.html
│ │ ├── profile.module.ts
│ │ ├── profile-resolver.service.ts
│ │ ├── profile-routing.module.ts
│ │ ├── profile-favorites.component.ts
│ │ ├── profile-articles.component.ts
│ │ ├── profile.component.ts
│ │ └── profile.component.html
│ ├── app.component.html
│ ├── article
│ │ ├── markdown.pipe.ts
│ │ ├── article-routing.module.ts
│ │ ├── article.module.ts
│ │ ├── article-comment.component.html
│ │ ├── article-resolver.service.ts
│ │ ├── article-comment.component.ts
│ │ ├── article.component.ts
│ │ └── article.component.html
│ ├── editor
│ │ ├── editor.module.ts
│ │ ├── editor-routing.module.ts
│ │ ├── editable-article-resolver.service.ts
│ │ ├── editor.component.html
│ │ └── editor.component.ts
│ ├── settings
│ │ ├── settings.module.ts
│ │ ├── settings-routing.module.ts
│ │ ├── settings.component.ts
│ │ └── settings.component.html
│ ├── app.component.ts
│ ├── auth
│ │ ├── auth.module.ts
│ │ ├── auth-routing.module.ts
│ │ ├── no-auth-guard.service.ts
│ │ ├── auth.component.html
│ │ └── auth.component.ts
│ ├── app.module.ts
│ └── app-routing.module.ts
├── styles.css
├── favicon.ico
├── typings.d.ts
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── tsconfig.app.json
├── tsconfig.spec.json
├── main.ts
├── index.html
├── test.ts
├── manifest.webmanifest
└── polyfills.ts
├── CNAME
├── logo.png
├── e2e
├── app.po.ts
├── tsconfig.e2e.json
└── app.e2e-spec.ts
├── .editorconfig
├── .travis.yml
├── tsconfig.json
├── ngsw-config.json
├── .gitignore
├── protractor.conf.js
├── LICENSE.txt
├── karma.conf.js
├── .eslintrc.json
├── package.json
├── angular.json
└── README.md
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/.npmignore:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/CNAME:
--------------------------------------------------------------------------------
1 | angular.realworld.io
2 |
--------------------------------------------------------------------------------
/src/app/core/interceptors/index.ts:
--------------------------------------------------------------------------------
1 | export * from './http.token.interceptor';
2 |
--------------------------------------------------------------------------------
/src/app/index.ts:
--------------------------------------------------------------------------------
1 | export * from './app.component';
2 | export * from './app.module';
3 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/logo.png
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-list.component.css:
--------------------------------------------------------------------------------
1 | .page-link {
2 | cursor: pointer;
3 | }
4 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/favicon.ico
--------------------------------------------------------------------------------
/src/app/core/models/errors.model.ts:
--------------------------------------------------------------------------------
1 | export interface Errors {
2 | errors: {[key: string]: string};
3 | }
4 |
--------------------------------------------------------------------------------
/src/app/shared/layout/index.ts:
--------------------------------------------------------------------------------
1 | export * from './footer.component';
2 | export * from './header.component';
3 |
--------------------------------------------------------------------------------
/src/app/home/home.component.css:
--------------------------------------------------------------------------------
1 | .nav-link {
2 | cursor:pointer;
3 | }
4 |
5 | .tag-pill{
6 | cursor:pointer;
7 | }
8 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/index.ts:
--------------------------------------------------------------------------------
1 | export * from './favorite-button.component';
2 | export * from './follow-button.component';
3 |
--------------------------------------------------------------------------------
/src/app/profile/profile-articles.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/app/profile/profile-favorites.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/assets/icons/icon-128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/assets/icons/icon-128x128.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/assets/icons/icon-144x144.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/assets/icons/icon-152x152.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/assets/icons/icon-192x192.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-384x384.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/assets/icons/icon-384x384.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/assets/icons/icon-512x512.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/assets/icons/icon-72x72.png
--------------------------------------------------------------------------------
/src/assets/icons/icon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khaledosman/angular-realworld-example-app/HEAD/src/assets/icons/icon-96x96.png
--------------------------------------------------------------------------------
/src/typings.d.ts:
--------------------------------------------------------------------------------
1 | /* SystemJS module definition */
2 | declare var module: NodeModule;
3 | interface NodeModule {
4 | id: string;
5 | }
6 |
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true,
3 | api_url: 'https://api.realworld.io/api'
4 | };
5 |
--------------------------------------------------------------------------------
/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/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/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/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/list-errors.component.html:
--------------------------------------------------------------------------------
1 |
2 | -
3 | {{ error }}
4 |
5 |
6 |
--------------------------------------------------------------------------------
/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/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/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 |
--------------------------------------------------------------------------------
/e2e/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, element, by } from 'protractor';
2 |
3 | export class Ng2RealApp {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('.logo-font')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/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/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "baseUrl": "./",
6 | "types": []
7 | },
8 | "files": [
9 | "main.ts",
10 | "polyfills.ts"
11 | ],
12 | "include": [
13 | "src/**/*.d.ts"
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "baseUrl": "./",
6 | "module": "commonjs",
7 | "target": "es2022",
8 | "types": [
9 | "jasmine",
10 | "jasminewd2",
11 | "node"
12 | ]
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/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/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/shared/buttons/favorite-button.component.html:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/app/shared/layout/footer.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, ChangeDetectionStrategy } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-layout-footer',
5 | templateUrl: './footer.component.html',
6 | changeDetection: ChangeDetectionStrategy.OnPush
7 | })
8 | export class FooterComponent {
9 | today: number = Date.now();
10 | }
11 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/e2e/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { Ng2RealApp } from './app.po';
2 |
3 | describe('ng-demo App', () => {
4 | let page: Ng2RealApp;
5 |
6 | beforeEach(() => {
7 | page = new Ng2RealApp();
8 | });
9 |
10 | it('should display message saying app works', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toContain('conduit');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "baseUrl": "./",
6 | "types": [
7 | "jasmine",
8 | "node"
9 | ]
10 | },
11 | "files": [
12 | "test.ts",
13 | "polyfills.ts"
14 | ],
15 | "include": [
16 | "**/*.spec.ts",
17 | "**/*.d.ts"
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/src/app/shared/layout/footer.component.html:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-meta.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
2 |
3 | import { Article } from '../../core';
4 |
5 | @Component({
6 | selector: 'app-article-meta',
7 | templateUrl: './article-meta.component.html',
8 | changeDetection: ChangeDetectionStrategy.OnPush
9 | })
10 | export class ArticleMetaComponent {
11 | @Input() article: Article;
12 | }
13 |
--------------------------------------------------------------------------------
/src/app/editor/editor.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 |
3 |
4 | import { EditorComponent } from './editor.component';
5 |
6 | import { SharedModule } from '../shared';
7 | import { EditorRoutingModule } from './editor-routing.module';
8 |
9 | @NgModule({
10 | imports: [SharedModule, EditorRoutingModule],
11 | declarations: [EditorComponent],
12 | providers: []
13 | })
14 | export class EditorModule {}
15 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/follow-button.component.html:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/src/app/home/home.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 |
3 | import { HomeComponent } from './home.component';
4 | import { SharedModule } from '../shared';
5 | import { HomeRoutingModule } from './home-routing.module';
6 |
7 | @NgModule({
8 | imports: [
9 | SharedModule,
10 | HomeRoutingModule
11 | ],
12 | declarations: [
13 | HomeComponent
14 | ],
15 | providers: [
16 | ]
17 | })
18 | export class HomeModule {}
19 |
--------------------------------------------------------------------------------
/src/app/core/services/jwt.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 |
3 |
4 | @Injectable({
5 | providedIn: 'root'
6 | })
7 | export class JwtService {
8 |
9 | getToken(): String {
10 | return window.localStorage['jwtToken'];
11 | }
12 |
13 | saveToken(token: String) {
14 | window.localStorage['jwtToken'] = token;
15 | }
16 |
17 | destroyToken() {
18 | window.localStorage.removeItem('jwtToken');
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/app/settings/settings.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 |
3 | import { SettingsComponent } from './settings.component';
4 | import { SharedModule } from '../shared';
5 | import { SettingsRoutingModule } from './settings-routing.module';
6 |
7 | @NgModule({
8 | imports: [
9 | SharedModule,
10 | SettingsRoutingModule
11 | ],
12 | declarations: [
13 | SettingsComponent
14 | ]
15 | })
16 | export class SettingsModule {}
17 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
2 |
3 | import { UserService } from "./core";
4 |
5 | @Component({
6 | selector: 'app-root',
7 | templateUrl: './app.component.html',
8 | changeDetection: ChangeDetectionStrategy.OnPush
9 | })
10 | export class AppComponent implements OnInit {
11 | constructor(private userService: UserService) {}
12 |
13 | ngOnInit() {
14 | this.userService.populate();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "12.3.1"
4 |
5 | branches:
6 | only:
7 | - master
8 |
9 | before_script:
10 | - yarn install --frozen-lockfile
11 |
12 | env:
13 | - NG_CLI_ANALYTICS=ci
14 |
15 | script:
16 | - yarn build
17 |
18 | deploy:
19 | provider: pages
20 | skip-cleanup: true
21 | github-token: $GITHUB_TOKEN # Set in travis-ci.org dashboard, marked secure
22 | keep-history: true
23 | on:
24 | branch: master
25 | local_dir: dist
26 |
--------------------------------------------------------------------------------
/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://api.realworld.io/api'
9 | };
10 |
--------------------------------------------------------------------------------
/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 | @NgModule({
7 | imports: [
8 | CommonModule
9 | ],
10 | providers: [
11 | { provide: HTTP_INTERCEPTORS, useClass: HttpTokenInterceptor, multi: true }
12 | ],
13 | declarations: []
14 | })
15 | export class CoreModule { }
16 |
--------------------------------------------------------------------------------
/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 | providedIn: 'root'
9 | })
10 | export class TagsService {
11 | constructor (
12 | private apiService: ApiService
13 | ) {}
14 |
15 | getAll(): Observable<[string]> {
16 | return this.apiService.get('/tags')
17 | .pipe(map(data => data.tags));
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/app/auth/auth.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 |
3 | import { AuthComponent } from './auth.component';
4 | import { NoAuthGuard } from './no-auth-guard.service';
5 | import { SharedModule } from '../shared';
6 | import { AuthRoutingModule } from './auth-routing.module';
7 |
8 | @NgModule({
9 | imports: [
10 | SharedModule,
11 | AuthRoutingModule
12 | ],
13 | declarations: [
14 | AuthComponent
15 | ],
16 | providers: [
17 | NoAuthGuard
18 | ]
19 | })
20 | export class AuthModule {}
21 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "importHelpers": true,
5 | "downlevelIteration": true,
6 | "outDir": "./dist/out-tsc",
7 | "sourceMap": true,
8 | "declaration": false,
9 | "module": "es2020",
10 | "moduleResolution": "node",
11 | "emitDecoratorMetadata": true,
12 | "experimentalDecorators": true,
13 | "target": "es2022",
14 | "typeRoots": [
15 | "node_modules/@types"
16 | ],
17 | "lib": [
18 | "es2018",
19 | "dom"
20 | ]
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/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/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/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/shared/article-helpers/article-meta.component.html:
--------------------------------------------------------------------------------
1 |
18 |
--------------------------------------------------------------------------------
/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/article/article.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 |
3 | import { ArticleComponent } from './article.component';
4 | import { ArticleCommentComponent } from './article-comment.component';
5 | import { MarkdownPipe } from './markdown.pipe';
6 | import { SharedModule } from '../shared';
7 | import { ArticleRoutingModule } from './article-routing.module';
8 |
9 | @NgModule({
10 | imports: [
11 | SharedModule,
12 | ArticleRoutingModule
13 | ],
14 | declarations: [
15 | ArticleComponent,
16 | ArticleCommentComponent,
17 | MarkdownPipe
18 | ],
19 |
20 | providers: [
21 | ]
22 | })
23 | export class ArticleModule {}
24 |
--------------------------------------------------------------------------------
/src/app/profile/profile.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 |
3 | import { ProfileArticlesComponent } from './profile-articles.component';
4 | import { ProfileComponent } from './profile.component';
5 | import { ProfileFavoritesComponent } from './profile-favorites.component';
6 | import { SharedModule } from '../shared';
7 | import { ProfileRoutingModule } from './profile-routing.module';
8 |
9 | @NgModule({
10 | imports: [
11 | SharedModule,
12 | ProfileRoutingModule
13 | ],
14 | declarations: [
15 | ProfileArticlesComponent,
16 | ProfileComponent,
17 | ProfileFavoritesComponent
18 | ],
19 | providers: [
20 | ]
21 | })
22 | export class ProfileModule {}
23 |
--------------------------------------------------------------------------------
/src/app/shared/list-errors.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
2 |
3 | import { Errors } from '../core';
4 |
5 | @Component({
6 | selector: 'app-list-errors',
7 | templateUrl: './list-errors.component.html',
8 | changeDetection: ChangeDetectionStrategy.OnPush
9 | })
10 | export class ListErrorsComponent {
11 | formattedErrors: Array = [];
12 |
13 | @Input()
14 | set errors(errorList: Errors) {
15 | this.formattedErrors = Object.keys(errorList.errors || {})
16 | .map(key => `${key} ${errorList.errors[key]}`);
17 | }
18 |
19 | get errorList() { return this.formattedErrors; }
20 |
21 | trackByFn(index, item) {
22 | return index;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/ngsw-config.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/service-worker/config/schema.json",
3 | "index": "/index.html",
4 | "assetGroups": [
5 | {
6 | "name": "app",
7 | "installMode": "prefetch",
8 | "resources": {
9 | "files": [
10 | "/favicon.ico",
11 | "/index.html",
12 | "/*.css",
13 | "/*.js",
14 | "/manifest.webmanifest"
15 | ]
16 | }
17 | }, {
18 | "name": "assets",
19 | "installMode": "lazy",
20 | "updateMode": "prefetch",
21 | "resources": {
22 | "files": [
23 | "/assets/**",
24 | "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
25 | ]
26 | }
27 | }
28 | ]
29 | }
30 |
--------------------------------------------------------------------------------
/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 | providedIn: 'root'
10 | })
11 | export class HomeAuthResolver implements Resolve {
12 | constructor(
13 | private router: Router,
14 | private userService: UserService
15 | ) {}
16 |
17 | resolve(
18 | route: ActivatedRouteSnapshot,
19 | state: RouterStateSnapshot
20 | ): Observable {
21 |
22 | return this.userService.isAuthenticated.pipe(take(1));
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/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 | providedIn: 'root'
10 | })
11 | export class AuthGuard implements CanActivate {
12 | constructor(
13 | private router: Router,
14 | private userService: UserService
15 | ) {}
16 |
17 | canActivate(
18 | route: ActivatedRouteSnapshot,
19 | state: RouterStateSnapshot
20 | ): Observable {
21 |
22 | return this.userService.isAuthenticated.pipe(take(1));
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-preview.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
2 |
3 | import { Article } from '../../core';
4 |
5 | @Component({
6 | selector: 'app-article-preview',
7 | templateUrl: './article-preview.component.html',
8 | changeDetection: ChangeDetectionStrategy.OnPush
9 | })
10 | export class ArticlePreviewComponent {
11 | @Input() article: Article;
12 |
13 | trackByFn(index, item) {
14 | return index;
15 | }
16 |
17 | onToggleFavorite(favorited: boolean) {
18 | this.article['favorited'] = favorited;
19 |
20 | if (favorited) {
21 | this.article['favoritesCount']++;
22 | } else {
23 | this.article['favoritesCount']--;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.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 | /.angular/cache
30 | /.sass-cache
31 | /connect.lock
32 | /coverage
33 | /libpeerconnection.log
34 | npm-debug.log
35 | testem.log
36 | /typings
37 | yarn-error.log
38 |
39 | # e2e
40 | /e2e/*.js
41 | /e2e/*.map
42 |
43 | # System Files
44 | .DS_Store
45 | Thumbs.db
46 |
--------------------------------------------------------------------------------
/src/app/shared/layout/header.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
2 |
3 | import { User, UserService } from '../../core';
4 |
5 | @Component({
6 | selector: 'app-layout-header',
7 | templateUrl: './header.component.html',
8 | changeDetection: ChangeDetectionStrategy.OnPush
9 | })
10 | export class HeaderComponent implements OnInit {
11 | constructor(
12 | private userService: UserService,
13 | private cd: ChangeDetectorRef
14 | ) {}
15 |
16 | currentUser: User;
17 |
18 | ngOnInit() {
19 | this.userService.currentUser.subscribe(
20 | (userData) => {
21 | this.currentUser = userData;
22 | this.cd.markForCheck();
23 | }
24 | );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-preview.component.html:
--------------------------------------------------------------------------------
1 |
23 |
--------------------------------------------------------------------------------
/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/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/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 | providedIn: 'root'
10 | })
11 | export class ProfileResolver implements Resolve {
12 | constructor(
13 | private profilesService: ProfilesService,
14 | private router: Router
15 | ) {}
16 |
17 | resolve(
18 | route: ActivatedRouteSnapshot,
19 | state: RouterStateSnapshot
20 | ): Observable {
21 |
22 | return this.profilesService.get(route.params['username'])
23 | .pipe(catchError((err) => this.router.navigateByUrl('/')));
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/src/app/article/article-comment.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{ comment.body }}
5 |
6 |
7 |
22 |
23 |
--------------------------------------------------------------------------------
/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 | providedIn: 'root'
10 | })
11 | export class ArticleResolver implements Resolve {
12 | constructor(
13 | private articlesService: ArticlesService,
14 | private router: Router,
15 | private userService: UserService
16 | ) {}
17 |
18 | resolve(
19 | route: ActivatedRouteSnapshot,
20 | state: RouterStateSnapshot
21 | ): Observable {
22 |
23 | return this.articlesService.get(route.params['slug'])
24 | .pipe(catchError((err) => this.router.navigateByUrl('/')));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/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 | providedIn: 'root'
10 | })
11 | export class ProfilesService {
12 | constructor (
13 | private apiService: ApiService
14 | ) {}
15 |
16 | get(username: string): Observable {
17 | return this.apiService.get('/profiles/' + username)
18 | .pipe(map((data: {profile: Profile}) => data.profile));
19 | }
20 |
21 | follow(username: string): Observable {
22 | return this.apiService.post('/profiles/' + username + '/follow');
23 | }
24 |
25 | unfollow(username: string): Observable {
26 | return this.apiService.delete('/profiles/' + username + '/follow');
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/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/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Conduit
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | Loading...
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 | providedIn: 'root'
11 | })
12 | export class CommentsService {
13 | constructor (
14 | private apiService: ApiService
15 | ) {}
16 |
17 | add(slug, payload): Observable {
18 | return this.apiService
19 | .post(
20 | `/articles/${slug}/comments`,
21 | { comment: { body: payload } }
22 | ).pipe(map(data => data.comment));
23 | }
24 |
25 | getAll(slug): Observable {
26 | return this.apiService.get(`/articles/${slug}/comments`)
27 | .pipe(map(data => data.comments));
28 | }
29 |
30 | destroy(commentId, articleSlug) {
31 | return this.apiService
32 | .delete(`/articles/${articleSlug}/comments/${commentId}`);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/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/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/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 | import { ServiceWorkerModule } from '@angular/service-worker';
15 | import { environment } from '../environments/environment';
16 |
17 | @NgModule({
18 | declarations: [AppComponent, FooterComponent, HeaderComponent],
19 | imports: [
20 | BrowserModule,
21 | CoreModule,
22 | SharedModule,
23 | HomeModule,
24 | AuthModule,
25 | AppRoutingModule,
26 | ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
27 | ],
28 | providers: [],
29 | bootstrap: [AppComponent]
30 | })
31 | export class AppModule {}
32 |
--------------------------------------------------------------------------------
/src/app/profile/profile-favorites.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
10 | })
11 | export class ProfileFavoritesComponent implements OnInit {
12 | constructor(
13 | private route: ActivatedRoute,
14 | private cd: ChangeDetectorRef
15 | ) {}
16 |
17 | profile: Profile;
18 | favoritesConfig: ArticleListConfig = {
19 | type: 'all',
20 | filters: {}
21 | };
22 |
23 | ngOnInit() {
24 | this.route.parent.data.subscribe(
25 | (data: {profile: Profile}) => {
26 | this.profile = data.profile;
27 | this.favoritesConfig = {...this.favoritesConfig};
28 | this.favoritesConfig.filters.favorited = this.profile.username;
29 | this.cd.markForCheck();
30 | }
31 | );
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) [2022] [Khaled Osman]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { QuicklinkModule, QuicklinkStrategy } from 'ngx-quicklink';
4 |
5 | const routes: Routes = [
6 | {
7 | path: 'settings',
8 | loadChildren: () => import('./settings/settings.module').then(m => m.SettingsModule)
9 | },
10 | {
11 | path: 'profile',
12 | loadChildren: () => import('./profile/profile.module').then(m => m.ProfileModule)
13 | },
14 | {
15 | path: 'editor',
16 | loadChildren: () => import('./editor/editor.module').then(m => m.EditorModule)
17 | },
18 | {
19 | path: 'article',
20 | loadChildren: () => import('./article/article.module').then(m => m.ArticleModule)
21 | }
22 | ];
23 |
24 | @NgModule({
25 | imports: [
26 | QuicklinkModule,
27 | RouterModule.forRoot(routes, {
28 | // preload all modules; optionally we could
29 | // implement a custom preloading strategy for just some
30 | // of the modules (PRs welcome 😉)
31 | preloadingStrategy: QuicklinkStrategy,
32 | })],
33 | exports: [RouterModule]
34 | })
35 | export class AppRoutingModule {}
36 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function(config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, 'coverage'), reports: ['html', 'lcovonly'],
20 | fixWebpackSourcePaths: true
21 | },
22 |
23 | reporters:
24 | config.angularCli && config.angularCli.codeCoverage
25 | ? ['progress', 'coverage-istanbul']
26 | : ['progress', 'kjhtml'],
27 | port: 9876,
28 | colors: true,
29 | logLevel: config.LOG_INFO,
30 | autoWatch: true,
31 | browsers: ['Chrome'],
32 | singleRun: false
33 | });
34 | };
35 |
--------------------------------------------------------------------------------
/src/app/profile/profile-articles.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
10 | })
11 | export class ProfileArticlesComponent implements OnInit {
12 | constructor(
13 | private route: ActivatedRoute,
14 | private router: Router,
15 | private cd: ChangeDetectorRef
16 | ) {}
17 |
18 | profile: Profile;
19 | articlesConfig: ArticleListConfig = {
20 | type: 'all',
21 | filters: {}
22 | };
23 |
24 | ngOnInit() {
25 | this.route.parent.data.subscribe(
26 | (data: {profile: Profile}) => {
27 | this.profile = data.profile;
28 | this.articlesConfig = {
29 | type: 'all',
30 | filters: {}
31 | }; // Only method I found to refresh article load on swap
32 | this.articlesConfig.filters.author = this.profile.username;
33 | this.cd.markForCheck();
34 | }
35 | );
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/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 | providedIn: 'root'
10 | })
11 | export class EditableArticleResolver implements Resolve {
12 | constructor(
13 | private articlesService: ArticlesService,
14 | private router: Router,
15 | private userService: UserService
16 | ) { }
17 |
18 | resolve(
19 | route: ActivatedRouteSnapshot,
20 | state: RouterStateSnapshot
21 | ): Observable {
22 |
23 | return this.articlesService.get(route.params['slug'])
24 | .pipe(
25 | map(
26 | article => {
27 | if (this.userService.getCurrentUser().username === article.author.username) {
28 | return article;
29 | } else {
30 | this.router.navigateByUrl('/');
31 | }
32 | }
33 | ),
34 | catchError((err) => this.router.navigateByUrl('/'))
35 | );
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "ignorePatterns": [
4 | "projects/**/*"
5 | ],
6 | "overrides": [
7 | {
8 | "files": [
9 | "*.ts"
10 | ],
11 | "parserOptions": {
12 | "project": [
13 | "tsconfig.json",
14 | "e2e/tsconfig.json"
15 | ],
16 | "createDefaultProgram": true
17 | },
18 | "extends": [
19 | "plugin:@angular-eslint/recommended",
20 | "plugin:@angular-eslint/template/process-inline-templates"
21 | ],
22 | "rules": {
23 | "@angular-eslint/component-selector": [
24 | "error",
25 | {
26 | "prefix": "app",
27 | "style": "kebab-case",
28 | "type": "element"
29 | }
30 | ],
31 | "@angular-eslint/directive-selector": [
32 | "error",
33 | {
34 | "prefix": "app",
35 | "style": "camelCase",
36 | "type": "attribute"
37 | }
38 | ]
39 | }
40 | },
41 | {
42 | "files": [
43 | "*.html"
44 | ],
45 | "extends": [
46 | "plugin:@angular-eslint/template/recommended"
47 | ],
48 | "rules": {}
49 | }
50 | ]
51 | }
52 |
--------------------------------------------------------------------------------
/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 | teardown: { destroyAfterEach: false }
27 | }
28 | );
29 | // Then we find all the tests.
30 | const context = require.context('./', true, /\.spec\.ts$/);
31 | // And load the modules.
32 | context.keys().map(context);
33 | // Finally, start Karma to run the tests.
34 | __karma__.start();
35 |
--------------------------------------------------------------------------------
/src/app/article/article-comment.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, Output, OnInit, OnDestroy, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
10 | })
11 | export class ArticleCommentComponent implements OnInit, OnDestroy {
12 | constructor(
13 | private userService: UserService,
14 | private cd: ChangeDetectorRef
15 | ) {}
16 |
17 | private subscription: Subscription;
18 |
19 | @Input() comment: Comment;
20 | @Output() deleteComment = new EventEmitter();
21 |
22 | canModify: boolean;
23 |
24 | ngOnInit() {
25 | // Load the current user's data
26 | this.subscription = this.userService.currentUser.subscribe(
27 | (userData: User) => {
28 | this.canModify = (userData.username === this.comment.author.username);
29 | this.cd.markForCheck();
30 | }
31 | );
32 | }
33 |
34 | ngOnDestroy() {
35 | this.subscription.unsubscribe();
36 | }
37 |
38 | deleteClicked() {
39 | this.deleteComment.emit(true);
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/manifest.webmanifest:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ang2-conduit",
3 | "short_name": "ang2-conduit",
4 | "theme_color": "#1976d2",
5 | "background_color": "#fafafa",
6 | "display": "standalone",
7 | "scope": "/",
8 | "start_url": "/",
9 | "icons": [
10 | {
11 | "src": "assets/icons/icon-72x72.png",
12 | "sizes": "72x72",
13 | "type": "image/png"
14 | },
15 | {
16 | "src": "assets/icons/icon-96x96.png",
17 | "sizes": "96x96",
18 | "type": "image/png"
19 | },
20 | {
21 | "src": "assets/icons/icon-128x128.png",
22 | "sizes": "128x128",
23 | "type": "image/png"
24 | },
25 | {
26 | "src": "assets/icons/icon-144x144.png",
27 | "sizes": "144x144",
28 | "type": "image/png"
29 | },
30 | {
31 | "src": "assets/icons/icon-152x152.png",
32 | "sizes": "152x152",
33 | "type": "image/png"
34 | },
35 | {
36 | "src": "assets/icons/icon-192x192.png",
37 | "sizes": "192x192",
38 | "type": "image/png"
39 | },
40 | {
41 | "src": "assets/icons/icon-384x384.png",
42 | "sizes": "384x384",
43 | "type": "image/png"
44 | },
45 | {
46 | "src": "assets/icons/icon-512x512.png",
47 | "sizes": "512x512",
48 | "type": "image/png"
49 | }
50 | ]
51 | }
--------------------------------------------------------------------------------
/src/app/profile/profile.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
11 | })
12 | export class ProfileComponent implements OnInit {
13 | constructor(
14 | private route: ActivatedRoute,
15 | private userService: UserService,
16 | private cd: ChangeDetectorRef
17 | ) { }
18 |
19 | profile: Profile;
20 | currentUser: User;
21 | isUser: boolean;
22 |
23 | ngOnInit() {
24 | this.route.data.pipe(
25 | concatMap((data: { profile: Profile }) => {
26 | this.profile = data.profile;
27 | // Load the current user's data.
28 | return this.userService.currentUser.pipe(tap(
29 | (userData: User) => {
30 | this.currentUser = userData;
31 | this.isUser = (this.currentUser.username === this.profile.username);
32 | }
33 | ));
34 | })
35 | ).subscribe((() => {
36 | this.cd.markForCheck();
37 | }));
38 | }
39 |
40 | onToggleFollowing(following: boolean) {
41 | this.profile.following = following;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/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 { catchError } from 'rxjs/operators';
7 |
8 | @Injectable({
9 | providedIn: 'root'
10 | })
11 | export class ApiService {
12 | constructor(
13 | private http: HttpClient
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/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/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/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE10 and IE11 requires the following for the Reflect API. */
22 | // import 'core-js/es6/reflect';
23 |
24 | /** Evergreen browsers require these. **/
25 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
26 | // import 'core-js/es7/reflect';
27 |
28 | /***************************************************************************************************
29 | * Zone JS is required by default for Angular itself.
30 | */
31 | import 'zone.js'; // Included with Angular CLI.
32 |
33 | /***************************************************************************************************
34 | * APPLICATION IMPORTS
35 | */
36 |
--------------------------------------------------------------------------------
/src/app/auth/auth.component.html:
--------------------------------------------------------------------------------
1 |
46 |
--------------------------------------------------------------------------------
/src/app/shared/article-helpers/article-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, ChangeDetectorRef, ChangeDetectionStrategy } 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 | changeDetection: ChangeDetectionStrategy.OnPush
9 | })
10 | export class ArticleListComponent {
11 | constructor (
12 | private articlesService: ArticlesService,
13 | private cd: ChangeDetectorRef
14 | ) {}
15 |
16 | @Input() limit: number;
17 | @Input()
18 | set config(config: ArticleListConfig) {
19 | if (config) {
20 | this.query = config;
21 | this.currentPage = 1;
22 | this.runQuery();
23 | }
24 | }
25 |
26 | query: ArticleListConfig;
27 | results: Article[];
28 | loading = false;
29 | currentPage = 1;
30 | totalPages: Array = [1];
31 |
32 | setPageTo(pageNumber) {
33 | this.currentPage = pageNumber;
34 | this.runQuery();
35 | }
36 |
37 | trackByFn(index, item) {
38 | return index;
39 | }
40 |
41 | runQuery() {
42 | this.loading = true;
43 | this.results = [];
44 |
45 | // Create limit and offset filter (if necessary)
46 | if (this.limit) {
47 | this.query.filters.limit = this.limit;
48 | this.query.filters.offset = (this.limit * (this.currentPage - 1));
49 | }
50 |
51 | this.articlesService.query(this.query)
52 | .subscribe(data => {
53 | this.loading = false;
54 | this.results = data.articles;
55 |
56 | // Used from http://www.jstips.co/en/create-range-0...n-easily-using-one-line/
57 | this.totalPages = Array.from(new Array(Math.ceil(data.articlesCount / this.limit)), (val, index) => index + 1);
58 | this.cd.markForCheck();
59 | });
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/app/home/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
11 | })
12 | export class HomeComponent implements OnInit {
13 | constructor(
14 | private router: Router,
15 | private tagsService: TagsService,
16 | private userService: UserService,
17 | private cd: ChangeDetectorRef
18 | ) {}
19 |
20 | isAuthenticated: boolean;
21 | listConfig: ArticleListConfig = {
22 | type: 'all',
23 | filters: {}
24 | };
25 | tags: Array = [];
26 | tagsLoaded = false;
27 |
28 | ngOnInit() {
29 | this.userService.isAuthenticated.subscribe(
30 | (authenticated) => {
31 | this.isAuthenticated = authenticated;
32 |
33 | // set the article list accordingly
34 | if (authenticated) {
35 | this.setListTo('feed');
36 | } else {
37 | this.setListTo('all');
38 | }
39 | this.cd.markForCheck();
40 | }
41 | );
42 |
43 | this.tagsService.getAll()
44 | .subscribe(tags => {
45 | this.tags = tags;
46 | this.tagsLoaded = true;
47 | this.cd.markForCheck();
48 | });
49 | }
50 |
51 | trackByFn(index, item) {
52 | return index;
53 | }
54 |
55 | setListTo(type: string = '', filters: Object = {}) {
56 | // If feed is requested but user is not authenticated, redirect to login
57 | if (type === 'feed' && !this.isAuthenticated) {
58 | this.router.navigateByUrl('/login');
59 | return;
60 | }
61 |
62 | // Otherwise, set the list object
63 | this.listConfig = {type: type, filters: filters};
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/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 | providedIn: 'root'
11 | })
12 | export class ArticlesService {
13 | constructor (
14 | private apiService: ApiService
15 | ) {}
16 |
17 | query(config: ArticleListConfig): Observable<{articles: Article[], articlesCount: number}> {
18 | // Convert any filters over to Angular's URLSearchParams
19 | const params = {};
20 |
21 | Object.keys(config.filters)
22 | .forEach((key) => {
23 | params[key] = config.filters[key];
24 | });
25 |
26 | return this.apiService
27 | .get(
28 | '/articles' + ((config.type === 'feed') ? '/feed' : ''),
29 | new HttpParams({ fromObject: params })
30 | );
31 | }
32 |
33 | get(slug): Observable {
34 | return this.apiService.get('/articles/' + slug)
35 | .pipe(map(data => data.article));
36 | }
37 |
38 | destroy(slug) {
39 | return this.apiService.delete('/articles/' + slug);
40 | }
41 |
42 | save(article): Observable {
43 | // If we're updating an existing article
44 | if (article.slug) {
45 | return this.apiService.put('/articles/' + article.slug, {article: article})
46 | .pipe(map(data => data.article));
47 |
48 | // Otherwise, create a new article
49 | } else {
50 | return this.apiService.post('/articles/', {article: article})
51 | .pipe(map(data => data.article));
52 | }
53 | }
54 |
55 | favorite(slug): Observable {
56 | return this.apiService.post('/articles/' + slug + '/favorite');
57 | }
58 |
59 | unfavorite(slug): Observable {
60 | return this.apiService.delete('/articles/' + slug + '/favorite');
61 | }
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/app/profile/profile.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
26 |
27 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/src/app/editor/editor.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/app/settings/settings.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
11 | })
12 | export class SettingsComponent implements OnInit {
13 | user: User = {} as User;
14 | settingsForm: FormGroup;
15 | errors: Object = {};
16 | isSubmitting = false;
17 |
18 | constructor(
19 | private router: Router,
20 | private userService: UserService,
21 | private fb: FormBuilder,
22 | private cd: ChangeDetectorRef
23 | ) {
24 | // create form group using the form builder
25 | this.settingsForm = this.fb.group({
26 | image: '',
27 | username: '',
28 | bio: '',
29 | email: '',
30 | password: ''
31 | });
32 | // Optional: subscribe to changes on the form
33 | // this.settingsForm.valueChanges.subscribe(values => this.updateUser(values));
34 | }
35 |
36 | ngOnInit() {
37 | // Make a fresh copy of the current user's object to place in editable form fields
38 | Object.assign(this.user, this.userService.getCurrentUser());
39 | // Fill the form
40 | this.settingsForm.patchValue(this.user);
41 | }
42 |
43 | logout() {
44 | this.userService.purgeAuth();
45 | this.router.navigateByUrl('/');
46 | }
47 |
48 | submitForm() {
49 | this.isSubmitting = true;
50 |
51 | // update the model
52 | this.updateUser(this.settingsForm.value);
53 |
54 | this.userService
55 | .update(this.user)
56 | .subscribe(
57 | updatedUser => this.router.navigateByUrl('/profile/' + updatedUser.username),
58 | err => {
59 | this.errors = err;
60 | this.isSubmitting = false;
61 | this.cd.markForCheck();
62 | }
63 | );
64 | }
65 |
66 | updateUser(values: Object) {
67 | Object.assign(this.user, values);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/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/auth/auth.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
11 | })
12 | export class AuthComponent implements OnInit {
13 | authType: String = '';
14 | title: String = '';
15 | errors: Errors = {errors: {}};
16 | isSubmitting = false;
17 | authForm: FormGroup;
18 |
19 | constructor(
20 | private route: ActivatedRoute,
21 | private router: Router,
22 | private userService: UserService,
23 | private fb: FormBuilder,
24 | private cd: ChangeDetectorRef
25 | ) {
26 | // use FormBuilder to create a form group
27 | this.authForm = this.fb.group({
28 | 'email': ['', Validators.required],
29 | 'password': ['', Validators.required]
30 | });
31 | }
32 |
33 | ngOnInit() {
34 | this.route.url.subscribe(data => {
35 | // Get the last piece of the URL (it's either 'login' or 'register')
36 | this.authType = data[data.length - 1].path;
37 | // Set a title for the page accordingly
38 | this.title = (this.authType === 'login') ? 'Sign in' : 'Sign up';
39 | // add form control for username if this is the register page
40 | if (this.authType === 'register') {
41 | this.authForm.addControl('username', new FormControl());
42 | }
43 | this.cd.markForCheck();
44 | });
45 | }
46 |
47 | submitForm() {
48 | this.isSubmitting = true;
49 | this.errors = {errors: {}};
50 |
51 | const credentials = this.authForm.value;
52 | this.userService
53 | .attemptAuth(this.authType, credentials)
54 | .subscribe(
55 | data => this.router.navigateByUrl('/'),
56 | err => {
57 | this.errors = err;
58 | this.isSubmitting = false;
59 | this.cd.markForCheck();
60 | }
61 | );
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/favorite-button.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, Output, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
12 | })
13 | export class FavoriteButtonComponent {
14 | constructor(
15 | private articlesService: ArticlesService,
16 | private router: Router,
17 | private userService: UserService,
18 | private cd: ChangeDetectorRef
19 | ) {}
20 |
21 | @Input() article: Article;
22 | @Output() toggle = new EventEmitter();
23 | isSubmitting = false;
24 |
25 | toggleFavorite() {
26 | this.isSubmitting = true;
27 |
28 | this.userService.isAuthenticated.pipe(concatMap(
29 | (authenticated) => {
30 | // Not authenticated? Push to login screen
31 | if (!authenticated) {
32 | this.router.navigateByUrl('/login');
33 | return of(null);
34 | }
35 |
36 | // Favorite the article if it isn't favorited yet
37 | if (!this.article.favorited) {
38 | return this.articlesService.favorite(this.article.slug)
39 | .pipe(tap(
40 | data => {
41 | this.isSubmitting = false;
42 | this.toggle.emit(true);
43 | },
44 | err => this.isSubmitting = false
45 | ));
46 |
47 | // Otherwise, unfavorite the article
48 | } else {
49 | return this.articlesService.unfavorite(this.article.slug)
50 | .pipe(tap(
51 | data => {
52 | this.isSubmitting = false;
53 | this.toggle.emit(false);
54 | },
55 | err => this.isSubmitting = false
56 | ));
57 | }
58 |
59 | }
60 | )).subscribe(() => {
61 | this.cd.markForCheck();
62 | });
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/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 | "build": "ng build --configuration production --base-href ./ && cp CNAME dist/CNAME",
9 | "test": "ng test",
10 | "lint": "ng lint --force",
11 | "e2e": "ng e2e"
12 | },
13 | "pre-commit": [
14 | "lint"
15 | ],
16 | "private": true,
17 | "dependencies": {
18 | "@angular/animations": "16.0.1",
19 | "@angular/common": "16.0.1",
20 | "@angular/compiler": "16.0.1",
21 | "@angular/core": "16.0.1",
22 | "@angular/forms": "16.0.1",
23 | "@angular/platform-browser": "16.0.1",
24 | "@angular/platform-browser-dynamic": "16.0.1",
25 | "@angular/router": "16.0.1",
26 | "@angular/service-worker": "16.0.1",
27 | "core-js": "^3.30.2",
28 | "marked": "^5.0.2",
29 | "ngx-quicklink": "^0.4.2",
30 | "rxjs": "^7.8.1",
31 | "tslib": "^2.5.0",
32 | "zone.js": "~0.13.0"
33 | },
34 | "devDependencies": {
35 | "@angular-devkit/build-angular": "~16.0.1",
36 | "@angular-eslint/builder": "16.0.1",
37 | "@angular-eslint/eslint-plugin": "16.0.1",
38 | "@angular-eslint/eslint-plugin-template": "16.0.1",
39 | "@angular-eslint/schematics": "16.0.1",
40 | "@angular-eslint/template-parser": "16.0.1",
41 | "@angular/cli": "^16.0.1",
42 | "@angular/compiler-cli": "16.0.1",
43 | "@angular/language-service": "16.0.1",
44 | "@types/jasmine": "~4.3.1",
45 | "@types/jasminewd2": "~2.0.10",
46 | "@types/node": "^20.1.4",
47 | "@typescript-eslint/eslint-plugin": "5.59.5",
48 | "@typescript-eslint/parser": "5.59.5",
49 | "eslint": "^8.40.0",
50 | "jasmine-core": "~5.0.0",
51 | "jasmine-spec-reporter": "~7.0.0",
52 | "karma": "~6.4.2",
53 | "karma-chrome-launcher": "~3.2.0",
54 | "karma-cli": "~2.0.0",
55 | "karma-coverage-istanbul-reporter": "~3.0.3",
56 | "karma-jasmine": "~5.1.0",
57 | "karma-jasmine-html-reporter": "^2.0.0",
58 | "pre-commit": "^1.2.2",
59 | "protractor": "~7.0.0",
60 | "ts-node": "~10.9.1",
61 | "typescript": "5.0.4"
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/app/shared/buttons/follow-button.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, Output, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
12 | })
13 | export class FollowButtonComponent {
14 | constructor(
15 | private profilesService: ProfilesService,
16 | private router: Router,
17 | private userService: UserService,
18 | private cd: ChangeDetectorRef
19 | ) {}
20 |
21 | @Input() profile: Profile;
22 | @Output() toggle = new EventEmitter();
23 | isSubmitting = false;
24 |
25 | toggleFollowing() {
26 | this.isSubmitting = true;
27 | // TODO: remove nested subscribes, use mergeMap
28 |
29 | this.userService.isAuthenticated.pipe(concatMap(
30 | (authenticated) => {
31 | // Not authenticated? Push to login screen
32 | if (!authenticated) {
33 | this.router.navigateByUrl('/login');
34 | return of(null);
35 | }
36 |
37 | // Follow this profile if we aren't already
38 | if (!this.profile.following) {
39 | return this.profilesService.follow(this.profile.username)
40 | .pipe(tap(
41 | data => {
42 | this.isSubmitting = false;
43 | this.toggle.emit(true);
44 | },
45 | err => this.isSubmitting = false
46 | ));
47 |
48 | // Otherwise, unfollow this profile
49 | } else {
50 | return this.profilesService.unfollow(this.profile.username)
51 | .pipe(tap(
52 | data => {
53 | this.isSubmitting = false;
54 | this.toggle.emit(false);
55 | },
56 | err => this.isSubmitting = false
57 | ));
58 | }
59 | }
60 | )).subscribe(() => {
61 | this.cd.markForCheck();
62 | });
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/app/shared/layout/header.component.html:
--------------------------------------------------------------------------------
1 |
76 |
--------------------------------------------------------------------------------
/src/app/settings/settings.component.html:
--------------------------------------------------------------------------------
1 |
69 |
--------------------------------------------------------------------------------
/src/app/editor/editor.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
11 | })
12 | export class EditorComponent implements OnInit {
13 | article: Article = {} as Article;
14 | articleForm: FormGroup;
15 | tagField = new FormControl();
16 | errors: Object = {};
17 | isSubmitting = false;
18 |
19 | constructor(
20 | private articlesService: ArticlesService,
21 | private route: ActivatedRoute,
22 | private router: Router,
23 | private fb: FormBuilder,
24 | private cd: ChangeDetectorRef
25 | ) {
26 | // use the FormBuilder to create a form group
27 | this.articleForm = this.fb.group({
28 | title: '',
29 | description: '',
30 | body: ''
31 | });
32 |
33 | // Initialized tagList as empty array
34 | this.article.tagList = [];
35 |
36 | // Optional: subscribe to value changes on the form
37 | // this.articleForm.valueChanges.subscribe(value => this.updateArticle(value));
38 | }
39 |
40 | ngOnInit() {
41 | // If there's an article prefetched, load it
42 | this.route.data.subscribe((data: { article: Article }) => {
43 | if (data.article) {
44 | this.article = data.article;
45 | this.articleForm.patchValue(data.article);
46 | this.cd.markForCheck();
47 | }
48 | });
49 | }
50 |
51 | trackByFn(index, item) {
52 | return index;
53 | }
54 |
55 | addTag() {
56 | // retrieve tag control
57 | const tag = this.tagField.value;
58 | // only add tag if it does not exist yet
59 | if (this.article.tagList.indexOf(tag) < 0) {
60 | this.article.tagList.push(tag);
61 | }
62 | // clear the input
63 | this.tagField.reset('');
64 | }
65 |
66 | removeTag(tagName: string) {
67 | this.article.tagList = this.article.tagList.filter(tag => tag !== tagName);
68 | }
69 |
70 | submitForm() {
71 | this.isSubmitting = true;
72 |
73 | // update the model
74 | this.updateArticle(this.articleForm.value);
75 |
76 | // post the changes
77 | this.articlesService.save(this.article).subscribe(
78 | article => {
79 | this.router.navigateByUrl('/article/' + article.slug);
80 | this.cd.markForCheck();
81 | },
82 | err => {
83 | this.errors = err;
84 | this.isSubmitting = false;
85 | this.cd.markForCheck();
86 | }
87 | );
88 | }
89 |
90 | updateArticle(values: Object) {
91 | Object.assign(this.article, values);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/app/core/services/user.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Observable , BehaviorSubject , ReplaySubject } from 'rxjs';
3 |
4 | import { ApiService } from './api.service';
5 | import { JwtService } from './jwt.service';
6 | import { User } from '../models';
7 | import { map , distinctUntilChanged } from 'rxjs/operators';
8 |
9 |
10 | @Injectable({
11 | providedIn: 'root'
12 | })
13 | export class UserService {
14 | private currentUserSubject = new BehaviorSubject({} as User);
15 | public currentUser = this.currentUserSubject.asObservable().pipe(distinctUntilChanged());
16 |
17 | private isAuthenticatedSubject = new ReplaySubject(1);
18 | public isAuthenticated = this.isAuthenticatedSubject.asObservable();
19 |
20 | constructor (
21 | private apiService: ApiService,
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 | const token = this.jwtService.getToken();
30 | if (token) {
31 | this.apiService.get("/user").subscribe(
32 | (data) => {
33 | return this.setAuth({ ...data.user, token });
34 | },
35 | (err) => this.purgeAuth()
36 | );
37 | } else {
38 | // Remove any potential remnants of previous auth states
39 | this.purgeAuth();
40 | }
41 | }
42 |
43 | setAuth(user: User) {
44 | // Save JWT sent from server in localstorage
45 | this.jwtService.saveToken(user.token);
46 | // Set current user data into observable
47 | this.currentUserSubject.next(user);
48 | // Set isAuthenticated to true
49 | this.isAuthenticatedSubject.next(true);
50 | }
51 |
52 | purgeAuth() {
53 | // Remove JWT from localstorage
54 | this.jwtService.destroyToken();
55 | // Set current user to an empty object
56 | this.currentUserSubject.next({} as User);
57 | // Set auth status to false
58 | this.isAuthenticatedSubject.next(false);
59 | }
60 |
61 | attemptAuth(type, credentials): Observable {
62 | const route = (type === 'login') ? '/login' : '';
63 | return this.apiService.post(`/users${route}`, {user: credentials})
64 | .pipe(map(
65 | data => {
66 | this.setAuth(data.user);
67 | return data;
68 | }
69 | ));
70 | }
71 |
72 | getCurrentUser(): User {
73 | return this.currentUserSubject.value;
74 | }
75 |
76 | // Update the user on the server (email, pass, etc)
77 | update(user): Observable {
78 | return this.apiService
79 | .put('/user', { user })
80 | .pipe(map(data => {
81 | // Update the currentUser observable
82 | this.currentUserSubject.next(data.user);
83 | return data.user;
84 | }));
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/src/app/article/article.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } 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 | changeDetection: ChangeDetectionStrategy.OnPush
18 | })
19 | export class ArticleComponent implements OnInit {
20 | article: Article;
21 | currentUser: User;
22 | canModify: boolean;
23 | comments: Comment[];
24 | commentControl = new FormControl();
25 | commentFormErrors = {};
26 | isSubmitting = false;
27 | isDeleting = false;
28 |
29 | constructor(
30 | private route: ActivatedRoute,
31 | private articlesService: ArticlesService,
32 | private commentsService: CommentsService,
33 | private router: Router,
34 | private userService: UserService,
35 | private cd: ChangeDetectorRef
36 | ) { }
37 |
38 | ngOnInit() {
39 | // Retreive the prefetched article
40 | this.route.data.subscribe(
41 | (data: { article: Article }) => {
42 | this.article = data.article;
43 |
44 | // Load the comments on this article
45 | this.populateComments();
46 | this.cd.markForCheck();
47 | }
48 | );
49 |
50 | // Load the current user's data
51 | this.userService.currentUser.subscribe(
52 | (userData: User) => {
53 | this.currentUser = userData;
54 |
55 | this.canModify = (this.currentUser.username === this.article.author.username);
56 | this.cd.markForCheck();
57 | }
58 | );
59 | }
60 |
61 | onToggleFavorite(favorited: boolean) {
62 | this.article.favorited = favorited;
63 |
64 | if (favorited) {
65 | this.article.favoritesCount++;
66 | } else {
67 | this.article.favoritesCount--;
68 | }
69 | }
70 |
71 | trackByFn(index, item) {
72 | return index;
73 | }
74 |
75 | onToggleFollowing(following: boolean) {
76 | this.article.author.following = following;
77 | }
78 |
79 | deleteArticle() {
80 | this.isDeleting = true;
81 |
82 | this.articlesService.destroy(this.article.slug)
83 | .subscribe(
84 | success => {
85 | this.router.navigateByUrl('/');
86 | }
87 | );
88 | }
89 |
90 | populateComments() {
91 | this.commentsService.getAll(this.article.slug)
92 | .subscribe(comments => {
93 | this.comments = comments;
94 | this.cd.markForCheck();
95 | });
96 | }
97 |
98 | addComment() {
99 | this.isSubmitting = true;
100 | this.commentFormErrors = {};
101 |
102 | const commentBody = this.commentControl.value;
103 | this.commentsService
104 | .add(this.article.slug, commentBody)
105 | .subscribe(
106 | comment => {
107 | this.comments.unshift(comment);
108 | this.commentControl.reset('');
109 | this.isSubmitting = false;
110 | this.cd.markForCheck();
111 | },
112 | errors => {
113 | this.isSubmitting = false;
114 | this.commentFormErrors = errors;
115 | this.cd.markForCheck();
116 | }
117 | );
118 | }
119 |
120 | onDeleteComment(comment) {
121 | this.commentsService.destroy(comment.id, this.article.slug)
122 | .subscribe(
123 | success => {
124 | this.comments = this.comments.filter((item) => item !== comment);
125 | this.cd.markForCheck();
126 | }
127 | );
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | "src/manifest.webmanifest"
23 | ],
24 | "styles": [
25 | "src/styles.css"
26 | ],
27 | "scripts": [],
28 | "namedChunks": true,
29 | "vendorChunk": true,
30 | "extractLicenses": false,
31 | "buildOptimizer": false,
32 | "sourceMap": true,
33 | "optimization": false,
34 | "aot": true
35 | },
36 | "configurations": {
37 | "production": {
38 | "optimization": true,
39 | "outputHashing": "all",
40 | "sourceMap": false,
41 | "extractLicenses": true,
42 | "vendorChunk": false,
43 | "buildOptimizer": true,
44 | "budgets": [
45 | {
46 | "type": "initial",
47 | "maximumWarning": "2mb",
48 | "maximumError": "5mb"
49 | },
50 | {
51 | "type": "anyComponentStyle",
52 | "maximumWarning": "6kb"
53 | }
54 | ],
55 | "fileReplacements": [
56 | {
57 | "replace": "src/environments/environment.ts",
58 | "with": "src/environments/environment.prod.ts"
59 | }
60 | ],
61 | "serviceWorker": true,
62 | "ngswConfigPath": "ngsw-config.json"
63 | }
64 | },
65 | "defaultConfiguration": ""
66 | },
67 | "serve": {
68 | "builder": "@angular-devkit/build-angular:dev-server",
69 | "options": {
70 | "browserTarget": "ang2-conduit:build"
71 | },
72 | "configurations": {
73 | "production": {
74 | "browserTarget": "ang2-conduit:build:production"
75 | }
76 | }
77 | },
78 | "extract-i18n": {
79 | "builder": "@angular-devkit/build-angular:extract-i18n",
80 | "options": {
81 | "browserTarget": "ang2-conduit:build"
82 | }
83 | },
84 | "test": {
85 | "builder": "@angular-devkit/build-angular:karma",
86 | "options": {
87 | "main": "src/test.ts",
88 | "karmaConfig": "./karma.conf.js",
89 | "polyfills": "src/polyfills.ts",
90 | "tsConfig": "src/tsconfig.spec.json",
91 | "scripts": [],
92 | "styles": [
93 | "src/styles.css"
94 | ],
95 | "assets": [
96 | "src/assets",
97 | "src/favicon.ico",
98 | "src/manifest.webmanifest"
99 | ]
100 | }
101 | },
102 | "lint": {
103 | "builder": "@angular-eslint/builder:lint",
104 | "options": {
105 | "lintFilePatterns": [
106 | "src/**/*.ts",
107 | "src/**/*.html"
108 | ]
109 | }
110 | }
111 | }
112 | },
113 | "ang2-conduit-e2e": {
114 | "root": "e2e",
115 | "sourceRoot": "e2e",
116 | "projectType": "application",
117 | "architect": {
118 | "e2e": {
119 | "builder": "@angular-devkit/build-angular:protractor",
120 | "options": {
121 | "protractorConfig": "./protractor.conf.js",
122 | "devServerTarget": "ang2-conduit:serve"
123 | }
124 | }
125 | }
126 | }
127 | },
128 | "defaultProject": "ang2-conduit",
129 | "schematics": {
130 | "@schematics/angular:component": {
131 | "prefix": "app",
132 | "style": "css"
133 | },
134 | "@schematics/angular:directive": {
135 | "prefix": "app"
136 | }
137 | },
138 | "cli": {
139 | "analytics": false,
140 | "defaultCollection": "@angular-eslint/schematics"
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](http://realworld.io)
2 | [](https://app.netlify.com/sites/angular-realworld/deploys)
3 |
4 | # 
5 |
6 | > ### 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.
7 |
8 |
9 |
10 |
11 | ### [Demo](https://angular-realworld.netlify.app/) [RealWorld](https://github.com/gothinkster/realworld)
12 |
13 |
14 |
15 | 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.
16 |
17 | Additionally, there is an Angular 1.5 version of this codebase that you can [fork](https://github.com/gothinkster/angularjs-realworld-example-app) and/or [learn how to recreate](https://thinkster.io/angularjs-es6-tutorial).
18 |
19 |
20 | # How it works
21 |
22 | We're currently working on some docs for the codebase (explaining where functionality is located, how it works, etc) but the codebase should be straightforward to follow as is. We've also released a [step-by-step tutorial w/ screencasts](https://thinkster.io/tutorials/building-real-world-angular-2-apps) that teaches you how to recreate the codebase from scratch.
23 |
24 | ### Making requests to the backend API
25 |
26 | For convenience, we have a live API server running at https://api.realworld.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.
27 |
28 | The source code for the backend server (available for Node, Rails and Django) can be found in the [main RealWorld repo](https://github.com/gothinkster/realworld).
29 |
30 | If you want to change the API URL to a local server, simply edit `src/environments/environment.ts` and change `api_url` to the local server's URL (i.e. `localhost:3000/api`)
31 |
32 |
33 | # Getting started
34 |
35 | Make sure you have the [Angular CLI](https://github.com/angular/angular-cli#installation) installed globally. We use [Yarn](https://yarnpkg.com) to manage the dependencies, so we strongly recommend you to use it. you can install it from [Here](https://yarnpkg.com/en/docs/install), then run `yarn install` to resolve all dependencies (might take a minute).
36 |
37 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
38 |
39 | ### Building the project
40 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
41 |
42 |
43 | ## Functionality overview
44 |
45 | 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
46 |
47 | **General functionality:**
48 |
49 | - Authenticate users via JWT (login/signup pages + logout button on settings page)
50 | - CRU* users (sign up & settings page - no deleting required)
51 | - CRUD Articles
52 | - CR*D Comments on articles (no updating required)
53 | - GET and display paginated lists of articles
54 | - Favorite articles
55 | - Follow other users
56 |
57 | **The general page breakdown looks like this:**
58 |
59 | - Home page (URL: /#/ )
60 | - List of tags
61 | - List of articles pulled from either Feed, Global, or by Tag
62 | - Pagination for list of articles
63 | - Sign in/Sign up pages (URL: /#/login, /#/register )
64 | - Uses JWT (store the token in localStorage)
65 | - Authentication can be easily switched to session/cookie based
66 | - Settings page (URL: /#/settings )
67 | - Editor page to create/edit articles (URL: /#/editor, /#/editor/article-slug-here )
68 | - Article page (URL: /#/article/article-slug-here )
69 | - Delete article button (only shown to article's author)
70 | - Render markdown from server client side
71 | - Comments section at bottom of page
72 | - Delete comment button (only shown to comment's author)
73 | - Profile page (URL: /#/profile/:username, /#/profile/:username/favorites )
74 | - Show basic user info
75 | - List of articles populated from author's created articles or author's favorited articles
76 |
77 |
78 |
79 |
80 | [](https://thinkster.io)
81 |
--------------------------------------------------------------------------------