Functioning UI
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
} from 'snjs';
|
||||
import find from 'lodash/find';
|
||||
import { isDesktopApplication } from '@/utils';
|
||||
import { KeyboardModifiers, KeyboardKeys } from '@/services/keyboardManager';
|
||||
import template from '%/editor.pug';
|
||||
import { PureCtrl } from '@Controllers';
|
||||
import { AppStateEvents, EventSources } from '@/state';
|
||||
@@ -80,9 +81,12 @@ class EditorCtrl extends PureCtrl {
|
||||
this.addAppStateObserver();
|
||||
this.addAppEventObserver();
|
||||
this.addSyncStatusObserver();
|
||||
this.streamItems();
|
||||
this.registerComponentHandler();
|
||||
this.registerKeyboardShortcuts();
|
||||
|
||||
application.onReady(() => {
|
||||
this.streamItems();
|
||||
this.registerComponentHandler();
|
||||
});
|
||||
|
||||
/** Used by .pug template */
|
||||
this.prefKeyMonospace = PrefKeys.EditorMonospaceEnabled;
|
||||
@@ -269,7 +273,7 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
editorForNote(note) {
|
||||
return this.componentManager.editorForNote(note);
|
||||
return this.application.componentManager.editorForNote(note);
|
||||
}
|
||||
|
||||
setMenuState(menu, state) {
|
||||
@@ -861,7 +865,7 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
registerComponentHandler() {
|
||||
this.componentManager.registerHandler({
|
||||
this.application.componentManager.registerHandler({
|
||||
identifier: 'editor',
|
||||
areas: [
|
||||
'note-tags',
|
||||
@@ -973,7 +977,7 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
reloadComponentStackArray() {
|
||||
const components = this.componentManager.componentsForArea('editor-stack')
|
||||
const components = this.application.componentManager.componentsForArea('editor-stack')
|
||||
.sort((a, b) => {
|
||||
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
|
||||
});
|
||||
@@ -988,7 +992,7 @@ class EditorCtrl extends PureCtrl {
|
||||
if (this.state.note) {
|
||||
for (const component of this.state.componentStack) {
|
||||
if (component.active) {
|
||||
this.componentManager.setComponentHidden(
|
||||
this.application.componentManager.setComponentHidden(
|
||||
component,
|
||||
!component.isExplicitlyEnabledForItem(this.state.note)
|
||||
);
|
||||
@@ -996,21 +1000,21 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
this.componentManager.contextItemDidChangeInArea('note-tags');
|
||||
this.componentManager.contextItemDidChangeInArea('editor-stack');
|
||||
this.componentManager.contextItemDidChangeInArea('editor-editor');
|
||||
this.application.componentManager.contextItemDidChangeInArea('note-tags');
|
||||
this.application.componentManager.contextItemDidChangeInArea('editor-stack');
|
||||
this.application.componentManager.contextItemDidChangeInArea('editor-editor');
|
||||
}
|
||||
|
||||
toggleStackComponentForCurrentItem(component) {
|
||||
if (component.hidden || !component.active) {
|
||||
this.componentManager.setComponentHidden(component, false);
|
||||
this.application.componentManager.setComponentHidden(component, false);
|
||||
this.associateComponentWithCurrentNote(component);
|
||||
if (!component.active) {
|
||||
this.componentManager.activateComponent(component);
|
||||
this.application.componentManager.activateComponent(component);
|
||||
}
|
||||
this.componentManager.contextItemDidChangeInArea('editor-stack');
|
||||
this.application.componentManager.contextItemDidChangeInArea('editor-stack');
|
||||
} else {
|
||||
this.componentManager.setComponentHidden(component, true);
|
||||
this.application.componentManager.setComponentHidden(component, true);
|
||||
this.disassociateComponentWithCurrentNote(component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,21 +37,29 @@ class FooterCtrl {
|
||||
this.showSyncResolution = false;
|
||||
|
||||
this.addAppStateObserver();
|
||||
this.updateOfflineStatus();
|
||||
this.addAppEventObserver();
|
||||
this.findErrors();
|
||||
this.streamItems();
|
||||
this.registerComponentHandler();
|
||||
this.addRootScopeListeners();
|
||||
|
||||
this.godService.checkForSecurityUpdate().then((available) => {
|
||||
this.securityUpdateAvailable = available;
|
||||
});
|
||||
this.statusManager.addStatusObserver((string) => {
|
||||
this.$timeout(() => {
|
||||
this.arbitraryStatusMessage = string;
|
||||
});
|
||||
});
|
||||
|
||||
application.onReady(() => {
|
||||
this.application.hasPasscode().then((value) => {
|
||||
this.hasPasscode = value;
|
||||
});
|
||||
|
||||
this.godService.checkForSecurityUpdate().then((available) => {
|
||||
this.securityUpdateAvailable = available;
|
||||
});
|
||||
this.user = this.application.getUser();
|
||||
this.updateOfflineStatus();
|
||||
this.addAppEventObserver();
|
||||
this.findErrors();
|
||||
this.streamItems();
|
||||
this.registerComponentHandler();
|
||||
});
|
||||
}
|
||||
|
||||
addRootScopeListeners() {
|
||||
@@ -99,7 +107,7 @@ class FooterCtrl {
|
||||
}
|
||||
|
||||
addAppEventObserver() {
|
||||
this.application.addEventHandler((eventName) => {
|
||||
this.application.addEventObserver((eventName) => {
|
||||
if (eventName === ApplicationEvents.LoadedLocalData) {
|
||||
if(this.offline && this.application.getNoteCount() === 0) {
|
||||
this.showAccountMenu = true;
|
||||
@@ -203,12 +211,8 @@ class FooterCtrl {
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
getUser() {
|
||||
return this.application.getUser();
|
||||
}
|
||||
|
||||
updateOfflineStatus() {
|
||||
this.offline = this.application.noUser();
|
||||
this.offline = this.application.noAccount();
|
||||
}
|
||||
|
||||
openSecurityUpdate() {
|
||||
@@ -232,10 +236,6 @@ class FooterCtrl {
|
||||
this.showAccountMenu = false;
|
||||
}
|
||||
|
||||
hasPasscode() {
|
||||
return this.application.hasPasscode();
|
||||
}
|
||||
|
||||
lockApp() {
|
||||
this.$rootScope.lockApplication();
|
||||
}
|
||||
@@ -351,7 +351,7 @@ class FooterCtrl {
|
||||
}
|
||||
|
||||
clickOutsideAccountMenu() {
|
||||
if(this.application.privilegesManager.authenticationInProgress()) {
|
||||
if(this.godService.authenticationInProgress()) {
|
||||
return;
|
||||
}
|
||||
this.showAccountMenu = false;
|
||||
|
||||
@@ -4,6 +4,7 @@ import template from '%/notes.pug';
|
||||
import { ApplicationEvents, ContentTypes } from 'snjs';
|
||||
import { PureCtrl } from '@Controllers';
|
||||
import { AppStateEvents } from '@/state';
|
||||
import { KeyboardModifiers, KeyboardKeys } from '@/services/keyboardManager';
|
||||
import {
|
||||
PrefKeys
|
||||
} from '@/services/preferencesManager';
|
||||
@@ -70,13 +71,15 @@ class NotesCtrl extends PureCtrl {
|
||||
|
||||
this.addAppStateObserver();
|
||||
this.addAppEventObserver();
|
||||
this.streamNotesAndTags();
|
||||
this.reloadPreferences();
|
||||
this.resetPagination();
|
||||
this.registerKeyboardShortcuts();
|
||||
angular.element(document).ready(() => {
|
||||
this.reloadPreferences();
|
||||
});
|
||||
application.onReady(() => {
|
||||
this.streamNotesAndTags();
|
||||
this.reloadPreferences();
|
||||
});
|
||||
}
|
||||
|
||||
addAppStateObserver() {
|
||||
@@ -99,7 +102,7 @@ class NotesCtrl extends PureCtrl {
|
||||
if (eventName === ApplicationEvents.SignedIn) {
|
||||
/** Delete dummy note if applicable */
|
||||
if (this.state.selectedNote && this.state.selectedNote.dummy) {
|
||||
this.application.removeItemLocally({ item: this.state.selectedNote });
|
||||
this.application.deleteItemLocally({ item: this.state.selectedNote });
|
||||
this.selectNote(null).then(() => {
|
||||
this.reloadNotes();
|
||||
});
|
||||
@@ -110,10 +113,6 @@ class NotesCtrl extends PureCtrl {
|
||||
*/
|
||||
this.createDummyOnSynCompletionIfNoNotes = true;
|
||||
}
|
||||
} else if (eventName === ApplicationEvents.LoadedLocalData) {
|
||||
if (this.state.notes.length === 0) {
|
||||
this.createNewNote();
|
||||
}
|
||||
} else if (eventName === ApplicationEvents.CompletedSync) {
|
||||
if (this.createDummyOnSynCompletionIfNoNotes && this.state.notes.length === 0) {
|
||||
this.createDummyOnSynCompletionIfNoNotes = false;
|
||||
@@ -152,7 +151,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.deleteItemLocally({ item: this.state.selectedNote });
|
||||
if (previousTag) {
|
||||
_.remove(previousTag.notes, this.state.selectedNote);
|
||||
}
|
||||
@@ -251,7 +250,7 @@ class NotesCtrl extends PureCtrl {
|
||||
}
|
||||
const previousNote = this.state.selectedNote;
|
||||
if (previousNote && previousNote.dummy) {
|
||||
this.application.removeItemLocally({ previousNote });
|
||||
this.application.deleteItemLocally({ item: previousNote });
|
||||
this.removeNoteFromList(previousNote);
|
||||
}
|
||||
await this.setState({
|
||||
@@ -502,12 +501,17 @@ class NotesCtrl extends PureCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
createNewNote() {
|
||||
async createNewNote() {
|
||||
const selectedTag = this.appState.getSelectedTag();
|
||||
if (!selectedTag) {
|
||||
debugger;
|
||||
throw 'Attempting to create note with no selected tag';
|
||||
}
|
||||
if (this.state.selectedNote && this.state.selectedNote.dummy) {
|
||||
return;
|
||||
}
|
||||
const title = "Note" + (this.state.notes ? (" " + (this.state.notes.length + 1)) : "");
|
||||
const newNote = this.application.createItem({
|
||||
const newNote = await this.application.createItem({
|
||||
contentType: ContentTypes.Note,
|
||||
content: {
|
||||
text: '',
|
||||
@@ -517,7 +521,6 @@ class NotesCtrl extends PureCtrl {
|
||||
newNote.client_updated_at = new Date();
|
||||
newNote.dummy = true;
|
||||
this.application.setItemNeedsSync({ item: newNote });
|
||||
const selectedTag = this.appState.getSelectedTag();
|
||||
if (!selectedTag.isSmartTag()) {
|
||||
selectedTag.addItemAsRelationship(newNote);
|
||||
this.application.setItemNeedsSync({ item: selectedTag });
|
||||
|
||||
@@ -22,7 +22,7 @@ class RootCtrl extends PureCtrl {
|
||||
$timeout,
|
||||
application,
|
||||
appState,
|
||||
databaseManager,
|
||||
desktopManager,
|
||||
lockManager,
|
||||
preferencesManager,
|
||||
themeManager /** Unused below, required to load globally */,
|
||||
@@ -34,7 +34,7 @@ class RootCtrl extends PureCtrl {
|
||||
this.$timeout = $timeout;
|
||||
this.application = application;
|
||||
this.appState = appState;
|
||||
this.databaseManager = databaseManager;
|
||||
this.desktopManager = desktopManager;
|
||||
this.lockManager = lockManager;
|
||||
this.preferencesManager = preferencesManager;
|
||||
this.statusManager = statusManager;
|
||||
@@ -44,27 +44,34 @@ class RootCtrl extends PureCtrl {
|
||||
appClass: ''
|
||||
};
|
||||
this.loadApplication();
|
||||
this.handleAutoSignInFromParams();
|
||||
this.addAppStateObserver();
|
||||
this.addDragDropHandlers();
|
||||
|
||||
application.onReady(() => {
|
||||
this.handleAutoSignInFromParams();
|
||||
});
|
||||
}
|
||||
|
||||
async loadApplication() {
|
||||
await this.application.prepareForLaunch({
|
||||
callbacks: {
|
||||
authChallengeResponses: async (challenges) => {
|
||||
console.log("Needs challenge repsonses", challenges);
|
||||
if (challenges.includes(Challenges.LocalPasscode)) {
|
||||
this.setState({ needsUnlock: true });
|
||||
}
|
||||
},
|
||||
onReady: async () => {
|
||||
await this.appState.setApplicationReady();
|
||||
}
|
||||
}
|
||||
});
|
||||
await this.application.launch();
|
||||
this.setState({ needsUnlock: false });
|
||||
await this.openDatabase();
|
||||
await this.preferencesManager.initialize();
|
||||
this.addSyncStatusObserver();
|
||||
this.addSyncEventHandler();
|
||||
this.application.componentManager.setDesktopManager(this.desktopManager);
|
||||
this.preferencesManager.initialize();
|
||||
// this.addSyncStatusObserver();
|
||||
// this.addSyncEventHandler();
|
||||
}
|
||||
|
||||
onUpdateAvailable() {
|
||||
@@ -92,20 +99,6 @@ class RootCtrl extends PureCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
async openDatabase() {
|
||||
this.databaseManager.setLocked(false);
|
||||
this.databaseManager.openDatabase({
|
||||
onUpgradeNeeded: () => {
|
||||
/**
|
||||
* New database/database wiped, delete syncToken so that items
|
||||
* can be refetched entirely from server
|
||||
*/
|
||||
this.application.syncManager.clearSyncPositionTokens();
|
||||
this.application.sync();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// addSyncStatusObserver() {
|
||||
// this.syncStatusObserver = syncManager.registerSyncStatusObserver((status) => {
|
||||
// if (status.retrievedCount > 20) {
|
||||
|
||||
@@ -21,18 +21,21 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
this.appState = appState;
|
||||
this.preferencesManager = preferencesManager;
|
||||
this.panelController = {};
|
||||
this.beginStreamingItems();
|
||||
this.addAppStateObserver();
|
||||
this.loadPreferences();
|
||||
this.registerComponentHandler();
|
||||
this.state = {
|
||||
smartTags: this.application.getSmartTags(),
|
||||
smartTags: [],
|
||||
noteCounts: {}
|
||||
};
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this.selectTag(this.state.smartTags[0]);
|
||||
application.onReady(() => {
|
||||
this.beginStreamingItems();
|
||||
const smartTags = this.application.getSmartTags();
|
||||
this.setState({
|
||||
smartTags: smartTags,
|
||||
});
|
||||
this.selectTag(smartTags[0]);
|
||||
});
|
||||
}
|
||||
|
||||
beginStreamingItems() {
|
||||
@@ -41,7 +44,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
stream: async ({ items }) => {
|
||||
await this.setState({
|
||||
tags: this.application.getItems({ contentType: ContentTypes.Tag }),
|
||||
smartTags: this.application.getItems({ contentType: ContentTypes.SmartTag }),
|
||||
smartTags: this.application.getSmartTags(),
|
||||
});
|
||||
this.reloadNoteCounts();
|
||||
if (this.state.selectedTag) {
|
||||
@@ -159,11 +162,11 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
this.appState.setSelectedTag(tag);
|
||||
}
|
||||
|
||||
clickedAddNewTag() {
|
||||
async clickedAddNewTag() {
|
||||
if (this.state.editingTag) {
|
||||
return;
|
||||
}
|
||||
const newTag = this.application.createItem({
|
||||
const newTag = await this.application.createItem({
|
||||
contentType: ContentTypes.Tag
|
||||
});
|
||||
this.setState({
|
||||
|
||||
Reference in New Issue
Block a user