From 2dc962c75482095892c991ac4e8b244c2c9f7abf Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 3 Sep 2020 10:53:41 +0200 Subject: [PATCH] implemented editable help --- src/app/app.component.ts | 2 +- .../documentation-database.component.html | 17 +++++++++ src/app/help/help.component.html | 37 ++++++++++++------- src/app/help/help.component.scss | 3 ++ src/app/help/help.component.ts | 36 ++++++++++++++++-- src/app/models/help.model.spec.ts | 7 ++++ src/app/models/help.model.ts | 6 +++ 7 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 src/app/models/help.model.spec.ts create mode 100644 src/app/models/help.model.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 25d053b..7d08253 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -37,7 +37,7 @@ export class AppComponent implements OnInit{ ngOnInit() { this.login.login().then(res => { - if (!res && !(this.route.snapshot.url.length && this.route.snapshot.url[0].path === '/documentation')) { + if (!res && !(/\/documentation/.test(this.router.url))) { this.router.navigate(['/']); } }); diff --git a/src/app/documentation/documentation-database/documentation-database.component.html b/src/app/documentation/documentation-database/documentation-database.component.html index e2ede6d..4562eb1 100644 --- a/src/app/documentation/documentation-database/documentation-database.component.html +++ b/src/app/documentation/documentation-database/documentation-database.component.html @@ -387,4 +387,21 @@ Every time: The user that executed this command '5f2e63118d1c020f8cda6a09' + + help + + _id + Automatically generated unique id + '5f2e63d28d1c020f8cda6f86' + + + key + The key used to find the required help text + '/documentation/database' + + + text + The actual help text + 'This page documents the database.' + diff --git a/src/app/help/help.component.html b/src/app/help/help.component.html index 2b615dc..7e6450b 100644 --- a/src/app/help/help.component.html +++ b/src/app/help/help.component.html @@ -1,14 +1,25 @@ -

Help

+

Help + +

- -

Please log in for further access. If you do not have an account yet, please contact - {{d.contact.name}}. -

-

Please log in for further access. If you do not have an account yet, please contact - {{d.contact.name}}. -

-

- Sadly, currently there is no help available for this page. Please contact - {{d.contact.name}} for further questions. -

-
+
+ + + + + + Save + Delete +
+ + +

+ {{content.text}} +

+ + + Sadly, currently there is no help available for this page. Please contact + {{d.contact.name}} for further questions. + + +
diff --git a/src/app/help/help.component.scss b/src/app/help/help.component.scss index e69de29..b7b3479 100644 --- a/src/app/help/help.component.scss +++ b/src/app/help/help.component.scss @@ -0,0 +1,3 @@ +.delete-btn { + float: right; +} diff --git a/src/app/help/help.component.ts b/src/app/help/help.component.ts index 371000d..77db6ec 100644 --- a/src/app/help/help.component.ts +++ b/src/app/help/help.component.ts @@ -1,6 +1,9 @@ import { Component, OnInit } from '@angular/core'; import {Router} from '@angular/router'; import {DataService} from '../services/data.service'; +import {ApiService} from '../services/api.service'; +import {HelpModel} from '../models/help.model'; +import {LoginService} from '../services/login.service'; @Component({ selector: 'app-help', @@ -9,16 +12,41 @@ import {DataService} from '../services/data.service'; }) export class HelpComponent implements OnInit { - route = ''; + content: HelpModel = new HelpModel().deserialize({text: null, level: 'none'}); + edit = false; + private route = ''; constructor( private router: Router, - public d: DataService + public d: DataService, + private api: ApiService, + public login: LoginService ) { } ngOnInit(): void { - this.route = this.router.url.replace(/\/[0-9a-f]{24}/, ''); // remove ids - console.log(this.route); + this.route = encodeURIComponent(this.router.url.replace(/\/[0-9a-f]{24}/, '')); + // remove ids from path and get help content + this.api.get('/help/' + this.route, (data, err) => { + if (!err) { // content was found + this.content = new HelpModel().deserialize(data); + } + else { + this.content.text = ''; + } + console.log(this.content); + }); } + saveHelp() { + this.api.post('/help/' + this.route, this.content.sendFormat(), () => { + this.edit = false; + }); + } + + deleteHelp() { + this.api.delete('/help/' + this.route, (ignore, ignore) => { + this.content = new HelpModel().deserialize({text: null, level: 'none'}); + this.edit = false; + }); + } } diff --git a/src/app/models/help.model.spec.ts b/src/app/models/help.model.spec.ts new file mode 100644 index 0000000..899436f --- /dev/null +++ b/src/app/models/help.model.spec.ts @@ -0,0 +1,7 @@ +import { HelpModel } from './help.model'; + +describe('Help.Model', () => { + it('should create an instance', () => { + expect(new HelpModel()).toBeTruthy(); + }); +}); diff --git a/src/app/models/help.model.ts b/src/app/models/help.model.ts new file mode 100644 index 0000000..cc4e63b --- /dev/null +++ b/src/app/models/help.model.ts @@ -0,0 +1,6 @@ +import {BaseModel} from './base.model'; + +export class HelpModel extends BaseModel { + text = ''; + level = 'none'; +}