Skip to content

Commit fd9b79a

Browse files
authored
Merge pull request #2526 from NoelDeMartin/MOBILE-3523
MOBILE-3523 login: Move login checks and modals to providers
2 parents 471048d + 793e029 commit fd9b79a

File tree

4 files changed

+65
-54
lines changed

4 files changed

+65
-54
lines changed

src/core/login/pages/site/site.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export class CoreLoginSitePage {
335335
* @return Promise resolved after logging in.
336336
*/
337337
protected async login(response: CoreSiteCheckResponse, foundSite?: CoreLoginSiteInfoExtended): Promise<void> {
338-
return this.sitesProvider.checkRequiredMinimumVersion(response.config).then(() => {
338+
return this.sitesProvider.checkApplication(response).then(() => {
339339

340340
this.domUtils.triggerFormSubmittedEvent(this.formElement, true);
341341

src/core/login/providers/helper.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import { Injectable } from '@angular/core';
1616
import { Location } from '@angular/common';
17-
import { AlertController, NavController, NavOptions } from 'ionic-angular';
17+
import { NavController, NavOptions } from 'ionic-angular';
1818
import { TranslateService } from '@ngx-translate/core';
1919
import { CoreApp, CoreStoreConfig } from '@providers/app';
2020
import { CoreConfigProvider } from '@providers/config';
@@ -101,7 +101,6 @@ export class CoreLoginHelperProvider {
101101
private initDelegate: CoreInitDelegate,
102102
private sitePluginsProvider: CoreSitePluginsProvider,
103103
private location: Location,
104-
private alertCtrl: AlertController,
105104
private courseProvider: CoreCourseProvider
106105
) {
107106
this.logger = logger.getInstance('CoreLoginHelper');
@@ -1235,7 +1234,7 @@ export class CoreLoginHelperProvider {
12351234
protected showWorkplaceNoticeModal(message: string): void {
12361235
const link = CoreApp.instance.getAppStoreUrl({android: 'com.moodle.workplace', ios: 'id1470929705' });
12371236

1238-
this.showDownloadAppNoticeModal(message, link);
1237+
this.domUtils.showDownloadAppNoticeModal(message, link);
12391238
}
12401239

12411240
/**
@@ -1251,45 +1250,7 @@ export class CoreLoginHelperProvider {
12511250

12521251
const link = CoreApp.instance.getAppStoreUrl(storesConfig);
12531252

1254-
this.showDownloadAppNoticeModal(message, link);
1255-
}
1256-
1257-
/**
1258-
* Show a modal warning the user that he should use a different app.
1259-
*
1260-
* @param message The warning message.
1261-
* @param link Link to the app to download if any.
1262-
*/
1263-
protected showDownloadAppNoticeModal(message: string, link?: string): void {
1264-
const buttons: any[] = [
1265-
{
1266-
text: this.translate.instant('core.ok'),
1267-
role: 'cancel'
1268-
}
1269-
];
1270-
1271-
if (link) {
1272-
buttons.push({
1273-
text: this.translate.instant('core.download'),
1274-
handler: (): void => {
1275-
this.utils.openInBrowser(link);
1276-
}
1277-
});
1278-
}
1279-
1280-
const alert = this.alertCtrl.create({
1281-
message: message,
1282-
buttons: buttons
1283-
});
1284-
1285-
alert.present().then(() => {
1286-
const isDevice = CoreApp.instance.isAndroid() || CoreApp.instance.isIOS();
1287-
if (!isDevice) {
1288-
// Treat all anchors so they don't override the app.
1289-
const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message');
1290-
this.domUtils.treatAnchors(alertMessageEl);
1291-
}
1292-
});
1253+
this.domUtils.showDownloadAppNoticeModal(message, link);
12931254
}
12941255

12951256
/**

src/providers/sites.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,15 @@ export class CoreSitesProvider {
10231023
return this.appDB.insertRecord(CoreSitesProvider.SITES_TABLE, entry);
10241024
}
10251025

1026+
/**
1027+
* Check the app for a site and show a download dialogs if necessary.
1028+
*
1029+
* @param response Data obtained during site check.
1030+
*/
1031+
async checkApplication(response: CoreSiteCheckResponse): Promise<void> {
1032+
await this.checkRequiredMinimumVersion(response.config);
1033+
}
1034+
10261035
/**
10271036
* Check the required minimum version of the app for a site and shows a download dialog.
10281037
*

src/providers/utils/dom.ts

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,42 @@ export class CoreDomUtilsProvider {
14021402
return loader;
14031403
}
14041404

1405+
/**
1406+
* Show a modal warning the user that he should use a different app.
1407+
*
1408+
* @param message The warning message.
1409+
* @param link Link to the app to download if any.
1410+
*/
1411+
showDownloadAppNoticeModal(message: string, link?: string): void {
1412+
const buttons: any[] = [{
1413+
text: this.translate.instant('core.ok'),
1414+
role: 'cancel'
1415+
}];
1416+
1417+
if (link) {
1418+
buttons.push({
1419+
text: this.translate.instant('core.download'),
1420+
handler: (): void => {
1421+
this.openInBrowser(link);
1422+
}
1423+
});
1424+
}
1425+
1426+
const alert = this.alertCtrl.create({
1427+
message: message,
1428+
buttons: buttons
1429+
});
1430+
1431+
alert.present().then(() => {
1432+
const isDevice = CoreApp.instance.isAndroid() || CoreApp.instance.isIOS();
1433+
if (!isDevice) {
1434+
// Treat all anchors so they don't override the app.
1435+
const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message');
1436+
this.treatAnchors(alertMessageEl);
1437+
}
1438+
});
1439+
}
1440+
14051441
/**
14061442
* Show a prompt modal to input some data.
14071443
*
@@ -1559,17 +1595,7 @@ export class CoreDomUtilsProvider {
15591595
event.preventDefault();
15601596
event.stopPropagation();
15611597

1562-
// We cannot use CoreDomUtilsProvider.openInBrowser due to circular dependencies.
1563-
if (CoreApp.instance.isDesktop()) {
1564-
// It's a desktop app, use Electron shell library to open the browser.
1565-
const shell = require('electron').shell;
1566-
if (!shell.openExternal(href)) {
1567-
// Open browser failed, open a new window in the app.
1568-
window.open(href, '_system');
1569-
}
1570-
} else {
1571-
window.open(href, '_system');
1572-
}
1598+
this.openInBrowser(href);
15731599
}
15741600
});
15751601
});
@@ -1680,6 +1706,21 @@ export class CoreDomUtilsProvider {
16801706
online: !!online,
16811707
}, siteId);
16821708
}
1709+
1710+
// We cannot use CoreUtilsProvider.openInBrowser due to circular dependencies.
1711+
protected openInBrowser(url: string): void {
1712+
if (CoreApp.instance.isDesktop()) {
1713+
// It's a desktop app, use Electron shell library to open the browser.
1714+
const shell = require('electron').shell;
1715+
if (!shell.openExternal(url)) {
1716+
// Open browser failed, open a new window in the app.
1717+
window.open(url, '_system');
1718+
}
1719+
} else {
1720+
window.open(url, '_system');
1721+
}
1722+
}
1723+
16831724
}
16841725

16851726
export class CoreDomUtils extends makeSingleton(CoreDomUtilsProvider) {}

0 commit comments

Comments
 (0)