Merge pull request #2526 from NoelDeMartin/MOBILE-3523

MOBILE-3523 login: Move login checks and modals to providers
main
Juan Leyva 2020-09-17 15:24:32 +02:00 committed by GitHub
commit fd9b79a39f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 54 deletions

View File

@ -335,7 +335,7 @@ export class CoreLoginSitePage {
* @return Promise resolved after logging in. * @return Promise resolved after logging in.
*/ */
protected async login(response: CoreSiteCheckResponse, foundSite?: CoreLoginSiteInfoExtended): Promise<void> { protected async login(response: CoreSiteCheckResponse, foundSite?: CoreLoginSiteInfoExtended): Promise<void> {
return this.sitesProvider.checkRequiredMinimumVersion(response.config).then(() => { return this.sitesProvider.checkApplication(response).then(() => {
this.domUtils.triggerFormSubmittedEvent(this.formElement, true); this.domUtils.triggerFormSubmittedEvent(this.formElement, true);

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { AlertController, NavController, NavOptions } from 'ionic-angular'; import { NavController, NavOptions } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { CoreApp, CoreStoreConfig } from '@providers/app'; import { CoreApp, CoreStoreConfig } from '@providers/app';
import { CoreConfigProvider } from '@providers/config'; import { CoreConfigProvider } from '@providers/config';
@ -101,7 +101,6 @@ export class CoreLoginHelperProvider {
private initDelegate: CoreInitDelegate, private initDelegate: CoreInitDelegate,
private sitePluginsProvider: CoreSitePluginsProvider, private sitePluginsProvider: CoreSitePluginsProvider,
private location: Location, private location: Location,
private alertCtrl: AlertController,
private courseProvider: CoreCourseProvider private courseProvider: CoreCourseProvider
) { ) {
this.logger = logger.getInstance('CoreLoginHelper'); this.logger = logger.getInstance('CoreLoginHelper');
@ -1235,7 +1234,7 @@ export class CoreLoginHelperProvider {
protected showWorkplaceNoticeModal(message: string): void { protected showWorkplaceNoticeModal(message: string): void {
const link = CoreApp.instance.getAppStoreUrl({android: 'com.moodle.workplace', ios: 'id1470929705' }); const link = CoreApp.instance.getAppStoreUrl({android: 'com.moodle.workplace', ios: 'id1470929705' });
this.showDownloadAppNoticeModal(message, link); this.domUtils.showDownloadAppNoticeModal(message, link);
} }
/** /**
@ -1251,45 +1250,7 @@ export class CoreLoginHelperProvider {
const link = CoreApp.instance.getAppStoreUrl(storesConfig); const link = CoreApp.instance.getAppStoreUrl(storesConfig);
this.showDownloadAppNoticeModal(message, link); this.domUtils.showDownloadAppNoticeModal(message, link);
}
/**
* Show a modal warning the user that he should use a different app.
*
* @param message The warning message.
* @param link Link to the app to download if any.
*/
protected showDownloadAppNoticeModal(message: string, link?: string): void {
const buttons: any[] = [
{
text: this.translate.instant('core.ok'),
role: 'cancel'
}
];
if (link) {
buttons.push({
text: this.translate.instant('core.download'),
handler: (): void => {
this.utils.openInBrowser(link);
}
});
}
const alert = this.alertCtrl.create({
message: message,
buttons: buttons
});
alert.present().then(() => {
const isDevice = CoreApp.instance.isAndroid() || CoreApp.instance.isIOS();
if (!isDevice) {
// Treat all anchors so they don't override the app.
const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message');
this.domUtils.treatAnchors(alertMessageEl);
}
});
} }
/** /**

View File

@ -1023,6 +1023,15 @@ export class CoreSitesProvider {
return this.appDB.insertRecord(CoreSitesProvider.SITES_TABLE, entry); return this.appDB.insertRecord(CoreSitesProvider.SITES_TABLE, entry);
} }
/**
* Check the app for a site and show a download dialogs if necessary.
*
* @param response Data obtained during site check.
*/
async checkApplication(response: CoreSiteCheckResponse): Promise<void> {
await this.checkRequiredMinimumVersion(response.config);
}
/** /**
* Check the required minimum version of the app for a site and shows a download dialog. * Check the required minimum version of the app for a site and shows a download dialog.
* *

View File

@ -1402,6 +1402,42 @@ export class CoreDomUtilsProvider {
return loader; return loader;
} }
/**
* Show a modal warning the user that he should use a different app.
*
* @param message The warning message.
* @param link Link to the app to download if any.
*/
showDownloadAppNoticeModal(message: string, link?: string): void {
const buttons: any[] = [{
text: this.translate.instant('core.ok'),
role: 'cancel'
}];
if (link) {
buttons.push({
text: this.translate.instant('core.download'),
handler: (): void => {
this.openInBrowser(link);
}
});
}
const alert = this.alertCtrl.create({
message: message,
buttons: buttons
});
alert.present().then(() => {
const isDevice = CoreApp.instance.isAndroid() || CoreApp.instance.isIOS();
if (!isDevice) {
// Treat all anchors so they don't override the app.
const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message');
this.treatAnchors(alertMessageEl);
}
});
}
/** /**
* Show a prompt modal to input some data. * Show a prompt modal to input some data.
* *
@ -1559,17 +1595,7 @@ export class CoreDomUtilsProvider {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
// We cannot use CoreDomUtilsProvider.openInBrowser due to circular dependencies. this.openInBrowser(href);
if (CoreApp.instance.isDesktop()) {
// It's a desktop app, use Electron shell library to open the browser.
const shell = require('electron').shell;
if (!shell.openExternal(href)) {
// Open browser failed, open a new window in the app.
window.open(href, '_system');
}
} else {
window.open(href, '_system');
}
} }
}); });
}); });
@ -1680,6 +1706,21 @@ export class CoreDomUtilsProvider {
online: !!online, online: !!online,
}, siteId); }, siteId);
} }
// We cannot use CoreUtilsProvider.openInBrowser due to circular dependencies.
protected openInBrowser(url: string): void {
if (CoreApp.instance.isDesktop()) {
// It's a desktop app, use Electron shell library to open the browser.
const shell = require('electron').shell;
if (!shell.openExternal(url)) {
// Open browser failed, open a new window in the app.
window.open(url, '_system');
}
} else {
window.open(url, '_system');
}
}
} }
export class CoreDomUtils extends makeSingleton(CoreDomUtilsProvider) {} export class CoreDomUtils extends makeSingleton(CoreDomUtilsProvider) {}