|
@@ -47,7 +47,7 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
};
|
|
|
|
|
|
public isInEditMode = false;
|
|
|
- public currentEntryIndex: number = 0;
|
|
|
+ public currentIndex: number = -1;
|
|
|
private backupIndex: number = -1;
|
|
|
public isNewEntry = false;
|
|
|
|
|
@@ -72,14 +72,12 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
this._adapter.setLocale('de');
|
|
|
this.entries = this.dataService.notesData;
|
|
|
|
|
|
- // if the list is empty, set the currentEntryIndex to -1 to hide the entry-container
|
|
|
+ // if the list is empty, set the currentIndex to -1 to hide the entry-container
|
|
|
if (this.entries.length === 0) {
|
|
|
- this.currentEntryIndex = -1;
|
|
|
+ this.currentIndex = -1;
|
|
|
} else {
|
|
|
- this.currentEntry = this.entries[0];
|
|
|
- this.tooltipifiedEntry = JSON.parse(JSON.stringify(this.currentEntry));
|
|
|
+ this.selectEntry(0);
|
|
|
}
|
|
|
- this.tooltipify();
|
|
|
}
|
|
|
|
|
|
// ACTIONS FROM THE TEMPLATE
|
|
@@ -91,8 +89,9 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
* @param index The index of the selected entry.
|
|
|
*/
|
|
|
public selectEntry(index: number): void {
|
|
|
- if (this.isInEditMode || index !== this.currentEntryIndex) {
|
|
|
- this.currentEntryIndex = index;
|
|
|
+ // hier
|
|
|
+ if (this.isInEditMode || index !== this.currentIndex) {
|
|
|
+ this.currentIndex = index;
|
|
|
this.currentEntry = this.getEntryAt(index);
|
|
|
this.isNewEntry = false;
|
|
|
this.isInEditMode = false;
|
|
@@ -111,9 +110,9 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
};
|
|
|
this.isNewEntry = true;
|
|
|
this.isInEditMode = true;
|
|
|
- this.backupIndex = this.currentEntryIndex;
|
|
|
+ this.backupIndex = this.currentIndex;
|
|
|
// Hightlight no entry because the placeholder is shown as active
|
|
|
- this.currentEntryIndex = -1;
|
|
|
+ this.currentIndex = -1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -133,27 +132,27 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
// Prepend the new JournalEntry
|
|
|
this.entries.unshift(this.currentEntry);
|
|
|
this.isNewEntry = false;
|
|
|
- this.currentEntryIndex = 0;
|
|
|
+ this.currentIndex = 0;
|
|
|
}
|
|
|
this.isInEditMode = false;
|
|
|
- this.entries[this.currentEntryIndex] = this.currentEntry;
|
|
|
+ this.entries[this.currentIndex] = this.currentEntry;
|
|
|
this.tooltipify();
|
|
|
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.
|
|
|
+ * If the entry was a new entry, the currentIndex is reset to the last selected entry.
|
|
|
* The content is also tooltipified again.
|
|
|
*/
|
|
|
public discardEntry(): void {
|
|
|
if (this.isNewEntry) {
|
|
|
- this.currentEntryIndex = this.backupIndex;
|
|
|
+ this.currentIndex = this.backupIndex;
|
|
|
this.isNewEntry = false;
|
|
|
}
|
|
|
if (this.entries.length > 0) {
|
|
|
// Reset the currentEntry to the last saved version
|
|
|
- this.currentEntry = this.getEntryAt(this.currentEntryIndex);
|
|
|
+ this.currentEntry = this.getEntryAt(this.currentIndex);
|
|
|
}
|
|
|
this.isInEditMode = false;
|
|
|
this.tooltipify();
|
|
@@ -161,16 +160,16 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
/**
|
|
|
* Deletes the current entry and removes it from the entries list.
|
|
|
- * If the last entry was deleted, the currentEntryIndex is reset to -1.
|
|
|
+ * If the last entry was deleted, the currentIndex is reset to -1.
|
|
|
* The content is saved in the database.
|
|
|
*/
|
|
|
public deleteEntry(): void {
|
|
|
- this.entries.splice(this.currentEntryIndex, 1);
|
|
|
+ this.entries.splice(this.currentIndex, 1);
|
|
|
if (this.entries.length === 0) {
|
|
|
- this.currentEntryIndex = -1;
|
|
|
+ this.currentIndex = -1;
|
|
|
} else {
|
|
|
- this.currentEntryIndex = Math.max(this.currentEntryIndex - 1, 0);
|
|
|
- this.currentEntry = this.getEntryAt(this.currentEntryIndex);
|
|
|
+ this.currentIndex = Math.max(this.currentIndex - 1, 0);
|
|
|
+ this.currentEntry = this.getEntryAt(this.currentIndex);
|
|
|
// Update the tooltipified entry
|
|
|
this.tooltipify();
|
|
|
}
|
|
@@ -200,7 +199,7 @@ export class JournalNotesComponent implements OnInit, OnDestroy {
|
|
|
*/
|
|
|
public tooltipify(): void {
|
|
|
let result: any = this.tooltipService.tooltipifyEntry(
|
|
|
- this.getEntryAt(this.currentEntryIndex).content,
|
|
|
+ this.getEntryAt(this.currentIndex).content,
|
|
|
);
|
|
|
|
|
|
this.tooltipifiedEntry.content = result.content;
|