├── README.md ├── angular_programming.jpg ├── backend ├── .gitignore ├── _db.json ├── app.js └── package.json └── frontend ├── .angular-cli.json ├── .editorconfig ├── .gitignore ├── e2e ├── app.e2e-spec.ts ├── app.po.ts └── tsconfig.e2e.json ├── karma.conf.js ├── package.json ├── protractor.conf.js ├── src ├── app │ ├── about │ │ ├── about-routing.module.ts │ │ ├── about.component.css │ │ ├── about.component.html │ │ ├── about.component.spec.ts │ │ ├── about.component.ts │ │ └── about.module.ts │ ├── admin │ │ ├── admin-routing.module.ts │ │ ├── admin.component.html │ │ ├── admin.component.ts │ │ ├── admin.module.ts │ │ ├── center │ │ │ ├── center.component.css │ │ │ ├── center.component.html │ │ │ ├── center.component.ts │ │ │ ├── index.ts │ │ │ └── shared │ │ │ │ ├── center-shared.module.ts │ │ │ │ ├── index.ts │ │ │ │ ├── questionnaire-controls │ │ │ │ ├── index.ts │ │ │ │ ├── questionnaire-controls.component.css │ │ │ │ ├── questionnaire-controls.component.html │ │ │ │ └── questionnaire-controls.component.ts │ │ │ │ ├── questionnaire-detail │ │ │ │ ├── index.ts │ │ │ │ ├── questionnaire-detail.component.html │ │ │ │ └── questionnaire-detail.component.ts │ │ │ │ └── questionnaire-item │ │ │ │ ├── index.ts │ │ │ │ ├── questionnaire-item.component.html │ │ │ │ └── questionnaire-item.component.ts │ │ └── edit │ │ │ ├── edit.component.css │ │ │ ├── edit.component.html │ │ │ ├── edit.component.ts │ │ │ ├── index.ts │ │ │ └── shared │ │ │ ├── edit-shared.module.ts │ │ │ ├── index.ts │ │ │ ├── question-select │ │ │ ├── index.ts │ │ │ ├── question-select.component.css │ │ │ ├── question-select.component.html │ │ │ └── question-select.component.ts │ │ │ └── questionnaire-outline │ │ │ ├── index.ts │ │ │ ├── questionnaire-outline.component.css │ │ │ ├── questionnaire-outline.component.html │ │ │ └── questionnaire-outline.component.ts │ ├── app-routing.module.ts │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── core │ │ ├── core.module.ts │ │ └── services │ │ │ ├── auth-guard.service.ts │ │ │ ├── index.ts │ │ │ ├── login.service.ts │ │ │ ├── questionnaire-old.service.ts │ │ │ ├── questionnaire.service.ts │ │ │ ├── register.service.ts │ │ │ └── user.service.ts │ ├── home │ │ ├── home-routing.module.ts │ │ ├── home.component.css │ │ ├── home.component.html │ │ ├── home.component.ts │ │ └── home.module.ts │ ├── published │ │ ├── published-routing.module.ts │ │ ├── published.component.css │ │ ├── published.component.html │ │ ├── published.component.ts │ │ └── published.module.ts │ ├── shared │ │ ├── config │ │ │ └── env.config.ts │ │ ├── index.ts │ │ ├── models │ │ │ ├── index.ts │ │ │ ├── question.model.ts │ │ │ ├── questionnaire.model.ts │ │ │ └── user.model.ts │ │ ├── navbar │ │ │ ├── index.ts │ │ │ ├── navbar.component.css │ │ │ ├── navbar.component.html │ │ │ └── navbar.component.ts │ │ ├── question │ │ │ ├── index.ts │ │ │ ├── question.component.ts │ │ │ ├── question.module.ts │ │ │ └── shared │ │ │ │ ├── index.ts │ │ │ │ ├── question-checkbox │ │ │ │ ├── index.ts │ │ │ │ ├── question-checkbox.component.html │ │ │ │ └── question-checkbox.component.ts │ │ │ │ ├── question-radio │ │ │ │ ├── index.ts │ │ │ │ ├── question-radio.component.html │ │ │ │ └── question-radio.component.ts │ │ │ │ ├── question-score │ │ │ │ ├── index.ts │ │ │ │ ├── question-score.component.html │ │ │ │ └── question-score.component.ts │ │ │ │ ├── question-shared.module.ts │ │ │ │ └── question-text │ │ │ │ ├── index.ts │ │ │ │ ├── question-text.component.html │ │ │ │ └── question-text.component.ts │ │ ├── questionnaire │ │ │ ├── index.ts │ │ │ ├── questionnaire.component.css │ │ │ ├── questionnaire.component.html │ │ │ ├── questionnaire.component.ts │ │ │ └── questionnaire.module.ts │ │ └── shared.module.ts │ └── user │ │ ├── index.ts │ │ ├── shared │ │ ├── field │ │ │ ├── field-base.ts │ │ │ ├── field-radio.ts │ │ │ ├── field-select.ts │ │ │ ├── field-text.ts │ │ │ ├── field-validators.ts │ │ │ ├── field.component.css │ │ │ ├── field.component.html │ │ │ ├── field.component.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── login │ │ │ ├── index.ts │ │ │ ├── login.component.css │ │ │ ├── login.component.html │ │ │ └── login.component.ts │ │ ├── register │ │ │ ├── index.ts │ │ │ ├── register.component.css │ │ │ ├── register.component.html │ │ │ └── register.component.ts │ │ └── user-shared.module.ts │ │ ├── user-routing.module.ts │ │ └── user.module.ts ├── assets │ ├── .gitkeep │ ├── img │ │ ├── about │ │ │ ├── create.jpg │ │ │ ├── faq.jpg │ │ │ └── my.jpg │ │ ├── edit │ │ │ ├── checkbox.png │ │ │ ├── radio.png │ │ │ ├── star.png │ │ │ └── text.png │ │ ├── home │ │ │ ├── banner_01.jpg │ │ │ ├── banner_02.jpg │ │ │ └── banner_03.jpg │ │ └── notfound.png │ └── svg │ │ └── more.svg ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── index.html ├── main.ts ├── polyfills.ts ├── styles.css ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── typings.d.ts ├── tsconfig.json ├── tslint.json └── yarn.lock /README.md: -------------------------------------------------------------------------------- 1 | # Angular 调查问卷示例项目 2 | 3 | ### 这是由广发证券互联网金融技术团队出品的原创书籍《揭秘 Angular》的第三部分项目实战的源代码。 4 | 5 | ![揭秘 Angular 封面](./angular_programming.jpg) 6 | 7 | 这个示例项目包含以下特点: 8 | 9 | * 遵循官方最佳实践的目录布局 10 | * 代码难易程度适中,方便学习 11 | * 功能丰富的脚手架,易于扩展使用 12 | * 简洁化的后端服务,聚焦前端框架学习 13 | 14 | 15 | ## 如何上手 16 | 17 | 调查问卷项目包括前端 frontend 目录以及后端 backend 目录。我们可以先运行后端服务,方便前端的注册与登录用户以及提供问卷相关的服务。安装过 Node.js 之后(确保你的 Node.js 版本为 6.x 及以上),在终端运行以下命令: 18 | 19 | ```bash 20 | cd backend 21 | npm install 22 | node app 23 | ``` 24 | 25 | 接下来,将终端目录定位 frontend 之中,再运行以下命令: 26 | 27 | ```bash 28 | npm install 29 | npm start 30 | ``` 31 | 32 | 以上前后台的命令都执行完后,即成功启动整个项目应用。 33 | -------------------------------------------------------------------------------- /angular_programming.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/angular_programming.jpg -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-* 3 | -------------------------------------------------------------------------------- /backend/_db.json: -------------------------------------------------------------------------------- 1 | { 2 | "user": [ 3 | { 4 | "username": "admin", 5 | "password": "dc483e80a7a0bd9ef71d8cf973673924", 6 | "createDate": "2016-12-08" 7 | }, 8 | { 9 | "username": "test", 10 | "password": "e10adc3949ba59abbe56e057f20f883e", 11 | "createDate": "5/2/2017" 12 | } 13 | ], 14 | "questionnaires": [ 15 | { 16 | "title": "关于 Angular 2 在 2016 的发展现状调查", 17 | "starter": "关于在 2016 年 9 月中旬,Google 官方正式发布了 Angular 2 版本后的一些问卷调查", 18 | "ending": "", 19 | "state": 1, 20 | "questionList": [ 21 | { 22 | "title": "如何评价 Angular 2.0 Final Release 的发布?", 23 | "type": 0, 24 | "answer": "" 25 | }, 26 | { 27 | "title": "你会在下一个项目中考虑使用 Angular 2 吗?", 28 | "type": 1, 29 | "options": [ 30 | { 31 | "key": 0, 32 | "value": "会" 33 | }, 34 | { 35 | "key": 1, 36 | "value": "不会" 37 | } 38 | ], 39 | "answer": "" 40 | }, 41 | { 42 | "title": "Angular 2 中数据状态管理方案有哪些?", 43 | "type": 0, 44 | "answer": "" 45 | }, 46 | { 47 | "title": "Angular 2.0与 Angular1.x 版本相比,有哪些方面的改进呢?", 48 | "type": 3, 49 | "answer": "" 50 | }, 51 | { 52 | "title": "Angular 2 能兼容到 IE 的什么版本?", 53 | "type": 2, 54 | "options": [ 55 | { 56 | "key": 0, 57 | "value": "IE8 及以下版本" 58 | }, 59 | { 60 | "key": 1, 61 | "value": "IE9" 62 | }, 63 | { 64 | "key": 2, 65 | "value": "IE10" 66 | }, 67 | { 68 | "key": 3, 69 | "value": "IE11" 70 | } 71 | ], 72 | "answer": { 73 | "selected": [] 74 | } 75 | }, 76 | { 77 | "title": "TypeScript 会不会借着 Angular,成为主流编程语言?", 78 | "type": 1, 79 | "options": [ 80 | { 81 | "key": 0, 82 | "value": "会" 83 | }, 84 | { 85 | "key": 1, 86 | "value": "不会" 87 | } 88 | ], 89 | "answer": "" 90 | }, 91 | { 92 | "title": "关于如何正确的学习 Angular 2 的思考,您有哪些建议 ?", 93 | "type": 0, 94 | "answer": "" 95 | } 96 | ], 97 | "id": "eb988080-bdb1-11e6-9040-db60cb4931b1", 98 | "createDate": "2016-12-01" 99 | }, 100 | { 101 | "title": "关于 2016 谷歌开发者大会在北京和上海召开的相关问卷调查", 102 | "starter": "", 103 | "ending": "", 104 | "state": 1, 105 | "questionList": [], 106 | "id": "b0b4d4b0-bdb5-11e6-8153-af1293d9eace", 107 | "createDate": "2016-12-08" 108 | }, 109 | { 110 | "title": "Angular 2 对于 TypeScript 的生态建设影响的相关调查", 111 | "starter": "", 112 | "ending": "", 113 | "state": 0, 114 | "questionList": [], 115 | "id": "19655e30-bdb6-11e6-8153-af1293d9eace", 116 | "createDate": "2016-12-09" 117 | }, 118 | { 119 | "title": "fdsg", 120 | "starter": "efwdsg", 121 | "ending": "", 122 | "state": 0, 123 | "questionList": [ 124 | { 125 | "title": "问题标题fewgewfefewgew", 126 | "type": 0, 127 | "answer": "" 128 | } 129 | ], 130 | "id": "691dd290-3e99-11e7-95ac-21877dadc395", 131 | "createDate": "5/22/2017" 132 | } 133 | ] 134 | } -------------------------------------------------------------------------------- /backend/app.js: -------------------------------------------------------------------------------- 1 | const jsonServer = require('json-server'); 2 | const uuid = require('node-uuid'); 3 | const crypto = require('crypto'); 4 | const bodyParser = require('body-parser'); 5 | const low = require('lowdb'); 6 | const storage = require('lowdb/file-async'); 7 | 8 | // import jsonServer from 'json-server'; 9 | // import uuid from 'node-uuid'; 10 | // import bodyParser from 'body-parser'; 11 | 12 | // import low from 'lowdb'; 13 | // import storage from 'lowdb/file-async'; 14 | 15 | 16 | //创建一个Express服务器 17 | const server = jsonServer.create(); 18 | 19 | //使用json-server默认选择的中间件(logger,static, cors和no-cache) 20 | server.use(jsonServer.defaults()); 21 | 22 | //使用body-parser中间件 23 | server.use(bodyParser.json()); 24 | 25 | 26 | //数据文件 27 | const dbfile = process.env.prod === '1' ? 'db.json' : '_db.json'; 28 | 29 | //创建一个lowdb实例 30 | const db = low(dbfile, {storage}); 31 | 32 | 33 | const md5 = str => crypto 34 | .createHash('md5') 35 | .update(str.toString()) 36 | .digest('hex'); 37 | 38 | //添加新问卷 39 | server.post('/questionnaire/add', (req, res) => { 40 | const item = req.body; 41 | item.id = uuid.v1(); 42 | item.createDate = new Date().toLocaleDateString(); 43 | db('questionnaires').push(item).then(() => { 44 | res.json({'success':true, data:item}); 45 | }); 46 | }); 47 | 48 | //删除已有问卷 49 | server.get('/questionnaire/delete/:id', (req, res)=>{ 50 | db('questionnaires').remove({id: req.params.id}).then(()=>{ 51 | res.json({'success': true}); 52 | }); 53 | }); 54 | 55 | //获取所有问卷 56 | server.get('/questionnaires', (req, res) => { 57 | const questionnaires = db('questionnaires'); 58 | res.json({'success':true, data:questionnaires}); 59 | }); 60 | 61 | //根据id获取问卷数据 62 | server.get('/questionnaire/:id', (req, res) => { 63 | const questionnaire = db('questionnaires').find({id: req.params.id}); 64 | res.json({'success':true, data:questionnaire}); 65 | }); 66 | 67 | //更新已有问卷 68 | server.post('/questionnaire/update', (req, res) => { 69 | const item = req.body; 70 | db('questionnaires').chain().find({id:item.id}).assign(item).value(); 71 | res.json({'success':true, data:item}); 72 | }); 73 | 74 | //发布问卷 75 | server.post('/questionnaire/updateState', (req, res)=>{ 76 | const params = req.body; 77 | const item = db('questionnaires').chain().find({id:params.id}); 78 | item.assign({state:params.state}).value(); 79 | res.json({'success':true, data:item}); 80 | }); 81 | 82 | // get userinfo 83 | server.get('/user/:username', (req, res) => { 84 | const user = db('user') 85 | .find({ 86 | username: req.params.username 87 | }); 88 | 89 | res.json({ 90 | success: true, 91 | data: { 92 | username: user.username, 93 | createDate: user.createDate 94 | } 95 | }); 96 | }); 97 | 98 | // register 99 | server.post('/user/add', (req, res) => { 100 | const item = req.body; 101 | const user = db('user') 102 | .find({ 103 | username: item.username 104 | }); 105 | if (user) { 106 | res.json({ 107 | success: false, 108 | message: `"${item.username}" is exists` 109 | }) 110 | } else { 111 | item.password = md5(item.password); 112 | item.createDate = new Date().toLocaleDateString(); 113 | db('user') 114 | .push(item) 115 | .then(() => { 116 | res.json({ 117 | success: true 118 | }); 119 | }); 120 | } 121 | }); 122 | 123 | // login 124 | server.post('/login', (req, res) => { 125 | const data = req.body || {}; 126 | const username = data.username; 127 | const user = db('user') 128 | .find({ 129 | username 130 | }); 131 | 132 | if (user && user.password === md5(data.password)) { 133 | // todo reset session 134 | res.json({ 135 | success: true 136 | }); 137 | } else { 138 | res.json({ 139 | success: false, 140 | message: 'username or password error' 141 | }); 142 | } 143 | }); 144 | 145 | //路由配置 146 | const router = jsonServer.router(dbfile); 147 | server.use('/api', router); 148 | 149 | //启动服务,并监听5000端口 150 | server.listen(5000, () => { 151 | console.log('server is running at ', 5000, dbfile); 152 | }); 153 | -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "body-parser": "^1.14.2", 13 | "json-server": "^0.8.7", 14 | "lowdb": "^0.12.2", 15 | "node-uuid": "^1.4.7" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /frontend/.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "angular-questionnaire" 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 | "../node_modules/bootstrap/dist/css/bootstrap.min.css", 23 | "styles.css" 24 | ], 25 | "scripts": [], 26 | "environmentSource": "environments/environment.ts", 27 | "environments": { 28 | "dev": "environments/environment.ts", 29 | "prod": "environments/environment.prod.ts" 30 | } 31 | } 32 | ], 33 | "e2e": { 34 | "protractor": { 35 | "config": "./protractor.conf.js" 36 | } 37 | }, 38 | "lint": [ 39 | { 40 | "project": "src/tsconfig.app.json", 41 | "exclude": "**/node_modules/**" 42 | }, 43 | { 44 | "project": "src/tsconfig.spec.json", 45 | "exclude": "**/node_modules/**" 46 | }, 47 | { 48 | "project": "e2e/tsconfig.e2e.json", 49 | "exclude": "**/node_modules/**" 50 | } 51 | ], 52 | "test": { 53 | "karma": { 54 | "config": "./karma.conf.js" 55 | } 56 | }, 57 | "defaults": { 58 | "styleExt": "css", 59 | "component": {} 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /frontend/.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 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .vscode 3 | -------------------------------------------------------------------------------- /frontend/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Ng2demoCliPage } from './app.po'; 2 | 3 | describe('ng2demo-cli App', () => { 4 | let page: Ng2demoCliPage; 5 | 6 | beforeEach(() => { 7 | page = new Ng2demoCliPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /frontend/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class Ng2demoCliPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /frontend/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "declaration": false, 5 | "moduleResolution": "node", 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "lib": [ 9 | "es2016" 10 | ], 11 | "outDir": "../dist/out-tsc-e2e", 12 | "module": "commonjs", 13 | "target": "es6", 14 | "types":[ 15 | "jasmine", 16 | "node" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /frontend/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/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 | files: [ 19 | { pattern: './src/test.ts', watched: false } 20 | ], 21 | preprocessors: { 22 | './src/test.ts': ['@angular/cli'] 23 | }, 24 | mime: { 25 | 'text/x-typescript': ['ts','tsx'] 26 | }, 27 | coverageIstanbulReporter: { 28 | reports: [ 'html', 'lcovonly' ], 29 | fixWebpackSourcePaths: true 30 | }, 31 | angularCli: { 32 | environment: 'dev' 33 | }, 34 | reporters: config.angularCli && config.angularCli.codeCoverage 35 | ? ['progress', 'coverage-istanbul'] 36 | : ['progress', 'kjhtml'], 37 | port: 9876, 38 | colors: true, 39 | logLevel: config.LOG_INFO, 40 | autoWatch: true, 41 | browsers: ['Chrome'], 42 | singleRun: false 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-questionnaire", 3 | "version": "1.0.1", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "5.0.0", 16 | "@angular/common": "5.0.0", 17 | "@angular/compiler": "5.0.0", 18 | "@angular/core": "5.0.0", 19 | "@angular/forms": "5.0.0", 20 | "@angular/http": "5.0.0", 21 | "@angular/platform-browser": "5.0.0", 22 | "@angular/platform-browser-dynamic": "5.0.0", 23 | "@angular/router": "5.0.0", 24 | "core-js": "2.4.1", 25 | "rxjs": "5.5.2", 26 | "zone.js": "0.8.14", 27 | "bootstrap": "3.3.7", 28 | "moment": "2.18.1", 29 | "ngx-bootstrap": "1.8.0" 30 | }, 31 | "devDependencies": { 32 | "@angular/cli": "1.5.0", 33 | "@angular/compiler-cli": "5.0.0", 34 | "@angular/language-service": "5.0.0", 35 | "@types/jasmine": "~2.5.53", 36 | "@types/jasminewd2": "~2.0.2", 37 | "@types/node": "~6.0.60", 38 | "codelyzer": "~3.2.0", 39 | "jasmine-core": "~2.6.2", 40 | "jasmine-spec-reporter": "~4.1.0", 41 | "karma": "~1.7.0", 42 | "karma-chrome-launcher": "~2.1.1", 43 | "karma-cli": "~1.0.1", 44 | "karma-coverage-istanbul-reporter": "1.2.1", 45 | "karma-jasmine": "~1.1.0", 46 | "karma-jasmine-html-reporter": "0.2.2", 47 | "protractor": "~5.1.2", 48 | "ts-node": "~3.2.0", 49 | "tslint": "~5.7.0", 50 | "typescript": "~2.4.2" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /frontend/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 | beforeLaunch: function() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | }, 27 | onPrepare() { 28 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /frontend/src/app/about/about-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { AboutComponent } from './about.component'; 4 | const routes: Routes = [ 5 | { path: 'about', component: AboutComponent } 6 | ]; 7 | @NgModule({ 8 | imports: [ 9 | RouterModule.forChild(routes) 10 | ], 11 | exports: [ 12 | RouterModule 13 | ] 14 | }) 15 | export class AboutRoutingModule { } 16 | -------------------------------------------------------------------------------- /frontend/src/app/about/about.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | padding: 16px; 4 | } 5 | 6 | accordion-group .col-lg-3 { 7 | text-align: center; 8 | } 9 | -------------------------------------------------------------------------------- /frontend/src/app/about/about.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 5 |
6 |
7 | {{item.text}} 8 |
9 |
10 | {{ item?.desc }} 11 |
12 |
13 |
14 |
15 |
16 | -------------------------------------------------------------------------------- /frontend/src/app/about/about.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | import { By } from '@angular/platform-browser'; 3 | 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { AboutComponent } from './about.component'; 7 | import { AccordionModule } from 'ngx-bootstrap'; 8 | import { SharedModule } from '../shared/shared.module'; 9 | 10 | export function main() { 11 | describe('About component', () => { 12 | 13 | let comp: AboutComponent; 14 | let fixture: ComponentFixture; 15 | let aboutEl: DebugElement; 16 | 17 | // setting module for testing 18 | // compile template and css 19 | beforeEach( async(() => { 20 | TestBed.configureTestingModule({ 21 | imports: [SharedModule, AccordionModule], 22 | declarations: [AboutComponent], 23 | }) 24 | .compileComponents(); 25 | })); 26 | 27 | // synchronous beforeEach 28 | beforeEach(() => { 29 | fixture = TestBed.createComponent(AboutComponent); 30 | comp = fixture.componentInstance; 31 | aboutEl = fixture.debugElement; 32 | 33 | fixture.detectChanges(); // trigger initial data binding 34 | }); 35 | 36 | it('should render accordion', ()=>{ 37 | 38 | const de = aboutEl.queryAll(By.css('accordion')); 39 | expect(de.length).toBe(1); 40 | }); 41 | 42 | it('should render correct accordion text', ()=>{ 43 | 44 | // const de = aboutEl.queryAll(By.css('accordion')); 45 | expect(aboutEl.nativeElement.textContent).toContain('常见FAQ'); 46 | }); 47 | }); 48 | } 49 | 50 | ////// Test Host Component ////// 51 | import { Component } from '@angular/core'; 52 | 53 | @Component({ 54 | selector: 'test-cmp', 55 | template: '' 56 | }) 57 | class TestComponent {} 58 | -------------------------------------------------------------------------------- /frontend/src/app/about/about.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'sd-help', 5 | templateUrl: 'about.component.html', 6 | styleUrls: ['about.component.css'] 7 | }) 8 | export class AboutComponent { 9 | 10 | private items: any[]; 11 | 12 | constructor() { 13 | this.items = [ 14 | { 15 | icon:'./assets/img/about/faq.jpg', 16 | text:'常见FAQ', 17 | desc:'使用问卷收集数据的基本流程是:创建问卷、编辑问卷、设置问卷、预览问卷、回收问卷、数据分析等几个步骤。问卷提供三种创建问卷方式,创建空白问卷、选择问卷模板、文本编辑器。可以灵活设置问卷的显示、回收条件,在线实时统计回收结果,并可以导出Excel和SPSS数据。详细操作指引请参照帮助中心”操作指引“部分。', 18 | open: true 19 | }, 20 | { 21 | icon:'./assets/img/about/create.jpg', 22 | text:'创建问卷', 23 | desc:'问卷,共有三种创建问卷的方式让您来选择使用:创建空白问卷、选择问卷模板、文本编辑器,可根据自身的使用习惯,选择最合适的方式来快速创建一份问卷。', 24 | open: false 25 | }, 26 | { 27 | icon:'./assets/img/about/my.jpg', 28 | text:'我的问卷', 29 | desc:'问卷编辑、预览完成后,一份在线问卷即完成,此时可以通过对问卷的复制、编辑、删除、发布、统计、导出、分享等功能,实现对问卷的全面管理', 30 | open: false 31 | } 32 | ]; 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /frontend/src/app/about/about.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { AboutComponent } from './about.component'; 5 | import { AccordionModule } from 'ngx-bootstrap'; 6 | import { AboutRoutingModule } from './about-routing.module'; 7 | 8 | @NgModule({ 9 | imports: [CommonModule, AccordionModule.forRoot(), AboutRoutingModule], 10 | declarations: [AboutComponent] 11 | }) 12 | export class AboutModule { } 13 | -------------------------------------------------------------------------------- /frontend/src/app/admin/admin-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { AdminComponent } from './admin.component'; 5 | import { CenterComponent } from './center/center.component'; 6 | import { EditComponent } from './edit/edit.component'; 7 | 8 | import { AuthGuard } from '../core/services/auth-guard.service'; 9 | 10 | const routes: Routes = [ 11 | { 12 | path: 'admin', 13 | component: AdminComponent, 14 | canActivate: [AuthGuard], 15 | children: [ 16 | { 17 | path: '', 18 | children: [ 19 | { path: 'center', component: CenterComponent }, 20 | { path: 'edit/:id', component: EditComponent } 21 | ] 22 | } 23 | ] 24 | } 25 | ]; 26 | 27 | @NgModule({ 28 | imports: [RouterModule.forChild(routes)], 29 | exports: [RouterModule] 30 | }) 31 | export class AdminRoutingModule { } 32 | 33 | -------------------------------------------------------------------------------- /frontend/src/app/admin/admin.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /frontend/src/app/admin/admin.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'sd-admin', 5 | templateUrl: 'admin.component.html', 6 | }) 7 | export class AdminComponent { } 8 | -------------------------------------------------------------------------------- /frontend/src/app/admin/admin.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { AdminComponent } from './admin.component'; 5 | import { CenterComponent } from './center'; 6 | import { EditComponent } from './edit'; 7 | 8 | import { AdminRoutingModule } from './admin-routing.module'; 9 | import { SharedModule } from '../shared/shared.module'; 10 | import { QuestionnaireModule } from '../shared/questionnaire/questionnaire.module'; 11 | import { CenterSharedModule } from './center/shared/center-shared.module'; 12 | import { EditSharedModule } from './edit/shared/edit-shared.module'; 13 | 14 | import { TabsModule } from 'ngx-bootstrap'; 15 | 16 | @NgModule({ 17 | imports: [CommonModule, AdminRoutingModule, SharedModule, TabsModule.forRoot(), QuestionnaireModule, CenterSharedModule, EditSharedModule], 18 | declarations: [ 19 | AdminComponent, 20 | CenterComponent, 21 | EditComponent 22 | ] 23 | }) 24 | export class AdminModule { } 25 | -------------------------------------------------------------------------------- /frontend/src/app/admin/center/center.component.css: -------------------------------------------------------------------------------- 1 | .center-container{ 2 | padding:20px; 3 | } 4 | 5 | .center-container .show-empty{ 6 | width: 360px; 7 | margin: 0 auto; 8 | height: 260px; 9 | text-align: center; 10 | padding-top: 200px; 11 | background: url(/assets/img/notfound.png) no-repeat center center; 12 | } -------------------------------------------------------------------------------- /frontend/src/app/admin/center/center.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 尚未创建任何问卷,马上创建一个吧! 4 |
5 |
6 |
7 |
8 |
9 |
问卷列表
10 |
11 | 13 | 14 | 15 |
16 |
17 |
18 |
19 |
20 |
问卷详情
21 |
22 | 23 |
24 |
25 |
26 |
问卷管理
27 |
28 | 31 |
32 |
33 |
34 |
-------------------------------------------------------------------------------- /frontend/src/app/admin/center/center.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ChangeDetectorRef } from '@angular/core'; 2 | 3 | import { QuestionnaireService } from '../../core/services/questionnaire.service'; 4 | import { QuestionnaireModel, QuestionnaireState } from '../../shared/models/questionnaire.model'; 5 | 6 | @Component({ 7 | selector: 'sd-center', 8 | templateUrl: 'center.component.html', 9 | styleUrls: ['center.component.css'] 10 | }) 11 | export class CenterComponent implements OnInit { 12 | 13 | private questionnaires:QuestionnaireModel[] = []; 14 | private selectedQuestionnaire:QuestionnaireModel; 15 | private selectedIndex:number; 16 | private isEmpty:boolean; 17 | 18 | constructor(private cd:ChangeDetectorRef, private questionnaireService:QuestionnaireService) { } 19 | 20 | ngOnInit() { 21 | this.questionnaireService.getQuestionnaires() 22 | .subscribe( 23 | questionnaires => { 24 | // 后端返回空对象或者空的问卷数组 25 | if(!questionnaires || questionnaires.length === 0){ 26 | this.isEmpty = true; 27 | return; 28 | } 29 | this.isEmpty = false; 30 | this.questionnaires = questionnaires; 31 | this.selectedQuestionnaire = this.questionnaires[0]; 32 | this.selectedIndex = 0; 33 | }, 34 | error => console.error(error) 35 | ); 36 | } 37 | 38 | onSelect(questionnaire:QuestionnaireModel, index:number) { 39 | this.selectedQuestionnaire = questionnaire; 40 | this.selectedIndex = index; 41 | } 42 | 43 | onDeleteQuestionnaire() { 44 | this.questionnaireService.deleteQuestionnaire(this.selectedQuestionnaire.id) 45 | .subscribe( 46 | res => { 47 | this.questionnaires.splice(this.selectedIndex, 1); 48 | //全部删除 49 | if(this.questionnaires.length === 0){ 50 | this.isEmpty = true; 51 | } else { 52 | this.selectedQuestionnaire = this.questionnaires[0]; 53 | this.selectedIndex = 0; 54 | } 55 | }, 56 | error => console.log(error) 57 | 58 | ); 59 | } 60 | 61 | onPublishQuestionnaire(){ 62 | this.questionnaireService.updateQuestionnaireState(this.selectedQuestionnaire.id, QuestionnaireState.Published) 63 | .subscribe( 64 | questionnaire => { 65 | this.selectedQuestionnaire.state = QuestionnaireState.Published; 66 | this.questionnaires[this.selectedIndex] = Object.assign({}, this.selectedQuestionnaire); 67 | this.cd.detectChanges(); 68 | }, 69 | error => console.log(error) 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /frontend/src/app/admin/center/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./center.component"; 2 | export * from './shared/questionnaire-controls/index'; 3 | export * from './shared/questionnaire-detail/index'; 4 | export * from './shared/questionnaire-item/index'; 5 | -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/center-shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { QuestionnaireItemComponent } from './questionnaire-item/index'; 5 | import { QuestionnaireDetailComponent } from './questionnaire-detail/index'; 6 | import { QuestionnaireControlsComponent } from './questionnaire-controls/index'; 7 | 8 | @NgModule({ 9 | imports: [CommonModule], 10 | declarations: [QuestionnaireItemComponent, QuestionnaireDetailComponent, QuestionnaireControlsComponent], 11 | exports: [QuestionnaireItemComponent, QuestionnaireDetailComponent, QuestionnaireControlsComponent, CommonModule] 12 | }) 13 | export class CenterSharedModule { } 14 | -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/index.ts: -------------------------------------------------------------------------------- 1 | export * from './questionnaire-item/index'; 2 | export * from './questionnaire-detail/index'; 3 | export * from './questionnaire-controls/index'; -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-controls/index.ts: -------------------------------------------------------------------------------- 1 | export * from './questionnaire-controls.component'; -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-controls/questionnaire-controls.component.css: -------------------------------------------------------------------------------- 1 | .control-text{ 2 | display: block; 3 | text-align: center; 4 | font-size: 16px; 5 | } -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-controls/questionnaire-controls.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 7 |
8 |
9 | 13 |
14 |
15 | 19 |
20 |
21 | 25 |
26 |
27 | 31 |
32 |
-------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-controls/questionnaire-controls.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Input, Output } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | 4 | import { QuestionnaireModel } from '../../../../shared/models/questionnaire.model'; 5 | 6 | @Component({ 7 | selector: 'questionnaire-controls', 8 | templateUrl: 'questionnaire-controls.component.html', 9 | styleUrls: ['questionnaire-controls.component.css'] 10 | }) 11 | export class QuestionnaireControlsComponent { 12 | 13 | @Input() questionnaire:QuestionnaireModel; 14 | @Output() deleteQuestionnaire: EventEmitter = new EventEmitter(); 15 | @Output() publishQuestionnaire: EventEmitter = new EventEmitter(); 16 | 17 | constructor(private router: Router) {} 18 | 19 | onEdit(){ 20 | this.router.navigateByUrl('admin/edit/' + this.questionnaire.id); 21 | } 22 | 23 | onPreview(){ 24 | this.router.navigateByUrl('published/' + this.questionnaire.id); 25 | } 26 | 27 | onDelete(){ 28 | this.deleteQuestionnaire.emit(); 29 | } 30 | 31 | onPublish(){ 32 | this.publishQuestionnaire.emit(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-detail/index.ts: -------------------------------------------------------------------------------- 1 | export * from './questionnaire-detail.component'; -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-detail/questionnaire-detail.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
问卷标题:{{questionnaire.title}}
问卷简介:{{questionnaire.starter}}
问题总数:{{questionnaire.questionList.length}}
创建时间:{{questionnaire.createDate}}
-------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-detail/questionnaire-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input } from '@angular/core'; 2 | 3 | import { QuestionnaireModel } from '../../../../shared/models/questionnaire.model'; 4 | 5 | @Component({ 6 | selector: 'questionnaire-detail', 7 | templateUrl: 'questionnaire-detail.component.html' 8 | }) 9 | export class QuestionnaireDetailComponent { 10 | 11 | @Input() questionnaire: QuestionnaireModel; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-item/index.ts: -------------------------------------------------------------------------------- 1 | export * from './questionnaire-item.component'; -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-item/questionnaire-item.component.html: -------------------------------------------------------------------------------- 1 | {{questionnaire.title}} 2 | {{stateText}} 3 | {{questionnaire.createDate}} -------------------------------------------------------------------------------- /frontend/src/app/admin/center/shared/questionnaire-item/questionnaire-item.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnChanges, SimpleChanges, Input } from '@angular/core'; 2 | 3 | import { QuestionnaireModel, QuestionnaireState } from '../../../../shared/models/questionnaire.model'; 4 | 5 | @Component({ 6 | selector: 'questionnaire-item', 7 | templateUrl: 'questionnaire-item.component.html' 8 | }) 9 | export class QuestionnaireItemComponent implements OnInit, OnChanges { 10 | 11 | @Input() questionnaire:QuestionnaireModel; 12 | 13 | private stateText:String; 14 | private stateClass:String; 15 | 16 | ngOnChanges(changes: SimpleChanges){ 17 | let questionnaireChange = changes['questionnaire']; 18 | if(questionnaireChange && questionnaireChange.previousValue && questionnaireChange.previousValue.state && 19 | questionnaireChange.currentValue.state !== questionnaireChange.previousValue.state){ 20 | this.questionnaire = changes['questionnaire'].currentValue; 21 | this.setState(); 22 | } 23 | } 24 | 25 | ngOnInit() { 26 | this.setState(); 27 | } 28 | 29 | setState(){ 30 | switch(this.questionnaire.state){ 31 | case QuestionnaireState.Created: 32 | this.stateText = '已创建'; 33 | this.stateClass = 'label-warning'; 34 | break; 35 | case QuestionnaireState.Published: 36 | this.stateText = '回收中'; 37 | this.stateClass = 'label-info'; 38 | break; 39 | case QuestionnaireState.Finished: 40 | this.stateText = '已结束'; 41 | this.stateClass = 'label-success'; 42 | break; 43 | default: 44 | break; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/edit.component.css: -------------------------------------------------------------------------------- 1 | .questionnaire-container{ 2 | background-color: #f0f0f0; 3 | min-height: 800px; 4 | } 5 | 6 | .edit-container .sidebar{ 7 | padding:20px; 8 | } -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/edit.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 13 |
14 |
15 | 16 |
17 |
-------------------------------------------------------------------------------- /frontend/src/app/admin/edit/edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | 4 | import { QuestionType } from '../../shared/models/question.model'; 5 | import { QuestionnaireService } from '../../core/services/questionnaire.service'; 6 | import { QuestionnaireModel, QuestionnaireState } from '../../shared/models/questionnaire.model'; 7 | 8 | @Component({ 9 | selector: 'sd-edit', 10 | templateUrl: 'edit.component.html', 11 | styleUrls: ['edit.component.css'] 12 | }) 13 | export class EditComponent implements OnInit { 14 | 15 | private questionnaire: QuestionnaireModel; 16 | private id: string; 17 | 18 | constructor(private questionnaireService:QuestionnaireService, private activatedRoute:ActivatedRoute, 19 | private router: Router) { 20 | 21 | //初始化一个空的问卷对象 22 | this.questionnaire = { 23 | title: '', 24 | starter: '', 25 | ending: '', 26 | state: QuestionnaireState.Created, 27 | questionList: [] 28 | }; 29 | } 30 | 31 | ngOnInit() { 32 | //初始化问卷数据 33 | this.id = this.activatedRoute.snapshot.params['id']; 34 | 35 | if(this.id && this.id !== '0'){ 36 | //id存在,代表当前页面为编辑已有问卷页面,调用服务获取问卷对象信息 37 | this.questionnaireService.getQuestionnaireById(this.id) 38 | .subscribe( 39 | questionnaire => this.questionnaire = questionnaire, 40 | error => console.log(error) 41 | ); 42 | } 43 | } 44 | 45 | onAddQuestion(type: QuestionType) { 46 | //添加问题到问卷的问题列表 47 | switch(type){ 48 | case QuestionType.Text: 49 | case QuestionType.Score: 50 | this.questionnaire.questionList.push({ 51 | title: '问题标题', 52 | type: type, 53 | answer: '' 54 | }); 55 | break; 56 | case QuestionType.SingleSelect: 57 | this.questionnaire.questionList.push({ 58 | title: '问题标题', 59 | type: type, 60 | options: [{'key': 0, 'value': '选项1'}], 61 | answer:'' 62 | }); 63 | break; 64 | case QuestionType.MultiSelect: 65 | this.questionnaire.questionList.push({ 66 | title: '问题标题', 67 | type: type, 68 | options: [{'key': 0, 'value': '选项1'}], 69 | answer:{} 70 | }); 71 | break; 72 | } 73 | } 74 | 75 | onSubmitQuestionniare(questionnaire: QuestionnaireModel) { 76 | //保存问卷或回收答案 77 | if (questionnaire.state === QuestionnaireState.Created) { 78 | if (this.id && this.id !== '0') { 79 | //编辑已有问卷 80 | this.questionnaireService.updateQuestionnaire(questionnaire) 81 | .subscribe( 82 | questionnaire => this.gotoCenter(), 83 | error => console.log(error)); 84 | } else { 85 | //创建新问卷 86 | this.questionnaireService.addQuestionnaire(questionnaire) 87 | .subscribe( 88 | questionnaire => this.gotoCenter(), 89 | error=> console.error(error)); 90 | } 91 | } 92 | } 93 | 94 | gotoCenter() { 95 | this.router.navigateByUrl('admin/center'); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./edit.component"; 2 | export * from './shared/question-select/index'; 3 | export * from './shared/questionnaire-outline/index'; 4 | -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/edit-shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { QuestionSelectComponent } from './question-select/index'; 5 | import { QuestionnaireOutlineComponent } from './questionnaire-outline/index'; 6 | 7 | @NgModule({ 8 | imports: [CommonModule], 9 | declarations: [QuestionSelectComponent, QuestionnaireOutlineComponent], 10 | exports: [QuestionSelectComponent, QuestionnaireOutlineComponent, CommonModule] 11 | }) 12 | export class EditSharedModule { } 13 | -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question-select/index'; 2 | export * from './questionnaire-outline/index'; 3 | -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/question-select/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question-select.component'; -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/question-select/question-select.component.css: -------------------------------------------------------------------------------- 1 | .question-controls li{ 2 | list-style-type: none; 3 | border:none; 4 | } 5 | 6 | .question-controls li.list-group-item{ 7 | border-bottom: 1px solid #ccc; 8 | } 9 | 10 | .question-controls li a{ 11 | background-repeat: no-repeat; 12 | padding-left: 24px; 13 | cursor: pointer; 14 | text-decoration: none; 15 | } 16 | 17 | .icon-text { 18 | background-image: url(/assets/img/edit/text.png); 19 | } 20 | 21 | .icon-star { 22 | background-image: url(/assets/img/edit/star.png); 23 | } 24 | 25 | .icon-radio { 26 | background-image: url(/assets/img/edit/radio.png); 27 | } 28 | 29 | .icon-checkbox { 30 | background-image: url(/assets/img/edit/checkbox.png); 31 | } -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/question-select/question-select.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/question-select/question-select.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Output } from '@angular/core'; 2 | import { QuestionType } from '../../../../shared/models/question.model'; 3 | 4 | @Component({ 5 | selector: 'question-select', 6 | styleUrls: ['question-select.component.css'], 7 | templateUrl: 'question-select.component.html' 8 | }) 9 | export class QuestionSelectComponent { 10 | 11 | @Output() addQuestionRequest = new EventEmitter(); 12 | 13 | private controls:any[]; 14 | 15 | constructor() { 16 | this.controls = [ 17 | {type: QuestionType.Text, label: '文本问题', iconClass: 'icon-text'}, 18 | {type: QuestionType.SingleSelect, label: '单选问题', iconClass: 'icon-radio'}, 19 | {type: QuestionType.MultiSelect, label: '多选问题', iconClass: 'icon-checkbox'}, 20 | {type: QuestionType.Score, label: '分值问题', iconClass: 'icon-star'} 21 | ]; 22 | } 23 | 24 | onAddQuestion(control: any) { 25 | this.addQuestionRequest.emit(control.type); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/questionnaire-outline/index.ts: -------------------------------------------------------------------------------- 1 | export * from './questionnaire-outline.component'; -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/questionnaire-outline/questionnaire-outline.component.css: -------------------------------------------------------------------------------- 1 | .questionnaire-outline{ 2 | margin-top: 20px; 3 | } 4 | 5 | .questionnaire-outline li{ 6 | font-size: 12px; 7 | line-height: 20px; 8 | } -------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/questionnaire-outline/questionnaire-outline.component.html: -------------------------------------------------------------------------------- 1 |
    2 |
  • 3 | {{(i + 1) + ". " + q.title}} 4 |
  • 5 |
-------------------------------------------------------------------------------- /frontend/src/app/admin/edit/shared/questionnaire-outline/questionnaire-outline.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input } from '@angular/core'; 2 | 3 | import { QuestionnaireModel } from '../../../../shared/models/questionnaire.model'; 4 | 5 | @Component({ 6 | selector: 'questionnaire-outline', 7 | styleUrls: ['questionnaire-outline.component.css'], 8 | templateUrl: 'questionnaire-outline.component.html' 9 | }) 10 | export class QuestionnaireOutlineComponent { 11 | 12 | @Input() questionnaire: QuestionnaireModel; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /frontend/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | export const routes: Routes = [ 5 | { path: '', redirectTo: '/home', pathMatch: 'full' } 6 | ]; 7 | 8 | @NgModule({ 9 | imports: [RouterModule.forRoot(routes)], 10 | exports: [RouterModule] 11 | }) 12 | export class AppRoutingModule { } 13 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: #369; 3 | font-family: Arial, Helvetica, sans-serif; 4 | font-size: 250%; 5 | } 6 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /frontend/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 works!'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('app works!'); 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('app works!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /frontend/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 = 'My First Anagular App!'; 10 | } 11 | -------------------------------------------------------------------------------- /frontend/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | import { AppComponent } from './app.component'; 6 | import { AppRoutingModule } from './app-routing.module'; 7 | import { CoreModule } from './core/core.module'; 8 | import { AdminModule } from './admin/admin.module'; 9 | import { AboutModule } from './about/about.module'; 10 | import { HomeModule } from './home/home.module'; 11 | import { UserModule } from './user/user.module'; 12 | import { PublishedModule } from './published/published.module'; 13 | 14 | 15 | @NgModule({ 16 | declarations: [ 17 | AppComponent 18 | ], 19 | imports: [CoreModule, AdminModule, BrowserModule, AppRoutingModule, PublishedModule, UserModule, HomeModule, AboutModule], 20 | providers: [], 21 | bootstrap: [AppComponent] 22 | }) 23 | export class AppModule { } 24 | -------------------------------------------------------------------------------- /frontend/src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, Optional, SkipSelf } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { RouterModule } from '@angular/router'; 4 | import { HttpModule } from '@angular/http'; 5 | import { HttpClientModule } from "@angular/common/http"; 6 | 7 | import { AuthGuard } from './services/auth-guard.service'; 8 | import { LoginService } from './services/login.service'; 9 | import { QuestionnaireService } from './services/questionnaire.service'; 10 | import { RegisterService } from './services/register.service'; 11 | import { UserService } from './services/user.service'; 12 | 13 | @NgModule({ 14 | imports: [CommonModule, RouterModule, HttpClientModule], 15 | declarations: [], 16 | providers: [QuestionnaireService, UserService, LoginService, RegisterService, AuthGuard], 17 | exports: [HttpModule] 18 | }) 19 | export class CoreModule { 20 | 21 | constructor (@Optional() @SkipSelf() parentModule: CoreModule) { 22 | if (parentModule) { 23 | throw new Error( 24 | 'CoreModule is already loaded. Import it in the AppModule only'); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /frontend/src/app/core/services/auth-guard.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router'; 3 | 4 | import { UserService } from './user.service'; 5 | 6 | @Injectable() 7 | export class AuthGuard implements CanActivate { 8 | 9 | constructor(private userService:UserService, private route:Router) { } 10 | 11 | canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { 12 | if(this.userService.isLogin) { 13 | return true; 14 | } 15 | this.route.navigate(['/login'],{queryParams:{returnUrl:state.url}}); 16 | return false; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /frontend/src/app/core/services/index.ts: -------------------------------------------------------------------------------- 1 | export * from './user.service'; 2 | export * from './questionnaire.service'; 3 | export * from './login.service'; 4 | export * from './register.service'; 5 | export * from './auth-guard.service'; 6 | -------------------------------------------------------------------------------- /frontend/src/app/core/services/login.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { FormControl, FormGroup, Validators } from '@angular/forms'; 3 | import { Http } from '@angular/http'; 4 | import { Headers } from '@angular/http'; 5 | import { Observable } from 'rxjs/Observable'; 6 | import { Observer } from 'rxjs/Observer'; 7 | 8 | import { FieldBase } from '../../user/shared/field/field-base'; 9 | import { FieldText } from '../../user/shared/field/field-text'; 10 | import { FieldValidators } from '../../user/shared/field/field-validators'; 11 | import { SITE_HOST_URL } from '../../shared/index'; 12 | 13 | @Injectable() 14 | export class LoginService { 15 | 16 | private loginUrl = `${SITE_HOST_URL}login`; 17 | 18 | constructor(private http: Http) { } 19 | 20 | getFields() { 21 | let fields: FieldBase[] = [ 22 | new FieldText({ 23 | key: 'username', 24 | label: '用户名', 25 | value: '', 26 | required: true, 27 | pattern: 'username', 28 | order: 1 29 | }), 30 | new FieldText({ 31 | key: 'password', 32 | label: '密码', 33 | type: 'password', 34 | value: '', 35 | required: true, 36 | pattern: 'password', 37 | order: 2 38 | }), 39 | ]; 40 | return fields.sort((a, b) => a.order - b.order); 41 | } 42 | 43 | toFormGroup(fields: FieldBase[]) { 44 | let group: any = {}; 45 | 46 | fields.forEach(field => { 47 | group[field.key] = 48 | field.pattern ? 49 | new FormControl(field.value || '', (FieldValidators)[field.pattern]) : 50 | field.required ? 51 | new FormControl(field.value || '', Validators.required) : 52 | new FormControl(field.value || ''); 53 | }); 54 | return new FormGroup(group); 55 | } 56 | 57 | login(data: Object) { 58 | let body = JSON.stringify(data); 59 | let headers = new Headers(); 60 | headers.append('Content-Type', 'application/json'); 61 | return new Observable((observer: Observer)=>{ 62 | this.http.post(this.loginUrl, body, { headers }).subscribe(res=>{ 63 | let body = res.json(); 64 | if (body && body.success) { 65 | // this.userService.isLogin = true; 66 | // this.userService.userName = data['username']; 67 | observer.next(res); 68 | observer.complete(); 69 | } 70 | }); 71 | }); 72 | } 73 | 74 | logout() { 75 | //this.userService.isLogin = false; 76 | //this.userService.userName = ''; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /frontend/src/app/core/services/questionnaire-old.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Http, Headers, RequestOptions, Response } from '@angular/http'; 3 | import { Observable } from 'rxjs/Rx'; 4 | 5 | import { QuestionnaireModel } from '../../shared/models/questionnaire.model'; 6 | import { SITE_HOST_URL } from '../../shared/index'; 7 | 8 | @Injectable() 9 | export class QuestionnaireService { 10 | constructor(private http: Http) {} 11 | 12 | private handleError(error: Response) { 13 | console.error(error); 14 | return Observable.throw(error.json().error || 'server error'); 15 | } 16 | 17 | //根据id获取问卷信息 18 | getQuestionnaireById(id: string) { 19 | return this.http 20 | .get(SITE_HOST_URL + 'questionnaire/' + id) 21 | .map(res => res.json().data) 22 | .catch(this.handleError); 23 | } 24 | 25 | getQuestionnaires() { 26 | return this.http 27 | .get(SITE_HOST_URL + 'questionnaires') 28 | .map(res => res.json().data) 29 | .catch(this.handleError); 30 | } 31 | 32 | //添加新问卷 33 | addQuestionnaire(questionnaire: QuestionnaireModel) { 34 | let body = JSON.stringify(questionnaire); 35 | let headers = new Headers({ 'Content-Type': 'application/json' }); 36 | let options = new RequestOptions({ headers: headers }); 37 | 38 | return this.http 39 | .post(SITE_HOST_URL + 'questionnaire/add', body, options) 40 | .map(res => res.json().data) 41 | .catch(this.handleError); 42 | } 43 | 44 | //删除已有问卷 45 | deleteQuestionnaire(id: string) { 46 | return this.http 47 | .get(SITE_HOST_URL + 'questionnaire/delete/' + id) 48 | .map(res => res.json().data) 49 | .catch(this.handleError); 50 | } 51 | 52 | //更新已有问卷 53 | updateQuestionnaire(questionnaire: QuestionnaireModel) { 54 | let body = JSON.stringify(questionnaire); 55 | let headers = new Headers({ 'Content-Type': 'application/json' }); 56 | let options = new RequestOptions({ headers: headers }); 57 | 58 | return this.http 59 | .post(SITE_HOST_URL + 'questionnaire/update', body, options) 60 | .map(res => res.json().data) 61 | .catch(this.handleError); 62 | } 63 | 64 | //发布问卷 65 | publishQuestionnaire(id: string) { 66 | return this.http 67 | .get(SITE_HOST_URL + 'questionnaire/publish/' + id) 68 | .map(res => res.json().data) 69 | .catch(this.handleError); 70 | } 71 | 72 | //回收问卷 73 | reclaimQuestionnaire(questionnaire: QuestionnaireModel) {} 74 | } 75 | -------------------------------------------------------------------------------- /frontend/src/app/core/services/questionnaire.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Observable } from 'rxjs/Rx'; 3 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 4 | 5 | import { QuestionnaireModel, QuestionnaireState } from '../../shared/models/questionnaire.model'; 6 | import { SITE_HOST_URL } from '../../shared/index'; 7 | 8 | @Injectable() 9 | export class QuestionnaireService { 10 | constructor(private http: HttpClient) {} 11 | 12 | private handleError(error) { 13 | console.error(error); 14 | return Observable.throw(error || 'server error'); 15 | } 16 | 17 | //根据id获取问卷信息 18 | getQuestionnaireById(id: string) { 19 | return this.http 20 | .get(SITE_HOST_URL + 'questionnaire/' + id) 21 | .map((res: any) => res.data) 22 | .catch(this.handleError); 23 | } 24 | 25 | getQuestionnaires() { 26 | return this.http 27 | .get(SITE_HOST_URL + 'questionnaires') 28 | .map((res: any) => res.data) 29 | .catch(this.handleError); 30 | } 31 | 32 | //添加新问卷 33 | addQuestionnaire(questionnaire: QuestionnaireModel) { 34 | return this.http 35 | .post(SITE_HOST_URL + 'questionnaire/add', questionnaire) 36 | .map((res: any) => res.data) 37 | .catch(this.handleError); 38 | } 39 | 40 | //删除已有问卷 41 | deleteQuestionnaire(id: string) { 42 | return this.http 43 | .get(SITE_HOST_URL + 'questionnaire/delete/' + id) 44 | .map((res: any) => res.data) 45 | .catch(this.handleError); 46 | } 47 | 48 | //更新已有问卷 49 | updateQuestionnaire(questionnaire: QuestionnaireModel) { 50 | return this.http 51 | .post(SITE_HOST_URL + 'questionnaire/update', questionnaire) 52 | .map((res: any) => res.data) 53 | .catch(this.handleError); 54 | } 55 | 56 | //发布问卷 57 | updateQuestionnaireState(id: string, state: QuestionnaireState) { 58 | return this.http 59 | .post(SITE_HOST_URL + 'questionnaire/updateState',{id:id, state:state}) 60 | .map((res: any) => res.data) 61 | .catch(this.handleError); 62 | } 63 | 64 | //回收问卷 65 | reclaimQuestionnaire(questionnaire: QuestionnaireModel) {} 66 | } 67 | -------------------------------------------------------------------------------- /frontend/src/app/core/services/register.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { FormControl, FormGroup, Validators } from '@angular/forms'; 3 | import { Http, Headers } from '@angular/http'; 4 | 5 | import { FieldBase } from '../../user/shared/field/field-base'; 6 | import { FieldText } from '../../user/shared/field/field-text'; 7 | import { FieldValidators } from '../../user/shared/field/field-validators'; 8 | import { SITE_HOST_URL } from '../../shared/index'; 9 | 10 | @Injectable() 11 | export class RegisterService { 12 | 13 | private registerUrl = `${SITE_HOST_URL}user/add`; 14 | 15 | constructor(private http: Http) { } 16 | 17 | getFields() { 18 | let fields: FieldBase[] = [ 19 | new FieldText({ 20 | key: 'username', 21 | label: '用户名', 22 | value: '', 23 | required: true, 24 | pattern: 'username', 25 | order: 1 26 | }), 27 | new FieldText({ 28 | key: 'password', 29 | label: '密码', 30 | type: 'password', 31 | value: '', 32 | required: true, 33 | pattern: 'password', 34 | order: 2 35 | }), 36 | ]; 37 | return fields.sort((a, b) => a.order - b.order); 38 | } 39 | 40 | toFormGroup(fields: FieldBase[]) { 41 | let group: any = {}; 42 | 43 | fields.forEach(field => { 44 | group[field.key] = 45 | field.pattern ? 46 | new FormControl(field.value || '', (FieldValidators)[field.pattern]) : 47 | field.required ? 48 | new FormControl(field.value || '', Validators.required) : 49 | new FormControl(field.value || ''); 50 | }); 51 | return new FormGroup(group); 52 | } 53 | 54 | addUser(data: Object) { 55 | let body = JSON.stringify(data); 56 | let headers = new Headers(); 57 | headers.append('Content-Type', 'application/json'); 58 | 59 | return this.http 60 | .post(this.registerUrl, body, { headers }); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /frontend/src/app/core/services/user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | import { Http } from "@angular/http"; 3 | import { Observable } from "rxjs/Observable"; 4 | import { Observer } from "rxjs/Observer"; 5 | 6 | import { SITE_HOST_URL } from "../../shared/index"; 7 | import { UserModel } from "../../shared/models/user.model"; 8 | 9 | @Injectable() 10 | export class UserService { 11 | public isLogin: boolean = false; 12 | public userName: string = ""; 13 | public userInfo: UserModel; 14 | private getUserInfoUrl = (api: string, userName: string) => 15 | `${api}user/get/${userName}`; 16 | 17 | constructor(private http: Http) { 18 | let sessionUser 19 | , tmp = sessionStorage.getItem('user'); 20 | try { 21 | sessionUser = JSON.parse(tmp); 22 | } catch(_) { } 23 | if(sessionUser) { 24 | this.isLogin = true; 25 | this.userInfo = sessionUser; 26 | } 27 | } 28 | 29 | setUser(userInfo) { 30 | if(userInfo) { 31 | this.isLogin = true; 32 | this.userInfo = userInfo; 33 | sessionStorage.setItem('user', JSON.stringify(userInfo)); 34 | } 35 | } 36 | 37 | clearUser() { 38 | this.isLogin = false; 39 | this.userInfo = null; 40 | sessionStorage.removeItem('user'); 41 | } 42 | 43 | getUser() { 44 | return new Observable((observer: Observer) => { 45 | if (!this.userName) { 46 | observer.next(""); 47 | observer.complete(); 48 | } else { 49 | this.http 50 | .get(this.getUserInfoUrl(SITE_HOST_URL, this.userName)) 51 | .map(res => res.json().data) 52 | .subscribe( 53 | data => { 54 | this.isLogin = true; 55 | this.userInfo = data; 56 | sessionStorage.setItem('user', JSON.stringify(data)); 57 | observer.next(data); 58 | observer.complete(); 59 | }, 60 | err => { 61 | this.isLogin = false; 62 | this.userInfo = null; 63 | observer.error(err); 64 | } 65 | ); 66 | } 67 | }); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /frontend/src/app/home/home-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { HomeComponent } from './home.component'; 4 | const routes: Routes = [ 5 | { path: 'home', component: HomeComponent } 6 | ]; 7 | @NgModule({ 8 | imports: [ 9 | RouterModule.forChild(routes) 10 | ], 11 | exports: [ 12 | RouterModule 13 | ] 14 | }) 15 | export class HomeRoutingModule { } 16 | -------------------------------------------------------------------------------- /frontend/src/app/home/home.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | padding: 0 16px; 4 | 5 | } 6 | .login-title { 7 | color: #337ab7; 8 | } 9 | 10 | .home .slide-image { 11 | text-align: center; 12 | } 13 | 14 | .hero-title { 15 | margin-top: 50px; 16 | text-align: center; 17 | font-size: 18px; 18 | } 19 | 20 | .hero-title span { 21 | color: green; 22 | font-size: 22px; 23 | } 24 | 25 | .hero-title a { 26 | margin-left: 80px; 27 | width: 250px; 28 | } 29 | 30 | .carousel-indicators li { 31 | margin: 1px 5px; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /frontend/src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | 6 | 8 |
9 | 10 |
11 | 12 | 15 |
16 |
17 | 18 |
19 |

20 | 10,145,267个用户正在使用 21 | 创建新问卷 22 |

23 |
24 |
25 |
26 |
27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /frontend/src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'sd-home', 5 | styleUrls:[ 'home.component.css'], 6 | templateUrl: 'home.component.html' 7 | }) 8 | export class HomeComponent { 9 | 10 | // public myInterval:number = 5000; 11 | // public noWrapSlides:boolean = false; 12 | slides:Array = []; 13 | slogns:Array = ['免费简约的问卷系统', '简单 好用 在线调查网站', '多方式创建编辑问卷']; 14 | 15 | constructor() { 16 | for (let i = 0; i < 3; i++) { 17 | this.addSlide(i); 18 | } 19 | } 20 | 21 | addSlide(idx: number) { 22 | this.slides.push({ 23 | image: `./assets/img/home/banner_0${idx+1}.jpg`, 24 | text: this.slogns[idx] 25 | }); 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /frontend/src/app/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | // import { CoreModule } from '../core/core.module'; 5 | import { HomeComponent } from './home.component'; 6 | import { CarouselModule } from 'ngx-bootstrap'; 7 | import { SharedModule } from '../shared/shared.module'; 8 | import { HomeRoutingModule } from './home-routing.module'; 9 | 10 | @NgModule({ 11 | imports: [CommonModule, SharedModule, CarouselModule.forRoot(), HomeRoutingModule], 12 | declarations: [HomeComponent], 13 | exports: [HomeComponent] 14 | }) 15 | export class HomeModule { } 16 | -------------------------------------------------------------------------------- /frontend/src/app/published/published-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { PublishedComponent } from './published.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: 'published/:id', 9 | component: PublishedComponent 10 | } 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [RouterModule.forChild(routes)], 15 | exports: [RouterModule] 16 | }) 17 | export class PublishedRoutingModule { } 18 | -------------------------------------------------------------------------------- /frontend/src/app/published/published.component.css: -------------------------------------------------------------------------------- 1 | .published-container{ 2 | width: 1024px; 3 | margin: 0 auto; 4 | } 5 | 6 | .published-container .questionnaire-container{ 7 | background: #ccc !important; 8 | } -------------------------------------------------------------------------------- /frontend/src/app/published/published.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
-------------------------------------------------------------------------------- /frontend/src/app/published/published.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | 4 | import { QuestionnaireModel } from '../shared/models/questionnaire.model'; 5 | import { QuestionnaireService } from '../core/services/questionnaire.service'; 6 | 7 | @Component({ 8 | selector: 'sd-published', 9 | templateUrl: 'published.component.html', 10 | styleUrls: ['published.component.css'] 11 | }) 12 | export class PublishedComponent implements OnInit { 13 | 14 | private questionnaire: QuestionnaireModel; 15 | private id: string; 16 | 17 | constructor(private questionnaireService:QuestionnaireService, private activatedRoute:ActivatedRoute) { } 18 | 19 | ngOnInit() { 20 | this.id = this.activatedRoute.snapshot.params['id']; 21 | if (this.id && this.id !== '0') { 22 | this.questionnaireService.getQuestionnaireById(this.id) 23 | .subscribe( 24 | questionnaire => this.questionnaire = questionnaire, 25 | error => console.log(error) 26 | ); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /frontend/src/app/published/published.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { PublishedComponent } from './published.component'; 5 | import { PublishedRoutingModule } from './published-routing.module'; 6 | import { QuestionnaireModule } from '../shared/questionnaire/questionnaire.module'; 7 | 8 | @NgModule({ 9 | imports: [CommonModule, PublishedRoutingModule, QuestionnaireModule], 10 | declarations: [PublishedComponent], 11 | exports: [PublishedComponent] 12 | }) 13 | export class PublishedModule { } 14 | -------------------------------------------------------------------------------- /frontend/src/app/shared/config/env.config.ts: -------------------------------------------------------------------------------- 1 | // Feel free to extend this interface 2 | // depending on your app specific config. 3 | // export interface EnvConfig { 4 | // API?: string; 5 | // ENV?: string; 6 | // } 7 | 8 | // export const Config: EnvConfig = JSON.parse('<%= ENV_CONFIG %>'); 9 | 10 | export const SITE_HOST_URL: string = 'http://localhost:5000/'; 11 | 12 | -------------------------------------------------------------------------------- /frontend/src/app/shared/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This barrel file provides the exports for the shared resources (services, components). 3 | */ 4 | export * from './config/env.config'; 5 | export * from './models/index'; 6 | export * from './question/index'; 7 | export * from './questionnaire/index'; 8 | -------------------------------------------------------------------------------- /frontend/src/app/shared/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question.model'; 2 | export * from './questionnaire.model'; 3 | export * from './user.model'; 4 | -------------------------------------------------------------------------------- /frontend/src/app/shared/models/question.model.ts: -------------------------------------------------------------------------------- 1 | // 问题模型数据定义 2 | 3 | // export interface QuestionModel{ 4 | // title:string; //问题标题(描述) 5 | // type:QuestionType; //问题类型 6 | // options?:any[]; //答案选项 7 | // answer:any; //问题答案 8 | // } 9 | 10 | export class QuestionModel { 11 | title:string; //问题标题(描述) 12 | type:QuestionType; //问题类型 13 | options?:any[]; //答案选项 14 | answer:any; //问题答案 15 | } 16 | 17 | // 问题类型 18 | export const enum QuestionType{ 19 | Text, 20 | SingleSelect, 21 | MultiSelect, 22 | Score 23 | } 24 | -------------------------------------------------------------------------------- /frontend/src/app/shared/models/questionnaire.model.ts: -------------------------------------------------------------------------------- 1 | import { QuestionModel } from './question.model'; 2 | 3 | // //问卷数据模型定义 4 | // export interface QuestionnaireModel{ 5 | // id?:string; //问卷ID 6 | // title:string; //问卷标题 7 | // starter:string; //开始问候语 8 | // ending:string; //结束问候语 9 | // state:QuestionnaireState; //问卷状态 10 | // questionList: QuestionModel[]; //问题列表 11 | // createDate?:string; //创建日期 12 | // } 13 | 14 | //问卷数据模型定义 15 | export class QuestionnaireModel{ 16 | id?:string; //问卷ID 17 | title:string; //问卷标题 18 | starter:string; //开始问候语 19 | ending:string; //结束问候语 20 | state:QuestionnaireState; //问卷状态 21 | questionList: QuestionModel[]; //问题列表 22 | createDate?:string; //创建日期 23 | } 24 | 25 | //问卷状态枚举类型 26 | export const enum QuestionnaireState{ 27 | Created, //已创建状态 28 | Published, //发布回收状态 29 | Finished //完成状态 30 | } 31 | -------------------------------------------------------------------------------- /frontend/src/app/shared/models/user.model.ts: -------------------------------------------------------------------------------- 1 | // 用户信息 2 | // export interface UserModel{ 3 | // username:string; //问卷标题 4 | // createDate?:string; //创建日期 5 | // } 6 | 7 | export class UserModel{ 8 | username:string; //问卷标题 9 | createDate?:string; //创建日期 10 | } 11 | -------------------------------------------------------------------------------- /frontend/src/app/shared/navbar/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This barrel file provides the export for the shared NavbarComponent. 3 | */ 4 | export * from './navbar.component'; 5 | -------------------------------------------------------------------------------- /frontend/src/app/shared/navbar/navbar.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | border-color: #e1e1e1; 3 | border-style: solid; 4 | border-width: 0 0 1px; 5 | display: block; 6 | height: 48px; 7 | padding: 0 16px; 8 | } 9 | 10 | nav a { 11 | color: #8f8f8f; 12 | font-size: 14px; 13 | font-weight: 500; 14 | line-height: 48px; 15 | margin-right: 20px; 16 | text-decoration: none; 17 | vertical-align: middle; 18 | } 19 | 20 | nav a.router-link-active { 21 | color: #106cc8; 22 | } 23 | -------------------------------------------------------------------------------- /frontend/src/app/shared/navbar/navbar.component.html: -------------------------------------------------------------------------------- 1 | 6 | 13 | -------------------------------------------------------------------------------- /frontend/src/app/shared/navbar/navbar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | 4 | import { LoginService } from '../../core/services/login.service'; 5 | import { UserService } from '../../core/services/user.service'; 6 | 7 | /** 8 | * This class represents the navigation bar component. 9 | */ 10 | @Component({ 11 | selector: 'sd-navbar', 12 | templateUrl: 'navbar.component.html', 13 | styleUrls: ['navbar.component.css'], 14 | }) 15 | export class NavbarComponent { 16 | 17 | constructor(private userService:UserService, private loginService:LoginService, private router:Router) { } 18 | 19 | logout($event) { 20 | $event.preventDefault(); 21 | this.userService.clearUser(); 22 | this.router.navigate(['']); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question.component'; 2 | export * from './shared/index'; 3 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/question.component.ts: -------------------------------------------------------------------------------- 1 | import { OnInit, EventEmitter } from '@angular/core'; 2 | 3 | import { QuestionModel } from '../models/question.model'; 4 | 5 | export class QuestionComponent implements OnInit { 6 | 7 | question: QuestionModel; 8 | backupQuestion: QuestionModel; 9 | editable: boolean = false; 10 | isEditing: boolean = false; 11 | deleteQuestionRequest: EventEmitter = new EventEmitter(); 12 | 13 | ngOnInit(){ 14 | this.copyQuestion(); 15 | } 16 | 17 | private copy(source: QuestionModel): QuestionModel { 18 | return JSON.parse(JSON.stringify(source)); 19 | } 20 | 21 | public copyQuestion() { 22 | this.backupQuestion = this.copy(this.question); 23 | 24 | } 25 | 26 | onEdit() { 27 | this.isEditing = true; 28 | } 29 | 30 | onSave() { 31 | this.copyQuestion(); 32 | this.isEditing = false; 33 | } 34 | 35 | onCancel() { 36 | this.question = this.copy(this.backupQuestion); 37 | this.isEditing = false; 38 | } 39 | 40 | onDelete() { 41 | this.deleteQuestionRequest.emit(this.question); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/question.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, ModuleWithProviders } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | import { QuestionSharedModule } from './shared/question-shared.module'; 6 | 7 | @NgModule({ 8 | imports: [CommonModule, FormsModule, QuestionSharedModule], 9 | exports: [CommonModule, QuestionSharedModule] 10 | }) 11 | export class QuestionModule { 12 | 13 | static forRoot(): ModuleWithProviders { 14 | return { 15 | ngModule: QuestionModule 16 | }; 17 | } 18 | } -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question-checkbox/index'; 2 | export * from './question-radio/index'; 3 | export * from './question-score/index'; 4 | export * from './question-text/index'; 5 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-checkbox/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question-checkbox.component'; -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-checkbox/question-checkbox.component.html: -------------------------------------------------------------------------------- 1 |

复选题

2 |
3 |

{{question.title}}

4 |
5 | 9 |
10 |
11 |
12 | 13 |
14 |
15 | 16 |
17 |
18 | X 19 |
20 |
21 |
22 | 23 | 24 | 25 |
26 |
27 |
28 |

{{question.title}}

29 |
30 | 34 |
35 |
36 | 37 | 38 |
39 |
40 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-checkbox/question-checkbox.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Input, Output } from '@angular/core'; 2 | 3 | import { QuestionComponent } from '../../question.component'; 4 | import { QuestionModel } from '../../../models/question.model'; 5 | 6 | @Component({ 7 | selector: 'question-checkbox', 8 | templateUrl: 'question-checkbox.component.html' 9 | }) 10 | export class QuestionCheckboxComponent extends QuestionComponent { 11 | 12 | @Input() question: QuestionModel; 13 | @Input() editable: boolean; 14 | @Output() deleteQuestionRequest: EventEmitter = new EventEmitter(); 15 | 16 | private key: number; 17 | 18 | ngOnInit() { 19 | this.copyQuestion(); 20 | let options = this.question.options; 21 | this.key = options[options.length-1].key; 22 | if(!this.question.answer.selected){ 23 | this.question.answer.selected = []; 24 | } 25 | } 26 | 27 | onDeleteOption(index: number) { 28 | if(this.question.options.length <= 1) { 29 | return; 30 | } 31 | 32 | this.question.options.splice(index, 1); 33 | } 34 | 35 | onAddOption() { 36 | this.question.options.push({key: ++this.key, value:'' }); 37 | } 38 | 39 | setSelectedValue(checked: boolean, value: string) { 40 | let selected = this.question.answer.selected; 41 | let index:number = selected.indexOf(value); 42 | if(checked){ 43 | if(index < 0){ 44 | selected.push(value); 45 | } 46 | }else{ 47 | if(index > -1){ 48 | selected.splice(index, 1); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-radio/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question-radio.component'; -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-radio/question-radio.component.html: -------------------------------------------------------------------------------- 1 |

单选题

2 |
3 |

{{question.title}}

4 |
5 | 8 |
9 |
10 |
11 | 12 |
13 |
14 | 15 |
16 |
17 | X 18 |
19 |
20 |
21 | 22 | 23 | 24 |
25 |
26 |
27 |

{{question.title}}

28 |
29 | 33 |
34 |
35 | 36 | 37 |
38 |
39 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-radio/question-radio.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Input, Output } from '@angular/core'; 2 | 3 | import { QuestionComponent } from '../../question.component'; 4 | import { QuestionModel } from '../../../models/question.model'; 5 | 6 | @Component({ 7 | selector: 'question-radio', 8 | templateUrl: 'question-radio.component.html' 9 | }) 10 | export class QuestionRadioComponent extends QuestionComponent { 11 | 12 | @Input() question: QuestionModel; 13 | @Input() editable: boolean; 14 | @Output() deleteQuestionRequest: EventEmitter = new EventEmitter(); 15 | 16 | private key: number; 17 | 18 | ngOnInit() { 19 | this.copyQuestion(); 20 | let options = this.question.options; 21 | this.key = options[options.length-1].key; 22 | } 23 | 24 | onDeleteOption(index:number) { 25 | if(this.question.options.length <= 1) { 26 | return; 27 | } 28 | 29 | this.question.options.splice(index, 1); 30 | } 31 | 32 | onAddOption() { 33 | this.question.options.push({key: ++this.key, value:'' }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-score/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question-score.component'; -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-score/question-score.component.html: -------------------------------------------------------------------------------- 1 |

分值题

2 | 3 |
4 |

{{question.title}}

5 |

6 | 7 | 8 |

9 |
10 | 11 |
12 | 13 |
14 | 15 | 16 |
17 |
18 | 19 |
20 |

{{question.title}}

21 |

22 | 23 | 24 |

25 |
26 | 27 | 28 |
29 |
30 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-score/question-score.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Input, Output } from '@angular/core'; 2 | 3 | import { QuestionComponent } from '../../question.component'; 4 | import { QuestionModel } from '../../../models/question.model'; 5 | 6 | @Component({ 7 | selector: 'question-score', 8 | templateUrl: 'question-score.component.html' 9 | }) 10 | export class QuestionScoreComponent extends QuestionComponent { 11 | 12 | @Input() question: QuestionModel; 13 | @Input() editable: boolean; 14 | @Output() deleteQuestionRequest: EventEmitter = new EventEmitter(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | import { QuestionCheckboxComponent } from './question-checkbox/index'; 6 | import { QuestionRadioComponent } from './question-radio/index'; 7 | import { QuestionScoreComponent } from './question-score/index'; 8 | import { QuestionTextComponent } from './question-text/index'; 9 | 10 | @NgModule({ 11 | imports: [CommonModule, FormsModule], 12 | declarations: [QuestionCheckboxComponent, QuestionRadioComponent, QuestionScoreComponent, QuestionTextComponent], 13 | exports: [QuestionCheckboxComponent, QuestionRadioComponent, QuestionScoreComponent, QuestionTextComponent, CommonModule, FormsModule] 14 | }) 15 | export class QuestionSharedModule { } 16 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-text/index.ts: -------------------------------------------------------------------------------- 1 | export * from './question-text.component'; -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-text/question-text.component.html: -------------------------------------------------------------------------------- 1 |

问答题

2 |
3 |

{{question.title}}

4 | 5 |
6 | 7 |
8 | 9 |
10 | 11 | 12 |
13 |
14 | 15 |
16 |

{{question.title}}

17 | 18 |
19 | 20 | 21 |
22 |
23 | -------------------------------------------------------------------------------- /frontend/src/app/shared/question/shared/question-text/question-text.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Input, Output } from '@angular/core'; 2 | 3 | import { QuestionComponent } from '../../question.component'; 4 | import { QuestionModel } from '../../../models/question.model'; 5 | 6 | @Component({ 7 | selector: 'question-text', 8 | templateUrl: 'question-text.component.html' 9 | }) 10 | export class QuestionTextComponent extends QuestionComponent { 11 | 12 | @Input() question: QuestionModel; 13 | @Input() editable: boolean; 14 | @Output() deleteQuestionRequest: EventEmitter = new EventEmitter(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /frontend/src/app/shared/questionnaire/index.ts: -------------------------------------------------------------------------------- 1 | export * from './questionnaire.component'; -------------------------------------------------------------------------------- /frontend/src/app/shared/questionnaire/questionnaire.component.css: -------------------------------------------------------------------------------- 1 | .questionnaire-container{ 2 | padding:30px; 3 | background-color: #fff; 4 | margin-top:20px; 5 | } 6 | 7 | .questionnaire-container .btn-primary{ 8 | width: 120px; 9 | } 10 | 11 | .questionnaire ul li { 12 | border-bottom: 1px solid lightgrey; 13 | padding-bottom: 10px; 14 | margin-bottom: 20px; 15 | } 16 | 17 | .questionnaire{ 18 | margin-bottom: 30px; 19 | } -------------------------------------------------------------------------------- /frontend/src/app/shared/questionnaire/questionnaire.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

{{questionnaire.title}}

4 |

5 | 6 |

7 |

{{questionnaire.starter}}

8 |

9 | 10 |

11 |
    12 |
  • 13 | 14 |
    15 | 16 |
    17 |
    18 | 19 |
    20 |
    21 | 22 |
    23 |
    24 | 25 |
    26 |
  • 27 |
28 |

{{questionnaire.ending}}

29 |

30 | 31 |

32 |
33 |
34 | 36 |
37 |
-------------------------------------------------------------------------------- /frontend/src/app/shared/questionnaire/questionnaire.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, EventEmitter, Input, Output } from '@angular/core'; 2 | 3 | import { QuestionnaireModel, QuestionnaireState } from '../models/questionnaire.model'; 4 | 5 | @Component({ 6 | selector: 'questionnaire', 7 | styleUrls:['questionnaire.component.css'], 8 | templateUrl: 'questionnaire.component.html' 9 | }) 10 | export class QuestionnaireComponent implements OnInit { 11 | 12 | @Input() questionnaire: QuestionnaireModel; 13 | @Output() submitQuestionnaire = new EventEmitter(); 14 | 15 | private editable:boolean; 16 | 17 | ngOnInit() { 18 | this.editable = this.questionnaire && this.questionnaire.state === QuestionnaireState.Created; 19 | } 20 | 21 | onDeleteQuestion(index: number) { 22 | this.questionnaire.questionList.splice(index, 1); 23 | } 24 | 25 | onSubmit() { 26 | this.submitQuestionnaire.emit(this.questionnaire); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /frontend/src/app/shared/questionnaire/questionnaire.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | import { QuestionModule } from '../question/question.module'; 6 | import { QuestionnaireComponent } from './questionnaire.component'; 7 | 8 | @NgModule({ 9 | imports: [CommonModule, FormsModule, QuestionModule], 10 | declarations: [QuestionnaireComponent], 11 | exports: [QuestionnaireComponent, CommonModule, FormsModule] 12 | }) 13 | export class QuestionnaireModule { } -------------------------------------------------------------------------------- /frontend/src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, ModuleWithProviders } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 4 | import { RouterModule } from '@angular/router'; 5 | import { NavbarComponent } from './navbar'; 6 | 7 | 8 | @NgModule({ 9 | imports: [CommonModule, RouterModule], 10 | declarations: [NavbarComponent], 11 | exports: [CommonModule, FormsModule, ReactiveFormsModule, RouterModule, NavbarComponent] 12 | }) 13 | export class SharedModule { 14 | 15 | static forRoot(): ModuleWithProviders { 16 | return { 17 | ngModule: SharedModule 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /frontend/src/app/user/index.ts: -------------------------------------------------------------------------------- 1 | export * from './shared/index'; 2 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/field-base.ts: -------------------------------------------------------------------------------- 1 | export class FieldBase{ 2 | value: T; 3 | key: string; 4 | label: string; 5 | required: boolean; 6 | pattern: string; 7 | order: number; 8 | controlType: string; 9 | 10 | constructor(options: { 11 | value?: T, 12 | key?: string, 13 | label?: string, 14 | required?: boolean, 15 | pattern?: string, 16 | order?: number, 17 | controlType?: string 18 | } = {}) { 19 | this.value = options.value; 20 | this.key = options.key || ''; 21 | this.label = options.label || ''; 22 | this.required = !!options.required; 23 | this.pattern = options.pattern || ''; 24 | this.order = options.order === undefined ? 1 : options.order; 25 | this.controlType = options.controlType || ''; 26 | } 27 | } -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/field-radio.ts: -------------------------------------------------------------------------------- 1 | import { FieldBase } from './field-base'; 2 | 3 | export class FieldRadio extends FieldBase { 4 | 5 | controlType = 'radio'; 6 | type: string; 7 | items: {name: string, value: string}[] = []; 8 | 9 | constructor(options: any) { 10 | super(options); 11 | this.items = options['items'] || []; 12 | this.type = 'radio'; 13 | } 14 | } -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/field-select.ts: -------------------------------------------------------------------------------- 1 | import { FieldBase } from './field-base'; 2 | 3 | export class SelectField extends FieldBase { 4 | 5 | controlType = 'select'; 6 | options: {key: string, value: string}[] = []; 7 | 8 | constructor(options: any) { 9 | super(options); 10 | this.options = options['options'] || []; 11 | } 12 | } -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/field-text.ts: -------------------------------------------------------------------------------- 1 | import { FieldBase } from './field-base'; 2 | 3 | export class FieldText extends FieldBase { 4 | 5 | controlType = 'text'; 6 | type: string; 7 | 8 | constructor(options: any) { 9 | super(options); 10 | this.type = options['type']; 11 | } 12 | } -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/field-validators.ts: -------------------------------------------------------------------------------- 1 | import { FormControl } from '@angular/forms'; 2 | 3 | const REG = { 4 | USERNAME: /^\w{1,20}$/, 5 | PASSWORD: /^\w{6,20}$/ 6 | }; 7 | 8 | interface ValidationResult { 9 | [key: string]: boolean; 10 | } 11 | 12 | export class FieldValidators { 13 | 14 | public static username(control: FormControl): ValidationResult { 15 | if (control.value.length === 0) { 16 | return { 17 | empty: true 18 | }; 19 | } 20 | if (REG.USERNAME.test(control.value)) { 21 | return null; 22 | } 23 | return { 'invalid': true }; 24 | } 25 | 26 | public static password(control: FormControl): ValidationResult { 27 | if (control.value.length === 0) { 28 | return { 29 | empty: true 30 | }; 31 | } 32 | if (REG.PASSWORD.test(control.value)) { 33 | return null; 34 | } 35 | return { 'invalid': true }; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/field.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | padding: 0 16px; 4 | margin: 0 auto; 5 | } 6 | 7 | input { 8 | border: 1px solid #106cc8 !important; 9 | box-shadow: none !important; 10 | width: 100%; 11 | border-radius: 5px; 12 | } 13 | 14 | select { 15 | display: block; 16 | border: 1px solid #106cc8; 17 | /*border-radius: 0;*/ 18 | /*-webkit-appearance: none;*/ 19 | } 20 | 21 | label { 22 | font-size: 1.2rem; 23 | color: #666; 24 | margin-top: 20px; 25 | } 26 | 27 | .ng-valid[required] { 28 | border-left: 5px solid #42A948; /* green */ 29 | } 30 | 31 | .ng-invalid { 32 | /*border-left: 5px solid #a94442; */ 33 | } 34 | 35 | input[type=text], 36 | input[type=password] { 37 | padding-left: 10px; 38 | letter-spacing: 2px; 39 | margin-bottom: 0; 40 | } 41 | 42 | [type=submit] { 43 | margin-right: 20px; 44 | } 45 | 46 | .errorMessage { 47 | margin-top: 5px; 48 | color: #ee6e73; 49 | } 50 | 51 | .tipsMessage { 52 | margin-top: 5px; 53 | } 54 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/field.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 | 7 |
8 | 9 |
10 | 11 |
12 | 18 |
19 | 20 | 23 | 24 |
25 | 26 |
{{field.label}}格式不正确
27 |
请填写{{field.label}}
28 |
29 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/field.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input } from '@angular/core'; 2 | import { FormGroup } from '@angular/forms'; 3 | 4 | import { FieldBase } from './field-base'; 5 | 6 | @Component({ 7 | selector: 'field', 8 | templateUrl: 'field.component.html', 9 | styleUrls: ['field.component.css'] 10 | }) 11 | export class FieldComponent { 12 | 13 | @Input() field: FieldBase; 14 | @Input() form: FormGroup; 15 | 16 | get isValid() { 17 | return this.form.controls[this.field.key].valid; 18 | } 19 | 20 | get isEmpty() { 21 | let errors = this.form.controls[this.field.key].errors || {}; 22 | return errors['empty']; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/field/index.ts: -------------------------------------------------------------------------------- 1 | export * from './field.component'; 2 | export * from './field-base'; 3 | export * from './field-radio'; 4 | export * from './field-select'; 5 | export * from './field-text'; 6 | export * from './field-validators'; -------------------------------------------------------------------------------- /frontend/src/app/user/shared/index.ts: -------------------------------------------------------------------------------- 1 | export * from './field/index'; 2 | export * from './login/index'; 3 | export * from './register/index'; 4 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/login/index.ts: -------------------------------------------------------------------------------- 1 | export * from './login.component'; 2 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/login/login.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | margin: 20px 20%; 4 | } 5 | 6 | h2, h3 { 7 | font-size: 52px; 8 | font-weight: 500; 9 | letter-spacing: 0.005em; 10 | margin-bottom: 0; 11 | margin-top: 0.83em; 12 | text-align: center; 13 | } 14 | 15 | h3 { 16 | font-size: 40px; 17 | } 18 | 19 | .form-row { 20 | height: 115px; 21 | } 22 | 23 | .form-checkbox { 24 | height: 30px; 25 | margin: 36px 16px 0; 26 | } 27 | 28 | button { 29 | margin: 40px 16px; 30 | padding: 0 32px; 31 | text-align: center; 32 | } 33 | 34 | button[disabled] { 35 | background-color: #ccc; 36 | } 37 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/login/login.component.html: -------------------------------------------------------------------------------- 1 |
2 |

3 |
4 |
5 |
6 | 7 |
8 |
9 | 10 |
11 | 14 |
15 |
16 |
17 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { ActivatedRoute, Router } from "@angular/router"; 3 | import { FormGroup } from "@angular/forms"; 4 | import { Response } from "@angular/http"; 5 | 6 | import { FieldBase } from "../field/field-base"; 7 | import { LoginService } from "../../../core/services/login.service"; 8 | import { UserService } from "../../../core/services/user.service"; 9 | 10 | @Component({ 11 | selector: "login", 12 | templateUrl: "login.component.html", 13 | styleUrls: ["login.component.css"] 14 | }) 15 | export class LoginComponent implements OnInit { 16 | form: FormGroup; 17 | fields: FieldBase[] = []; 18 | returnUrl: string = ""; 19 | 20 | constructor( 21 | private rs: LoginService, 22 | private activeRoute: ActivatedRoute, 23 | private route: Router, 24 | private userService: UserService 25 | ) { 26 | this.fields = rs.getFields(); 27 | this.activeRoute.queryParams.subscribe(params => { 28 | this.returnUrl = params["returnUrl"]; 29 | }); 30 | } 31 | 32 | ngOnInit() { 33 | this.form = this.rs.toFormGroup(this.fields); 34 | } 35 | 36 | login() { 37 | this.rs.login(this.form.value).subscribe( 38 | (res: Response) => { 39 | let body = res.json(); 40 | if (body && body.success) { 41 | this.userService.setUser({ 42 | username: this.form.value.username, 43 | createDate: new Date().toLocaleString() 44 | }); 45 | this.route.navigateByUrl(this.returnUrl ? this.returnUrl : "/"); 46 | } 47 | }, 48 | error => { 49 | console.error(error); 50 | } 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/register/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This barrel file provides the export for the lazy loaded RegisterComponent. 3 | */ 4 | export * from './register.component'; 5 | 6 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/register/register.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | margin: 20px 20%; 4 | } 5 | 6 | h2, h3 { 7 | font-size: 52px; 8 | font-weight: 500; 9 | letter-spacing: 0.005em; 10 | margin-bottom: 0; 11 | margin-top: 0.83em; 12 | text-align: center; 13 | } 14 | 15 | h3 { 16 | font-size: 40px; 17 | } 18 | 19 | .form-row { 20 | height: 115px; 21 | } 22 | 23 | .form-checkbox { 24 | height: 30px; 25 | margin: 36px 16px 0; 26 | } 27 | 28 | button { 29 | margin: 40px 16px; 30 | padding: 0 32px; 31 | text-align: center; 32 | } 33 | 34 | button[disabled] { 35 | background-color: #ccc; 36 | } 37 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/register/register.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

注册

4 |
5 | 6 |
7 | 8 |
9 | 10 |
11 | 12 | 13 |
14 | 15 |
16 | 17 | 18 |
19 |
20 |
21 |
22 | 23 | {{ alert?.msg }} 24 | 25 |
26 |
-------------------------------------------------------------------------------- /frontend/src/app/user/shared/register/register.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormGroup } from '@angular/forms'; 3 | import { Router } from '@angular/router'; 4 | import { Observable } from 'rxjs/Observable'; 5 | import { Observer } from 'rxjs/Observer'; 6 | 7 | import { FieldBase } from '../field/field-base'; 8 | import { RegisterService } from '../../../core/services/register.service'; 9 | import { UserService } from '../../../core/services/user.service'; 10 | 11 | @Component({ 12 | selector: 'register', 13 | templateUrl: 'register.component.html', 14 | styleUrls: ['register.component.css'] 15 | }) 16 | export class RegisterComponent implements OnInit { 17 | 18 | form: FormGroup; 19 | registered = false; 20 | fields: FieldBase[] = []; 21 | alert:any = {msg: '注册成功', type: 'success', closable: true}; 22 | 23 | constructor(private rs: RegisterService, 24 | private userService:UserService, 25 | private route:Router) { 26 | this.fields = rs.getFields(); 27 | } 28 | 29 | ngOnInit() { 30 | this.form = this.rs.toFormGroup(this.fields); 31 | } 32 | 33 | showPassword () { 34 | this.fields.forEach((field : any) => { 35 | if (field.key === 'password') { 36 | field.type = field.type === 'password' ? 'text' : 'password'; 37 | } 38 | }); 39 | } 40 | 41 | resetForm () { 42 | this.form.reset(); 43 | } 44 | 45 | register() { 46 | this.rs 47 | .addUser(this.form.value) 48 | .subscribe((res: any) => { 49 | let body = res.json(); 50 | this.registered = true; 51 | new Observable((observer: Observer) => { 52 | this.alert.msg = body.message || "注册成功"; // 操作提示信息 53 | this.alert.type =body.success ? "success" : "danger"; 54 | this.registered = true; 55 | observer.next(true); 56 | }).delay(2000).subscribe(data=>{ // 操作提示,2秒后跳转到首页 57 | if(body.success) { 58 | this.userService.isLogin = true; // 设置当前用户已登录 59 | this.userService.userInfo = { username: this.form.value.username,createDate:new Date().toLocaleString()} // 缓存用户信息,显示在导航栏上 60 | this.route.navigate(['']); // 跳到首页 61 | } 62 | this.registered = false; 63 | }); 64 | }, (error: any) => { 65 | console.error(error); 66 | }); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /frontend/src/app/user/shared/user-shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { ReactiveFormsModule } from '@angular/forms'; 4 | 5 | import { AlertModule } from 'ngx-bootstrap'; 6 | import { SharedModule } from '../../shared/shared.module'; 7 | import { FieldComponent } from './field/index'; 8 | // import { RegisterComponent } from './register/index'; 9 | 10 | @NgModule({ 11 | imports: [CommonModule, ReactiveFormsModule, SharedModule, AlertModule], 12 | declarations: [FieldComponent], 13 | exports: [FieldComponent, CommonModule] 14 | }) 15 | export class UserSharedModule { } -------------------------------------------------------------------------------- /frontend/src/app/user/user-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { LoginComponent } from './shared/login/login.component'; 4 | import { RegisterComponent } from './shared/register/register.component'; 5 | 6 | const routes: Routes = [ 7 | { path: 'login', component: LoginComponent }, 8 | { path: 'register', component: RegisterComponent } 9 | ]; 10 | @NgModule({ 11 | imports: [ 12 | RouterModule.forChild(routes) 13 | ], 14 | exports: [ 15 | RouterModule 16 | ] 17 | }) 18 | export class UserRoutingModule { } 19 | -------------------------------------------------------------------------------- /frontend/src/app/user/user.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { SharedModule } from '../shared/shared.module'; 5 | import { AlertModule } from 'ngx-bootstrap'; 6 | import { UserSharedModule } from './shared/user-shared.module'; 7 | import { UserRoutingModule } from './user-routing.module'; 8 | 9 | import { LoginComponent, RegisterComponent } from './shared'; 10 | 11 | @NgModule({ 12 | imports: [CommonModule, SharedModule, AlertModule, UserSharedModule, UserRoutingModule], 13 | declarations: [ LoginComponent, RegisterComponent ], 14 | exports: [CommonModule, UserSharedModule] 15 | }) 16 | export class UserModule { } 17 | -------------------------------------------------------------------------------- /frontend/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/.gitkeep -------------------------------------------------------------------------------- /frontend/src/assets/img/about/create.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/about/create.jpg -------------------------------------------------------------------------------- /frontend/src/assets/img/about/faq.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/about/faq.jpg -------------------------------------------------------------------------------- /frontend/src/assets/img/about/my.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/about/my.jpg -------------------------------------------------------------------------------- /frontend/src/assets/img/edit/checkbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/edit/checkbox.png -------------------------------------------------------------------------------- /frontend/src/assets/img/edit/radio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/edit/radio.png -------------------------------------------------------------------------------- /frontend/src/assets/img/edit/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/edit/star.png -------------------------------------------------------------------------------- /frontend/src/assets/img/edit/text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/edit/text.png -------------------------------------------------------------------------------- /frontend/src/assets/img/home/banner_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/home/banner_01.jpg -------------------------------------------------------------------------------- /frontend/src/assets/img/home/banner_02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/home/banner_02.jpg -------------------------------------------------------------------------------- /frontend/src/assets/img/home/banner_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/home/banner_03.jpg -------------------------------------------------------------------------------- /frontend/src/assets/img/notfound.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angular-programming/angular-questionnaire/1c0b80face5bf6180d2807732d4389830bfca336/frontend/src/assets/img/notfound.png -------------------------------------------------------------------------------- /frontend/src/assets/svg/more.svg: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /frontend/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /frontend/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 | -------------------------------------------------------------------------------- /frontend/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angular调查问卷 6 | 7 | 8 | 9 | 10 | 11 | 12 | Loading... 13 | 14 | 15 | -------------------------------------------------------------------------------- /frontend/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /frontend/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/set'; 35 | 36 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 37 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 38 | 39 | /** IE10 and IE11 requires the following to support `@angular/animation`. */ 40 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 41 | 42 | 43 | /** Evergreen browsers require these. **/ 44 | import 'core-js/es6/reflect'; 45 | import 'core-js/es7/reflect'; 46 | 47 | 48 | /** ALL Firefox browsers require the following to support `@angular/animation`. **/ 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 | -------------------------------------------------------------------------------- /frontend/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /frontend/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 var __karma__: any; 17 | declare var 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 | -------------------------------------------------------------------------------- /frontend/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "declaration": false, 5 | "moduleResolution": "node", 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "lib": [ 9 | "es2016", 10 | "dom" 11 | ], 12 | "outDir": "../out-tsc/app", 13 | "target": "es5", 14 | "module": "es2015", 15 | "baseUrl": "", 16 | "types": [] 17 | }, 18 | "exclude": [ 19 | "test.ts", 20 | "**/*.spec.ts" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /frontend/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "declaration": false, 5 | "moduleResolution": "node", 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "lib": [ 9 | "es2016" 10 | ], 11 | "outDir": "../out-tsc/spec", 12 | "module": "commonjs", 13 | "target": "es6", 14 | "baseUrl": "", 15 | "types": [ 16 | "jasmine", 17 | "node" 18 | ] 19 | }, 20 | "files": [ 21 | "test.ts" 22 | ], 23 | "include": [ 24 | "**/*.spec.ts" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /frontend/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: { 3 | id: string; 4 | }; 5 | -------------------------------------------------------------------------------- /frontend/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 | } 20 | -------------------------------------------------------------------------------- /frontend/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 | "eofline": true, 15 | "forin": true, 16 | "import-blacklist": [ 17 | true, 18 | "rxjs", 19 | "rxjs/Rx" 20 | ], 21 | "import-spacing": true, 22 | "indent": [ 23 | true, 24 | "spaces" 25 | ], 26 | "interface-over-type-literal": true, 27 | "label-position": true, 28 | "max-line-length": [ 29 | true, 30 | 140 31 | ], 32 | "member-access": false, 33 | "member-ordering": [ 34 | true, 35 | { 36 | "order": [ 37 | "static-field", 38 | "instance-field", 39 | "static-method", 40 | "instance-method" 41 | ] 42 | } 43 | ], 44 | "no-arg": true, 45 | "no-bitwise": true, 46 | "no-console": [ 47 | true, 48 | "debug", 49 | "info", 50 | "time", 51 | "timeEnd", 52 | "trace" 53 | ], 54 | "no-construct": true, 55 | "no-debugger": true, 56 | "no-duplicate-super": true, 57 | "no-empty": false, 58 | "no-empty-interface": true, 59 | "no-eval": true, 60 | "no-inferrable-types": [ 61 | true, 62 | "ignore-params" 63 | ], 64 | "no-misused-new": true, 65 | "no-non-null-assertion": true, 66 | "no-shadowed-variable": true, 67 | "no-string-literal": false, 68 | "no-string-throw": true, 69 | "no-switch-case-fall-through": true, 70 | "no-trailing-whitespace": true, 71 | "no-unnecessary-initializer": true, 72 | "no-unused-expression": true, 73 | "no-use-before-declare": true, 74 | "no-var-keyword": true, 75 | "object-literal-sort-keys": false, 76 | "one-line": [ 77 | true, 78 | "check-open-brace", 79 | "check-catch", 80 | "check-else", 81 | "check-whitespace" 82 | ], 83 | "prefer-const": true, 84 | "quotemark": [ 85 | true, 86 | "single" 87 | ], 88 | "radix": true, 89 | "semicolon": [ 90 | true, 91 | "always" 92 | ], 93 | "triple-equals": [ 94 | true, 95 | "allow-null-check" 96 | ], 97 | "typedef-whitespace": [ 98 | true, 99 | { 100 | "call-signature": "nospace", 101 | "index-signature": "nospace", 102 | "parameter": "nospace", 103 | "property-declaration": "nospace", 104 | "variable-declaration": "nospace" 105 | } 106 | ], 107 | "typeof-compare": true, 108 | "unified-signatures": true, 109 | "variable-name": false, 110 | "whitespace": [ 111 | true, 112 | "check-branch", 113 | "check-decl", 114 | "check-operator", 115 | "check-separator", 116 | "check-type" 117 | ], 118 | "directive-selector": [ 119 | true, 120 | "attribute", 121 | "app", 122 | "camelCase" 123 | ], 124 | "component-selector": [ 125 | true, 126 | "element", 127 | "app", 128 | "kebab-case" 129 | ], 130 | "use-input-property-decorator": true, 131 | "use-output-property-decorator": true, 132 | "use-host-property-decorator": true, 133 | "no-input-rename": true, 134 | "no-output-rename": true, 135 | "use-life-cycle-interface": true, 136 | "use-pipe-transform-interface": true, 137 | "component-class-suffix": true, 138 | "directive-class-suffix": true, 139 | "invoke-injectable": true 140 | } 141 | } 142 | --------------------------------------------------------------------------------