|
@@ -3,7 +3,6 @@ import {
|
|
OnInit,
|
|
OnInit,
|
|
OnDestroy,
|
|
OnDestroy,
|
|
inject,
|
|
inject,
|
|
- ComponentFactoryResolver,
|
|
|
|
TemplateRef,
|
|
TemplateRef,
|
|
ViewChild,
|
|
ViewChild,
|
|
ViewContainerRef,
|
|
ViewContainerRef,
|
|
@@ -18,7 +17,6 @@ import { registerLocaleData } from '@angular/common';
|
|
import { DataService } from 'src/services/data/data.service';
|
|
import { DataService } from 'src/services/data/data.service';
|
|
import { TooltipService } from 'src/services/tooltip/tooltip.service';
|
|
import { TooltipService } from 'src/services/tooltip/tooltip.service';
|
|
import { HighlightComponent } from 'src/app/shared-components/highlight/highlight.component';
|
|
import { HighlightComponent } from 'src/app/shared-components/highlight/highlight.component';
|
|
-import { DomSanitizer } from '@angular/platform-browser';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-journal-notes',
|
|
selector: 'app-journal-notes',
|
|
@@ -26,12 +24,12 @@ import { DomSanitizer } from '@angular/platform-browser';
|
|
styleUrl: './journal-notes.component.scss',
|
|
styleUrl: './journal-notes.component.scss',
|
|
})
|
|
})
|
|
export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
|
+ /** Reference to the tooltip */
|
|
@ViewChild('tooltip', { read: TemplateRef }) tooltip!: TemplateRef<any>;
|
|
@ViewChild('tooltip', { read: TemplateRef }) tooltip!: TemplateRef<any>;
|
|
- @ViewChild('test', { read: ViewContainerRef }) test!: ViewContainerRef;
|
|
|
|
|
|
|
|
- tooltipText = 'Initial';
|
|
|
|
-
|
|
|
|
- public npcDescriptions: any = {};
|
|
|
|
|
|
+ /** Reference to the creation anchor */
|
|
|
|
+ @ViewChild('creationAnchor', { read: ViewContainerRef })
|
|
|
|
+ creationAnchor!: ViewContainerRef;
|
|
|
|
|
|
editor: Editor = new Editor();
|
|
editor: Editor = new Editor();
|
|
toolbar: any = [
|
|
toolbar: any = [
|
|
@@ -41,20 +39,21 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
[{ heading: ['h3', 'h4', 'h5', 'h6'] }],
|
|
[{ heading: ['h3', 'h4', 'h5', 'h6'] }],
|
|
];
|
|
];
|
|
|
|
|
|
- /** Used to show the interactale form or the display version of an entry. */
|
|
|
|
- public isInEditMode = false;
|
|
|
|
|
|
+ public entries: JournalEntry[] = [];
|
|
|
|
+ public currentEntry: JournalEntry = {
|
|
|
|
+ title: '',
|
|
|
|
+ content: '',
|
|
|
|
+ created: new Date(),
|
|
|
|
+ };
|
|
|
|
|
|
- /** The index of the currently active entry */
|
|
|
|
|
|
+ public isInEditMode = false;
|
|
public currentEntryIndex: number = 0;
|
|
public currentEntryIndex: number = 0;
|
|
-
|
|
|
|
private backupIndex: number = -1;
|
|
private backupIndex: number = -1;
|
|
- /** Indicates, if the currentEntry is a newly generated one that is still not saved. */
|
|
|
|
public isNewEntry = false;
|
|
public isNewEntry = false;
|
|
|
|
|
|
- /**The array of JournalEntries, synched to the */
|
|
|
|
- public entries: JournalEntry[] = [];
|
|
|
|
|
|
+ public tooltipText: string = '';
|
|
|
|
|
|
- public tooltipifiedEntries: JournalEntry[] = [];
|
|
|
|
|
|
+ public npcDescriptions: any = {};
|
|
|
|
|
|
tooltipifiedEntry: JournalEntry = {
|
|
tooltipifiedEntry: JournalEntry = {
|
|
title: 'Title',
|
|
title: 'Title',
|
|
@@ -62,17 +61,9 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
created: new Date(),
|
|
created: new Date(),
|
|
};
|
|
};
|
|
|
|
|
|
- /** Holds the data for the current entry */
|
|
|
|
- public currentEntry: JournalEntry = {
|
|
|
|
- title: '',
|
|
|
|
- content: '',
|
|
|
|
- created: new Date(),
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
private _adapter: DateAdapter<any> = inject(DateAdapter);
|
|
private _adapter: DateAdapter<any> = inject(DateAdapter);
|
|
private dataService: DataService = inject(DataService);
|
|
private dataService: DataService = inject(DataService);
|
|
private tooltipService: TooltipService = inject(TooltipService);
|
|
private tooltipService: TooltipService = inject(TooltipService);
|
|
- private sanitizer: DomSanitizer = inject(DomSanitizer);
|
|
|
|
private renderer: Renderer2 = inject(Renderer2);
|
|
private renderer: Renderer2 = inject(Renderer2);
|
|
private el: ElementRef = inject(ElementRef);
|
|
private el: ElementRef = inject(ElementRef);
|
|
|
|
|
|
@@ -80,7 +71,6 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
registerLocaleData(localeDe);
|
|
registerLocaleData(localeDe);
|
|
this._adapter.setLocale('de');
|
|
this._adapter.setLocale('de');
|
|
this.entries = this.dataService.notesData;
|
|
this.entries = this.dataService.notesData;
|
|
- this.tooltipifiedEntries = this.entries;
|
|
|
|
|
|
|
|
// if the list is empty, set the currentEntryIndex to -1 to hide the entry-container
|
|
// if the list is empty, set the currentEntryIndex to -1 to hide the entry-container
|
|
if (this.entries.length === 0) {
|
|
if (this.entries.length === 0) {
|
|
@@ -92,23 +82,28 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
this.tooltipify();
|
|
this.tooltipify();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // ACTIONS FROM THE TEMPLATE
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Sets the currentEntry variable when being clicked on in the entries list on the left.
|
|
* Sets the currentEntry variable when being clicked on in the entries list on the left.
|
|
|
|
+ * It also modifies the content of the entry by highlighting names and adding tooltips.
|
|
|
|
+ * Is only called when the entry is not in edit mode or a different entry is selected.
|
|
* @param index The index of the selected entry.
|
|
* @param index The index of the selected entry.
|
|
*/
|
|
*/
|
|
public selectEntry(index: number): void {
|
|
public selectEntry(index: number): void {
|
|
- this.currentEntryIndex = index;
|
|
|
|
- this.currentEntry = this.getEntryAt(index);
|
|
|
|
- this.isNewEntry = false;
|
|
|
|
- this.isInEditMode = false;
|
|
|
|
- // this.tooltipify();
|
|
|
|
- this.collectNamesFromEntry().forEach((name) => {
|
|
|
|
- this.addHighlightsToText(name);
|
|
|
|
- });
|
|
|
|
|
|
+ if (this.isInEditMode || index !== this.currentEntryIndex) {
|
|
|
|
+ this.currentEntryIndex = index;
|
|
|
|
+ this.currentEntry = this.getEntryAt(index);
|
|
|
|
+ this.isNewEntry = false;
|
|
|
|
+ this.isInEditMode = false;
|
|
|
|
+ this.tooltipify();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- // DONE
|
|
|
|
- addEntry(): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Adds an new empty entry, switches to edit mode and removes the highlighting of the selected entry.
|
|
|
|
+ */
|
|
|
|
+ public addEntry(): void {
|
|
this.currentEntry = {
|
|
this.currentEntry = {
|
|
title: '',
|
|
title: '',
|
|
content: '',
|
|
content: '',
|
|
@@ -121,11 +116,18 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
this.currentEntryIndex = -1;
|
|
this.currentEntryIndex = -1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Switches to edit mode.
|
|
|
|
+ */
|
|
public editEntry(): void {
|
|
public editEntry(): void {
|
|
this.isInEditMode = true;
|
|
this.isInEditMode = true;
|
|
}
|
|
}
|
|
|
|
|
|
- // DONE
|
|
|
|
|
|
+ /**
|
|
|
|
+ * If the current entry is a new entry, it will be prepended to the entries list.
|
|
|
|
+ * Else it is saved at the current index.
|
|
|
|
+ * The content is the tooltipified and saved in the database.
|
|
|
|
+ */
|
|
public saveEntry(): void {
|
|
public saveEntry(): void {
|
|
if (this.isNewEntry) {
|
|
if (this.isNewEntry) {
|
|
// Prepend the new JournalEntry
|
|
// Prepend the new JournalEntry
|
|
@@ -139,6 +141,11 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
this.uploadNotes();
|
|
this.uploadNotes();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Discards the current entry and resets the currentEntry to the last saved version.
|
|
|
|
+ * If the entry was a new entry, the currentEntryIndex is reset to the last selected entry.
|
|
|
|
+ * The content is also tooltipified again.
|
|
|
|
+ */
|
|
public discardEntry(): void {
|
|
public discardEntry(): void {
|
|
if (this.isNewEntry) {
|
|
if (this.isNewEntry) {
|
|
this.currentEntryIndex = this.backupIndex;
|
|
this.currentEntryIndex = this.backupIndex;
|
|
@@ -149,8 +156,14 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
this.currentEntry = this.getEntryAt(this.currentEntryIndex);
|
|
this.currentEntry = this.getEntryAt(this.currentEntryIndex);
|
|
}
|
|
}
|
|
this.isInEditMode = false;
|
|
this.isInEditMode = false;
|
|
|
|
+ this.tooltipify();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Deletes the current entry and removes it from the entries list.
|
|
|
|
+ * If the last entry was deleted, the currentEntryIndex is reset to -1.
|
|
|
|
+ * The content is saved in the database.
|
|
|
|
+ */
|
|
public deleteEntry(): void {
|
|
public deleteEntry(): void {
|
|
this.entries.splice(this.currentEntryIndex, 1);
|
|
this.entries.splice(this.currentEntryIndex, 1);
|
|
if (this.entries.length === 0) {
|
|
if (this.entries.length === 0) {
|
|
@@ -158,93 +171,70 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
} else {
|
|
} else {
|
|
this.currentEntryIndex = Math.max(this.currentEntryIndex - 1, 0);
|
|
this.currentEntryIndex = Math.max(this.currentEntryIndex - 1, 0);
|
|
this.currentEntry = this.getEntryAt(this.currentEntryIndex);
|
|
this.currentEntry = this.getEntryAt(this.currentEntryIndex);
|
|
|
|
+ // Update the tooltipified entry
|
|
|
|
+ this.tooltipify();
|
|
}
|
|
}
|
|
this.uploadNotes();
|
|
this.uploadNotes();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns a deep copy of the entry at the given index.
|
|
|
|
+ * @param index Defines the index of the entry that should be returned.
|
|
|
|
+ * @returns A deep copy of the entry at the given index.
|
|
|
|
+ */
|
|
private getEntryAt(index: number): JournalEntry {
|
|
private getEntryAt(index: number): JournalEntry {
|
|
return JSON.parse(JSON.stringify(this.entries[index]));
|
|
return JSON.parse(JSON.stringify(this.entries[index]));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Saves the current entries in the data service.
|
|
|
|
+ */
|
|
private uploadNotes(): void {
|
|
private uploadNotes(): void {
|
|
this.dataService.notesData = this.entries;
|
|
this.dataService.notesData = this.entries;
|
|
}
|
|
}
|
|
|
|
|
|
- ////////////////////////////////////////////////////
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Converts the content of the current entry to a tooltipified version.
|
|
* Converts the content of the current entry to a tooltipified version.
|
|
- * Is called on everyx refresh of an entry
|
|
|
|
|
|
+ * It then adds the highlights to the names and sets the tooltip text.
|
|
|
|
+ * Is called on every refresh of an entry (selecting, saving, discarding, deleting, adding, etc.)
|
|
*/
|
|
*/
|
|
- tooltipify() {
|
|
|
|
|
|
+ public tooltipify(): void {
|
|
let result: any = this.tooltipService.tooltipifyEntry(
|
|
let result: any = this.tooltipService.tooltipifyEntry(
|
|
- JSON.parse(JSON.stringify(this.currentEntry.content)),
|
|
|
|
|
|
+ this.getEntryAt(this.currentEntryIndex).content,
|
|
);
|
|
);
|
|
- console.log(result.npcDescriptions);
|
|
|
|
|
|
+
|
|
this.tooltipifiedEntry.content = result.content;
|
|
this.tooltipifiedEntry.content = result.content;
|
|
this.npcDescriptions = result.npcDescriptions;
|
|
this.npcDescriptions = result.npcDescriptions;
|
|
-
|
|
|
|
- console.log(this.npcDescriptions);
|
|
|
|
-
|
|
|
|
- // console.log(result.content);
|
|
|
|
- // console.log(this.tooltipifiedEntry);
|
|
|
|
-
|
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
result.npcs.forEach((name: string) => {
|
|
result.npcs.forEach((name: string) => {
|
|
this.addHighlightsToText(name);
|
|
this.addHighlightsToText(name);
|
|
});
|
|
});
|
|
- }, 10);
|
|
|
|
-
|
|
|
|
- // result.forEach((entry: any) => {
|
|
|
|
- // entry.content = this.sanitizer.bypassSecurityTrustHtml(entry.content);
|
|
|
|
- // });
|
|
|
|
- // this.tooltipifiedEntries = result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Searches the current entry for names that are mentioned in the text.
|
|
|
|
- * @returns An array of all the names that are mentioned in the current entry.
|
|
|
|
- */
|
|
|
|
- private collectNamesFromEntry(): string[] {
|
|
|
|
- const matches = this.currentEntry.content.match(/(?<=@)\w+/g);
|
|
|
|
- const uniqueMatches = [...new Set(matches)];
|
|
|
|
- return uniqueMatches;
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * Adds a highlight component to the names that are mentioned in the current entry.
|
|
* Highlights and adds tooltips to the names that are mentioned in the current entry.
|
|
* Highlights and adds tooltips to the names that are mentioned in the current entry.
|
|
* @param name The name of the person which is currently highlighted.
|
|
* @param name The name of the person which is currently highlighted.
|
|
*/
|
|
*/
|
|
- addHighlightsToText(name: string) {
|
|
|
|
- console.log('Highlighting: ' + name);
|
|
|
|
-
|
|
|
|
- // Target the correct containers
|
|
|
|
|
|
+ private addHighlightsToText(name: string) {
|
|
|
|
+ // get all elements where a highlight component should be added to
|
|
const parent = this.el.nativeElement.querySelectorAll('.' + name);
|
|
const parent = this.el.nativeElement.querySelectorAll('.' + name);
|
|
- console.log(parent);
|
|
|
|
-
|
|
|
|
parent.forEach((element: any) => {
|
|
parent.forEach((element: any) => {
|
|
- const componentRef = this.test.createComponent(HighlightComponent);
|
|
|
|
- // The name
|
|
|
|
|
|
+ const componentRef =
|
|
|
|
+ this.creationAnchor.createComponent(HighlightComponent);
|
|
componentRef.instance.text = name;
|
|
componentRef.instance.text = name;
|
|
- // A reference to the tooltip template
|
|
|
|
componentRef.instance.tooltip = this.tooltip;
|
|
componentRef.instance.tooltip = this.tooltip;
|
|
- // Appends it at the right spot
|
|
|
|
this.renderer.appendChild(element, componentRef.location.nativeElement);
|
|
this.renderer.appendChild(element, componentRef.location.nativeElement);
|
|
- // add a mouseover event listener to the highlight component
|
|
|
|
|
|
+ // add a mouseover event listener to the highlight component, when it is hovered over, the tooltip-text is set
|
|
this.renderer.listen(
|
|
this.renderer.listen(
|
|
componentRef.location.nativeElement,
|
|
componentRef.location.nativeElement,
|
|
'mouseover',
|
|
'mouseover',
|
|
() => {
|
|
() => {
|
|
- console.log('Mouseover on: ' + name);
|
|
|
|
- console.log(this.npcDescriptions);
|
|
|
|
-
|
|
|
|
this.tooltipText = this.npcDescriptions[name];
|
|
this.tooltipText = this.npcDescriptions[name];
|
|
},
|
|
},
|
|
);
|
|
);
|
|
});
|
|
});
|
|
- // Modufies the text inside the tooltip template
|
|
|
|
- // Muss auf mouseover erfolgen
|
|
|
|
- // this.tooltipText = 'Neuer Tooltip <b>text</b>';
|
|
|
|
}
|
|
}
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
ngOnDestroy(): void {
|