Compiles
This commit is contained in:
@@ -2,37 +2,24 @@ import angular from 'angular';
|
||||
import {
|
||||
ApplicationEvents,
|
||||
isPayloadSourceRetrieved,
|
||||
CONTENT_TYPE_NOTE,
|
||||
CONTENT_TYPE_TAG,
|
||||
CONTENT_TYPE_COMPONENT,
|
||||
ContentTypes,
|
||||
ProtectedActions
|
||||
} from 'snjs';
|
||||
import find from 'lodash/find';
|
||||
import { isDesktopApplication } from '@/utils';
|
||||
import { KeyboardManager } from '@/services/keyboardManager';
|
||||
import template from '%/editor.pug';
|
||||
import { PureCtrl } from '@Controllers';
|
||||
import {
|
||||
APP_STATE_EVENT_NOTE_CHANGED,
|
||||
APP_STATE_EVENT_PREFERENCES_CHANGED,
|
||||
EVENT_SOURCE_SCRIPT
|
||||
} from '@/state';
|
||||
import { AppStateEvents, EventSources } from '@/state';
|
||||
import {
|
||||
STRING_DELETED_NOTE,
|
||||
STRING_INVALID_NOTE,
|
||||
STRING_ELLIPSES,
|
||||
STRING_GENERIC_SAVE_ERROR,
|
||||
STRING_DELETE_PLACEHOLDER_ATTEMPT,
|
||||
STRING_DELETE_LOCKED_ATTEMPT,
|
||||
StringDeleteNote,
|
||||
StringEmptyTrash
|
||||
} from '@/strings';
|
||||
import {
|
||||
PREF_EDITOR_WIDTH,
|
||||
PREF_EDITOR_LEFT,
|
||||
PREF_EDITOR_MONOSPACE_ENABLED,
|
||||
PREF_EDITOR_SPELLCHECK,
|
||||
PREF_EDITOR_RESIZERS_ENABLED
|
||||
} from '@/services/preferencesManager';
|
||||
import { PrefKeys } from '@/services/preferencesManager';
|
||||
|
||||
const NOTE_PREVIEW_CHAR_LIMIT = 80;
|
||||
const MINIMUM_STATUS_DURATION = 400;
|
||||
@@ -40,19 +27,23 @@ const SAVE_TIMEOUT_DEBOUNCE = 350;
|
||||
const SAVE_TIMEOUT_NO_DEBOUNCE = 100;
|
||||
const EDITOR_DEBOUNCE = 200;
|
||||
|
||||
const APP_DATA_KEY_PINNED = 'pinned';
|
||||
const APP_DATA_KEY_LOCKED = 'locked';
|
||||
const APP_DATA_KEY_ARCHIVED = 'archived';
|
||||
const APP_DATA_KEY_PREFERS_PLAIN_EDITOR = 'prefersPlainEditor';
|
||||
|
||||
const ELEMENT_ID_NOTE_TEXT_EDITOR = 'note-text-editor';
|
||||
const ELEMENT_ID_NOTE_TITLE_EDITOR = 'note-title-editor';
|
||||
const ELEMENT_ID_EDITOR_CONTENT = 'editor-content';
|
||||
const ELEMENT_ID_NOTE_TAGS_COMPONENT_CONTAINER = 'note-tags-component-container';
|
||||
|
||||
const DESKTOP_MONOSPACE_FAMILY = `Menlo,Consolas,'DejaVu Sans Mono',monospace`;
|
||||
const WEB_MONOSPACE_FAMILY = `monospace`;
|
||||
const SANS_SERIF_FAMILY = `inherit`;
|
||||
const AppDataKeys = {
|
||||
Pinned: 'pinned',
|
||||
Locked: 'locked',
|
||||
Archived: 'archived',
|
||||
PrefersPlainEditor: 'prefersPlainEditor'
|
||||
};
|
||||
const ElementIds = {
|
||||
NoteTextEditor: 'note-text-editor',
|
||||
NoteTitleEditor: 'note-title-editor',
|
||||
EditorContent: 'editor-content',
|
||||
NoteTagsComponentContainer: 'note-tags-component-container'
|
||||
};
|
||||
const Fonts = {
|
||||
DesktopMonospaceFamily: `Menlo,Consolas,'DejaVu Sans Mono',monospace`,
|
||||
WebMonospaceFamily: `monospace`,
|
||||
SansSerifFamily: `inherit`
|
||||
};
|
||||
|
||||
class EditorCtrl extends PureCtrl {
|
||||
/* @ngInject */
|
||||
@@ -61,17 +52,14 @@ class EditorCtrl extends PureCtrl {
|
||||
$rootScope,
|
||||
appState,
|
||||
application,
|
||||
actionsManager,
|
||||
desktopManager,
|
||||
keyboardManager,
|
||||
preferencesManager,
|
||||
sessionHistory /** Unused below, required to load globally */
|
||||
) {
|
||||
super($timeout);
|
||||
this.$rootScope = $rootScope;
|
||||
this.application = application;
|
||||
this.appState = appState;
|
||||
this.actionsManager = actionsManager;
|
||||
this.desktopManager = desktopManager;
|
||||
this.keyboardManager = keyboardManager;
|
||||
this.preferencesManager = preferencesManager;
|
||||
@@ -97,19 +85,19 @@ class EditorCtrl extends PureCtrl {
|
||||
this.registerKeyboardShortcuts();
|
||||
|
||||
/** Used by .pug template */
|
||||
this.prefKeyMonospace = PREF_EDITOR_MONOSPACE_ENABLED;
|
||||
this.prefKeySpellcheck = PREF_EDITOR_SPELLCHECK;
|
||||
this.prefKeyMarginResizers = PREF_EDITOR_RESIZERS_ENABLED;
|
||||
this.prefKeyMonospace = PrefKeys.EditorMonospaceEnabled;
|
||||
this.prefKeySpellcheck = PrefKeys.EditorSpellcheck;
|
||||
this.prefKeyMarginResizers = PrefKeys.EditorResizersEnabled;
|
||||
}
|
||||
|
||||
addAppStateObserver() {
|
||||
this.appState.addObserver((eventName, data) => {
|
||||
if (eventName === APP_STATE_EVENT_NOTE_CHANGED) {
|
||||
if (eventName === AppStateEvents.NoteChanged) {
|
||||
this.handleNoteSelectionChange(
|
||||
this.appState.getSelectedNote(),
|
||||
data.previousNote
|
||||
);
|
||||
} else if (eventName === APP_STATE_EVENT_PREFERENCES_CHANGED) {
|
||||
} else if (eventName === AppStateEvents.PreferencesChanged) {
|
||||
this.loadPreferences();
|
||||
}
|
||||
});
|
||||
@@ -117,7 +105,7 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
streamItems() {
|
||||
this.application.streamItems({
|
||||
contentType: CONTENT_TYPE_NOTE,
|
||||
contentType: ContentTypes.Note,
|
||||
stream: async ({ items, source }) => {
|
||||
if (!this.state.note) {
|
||||
return;
|
||||
@@ -139,7 +127,7 @@ class EditorCtrl extends PureCtrl {
|
||||
});
|
||||
|
||||
this.application.streamItems({
|
||||
contentType: CONTENT_TYPE_TAG,
|
||||
contentType: ContentTypes.Tag,
|
||||
stream: async ({ items, source }) => {
|
||||
if (!this.state.note) {
|
||||
return;
|
||||
@@ -158,7 +146,7 @@ class EditorCtrl extends PureCtrl {
|
||||
});
|
||||
|
||||
this.application.streamItems({
|
||||
contentType: CONTENT_TYPE_COMPONENT,
|
||||
contentType: ContentTypes.Component,
|
||||
stream: async ({ items, source }) => {
|
||||
if (!this.state.note) {
|
||||
return;
|
||||
@@ -267,7 +255,7 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
addSyncStatusObserver() {
|
||||
/** @todo */
|
||||
// this.syncStatusObserver = this.syncManager.
|
||||
// this.syncStatusObserver = syncManager.
|
||||
// registerSyncStatusObserver((status) => {
|
||||
// if (status.localError) {
|
||||
// this.$timeout(() => {
|
||||
@@ -321,11 +309,11 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
if (editor) {
|
||||
const prefersPlain = this.state.note.getAppDataItem(
|
||||
APP_DATA_KEY_PREFERS_PLAIN_EDITOR
|
||||
AppDataKeys.PrefersPlainEditor
|
||||
) === true;
|
||||
if (prefersPlain) {
|
||||
this.state.note.setAppDataItem(
|
||||
APP_DATA_KEY_PREFERS_PLAIN_EDITOR,
|
||||
AppDataKeys.PrefersPlainEditor,
|
||||
false
|
||||
);
|
||||
this.application.setItemNeedsSync({ item: this.state.note });
|
||||
@@ -333,9 +321,9 @@ class EditorCtrl extends PureCtrl {
|
||||
this.associateComponentWithCurrentNote(editor);
|
||||
} else {
|
||||
/** Note prefers plain editor */
|
||||
if (!this.state.note.getAppDataItem(APP_DATA_KEY_PREFERS_PLAIN_EDITOR)) {
|
||||
if (!this.state.note.getAppDataItem(AppDataKeys.PrefersPlainEditor)) {
|
||||
this.state.note.setAppDataItem(
|
||||
APP_DATA_KEY_PREFERS_PLAIN_EDITOR,
|
||||
AppDataKeys.PrefersPlainEditor,
|
||||
true
|
||||
);
|
||||
this.application.setItemNeedsSync({ item: this.state.note });
|
||||
@@ -356,7 +344,7 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
hasAvailableExtensions() {
|
||||
return this.actionsManager.extensionsInContextOfItem(this.state.note).length > 0;
|
||||
return this.application.actionsManager.extensionsInContextOfItem(this.state.note).length > 0;
|
||||
}
|
||||
|
||||
performFirefoxPinnedTabFix() {
|
||||
@@ -494,15 +482,15 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
focusEditor() {
|
||||
const element = document.getElementById(ELEMENT_ID_NOTE_TEXT_EDITOR);
|
||||
const element = document.getElementById(ElementIds.NoteTextEditor);
|
||||
if (element) {
|
||||
this.lastEditorFocusEventSource = EVENT_SOURCE_SCRIPT;
|
||||
this.lastEditorFocusEventSource = EventSources.Script;
|
||||
element.focus();
|
||||
}
|
||||
}
|
||||
|
||||
focusTitle() {
|
||||
document.getElementById(ELEMENT_ID_NOTE_TITLE_EDITOR).focus();
|
||||
document.getElementById(ElementIds.NoteTitleEditor).focus();
|
||||
}
|
||||
|
||||
clickedTextArea() {
|
||||
@@ -627,7 +615,7 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
togglePin() {
|
||||
this.state.note.setAppDataItem(
|
||||
APP_DATA_KEY_PINNED,
|
||||
AppDataKeys.Pinned,
|
||||
!this.state.note.pinned
|
||||
);
|
||||
this.saveNote({
|
||||
@@ -638,7 +626,7 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
toggleLockNote() {
|
||||
this.state.note.setAppDataItem(
|
||||
APP_DATA_KEY_LOCKED,
|
||||
AppDataKeys.Locked,
|
||||
!this.state.note.locked
|
||||
);
|
||||
this.saveNote({
|
||||
@@ -674,7 +662,7 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
toggleArchiveNote() {
|
||||
this.state.note.setAppDataItem(
|
||||
APP_DATA_KEY_ARCHIVED,
|
||||
AppDataKeys.Archived,
|
||||
!this.state.note.archived
|
||||
);
|
||||
this.saveNote({
|
||||
@@ -734,7 +722,7 @@ class EditorCtrl extends PureCtrl {
|
||||
this.application.setItemsNeedsSync({ items: toRemove });
|
||||
const tags = [];
|
||||
for (const tagString of strings) {
|
||||
const existingRelationship = _.find(
|
||||
const existingRelationship = find(
|
||||
this.state.note.tags,
|
||||
{ title: tagString }
|
||||
);
|
||||
@@ -754,13 +742,13 @@ class EditorCtrl extends PureCtrl {
|
||||
onPanelResizeFinish = (width, left, isMaxWidth) => {
|
||||
if (isMaxWidth) {
|
||||
this.preferencesManager.setUserPrefValue(
|
||||
PREF_EDITOR_WIDTH,
|
||||
PrefKeys.EditorWidth,
|
||||
null
|
||||
);
|
||||
} else {
|
||||
if (width !== undefined && width !== null) {
|
||||
this.preferencesManager.setUserPrefValue(
|
||||
PREF_EDITOR_WIDTH,
|
||||
PrefKeys.EditorWidth,
|
||||
width
|
||||
);
|
||||
this.leftResizeControl.setWidth(width);
|
||||
@@ -768,7 +756,7 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
if (left !== undefined && left !== null) {
|
||||
this.preferencesManager.setUserPrefValue(
|
||||
PREF_EDITOR_LEFT,
|
||||
PrefKeys.EditorLeft,
|
||||
left
|
||||
);
|
||||
this.rightResizeControl.setLeft(left);
|
||||
@@ -778,15 +766,15 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
loadPreferences() {
|
||||
const monospaceEnabled = this.preferencesManager.getValue(
|
||||
PREF_EDITOR_MONOSPACE_ENABLED,
|
||||
PrefKeys.EditorMonospaceEnabled,
|
||||
true
|
||||
);
|
||||
const spellcheck = this.preferencesManager.getValue(
|
||||
PREF_EDITOR_SPELLCHECK,
|
||||
PrefKeys.EditorSpellcheck,
|
||||
true
|
||||
);
|
||||
const marginResizersEnabled = this.preferencesManager.getValue(
|
||||
PREF_EDITOR_RESIZERS_ENABLED,
|
||||
PrefKeys.EditorResizersEnabled,
|
||||
true
|
||||
);
|
||||
this.setState({
|
||||
@@ -795,7 +783,7 @@ class EditorCtrl extends PureCtrl {
|
||||
marginResizersEnabled
|
||||
});
|
||||
|
||||
if (!document.getElementById(ELEMENT_ID_EDITOR_CONTENT)) {
|
||||
if (!document.getElementById(ElementIds.EditorContent)) {
|
||||
/** Elements have not yet loaded due to ng-if around wrapper */
|
||||
return;
|
||||
}
|
||||
@@ -804,7 +792,7 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
if (this.state.marginResizersEnabled) {
|
||||
const width = this.preferencesManager.getValue(
|
||||
PREF_EDITOR_WIDTH,
|
||||
PrefKeys.EditorWidth,
|
||||
null
|
||||
);
|
||||
if (width != null) {
|
||||
@@ -812,7 +800,7 @@ class EditorCtrl extends PureCtrl {
|
||||
this.rightResizeControl.setWidth(width);
|
||||
}
|
||||
const left = this.preferencesManager.getValue(
|
||||
PREF_EDITOR_LEFT,
|
||||
PrefKeys.EditorLeft,
|
||||
null
|
||||
);
|
||||
if (left != null) {
|
||||
@@ -824,19 +812,19 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
reloadFont() {
|
||||
const editor = document.getElementById(
|
||||
ELEMENT_ID_NOTE_TEXT_EDITOR
|
||||
ElementIds.NoteTextEditor
|
||||
);
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
if (this.state.monospaceEnabled) {
|
||||
if (this.state.isDesktop) {
|
||||
editor.style.fontFamily = DESKTOP_MONOSPACE_FAMILY;
|
||||
editor.style.fontFamily = Fonts.DesktopMonospaceFamily;
|
||||
} else {
|
||||
editor.style.fontFamily = WEB_MONOSPACE_FAMILY;
|
||||
editor.style.fontFamily = Fonts.WebMonospaceFamily;
|
||||
}
|
||||
} else {
|
||||
editor.style.fontFamily = SANS_SERIF_FAMILY;
|
||||
editor.style.fontFamily = Fonts.SansSerifFamily;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -849,7 +837,7 @@ class EditorCtrl extends PureCtrl {
|
||||
);
|
||||
this.reloadFont();
|
||||
|
||||
if (key === PREF_EDITOR_SPELLCHECK) {
|
||||
if (key === PrefKeys.EditorSpellcheck) {
|
||||
/** Allows textarea to reload */
|
||||
await this.setState({
|
||||
noteReady: false
|
||||
@@ -858,7 +846,7 @@ class EditorCtrl extends PureCtrl {
|
||||
noteReady: true
|
||||
});
|
||||
this.reloadFont();
|
||||
} else if (key === PREF_EDITOR_RESIZERS_ENABLED && this[key] === true) {
|
||||
} else if (key === PrefKeys.EditorResizersEnabled && this[key] === true) {
|
||||
this.$timeout(() => {
|
||||
this.leftResizeControl.flash();
|
||||
this.rightResizeControl.flash();
|
||||
@@ -956,7 +944,7 @@ class EditorCtrl extends PureCtrl {
|
||||
if (data.type === 'container') {
|
||||
if (component.area === 'note-tags') {
|
||||
const container = document.getElementById(
|
||||
ELEMENT_ID_NOTE_TAGS_COMPONENT_CONTAINER
|
||||
ElementIds.NoteTagsComponentContainer
|
||||
);
|
||||
setSize(container, data);
|
||||
}
|
||||
@@ -1055,7 +1043,7 @@ class EditorCtrl extends PureCtrl {
|
||||
registerKeyboardShortcuts() {
|
||||
this.altKeyObserver = this.keyboardManager.addKeyObserver({
|
||||
modifiers: [
|
||||
KeyboardManager.KeyModifierAlt
|
||||
KeyboardModifiers.Alt
|
||||
],
|
||||
onKeyDown: () => {
|
||||
this.setState({
|
||||
@@ -1070,23 +1058,23 @@ class EditorCtrl extends PureCtrl {
|
||||
});
|
||||
|
||||
this.trashKeyObserver = this.keyboardManager.addKeyObserver({
|
||||
key: KeyboardManager.KeyBackspace,
|
||||
key: KeyboardKeys.Backspace,
|
||||
notElementIds: [
|
||||
ELEMENT_ID_NOTE_TEXT_EDITOR,
|
||||
ELEMENT_ID_NOTE_TITLE_EDITOR
|
||||
ElementIds.NoteTextEditor,
|
||||
ElementIds.NoteTitleEditor
|
||||
],
|
||||
modifiers: [KeyboardManager.KeyModifierMeta],
|
||||
modifiers: [KeyboardModifiers.Meta],
|
||||
onKeyDown: () => {
|
||||
this.deleteNote();
|
||||
},
|
||||
});
|
||||
|
||||
this.deleteKeyObserver = this.keyboardManager.addKeyObserver({
|
||||
key: KeyboardManager.KeyBackspace,
|
||||
key: KeyboardKeys.Backspace,
|
||||
modifiers: [
|
||||
KeyboardManager.KeyModifierMeta,
|
||||
KeyboardManager.KeyModifierShift,
|
||||
KeyboardManager.KeyModifierAlt
|
||||
KeyboardModifiers.Meta,
|
||||
KeyboardModifiers.Shift,
|
||||
KeyboardModifiers.Alt
|
||||
],
|
||||
onKeyDown: (event) => {
|
||||
event.preventDefault();
|
||||
@@ -1107,11 +1095,11 @@ class EditorCtrl extends PureCtrl {
|
||||
* not fired.
|
||||
*/
|
||||
const editor = document.getElementById(
|
||||
ELEMENT_ID_NOTE_TEXT_EDITOR
|
||||
ElementIds.NoteTextEditor
|
||||
);
|
||||
this.tabObserver = this.keyboardManager.addKeyObserver({
|
||||
element: editor,
|
||||
key: KeyboardManager.KeyTab,
|
||||
key: KeyboardKeys.Tab,
|
||||
onKeyDown: (event) => {
|
||||
if (this.state.note.locked || event.shiftKey) {
|
||||
return;
|
||||
|
||||
@@ -2,15 +2,11 @@ import { dateToLocalizedString } from '@/utils';
|
||||
import {
|
||||
ApplicationEvents,
|
||||
TIMING_STRATEGY_FORCE_SPAWN_NEW,
|
||||
ProtectedActions
|
||||
ProtectedActions,
|
||||
ContentTypes
|
||||
} from 'snjs';
|
||||
import template from '%/footer.pug';
|
||||
import {
|
||||
APP_STATE_EVENT_EDITOR_FOCUSED,
|
||||
APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD,
|
||||
APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD,
|
||||
EVENT_SOURCE_USER_INTERACTION
|
||||
} from '@/state';
|
||||
import { AppStateEvents, EventSources } from '@/state';
|
||||
import {
|
||||
STRING_GENERIC_SYNC_ERROR,
|
||||
STRING_NEW_UPDATE_READY
|
||||
@@ -74,16 +70,16 @@ class FooterCtrl {
|
||||
|
||||
addAppStateObserver() {
|
||||
this.appState.addObserver((eventName, data) => {
|
||||
if(eventName === APP_STATE_EVENT_EDITOR_FOCUSED) {
|
||||
if (data.eventSource === EVENT_SOURCE_USER_INTERACTION) {
|
||||
if(eventName === AppStateEvents.EditorFocused) {
|
||||
if (data.eventSource === EventSources.UserInteraction) {
|
||||
this.closeAllRooms();
|
||||
this.closeAccountMenu();
|
||||
}
|
||||
} else if(eventName === APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD) {
|
||||
} else if(eventName === AppStateEvents.BeganBackupDownload) {
|
||||
this.backupStatus = this.statusManager.addStatusFromString(
|
||||
"Saving local backup..."
|
||||
);
|
||||
} else if(eventName === APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD) {
|
||||
} else if(eventName === AppStateEvents.EndedBackupDownload) {
|
||||
if(data.success) {
|
||||
this.backupStatus = this.statusManager.replaceStatusWithString(
|
||||
this.backupStatus,
|
||||
@@ -125,10 +121,10 @@ class FooterCtrl {
|
||||
|
||||
streamItems() {
|
||||
this.application.streamItems({
|
||||
contentType: CONTENT_TYPE_COMPONENT,
|
||||
contentType: ContentTypes.Component,
|
||||
stream: async () => {
|
||||
this.rooms = this.application.getItems({
|
||||
contentType: CONTENT_TYPE_COMPONENT
|
||||
contentType: ContentTypes.Component
|
||||
}).filter((candidate) => {
|
||||
return candidate.area === 'rooms' && !candidate.deleted;
|
||||
});
|
||||
@@ -143,7 +139,7 @@ class FooterCtrl {
|
||||
contentType: 'SN|Theme',
|
||||
stream: async () => {
|
||||
const themes = this.application.getDisplayableItems({
|
||||
contentType: CONTENT_TYPE_THEME
|
||||
contentType: ContentTypes.Theme
|
||||
}).filter((candidate) => {
|
||||
return (
|
||||
!candidate.deleted &&
|
||||
@@ -159,7 +155,7 @@ class FooterCtrl {
|
||||
this.reloadDockShortcuts();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
registerComponentHandler() {
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
import template from '%/lock-screen.pug';
|
||||
import {
|
||||
APP_STATE_EVENT_WINDOW_DID_FOCUS
|
||||
} from '@/state';
|
||||
import { AppStateEvents } from '@/state';
|
||||
|
||||
const ELEMENT_ID_PASSCODE_INPUT = 'passcode-input';
|
||||
|
||||
class LockScreenCtrl {
|
||||
|
||||
/* @ngInject */
|
||||
constructor(
|
||||
$scope,
|
||||
alertManager,
|
||||
application,
|
||||
appState
|
||||
) {
|
||||
this.$scope = $scope;
|
||||
this.alertManager = alertManager;
|
||||
this.application = application;
|
||||
this.appState = appState;
|
||||
this.formData = {};
|
||||
@@ -37,7 +32,7 @@ class LockScreenCtrl {
|
||||
|
||||
addVisibilityObserver() {
|
||||
this.unregisterObserver = this.appState.addObserver((eventName, data) => {
|
||||
if (eventName === APP_STATE_EVENT_WINDOW_DID_FOCUS) {
|
||||
if (eventName === AppStateEvents.WindowDidFocus) {
|
||||
const input = this.passcodeInput;
|
||||
if(input) {
|
||||
input.focus();
|
||||
@@ -56,7 +51,7 @@ class LockScreenCtrl {
|
||||
this.passcodeInput.blur();
|
||||
const success = await this.onValue()(this.formData.passcode);
|
||||
if(!success) {
|
||||
this.alertManager.alert({
|
||||
this.application.alertManager.alert({
|
||||
text: "Invalid passcode. Please try again.",
|
||||
onClose: () => {
|
||||
this.passcodeInput.focus();
|
||||
@@ -70,7 +65,7 @@ class LockScreenCtrl {
|
||||
}
|
||||
|
||||
beginDeleteData() {
|
||||
this.alertManager.confirm({
|
||||
this.application.alertManager.confirm({
|
||||
text: "Are you sure you want to clear all local data?",
|
||||
destructive: true,
|
||||
onConfirm: async () => {
|
||||
|
||||
@@ -1,24 +1,11 @@
|
||||
import _ from 'lodash';
|
||||
import angular from 'angular';
|
||||
import template from '%/notes.pug';
|
||||
import { ApplicationEvents, CONTENT_TYPE_NOTE, CONTENT_TYPE_TAG } from 'snjs';
|
||||
import { KeyboardManager } from '@/services/keyboardManager';
|
||||
import { ApplicationEvents, ContentTypes } from 'snjs';
|
||||
import { PureCtrl } from '@Controllers';
|
||||
import { AppStateEvents } from '@/state';
|
||||
import {
|
||||
APP_STATE_EVENT_NOTE_CHANGED,
|
||||
APP_STATE_EVENT_TAG_CHANGED,
|
||||
APP_STATE_EVENT_PREFERENCES_CHANGED,
|
||||
APP_STATE_EVENT_EDITOR_FOCUSED
|
||||
} from '@/state';
|
||||
import {
|
||||
PREF_NOTES_PANEL_WIDTH,
|
||||
PREF_SORT_NOTES_BY,
|
||||
PREF_SORT_NOTES_REVERSE,
|
||||
PREF_NOTES_SHOW_ARCHIVED,
|
||||
PREF_NOTES_HIDE_PINNED,
|
||||
PREF_NOTES_HIDE_NOTE_PREVIEW,
|
||||
PREF_NOTES_HIDE_DATE,
|
||||
PREF_NOTES_HIDE_TAGS
|
||||
PrefKeys
|
||||
} from '@/services/preferencesManager';
|
||||
import {
|
||||
PANEL_NAME_NOTES
|
||||
@@ -37,8 +24,6 @@ import {
|
||||
*/
|
||||
const MIN_NOTE_CELL_HEIGHT = 51.0;
|
||||
const DEFAULT_LIST_NUM_NOTES = 20;
|
||||
|
||||
|
||||
const ELEMENT_ID_SEARCH_BAR = 'search-bar';
|
||||
const ELEMENT_ID_SCROLL_CONTAINER = 'notes-scrollable';
|
||||
|
||||
@@ -96,14 +81,14 @@ class NotesCtrl extends PureCtrl {
|
||||
|
||||
addAppStateObserver() {
|
||||
this.appState.addObserver((eventName, data) => {
|
||||
if (eventName === APP_STATE_EVENT_TAG_CHANGED) {
|
||||
if (eventName === AppStateEvents.TagChanged) {
|
||||
this.handleTagChange(this.appState.getSelectedTag(), data.previousTag);
|
||||
} else if (eventName === APP_STATE_EVENT_NOTE_CHANGED) {
|
||||
} else if (eventName === AppStateEvents.NoteChanged) {
|
||||
this.handleNoteSelection(this.appState.getSelectedNote());
|
||||
} else if (eventName === APP_STATE_EVENT_PREFERENCES_CHANGED) {
|
||||
} else if (eventName === AppStateEvents.PreferencesChanged) {
|
||||
this.reloadPreferences();
|
||||
this.reloadNotes();
|
||||
} else if (eventName === APP_STATE_EVENT_EDITOR_FOCUSED) {
|
||||
} else if (eventName === AppStateEvents.EditorFocused) {
|
||||
this.setShowMenuFalse();
|
||||
}
|
||||
});
|
||||
@@ -129,7 +114,7 @@ class NotesCtrl extends PureCtrl {
|
||||
if (this.state.notes.length === 0) {
|
||||
this.createNewNote();
|
||||
}
|
||||
} else if(eventName === ApplicationEvents.CompletedSync) {
|
||||
} else if (eventName === ApplicationEvents.CompletedSync) {
|
||||
if (this.createDummyOnSynCompletionIfNoNotes && this.state.notes.length === 0) {
|
||||
this.createDummyOnSynCompletionIfNoNotes = false;
|
||||
this.createNewNote();
|
||||
@@ -140,7 +125,7 @@ class NotesCtrl extends PureCtrl {
|
||||
|
||||
streamNotesAndTags() {
|
||||
this.application.streamItems({
|
||||
contentType: [CONTENT_TYPE_NOTE, CONTENT_TYPE_TAG],
|
||||
contentType: [ContentTypes.Note, ContentTypes.Tag],
|
||||
stream: async ({ items }) => {
|
||||
await this.reloadNotes();
|
||||
const selectedNote = this.state.selectedNote;
|
||||
@@ -155,7 +140,7 @@ class NotesCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
/** Note has changed values, reset its flags */
|
||||
const notes = items.filter((item) => item.content_type === CONTENT_TYPE_NOTE);
|
||||
const notes = items.filter((item) => item.content_type === ContentTypes.Note);
|
||||
for (const note of notes) {
|
||||
this.loadFlagsForNote(note);
|
||||
note.cachedCreatedAtString = note.createdAtString();
|
||||
@@ -167,7 +152,7 @@ class NotesCtrl extends PureCtrl {
|
||||
|
||||
async handleTagChange(tag, previousTag) {
|
||||
if (this.state.selectedNote && this.state.selectedNote.dummy) {
|
||||
this.application.removeItemLocally({item: this.state.selectedNote});
|
||||
this.application.removeItemLocally({ item: this.state.selectedNote });
|
||||
if (previousTag) {
|
||||
_.remove(previousTag.notes, this.state.selectedNote);
|
||||
}
|
||||
@@ -266,7 +251,7 @@ class NotesCtrl extends PureCtrl {
|
||||
}
|
||||
const previousNote = this.state.selectedNote;
|
||||
if (previousNote && previousNote.dummy) {
|
||||
this.application.removeItemLocally({previousNote});
|
||||
this.application.removeItemLocally({ previousNote });
|
||||
this.removeNoteFromList(previousNote);
|
||||
}
|
||||
await this.setState({
|
||||
@@ -279,7 +264,7 @@ class NotesCtrl extends PureCtrl {
|
||||
this.selectedIndex = Math.max(0, this.displayableNotes().indexOf(note));
|
||||
if (note.content.conflict_of) {
|
||||
note.content.conflict_of = null;
|
||||
this.application.saveItem({item: note});
|
||||
this.application.saveItem({ item: note });
|
||||
}
|
||||
if (this.isFiltering()) {
|
||||
this.desktopManager.searchText(this.state.noteFilter.text);
|
||||
@@ -290,7 +275,7 @@ class NotesCtrl extends PureCtrl {
|
||||
const viewOptions = {};
|
||||
const prevSortValue = this.state.sortBy;
|
||||
let sortBy = this.preferencesManager.getValue(
|
||||
PREF_SORT_NOTES_BY,
|
||||
PrefKeys.SortNotesBy,
|
||||
SORT_KEY_CREATED_AT
|
||||
);
|
||||
if (sortBy === SORT_KEY_UPDATED_AT) {
|
||||
@@ -299,27 +284,27 @@ class NotesCtrl extends PureCtrl {
|
||||
}
|
||||
viewOptions.sortBy = sortBy;
|
||||
viewOptions.sortReverse = this.preferencesManager.getValue(
|
||||
PREF_SORT_NOTES_REVERSE,
|
||||
PrefKeys.SortNotesReverse,
|
||||
false
|
||||
);
|
||||
viewOptions.showArchived = this.preferencesManager.getValue(
|
||||
PREF_NOTES_SHOW_ARCHIVED,
|
||||
PrefKeys.NotesShowArchived,
|
||||
false
|
||||
);
|
||||
viewOptions.hidePinned = this.preferencesManager.getValue(
|
||||
PREF_NOTES_HIDE_PINNED,
|
||||
PrefKeys.NotesHidePinned,
|
||||
false
|
||||
);
|
||||
viewOptions.hideNotePreview = this.preferencesManager.getValue(
|
||||
PREF_NOTES_HIDE_NOTE_PREVIEW,
|
||||
PrefKeys.NotesHideNotePreview,
|
||||
false
|
||||
);
|
||||
viewOptions.hideDate = this.preferencesManager.getValue(
|
||||
PREF_NOTES_HIDE_DATE,
|
||||
PrefKeys.NotesHideDate,
|
||||
false
|
||||
);
|
||||
viewOptions.hideTags = this.preferencesManager.getValue(
|
||||
PREF_NOTES_HIDE_TAGS,
|
||||
PrefKeys.NotesHideTags,
|
||||
false
|
||||
);
|
||||
this.setState({
|
||||
@@ -329,7 +314,7 @@ class NotesCtrl extends PureCtrl {
|
||||
this.selectFirstNote();
|
||||
}
|
||||
const width = this.preferencesManager.getValue(
|
||||
PREF_NOTES_PANEL_WIDTH
|
||||
PrefKeys.NotesPanelWidth
|
||||
);
|
||||
if (width) {
|
||||
this.panelController.setWidth(width);
|
||||
@@ -344,7 +329,7 @@ class NotesCtrl extends PureCtrl {
|
||||
|
||||
onPanelResize = (newWidth, lastLeft, isAtMaxWidth, isCollapsed) => {
|
||||
this.preferencesManager.setUserPrefValue(
|
||||
PREF_NOTES_PANEL_WIDTH,
|
||||
PrefKeys.NotesPanelWidth,
|
||||
newWidth
|
||||
);
|
||||
this.preferencesManager.syncUserPreferences();
|
||||
@@ -523,7 +508,7 @@ class NotesCtrl extends PureCtrl {
|
||||
}
|
||||
const title = "Note" + (this.state.notes ? (" " + (this.state.notes.length + 1)) : "");
|
||||
const newNote = this.application.createItem({
|
||||
contentType: CONTENT_TYPE_NOTE,
|
||||
contentType: ContentTypes.Note,
|
||||
content: {
|
||||
text: '',
|
||||
title: title
|
||||
@@ -531,7 +516,7 @@ class NotesCtrl extends PureCtrl {
|
||||
});
|
||||
newNote.client_updated_at = new Date();
|
||||
newNote.dummy = true;
|
||||
this.application.setItemNeedsSync({item: newNote});
|
||||
this.application.setItemNeedsSync({ item: newNote });
|
||||
const selectedTag = this.appState.getSelectedTag();
|
||||
if (!selectedTag.isSmartTag()) {
|
||||
selectedTag.addItemAsRelationship(newNote);
|
||||
@@ -605,7 +590,7 @@ class NotesCtrl extends PureCtrl {
|
||||
toggleReverseSort() {
|
||||
this.selectedMenuItem();
|
||||
this.preferencesManager.setUserPrefValue(
|
||||
PREF_SORT_NOTES_REVERSE,
|
||||
PrefKeys.SortNotesReverse,
|
||||
!this.state.sortReverse
|
||||
);
|
||||
this.preferencesManager.syncUserPreferences();
|
||||
@@ -613,7 +598,7 @@ class NotesCtrl extends PureCtrl {
|
||||
|
||||
setSortBy(type) {
|
||||
this.preferencesManager.setUserPrefValue(
|
||||
PREF_SORT_NOTES_BY,
|
||||
PrefKeys.SortNotesBy,
|
||||
type
|
||||
);
|
||||
this.preferencesManager.syncUserPreferences();
|
||||
@@ -649,8 +634,8 @@ class NotesCtrl extends PureCtrl {
|
||||
this.newNoteKeyObserver = this.keyboardManager.addKeyObserver({
|
||||
key: 'n',
|
||||
modifiers: [
|
||||
KeyboardManager.KeyModifierMeta,
|
||||
KeyboardManager.KeyModifierCtrl
|
||||
KeyboardModifiers.Meta,
|
||||
KeyboardModifiers.Ctrl
|
||||
],
|
||||
onKeyDown: (event) => {
|
||||
event.preventDefault();
|
||||
@@ -659,7 +644,7 @@ class NotesCtrl extends PureCtrl {
|
||||
});
|
||||
|
||||
this.nextNoteKeyObserver = this.keyboardManager.addKeyObserver({
|
||||
key: KeyboardManager.KeyDown,
|
||||
key: KeyboardKeys.Down,
|
||||
elements: [
|
||||
document.body,
|
||||
this.getSearchBar()
|
||||
@@ -674,7 +659,7 @@ class NotesCtrl extends PureCtrl {
|
||||
});
|
||||
|
||||
this.nextNoteKeyObserver = this.keyboardManager.addKeyObserver({
|
||||
key: KeyboardManager.KeyUp,
|
||||
key: KeyboardKeys.Up,
|
||||
element: document.body,
|
||||
onKeyDown: (event) => {
|
||||
this.selectPreviousNote();
|
||||
@@ -684,8 +669,8 @@ class NotesCtrl extends PureCtrl {
|
||||
this.searchKeyObserver = this.keyboardManager.addKeyObserver({
|
||||
key: "f",
|
||||
modifiers: [
|
||||
KeyboardManager.KeyModifierMeta,
|
||||
KeyboardManager.KeyModifierShift
|
||||
KeyboardModifiers.Meta,
|
||||
KeyboardModifiers.Shift
|
||||
],
|
||||
onKeyDown: (event) => {
|
||||
const searchBar = this.getSearchBar();
|
||||
|
||||
@@ -2,10 +2,7 @@ import _ from 'lodash';
|
||||
import { Challenges } from 'snjs';
|
||||
import { getPlatformString } from '@/utils';
|
||||
import template from '%/root.pug';
|
||||
import {
|
||||
APP_STATE_EVENT_PANEL_RESIZED,
|
||||
APP_STATE_EVENT_WINDOW_DID_FOCUS
|
||||
} from '@/state';
|
||||
import { AppStateEvents } from '@/state';
|
||||
import {
|
||||
PANEL_NAME_NOTES,
|
||||
PANEL_NAME_TAGS
|
||||
@@ -15,6 +12,7 @@ import {
|
||||
STRING_DEFAULT_FILE_ERROR,
|
||||
StringSyncException
|
||||
} from '@/strings';
|
||||
import { PureCtrl } from './abstract/pure_ctrl';
|
||||
|
||||
class RootCtrl extends PureCtrl {
|
||||
/* @ngInject */
|
||||
@@ -45,7 +43,6 @@ class RootCtrl extends PureCtrl {
|
||||
needsUnlock: false,
|
||||
appClass: ''
|
||||
};
|
||||
|
||||
this.loadApplication();
|
||||
this.handleAutoSignInFromParams();
|
||||
this.addAppStateObserver();
|
||||
@@ -53,7 +50,7 @@ class RootCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
async loadApplication() {
|
||||
this.application.prepareForLaunch({
|
||||
await this.application.prepareForLaunch({
|
||||
callbacks: {
|
||||
authChallengeResponses: async (challenges) => {
|
||||
if (challenges.includes(Challenges.LocalPasscode)) {
|
||||
@@ -65,7 +62,7 @@ class RootCtrl extends PureCtrl {
|
||||
await this.application.launch();
|
||||
this.setState({ needsUnlock: false });
|
||||
await this.openDatabase();
|
||||
this.preferencesManager.load();
|
||||
await this.preferencesManager.initialize();
|
||||
this.addSyncStatusObserver();
|
||||
this.addSyncEventHandler();
|
||||
}
|
||||
@@ -76,7 +73,7 @@ class RootCtrl extends PureCtrl {
|
||||
|
||||
addAppStateObserver() {
|
||||
this.appState.addObserver(async (eventName, data) => {
|
||||
if (eventName === APP_STATE_EVENT_PANEL_RESIZED) {
|
||||
if (eventName === AppStateEvents.PanelResized) {
|
||||
if (data.panel === PANEL_NAME_NOTES) {
|
||||
this.notesCollapsed = data.collapsed;
|
||||
}
|
||||
@@ -87,7 +84,7 @@ class RootCtrl extends PureCtrl {
|
||||
if (this.notesCollapsed) { appClass += "collapsed-notes"; }
|
||||
if (this.tagsCollapsed) { appClass += " collapsed-tags"; }
|
||||
this.setState({ appClass });
|
||||
} else if (eventName === APP_STATE_EVENT_WINDOW_DID_FOCUS) {
|
||||
} else if (eventName === AppStateEvents.WindowDidFocus) {
|
||||
if (!(await this.application.isPasscodeLocked())) {
|
||||
this.application.sync();
|
||||
}
|
||||
@@ -110,7 +107,7 @@ class RootCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
// addSyncStatusObserver() {
|
||||
// this.syncStatusObserver = this.syncManager.registerSyncStatusObserver((status) => {
|
||||
// this.syncStatusObserver = syncManager.registerSyncStatusObserver((status) => {
|
||||
// if (status.retrievedCount > 20) {
|
||||
// const text = `Downloading ${status.retrievedCount} items. Keep app open.`;
|
||||
// this.syncStatus = this.statusManager.replaceStatusWithString(
|
||||
@@ -143,7 +140,7 @@ class RootCtrl extends PureCtrl {
|
||||
|
||||
// addSyncEventHandler() {
|
||||
// let lastShownDate;
|
||||
// this.syncManager.addEventHandler((syncEvent, data) => {
|
||||
// syncManager.addEventHandler((syncEvent, data) => {
|
||||
// this.$rootScope.$broadcast(
|
||||
// syncEvent,
|
||||
// data || {}
|
||||
@@ -183,14 +180,14 @@ class RootCtrl extends PureCtrl {
|
||||
// status
|
||||
// );
|
||||
// };
|
||||
// this.syncManager.loadLocalItems({ incrementalCallback }).then(() => {
|
||||
// syncManager.loadLocalItems({ incrementalCallback }).then(() => {
|
||||
// this.$timeout(() => {
|
||||
// this.$rootScope.$broadcast("initial-data-loaded");
|
||||
// this.syncStatus = this.statusManager.replaceStatusWithString(
|
||||
// this.syncStatus,
|
||||
// "Syncing..."
|
||||
// );
|
||||
// this.syncManager.sync({
|
||||
// syncManager.sync({
|
||||
// checkIntegrity: true
|
||||
// }).then(() => {
|
||||
// this.syncStatus = this.statusManager.removeStatus(this.syncStatus);
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import { SNNote, SNSmartTag, CONTENT_TYPE_TAG, CONTENT_TYPE_SMART_TAG } from 'snjs';
|
||||
import { SNNote, SNSmartTag, ContentTypes } from 'snjs';
|
||||
import template from '%/tags.pug';
|
||||
import {
|
||||
APP_STATE_EVENT_PREFERENCES_CHANGED,
|
||||
APP_STATE_EVENT_TAG_CHANGED
|
||||
} from '@/state';
|
||||
import { AppStateEvents } from '@/state';
|
||||
import { PANEL_NAME_TAGS } from '@/controllers/constants';
|
||||
import { PREF_TAGS_PANEL_WIDTH } from '@/services/preferencesManager';
|
||||
import { PrefKeys } from '@/services/preferencesManager';
|
||||
import { STRING_DELETE_TAG } from '@/strings';
|
||||
import { PureCtrl } from '@Controllers';
|
||||
|
||||
@@ -40,11 +37,11 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
|
||||
beginStreamingItems() {
|
||||
this.application.streamItems({
|
||||
contentType: CONTENT_TYPE_TAG,
|
||||
stream: async ({items}) => {
|
||||
contentType: ContentTypes.Tag,
|
||||
stream: async ({ items }) => {
|
||||
await this.setState({
|
||||
tags: this.application.getItems({contentType: CONTENT_TYPE_TAG}),
|
||||
smartTags: this.application.getItems({ contentType: CONTENT_TYPE_SMART_TAG }),
|
||||
tags: this.application.getItems({ contentType: ContentTypes.Tag }),
|
||||
smartTags: this.application.getItems({ contentType: ContentTypes.SmartTag }),
|
||||
});
|
||||
this.reloadNoteCounts();
|
||||
if (this.state.selectedTag) {
|
||||
@@ -62,9 +59,9 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
|
||||
addAppStateObserver() {
|
||||
this.appState.addObserver((eventName, data) => {
|
||||
if (eventName === APP_STATE_EVENT_PREFERENCES_CHANGED) {
|
||||
if (eventName === AppStateEvents.PreferencesChanged) {
|
||||
this.loadPreferences();
|
||||
} else if (eventName === APP_STATE_EVENT_TAG_CHANGED) {
|
||||
} else if (eventName === AppStateEvents.TagChanged) {
|
||||
this.setState({
|
||||
selectedTag: this.appState.getSelectedTag()
|
||||
});
|
||||
@@ -93,7 +90,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
loadPreferences() {
|
||||
const width = this.preferencesManager.getValue(PREF_TAGS_PANEL_WIDTH);
|
||||
const width = this.preferencesManager.getValue(PrefKeys.TagsPanelWidth);
|
||||
if (width) {
|
||||
this.panelController.setWidth(width);
|
||||
if (this.panelController.isCollapsed()) {
|
||||
@@ -107,7 +104,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
|
||||
onPanelResize = (newWidth, lastLeft, isAtMaxWidth, isCollapsed) => {
|
||||
this.preferencesManager.setUserPrefValue(
|
||||
PREF_TAGS_PANEL_WIDTH,
|
||||
PrefKeys.TagsPanelWidth,
|
||||
newWidth,
|
||||
true
|
||||
);
|
||||
@@ -130,7 +127,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
actionHandler: (component, action, data) => {
|
||||
if (action === 'select-item') {
|
||||
if (data.item.content_type === 'Tag') {
|
||||
const tag = this.application.findItem({uuid: data.item.uuid});
|
||||
const tag = this.application.findItem({ uuid: data.item.uuid });
|
||||
if (tag) {
|
||||
this.selectTag(tag);
|
||||
}
|
||||
@@ -157,7 +154,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
}
|
||||
if (tag.content.conflict_of) {
|
||||
tag.content.conflict_of = null;
|
||||
this.application.saveItem({item: tag});
|
||||
this.application.saveItem({ item: tag });
|
||||
}
|
||||
this.appState.setSelectedTag(tag);
|
||||
}
|
||||
@@ -167,7 +164,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
return;
|
||||
}
|
||||
const newTag = this.application.createItem({
|
||||
contentType: CONTENT_TYPE_TAG
|
||||
contentType: ContentTypes.Tag
|
||||
});
|
||||
this.setState({
|
||||
previousTag: this.state.selectedTag,
|
||||
@@ -177,7 +174,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
});
|
||||
/** @todo Should not be accessing internal function */
|
||||
/** Rely on local state instead of adding to global state */
|
||||
this.application.modelManager.insertItems({items: [newTag]});
|
||||
this.application.modelManager.insertItems({ items: [newTag] });
|
||||
}
|
||||
|
||||
tagTitleDidChange(tag) {
|
||||
@@ -188,14 +185,14 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
|
||||
async saveTag($event, tag) {
|
||||
$event.target.blur();
|
||||
await this.setState({
|
||||
editingTag: null
|
||||
await this.setState({
|
||||
editingTag: null
|
||||
});
|
||||
if (!tag.title || tag.title.length === 0) {
|
||||
if (this.state.editingTag) {
|
||||
tag.title = this.editingOriginalName;
|
||||
this.editingOriginalName = null;
|
||||
} else if(this.state.newTag) {
|
||||
} else if (this.state.newTag) {
|
||||
/** @todo Should not be accessing internal function */
|
||||
/** Rely on local state instead of adding to global state */
|
||||
this.application.modelManager.removeItemLocally(tag);
|
||||
@@ -206,10 +203,10 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
this.setState({ newTag: null });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.editingOriginalName = null;
|
||||
|
||||
const matchingTag = this.application.findTag({title: tag.title});
|
||||
const matchingTag = this.application.findTag({ title: tag.title });
|
||||
const alreadyExists = matchingTag && matchingTag !== tag;
|
||||
if (this.state.newTag === tag && alreadyExists) {
|
||||
this.application.alertManager.alert({
|
||||
@@ -222,7 +219,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
return;
|
||||
}
|
||||
|
||||
this.application.saveItem({item: tag});
|
||||
this.application.saveItem({ item: tag });
|
||||
this.selectTag(tag);
|
||||
this.setState({
|
||||
newTag: null
|
||||
@@ -247,7 +244,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
text: STRING_DELETE_TAG,
|
||||
destructive: true,
|
||||
onConfirm: () => {
|
||||
this.application.deleteItem({item: tag});
|
||||
this.application.deleteItem({ item: tag });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user