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