From 08f2683a6b8c13d0315cae266c1975f4238d4c9b Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 2 Nov 2022 13:06:58 +0100 Subject: [PATCH] MOBILE-4081 login: Allow customizing default image --- src/core/features/login/pages/site/site.ts | 24 +++++++++---------- .../features/login/services/login-helper.ts | 10 ++++++++ src/core/services/sites.ts | 11 +++++++++ src/types/config.d.ts | 4 ++-- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/core/features/login/pages/site/site.ts b/src/core/features/login/pages/site/site.ts index bd7df5d05..9d900b2f2 100644 --- a/src/core/features/login/pages/site/site.ts +++ b/src/core/features/login/pages/site/site.ts @@ -21,7 +21,12 @@ import { CoreConfig } from '@services/config'; import { CoreSites, CoreSiteCheckResponse, CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreLoginHelper, CoreLoginHelperProvider, CoreLoginSiteSelectorListMethod } from '@features/login/services/login-helper'; +import { + CoreLoginHelper, + CoreLoginHelperProvider, + CoreLoginSiteFinderSettings, + CoreLoginSiteSelectorListMethod, +} from '@features/login/services/login-helper'; import { CoreSite } from '@classes/site'; import { CoreError } from '@classes/errors/error'; import { CoreConstants } from '@/core/constants'; @@ -60,7 +65,7 @@ export class CoreLoginSitePage implements OnInit { searchFunction: (search: string) => void; showScanQR: boolean; enteredSiteUrl?: CoreLoginSiteInfoExtended; - siteFinderSettings: SiteFinderSettings; + siteFinderSettings: CoreLoginSiteFinderSettings; constructor( protected formBuilder: FormBuilder, @@ -69,7 +74,7 @@ export class CoreLoginSitePage implements OnInit { let url = ''; this.siteSelector = CoreConstants.CONFIG.multisitesdisplay; - const siteFinderSettings: Partial = CoreConstants.CONFIG.sitefindersettings || {}; + const siteFinderSettings: Partial = CoreConstants.CONFIG.sitefindersettings || {}; this.siteFinderSettings = { displaysitename: true, displayimage: true, @@ -177,6 +182,10 @@ export class CoreLoginSitePage implements OnInit { // Separate location with hiphen if both country and city are present. site.location = city && country ? city + ' - ' + country : city + country; + if (CoreSites.hasDefaultImage(site) && this.siteFinderSettings.defaultimageurl) { + site.imageurl = this.siteFinderSettings.defaultimageurl; + } + return site; }); } @@ -578,12 +587,3 @@ type CoreLoginSiteInfoExtended = CoreLoginSiteInfo & { location: string; // City + country. title: string; // Name + alias. }; - -type SiteFinderSettings = { - displayalias: boolean; - displaycity: boolean; - displaycountry: boolean; - displayimage: boolean; - displaysitename: boolean; - displayurl: boolean; -}; diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index 688b82138..a2e14d6fb 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -1577,3 +1577,13 @@ export type CoreLoginMethod = { icon: string; // Icon of the provider. action: () => unknown; // Action to execute on button click. }; + +export type CoreLoginSiteFinderSettings = { + displayalias: boolean; + displaycity: boolean; + displaycountry: boolean; + displayimage: boolean; + displaysitename: boolean; + displayurl: boolean; + defaultimageurl?: string; +}; diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index 7217ef250..c6d56dffd 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -1818,6 +1818,17 @@ export class CoreSitesProvider { return []; } + /** + * Check whether a site is using a default image or not. + * + * @param site Site info. + * @returns Whether the site is using a default image. + */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + hasDefaultImage(site: CoreLoginSiteInfo): boolean { + return false; + } + /** * Migrate the legacy current_site table. */ diff --git a/src/types/config.d.ts b/src/types/config.d.ts index ceb4bb32c..a3b66651b 100644 --- a/src/types/config.d.ts +++ b/src/types/config.d.ts @@ -16,7 +16,7 @@ import { CoreColorScheme, CoreZoomLevel } from '@features/settings/services/sett import { CoreMainMenuLocalizedCustomItem } from '@features/mainmenu/services/mainmenu'; import { CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites'; import { OpenFileAction } from '@services/utils/utils'; -import { CoreLoginSiteSelectorListMethod } from '@features/login/services/login-helper'; +import { CoreLoginSiteFinderSettings, CoreLoginSiteSelectorListMethod } from '@features/login/services/login-helper'; import { CoreDatabaseConfiguration } from '@classes/database/database-table'; import { ToastDuration } from '@services/utils/dom'; @@ -45,7 +45,7 @@ export interface EnvironmentConfig { siteurl: string | CoreLoginSiteInfo[]; sitename: string; multisitesdisplay: CoreLoginSiteSelectorListMethod; - sitefindersettings: Record; + sitefindersettings: Partial; onlyallowlistedsites: boolean; skipssoconfirmation: boolean; forcedefaultlanguage: boolean;