Merge pull request #3429 from NoelDeMartin/MOBILE-4081

MOBILE-4081 login: Allow customizing default image
main
Dani Palou 2022-11-03 09:49:30 +01:00 committed by GitHub
commit e1ad3e1b4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 14 deletions

View File

@ -21,7 +21,12 @@ import { CoreConfig } from '@services/config';
import { CoreSites, CoreSiteCheckResponse, CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites'; import { CoreSites, CoreSiteCheckResponse, CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreDomUtils } from '@services/utils/dom'; 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 { CoreSite } from '@classes/site';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
@ -60,7 +65,7 @@ export class CoreLoginSitePage implements OnInit {
searchFunction: (search: string) => void; searchFunction: (search: string) => void;
showScanQR: boolean; showScanQR: boolean;
enteredSiteUrl?: CoreLoginSiteInfoExtended; enteredSiteUrl?: CoreLoginSiteInfoExtended;
siteFinderSettings: SiteFinderSettings; siteFinderSettings: CoreLoginSiteFinderSettings;
constructor( constructor(
protected formBuilder: FormBuilder, protected formBuilder: FormBuilder,
@ -69,7 +74,7 @@ export class CoreLoginSitePage implements OnInit {
let url = ''; let url = '';
this.siteSelector = CoreConstants.CONFIG.multisitesdisplay; this.siteSelector = CoreConstants.CONFIG.multisitesdisplay;
const siteFinderSettings: Partial<SiteFinderSettings> = CoreConstants.CONFIG.sitefindersettings || {}; const siteFinderSettings: Partial<CoreLoginSiteFinderSettings> = CoreConstants.CONFIG.sitefindersettings || {};
this.siteFinderSettings = { this.siteFinderSettings = {
displaysitename: true, displaysitename: true,
displayimage: true, displayimage: true,
@ -177,6 +182,10 @@ export class CoreLoginSitePage implements OnInit {
// Separate location with hiphen if both country and city are present. // Separate location with hiphen if both country and city are present.
site.location = city && country ? city + ' - ' + country : city + country; site.location = city && country ? city + ' - ' + country : city + country;
if (CoreSites.hasDefaultImage(site) && this.siteFinderSettings.defaultimageurl) {
site.imageurl = this.siteFinderSettings.defaultimageurl;
}
return site; return site;
}); });
} }
@ -578,12 +587,3 @@ type CoreLoginSiteInfoExtended = CoreLoginSiteInfo & {
location: string; // City + country. location: string; // City + country.
title: string; // Name + alias. title: string; // Name + alias.
}; };
type SiteFinderSettings = {
displayalias: boolean;
displaycity: boolean;
displaycountry: boolean;
displayimage: boolean;
displaysitename: boolean;
displayurl: boolean;
};

View File

@ -1577,3 +1577,13 @@ export type CoreLoginMethod = {
icon: string; // Icon of the provider. icon: string; // Icon of the provider.
action: () => unknown; // Action to execute on button click. 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;
};

View File

@ -1818,6 +1818,17 @@ export class CoreSitesProvider {
return []; 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. * Migrate the legacy current_site table.
*/ */

View File

@ -16,7 +16,7 @@ import { CoreColorScheme, CoreZoomLevel } from '@features/settings/services/sett
import { CoreMainMenuLocalizedCustomItem } from '@features/mainmenu/services/mainmenu'; import { CoreMainMenuLocalizedCustomItem } from '@features/mainmenu/services/mainmenu';
import { CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites'; import { CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites';
import { OpenFileAction } from '@services/utils/utils'; 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 { CoreDatabaseConfiguration } from '@classes/database/database-table';
import { ToastDuration } from '@services/utils/dom'; import { ToastDuration } from '@services/utils/dom';
@ -45,7 +45,7 @@ export interface EnvironmentConfig {
siteurl: string | CoreLoginSiteInfo[]; siteurl: string | CoreLoginSiteInfo[];
sitename: string; sitename: string;
multisitesdisplay: CoreLoginSiteSelectorListMethod; multisitesdisplay: CoreLoginSiteSelectorListMethod;
sitefindersettings: Record<string, unknown>; sitefindersettings: Partial<CoreLoginSiteFinderSettings>;
onlyallowlistedsites: boolean; onlyallowlistedsites: boolean;
skipssoconfirmation: boolean; skipssoconfirmation: boolean;
forcedefaultlanguage: boolean; forcedefaultlanguage: boolean;