├── src ├── assets │ ├── .gitkeep │ └── scenery.png ├── app │ ├── app.component.css │ ├── feedback │ │ ├── index.ts │ │ ├── entity │ │ │ ├── feedback.ts │ │ │ └── rectangle.ts │ │ ├── feedback-rectangle │ │ │ ├── feedback-rectangle.component.css │ │ │ ├── feedback-rectangle.component.html │ │ │ └── feedback-rectangle.component.ts │ │ ├── feedback.module.ts │ │ ├── feedback-toolbar │ │ │ ├── feedback-toolbar.component.css │ │ │ ├── feedback-toolbar.component.html │ │ │ └── feedback-toolbar.component.ts │ │ ├── feedback-dialog │ │ │ ├── feedback-dialog.component.html │ │ │ ├── feedback-dialog.component.css │ │ │ └── feedback-dialog.component.ts │ │ ├── feedback.directive.ts │ │ └── feedback.service.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── app.component.spec.ts │ └── app.component.html ├── favicon.ico ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── typings.d.ts ├── styles.css ├── tsconfig.app.json ├── index.html ├── main.ts ├── tsconfig.spec.json ├── test.ts └── polyfills.ts ├── e2e ├── app.po.ts ├── tsconfig.e2e.json └── app.e2e-spec.ts ├── .editorconfig ├── tsconfig.json ├── .gitignore ├── protractor.conf.js ├── karma.conf.js ├── LICENSE ├── package.json ├── tslint.json ├── README.md └── angular.json /src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | div img { 2 | display: inline-block; 3 | } 4 | -------------------------------------------------------------------------------- /src/app/feedback/index.ts: -------------------------------------------------------------------------------- 1 | export { FeedbackModule } from './feedback.module'; 2 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickonChen/feedback/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /src/assets/scenery.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickonChen/feedback/HEAD/src/assets/scenery.png -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/app/feedback/entity/feedback.ts: -------------------------------------------------------------------------------- 1 | export class Feedback { 2 | public description: string; 3 | public screenshot: string; 4 | } 5 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import "~@angular/material/prebuilt-themes/deeppurple-amber.css"; 3 | body{ 4 | background-color: white; 5 | } 6 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class FeedbackPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [], 6 | "moduleResolution": "node" 7 | }, 8 | "exclude": [ 9 | "test.ts", 10 | "**/*.spec.ts" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/app/feedback/entity/rectangle.ts: -------------------------------------------------------------------------------- 1 | export class Rectangle { 2 | public startX: number; 3 | public startY: number; 4 | public width: number; 5 | public height: number; 6 | public color: string; 7 | public windowScrollY: number = window.scrollY; 8 | public windowScrollX: number = window.scrollX; 9 | } 10 | -------------------------------------------------------------------------------- /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.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'app'; 10 | public onSend(val) { 11 | console.log(val); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Feedback 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { FeedbackPage } from './app.po'; 2 | 3 | describe('feedback App', () => { 4 | let page: FeedbackPage; 5 | 6 | beforeEach(() => { 7 | page = new FeedbackPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule); 12 | -------------------------------------------------------------------------------- /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 | }; 9 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "baseUrl": "", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts", 15 | "polyfills.ts" 16 | ], 17 | "include": [ 18 | "**/*.spec.ts", 19 | "**/*.d.ts" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "target": "es5", 13 | "typeRoots": [ 14 | "node_modules/@types" 15 | ], 16 | "lib": [ 17 | "es2017", 18 | "dom" 19 | ], 20 | "paths": { 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FeedbackModule } from './feedback'; 4 | import { AppComponent } from './app.component'; 5 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; 6 | import {MatButtonModule} from '@angular/material'; 7 | @NgModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | imports: [ 12 | BrowserModule, 13 | FeedbackModule, 14 | BrowserAnimationsModule, 15 | MatButtonModule 16 | ], 17 | providers: [], 18 | bootstrap: [AppComponent] 19 | }) 20 | export class AppModule { } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /src/app/feedback/feedback-rectangle/feedback-rectangle.component.css: -------------------------------------------------------------------------------- 1 | .rect { 2 | position: fixed; 3 | background: none; 4 | z-index: 3; 5 | } 6 | .highlight:not(.noHover):hover { 7 | cursor: default; 8 | background: rgba(55, 131, 249, 0.2); 9 | } 10 | .hide { 11 | background-color: black; 12 | } 13 | .hide:not(.noHover):hover{ 14 | background-color: rgba(31, 31, 31, 0.75); 15 | } 16 | 17 | .rect .close { 18 | width: 24px; 19 | height: 24px; 20 | background: #FFF; 21 | border-radius: 50%; 22 | justify-content: center; 23 | align-items: center; 24 | color: #999; 25 | position: absolute; 26 | right: -12px; 27 | top: -12px; 28 | cursor: pointer; 29 | display: flex; 30 | user-select: none; 31 | } 32 | -------------------------------------------------------------------------------- /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/feedback/feedback-rectangle/feedback-rectangle.component.html: -------------------------------------------------------------------------------- 1 |
8 | 9 | 11 | 13 | 14 | 15 |
16 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/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: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /src/app/feedback/feedback-rectangle/feedback-rectangle.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, EventEmitter, HostListener, Input, Output} from '@angular/core'; 2 | import {Rectangle} from '../entity/rectangle'; 3 | import {FeedbackService} from '../feedback.service'; 4 | 5 | @Component({ 6 | selector: 'feedback-rectangle', 7 | templateUrl: './feedback-rectangle.component.html', 8 | styleUrls: ['./feedback-rectangle.component.css'] 9 | }) 10 | 11 | export class FeedbackRectangleComponent { 12 | @Input() 13 | public rectangle: Rectangle; 14 | @Input() 15 | public noHover: boolean; 16 | @Output() 17 | public close = new EventEmitter(); 18 | public showCloseTag: boolean = false; 19 | 20 | constructor(public feedbackService: FeedbackService) { 21 | } 22 | 23 | @HostListener('mouseenter') 24 | public onMouseEnter(): void { 25 | this.showCloseTag = this.noHover === false; 26 | } 27 | 28 | @HostListener('mouseleave') 29 | public onMouseLeave(): void { 30 | this.showCloseTag = false; 31 | } 32 | 33 | public onClose(): void { 34 | this.close.emit(); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | }).compileComponents(); 12 | })); 13 | 14 | it('should create the app', async(() => { 15 | const fixture = TestBed.createComponent(AppComponent); 16 | const app = fixture.debugElement.componentInstance; 17 | expect(app).toBeTruthy(); 18 | })); 19 | 20 | it(`should have as title 'app'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('app'); 24 | })); 25 | 26 | it('should render title in a h1 tag', async(() => { 27 | const fixture = TestBed.createComponent(AppComponent); 28 | fixture.detectChanges(); 29 | const compiled = fixture.debugElement.nativeElement; 30 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |

4 | Welcome to {{title}}!! 5 |

6 | 7 |
8 |

Here are some links to help you start:

9 | 23 | 24 |
25 | 26 |
27 | 28 |
29 | 30 |
31 |
32 | 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2017 RickonChen 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare const __karma__: any; 17 | declare const require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /src/app/feedback/feedback.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {CommonModule} from '@angular/common'; 3 | import {FormsModule} from '@angular/forms'; 4 | import {FeedbackDialogComponent} from './feedback-dialog/feedback-dialog.component'; 5 | import {FeedbackToolbarComponent} from './feedback-toolbar/feedback-toolbar.component'; 6 | import {FeedbackRectangleComponent} from './feedback-rectangle/feedback-rectangle.component'; 7 | import { 8 | MatDialogModule, 9 | MatButtonModule, 10 | MatIconModule, 11 | MatInputModule, 12 | MatTooltipModule, 13 | MatCheckboxModule, 14 | MatProgressSpinnerModule 15 | } from '@angular/material'; 16 | import {FeedbackService} from './feedback.service'; 17 | import {FeedbackDirective} from './feedback.directive'; 18 | 19 | @NgModule({ 20 | declarations: [ 21 | FeedbackDialogComponent, 22 | FeedbackToolbarComponent, 23 | FeedbackRectangleComponent, 24 | FeedbackDirective 25 | ], 26 | imports: [ 27 | MatDialogModule, 28 | MatButtonModule, 29 | MatIconModule, 30 | MatInputModule, 31 | MatTooltipModule, 32 | CommonModule, 33 | FormsModule, 34 | MatCheckboxModule, 35 | MatProgressSpinnerModule 36 | ], 37 | exports: [ 38 | FeedbackDirective 39 | ], 40 | entryComponents: [ 41 | FeedbackDialogComponent 42 | ], 43 | providers: [ 44 | FeedbackService 45 | ] 46 | }) 47 | export class FeedbackModule { 48 | } 49 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "feedback", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^6.1.10", 15 | "@angular/common": "^6.1.10", 16 | "@angular/compiler": "^6.1.10", 17 | "@angular/core": "^6.1.10", 18 | "@angular/forms": "^6.1.10", 19 | "@angular/http": "^6.1.10", 20 | "@angular/platform-browser": "^6.1.10", 21 | "@angular/platform-browser-dynamic": "^6.1.10", 22 | "@angular/router": "^6.1.10", 23 | "@angular/material": "^6.4.7", 24 | "@angular/cdk": "^6.4.7", 25 | "core-js": "^2.4.1", 26 | "html2canvas": "^1.0.0-alpha.12", 27 | "rxjs": "^6.3.3", 28 | "zone.js": "^0.8.26" 29 | }, 30 | "devDependencies": { 31 | "@angular-devkit/build-angular": "^0.10.5", 32 | "@angular-devkit/build-ng-packagr": "^0.10.5", 33 | "@angular/cli": "~6.2.4", 34 | "@angular/compiler-cli": "^6.1.0", 35 | "@angular/language-service": "^6.1.0", 36 | "@types/jasmine": "~2.8.8", 37 | "@types/jasminewd2": "~2.0.3", 38 | "@types/node": "~8.9.4", 39 | "codelyzer": "~4.3.0", 40 | "jasmine-core": "~2.99.1", 41 | "jasmine-spec-reporter": "~4.2.1", 42 | "karma": "^3.1.1", 43 | "karma-chrome-launcher": "~2.2.0", 44 | "karma-coverage-istanbul-reporter": "~2.0.1", 45 | "karma-jasmine": "~1.1.2", 46 | "karma-jasmine-html-reporter": "^0.2.2", 47 | "ng-packagr": "^4.4.0", 48 | "protractor": "~5.4.0", 49 | "ts-node": "~7.0.0", 50 | "tsickle": ">=0.29.0", 51 | "tslib": "^1.9.0", 52 | "tslint": "~5.11.0", 53 | "typescript": "~2.9.2" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/app/feedback/feedback-toolbar/feedback-toolbar.component.css: -------------------------------------------------------------------------------- 1 | .toolbar { 2 | align-items: center; 3 | background-color: white; 4 | border-radius: 2px; 5 | box-shadow: rgba(0, 0, 0, 0.14) 0px 24px 38px 3px, rgba(0, 0, 0, 0.12) 0px 9px 46px 8px, rgba(0, 0, 0, 0.2) 0px 11px 15px -7px; 6 | cursor: pointer; 7 | display: -webkit-inline-flex; 8 | flex-direction: row; 9 | height: 56px; 10 | min-width: 232px; 11 | pointer-events: auto; 12 | overflow: visible; 13 | position: absolute; 14 | margin: 0 auto; 15 | width: 228px; 16 | bottom: 0; 17 | top: 25%; 18 | left: 0; 19 | right: 0; 20 | z-index: 999; 21 | } 22 | 23 | .move-toolbar { 24 | cursor: -webkit-grab; 25 | height: 56px; 26 | padding: 0px 12px; 27 | position: relative; 28 | } 29 | 30 | .move-toolbar:active { 31 | cursor: -webkit-grabbing; 32 | } 33 | 34 | .toggle { 35 | display: inline-block; 36 | position: relative; 37 | height: 36px; 38 | width: 36px; 39 | } 40 | 41 | .toggle-decorator { 42 | left: 0px; 43 | position: absolute; 44 | top: 0px; 45 | } 46 | 47 | .highlight-toggle { 48 | align-items: center; 49 | background-color: rgb(255, 255, 255); 50 | border: none; 51 | box-sizing: border-box; 52 | cursor: pointer; 53 | display: -webkit-flex; 54 | justify-content: center; 55 | outline: none; 56 | padding: 10px; 57 | pointer-events: auto; 58 | position: relative; 59 | height: 56px; 60 | width: 56px; 61 | } 62 | 63 | .deepen-color { 64 | background-color: rgb(224, 224, 224) !important; 65 | } 66 | 67 | .hide-toggle { 68 | align-items: center; 69 | background-color: rgb(255, 255, 255); 70 | border: none; 71 | box-sizing: border-box; 72 | cursor: pointer; 73 | display: -webkit-flex; 74 | justify-content: center; 75 | outline: none; 76 | padding: 10px; 77 | pointer-events: auto; 78 | position: relative; 79 | height: 56px; 80 | width: 56px; 81 | } 82 | 83 | .merge-button { 84 | padding: 0 !important; 85 | margin: 0 10px 0 10px !important; 86 | min-width: 56px; 87 | color: #4285f4; 88 | } 89 | -------------------------------------------------------------------------------- /src/app/feedback/feedback-dialog/feedback-dialog.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | {{vars['title']}} 5 |
6 |
7 |
8 |
9 |
{{vars['placeholder']}}
10 |
11 | 16 |
17 |
18 | {{vars['checkboxLabel']}} 19 |
20 | 21 |
22 | 23 |
24 |
25 | 26 | 28 | 29 | {{vars['editTip']}} 30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 |
38 |
39 |
40 | {{vars['drawRectTip']}} 41 |
42 | 43 | 44 |
45 |
46 | 47 | 48 |
49 | 50 | -------------------------------------------------------------------------------- /src/app/feedback/feedback.directive.ts: -------------------------------------------------------------------------------- 1 | import {Directive, HostListener, EventEmitter, Output, Input, OnInit} from '@angular/core'; 2 | import {MatDialog} from '@angular/material'; 3 | import {FeedbackDialogComponent} from './feedback-dialog/feedback-dialog.component'; 4 | import {FeedbackService} from './feedback.service'; 5 | import {Overlay} from '@angular/cdk/overlay'; 6 | 7 | @Directive({selector: '[feedback]'}) 8 | export class FeedbackDirective implements OnInit { 9 | private overlay: Overlay; 10 | @Input() title: string = 'Send feedback'; 11 | @Input() placeholder: string = 'Describe your issue or share your ideas'; 12 | @Input() editTip = 'Click to highlight or hide info'; 13 | @Input() checkboxLabel = 'Include screenshot'; 14 | @Input() cancelLabel = 'CANCEL'; 15 | @Input() sendLabel = 'SEND'; 16 | @Input() moveToolbarTip = 'move toolbar'; 17 | @Input() drawRectTip = 'Draw using yellow to highlight issues or black to hide sensitive info'; 18 | @Input() highlightTip = 'highlight issues'; 19 | @Input() hideTip = 'hide sensitive info'; 20 | @Input() editDoneLabel = 'DONE'; 21 | @Output() public send = new EventEmitter(); 22 | 23 | public constructor(private dialogRef: MatDialog, private feedbackService: FeedbackService, overlay: Overlay) { 24 | this.feedbackService.feedback$.subscribe( 25 | (feedback) => { 26 | this.send.emit(feedback); 27 | } 28 | ); 29 | this.overlay = overlay; 30 | } 31 | 32 | @HostListener('click') 33 | public onClick() { 34 | this.openFeedbackDialog(); 35 | } 36 | 37 | public openFeedbackDialog() { 38 | this.feedbackService.initScreenshotCanvas(); 39 | const dialogRef = this.dialogRef.open(FeedbackDialogComponent, { 40 | panelClass: 'feedbackDialog', 41 | backdropClass: 'dialogBackDrop', 42 | disableClose: true, 43 | height: 'auto', 44 | width: 'auto', 45 | scrollStrategy: this.overlay.scrollStrategies.reposition() 46 | }); 47 | } 48 | 49 | ngOnInit(): void { 50 | this.feedbackService.initialVariables = { 51 | title: this.title, 52 | placeholder: this.placeholder, 53 | editTip: this.editTip, 54 | checkboxLabel: this.checkboxLabel, 55 | cancelLabel: this.cancelLabel, 56 | sendLabel: this.sendLabel, 57 | moveToolbarTip: this.moveToolbarTip, 58 | drawRectTip: this.drawRectTip, 59 | highlightTip: this.highlightTip, 60 | hideTip: this.hideTip, 61 | editDoneLabel: this.editDoneLabel 62 | }; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** Evergreen browsers require these. **/ 41 | import 'core-js/es6/reflect'; 42 | import 'core-js/es7/reflect'; 43 | 44 | 45 | /** 46 | * Required to support Web Animations `@angular/animation`. 47 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 48 | **/ 49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 50 | 51 | 52 | 53 | /*************************************************************************************************** 54 | * Zone JS is required by Angular itself. 55 | */ 56 | import 'zone.js/dist/zone'; // Included with Angular CLI. 57 | 58 | 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | 64 | /** 65 | * Date, currency, decimal and percent pipes. 66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 67 | */ 68 | // import 'intl'; // Run `npm install --save intl`. 69 | /** 70 | * Need to import at least one locale-data with intl. 71 | */ 72 | // import 'intl/locale-data/jsonp/en'; 73 | -------------------------------------------------------------------------------- /src/app/feedback/feedback-toolbar/feedback-toolbar.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 28 | 42 | 43 |
44 | -------------------------------------------------------------------------------- /src/app/feedback/feedback.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import html2canvas from 'html2canvas'; 3 | import {Subject, Observable} from 'rxjs'; 4 | import {Feedback} from './entity/feedback'; // import Observable to solve build issue 5 | 6 | @Injectable() 7 | export class FeedbackService { 8 | public initialVariables: object = {}; 9 | public highlightedColor = 'yellow'; 10 | public hiddenColor = 'black'; 11 | private screenshotCanvasSource = new Subject(); 12 | public screenshotCanvas$: Observable = this.screenshotCanvasSource.asObservable(); 13 | 14 | private feedbackSource = new Subject(); 15 | public feedback$: Observable = this.feedbackSource.asObservable(); 16 | 17 | private isDraggingToolbarSource = new Subject(); 18 | public isDraggingToolbar$: Observable = this.isDraggingToolbarSource.asObservable(); 19 | 20 | 21 | public initScreenshotCanvas() { 22 | const that = this; 23 | const body = document.body; 24 | html2canvas(body, { 25 | logging: false, 26 | width: document.documentElement.clientWidth, 27 | height: document.documentElement.clientHeight, 28 | x: document.documentElement.scrollLeft, 29 | y: document.documentElement.scrollTop, 30 | allowTaint : true 31 | }).then(bodyCanvas => { 32 | this.screenshotCanvasSource.next(bodyCanvas); 33 | }); 34 | } 35 | 36 | public setCanvas(canvas: HTMLCanvasElement): void { 37 | this.screenshotCanvasSource.next(canvas); 38 | } 39 | 40 | public setFeedback(feedback: Feedback): void { 41 | this.feedbackSource.next(feedback); 42 | } 43 | 44 | public setIsDraggingToolbar(isDragging: boolean): void { 45 | this.isDraggingToolbarSource.next(isDragging); 46 | } 47 | 48 | public getImgEle(canvas): HTMLElement { 49 | const img = canvas.toDataURL('image/png'), 50 | imageEle = document.createElement('img'); 51 | imageEle.setAttribute('src', img); 52 | Object.assign(imageEle.style, { 53 | position: 'absolute', 54 | top: '50%', 55 | right: '0', 56 | left: '0', 57 | margin: '0 auto', 58 | maxHeight: '100%', 59 | maxWidth: '100%', 60 | transform: 'translateY(-50%)' 61 | }); 62 | return imageEle; 63 | } 64 | 65 | public hideBackDrop() { 66 | const dialogBackDrop = document.getElementsByClassName('dialogBackDrop')[0] as HTMLElement; 67 | dialogBackDrop.style.backgroundColor = 'initial'; 68 | } 69 | 70 | public showBackDrop() { 71 | const dialogBackDrop = document.getElementsByClassName('dialogBackDrop')[0] as HTMLElement; 72 | if (!dialogBackDrop.getAttribute('data-html2canvas-ignore')) { 73 | dialogBackDrop.setAttribute('data-html2canvas-ignore', 'true'); 74 | } 75 | dialogBackDrop.style.backgroundColor = 'rgba(0, 0, 0, .288)'; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/app/feedback/feedback-toolbar/feedback-toolbar.component.ts: -------------------------------------------------------------------------------- 1 | import {fromEvent as observableFromEvent} from 'rxjs'; 2 | 3 | import {takeUntil, finalize, map, mergeMap} from 'rxjs/operators'; 4 | import {Component, ElementRef, Input, Output, EventEmitter, AfterViewInit, ViewChild, OnChanges} from '@angular/core'; 5 | import {FeedbackService} from '../feedback.service'; 6 | 7 | 8 | @Component({ 9 | selector: 'feedback-toolbar', 10 | templateUrl: './feedback-toolbar.component.html', 11 | styleUrls: ['./feedback-toolbar.component.css'] 12 | }) 13 | 14 | export class FeedbackToolbarComponent implements AfterViewInit, OnChanges { 15 | @Input() 16 | public drawColor: string; 17 | @Output() 18 | public manipulate = new EventEmitter(); 19 | public disableToolbarTips = false; 20 | @ViewChild('toggleMove') 21 | private toggleMoveBtn: ElementRef; 22 | public isSwitch = false; 23 | public isDragging = false; 24 | public vars: object = {}; 25 | 26 | constructor(public el: ElementRef, private feedbackService: FeedbackService) { 27 | this.vars = feedbackService.initialVariables; 28 | } 29 | 30 | public ngAfterViewInit() { 31 | const elStyle = this.el.nativeElement.style; 32 | elStyle.position = 'absolute'; 33 | elStyle.left = '43%'; 34 | elStyle.top = '60%'; 35 | this.addDragListenerOnMoveBtn(); 36 | } 37 | 38 | public ngOnChanges() { 39 | this.isSwitch = this.drawColor !== this.feedbackService.highlightedColor; 40 | } 41 | 42 | public done() { 43 | this.manipulate.emit('done'); 44 | } 45 | 46 | public toggleHighlight() { 47 | this.isSwitch = false; 48 | this.manipulate.emit(this.feedbackService.highlightedColor); 49 | } 50 | 51 | public toggleHide() { 52 | this.isSwitch = true; 53 | this.manipulate.emit(this.feedbackService.hiddenColor); 54 | } 55 | 56 | public addDragListenerOnMoveBtn() { 57 | const mouseUp = observableFromEvent(this.toggleMoveBtn.nativeElement, 'mouseup'); 58 | const mouseMove = observableFromEvent(document.documentElement, 'mousemove'); 59 | const mouseDown = observableFromEvent(this.toggleMoveBtn.nativeElement, 'mousedown'); 60 | const mouseDrag = mouseDown.pipe(mergeMap((md: MouseEvent) => { 61 | this.feedbackService.setIsDraggingToolbar(true); 62 | const startX = md.offsetX; 63 | const startY = md.offsetY; 64 | this.disableToolbarTips = true; 65 | this.isDragging = true; 66 | // Calculate dif with mousemove until mouseup 67 | return mouseMove.pipe( 68 | map((mm: MouseEvent) => { 69 | mm.preventDefault(); 70 | return { 71 | left: mm.clientX - startX, 72 | top: mm.clientY - startY 73 | }; 74 | }), 75 | finalize(() => { 76 | this.isDragging = false; 77 | this.disableToolbarTips = false; 78 | this.feedbackService.setIsDraggingToolbar(false); 79 | }), 80 | takeUntil(mouseUp)); 81 | })); 82 | mouseDrag.subscribe( 83 | (pos) => { 84 | this.el.nativeElement.style.left = pos.left + 'px'; 85 | this.el.nativeElement.style.top = pos.top + 'px'; 86 | }); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | false, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": false, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "component-class-suffix": true, 129 | "directive-class-suffix": true 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # feedback 2 | > An angular directive for sending feedback featuring [Angular 6](https://angular.io), [Html2canvas](https://html2canvas.hertzen.com/), [Angular Material](https://material.angular.io), [Rxjs](https://rxjs-dev.firebaseapp.com/), inspired by Google send feedback, based on [angular-cli](https://github.com/angular/angular-cli). 3 | 4 | ## Demo 5 | ![Alt text](/../screenshots/feedback.gif?raw=true "overview") 6 | 7 | ### Prerequisites 8 | make sure your project: 9 | * is an angular(version >= 6.0.0) project 10 | * has set up [angular material](https://github.com/angular/material2/blob/master/guides/getting-started.md) 11 | 12 | #### How to use it in your project 13 | > download it from npm 14 | 15 | ```bash 16 | npm install ng-feedback --save 17 | ``` 18 | 19 | use the feedback module in your project, at any module, you just need to imports into your module: 20 | ```es6 21 | import { FeedbackModule } from 'ng-feedback' 22 | ``` 23 | 24 | easy to use the directive, just add it in a html tag, such as: 25 | ``` 26 | 27 | ``` 28 | 29 | #### Properties 30 | 31 | | Name | Default Value | 32 | |------------------|-----------------------------------------------------------------------| 33 | | `title` | Send feedback | 34 | | `placeholder` | Describe your issue or share your ideas | 35 | | `editTip` | Click to highlight or hide info | 36 | | `checkboxLabel` | Include screenshot | 37 | | `cancelLabel` | CANCEL | 38 | | `sendLabel` | SEND | 39 | | `moveToolbarTip` | move toolbar | 40 | | `drawRectTip` | Draw using yellow to highlight issues or black to hide sensitive info | 41 | | `highlightTip` | highlight issues | 42 | | `hideTip` | hide sensitive info | 43 | | `editDoneLabel` | DONE | 44 | 45 | ### method 46 | 47 | ``` 48 | send(feedback) 49 | ``` 50 | 51 | it is an output of the directive, the usage is: 52 | 53 | ``` 54 | 58 | ``` 59 | Then you can custom the onSend method in your component. 60 | The param feedback is an object contains two properties: description and screenshot. 61 | * description is string to describe issues or ideas 62 | * screenshot comes from HTMLCanvasElement.toDataURL('image/png'), can be used as src of an img tag. 63 | 64 | ### Getting started with this repo 65 | **Make sure you have Node version >= 8.0 and NPM >= 5** 66 | > Clone/Download the repo then edit feedback library inside [`/src/app/feedback`](/src/app/feedback) 67 | 68 | ```bash 69 | # clone repo 70 | git clone https://github.com/RickonChen/feedback.git 71 | 72 | # change directory to our repo 73 | cd feedback 74 | 75 | # install the repo with npm 76 | npm install 77 | 78 | # start the server 79 | npm start 80 | 81 | # if you're in China use cnpm 82 | # https://github.com/cnpm/cnpm 83 | ``` 84 | go to [http://127.0.0.1:4200](http://127.0.0.1:4200) or [http://localhost:4200](http://localhost:4200) in your browser 85 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "feedback": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "architect": { 11 | "build": { 12 | "builder": "@angular-devkit/build-angular:browser", 13 | "options": { 14 | "outputPath": "dist", 15 | "index": "src/index.html", 16 | "main": "src/main.ts", 17 | "tsConfig": "src/tsconfig.app.json", 18 | "polyfills": "src/polyfills.ts", 19 | "assets": [ 20 | "src/assets", 21 | "src/favicon.ico" 22 | ], 23 | "styles": [ 24 | "src/styles.css" 25 | ], 26 | "scripts": [] 27 | }, 28 | "configurations": { 29 | "production": { 30 | "optimization": true, 31 | "outputHashing": "all", 32 | "sourceMap": false, 33 | "extractCss": true, 34 | "namedChunks": false, 35 | "aot": true, 36 | "extractLicenses": true, 37 | "vendorChunk": false, 38 | "buildOptimizer": true, 39 | "fileReplacements": [ 40 | { 41 | "replace": "src/environments/environment.ts", 42 | "with": "src/environments/environment.prod.ts" 43 | } 44 | ] 45 | } 46 | } 47 | }, 48 | "serve": { 49 | "builder": "@angular-devkit/build-angular:dev-server", 50 | "options": { 51 | "browserTarget": "feedback:build" 52 | }, 53 | "configurations": { 54 | "production": { 55 | "browserTarget": "feedback:build:production" 56 | } 57 | } 58 | }, 59 | "extract-i18n": { 60 | "builder": "@angular-devkit/build-angular:extract-i18n", 61 | "options": { 62 | "browserTarget": "feedback:build" 63 | } 64 | }, 65 | "test": { 66 | "builder": "@angular-devkit/build-angular:karma", 67 | "options": { 68 | "main": "src/test.ts", 69 | "karmaConfig": "./karma.conf.js", 70 | "polyfills": "src/polyfills.ts", 71 | "tsConfig": "src/tsconfig.spec.json", 72 | "scripts": [], 73 | "styles": [ 74 | "src/styles.css" 75 | ], 76 | "assets": [ 77 | "src/assets", 78 | "src/favicon.ico" 79 | ] 80 | } 81 | }, 82 | "lint": { 83 | "builder": "@angular-devkit/build-angular:tslint", 84 | "options": { 85 | "tsConfig": [ 86 | "src/tsconfig.app.json", 87 | "src/tsconfig.spec.json" 88 | ], 89 | "exclude": [] 90 | } 91 | } 92 | } 93 | }, 94 | "feedback-e2e": { 95 | "root": "e2e", 96 | "sourceRoot": "e2e", 97 | "projectType": "application", 98 | "architect": { 99 | "e2e": { 100 | "builder": "@angular-devkit/build-angular:protractor", 101 | "options": { 102 | "protractorConfig": "./protractor.conf.js", 103 | "devServerTarget": "feedback:serve" 104 | } 105 | }, 106 | "lint": { 107 | "builder": "@angular-devkit/build-angular:tslint", 108 | "options": { 109 | "tsConfig": [ 110 | "e2e/tsconfig.e2e.json" 111 | ], 112 | "exclude": [] 113 | } 114 | } 115 | } 116 | } 117 | }, 118 | "defaultProject": "feedback", 119 | "schematics": { 120 | "@schematics/angular:component": { 121 | "prefix": "app", 122 | "styleext": "css" 123 | }, 124 | "@schematics/angular:directive": { 125 | "prefix": "app" 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/app/feedback/feedback-dialog/feedback-dialog.component.css: -------------------------------------------------------------------------------- 1 | .dialog { 2 | z-index: 1000; 3 | position: relative; 4 | width: 360px; 5 | background-color: white; 6 | } 7 | 8 | .dialog-title { 9 | background-color: rgb(96, 125, 139); 10 | color: #ffffff; 11 | height: 56px; 12 | } 13 | 14 | .title-font { 15 | color: white; 16 | float: left; 17 | font-style: normal; 18 | font-variant: normal; 19 | font-weight: 300; 20 | font-stretch: normal; 21 | font-size: 20px; 22 | line-height: 56px; 23 | font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif; 24 | padding: 0px 16px; 25 | margin: 0px; 26 | } 27 | 28 | .dialog-content { 29 | display: -webkit-flex; 30 | flex-grow: 1; 31 | height: 200px; 32 | position: relative; 33 | } 34 | 35 | .description { 36 | border: none; 37 | box-sizing: border-box; 38 | box-shadow: none; 39 | color: rgb(33, 33, 33); 40 | flex-grow: 1; 41 | font-style: normal; 42 | font-variant: normal; 43 | font-weight: 400; 44 | font-stretch: normal; 45 | font-size: 16px; 46 | line-height: normal; 47 | font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif; 48 | max-width: 100%; 49 | outline: none; 50 | padding: 18px 16px 0px; 51 | resize: none; 52 | width: 100%; 53 | height: inherit; 54 | } 55 | 56 | .description-tips { 57 | color: rgb(189, 189, 189); 58 | display: block; 59 | font-style: normal; 60 | font-variant: normal; 61 | font-weight: 400; 62 | font-stretch: normal; 63 | font-size: 16px; 64 | line-height: normal; 65 | font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif; 66 | left: 0px; 67 | position: absolute; 68 | padding: 18px 16px 0px; 69 | right: 0px; 70 | } 71 | 72 | .screenshot-checkbox { 73 | padding: 0 16px 0 16px; 74 | background-color: #f8f8f8; 75 | height: 40px; 76 | display: flex; 77 | flex-direction: column; 78 | justify-content: center; 79 | } 80 | 81 | .screenshot-content { 82 | border: none; 83 | cursor: pointer; 84 | text-align: center; 85 | display: block; 86 | position: relative; 87 | padding: 0; 88 | overflow: hidden; 89 | height: 192px; 90 | width: 100%; 91 | background: rgb(237, 237, 237) none; 92 | } 93 | 94 | .screenshot-tips { 95 | align-items: center; 96 | background-color: rgba(248, 248, 248, 0.6); 97 | border-radius: 4px; 98 | box-sizing: border-box; 99 | display: -webkit-flex; 100 | flex-direction: column; 101 | justify-content: center; 102 | min-height: 112px; 103 | width: 224px; 104 | z-index: 5; 105 | position: absolute; 106 | top: 50%; 107 | right: 0; 108 | bottom: 0; 109 | left: 0; 110 | transform: translateY(-50%); 111 | margin: 0 auto; 112 | } 113 | 114 | .screenshot-content:hover .screenshot-tips { 115 | background-color: rgba(248, 248, 248, 0.8); 116 | } 117 | 118 | .screenshot-content:hover .screenshot-tips-content { 119 | color: rgb(66, 133, 244); 120 | } 121 | 122 | .screenshot-content:hover svg { 123 | color: #4285f4; 124 | fill: currentColor; 125 | } 126 | 127 | .screenshot-tips svg { 128 | color: #757575; 129 | fill: currentColor; 130 | height: 48px; 131 | width: 48px; 132 | } 133 | 134 | .screenshot-tips-content { 135 | color: rgb(117, 117, 117); 136 | font-weight: 400; 137 | font-size: 14px; 138 | line-height: 20px; 139 | font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif; 140 | margin-top: 12px; 141 | } 142 | 143 | .dialog-actions { 144 | border-top: 1px solid rgb(224, 224, 224); 145 | } 146 | 147 | .submit-button { 148 | margin-right: 8px !important; 149 | margin-left: 5px !important; 150 | color: rgb(66, 133, 244); 151 | } 152 | 153 | .action-button { 154 | font-style: normal; 155 | font-variant: normal; 156 | font-weight: 500; 157 | font-stretch: normal; 158 | font-size: 14px; 159 | height: 35px; 160 | line-height: normal; 161 | margin: 10px 0; 162 | padding: 0 8px 0 8px; 163 | position: relative; 164 | min-width: 75px; 165 | } 166 | 167 | .loading { 168 | margin: 0 auto; 169 | position: absolute; 170 | top: 45%; 171 | bottom: 0; 172 | left: 0; 173 | right: 0; 174 | } 175 | 176 | .mat-dialog-actions { 177 | padding: 0 !important; 178 | } 179 | 180 | ::ng-deep .feedbackDialog .mat-dialog-container { 181 | padding: 0; 182 | overflow: visible; 183 | background-color: rgba(255, 255, 255, 0); 184 | box-shadow: initial; 185 | } 186 | 187 | .toolbar-tips { 188 | background-color: rgba(255, 255, 255, 0.6); 189 | border-radius: 12px; 190 | color: rgb(117, 117, 117); 191 | font-style: normal; 192 | font-variant: normal; 193 | font-weight: 400; 194 | font-stretch: normal; 195 | font-size: 34px; 196 | line-height: 40px; 197 | font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif; 198 | margin-bottom: 72px; 199 | padding: 22px 0px; 200 | text-align: center; 201 | visibility: visible; 202 | width: 656px; 203 | height: auto; 204 | -moz-animation: cssAnimation 0s ease-in 5s forwards; 205 | /* Firefox */ 206 | -webkit-animation: cssAnimation 0s ease-in 5s forwards; 207 | /* Safari and Chrome */ 208 | -o-animation: cssAnimation 0s ease-in 5s forwards; 209 | /* Opera */ 210 | animation: cssAnimation 0s ease-in 5s forwards; 211 | -webkit-animation-fill-mode: forwards; 212 | animation-fill-mode: forwards; 213 | } 214 | 215 | @keyframes cssAnimation { 216 | to { 217 | width: 0; 218 | height: 0; 219 | overflow: hidden; 220 | } 221 | } 222 | 223 | @-webkit-keyframes cssAnimation { 224 | to { 225 | width: 0; 226 | height: 0; 227 | visibility: hidden; 228 | } 229 | } 230 | 231 | .drawCanvas{ 232 | position: absolute; 233 | top: 0; 234 | left: 0; 235 | z-index: -1; 236 | margin: 0 auto; 237 | cursor: crosshair; 238 | } 239 | 240 | .pointerCursor{ 241 | cursor: default!important; 242 | } 243 | -------------------------------------------------------------------------------- /src/app/feedback/feedback-dialog/feedback-dialog.component.ts: -------------------------------------------------------------------------------- 1 | import {from, fromEvent as observableFromEvent, Observable, Subscription} from 'rxjs'; 2 | 3 | import {takeUntil, finalize, map, mergeMap, timeout, skipWhile, filter, scan, first} from 'rxjs/operators'; 4 | import {Component, AfterViewInit, ViewChild, ElementRef, ChangeDetectorRef, HostListener, Renderer2} from '@angular/core'; 5 | import {MatDialogRef} from '@angular/material'; 6 | import {Feedback} from '../entity/feedback'; 7 | import {FeedbackService} from '../feedback.service'; 8 | 9 | import {Rectangle} from '../entity/rectangle'; 10 | import {element} from 'protractor'; 11 | 12 | @Component({ 13 | selector: 'feedback-dialog', 14 | templateUrl: './feedback-dialog.component.html', 15 | styleUrls: ['./feedback-dialog.component.css'] 16 | }) 17 | 18 | export class FeedbackDialogComponent implements AfterViewInit { 19 | public showToolbar = false; 20 | public vars: object = {}; 21 | public feedback = new Feedback(); 22 | public includeScreenshot: boolean = true; 23 | public showSpinner = true; 24 | public screenshotEle: HTMLElement; 25 | public drawCanvas: HTMLCanvasElement; 26 | public showToolbarTips: boolean = true; 27 | @ViewChild('screenshotParent') 28 | public screenshotParent: ElementRef; 29 | public drawColor: string = this.feedbackService.highlightedColor; 30 | public rectangles: Rectangle[] = []; 31 | private scrollWidth = document.documentElement.scrollWidth; 32 | private scrollHeight = document.documentElement.scrollHeight; 33 | private elCouldBeHighlighted = ['button', 'a', 'span', 'em', 'i', 'h1', 'h2', 'h3', 'h4', 34 | 'h5', 'h6', 'p', 'strong', 'small', 'sub', 'sup', 'b', 'time', 'img', 35 | 'video', 'input', 'label', 'select', 'textarea', 'article', 'summary', 'section']; 36 | // the flag field 'isManuallyDrawRect' to solve conflict between manually draw and auto draw 37 | private manuallyDrawRect$: Subscription; 38 | private autoDrawRect$: Subscription; 39 | public isDrawingRect: boolean = false; 40 | 41 | constructor(public dialogRef: MatDialogRef, 42 | private feedbackService: FeedbackService, 43 | private detector: ChangeDetectorRef, 44 | private el: ElementRef) { 45 | this.feedback = new Feedback(); 46 | this.feedback.description = ''; 47 | this.vars = this.feedbackService.initialVariables; 48 | } 49 | 50 | public ngAfterViewInit() { 51 | this.feedbackService.screenshotCanvas$.subscribe((canvas) => { 52 | this.showSpinner = false; 53 | this.feedback.screenshot = canvas.toDataURL('image/png'); 54 | this.screenshotEle = this.feedbackService.getImgEle(canvas); 55 | this.appendScreenshot(); 56 | }); 57 | 58 | this.feedbackService.isDraggingToolbar$.subscribe((isDragging) => { 59 | if (isDragging) { 60 | this.destroyCanvasListeners(); 61 | } else { 62 | this.addCanvasListeners(); 63 | } 64 | }); 65 | 66 | this.dialogRef.afterClosed().subscribe((sendNow) => { 67 | if (sendNow === true) { 68 | this.feedbackService.setFeedback(this.feedback); 69 | } 70 | }); 71 | this.feedbackService.showBackDrop(); 72 | } 73 | 74 | public expandDrawingBoard() { 75 | this.showToolbar = true; 76 | if (!this.drawCanvas) { 77 | this.detector.detectChanges(); 78 | this.initBackgroundCanvas(); 79 | this.feedbackService.hideBackDrop(); 80 | } 81 | this.addCanvasListeners(); 82 | this.el.nativeElement.appendChild(this.drawCanvas); 83 | this.feedbackService.hideBackDrop(); 84 | console.log('expand the board'); 85 | } 86 | 87 | @HostListener('document:keydown.escape', ['$event']) 88 | public onEscapeKeyDownHandler(evt: KeyboardEvent) { 89 | this.showToolbar = false; 90 | this.includeScreenshot = true; 91 | this.detector.detectChanges(); 92 | this.dialogRef.close('key down esc to close'); 93 | } 94 | 95 | public manipulate(manipulation: string) { 96 | if (manipulation === 'done') { 97 | this.showToolbarTips = false; 98 | this.showSpinner = true; 99 | this.destroyCanvasListeners(); 100 | this.showToolbar = false; 101 | this.detector.detectChanges(); 102 | this.feedbackService.initScreenshotCanvas(); 103 | } else { 104 | this.startDraw(manipulation); 105 | } 106 | } 107 | 108 | public startDraw(color: string) { 109 | this.drawColor = color; 110 | } 111 | 112 | public isIncludeScreenshot() { 113 | if (this.includeScreenshot) { 114 | this.detector.detectChanges(); 115 | this.showSpinner = false; 116 | this.appendScreenshot(); 117 | this.feedback.screenshot = this.screenshotEle.getAttribute('src'); 118 | } else { 119 | delete this.feedback['screenshot']; 120 | this.showSpinner = true; 121 | } 122 | } 123 | 124 | private appendScreenshot() { 125 | if (this.screenshotParent) { this.screenshotParent.nativeElement.appendChild(this.screenshotEle); } 126 | } 127 | 128 | private initBackgroundCanvas() { 129 | this.drawCanvas = document.getElementById('draw-canvas') as HTMLCanvasElement; 130 | // The canvas to draw, must use this way to initial the height and width 131 | this.drawCanvas.style.height = this.scrollHeight + ''; 132 | this.drawCanvas.style.width = this.scrollWidth + ''; 133 | this.drawCanvas.height = this.scrollHeight; 134 | this.drawCanvas.width = this.scrollWidth; 135 | this.drawContainerRect(); 136 | } 137 | 138 | private drawContainerRect() { 139 | const drawContext = this.drawCanvas.getContext('2d'), 140 | width = this.scrollWidth, 141 | height = this.scrollHeight; 142 | drawContext.beginPath(); 143 | drawContext.fillStyle = 'rgba(0,0,0,0.3)'; 144 | drawContext.clearRect(0, 0, width, height); 145 | drawContext.fillRect(0, 0, width, height); // draw the rectangle 146 | } 147 | 148 | private drawRectangle(rect: Rectangle) { 149 | const context = this.drawCanvas.getContext('2d'); 150 | context.lineJoin = 'round'; 151 | context.beginPath(); 152 | if (rect.color === this.feedbackService.hiddenColor) { 153 | context.fillStyle = 'rgba(31, 31, 31, 0.75)'; 154 | context.fillRect(rect.startX, rect.startY, rect.width, rect.height); 155 | context.rect(rect.startX, rect.startY, rect.width, rect.height); 156 | } else { 157 | context.clearRect(rect.startX, rect.startY, rect.width, rect.height); 158 | context.lineWidth = 5; 159 | context.strokeStyle = rect.color; 160 | context.rect(rect.startX, rect.startY, rect.width, rect.height); 161 | context.stroke(); 162 | context.clearRect(rect.startX, rect.startY, rect.width, rect.height); 163 | this.rectangles.forEach(tmpRect => { 164 | if (tmpRect.color === this.feedbackService.highlightedColor) { 165 | context.clearRect(tmpRect.startX, tmpRect.startY, tmpRect.width, tmpRect.height); 166 | } 167 | }); 168 | } 169 | } 170 | 171 | private addCanvasListeners(): void { 172 | const mouseUp = observableFromEvent(document.documentElement, 'mouseup'), 173 | mouseMove = observableFromEvent(document.documentElement, 'mousemove'), 174 | mouseDown = observableFromEvent(document.documentElement, 'mousedown'), 175 | scroll = observableFromEvent(window, 'scroll'); 176 | 177 | this.manuallyDrawRect(mouseDown, mouseMove, mouseUp); 178 | this.autoDrawRect(mouseMove); 179 | this.changeRectPosition(scroll); 180 | } 181 | 182 | private changeRectPosition(scroll: Observable) { 183 | scroll.subscribe( 184 | event => { 185 | const currentWindowScrollX = window.scrollX, 186 | currentWindowScrollY = window.scrollY; 187 | this.rectangles.forEach(rect => { 188 | rect.startY = rect.startY - (currentWindowScrollY - rect.windowScrollY); 189 | rect.startX = rect.startX - (currentWindowScrollX - rect.windowScrollX); 190 | rect.windowScrollY = currentWindowScrollY; 191 | rect.windowScrollX = currentWindowScrollX; 192 | }); 193 | this.drawPersistCanvasRectangles(); 194 | }, 195 | error => console.error(error) 196 | ); 197 | } 198 | 199 | private destroyCanvasListeners(): void { 200 | if (this.manuallyDrawRect$) { this.manuallyDrawRect$.unsubscribe(); } 201 | if (this.autoDrawRect$) { this.autoDrawRect$.unsubscribe(); } 202 | } 203 | 204 | private manuallyDrawRect(mouseDown: Observable, mouseMove: Observable, mouseUp: Observable): void { 205 | const mouseDrag = mouseDown.pipe(mergeMap((mouseDownEvent: MouseEvent) => { 206 | if (this.showToolbarTips) { this.showToolbarTips = false; } 207 | this.autoDrawRect$.unsubscribe(); 208 | this.isDrawingRect = true; 209 | 210 | const newRectangle = new Rectangle(); 211 | newRectangle.startX = mouseDownEvent.clientX; 212 | newRectangle.startY = mouseDownEvent.clientY; 213 | newRectangle.color = this.drawColor; 214 | 215 | return mouseMove.pipe( 216 | map((mouseMoveEvent: MouseEvent) => { 217 | newRectangle.width = mouseMoveEvent.clientX - mouseDownEvent.clientX; 218 | newRectangle.height = mouseMoveEvent.clientY - mouseDownEvent.clientY; 219 | return newRectangle; 220 | }), 221 | finalize(() => { 222 | // click to draw rectangle 223 | if (newRectangle.width === undefined || newRectangle.height === undefined || 224 | newRectangle.width === 0 || newRectangle.height === 0) { 225 | const rect = this.drawTempCanvasRectangle(mouseDownEvent); 226 | if (rect) { this.rectangles.push(rect); } 227 | } else { 228 | // drag to draw rectangle 229 | if (newRectangle.height < 0) { 230 | newRectangle.startY = newRectangle.startY + newRectangle.height; 231 | newRectangle.height = Math.abs(newRectangle.height); 232 | } 233 | if (newRectangle.width < 0) { 234 | newRectangle.startX = newRectangle.startX + newRectangle.width; 235 | newRectangle.width = Math.abs(newRectangle.width); 236 | } 237 | this.rectangles.push(newRectangle); 238 | } 239 | this.drawPersistCanvasRectangles(); 240 | this.autoDrawRect(mouseMove); 241 | this.isDrawingRect = false; 242 | }), 243 | takeUntil(mouseUp)); 244 | })); 245 | 246 | this.manuallyDrawRect$ = mouseDrag.subscribe( 247 | (rec) => { 248 | this.drawPersistCanvasRectangles(); 249 | this.drawRectangle(rec); 250 | } 251 | ); 252 | } 253 | 254 | private autoDrawRect(mouseMove: Observable): void { 255 | this.autoDrawRect$ = mouseMove.subscribe({ 256 | next: (mouseMoveEvent: MouseEvent) => { 257 | this.drawPersistCanvasRectangles(); 258 | this.drawTempCanvasRectangle(mouseMoveEvent); 259 | }, 260 | error: err => console.error('something wrong occurred: ' + err), 261 | }); 262 | } 263 | 264 | private drawPersistCanvasRectangles() { 265 | this.drawContainerRect(); 266 | this.rectangles.forEach(tmpRect => { 267 | this.drawRectangle(tmpRect); 268 | }); 269 | } 270 | 271 | private drawTempCanvasRectangle(event: MouseEvent) { 272 | let rectangle: Rectangle = null; 273 | const clientX = event.clientX, 274 | clientY = event.clientY, 275 | els = document.elementsFromPoint(clientX, clientY), 276 | el = els[2]; 277 | if ((!this.isExcludeRect(els)) && el && this.elCouldBeHighlighted.indexOf(el.nodeName.toLowerCase()) > -1) { 278 | rectangle = new Rectangle(); 279 | const rect = el.getBoundingClientRect(); 280 | this.drawCanvas.style.cursor = 'pointer'; 281 | 282 | Object.assign(rectangle, { 283 | startX: rect.left, 284 | startY: rect.top, 285 | width: rect.width, 286 | height: rect.height, 287 | color: this.drawColor 288 | }); 289 | this.drawRectangle(rectangle); 290 | } else { 291 | this.drawCanvas.style.cursor = 'crosshair'; 292 | } 293 | return rectangle; 294 | } 295 | 296 | public closeRect(index: number) { 297 | this.rectangles.splice(index, 1); 298 | this.drawPersistCanvasRectangles(); 299 | } 300 | 301 | private isExcludeRect(elements: Element[]): boolean { 302 | const result = elements.some( el => { 303 | return el.getAttribute('exclude-rect') === 'true'; 304 | }); 305 | return result; 306 | } 307 | } 308 | --------------------------------------------------------------------------------