| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { Injectable } from '@angular/core';
- import { JournalEntry } from 'src/interfaces/interfaces';
- @Injectable({
- providedIn: 'root',
- })
- export class NotesService {
- public isUnsaved: boolean = false;
- private isNewEntry: boolean = false;
- private unsavedEntry: JournalEntry | null = null;
- private unsavedIndex: number = -1;
- /**
- * Stores the unsaved entry and the index where it can be found.
- * @param entry The entry that was edited but not yet saved.
- * @param index The index of the entry in the entries list.
- */
- public setEntry(
- entry: JournalEntry,
- index: number,
- isNewEntry: boolean,
- ): void {
- this.unsavedEntry = entry;
- this.unsavedIndex = index;
- this.isNewEntry = isNewEntry;
- this.isUnsaved = true;
- }
- /**
- * Returns the entry that was edited but not yet saved when leaving the notes view.
- * @returns The unsaved entry and its index.
- */
- public getEntry(): { [key: string]: any } {
- return {
- entry: this.unsavedEntry,
- index: this.unsavedIndex,
- isNewEntry: this.isNewEntry,
- };
- }
- /**
- * Marks the entry as saved and resets the unsaved entry and index.
- */
- public markAsSaved(): void {
- this.isUnsaved = false;
- this.unsavedEntry = null;
- this.isNewEntry = false;
- this.unsavedIndex = -1;
- }
- }
|