|
|
@ -1,4 +1,4 @@ |
|
|
|
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild, HostListener, Host} from '@angular/core'; |
|
|
|
import {Component, OnInit, ViewChild, HostListener, Host} from '@angular/core'; |
|
|
|
|
|
|
|
import { |
|
|
|
AlertController, |
|
|
@ -23,6 +23,7 @@ import {NodeTypeIcons} from './structures/node-types'; |
|
|
|
import {NavigationService} from './service/navigation.service'; |
|
|
|
import {DatabaseService} from './service/db/database.service'; |
|
|
|
import {EditorService} from './service/editor.service'; |
|
|
|
import {debug} from './utility'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-root', |
|
|
@ -88,7 +89,7 @@ export class AppComponent implements OnInit { |
|
|
|
private platform: Platform, |
|
|
|
private splashScreen: SplashScreen, |
|
|
|
private statusBar: StatusBar, |
|
|
|
private api: ApiService, |
|
|
|
public readonly api: ApiService, |
|
|
|
protected router: Router, |
|
|
|
protected alerts: AlertController, |
|
|
|
protected popover: PopoverController, |
|
|
@ -99,27 +100,7 @@ export class AppComponent implements OnInit { |
|
|
|
protected toasts: ToastController, |
|
|
|
protected db: DatabaseService, |
|
|
|
protected editor: EditorService, |
|
|
|
) { |
|
|
|
this.initializeApp(); |
|
|
|
} |
|
|
|
|
|
|
|
async _doInit() { |
|
|
|
await this.db.createSchemata(); |
|
|
|
|
|
|
|
this.reloadMenuItems().subscribe(() => { |
|
|
|
this.ready$.next(true); |
|
|
|
setTimeout(() => { |
|
|
|
this.loader.dismiss(); |
|
|
|
this.menuTree.treeModel.expandAll(); |
|
|
|
}, 10); |
|
|
|
|
|
|
|
if ( !this.versionInterval ) { |
|
|
|
this.versionInterval = setInterval(() => { |
|
|
|
this.checkNewVersion(); |
|
|
|
}, 1000 * 60 * 5); // Check for new version every 5 mins
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
) { } |
|
|
|
|
|
|
|
async checkNewVersion() { |
|
|
|
if ( !this.showedNewVersionAlert && await this.session.newVersionAvailable() ) { |
|
|
@ -144,20 +125,8 @@ export class AppComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
if ( !this.initialized$.getValue() ) { |
|
|
|
this.navService.sidebarRefresh$.subscribe(([_, quiet]) => { |
|
|
|
this.onMenuRefresh(quiet); |
|
|
|
}); |
|
|
|
|
|
|
|
const sub = this.initialized$.subscribe((didInit) => { |
|
|
|
if (didInit) { |
|
|
|
this._doInit(); |
|
|
|
sub.unsubscribe(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
this._doInit(); |
|
|
|
} |
|
|
|
debug('Initializing application.'); |
|
|
|
this.initializeApp(); |
|
|
|
} |
|
|
|
|
|
|
|
showOptions($event) { |
|
|
@ -262,7 +231,7 @@ export class AppComponent implements OnInit { |
|
|
|
}); |
|
|
|
} else if ( result.data === 'export_html' ) { |
|
|
|
this.exportTargetAsHTML(); |
|
|
|
}; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
await popover.present(); |
|
|
@ -420,19 +389,24 @@ export class AppComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
async initializeApp() { |
|
|
|
console.log('app', this); |
|
|
|
debug('app', this); |
|
|
|
this.loader = await this.loading.create({ |
|
|
|
message: 'Starting up...', |
|
|
|
cssClass: 'noded-loading-mask', |
|
|
|
showBackdrop: true, |
|
|
|
}); |
|
|
|
|
|
|
|
debug('Initializing platform and database...'); |
|
|
|
await this.loader.present(); |
|
|
|
await this.platform.ready(); |
|
|
|
await this.db.createSchemata(); |
|
|
|
|
|
|
|
let toast: any; |
|
|
|
|
|
|
|
debug('Subscribing to offline changes...'); |
|
|
|
this.api.offline$.subscribe(async isOffline => { |
|
|
|
if ( isOffline && !this.showedOfflineAlert ) { |
|
|
|
debug('Application went offline!'); |
|
|
|
toast = await this.toasts.create({ |
|
|
|
cssClass: 'compat-toast-container', |
|
|
|
message: 'Uh, oh! It looks like you\'re offline. Some features might not work as expected...', |
|
|
@ -441,39 +415,64 @@ export class AppComponent implements OnInit { |
|
|
|
this.showedOfflineAlert = true; |
|
|
|
await toast.present(); |
|
|
|
} else if ( !isOffline && this.showedOfflineAlert ) { |
|
|
|
debug('Appliation went online!'); |
|
|
|
await toast.dismiss(); |
|
|
|
this.showedOfflineAlert = false; |
|
|
|
await this.api.syncOfflineData(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
debug('Getting initial status...'); |
|
|
|
let stat: any = await this.session.stat(); |
|
|
|
debug('Got stat:', stat); |
|
|
|
|
|
|
|
if ( stat.public_user ) { |
|
|
|
this.api.isPublicUser = true; |
|
|
|
} |
|
|
|
|
|
|
|
if ( stat.authenticated_user ) { |
|
|
|
this.api.isAuthenticated = true; |
|
|
|
} |
|
|
|
|
|
|
|
this.api.systemBase = stat.system_base; |
|
|
|
|
|
|
|
if ( !stat.authenticated_user ) { |
|
|
|
if ( !this.api.isAuthenticated || this.api.isPublicUser ) { |
|
|
|
debug('Unauthenticated or public user...'); |
|
|
|
if ( !this.api.isOffline ) { |
|
|
|
debug('Trying to resume session...'); |
|
|
|
await this.api.resumeSession(); |
|
|
|
debug('Checking new status...'); |
|
|
|
stat = await this.session.stat(); |
|
|
|
debug('Got session resume stat:', stat); |
|
|
|
|
|
|
|
this.api.isAuthenticated = stat.authenticated_user; |
|
|
|
this.api.isPublicUser = stat.public_user; |
|
|
|
|
|
|
|
if ( !stat.authenticated_user ) { |
|
|
|
debug('Not authenticated! Redirecting.'); |
|
|
|
window.location.href = `${stat.system_base}start`; |
|
|
|
return; |
|
|
|
} |
|
|
|
} else { |
|
|
|
debug('Unauthenticated offline user. Purging local data!'); |
|
|
|
await this.db.purge(); |
|
|
|
window.location.href = `${stat.system_base}start`; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
debug('Set app name and system base:', stat.app_name, stat.system_base); |
|
|
|
this.session.appName = stat.app_name; |
|
|
|
this.session.systemBase = stat.system_base; |
|
|
|
|
|
|
|
debug('Initializing session...'); |
|
|
|
await this.session.initialize(); |
|
|
|
|
|
|
|
if ( this.session.get('user.preferences.dark_mode') ) { |
|
|
|
this.toggleDark(); |
|
|
|
} |
|
|
|
|
|
|
|
debug('Hiding native splash screen & setting status bar styles...'); |
|
|
|
await this.statusBar.styleDefault(); |
|
|
|
await this.splashScreen.hide(); |
|
|
|
|
|
|
@ -495,11 +494,13 @@ export class AppComponent implements OnInit { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ( this.isPrefetch() ) { |
|
|
|
this.loader.message = 'Downloading data...'; // TODO actually do the prefetch
|
|
|
|
if ( this.isPrefetch() && !this.api.isPublicUser ) { |
|
|
|
debug('Pre-fetching offline data...'); |
|
|
|
this.loader.message = 'Downloading data...'; |
|
|
|
try { |
|
|
|
await this.api.prefetchOfflineData(); |
|
|
|
} catch (e) { |
|
|
|
debug('Pre-fetch error:', e); |
|
|
|
this.toasts.create({ |
|
|
|
cssClass: 'compat-toast-container', |
|
|
|
message: 'An error occurred while pre-fetching offline data. Not all data was saved.', |
|
|
@ -514,13 +515,37 @@ export class AppComponent implements OnInit { |
|
|
|
|
|
|
|
this.initialized$.next(true); |
|
|
|
|
|
|
|
if ( this.session.get('user.preferences.default_page') ) { |
|
|
|
if ( !this.api.isPublicUser && this.session.get('user.preferences.default_page') ) { |
|
|
|
debug('Navigating to default page!'); |
|
|
|
const id = this.session.get('user.preferences.default_page'); |
|
|
|
const node = this.findNode(id); |
|
|
|
if ( node ) { |
|
|
|
this.navigateEditorToNode(node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
debug('Creating menu subscription...'); |
|
|
|
this.navService.sidebarRefresh$.subscribe(([_, quiet]) => { |
|
|
|
this.onMenuRefresh(quiet); |
|
|
|
}); |
|
|
|
|
|
|
|
debug('Reloading menu items...'); |
|
|
|
this.reloadMenuItems().subscribe(() => { |
|
|
|
debug('Reloaded menu items. Displaying interface.'); |
|
|
|
this.ready$.next(true); |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
this.loader.dismiss(); |
|
|
|
this.menuTree?.treeModel?.expandAll(); |
|
|
|
}, 10); |
|
|
|
|
|
|
|
if ( !this.versionInterval ) { |
|
|
|
this.versionInterval = setInterval(() => { |
|
|
|
debug('Checking for new application version.'); |
|
|
|
this.checkNewVersion(); |
|
|
|
}, 1000 * 60 * 5); // Check for new version every 5 mins
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
async doPrefetch() { |
|
|
|