MOBILE-2302 core: Improve how to obtain root nav controller
parent
ad5365edfe
commit
b4f04e3478
|
@ -12,10 +12,11 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, ViewChild, AfterViewInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { Platform, Nav } from 'ionic-angular';
|
import { Platform } from 'ionic-angular';
|
||||||
import { StatusBar } from '@ionic-native/status-bar';
|
import { StatusBar } from '@ionic-native/status-bar';
|
||||||
import { SplashScreen } from '@ionic-native/splash-screen';
|
import { SplashScreen } from '@ionic-native/splash-screen';
|
||||||
|
import { CoreAppProvider } from '../providers/app';
|
||||||
import { CoreEventsProvider } from '../providers/events';
|
import { CoreEventsProvider } from '../providers/events';
|
||||||
import { CoreLoggerProvider } from '../providers/logger';
|
import { CoreLoggerProvider } from '../providers/logger';
|
||||||
import { CoreLoginHelperProvider } from '../core/login/providers/helper';
|
import { CoreLoginHelperProvider } from '../core/login/providers/helper';
|
||||||
|
@ -23,8 +24,7 @@ import { CoreLoginHelperProvider } from '../core/login/providers/helper';
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: 'app.html'
|
templateUrl: 'app.html'
|
||||||
})
|
})
|
||||||
export class MyApp implements AfterViewInit {
|
export class MoodleMobileApp implements OnInit {
|
||||||
@ViewChild(Nav) navCtrl;
|
|
||||||
// Use the page name (string) because the page is lazy loaded (Ionic feature). That way we can load pages without
|
// Use the page name (string) because the page is lazy loaded (Ionic feature). That way we can load pages without
|
||||||
// having to import them. The downside is that each page needs to implement a ngModule.
|
// having to import them. The downside is that each page needs to implement a ngModule.
|
||||||
rootPage:any = 'CoreLoginInitPage';
|
rootPage:any = 'CoreLoginInitPage';
|
||||||
|
@ -32,7 +32,8 @@ export class MyApp implements AfterViewInit {
|
||||||
protected lastUrls = {};
|
protected lastUrls = {};
|
||||||
|
|
||||||
constructor(private platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, logger: CoreLoggerProvider,
|
constructor(private platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, logger: CoreLoggerProvider,
|
||||||
private eventsProvider: CoreEventsProvider, private loginHelper: CoreLoginHelperProvider) {
|
private eventsProvider: CoreEventsProvider, private loginHelper: CoreLoginHelperProvider,
|
||||||
|
private appProvider: CoreAppProvider) {
|
||||||
this.logger = logger.getInstance('AppComponent');
|
this.logger = logger.getInstance('AppComponent');
|
||||||
|
|
||||||
platform.ready().then(() => {
|
platform.ready().then(() => {
|
||||||
|
@ -45,14 +46,12 @@ export class MyApp implements AfterViewInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View has been initialized.
|
* Component being initialized.
|
||||||
*/
|
*/
|
||||||
ngAfterViewInit() {
|
ngOnInit() {
|
||||||
this.loginHelper.setNavCtrl(this.navCtrl);
|
|
||||||
|
|
||||||
// Go to sites page when user is logged out.
|
// Go to sites page when user is logged out.
|
||||||
this.eventsProvider.on(CoreEventsProvider.LOGOUT, () => {
|
this.eventsProvider.on(CoreEventsProvider.LOGOUT, () => {
|
||||||
this.navCtrl.setRoot('CoreLoginSitesPage');
|
this.appProvider.getRootNavController().setRoot('CoreLoginSitesPage');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen for session expired events.
|
// Listen for session expired events.
|
||||||
|
|
|
@ -25,7 +25,7 @@ import { Keyboard } from '@ionic-native/keyboard';
|
||||||
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
||||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||||
|
|
||||||
import { MyApp } from './app.component';
|
import { MoodleMobileApp } from './app.component';
|
||||||
import { CoreInterceptor } from '../classes/interceptor';
|
import { CoreInterceptor } from '../classes/interceptor';
|
||||||
import { CoreLoggerProvider } from '../providers/logger';
|
import { CoreLoggerProvider } from '../providers/logger';
|
||||||
import { CoreDbProvider } from '../providers/db';
|
import { CoreDbProvider } from '../providers/db';
|
||||||
|
@ -66,13 +66,13 @@ export function createTranslateLoader(http: HttpClient) {
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
MyApp
|
MoodleMobileApp
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
HttpClientModule, // HttpClient is used to make JSON requests. It fails for HEAD requests because there is no content.
|
HttpClientModule, // HttpClient is used to make JSON requests. It fails for HEAD requests because there is no content.
|
||||||
HttpModule,
|
HttpModule,
|
||||||
IonicModule.forRoot(MyApp, {
|
IonicModule.forRoot(MoodleMobileApp, {
|
||||||
pageTransition: 'ios-transition'
|
pageTransition: 'ios-transition'
|
||||||
}),
|
}),
|
||||||
TranslateModule.forRoot({
|
TranslateModule.forRoot({
|
||||||
|
@ -90,7 +90,7 @@ export function createTranslateLoader(http: HttpClient) {
|
||||||
],
|
],
|
||||||
bootstrap: [IonicApp],
|
bootstrap: [IonicApp],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
MyApp
|
MoodleMobileApp
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -219,7 +219,7 @@ export class CoreLoginCredentialsPage {
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
} else {
|
} else {
|
||||||
return this.loginHelper.goToSiteInitialPage(this.navCtrl, true);
|
return this.loginHelper.goToSiteInitialPage();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
|
|
@ -74,13 +74,13 @@ export class CoreLoginInitPage {
|
||||||
protected loadPage() : void {
|
protected loadPage() : void {
|
||||||
if (this.sitesProvider.isLoggedIn()) {
|
if (this.sitesProvider.isLoggedIn()) {
|
||||||
if (!this.loginHelper.isSiteLoggedOut()) {
|
if (!this.loginHelper.isSiteLoggedOut()) {
|
||||||
this.loginHelper.goToSiteInitialPage(this.navCtrl, true);
|
this.loginHelper.goToSiteInitialPage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.sitesProvider.hasSites().then(() => {
|
this.sitesProvider.hasSites().then(() => {
|
||||||
this.navCtrl.setRoot('CoreLoginSitesPage');
|
this.navCtrl.setRoot('CoreLoginSitesPage');
|
||||||
}, () => {
|
}, () => {
|
||||||
this.loginHelper.goToAddSite(this.navCtrl, true);
|
this.loginHelper.goToAddSite(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ export class CoreLoginReconnectPage {
|
||||||
// Page defined, go to that page instead of site initial page.
|
// Page defined, go to that page instead of site initial page.
|
||||||
return this.navCtrl.setRoot(this.pageName, this.pageParams);
|
return this.navCtrl.setRoot(this.pageName, this.pageParams);
|
||||||
} else {
|
} else {
|
||||||
return this.loginHelper.goToSiteInitialPage(this.navCtrl, true);
|
return this.loginHelper.goToSiteInitialPage();
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
// Site deleted? Go back to login page.
|
// Site deleted? Go back to login page.
|
||||||
|
|
|
@ -110,7 +110,7 @@ export class CoreLoginSitePolicyPage {
|
||||||
return this.currentSite.invalidateWsCache().catch(() => {
|
return this.currentSite.invalidateWsCache().catch(() => {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return this.loginHelper.goToSiteInitialPage(this.navCtrl, true);
|
return this.loginHelper.goToSiteInitialPage();
|
||||||
});
|
});
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.domUtils.showErrorModalDefault(error.message, 'Error accepting site policy.');
|
this.domUtils.showErrorModalDefault(error.message, 'Error accepting site policy.');
|
||||||
|
|
|
@ -74,7 +74,7 @@ export class CoreLoginSitePage {
|
||||||
// It's a demo site.
|
// It's a demo site.
|
||||||
this.sitesProvider.getUserToken(siteData.url, siteData.username, siteData.password).then((data) => {
|
this.sitesProvider.getUserToken(siteData.url, siteData.username, siteData.password).then((data) => {
|
||||||
return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken).then(() => {
|
return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken).then(() => {
|
||||||
return this.loginHelper.goToSiteInitialPage(this.navCtrl, true);
|
return this.loginHelper.goToSiteInitialPage();
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
this.domUtils.showErrorModal(error);
|
this.domUtils.showErrorModal(error);
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { IonicPage, NavController } from 'ionic-angular';
|
import { IonicPage } from 'ionic-angular';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { CoreLoggerProvider } from '../../../../providers/logger';
|
import { CoreLoggerProvider } from '../../../../providers/logger';
|
||||||
import { CoreSitesProvider, CoreSiteBasicInfo } from '../../../../providers/sites';
|
import { CoreSitesProvider, CoreSiteBasicInfo } from '../../../../providers/sites';
|
||||||
|
@ -34,7 +34,7 @@ export class CoreLoginSitesPage {
|
||||||
showDelete: boolean;
|
showDelete: boolean;
|
||||||
protected logger;
|
protected logger;
|
||||||
|
|
||||||
constructor(private navCtrl: NavController, private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider,
|
constructor(private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider,
|
||||||
private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider,
|
private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider,
|
||||||
private translate: TranslateService, logger: CoreLoggerProvider) {
|
private translate: TranslateService, logger: CoreLoggerProvider) {
|
||||||
this.logger = logger.getInstance('CoreLoginSitesPage');
|
this.logger = logger.getInstance('CoreLoginSitesPage');
|
||||||
|
@ -85,7 +85,7 @@ export class CoreLoginSitesPage {
|
||||||
* Go to the page to add a site.
|
* Go to the page to add a site.
|
||||||
*/
|
*/
|
||||||
add() : void {
|
add() : void {
|
||||||
this.loginHelper.goToAddSite(this.navCtrl, false);
|
this.loginHelper.goToAddSite(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,7 +108,7 @@ export class CoreLoginSitesPage {
|
||||||
|
|
||||||
// If there are no sites left, go to add site.
|
// If there are no sites left, go to add site.
|
||||||
this.sitesProvider.hasNoSites().then(() => {
|
this.sitesProvider.hasNoSites().then(() => {
|
||||||
this.loginHelper.goToAddSite(this.navCtrl, true);
|
this.loginHelper.goToAddSite(true);
|
||||||
});
|
});
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.logger.error('Error deleting site ' + site.id, error);
|
this.logger.error('Error deleting site ' + site.id, error);
|
||||||
|
@ -131,7 +131,7 @@ export class CoreLoginSitesPage {
|
||||||
|
|
||||||
this.sitesProvider.loadSite(siteId).then(() => {
|
this.sitesProvider.loadSite(siteId).then(() => {
|
||||||
if (!this.loginHelper.isSiteLoggedOut()) {
|
if (!this.loginHelper.isSiteLoggedOut()) {
|
||||||
return this.loginHelper.goToSiteInitialPage(this.navCtrl, true);
|
return this.loginHelper.goToSiteInitialPage();
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.logger.error('Error loading site ' + siteId, error);
|
this.logger.error('Error loading site ' + siteId, error);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { NavController, Platform } from 'ionic-angular';
|
import { Platform } from 'ionic-angular';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { CoreAppProvider } from '../../../providers/app';
|
import { CoreAppProvider } from '../../../providers/app';
|
||||||
import { CoreConfigProvider } from '../../../providers/config';
|
import { CoreConfigProvider } from '../../../providers/config';
|
||||||
|
@ -46,7 +46,6 @@ export class CoreLoginHelperProvider {
|
||||||
protected logger;
|
protected logger;
|
||||||
protected isSSOConfirmShown = false;
|
protected isSSOConfirmShown = false;
|
||||||
protected isOpenEditAlertShown = false;
|
protected isOpenEditAlertShown = false;
|
||||||
protected navCtrl: NavController;
|
|
||||||
lastInAppUrl: string;
|
lastInAppUrl: string;
|
||||||
waitingForBrowser = false;
|
waitingForBrowser = false;
|
||||||
|
|
||||||
|
@ -142,9 +141,9 @@ export class CoreLoginHelperProvider {
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (siteData.pageName) {
|
if (siteData.pageName) {
|
||||||
// State defined, go to that state instead of site initial page.
|
// State defined, go to that state instead of site initial page.
|
||||||
this.navCtrl.push(siteData.pageName, siteData.pageParams);
|
this.appProvider.getRootNavController().push(siteData.pageName, siteData.pageParams);
|
||||||
} else {
|
} else {
|
||||||
this.goToSiteInitialPage(this.navCtrl, true);
|
this.goToSiteInitialPage();
|
||||||
}
|
}
|
||||||
}).catch((errorMessage) => {
|
}).catch((errorMessage) => {
|
||||||
if (typeof errorMessage == 'string' && errorMessage != '') {
|
if (typeof errorMessage == 'string' && errorMessage != '') {
|
||||||
|
@ -176,8 +175,9 @@ export class CoreLoginHelperProvider {
|
||||||
* Function called when an SSO InAppBrowser is closed or the app is resumed. Check if user needs to be logged out.
|
* Function called when an SSO InAppBrowser is closed or the app is resumed. Check if user needs to be logged out.
|
||||||
*/
|
*/
|
||||||
checkLogout() {
|
checkLogout() {
|
||||||
|
let navCtrl = this.appProvider.getRootNavController();
|
||||||
if (!this.appProvider.isSSOAuthenticationOngoing() && this.sitesProvider.isLoggedIn() &&
|
if (!this.appProvider.isSSOAuthenticationOngoing() && this.sitesProvider.isLoggedIn() &&
|
||||||
this.sitesProvider.getCurrentSite().isLoggedOut() && this.navCtrl.getActive().name == 'CoreLoginReconnectPage') {
|
this.sitesProvider.getCurrentSite().isLoggedOut() && navCtrl.getActive().name == 'CoreLoginReconnectPage') {
|
||||||
// User must reauthenticate but he closed the InAppBrowser without doing so, logout him.
|
// User must reauthenticate but he closed the InAppBrowser without doing so, logout him.
|
||||||
this.sitesProvider.logout();
|
this.sitesProvider.logout();
|
||||||
}
|
}
|
||||||
|
@ -345,11 +345,10 @@ export class CoreLoginHelperProvider {
|
||||||
* Go to the page to add a new site.
|
* Go to the page to add a new site.
|
||||||
* If a fixed URL is configured, go to credentials instead.
|
* If a fixed URL is configured, go to credentials instead.
|
||||||
*
|
*
|
||||||
* @param {NavController} navCtrl The NavController instance to use.
|
|
||||||
* @param {boolean} [setRoot] True to set the new page as root, false to add it to the stack.
|
* @param {boolean} [setRoot] True to set the new page as root, false to add it to the stack.
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
goToAddSite(navCtrl: NavController, setRoot?: boolean) : Promise<any> {
|
goToAddSite(setRoot?: boolean) : Promise<any> {
|
||||||
let pageName,
|
let pageName,
|
||||||
params;
|
params;
|
||||||
|
|
||||||
|
@ -365,25 +364,19 @@ export class CoreLoginHelperProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setRoot) {
|
if (setRoot) {
|
||||||
return navCtrl.setRoot(pageName, params, {animate: false});
|
return this.appProvider.getRootNavController().setRoot(pageName, params, {animate: false});
|
||||||
} else {
|
} else {
|
||||||
return navCtrl.push(pageName, params);
|
return this.appProvider.getRootNavController().push(pageName, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go to the initial page of a site depending on 'userhomepage' setting.
|
* Go to the initial page of a site depending on 'userhomepage' setting.
|
||||||
*
|
*
|
||||||
* @param {NavController} navCtrl The NavController instance to use.
|
|
||||||
* @param {boolean} [setRoot] True to set the new page as root, false to add it to the stack.
|
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
goToSiteInitialPage(navCtrl: NavController, setRoot?: boolean) : Promise<any> {
|
goToSiteInitialPage() : Promise<any> {
|
||||||
if (setRoot) {
|
return this.appProvider.getRootNavController().setRoot('CoreMainMenuPage');
|
||||||
return navCtrl.setRoot('CoreMainMenuPage', {}, {animate: false});
|
|
||||||
} else {
|
|
||||||
return navCtrl.push('CoreMainMenuPage');
|
|
||||||
}
|
|
||||||
// return this.isMyOverviewEnabled().then((myOverview) => {
|
// return this.isMyOverviewEnabled().then((myOverview) => {
|
||||||
// let myCourses = !myOverview && this.isMyCoursesEnabled(),
|
// let myCourses = !myOverview && this.isMyCoursesEnabled(),
|
||||||
// site = this.sitesProvider.getCurrentSite(),
|
// site = this.sitesProvider.getCurrentSite(),
|
||||||
|
@ -625,7 +618,7 @@ export class CoreLoginHelperProvider {
|
||||||
protected loadSiteAndPage(page: string, params: any, siteId: string) : void {
|
protected loadSiteAndPage(page: string, params: any, siteId: string) : void {
|
||||||
if (siteId == CoreConstants.noSiteId) {
|
if (siteId == CoreConstants.noSiteId) {
|
||||||
// Page doesn't belong to a site, just load the page.
|
// Page doesn't belong to a site, just load the page.
|
||||||
this.navCtrl.setRoot(page, params);
|
this.appProvider.getRootNavController().setRoot(page, params);
|
||||||
} else {
|
} else {
|
||||||
let modal = this.domUtils.showModalLoading();
|
let modal = this.domUtils.showModalLoading();
|
||||||
this.sitesProvider.loadSite(siteId).then(() => {
|
this.sitesProvider.loadSite(siteId).then(() => {
|
||||||
|
@ -634,7 +627,7 @@ export class CoreLoginHelperProvider {
|
||||||
}
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// Site doesn't exist.
|
// Site doesn't exist.
|
||||||
this.navCtrl.setRoot('CoreLoginSitesPage')
|
this.appProvider.getRootNavController().setRoot('CoreLoginSitesPage')
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
modal.dismiss();
|
modal.dismiss();
|
||||||
});
|
});
|
||||||
|
@ -648,7 +641,7 @@ export class CoreLoginHelperProvider {
|
||||||
* @param {any} params Params to pass to the page.
|
* @param {any} params Params to pass to the page.
|
||||||
*/
|
*/
|
||||||
protected loadPageInMainMenu(page: string, params: any) : void {
|
protected loadPageInMainMenu(page: string, params: any) : void {
|
||||||
this.navCtrl.setRoot('CoreMainMenuPage', {redirectPage: page, redirectParams: params})
|
this.appProvider.getRootNavController().setRoot('CoreMainMenuPage', {redirectPage: page, redirectParams: params})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -839,7 +832,7 @@ export class CoreLoginHelperProvider {
|
||||||
if (siteId) {
|
if (siteId) {
|
||||||
this.loadSiteAndPage(page, params, siteId);
|
this.loadSiteAndPage(page, params, siteId);
|
||||||
} else {
|
} else {
|
||||||
this.navCtrl.setRoot('CoreLoginSitesPage')
|
this.appProvider.getRootNavController().setRoot('CoreLoginSitesPage')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -919,7 +912,7 @@ export class CoreLoginHelperProvider {
|
||||||
} else {
|
} else {
|
||||||
let info = currentSite.getInfo();
|
let info = currentSite.getInfo();
|
||||||
if (typeof info != 'undefined' && typeof info.username != 'undefined') {
|
if (typeof info != 'undefined' && typeof info.username != 'undefined') {
|
||||||
this.navCtrl.setRoot('CoreLoginReconnectPage', {
|
this.appProvider.getRootNavController().setRoot('CoreLoginReconnectPage', {
|
||||||
infoSiteUrl: info.siteurl,
|
infoSiteUrl: info.siteurl,
|
||||||
siteUrl: result.siteUrl,
|
siteUrl: result.siteUrl,
|
||||||
siteId: siteId,
|
siteId: siteId,
|
||||||
|
@ -939,15 +932,6 @@ export class CoreLoginHelperProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a NavController to use.
|
|
||||||
*
|
|
||||||
* @param {NavController} navCtrl Nav controller.
|
|
||||||
*/
|
|
||||||
setNavCtrl(navCtrl: NavController) : void {
|
|
||||||
this.navCtrl = navCtrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a confirm should be shown to open a SSO authentication.
|
* Check if a confirm should be shown to open a SSO authentication.
|
||||||
*
|
*
|
||||||
|
@ -976,7 +960,7 @@ export class CoreLoginHelperProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.navCtrl.setRoot('CoreLoginSitePolicyPage', {siteId: siteId});
|
this.appProvider.getRootNavController().setRoot('CoreLoginSitePolicyPage', {siteId: siteId});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Platform } from 'ionic-angular';
|
import { Platform, App, NavController } from 'ionic-angular';
|
||||||
import { Keyboard } from '@ionic-native/keyboard';
|
import { Keyboard } from '@ionic-native/keyboard';
|
||||||
import { Network } from '@ionic-native/network';
|
import { Network } from '@ionic-native/network';
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ export class CoreAppProvider {
|
||||||
ssoAuthenticationPromise : Promise<any>;
|
ssoAuthenticationPromise : Promise<any>;
|
||||||
isKeyboardShown: boolean = false;
|
isKeyboardShown: boolean = false;
|
||||||
|
|
||||||
constructor(dbProvider: CoreDbProvider, private platform: Platform, private keyboard: Keyboard,
|
constructor(dbProvider: CoreDbProvider, private platform: Platform, private keyboard: Keyboard, private appCtrl: App,
|
||||||
private network: Network, logger: CoreLoggerProvider) {
|
private network: Network, logger: CoreLoggerProvider) {
|
||||||
this.logger = logger.getInstance('CoreAppProvider');
|
this.logger = logger.getInstance('CoreAppProvider');
|
||||||
this.db = dbProvider.getDB(this.DBNAME);
|
this.db = dbProvider.getDB(this.DBNAME);
|
||||||
|
@ -76,7 +76,7 @@ export class CoreAppProvider {
|
||||||
*/
|
*/
|
||||||
canRecordMedia() : boolean {
|
canRecordMedia() : boolean {
|
||||||
return !!(<any>window).MediaRecorder;
|
return !!(<any>window).MediaRecorder;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the keyboard.
|
* Closes the keyboard.
|
||||||
|
@ -85,7 +85,7 @@ export class CoreAppProvider {
|
||||||
if (this.isMobile()) {
|
if (this.isMobile()) {
|
||||||
this.keyboard.close();
|
this.keyboard.close();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the application global database.
|
* Get the application global database.
|
||||||
|
@ -94,7 +94,17 @@ export class CoreAppProvider {
|
||||||
*/
|
*/
|
||||||
getDB() : SQLiteDB {
|
getDB() : SQLiteDB {
|
||||||
return this.db;
|
return this.db;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the app's root NavController.
|
||||||
|
*
|
||||||
|
* @return {NavController} Root NavController.
|
||||||
|
*/
|
||||||
|
getRootNavController() : NavController {
|
||||||
|
// getRootNav is deprecated. Get the first root nav, there should always be one.
|
||||||
|
return this.appCtrl.getRootNavs()[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the app is running in a desktop environment (not browser).
|
* Checks if the app is running in a desktop environment (not browser).
|
||||||
|
@ -104,7 +114,7 @@ export class CoreAppProvider {
|
||||||
isDesktop() : boolean {
|
isDesktop() : boolean {
|
||||||
let process = (<any>window).process;
|
let process = (<any>window).process;
|
||||||
return !!(process && process.versions && typeof process.versions.electron != 'undefined');
|
return !!(process && process.versions && typeof process.versions.electron != 'undefined');
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the keyboard is visible.
|
* Check if the keyboard is visible.
|
||||||
|
@ -113,7 +123,7 @@ export class CoreAppProvider {
|
||||||
*/
|
*/
|
||||||
isKeyboardVisible() : boolean {
|
isKeyboardVisible() : boolean {
|
||||||
return this.isKeyboardShown;
|
return this.isKeyboardShown;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the app is running in a Linux environment.
|
* Check if the app is running in a Linux environment.
|
||||||
|
@ -158,7 +168,7 @@ export class CoreAppProvider {
|
||||||
*/
|
*/
|
||||||
isMobile() : boolean {
|
isMobile() : boolean {
|
||||||
return this.platform.is('cordova');
|
return this.platform.is('cordova');
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether we are online.
|
* Returns whether we are online.
|
||||||
|
@ -172,7 +182,7 @@ export class CoreAppProvider {
|
||||||
online = true;
|
online = true;
|
||||||
}
|
}
|
||||||
return online;
|
return online;
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if device uses a limited connection.
|
* Check if device uses a limited connection.
|
||||||
|
@ -188,7 +198,7 @@ export class CoreAppProvider {
|
||||||
|
|
||||||
let limited = [Connection.CELL_2G, Connection.CELL_3G, Connection.CELL_4G, Connection.CELL];
|
let limited = [Connection.CELL_2G, Connection.CELL_3G, Connection.CELL_4G, Connection.CELL];
|
||||||
return limited.indexOf(type) > -1;
|
return limited.indexOf(type) > -1;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the app is running in a Windows environment.
|
* Check if the app is running in a Windows environment.
|
||||||
|
@ -216,7 +226,7 @@ export class CoreAppProvider {
|
||||||
if (this.isMobile() && !this.platform.is('ios')) {
|
if (this.isMobile() && !this.platform.is('ios')) {
|
||||||
this.keyboard.show();
|
this.keyboard.show();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start an SSO authentication process.
|
* Start an SSO authentication process.
|
||||||
|
@ -243,7 +253,7 @@ export class CoreAppProvider {
|
||||||
this.ssoAuthenticationPromise.then(() => {
|
this.ssoAuthenticationPromise.then(() => {
|
||||||
clearTimeout(cancelTimeout);
|
clearTimeout(cancelTimeout);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finish an SSO authentication process.
|
* Finish an SSO authentication process.
|
||||||
|
@ -253,7 +263,7 @@ export class CoreAppProvider {
|
||||||
(<any>this.ssoAuthenticationPromise).resolve && (<any>this.ssoAuthenticationPromise).resolve();
|
(<any>this.ssoAuthenticationPromise).resolve && (<any>this.ssoAuthenticationPromise).resolve();
|
||||||
this.ssoAuthenticationPromise = undefined;
|
this.ssoAuthenticationPromise = undefined;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there's an ongoing SSO authentication process.
|
* Check if there's an ongoing SSO authentication process.
|
||||||
|
@ -262,7 +272,7 @@ export class CoreAppProvider {
|
||||||
*/
|
*/
|
||||||
isSSOAuthenticationOngoing() : boolean {
|
isSSOAuthenticationOngoing() : boolean {
|
||||||
return !!this.ssoAuthenticationPromise;
|
return !!this.ssoAuthenticationPromise;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a promise that will be resolved once SSO authentication finishes.
|
* Returns a promise that will be resolved once SSO authentication finishes.
|
||||||
|
@ -271,7 +281,7 @@ export class CoreAppProvider {
|
||||||
*/
|
*/
|
||||||
waitForSSOAuthentication() : Promise<any> {
|
waitForSSOAuthentication() : Promise<any> {
|
||||||
return this.ssoAuthenticationPromise || Promise.resolve();
|
return this.ssoAuthenticationPromise || Promise.resolve();
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve redirect data.
|
* Retrieve redirect data.
|
||||||
|
@ -299,7 +309,7 @@ export class CoreAppProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store redirect params.
|
* Store redirect params.
|
||||||
|
@ -317,5 +327,5 @@ export class CoreAppProvider {
|
||||||
localStorage.setItem('mmCoreRedirectTime', String(Date.now()));
|
localStorage.setItem('mmCoreRedirectTime', String(Date.now()));
|
||||||
} catch(ex) {}
|
} catch(ex) {}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue