Skip to content

Commit

Permalink
Functioning UI
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Feb 9, 2020
1 parent f6ef4a3 commit 8822580
Show file tree
Hide file tree
Showing 23 changed files with 2,047 additions and 1,688 deletions.
27 changes: 13 additions & 14 deletions app/assets/javascripts/app.js
Expand Up @@ -55,15 +55,14 @@ import { trusted } from './filters';

import {
ArchiveManager,
DatabaseManager,
DesktopManager,
KeyboardManager,
NativeExtManager,
GodService,
LockManager,
NativeExtManager,
PreferencesManager,
StatusManager,
ThemeManager,
AlertManager,
PreferencesManager
} from './services';

angular.module('app', ['ngSanitize']);
Expand Down Expand Up @@ -108,11 +107,12 @@ angular
.directive('accountMenu', () => new AccountMenu())
.directive('actionsMenu', () => new ActionsMenu())
.directive('componentModal', () => new ComponentModal())
.directive(
'componentView',
($rootScope, componentManager, desktopManager, $timeout) =>
new ComponentView($rootScope, componentManager, desktopManager, $timeout)
)
.directive('componentView', () => new ComponentView())
// .directive(
// 'componentView',
// ($rootScope, componentManager, desktopManager, $timeout) =>
// new ComponentView($rootScope, componentManager, desktopManager, $timeout)
// )
.directive('conflictResolutionModal', () => new ConflictResolutionModal())
.directive('editorMenu', () => new EditorMenu())
.directive('inputModal', () => new InputModal())
Expand All @@ -134,16 +134,15 @@ angular
// Services
angular
.module('app')
.service('application', Application)
.service('appState', AppState)
.service('preferencesManager', PreferencesManager)
.service('application', Application)
.service('archiveManager', ArchiveManager)
.service('databaseManager', DatabaseManager)
.service('desktopManager', DesktopManager)
.service('godService', GodService)
.service('keyboardManager', KeyboardManager)
.service('nativeExtManager', NativeExtManager)
.service('lockManager', LockManager)
.service('nativeExtManager', NativeExtManager)
.service('preferencesManager', PreferencesManager)
.service('statusManager', StatusManager)
.service('storageManager', StorageManager)
.service('alertManager', AlertManager)
.service('themeManager', ThemeManager);
31 changes: 14 additions & 17 deletions app/assets/javascripts/application.js
@@ -1,20 +1,21 @@
import {
import {
SNApplication,
SNAlertManager,
Platforms
} from 'snjs';
import angular from 'angular';
import { AlertManager } from '@/services/alertManager';
Environments,
platformFromString
} from 'snjs';
import angular from 'angular';
import { getPlatformString } from '@/utils';
import { AlertManager } from '@/services/alertManager';

import { WebDeviceInterface } from '@/web_device_interface';

export class Application extends SNApplication {
constructor(
desktopManager
) {
constructor() {
const deviceInterface = new WebDeviceInterface();
super({
platform: Platforms.Web,
environment: Environments.Web,
platform: platformFromString(getPlatformString()),
namespace: '',
host: window._default_sync_server,
deviceInterface: deviceInterface,
Expand All @@ -25,30 +26,26 @@ export class Application extends SNApplication {
}
]
});
this.desktopManager = desktopManager;
deviceInterface.setApplication(this);
this.overrideComponentManagerFunctions();
}

overrideComponentManagerFunctions() {
function openModalComponent(component) {
var scope = this.$rootScope.$new(true);
const scope = this.$rootScope.$new(true);
scope.component = component;
var el = this.$compile("<component-modal component='component' class='sk-modal'></component-modal>")(scope);
const el = this.$compile("<component-modal component='component' class='sk-modal'></component-modal>")(scope);
angular.element(document.body).append(el);
}

function presentPermissionsDialog(dialog) {
const scope = this.$rootScope.$new(true);
scope.permissionsString = dialog.permissionsString;
scope.component = dialog.component;
scope.callback = dialog.callback;

var el = this.$compile("<permissions-modal component='component' permissions-string='permissionsString' callback='callback' class='sk-modal'></permissions-modal>")(scope);
const el = this.$compile("<permissions-modal component='component' permissions-string='permissionsString' callback='callback' class='sk-modal'></permissions-modal>")(scope);
angular.element(document.body).append(el);
}

this.componentManager.openModalComponent = openModalComponent;
this.componentManager.presentPermissionsDialog = presentPermissionsDialog;
this.componentManager.setDesktopManager(this.desktopManager);
}
}
30 changes: 17 additions & 13 deletions app/assets/javascripts/controllers/editor.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -269,7 +273,7 @@ class EditorCtrl extends PureCtrl {
}

editorForNote(note) {
return this.componentManager.editorForNote(note);
return this.application.componentManager.editorForNote(note);
}

setMenuState(menu, state) {
Expand Down Expand Up @@ -861,7 +865,7 @@ class EditorCtrl extends PureCtrl {
}

registerComponentHandler() {
this.componentManager.registerHandler({
this.application.componentManager.registerHandler({
identifier: 'editor',
areas: [
'note-tags',
Expand Down Expand Up @@ -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;
});
Expand All @@ -988,29 +992,29 @@ 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)
);
}
}
}

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);
}
}
Expand Down
38 changes: 19 additions & 19 deletions app/assets/javascripts/controllers/footer.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -203,12 +211,8 @@ class FooterCtrl {
}, 2000);
}

getUser() {
return this.application.getUser();
}

updateOfflineStatus() {
this.offline = this.application.noUser();
this.offline = this.application.noAccount();
}

openSecurityUpdate() {
Expand All @@ -232,10 +236,6 @@ class FooterCtrl {
this.showAccountMenu = false;
}

hasPasscode() {
return this.application.hasPasscode();
}

lockApp() {
this.$rootScope.lockApplication();
}
Expand Down Expand Up @@ -351,7 +351,7 @@ class FooterCtrl {
}

clickOutsideAccountMenu() {
if(this.application.privilegesManager.authenticationInProgress()) {
if(this.godService.authenticationInProgress()) {
return;
}
this.showAccountMenu = false;
Expand Down
27 changes: 15 additions & 12 deletions app/assets/javascripts/controllers/notes/notes.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
});
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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: '',
Expand All @@ -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 });
Expand Down

0 comments on commit 8822580

Please sign in to comment.