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