implemented editable help

This commit is contained in:
VLE2FE 2020-09-03 10:53:41 +02:00
parent bda6331c59
commit 2dc962c754
7 changed files with 90 additions and 18 deletions

View File

@ -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(['/']);
}
});

View File

@ -387,4 +387,21 @@ Every time:
<td>The user that executed this command</td>
<td>'5f2e63118d1c020f8cda6a09'</td>
</tr>
<tr><th>help</th><th></th><th></th></tr>
<tr>
<td>_id</td>
<td>Automatically generated unique id</td>
<td>'5f2e63d28d1c020f8cda6f86'</td>
</tr>
<tr>
<td>key</td>
<td>The key used to find the required help text</td>
<td>'/documentation/database'</td>
</tr>
<tr>
<td>text</td>
<td>The actual help text</td>
<td>'This page documents the database.'</td>
</tr>
</rb-table>

View File

@ -1,14 +1,25 @@
<h3>Help</h3>
<h3>Help
<span *ngIf="login.isLevel.dev" class="rb-ic rb-ic-edit clickable space-left" (click)="edit = true"></span>
</h3>
<ng-container [ngSwitch]="route">
<p *ngSwitchCase="'/'">Please log in for further access. If you do not have an account yet, please contact
<a [href]="'mailto:' + d.contact.mail">{{d.contact.name}}</a>.
<div *ngIf="edit; else normalView">
<rb-form-select label="level" [(ngModel)]="content.level">
<option value="none">none</option>
<option *ngFor="let level of login.levels" [value]="level">{{level}}</option>
</rb-form-select>
<rb-form-textarea label="text" [(ngModel)]="content.text"></rb-form-textarea>
<rb-icon-button icon="save" mode="primary" (click)="saveHelp()">Save</rb-icon-button>
<rb-icon-button icon="delete" mode="danger" (click)="deleteHelp()" class="delete-btn">Delete</rb-icon-button>
</div>
<ng-template #normalView>
<p *ngIf="content.text; else defaultContent">
{{content.text}}
</p>
<p *ngSwitchCase="'/home'">Please log in for further access. If you do not have an account yet, please contact
<a [href]="'mailto:' + d.contact.mail">{{d.contact.name}}</a>.
</p>
<p *ngSwitchDefault>
<ng-template #defaultContent>
<ng-container *ngIf="content.text === ''">
Sadly, currently there is no help available for this page. Please contact
<a [href]="'mailto:' + d.contact.mail">{{d.contact.name}}</a> for further questions.
</p>
</ng-container>
</ng-template>
</ng-template>

View File

@ -0,0 +1,3 @@
.delete-btn {
float: right;
}

View File

@ -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<HelpModel>('/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;
});
}
}

View File

@ -0,0 +1,7 @@
import { HelpModel } from './help.model';
describe('Help.Model', () => {
it('should create an instance', () => {
expect(new HelpModel()).toBeTruthy();
});
});

View File

@ -0,0 +1,6 @@
import {BaseModel} from './base.model';
export class HelpModel extends BaseModel {
text = '';
level = 'none';
}