|
@@ -1,6 +1,9 @@
|
|
-import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
|
|
|
|
+import { Component, OnInit, OnDestroy, Inject } from '@angular/core';
|
|
import { Editor } from 'ngx-editor';
|
|
import { Editor } from 'ngx-editor';
|
|
-import { marked } from 'marked';
|
|
|
|
|
|
+import { DateAdapter } from '@angular/material/core';
|
|
|
|
+import { JournalEntry } from 'src/interfaces/interfaces';
|
|
|
|
+import localeDe from '@angular/common/locales/de';
|
|
|
|
+import { registerLocaleData } from '@angular/common';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-journal-notes',
|
|
selector: 'app-journal-notes',
|
|
@@ -10,27 +13,88 @@ import { marked } from 'marked';
|
|
export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
editor: Editor = new Editor();
|
|
editor: Editor = new Editor();
|
|
html = '';
|
|
html = '';
|
|
|
|
+ isInEditMode = true;
|
|
|
|
+ currentEntryIndex: number = 0;
|
|
|
|
+ isNewEntry = false;
|
|
|
|
|
|
- markdownString =
|
|
|
|
- ' # Hello \n \
|
|
|
|
- this is a test \
|
|
|
|
- **hi** \
|
|
|
|
- \
|
|
|
|
- - 1\
|
|
|
|
- - 2';
|
|
|
|
|
|
+ public entries: JournalEntry[] = [
|
|
|
|
+ {
|
|
|
|
+ title: 'testtitle',
|
|
|
|
+ content: 'testcontent',
|
|
|
|
+ created: new Date(2024, 8, 29),
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: 'zweiter titel',
|
|
|
|
+ content: 'zweiter content',
|
|
|
|
+ created: new Date(2023, 1, 2),
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+ currentEntry: JournalEntry = this.entries[this.currentEntryIndex];
|
|
|
|
|
|
- htmlString = '';
|
|
|
|
|
|
+ toolbar: any = [
|
|
|
|
+ // default value
|
|
|
|
+ ['bold', 'italic'],
|
|
|
|
+ ['bullet_list'],
|
|
|
|
+ [{ heading: ['h3', 'h4', 'h5', 'h6'] }],
|
|
|
|
+ ];
|
|
|
|
|
|
- constructor() {
|
|
|
|
- this.htmlString = marked(this.markdownString);
|
|
|
|
- console.log(this.markdownString);
|
|
|
|
- console.log(this.htmlString);
|
|
|
|
|
|
+ constructor(private _adapter: DateAdapter<any>) {
|
|
|
|
+ registerLocaleData(localeDe);
|
|
}
|
|
}
|
|
|
|
|
|
- ngOnInit(): void {}
|
|
|
|
|
|
+ ngOnInit(): void {
|
|
|
|
+ this._adapter.setLocale('de');
|
|
|
|
+ }
|
|
|
|
|
|
// make sure to destory the editor
|
|
// make sure to destory the editor
|
|
ngOnDestroy(): void {
|
|
ngOnDestroy(): void {
|
|
this.editor.destroy();
|
|
this.editor.destroy();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public activateEntry(index: number): void {
|
|
|
|
+ this.currentEntryIndex = index;
|
|
|
|
+ this.currentEntry = this.entries[index];
|
|
|
|
+ this.isInEditMode = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ addEntry(): void {
|
|
|
|
+ this.currentEntry = {
|
|
|
|
+ title: '',
|
|
|
|
+ content: '',
|
|
|
|
+ created: new Date(),
|
|
|
|
+ };
|
|
|
|
+ this.isNewEntry = true;
|
|
|
|
+ this.isInEditMode = true;
|
|
|
|
+ // Hightlight no entry
|
|
|
|
+ this.currentEntryIndex = -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public saveEntry(): void {
|
|
|
|
+ if (this.isNewEntry) {
|
|
|
|
+ // Prepend the new JournalEntry
|
|
|
|
+ this.entries = [this.currentEntry, ...this.entries];
|
|
|
|
+ this.isNewEntry = false;
|
|
|
|
+ this.currentEntryIndex = 0;
|
|
|
|
+ }
|
|
|
|
+ this.isInEditMode = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public discardEntry(): void {
|
|
|
|
+ if (this.isNewEntry) {
|
|
|
|
+ // this.currentEntryIndex = this.entries.length - 1;
|
|
|
|
+ this.isNewEntry = false;
|
|
|
|
+ }
|
|
|
|
+ this.currentEntry = this.entries[this.currentEntryIndex];
|
|
|
|
+ this.isInEditMode = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ deleteEntry(): void {
|
|
|
|
+ this.entries.splice(this.currentEntryIndex, 1);
|
|
|
|
+ if (this.entries.length === 0) {
|
|
|
|
+ this.currentEntryIndex = -1;
|
|
|
|
+ } else {
|
|
|
|
+ this.currentEntryIndex = Math.max(this.currentEntryIndex - 1, 0);
|
|
|
|
+ this.currentEntry = this.entries[this.currentEntryIndex];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|