implemented editable help
This commit is contained in:
parent
bda6331c59
commit
2dc962c754
@ -37,7 +37,7 @@ export class AppComponent implements OnInit{
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.login.login().then(res => {
|
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(['/']);
|
this.router.navigate(['/']);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -387,4 +387,21 @@ Every time:
|
|||||||
<td>The user that executed this command</td>
|
<td>The user that executed this command</td>
|
||||||
<td>'5f2e63118d1c020f8cda6a09'</td>
|
<td>'5f2e63118d1c020f8cda6a09'</td>
|
||||||
</tr>
|
</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>
|
</rb-table>
|
||||||
|
@ -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">
|
<div *ngIf="edit; else normalView">
|
||||||
<p *ngSwitchCase="'/'">Please log in for further access. If you do not have an account yet, please contact
|
<rb-form-select label="level" [(ngModel)]="content.level">
|
||||||
<a [href]="'mailto:' + d.contact.mail">{{d.contact.name}}</a>.
|
<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>
|
||||||
<p *ngSwitchCase="'/home'">Please log in for further access. If you do not have an account yet, please contact
|
<ng-template #defaultContent>
|
||||||
<a [href]="'mailto:' + d.contact.mail">{{d.contact.name}}</a>.
|
<ng-container *ngIf="content.text === ''">
|
||||||
</p>
|
|
||||||
<p *ngSwitchDefault>
|
|
||||||
Sadly, currently there is no help available for this page. Please contact
|
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.
|
<a [href]="'mailto:' + d.contact.mail">{{d.contact.name}}</a> for further questions.
|
||||||
</p>
|
</ng-container>
|
||||||
</ng-container>
|
</ng-template>
|
||||||
|
</ng-template>
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
.delete-btn {
|
||||||
|
float: right;
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {DataService} from '../services/data.service';
|
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({
|
@Component({
|
||||||
selector: 'app-help',
|
selector: 'app-help',
|
||||||
@ -9,16 +12,41 @@ import {DataService} from '../services/data.service';
|
|||||||
})
|
})
|
||||||
export class HelpComponent implements OnInit {
|
export class HelpComponent implements OnInit {
|
||||||
|
|
||||||
route = '';
|
content: HelpModel = new HelpModel().deserialize({text: null, level: 'none'});
|
||||||
|
edit = false;
|
||||||
|
private route = '';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
public d: DataService
|
public d: DataService,
|
||||||
|
private api: ApiService,
|
||||||
|
public login: LoginService
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.route = this.router.url.replace(/\/[0-9a-f]{24}/, ''); // remove ids
|
this.route = encodeURIComponent(this.router.url.replace(/\/[0-9a-f]{24}/, ''));
|
||||||
console.log(this.route);
|
// 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
7
src/app/models/help.model.spec.ts
Normal file
7
src/app/models/help.model.spec.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { HelpModel } from './help.model';
|
||||||
|
|
||||||
|
describe('Help.Model', () => {
|
||||||
|
it('should create an instance', () => {
|
||||||
|
expect(new HelpModel()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
6
src/app/models/help.model.ts
Normal file
6
src/app/models/help.model.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import {BaseModel} from './base.model';
|
||||||
|
|
||||||
|
export class HelpModel extends BaseModel {
|
||||||
|
text = '';
|
||||||
|
level = 'none';
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user