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 { 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<SiteFinderSettings> = CoreConstants.CONFIG.sitefindersettings || {};
const siteFinderSettings: Partial<CoreLoginSiteFinderSettings> = 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;
};

View File

@ -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;
};

View File

@ -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.
*/

View File

@ -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<string, unknown>;
sitefindersettings: Partial<CoreLoginSiteFinderSettings>;
onlyallowlistedsites: boolean;
skipssoconfirmation: boolean;
forcedefaultlanguage: boolean;