├── .angular-cli.json ├── .editorconfig ├── .gitignore ├── README.md ├── e2e ├── app.e2e-spec.ts ├── app.po.ts └── tsconfig.e2e.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── protractor.conf.js ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── auth │ │ ├── auth-routing.module.ts │ │ ├── auth.module.ts │ │ ├── auth.service.spec.ts │ │ ├── auth.service.ts │ │ ├── custom-validators.ts │ │ ├── login │ │ │ ├── login.component.html │ │ │ ├── login.component.spec.ts │ │ │ └── login.component.ts │ │ └── register │ │ │ ├── register.component.html │ │ │ ├── register.component.spec.ts │ │ │ └── register.component.ts │ ├── change-password │ │ ├── change-password-routing.module.ts │ │ ├── change-password.component.html │ │ ├── change-password.component.scss │ │ ├── change-password.component.spec.ts │ │ ├── change-password.component.ts │ │ ├── change-password.module.ts │ │ ├── change-password.service.spec.ts │ │ └── change-password.service.ts │ ├── core │ │ ├── core.module.ts │ │ ├── guards │ │ │ ├── authenticated.guard.spec.ts │ │ │ ├── authenticated.guard.ts │ │ │ ├── unauthenticated.guard.spec.ts │ │ │ └── unauthenticated.guard.ts │ │ ├── models │ │ │ ├── index.ts │ │ │ └── user.ts │ │ └── services │ │ │ ├── api.service.spec.ts │ │ │ ├── api.service.ts │ │ │ ├── user.service.spec.ts │ │ │ └── user.service.ts │ ├── home │ │ ├── chats.service.spec.ts │ │ ├── chats.service.ts │ │ ├── components │ │ │ ├── dropdown │ │ │ │ ├── dropdown.component.html │ │ │ │ ├── dropdown.component.scss │ │ │ │ ├── dropdown.component.spec.ts │ │ │ │ └── dropdown.component.ts │ │ │ ├── messages │ │ │ │ ├── messages.component.html │ │ │ │ ├── messages.component.scss │ │ │ │ ├── messages.component.spec.ts │ │ │ │ └── messages.component.ts │ │ │ ├── msg-block │ │ │ │ ├── msg-block.component.html │ │ │ │ ├── msg-block.component.scss │ │ │ │ ├── msg-block.component.spec.ts │ │ │ │ └── msg-block.component.ts │ │ │ ├── sidebar-group │ │ │ │ ├── sidebar-group.component.html │ │ │ │ ├── sidebar-group.component.scss │ │ │ │ ├── sidebar-group.component.spec.ts │ │ │ │ └── sidebar-group.component.ts │ │ │ └── sidebar │ │ │ │ ├── sidebar.component.html │ │ │ │ ├── sidebar.component.scss │ │ │ │ ├── sidebar.component.spec.ts │ │ │ │ └── sidebar.component.ts │ │ ├── home-routing.module.ts │ │ ├── home.component.html │ │ ├── home.component.scss │ │ ├── home.component.spec.ts │ │ ├── home.component.ts │ │ ├── home.module.ts │ │ └── models │ │ │ └── index.ts │ ├── shared │ │ ├── components │ │ │ └── not-found │ │ │ │ ├── not-found.component.html │ │ │ │ ├── not-found.component.scss │ │ │ │ ├── not-found.component.spec.ts │ │ │ │ └── not-found.component.ts │ │ ├── material.module.ts │ │ └── shared.module.ts │ └── utils │ │ └── index.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── sass │ ├── _common.scss │ ├── _material.scss │ ├── _variables.scss │ └── styles.scss ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── typings.d.ts ├── tsconfig.json └── tslint.json /.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "ngslack" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "sass/styles.scss" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json", 40 | "exclude": "**/node_modules/**" 41 | }, 42 | { 43 | "project": "src/tsconfig.spec.json", 44 | "exclude": "**/node_modules/**" 45 | }, 46 | { 47 | "project": "e2e/tsconfig.e2e.json", 48 | "exclude": "**/node_modules/**" 49 | } 50 | ], 51 | "test": { 52 | "karma": { 53 | "config": "./karma.conf.js" 54 | } 55 | }, 56 | "defaults": { 57 | "styleExt": "scss", 58 | "component": { 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /dist-server 6 | /tmp 7 | /out-tsc 8 | 9 | # dependencies 10 | /node_modules 11 | 12 | # IDEs and editors 13 | /.idea 14 | .project 15 | .classpath 16 | .c9/ 17 | *.launch 18 | .settings/ 19 | *.sublime-workspace 20 | 21 | # IDE - VSCode 22 | .vscode/* 23 | !.vscode/settings.json 24 | !.vscode/tasks.json 25 | !.vscode/launch.json 26 | !.vscode/extensions.json 27 | 28 | # misc 29 | /.sass-cache 30 | /connect.lock 31 | /coverage 32 | /libpeerconnection.log 33 | npm-debug.log 34 | yarn-error.log 35 | testem.log 36 | /typings 37 | 38 | # e2e 39 | /e2e/*.js 40 | /e2e/*.map 41 | 42 | # System Files 43 | .DS_Store 44 | Thumbs.db 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular-Slack 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.7.4. 4 | 5 | ## Development server 6 | 7 | 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. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Requirements 14 | 15 | - Node >= 6.9.0 16 | - MongoDB 17 | 18 | ## Install & Run 19 | 20 | ### Frontend 21 | 22 | ``` 23 | git clone ttps://github.com/Big-Silver/Angular-Slack.git 24 | cd Angular-Slack 25 | npm install 26 | npm start 27 | ``` 28 | 29 | ## Demo 30 | 31 | [Angular-Slack](https://angular-slack.herokuapp.com/) 32 | 33 | ## Build 34 | 35 | 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. 36 | 37 | ## Running unit tests 38 | 39 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 40 | 41 | ## Running end-to-end tests 42 | 43 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 44 | 45 | ## Further help 46 | 47 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 48 | -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('ngslack App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /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/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | angularCli: { 23 | environment: 'dev' 24 | }, 25 | reporters: ['progress', 'kjhtml'], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ['Chrome'], 31 | singleRun: false 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-slack", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build --prod", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "postinstall": "ng build --aot -prod" 13 | }, 14 | "private": true, 15 | "dependencies": { 16 | "@angular/animations": "^5.2.0", 17 | "@angular/cdk": "^5.2.4", 18 | "@angular/cli": "~1.7.4", 19 | "@angular/common": "^5.2.0", 20 | "@angular/compiler": "^5.2.0", 21 | "@angular/compiler-cli": "^5.2.0", 22 | "@angular/core": "^5.2.0", 23 | "@angular/forms": "^5.2.0", 24 | "@angular/http": "^5.2.0", 25 | "@angular/material": "^5.2.4", 26 | "@angular/platform-browser": "^5.2.0", 27 | "@angular/platform-browser-dynamic": "^5.2.0", 28 | "@angular/router": "^5.2.0", 29 | "core-js": "^2.4.1", 30 | "express": "^4.16.3", 31 | "hammerjs": "^2.0.8", 32 | "ionicons": "^3.0.0", 33 | "lodash": "^4.17.5", 34 | "ng2-password-strength-bar": "^1.2.0", 35 | "ngx-textarea-autosize": "^1.1.1", 36 | "nodemon": "^1.18.4", 37 | "path": "^0.12.7", 38 | "rxjs": "^5.5.6", 39 | "socket.io-client": "^2.1.0", 40 | "typescript": "~2.5.3", 41 | "zone.js": "^0.8.19" 42 | }, 43 | "devDependencies": { 44 | "@angular/cli": "~1.7.4", 45 | "@angular/compiler-cli": "^5.2.0", 46 | "@angular/language-service": "^5.2.0", 47 | "@types/jasmine": "~2.8.3", 48 | "@types/jasminewd2": "~2.0.2", 49 | "@types/node": "~6.0.60", 50 | "babel-cli": "^6.26.0", 51 | "codelyzer": "^4.0.1", 52 | "enhanced-resolve": "^3.3.0", 53 | "jasmine-core": "~2.8.0", 54 | "jasmine-spec-reporter": "~4.2.1", 55 | "karma": "~2.0.0", 56 | "karma-chrome-launcher": "~2.2.0", 57 | "karma-coverage-istanbul-reporter": "^1.2.1", 58 | "karma-jasmine": "~1.1.0", 59 | "karma-jasmine-html-reporter": "^0.2.2", 60 | "protractor": "~5.1.2", 61 | "ts-node": "~4.1.0", 62 | "tslint": "~5.9.1", 63 | "typescript": "~2.5.3" 64 | }, 65 | "engines": { 66 | "node": "9.2.1", 67 | "npm": "5.5.1" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { NotFoundComponent } from './shared/components/not-found/not-found.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | pathMatch: 'full', 10 | redirectTo: 'home' 11 | }, 12 | { 13 | path: 'home', 14 | loadChildren: './home/home.module#HomeModule' 15 | }, 16 | { 17 | path: 'change-password', 18 | loadChildren: './change-password/change-password.module#ChangePasswordModule' 19 | }, 20 | { 21 | path: '', 22 | loadChildren: './auth/auth.module#AuthModule' 23 | }, 24 | { 25 | path: '404', 26 | component: NotFoundComponent 27 | }, 28 | { 29 | path: '**', 30 | redirectTo: '/404' 31 | } 32 | ]; 33 | 34 | @NgModule({ 35 | imports: [RouterModule.forRoot(routes)], 36 | exports: [RouterModule] 37 | }) 38 | export class AppRoutingModule { } 39 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Big-Silver/Angular-Slack/c43f2571c447289cd1f77f7b68bd4c0d1380f0a5/src/app/app.component.scss -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | describe('AppComponent', () => { 4 | beforeEach(async(() => { 5 | TestBed.configureTestingModule({ 6 | declarations: [ 7 | AppComponent 8 | ], 9 | }).compileComponents(); 10 | })); 11 | it('should create the app', async(() => { 12 | const fixture = TestBed.createComponent(AppComponent); 13 | const app = fixture.debugElement.componentInstance; 14 | expect(app).toBeTruthy(); 15 | })); 16 | it(`should have as title 'app'`, async(() => { 17 | const fixture = TestBed.createComponent(AppComponent); 18 | const app = fixture.debugElement.componentInstance; 19 | expect(app.title).toEqual('app'); 20 | })); 21 | it('should render title in a h1 tag', async(() => { 22 | const fixture = TestBed.createComponent(AppComponent); 23 | fixture.detectChanges(); 24 | const compiled = fixture.debugElement.nativeElement; 25 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); 26 | })); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.scss'] 7 | }) 8 | export class AppComponent { 9 | title = 'app'; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 4 | 5 | import { AppComponent } from './app.component'; 6 | 7 | import { AppRoutingModule } from './app-routing.module'; 8 | import { CoreModule } from './core/core.module'; 9 | import { SharedModule } from './shared/shared.module'; 10 | 11 | @NgModule({ 12 | declarations: [ 13 | AppComponent 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | BrowserAnimationsModule, 18 | AppRoutingModule, 19 | CoreModule, 20 | SharedModule 21 | ], 22 | providers: [], 23 | bootstrap: [AppComponent] 24 | }) 25 | export class AppModule { } 26 | -------------------------------------------------------------------------------- /src/app/auth/auth-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { LoginComponent } from './login/login.component'; 5 | import { RegisterComponent } from './register/register.component'; 6 | import { UnauthenticatedGuard } from '../core/guards/unauthenticated.guard'; 7 | 8 | const routes: Routes = [ 9 | { 10 | path: 'login', 11 | component: LoginComponent, 12 | canActivate: [UnauthenticatedGuard] 13 | }, 14 | { 15 | path: 'register', 16 | component: RegisterComponent, 17 | canActivate: [UnauthenticatedGuard] 18 | } 19 | ]; 20 | 21 | @NgModule({ 22 | imports: [RouterModule.forChild(routes)], 23 | exports: [RouterModule] 24 | }) 25 | export class AuthRoutingModule { } 26 | -------------------------------------------------------------------------------- /src/app/auth/auth.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { ReactiveFormsModule } from '@angular/forms'; 4 | 5 | import { AuthRoutingModule } from './auth-routing.module'; 6 | import { MaterialModule } from '../shared/material.module'; 7 | 8 | import { LoginComponent } from './login/login.component'; 9 | import { RegisterComponent } from './register/register.component'; 10 | 11 | import { AuthService } from './auth.service'; 12 | 13 | @NgModule({ 14 | imports: [ 15 | CommonModule, 16 | ReactiveFormsModule, 17 | AuthRoutingModule, 18 | MaterialModule 19 | ], 20 | declarations: [ 21 | LoginComponent, 22 | RegisterComponent 23 | ], 24 | providers: [ 25 | AuthService 26 | ] 27 | }) 28 | export class AuthModule { } 29 | -------------------------------------------------------------------------------- /src/app/auth/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { AuthService } from './auth.service'; 4 | 5 | describe('AuthService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [AuthService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([AuthService], (service: AuthService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/auth/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { ApiService } from '../core/services/api.service'; 3 | import { UserService } from '../core/services/user.service'; 4 | 5 | @Injectable() 6 | export class AuthService { 7 | 8 | constructor( 9 | private api: ApiService, 10 | private user: UserService 11 | ) { } 12 | 13 | login(data) { 14 | return this.api.login(data) 15 | .map((res: any) => { 16 | this.user.setUser(res.user.username, res.user.email, res.token); 17 | return true; 18 | }); 19 | } 20 | 21 | register(data) { 22 | return this.api.register(data) 23 | .map((res: any) => { 24 | this.user.setUser(res.user.username, res.user.email, res.token); 25 | return true; 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/app/auth/custom-validators.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl} from '@angular/forms'; 2 | export class CustomValidators { 3 | static matchPassword(AC: AbstractControl) { 4 | let password = AC.get('password').value; 5 | let confirmPassword = AC.get('confirm').value; 6 | 7 | if(password != confirmPassword) { 8 | AC.get('confirm').setErrors( {matchpassword: true} ) 9 | } else { 10 | return null 11 | } 12 | } 13 | 14 | static passwordStrength(AC: AbstractControl) { 15 | let password = AC.get('password').value; 16 | 17 | const letter = /[A-Za-z]+/g; 18 | const number = /\d+/g; 19 | const special = /[!@#$%^&*()\[\]{}<>\/]/g; 20 | 21 | if (!(letter.exec(password) && number.exec(password) && special.exec(password))) { 22 | AC.get('password').setErrors({passwordStrength: true}); 23 | } 24 | return null; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/app/auth/login/login.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Login

3 | 4 |
5 | 6 | 7 | 8 | Please enter a valid email address 9 | Email is required 10 | 11 | 12 | 13 | 14 | Password is required 15 | Password must be at least 8 characters 16 | 17 | 18 | 19 | 20 |

21 | Don't have an account? Please sign up 22 |

23 |
24 |
25 | -------------------------------------------------------------------------------- /src/app/auth/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/auth/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormGroup, FormBuilder, Validators } from '@angular/forms'; 3 | import { Router } from '@angular/router'; 4 | import { MatSnackBar } from '@angular/material'; 5 | 6 | import { AuthService } from '../auth.service'; 7 | import { handleError } from '../../utils'; 8 | 9 | @Component({ 10 | selector: 'app-login', 11 | templateUrl: './login.component.html', 12 | }) 13 | export class LoginComponent implements OnInit { 14 | 15 | loginForm: FormGroup; 16 | loading = false; 17 | 18 | constructor( 19 | private fb: FormBuilder, 20 | private auth: AuthService, 21 | private router: Router, 22 | private snackBar: MatSnackBar 23 | ) { } 24 | 25 | ngOnInit() { 26 | this.loginForm = this.fb.group({ 27 | email: ['', Validators.compose([ 28 | Validators.required, Validators.email 29 | ])], 30 | password: ['', Validators.compose([ 31 | Validators.required, Validators.minLength(8) 32 | ])] 33 | }); 34 | } 35 | 36 | submit() { 37 | if (!this.loading) { 38 | this.loading = true; 39 | 40 | this.auth.login(this.loginForm.value) 41 | .subscribe( 42 | success => { 43 | this.router.navigate(['/home']); 44 | }, 45 | handleError(this.snackBar), 46 | () => { this.loading = false; } 47 | ); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/app/auth/register/register.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Register

3 | 4 |
5 | 6 | 7 | Please enter a valid email address 8 | Email is required 9 | 10 | 11 | 12 | 13 | Username is required 14 | 15 | 16 | 17 | 18 | Password is required 19 | Password must be at least 6 characters 20 | 21 | 22 | 23 | 24 | Password does not match 25 | 26 | 27 | 28 | 29 |

30 | Already register? Please login 31 |

32 |
33 |
34 | -------------------------------------------------------------------------------- /src/app/auth/register/register.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { RegisterComponent } from './register.component'; 4 | 5 | describe('RegisterComponent', () => { 6 | let component: RegisterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ RegisterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(RegisterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/auth/register/register.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormGroup, FormBuilder, Validators } from '@angular/forms'; 3 | import { Router } from '@angular/router'; 4 | import { MatSnackBar } from '@angular/material'; 5 | import { pick } from 'lodash'; 6 | 7 | import { CustomValidators } from '../custom-validators'; 8 | import { AuthService } from '../auth.service'; 9 | import { handleError } from '../../utils'; 10 | 11 | @Component({ 12 | selector: 'app-register', 13 | templateUrl: './register.component.html', 14 | }) 15 | export class RegisterComponent implements OnInit { 16 | 17 | registerForm: FormGroup; 18 | 19 | constructor( 20 | private fb: FormBuilder, 21 | private auth: AuthService, 22 | private router: Router, 23 | private snackBar: MatSnackBar 24 | ) { } 25 | 26 | ngOnInit() { 27 | this.registerForm = this.fb.group({ 28 | email: ['', Validators.compose([ 29 | Validators.required, Validators.email 30 | ])], 31 | username: ['', Validators.required], 32 | password: ['', Validators.compose([ 33 | Validators.required, Validators.minLength(8) 34 | ])], 35 | confirm: '' 36 | }, { 37 | validator: CustomValidators.matchPassword 38 | }); 39 | } 40 | 41 | submit() { 42 | this.auth.register( 43 | pick(this.registerForm.value, ['email', 'username', 'password']) 44 | ).subscribe( 45 | success => { 46 | this.router.navigate(['/home']); 47 | }, 48 | handleError(this.snackBar) 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/app/change-password/change-password-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { ChangePasswordComponent } from './change-password.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | component: ChangePasswordComponent 10 | } 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [RouterModule.forChild(routes)], 15 | exports: [RouterModule] 16 | }) 17 | export class ChangePasswordRoutingModule { } 18 | -------------------------------------------------------------------------------- /src/app/change-password/change-password.component.html: -------------------------------------------------------------------------------- 1 | 30 | -------------------------------------------------------------------------------- /src/app/change-password/change-password.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Big-Silver/Angular-Slack/c43f2571c447289cd1f77f7b68bd4c0d1380f0a5/src/app/change-password/change-password.component.scss -------------------------------------------------------------------------------- /src/app/change-password/change-password.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ChangePasswordComponent } from './change-password.component'; 4 | 5 | describe('ChangePasswordComponent', () => { 6 | let component: ChangePasswordComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ChangePasswordComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ChangePasswordComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/change-password/change-password.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormGroup, FormBuilder, Validators } from '@angular/forms'; 3 | import { CustomValidators } from '../auth/custom-validators'; 4 | import { ChangePasswordService } from './change-password.service'; 5 | import { MatSnackBar } from '@angular/material'; 6 | 7 | @Component({ 8 | selector: 'app-change-password', 9 | templateUrl: './change-password.component.html', 10 | styleUrls: ['./change-password.component.scss'] 11 | }) 12 | export class ChangePasswordComponent implements OnInit { 13 | 14 | passwordForm: FormGroup; 15 | public barLabel: string = ''; 16 | public myColors = ['#DD2C00', '#FF6D00', '#FFD600', '#AEEA00', '#00C853']; 17 | 18 | constructor(private fb: FormBuilder, private service: ChangePasswordService, private snackBar: MatSnackBar) { } 19 | 20 | ngOnInit() { 21 | this.passwordForm = this.fb.group({ 22 | oldPassword: '', 23 | password: ['', Validators.compose([ 24 | Validators.required, 25 | Validators.minLength(6) 26 | ])], 27 | confirm: '' 28 | }, { 29 | validator: Validators.compose([ 30 | CustomValidators.matchPassword, 31 | CustomValidators.passwordStrength 32 | ]) 33 | }); 34 | } 35 | 36 | 37 | submit() { 38 | this.service.change(this.passwordForm.value) 39 | .subscribe(rst => { 40 | if (rst.success) { 41 | this.snackBar.open('Password changed successfully!', '', { 42 | duration: 3000, 43 | horizontalPosition: 'right', 44 | verticalPosition: 'top', 45 | panelClass: 'welcome-msg' 46 | }); 47 | } 48 | }, err => { 49 | this.snackBar.open('Password change failed!', '', { 50 | duration: 3000, 51 | horizontalPosition: 'right', 52 | verticalPosition: 'top', 53 | panelClass: 'error-msg' 54 | }); 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/app/change-password/change-password.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { ReactiveFormsModule } from '@angular/forms'; 3 | import { CommonModule } from '@angular/common'; 4 | import { HttpModule } from '@angular/http'; 5 | import { PasswordStrengthBarModule } from 'ng2-password-strength-bar'; 6 | 7 | import { MaterialModule } from '../shared/material.module'; 8 | 9 | import { ChangePasswordRoutingModule } from './change-password-routing.module'; 10 | import { ChangePasswordComponent } from './change-password.component'; 11 | 12 | import { ChangePasswordService } from './change-password.service'; 13 | 14 | @NgModule({ 15 | imports: [ 16 | CommonModule, 17 | ReactiveFormsModule, 18 | ChangePasswordRoutingModule, 19 | MaterialModule, 20 | HttpModule, 21 | PasswordStrengthBarModule 22 | ], 23 | declarations: [ChangePasswordComponent], 24 | providers: [ChangePasswordService] 25 | }) 26 | export class ChangePasswordModule { } 27 | -------------------------------------------------------------------------------- /src/app/change-password/change-password.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { ChangePasswordService } from './change-password.service'; 4 | 5 | describe('ChangePasswordService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [ChangePasswordService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([ChangePasswordService], (service: ChangePasswordService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/change-password/change-password.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Http } from '@angular/http'; 3 | 4 | @Injectable() 5 | export class ChangePasswordService { 6 | 7 | constructor(private http: Http) { } 8 | 9 | change(form) { 10 | console.log(form); 11 | 12 | return this.http.post('http://192.168.0.27:8080/changepwd', { 13 | oldpwd: form.oldPassword, 14 | newpwd: form.password 15 | }) 16 | .map(res => res.json()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | 5 | import { ApiService } from './services/api.service'; 6 | import { UserService } from './services/user.service'; 7 | import { AuthenticatedGuard } from './guards/authenticated.guard'; 8 | import { UnauthenticatedGuard } from './guards/unauthenticated.guard'; 9 | 10 | @NgModule({ 11 | imports: [ 12 | CommonModule, 13 | HttpClientModule 14 | ], 15 | declarations: [], 16 | providers: [ 17 | ApiService, 18 | UserService, 19 | AuthenticatedGuard, 20 | UnauthenticatedGuard 21 | ] 22 | }) 23 | export class CoreModule { } 24 | -------------------------------------------------------------------------------- /src/app/core/guards/authenticated.guard.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async, inject } from '@angular/core/testing'; 2 | 3 | import { AuthenticatedGuard } from './authenticated.guard'; 4 | 5 | describe('AuthenticatedGuard', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [AuthenticatedGuard] 9 | }); 10 | }); 11 | 12 | it('should ...', inject([AuthenticatedGuard], (guard: AuthenticatedGuard) => { 13 | expect(guard).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/core/guards/authenticated.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router'; 3 | import { Observable } from 'rxjs/Observable'; 4 | import { UserService } from '../services/user.service'; 5 | 6 | @Injectable() 7 | export class AuthenticatedGuard implements CanActivate { 8 | constructor(private user: UserService, private router: Router) {} 9 | 10 | canActivate( 11 | next: ActivatedRouteSnapshot, 12 | state: RouterStateSnapshot 13 | ): Observable | Promise | boolean { 14 | 15 | if (this.user.isLoggedIn()) { 16 | return true; 17 | } 18 | 19 | this.router.navigate(['/login']); 20 | 21 | return false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/core/guards/unauthenticated.guard.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async, inject } from '@angular/core/testing'; 2 | 3 | import { UnauthenticatedGuard } from './unauthenticated.guard'; 4 | 5 | describe('UnauthenticatedGuard', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [UnauthenticatedGuard] 9 | }); 10 | }); 11 | 12 | it('should ...', inject([UnauthenticatedGuard], (guard: UnauthenticatedGuard) => { 13 | expect(guard).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/core/guards/unauthenticated.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router'; 3 | import { Observable } from 'rxjs/Observable'; 4 | import { UserService } from '../services/user.service'; 5 | 6 | @Injectable() 7 | export class UnauthenticatedGuard implements CanActivate { 8 | constructor(private user: UserService, private router: Router) {} 9 | 10 | canActivate( 11 | next: ActivatedRouteSnapshot, 12 | state: RouterStateSnapshot 13 | ): Observable | Promise | boolean { 14 | if (!this.user.isLoggedIn()) { 15 | return true; 16 | } 17 | 18 | this.router.navigate(['/home']); 19 | 20 | return this.user.isLoggedIn(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/app/core/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './user'; 2 | -------------------------------------------------------------------------------- /src/app/core/models/user.ts: -------------------------------------------------------------------------------- 1 | export class User { 2 | username: string; 3 | email: string; 4 | token: string; 5 | 6 | isLoggedIn() { 7 | return this.token !== ''; 8 | } 9 | 10 | constructor(username = '', email = '', token = '') { 11 | this.username = username; 12 | this.email = email; 13 | this.token = token; 14 | } 15 | 16 | cloneWithToken(token: string) { 17 | return new User(this.username, this.email, token); 18 | } 19 | 20 | cloneWithInfo(username: string, email: string) { 21 | return new User(username, email, this.token); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/core/services/api.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { ApiService } from './api.service'; 4 | 5 | describe('ApiService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [ApiService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([ApiService], (service: ApiService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/core/services/api.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 3 | import { environment } from '../../../environments/environment.prod'; 4 | 5 | const baseURL = environment.baseURL; 6 | 7 | @Injectable() 8 | export class ApiService { 9 | 10 | constructor(private httpClient: HttpClient ) { } 11 | 12 | login(form) { 13 | return this.post('/auth/login', form); 14 | } 15 | 16 | register(form) { 17 | return this.post('/auth/register', form); 18 | } 19 | 20 | validate(token) { 21 | return this.get('/auth/validate', token); 22 | } 23 | 24 | getChats(token) { 25 | return this.get('/chats', token); 26 | } 27 | 28 | private get(url, token = '') { 29 | if (token) { 30 | const httpOptions = { 31 | headers: new HttpHeaders({ 32 | 'Content-Type': 'application/json', 33 | 'x-access-token': token 34 | }) 35 | }; 36 | 37 | return this.httpClient.get(`${baseURL}${url}`, httpOptions); 38 | } 39 | 40 | return this.httpClient.get(`${baseURL}${url}`); 41 | } 42 | 43 | private post(url, data, token = '') { 44 | if (token) { 45 | const httpOptions = { 46 | headers: new HttpHeaders({ 47 | 'Content-Type': 'application/json', 48 | 'x-access-token': token 49 | }) 50 | }; 51 | 52 | return this.httpClient.post(`${baseURL}${url}`, data, httpOptions); 53 | } 54 | 55 | return this.httpClient.post(`${baseURL}${url}`, data); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/app/core/services/user.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { UserService } from './user.service'; 4 | 5 | describe('UserService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [UserService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([UserService], (service: UserService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/core/services/user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { BehaviorSubject } from 'rxjs/BehaviorSubject'; 3 | import { Router } from '@angular/router'; 4 | 5 | import { User } from '../models'; 6 | import { ApiService } from './api.service'; 7 | 8 | @Injectable() 9 | export class UserService { 10 | user: BehaviorSubject = new BehaviorSubject(new User()); 11 | 12 | constructor(private api: ApiService, private router: Router) { 13 | const token = localStorage.getItem('token'); 14 | if (token) { 15 | const user = new User('', '', token); 16 | this.user = new BehaviorSubject(user); 17 | 18 | api.validate(token) 19 | .subscribe( 20 | (res: any) => { 21 | const { username, email } = res.user; 22 | const newUser = new User(username, email, token); 23 | this.user.next(newUser); 24 | }, 25 | err => { 26 | console.log(err); 27 | this.resetUser(); 28 | } 29 | ); 30 | } 31 | } 32 | 33 | setUser(username: string, email: string, token: string) { 34 | localStorage.setItem('token', token); 35 | const newUser = new User(username, email, token); 36 | this.user.next(newUser); 37 | } 38 | 39 | resetUser() { 40 | localStorage.removeItem('token'); 41 | this.user.next(new User()); 42 | this.router.navigate(['/login']); 43 | } 44 | 45 | isLoggedIn() { 46 | return this.user.value.isLoggedIn(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/home/chats.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { ChatsService } from './chats.service'; 4 | 5 | describe('ChatsService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [ChatsService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([ChatsService], (service: ChatsService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/home/chats.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { MatSnackBar } from '@angular/material'; 3 | import { ApiService } from '../core/services/api.service'; 4 | import { UserService } from '../core/services/user.service'; 5 | import { User } from '../core/models'; 6 | import * as socketIo from 'socket.io-client'; 7 | import { BehaviorSubject } from 'rxjs/BehaviorSubject'; 8 | import { Message } from './models'; 9 | import { environment } from '../../environments/environment.prod'; 10 | 11 | const baseURL = environment.baseURL; 12 | 13 | @Injectable() 14 | export class ChatsService { 15 | msgs = new BehaviorSubject([]); 16 | isSend = new BehaviorSubject(false); 17 | 18 | private socket; 19 | private user: User; 20 | private isConnected: Boolean; 21 | private interval; 22 | 23 | constructor( 24 | private api: ApiService, 25 | private userService: UserService, 26 | private snackBar: MatSnackBar, 27 | ) { 28 | this.userService.user.subscribe(_user => { this.user = _user; }); 29 | this.isConnected = true; 30 | this.interval = null; 31 | } 32 | 33 | getChats() { 34 | this.api.getChats(this.user.token) 35 | .subscribe((messages: Message[]) => { 36 | this.msgs.next(messages); 37 | }); 38 | } 39 | 40 | initSocket() { 41 | this.socket = socketIo(baseURL, { query: 'token=' + this.user.token }); 42 | 43 | this.socket.on('connect_failed', () => { 44 | this.socket.close(); 45 | }); 46 | 47 | this.socket.on('disconnect', () => { 48 | this.isConnected = false; 49 | this.connectionFailMessage(); 50 | this.isSend.next(false); 51 | this.interval = window.setInterval(() => { 52 | if (this.isConnected) { 53 | clearInterval(this.interval); 54 | this.interval = null; 55 | return; 56 | } 57 | this.socket.connect(); 58 | }, 5000); 59 | // this.socket.close(); 60 | }); 61 | 62 | this.socket.on('receive', (data: { msg: Message }) => { 63 | this.msgs.next([ 64 | ...this.msgs.value, 65 | data.msg 66 | ]); 67 | }); 68 | 69 | this.socket.on('connect', () => { 70 | this.isSend.next(true); 71 | if (!this.isConnected) { 72 | this.connectionSuccessMessage(); 73 | } 74 | this.isConnected = true; 75 | this.getChats(); 76 | }); 77 | } 78 | 79 | sendMessage(text) { 80 | this.socket.emit('send', text); 81 | } 82 | 83 | disconnect() { 84 | this.socket.disconnect(); 85 | } 86 | 87 | private connectionFailMessage() { 88 | setTimeout(() => { 89 | this.snackBar.open(`Try to reconnect.`, 'close', { 90 | duration: 10000, 91 | horizontalPosition: 'right', 92 | verticalPosition: 'top', 93 | panelClass: 'error-msg' 94 | }); 95 | }); 96 | } 97 | 98 | private connectionSuccessMessage() { 99 | setTimeout(() => { 100 | this.snackBar.open(`The network was reconnected.`, 'close', { 101 | duration: 10000, 102 | horizontalPosition: 'right', 103 | verticalPosition: 'top', 104 | panelClass: 'welcome-msg' 105 | }); 106 | }); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/app/home/components/dropdown/dropdown.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/home/components/dropdown/dropdown.component.scss: -------------------------------------------------------------------------------- 1 | .dropdown { 2 | position: relative; 3 | flex: none; 4 | 5 | .dd-header { 6 | background: #3E313C; 7 | box-shadow: inset 0 0 1px #000000; 8 | display: flex; 9 | font-size: 20px; 10 | font-weight: bold; 11 | justify-content: space-between; 12 | padding: 15px 20px; 13 | cursor: pointer; 14 | } 15 | 16 | .dd-content { 17 | background: #3E313C; 18 | box-sizing: border-box; 19 | font-size: 1.2em; 20 | padding: 10px 20px; 21 | position: absolute; 22 | top: 0; 23 | transform: translateY(-100%); 24 | width: 100%; 25 | 26 | .dd-item { 27 | cursor: pointer; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/app/home/components/dropdown/dropdown.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { DropdownComponent } from './dropdown.component'; 4 | 5 | describe('DropdownComponent', () => { 6 | let component: DropdownComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ DropdownComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(DropdownComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/home/components/dropdown/dropdown.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; 2 | 3 | import { MenuDir, MenuItem } from '../../models'; 4 | 5 | @Component({ 6 | selector: 'app-dropdown', 7 | templateUrl: './dropdown.component.html', 8 | styleUrls: ['./dropdown.component.scss'] 9 | }) 10 | export class DropdownComponent implements OnInit { 11 | @Input() title = 'Title'; 12 | @Input() showArrow = false; 13 | @Input() menus: Array = []; 14 | @Input() defaultDir: MenuDir = MenuDir.Down; 15 | 16 | @Output() itemClicked = new EventEmitter(); 17 | 18 | menuOpen = false; 19 | dir = MenuDir.Down; 20 | 21 | constructor() { } 22 | 23 | ngOnInit() { 24 | } 25 | 26 | menuClick() { 27 | this.menuOpen = !this.menuOpen; 28 | if ( 29 | (this.defaultDir === MenuDir.Down && !this.menuOpen) || 30 | (this.defaultDir === MenuDir.Up && this.menuOpen) 31 | ) { 32 | this.dir = MenuDir.Down; 33 | } else { 34 | this.dir = MenuDir.Up; 35 | } 36 | } 37 | 38 | itemClick(id) { 39 | this.itemClicked.emit(id); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/app/home/components/messages/messages.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | @{{ msg.name }} 4 | {{ msg.time | date:'mediumTime' }}
5 | {{ msg.text }} 6 |
7 |
-------------------------------------------------------------------------------- /src/app/home/components/messages/messages.component.scss: -------------------------------------------------------------------------------- 1 | :host { 2 | flex: 1; 3 | overflow: auto; 4 | padding: 30px 10px 5 | } 6 | 7 | .message-board { 8 | overflow-y: auto; 9 | height: 100%; 10 | 11 | .message { 12 | margin-bottom: 1em; 13 | 14 | .name { 15 | font-weight: bold; 16 | } 17 | 18 | .time { 19 | color: lightgray; 20 | } 21 | 22 | .text { 23 | display: block; 24 | padding: .5em; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/app/home/components/messages/messages.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { MessagesComponent } from './messages.component'; 4 | 5 | describe('MessagesComponent', () => { 6 | let component: MessagesComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ MessagesComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(MessagesComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/home/components/messages/messages.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input, AfterViewChecked, ViewChild, ElementRef } from '@angular/core'; 2 | import { Message } from '../../models'; 3 | 4 | @Component({ 5 | selector: 'app-messages', 6 | templateUrl: './messages.component.html', 7 | styleUrls: ['./messages.component.scss'] 8 | }) 9 | export class MessagesComponent implements OnInit { 10 | @ViewChild('message_board') private messageContainer: ElementRef; 11 | 12 | @Input() messages: Message[] = []; 13 | 14 | constructor() { } 15 | 16 | ngOnInit() { 17 | this.scrollToBottom(); 18 | } 19 | 20 | scrollToBottom(): void { 21 | try { 22 | this.messageContainer.nativeElement.scrollTop = this.messageContainer.nativeElement.scrollHeight; 23 | } catch(err) { } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/app/home/components/msg-block/msg-block.component.html: -------------------------------------------------------------------------------- 1 |

2 | msg-block works! 3 |

4 | -------------------------------------------------------------------------------- /src/app/home/components/msg-block/msg-block.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Big-Silver/Angular-Slack/c43f2571c447289cd1f77f7b68bd4c0d1380f0a5/src/app/home/components/msg-block/msg-block.component.scss -------------------------------------------------------------------------------- /src/app/home/components/msg-block/msg-block.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { MsgBlockComponent } from './msg-block.component'; 4 | 5 | describe('MsgBlockComponent', () => { 6 | let component: MsgBlockComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ MsgBlockComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(MsgBlockComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/home/components/msg-block/msg-block.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-msg-block', 5 | templateUrl: './msg-block.component.html', 6 | styleUrls: ['./msg-block.component.scss'] 7 | }) 8 | export class MsgBlockComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/home/components/sidebar-group/sidebar-group.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/home/components/sidebar-group/sidebar-group.component.scss: -------------------------------------------------------------------------------- 1 | .sidebar-group { 2 | padding: 0 15px; 3 | margin-top: 24px; 4 | 5 | .group-name { 6 | font-size: 1.2em; 7 | font-weight: bold; 8 | display: flex; 9 | justify-content: space-between; 10 | text-transform: uppercase; 11 | } 12 | 13 | .group-list { 14 | margin-top: 12px; 15 | 16 | .item { 17 | padding: 4px 0 4px 10px; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/app/home/components/sidebar-group/sidebar-group.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { SidebarGroupComponent } from './sidebar-group.component'; 4 | 5 | describe('SidebarGroupComponent', () => { 6 | let component: SidebarGroupComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ SidebarGroupComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(SidebarGroupComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/home/components/sidebar-group/sidebar-group.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; 2 | 3 | import { MenuItem } from '../../models'; 4 | 5 | @Component({ 6 | selector: 'app-sidebar-group', 7 | templateUrl: './sidebar-group.component.html', 8 | styleUrls: ['./sidebar-group.component.scss'] 9 | }) 10 | export class SidebarGroupComponent implements OnInit { 11 | @Input() menus: Array = []; 12 | @Input() title = ''; 13 | @Output() itemClicked = new EventEmitter(); 14 | 15 | constructor() { } 16 | 17 | ngOnInit() { 18 | } 19 | 20 | itemClick(id: string) { 21 | this.itemClicked.emit(id); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/home/components/sidebar/sidebar.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/home/components/sidebar/sidebar.component.scss: -------------------------------------------------------------------------------- 1 | .sidebar { 2 | background: #4D384B; 3 | color: white; 4 | display: flex; 5 | flex-direction: column; 6 | position: relative; 7 | width: 280px; 8 | height: 100vh; 9 | 10 | .sidebar-content { 11 | flex: 1; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/app/home/components/sidebar/sidebar.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { SidebarComponent } from './sidebar.component'; 4 | 5 | describe('SidebarComponent', () => { 6 | let component: SidebarComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ SidebarComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(SidebarComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/home/components/sidebar/sidebar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | 4 | import { MenuItem } from '../../models'; 5 | import { UserService } from '../../../core/services/user.service'; 6 | 7 | @Component({ 8 | selector: 'app-sidebar', 9 | templateUrl: './sidebar.component.html', 10 | styleUrls: ['./sidebar.component.scss'] 11 | }) 12 | export class SidebarComponent implements OnInit { 13 | menus: Array = [ 14 | { 15 | id: 'logout', 16 | label: 'Logout' 17 | } 18 | ]; 19 | directChannels: Array = [ 20 | { 21 | id: 'john', 22 | label: 'John' 23 | }, 24 | { 25 | id: 'nick', 26 | label: 'Nick' 27 | }, 28 | ]; 29 | channels: Array = [ 30 | { 31 | id: 'general', 32 | label: 'General' 33 | } 34 | ]; 35 | username = 'test'; 36 | 37 | constructor(private user: UserService, private router: Router) { } 38 | 39 | ngOnInit() { 40 | } 41 | 42 | menuClick(id: string) { 43 | if (id === 'logout') { 44 | this.user.resetUser(); 45 | this.router.navigate(['/login']); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /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 { AuthenticatedGuard } from '../core/guards/authenticated.guard'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | component: HomeComponent, 10 | canActivate: [AuthenticatedGuard] 11 | } 12 | ]; 13 | 14 | @NgModule({ 15 | imports: [RouterModule.forChild(routes)], 16 | exports: [RouterModule] 17 | }) 18 | export class HomeRoutingModule { } 19 | -------------------------------------------------------------------------------- /src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 |

5 | #Channel 6 |

7 | 8 |
9 | 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /src/app/home/home.component.scss: -------------------------------------------------------------------------------- 1 | .home { 2 | display: flex; 3 | 4 | .chat-main { 5 | color: #555459; 6 | flex: 1; 7 | padding: 20px; 8 | display: flex; 9 | flex-direction: column; 10 | height: 100vh; 11 | overflow: hidden; 12 | box-sizing: border-box; 13 | 14 | .chat-header { 15 | margin: 0; 16 | padding-bottom: 5px; 17 | border-bottom: 1px solid #ccc; 18 | } 19 | 20 | .chat-input { 21 | padding-right: 12px; 22 | padding-top: 5px; 23 | 24 | textarea { 25 | width: 100%; 26 | border-radius: 5px; 27 | border: 1px solid #aaa; 28 | padding: 5px; 29 | margin-right: 10px; 30 | font-size: 16px; 31 | line-height: 1.5em; 32 | resize: none; 33 | max-height: 80px; 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/app/home/home.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeComponent } from './home.component'; 4 | 5 | describe('HomeComponent', () => { 6 | let component: HomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HomeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { MatSnackBar } from '@angular/material'; 3 | import { UserService } from '../core/services/user.service'; 4 | import { User } from '../core/models/user'; 5 | import { ChatsService } from './chats.service'; 6 | import { Message } from './models'; 7 | 8 | @Component({ 9 | selector: 'app-home', 10 | templateUrl: './home.component.html', 11 | styleUrls: ['./home.component.scss'] 12 | }) 13 | export class HomeComponent implements OnInit, OnDestroy { 14 | user: User; 15 | user$: any; 16 | showWelcome = true; 17 | msgToSend = ''; 18 | isSend = true; 19 | messages: Message[] = []; 20 | 21 | constructor( 22 | private userService: UserService, 23 | private snackBar: MatSnackBar, 24 | private chats: ChatsService 25 | ) { } 26 | 27 | ngOnInit() { 28 | this.user$ = this.userService.user.subscribe(u => { 29 | this.user = u; 30 | 31 | if (u.username && this.showWelcome) { 32 | this.showWelcomeMessage(); 33 | } 34 | }); 35 | 36 | // this.chats.getChats(); 37 | this.chats.initSocket(); 38 | 39 | this.chats.msgs.subscribe((value: Message[]) => { 40 | this.messages = value; 41 | }); 42 | 43 | this.chats.isSend.subscribe((value: boolean) => { 44 | this.isSend = value; 45 | }); 46 | } 47 | 48 | ngOnDestroy() { 49 | this.user$.unsubscribe(); 50 | } 51 | 52 | logout() { 53 | this.userService.resetUser(); 54 | } 55 | 56 | keydown(ev) { 57 | if (ev.keyCode === 13 && !ev.ctrlKey && !ev.shiftKey) { 58 | this.chats.sendMessage(this.msgToSend); 59 | this.msgToSend = ''; 60 | ev.preventDefault(); 61 | } 62 | } 63 | 64 | private showWelcomeMessage() { 65 | setTimeout(() => { 66 | this.snackBar.open(`Welcome, ${this.user.username}!`, '', { 67 | duration: 4000, 68 | horizontalPosition: 'right', 69 | verticalPosition: 'top', 70 | panelClass: 'welcome-msg' 71 | }); 72 | this.showWelcome = false; 73 | }); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/app/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | import { TextareaAutosizeModule } from 'ngx-textarea-autosize'; 6 | 7 | import { HomeRoutingModule } from './home-routing.module'; 8 | import { MaterialModule } from '../shared/material.module'; 9 | import { HomeComponent } from './home.component'; 10 | import { SidebarComponent } from './components/sidebar/sidebar.component'; 11 | import { SidebarGroupComponent } from './components/sidebar-group/sidebar-group.component'; 12 | import { DropdownComponent } from './components/dropdown/dropdown.component'; 13 | import { MessagesComponent } from './components/messages/messages.component'; 14 | import { MsgBlockComponent } from './components/msg-block/msg-block.component'; 15 | import { ChatsService } from './chats.service'; 16 | 17 | @NgModule({ 18 | imports: [ 19 | CommonModule, 20 | FormsModule, 21 | HomeRoutingModule, 22 | MaterialModule, 23 | TextareaAutosizeModule 24 | ], 25 | declarations: [ 26 | HomeComponent, 27 | SidebarComponent, 28 | SidebarGroupComponent, 29 | DropdownComponent, 30 | MessagesComponent, 31 | MsgBlockComponent 32 | ], 33 | providers: [ 34 | ChatsService 35 | ] 36 | }) 37 | export class HomeModule { } 38 | -------------------------------------------------------------------------------- /src/app/home/models/index.ts: -------------------------------------------------------------------------------- 1 | export enum MenuDir { 2 | Up = 1, 3 | Down 4 | } 5 | 6 | export interface MenuItem { 7 | id: string; 8 | label: string; 9 | } 10 | 11 | export interface Message { 12 | id: string; 13 | name: string; 14 | text: string; 15 | time: number; 16 | } 17 | -------------------------------------------------------------------------------- /src/app/shared/components/not-found/not-found.component.html: -------------------------------------------------------------------------------- 1 |

2 | not-found works! 3 |

4 | -------------------------------------------------------------------------------- /src/app/shared/components/not-found/not-found.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Big-Silver/Angular-Slack/c43f2571c447289cd1f77f7b68bd4c0d1380f0a5/src/app/shared/components/not-found/not-found.component.scss -------------------------------------------------------------------------------- /src/app/shared/components/not-found/not-found.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { NotFoundComponent } from './not-found.component'; 4 | 5 | describe('NotFoundComponent', () => { 6 | let component: NotFoundComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ NotFoundComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(NotFoundComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/shared/components/not-found/not-found.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-not-found', 5 | templateUrl: './not-found.component.html', 6 | styleUrls: ['./not-found.component.scss'] 7 | }) 8 | export class NotFoundComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/shared/material.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { 3 | MatButtonModule, 4 | MatInputModule, 5 | MatSnackBarModule, 6 | } from '@angular/material'; 7 | 8 | const matModules = [ 9 | MatButtonModule, 10 | MatInputModule, 11 | MatSnackBarModule, 12 | ]; 13 | 14 | @NgModule({ 15 | imports: matModules, 16 | exports: matModules 17 | }) 18 | export class MaterialModule { } 19 | -------------------------------------------------------------------------------- /src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { NotFoundComponent } from './components/not-found/not-found.component'; 4 | 5 | @NgModule({ 6 | imports: [ 7 | CommonModule 8 | ], 9 | declarations: [NotFoundComponent], 10 | exports: [NotFoundComponent] 11 | }) 12 | export class SharedModule { } 13 | -------------------------------------------------------------------------------- /src/app/utils/index.ts: -------------------------------------------------------------------------------- 1 | export const handleError = (snackBar) => err => { 2 | console.log(err); 3 | const sbConfig = { 4 | duration: 3000, 5 | horizontalPosition: 'right', 6 | verticalPosition: 'top', 7 | panelClass: 'error-msg' 8 | }; 9 | 10 | if (typeof err.error === 'string') { 11 | snackBar.open(err.error, '', sbConfig); 12 | } else { 13 | snackBar.open('Unknown error', '', sbConfig); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Big-Silver/Angular-Slack/c43f2571c447289cd1f77f7b68bd4c0d1380f0a5/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | baseURL: 'https://angular-slack-api.herokuapp.com' 4 | }; 5 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false, 8 | baseURL: 'http://localhost:8000' 9 | }; 10 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Big-Silver/Angular-Slack/c43f2571c447289cd1f77f7b68bd4c0d1380f0a5/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ngslack 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /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 | import 'hammerjs'; 8 | 9 | if (environment.production) { 10 | enableProdMode(); 11 | } 12 | 13 | platformBrowserDynamic().bootstrapModule(AppModule) 14 | .catch(err => console.log(err)); 15 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Required to support Web Animations `@angular/platform-browser/animations`. 51 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 52 | **/ 53 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 54 | 55 | /** 56 | * By default, zone.js will patch all possible macroTask and DomEvents 57 | * user can disable parts of macroTask/DomEvents patch by setting following flags 58 | */ 59 | 60 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 61 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 62 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 63 | 64 | /* 65 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 66 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 67 | */ 68 | // (window as any).__Zone_enable_cross_context_check = true; 69 | 70 | /*************************************************************************************************** 71 | * Zone JS is required by default for Angular itself. 72 | */ 73 | import 'zone.js/dist/zone'; // Included with Angular CLI. 74 | 75 | 76 | 77 | /*************************************************************************************************** 78 | * APPLICATION IMPORTS 79 | */ 80 | import 'rxjs/add/operator/map'; 81 | -------------------------------------------------------------------------------- /src/sass/_common.scss: -------------------------------------------------------------------------------- 1 | .login-register-form { 2 | box-sizing: border-box; 3 | display: flex; 4 | flex-direction: column; 5 | height: 100vh; 6 | max-width: 640px; 7 | margin: 0 auto; 8 | padding: 80px 30px 0; 9 | 10 | form > * { 11 | width: 100%; 12 | } 13 | 14 | h1 { 15 | margin-bottom: 1em; 16 | } 17 | 18 | button { 19 | margin-top: 1em; 20 | } 21 | 22 | .additional { 23 | text-align: center; 24 | } 25 | 26 | mat-form-field { 27 | margin-top: 8px; 28 | } 29 | } 30 | 31 | .error-msg { 32 | background-color: #b71c1c; 33 | color: white; 34 | } 35 | 36 | .welcome-msg { 37 | background-color: #2e7d32; 38 | color: white; 39 | } 40 | -------------------------------------------------------------------------------- /src/sass/_material.scss: -------------------------------------------------------------------------------- 1 | @import "~@angular/material/theming"; 2 | 3 | @include mat-core(); 4 | 5 | $app-primary: mat-palette($mat-indigo); 6 | $app-accent: mat-palette($mat-pink, A200, A100, A400); 7 | $app-warn: mat-palette($mat-red); 8 | $app-theme: mat-light-theme($app-primary, $app-accent, $app-warn); 9 | 10 | @include angular-material-theme($app-theme); 11 | -------------------------------------------------------------------------------- /src/sass/_variables.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Big-Silver/Angular-Slack/c43f2571c447289cd1f77f7b68bd4c0d1380f0a5/src/sass/_variables.scss -------------------------------------------------------------------------------- /src/sass/styles.scss: -------------------------------------------------------------------------------- 1 | @import './variables'; 2 | @import './material'; 3 | @import './common'; 4 | 5 | body { 6 | margin: 0; 7 | padding: 0; 8 | font-family: "Roboto", sans-serif; 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale; 11 | } 12 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "types": [ 8 | "jasmine", 9 | "node" 10 | ] 11 | }, 12 | "files": [ 13 | "test.ts" 14 | ], 15 | "include": [ 16 | "**/*.spec.ts", 17 | "**/*.d.ts" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "typeRoots": [ 12 | "node_modules/@types" 13 | ], 14 | "lib": [ 15 | "es2017", 16 | "dom" 17 | ] 18 | }, 19 | "include": [ 20 | "src/**/*", 21 | "node_modules/ngx-textarea-autosize/index.ts" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs", 22 | "rxjs/Rx" 23 | ], 24 | "import-spacing": true, 25 | "indent": [ 26 | true, 27 | "spaces" 28 | ], 29 | "interface-over-type-literal": true, 30 | "label-position": true, 31 | "max-line-length": [ 32 | true, 33 | 140 34 | ], 35 | "member-access": false, 36 | "member-ordering": [ 37 | true, 38 | { 39 | "order": [ 40 | "static-field", 41 | "instance-field", 42 | "static-method", 43 | "instance-method" 44 | ] 45 | } 46 | ], 47 | "no-arg": true, 48 | "no-bitwise": true, 49 | "no-console": [ 50 | true, 51 | "debug", 52 | "info", 53 | "time", 54 | "timeEnd", 55 | "trace" 56 | ], 57 | "no-construct": true, 58 | "no-debugger": true, 59 | "no-duplicate-super": true, 60 | "no-empty": false, 61 | "no-empty-interface": true, 62 | "no-eval": true, 63 | "no-inferrable-types": [ 64 | true, 65 | "ignore-params" 66 | ], 67 | "no-misused-new": true, 68 | "no-non-null-assertion": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "directive-selector": [ 121 | true, 122 | "attribute", 123 | "app", 124 | "camelCase" 125 | ], 126 | "component-selector": [ 127 | true, 128 | "element", 129 | "app", 130 | "kebab-case" 131 | ], 132 | "no-output-on-prefix": true, 133 | "use-input-property-decorator": true, 134 | "use-output-property-decorator": true, 135 | "use-host-property-decorator": true, 136 | "no-input-rename": true, 137 | "no-output-rename": true, 138 | "use-life-cycle-interface": true, 139 | "use-pipe-transform-interface": true, 140 | "component-class-suffix": true, 141 | "directive-class-suffix": true 142 | } 143 | } 144 | --------------------------------------------------------------------------------