2020-08-20 10:42:02 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import {Router} from '@angular/router';
|
|
|
|
import {DataService} from '../services/data.service';
|
2020-09-03 10:53:41 +02:00
|
|
|
import {ApiService} from '../services/api.service';
|
|
|
|
import {HelpModel} from '../models/help.model';
|
|
|
|
import {LoginService} from '../services/login.service';
|
2020-08-20 10:42:02 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-help',
|
|
|
|
templateUrl: './help.component.html',
|
|
|
|
styleUrls: ['./help.component.scss']
|
|
|
|
})
|
|
|
|
export class HelpComponent implements OnInit {
|
|
|
|
|
2020-09-03 15:51:53 +02:00
|
|
|
content: HelpModel = new HelpModel().deserialize({text: null, level: 'none'}); // help content
|
|
|
|
edit = false; // set true to change to edit mode
|
|
|
|
private route = ''; // URIComponent encoded route which serves as a key to fetch the help document
|
2020-08-20 10:42:02 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private router: Router,
|
2020-09-03 10:53:41 +02:00
|
|
|
public d: DataService,
|
|
|
|
private api: ApiService,
|
|
|
|
public login: LoginService
|
2020-08-20 10:42:02 +02:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-09-03 15:51:53 +02:00
|
|
|
// remove ids from path
|
2020-09-03 10:53:41 +02:00
|
|
|
this.route = encodeURIComponent(this.router.url.replace(/\/[0-9a-f]{24}/, ''));
|
|
|
|
this.api.get<HelpModel>('/help/' + this.route, (data, err) => {
|
|
|
|
if (!err) { // content was found
|
|
|
|
this.content = new HelpModel().deserialize(data);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.content.text = '';
|
|
|
|
}
|
|
|
|
});
|
2020-08-20 10:42:02 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 10:53:41 +02:00
|
|
|
saveHelp() {
|
|
|
|
this.api.post('/help/' + this.route, this.content.sendFormat(), () => {
|
|
|
|
this.edit = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteHelp() {
|
2020-09-03 10:54:20 +02:00
|
|
|
this.api.delete('/help/' + this.route, (ignore, err) => {
|
|
|
|
if (!err) {
|
|
|
|
this.content = new HelpModel().deserialize({text: null, level: 'none'});
|
|
|
|
this.edit = false;
|
|
|
|
}
|
2020-09-03 10:53:41 +02:00
|
|
|
});
|
|
|
|
}
|
2020-08-20 10:42:02 +02:00
|
|
|
}
|