|
@@ -17,6 +17,7 @@ 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 { NotesService } from 'src/services/notes/notes.service';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-journal-notes',
|
|
selector: 'app-journal-notes',
|
|
@@ -53,7 +54,7 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
public tooltipText: string = '';
|
|
public tooltipText: string = '';
|
|
|
|
|
|
- public npcDescriptions: any = {};
|
|
|
|
|
|
+ public descriptions: any = {};
|
|
|
|
|
|
tooltipifiedEntry: JournalEntry = {
|
|
tooltipifiedEntry: JournalEntry = {
|
|
title: 'Title',
|
|
title: 'Title',
|
|
@@ -61,9 +62,10 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
created: new Date(),
|
|
created: new Date(),
|
|
};
|
|
};
|
|
|
|
|
|
- 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 notesService: NotesService = inject(NotesService);
|
|
|
|
+ private _adapter: DateAdapter<any> = inject(DateAdapter);
|
|
private renderer: Renderer2 = inject(Renderer2);
|
|
private renderer: Renderer2 = inject(Renderer2);
|
|
private el: ElementRef = inject(ElementRef);
|
|
private el: ElementRef = inject(ElementRef);
|
|
|
|
|
|
@@ -72,8 +74,13 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
this._adapter.setLocale('de');
|
|
this._adapter.setLocale('de');
|
|
this.entries = this.dataService.notesData;
|
|
this.entries = this.dataService.notesData;
|
|
|
|
|
|
- // if the list is empty, set the currentIndex to -1 to hide the entry-container
|
|
|
|
- if (this.entries.length === 0) {
|
|
|
|
|
|
+ if (this.notesService.isUnsaved) {
|
|
|
|
+ const { entry, index, isNewEntry } = this.notesService.getEntry();
|
|
|
|
+ this.currentEntry = entry;
|
|
|
|
+ this.currentIndex = index;
|
|
|
|
+ this.isNewEntry = isNewEntry;
|
|
|
|
+ this.isInEditMode = true;
|
|
|
|
+ } else if (this.entries.length === 0) {
|
|
this.currentIndex = -1;
|
|
this.currentIndex = -1;
|
|
} else {
|
|
} else {
|
|
this.selectEntry(0);
|
|
this.selectEntry(0);
|
|
@@ -89,7 +96,6 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
* @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 {
|
|
- // hier
|
|
|
|
if (this.isInEditMode || index !== this.currentIndex) {
|
|
if (this.isInEditMode || index !== this.currentIndex) {
|
|
this.currentIndex = index;
|
|
this.currentIndex = index;
|
|
this.currentEntry = this.getEntryAt(index);
|
|
this.currentEntry = this.getEntryAt(index);
|
|
@@ -138,6 +144,7 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
this.entries[this.currentIndex] = this.currentEntry;
|
|
this.entries[this.currentIndex] = this.currentEntry;
|
|
this.tooltipify();
|
|
this.tooltipify();
|
|
this.uploadNotes();
|
|
this.uploadNotes();
|
|
|
|
+ this.notesService.markAsSaved();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -156,6 +163,7 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
}
|
|
}
|
|
this.isInEditMode = false;
|
|
this.isInEditMode = false;
|
|
this.tooltipify();
|
|
this.tooltipify();
|
|
|
|
+ this.notesService.markAsSaved();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -202,27 +210,32 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
this.getEntryAt(this.currentIndex).content,
|
|
this.getEntryAt(this.currentIndex).content,
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ console.log(result.content);
|
|
|
|
+
|
|
this.tooltipifiedEntry.content = result.content;
|
|
this.tooltipifiedEntry.content = result.content;
|
|
- this.npcDescriptions = result.npcDescriptions;
|
|
|
|
|
|
+ console.log(result.descriptions);
|
|
|
|
+
|
|
|
|
+ this.descriptions = result.descriptions;
|
|
|
|
+ console.log(result.identifiers);
|
|
|
|
+
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- result.npcs.forEach((name: string) => {
|
|
|
|
|
|
+ result.identifiers.forEach((name: string) => {
|
|
this.addHighlightsToText(name);
|
|
this.addHighlightsToText(name);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 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.
|
|
|
|
- * @param name The name of the person which is currently highlighted.
|
|
|
|
|
|
+ * Adds a highlight component to the persons and locations that are mentioned in the current entry.
|
|
|
|
+ * @param identifier The name of the person or location which is currently highlighted.
|
|
*/
|
|
*/
|
|
- private addHighlightsToText(name: string) {
|
|
|
|
|
|
+ private addHighlightsToText(identifier: string) {
|
|
// get all elements where a highlight component should be added to
|
|
// get all elements where a highlight component should be added to
|
|
- const parent = this.el.nativeElement.querySelectorAll('.' + name);
|
|
|
|
|
|
+ const parent = this.el.nativeElement.querySelectorAll('.' + identifier);
|
|
parent.forEach((element: any) => {
|
|
parent.forEach((element: any) => {
|
|
const componentRef =
|
|
const componentRef =
|
|
this.creationAnchor.createComponent(HighlightComponent);
|
|
this.creationAnchor.createComponent(HighlightComponent);
|
|
- componentRef.instance.text = name;
|
|
|
|
|
|
+ componentRef.instance.text = identifier;
|
|
componentRef.instance.tooltip = this.tooltip;
|
|
componentRef.instance.tooltip = this.tooltip;
|
|
this.renderer.appendChild(element, componentRef.location.nativeElement);
|
|
this.renderer.appendChild(element, componentRef.location.nativeElement);
|
|
// add a mouseover event listener to the highlight component, when it is hovered over, the tooltip-text is set
|
|
// add a mouseover event listener to the highlight component, when it is hovered over, the tooltip-text is set
|
|
@@ -230,13 +243,22 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
componentRef.location.nativeElement,
|
|
componentRef.location.nativeElement,
|
|
'mouseover',
|
|
'mouseover',
|
|
() => {
|
|
() => {
|
|
- this.tooltipText = this.npcDescriptions[name];
|
|
|
|
|
|
+ this.tooltipText = this.descriptions[identifier];
|
|
},
|
|
},
|
|
);
|
|
);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- ngOnDestroy(): void {
|
|
|
|
- this.editor.destroy();
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Saves unsaved changes to restore them when visiting the page the next time.
|
|
|
|
+ */
|
|
|
|
+ ngOnDestroy() {
|
|
|
|
+ if (this.isInEditMode) {
|
|
|
|
+ this.notesService.setEntry(
|
|
|
|
+ this.currentEntry,
|
|
|
|
+ this.currentIndex,
|
|
|
|
+ this.isNewEntry,
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|