From 836e866443777da6b9f8c58530ad79b3ba08ad5a Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 22 Oct 2020 12:31:31 +0200 Subject: [PATCH] MOBILE-3320 config: Update old config references --- config/utils.js | 9 ++++--- .../pages/credentials/credentials.page.ts | 10 ++++---- src/app/core/login/pages/site/site.page.ts | 12 ++++----- src/app/core/login/services/helper.ts | 25 +++++++++---------- src/types/global.d.ts | 4 ++- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/config/utils.js b/config/utils.js index 00f16c041..e2d482c8f 100644 --- a/config/utils.js +++ b/config/utils.js @@ -15,7 +15,7 @@ const { execSync } = require('child_process'); const { resolve } = require('path'); -export function getConfig(environment) { +function getConfig(environment) { const { parse: parseJsonc } = require('jsonc-parser'); const { readFileSync, existsSync } = require('fs'); const envSuffixesMap = { @@ -38,11 +38,14 @@ export function getConfig(environment) { return config; } -export function getBuild(environment) { +function getBuild(environment) { return { - environment, isProduction: environment === 'production', + isTesting: environment === 'testing', + isDevelopment: environment === 'development', lastCommitHash: execSync('git log -1 --pretty=format:"%H"').toString(), compilationTime: Date.now(), }; } + +module.exports = { getConfig, getBuild }; diff --git a/src/app/core/login/pages/credentials/credentials.page.ts b/src/app/core/login/pages/credentials/credentials.page.ts index 6bb45942c..89ec65eaf 100644 --- a/src/app/core/login/pages/credentials/credentials.page.ts +++ b/src/app/core/login/pages/credentials/credentials.page.ts @@ -22,7 +22,7 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { CoreLoginHelper, CoreLoginHelperProvider } from '@core/login/services/helper'; -import CoreConfigConstants from '@app/config.json'; +import { CoreConstants } from '@/app/core/constants'; import { Translate } from '@singletons/core.singletons'; import { CoreSiteIdentityProvider, CoreSitePublicConfigResponse } from '@/app/classes/site'; import { CoreEvents, CoreEventsProvider } from '@/app/services/events'; @@ -66,10 +66,10 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { const canScanQR = CoreUtils.instance.canScanQR(); if (canScanQR) { - if (typeof CoreConfigConstants['displayqroncredentialscreen'] == 'undefined') { + if (typeof CoreConstants.CONFIG.displayqroncredentialscreen == 'undefined') { this.showScanQR = CoreLoginHelper.instance.isFixedUrlSet(); } else { - this.showScanQR = !!CoreConfigConstants['displayqroncredentialscreen']; + this.showScanQR = !!CoreConstants.CONFIG.displayqroncredentialscreen; } } else { this.showScanQR = false; @@ -83,7 +83,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { this.route.queryParams.subscribe(params => { this.siteUrl = params['siteUrl']; this.siteName = params['siteName'] || undefined; - this.logoUrl = !CoreConfigConstants.forceLoginLogo && params['logoUrl'] || undefined; + this.logoUrl = !CoreConstants.CONFIG.forceLoginLogo && params['logoUrl'] || undefined; this.siteConfig = params['siteConfig']; this.urlToOpen = params['urlToOpen']; @@ -160,7 +160,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { */ protected treatSiteConfig(): void { if (this.siteConfig) { - this.siteName = CoreConfigConstants.sitename ? CoreConfigConstants.sitename : this.siteConfig.sitename; + this.siteName = CoreConstants.CONFIG.sitename ?? this.siteConfig.sitename; this.logoUrl = CoreLoginHelper.instance.getLogoUrl(this.siteConfig); this.authInstructions = this.siteConfig.authinstructions || Translate.instance.instant('core.login.loginsteps'); diff --git a/src/app/core/login/pages/site/site.page.ts b/src/app/core/login/pages/site/site.page.ts index 783f77060..cfd05ec96 100644 --- a/src/app/core/login/pages/site/site.page.ts +++ b/src/app/core/login/pages/site/site.page.ts @@ -24,7 +24,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreLoginHelper, CoreLoginHelperProvider } from '@core/login/services/helper'; import { CoreSite } from '@classes/site'; import { CoreError } from '@classes/errors/error'; -import CoreConfigConstants from '@app/config.json'; +import { CoreConstants } from '@/app/core/constants'; import { Translate } from '@singletons/core.singletons'; import { CoreUrl } from '@singletons/url'; import { CoreUrlUtils } from '@/app/services/utils/url'; @@ -63,9 +63,9 @@ export class CoreLoginSitePage implements OnInit { ) { let url = ''; - this.siteSelector = CoreConfigConstants.multisitesdisplay; + this.siteSelector = CoreConstants.CONFIG.multisitesdisplay; - const siteFinderSettings: Partial = CoreConfigConstants['sitefindersettings'] || {}; + const siteFinderSettings: Partial = CoreConstants.CONFIG.sitefindersettings || {}; this.siteFinderSettings = { displaysitename: true, displayimage: true, @@ -79,12 +79,12 @@ export class CoreLoginSitePage implements OnInit { // Load fixed sites if they're set. if (CoreLoginHelper.instance.hasSeveralFixedSites()) { url = this.initSiteSelector(); - } else if (CoreConfigConstants.enableonboarding && !CoreApp.instance.isIOS() && !CoreApp.instance.isMac()) { + } else if (CoreConstants.CONFIG.enableonboarding && !CoreApp.instance.isIOS() && !CoreApp.instance.isMac()) { this.initOnboarding(); } - this.showScanQR = CoreUtils.instance.canScanQR() && (typeof CoreConfigConstants['displayqronsitescreen'] == 'undefined' || - !!CoreConfigConstants['displayqronsitescreen']); + this.showScanQR = CoreUtils.instance.canScanQR() && (typeof CoreConstants.CONFIG.displayqronsitescreen == 'undefined' || + !!CoreConstants.CONFIG.displayqronsitescreen); this.siteForm = this.formBuilder.group({ siteUrl: [url, this.moodleUrlValidator()], diff --git a/src/app/core/login/services/helper.ts b/src/app/core/login/services/helper.ts index c01d9caf8..02b8a2b1c 100644 --- a/src/app/core/login/services/helper.ts +++ b/src/app/core/login/services/helper.ts @@ -27,7 +27,6 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUrlParams, CoreUrlUtils } from '@services/utils/url'; import { CoreUtils } from '@services/utils/utils'; -import CoreConfigConstants from '@app/config.json'; import { CoreConstants } from '@core/constants'; import { CoreSite, CoreSiteConfig, CoreSiteIdentityProvider, CoreSitePublicConfigResponse } from '@classes/site'; import { CoreError } from '@classes/errors/error'; @@ -304,7 +303,7 @@ export class CoreLoginHelperProvider { * @return Logo URL. */ getLogoUrl(config: CoreSitePublicConfigResponse): string | undefined { - return !CoreConfigConstants.forceLoginLogo && config ? (config.logourl || config.compactlogourl) : undefined; + return !CoreConstants.CONFIG.forceLoginLogo && config ? (config.logourl || config.compactlogourl) : undefined; } /** @@ -368,7 +367,7 @@ export class CoreLoginHelperProvider { * @return Fixed site or list of fixed sites. */ getFixedSites(): string | CoreLoginSiteInfo[] { - return CoreConfigConstants.siteurl; + return CoreConstants.CONFIG.siteurl; } /** @@ -489,8 +488,8 @@ export class CoreLoginHelperProvider { * @return Whether there are several fixed URLs. */ hasSeveralFixedSites(): boolean { - return !!(CoreConfigConstants.siteurl && Array.isArray(CoreConfigConstants.siteurl) && - CoreConfigConstants.siteurl.length > 1); + return !!(CoreConstants.CONFIG.siteurl && Array.isArray(CoreConstants.CONFIG.siteurl) && + CoreConstants.CONFIG.siteurl.length > 1); } /** @@ -528,11 +527,11 @@ export class CoreLoginHelperProvider { * @return Whether there is 1 fixed URL. */ isFixedUrlSet(): boolean { - if (Array.isArray(CoreConfigConstants.siteurl)) { - return CoreConfigConstants.siteurl.length == 1; + if (Array.isArray(CoreConstants.CONFIG.siteurl)) { + return CoreConstants.CONFIG.siteurl.length == 1; } - return !!CoreConfigConstants.siteurl; + return !!CoreConstants.CONFIG.siteurl; } /** @@ -585,7 +584,7 @@ export class CoreLoginHelperProvider { const sites = this.getFixedSites(); return sites.some((site) => CoreUrl.sameDomainAndPath(siteUrl, site.url)); - } else if (CoreConfigConstants.multisitesdisplay == 'sitefinder' && CoreConfigConstants.onlyallowlistedsites) { + } else if (CoreConstants.CONFIG.multisitesdisplay == 'sitefinder' && CoreConstants.CONFIG.onlyallowlistedsites) { // Call the sites finder to validate the site. const result = await CoreSites.instance.findSites(siteUrl.replace(/^https?:\/\/|\.\w{2,3}\/?$/g, '')); @@ -852,14 +851,14 @@ export class CoreLoginHelperProvider { urlParams?: CoreUrlParams, ): string { - service = service || CoreConfigConstants.wsextservice; + service = service || CoreConstants.CONFIG.wsextservice; launchUrl = launchUrl || siteUrl + '/local/mobile/launch.php'; const passport = Math.random() * 1000; let loginUrl = launchUrl + '?service=' + service; loginUrl += '&passport=' + passport; - loginUrl += '&urlscheme=' + CoreConfigConstants.customurlscheme; + loginUrl += '&urlscheme=' + CoreConstants.CONFIG.customurlscheme; if (urlParams) { loginUrl = CoreUrlUtils.instance.addParamsToUrl(loginUrl, urlParams); @@ -1033,7 +1032,7 @@ export class CoreLoginHelperProvider { */ shouldShowSSOConfirm(typeOfLogin: number): boolean { return !this.isSSOEmbeddedBrowser(typeOfLogin) && - (!CoreConfigConstants.skipssoconfirmation || String(CoreConfigConstants.skipssoconfirmation) === 'false'); + (!CoreConstants.CONFIG.skipssoconfirmation || String(CoreConstants.CONFIG.skipssoconfirmation) === 'false'); } /** @@ -1053,7 +1052,7 @@ export class CoreLoginHelperProvider { * @param message The warning message. */ protected showMoodleAppNoticeModal(message: string): void { - const storesConfig: CoreStoreConfig = CoreConfigConstants.appstores; + const storesConfig: CoreStoreConfig = CoreConstants.CONFIG.appstores; storesConfig.desktop = 'https://download.moodle.org/desktop/'; storesConfig.mobile = 'https://download.moodle.org/mobile/'; storesConfig.default = 'https://download.moodle.org/mobile/'; diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 2e42b5cb4..82c412499 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -38,7 +38,7 @@ declare global { languages: Record; wsservice: string; wsextservice: string; - demo_sites: Record>; + demo_sites: Record; font_sizes: number[]; customurlscheme: string; siteurl: string; @@ -64,6 +64,8 @@ declare global { forceLoginLogo: boolean; ioswebviewscheme: string; appstores: Record; + displayqroncredentialscreen?: boolean; + displayqronsitescreen?: boolean; }; BUILD: {