diff --git a/src/config.json b/src/config.json index 5d4d3f040..b88e12177 100644 --- a/src/config.json +++ b/src/config.json @@ -81,6 +81,7 @@ "siteurl": "", "sitename": "", "multisitesdisplay": "", + "sitefindersettings": {}, "onlyallowlistedsites": false, "skipssoconfirmation": false, "forcedefaultlanguage": false, diff --git a/src/core/login/pages/site/site.html b/src/core/login/pages/site/site.html index 206a04603..54203d58e 100644 --- a/src/core/login/pages/site/site.html +++ b/src/core/login/pages/site/site.html @@ -14,77 +14,72 @@ -
+ - - - -

{{ 'core.login.siteaddress' | translate }}

- -
-
- - -

{{ 'core.login.siteaddress' | translate }}

- -
+ + +

{{ 'core.login.siteaddress' | translate }}

+ +
+
+ + +

{{ 'core.login.siteaddress' | translate }}

+ +
- - - - - -
+
- - - {{ 'core.login.selectsite' | translate }} - - {{site.name}} - - - - + - +

{{ 'core.login.selectsite' | translate }}

- -

{{site.name}}

-

{{site.url}}

+ + + + + +

{{site.title}}

+

{{site.noProtocolUrl}}

+

{{site.location}}

{{ 'core.login.selectsite' | translate }}

- {{site.name}} + {{site.title}}
diff --git a/src/core/login/pages/site/site.ts b/src/core/login/pages/site/site.ts index 68b1c6142..4c734d1e6 100644 --- a/src/core/login/pages/site/site.ts +++ b/src/core/login/pages/site/site.ts @@ -35,7 +35,17 @@ import { TranslateService } from '@ngx-translate/core'; */ type CoreLoginSiteInfoExtended = CoreLoginSiteInfo & { noProtocolUrl?: string; // Url wihtout protocol. - country?: string; // Based on countrycode. + location?: string; // City + country. + title?: string; // Name + alias. +}; + +type SiteFinderSettings = { + displayalias: boolean, + displaycity: boolean, + displaycountry: boolean, + displayimage: boolean, + displaysitename: boolean, + displayurl: boolean }; /** @@ -51,8 +61,8 @@ export class CoreLoginSitePage { @ViewChild('siteFormEl') formElement: ElementRef; siteForm: FormGroup; - fixedSites: CoreLoginSiteInfo[]; - filteredSites: CoreLoginSiteInfo[]; + fixedSites: CoreLoginSiteInfoExtended[]; + filteredSites: CoreLoginSiteInfoExtended[]; siteSelector = 'sitefinder'; showKeyboard = false; filter = ''; @@ -62,6 +72,7 @@ export class CoreLoginSitePage { searchFnc: Function; showScanQR: boolean; enteredSiteUrl: CoreLoginSiteInfoExtended; + siteFinderSettings: SiteFinderSettings; constructor(navParams: NavParams, protected navCtrl: NavController, @@ -84,13 +95,37 @@ export class CoreLoginSitePage { let url = ''; this.siteSelector = CoreConfigConstants.multisitesdisplay; + const siteFinderSettings: Partial = CoreConfigConstants['sitefindersettings'] || {}; + this.siteFinderSettings = { + displaysitename: true, + displayimage: true, + displayalias: true, + displaycity: true, + displaycountry: true, + displayurl: true, + ...siteFinderSettings + }; + // Load fixed sites if they're set. if (this.loginHelper.hasSeveralFixedSites()) { - this.fixedSites = this.loginHelper.getFixedSites(); - // Autoselect if not defined. - if (['list', 'listnourl', 'select', 'buttons'].indexOf(this.siteSelector) < 0) { - this.siteSelector = this.fixedSites.length > 8 ? 'list' : (this.fixedSites.length > 3 ? 'select' : 'buttons'); + // Deprecate listnourl on 3.9.3, remove this block on the following release. + if (this.siteSelector == 'listnourl') { + this.siteSelector = 'list'; + this.siteFinderSettings.displayurl = false; } + + this.fixedSites = this.extendCoreLoginSiteInfo( this.loginHelper.getFixedSites()); + + // Do not show images if none are set. + if (!this.fixedSites.some((site) => !!site.imageurl)) { + this.siteFinderSettings.displayimage = false; + } + + // Autoselect if not defined. + if (this.siteSelector != 'list' && this.siteSelector != 'buttons') { + this.siteSelector = this.fixedSites.length > 3 ? 'list' : 'buttons'; + } + this.filteredSites = this.fixedSites; url = this.fixedSites[0].url; } else if (CoreConfigConstants.enableonboarding && !this.appProvider.isIOS() && !this.appProvider.isMac()) { @@ -116,11 +151,8 @@ export class CoreLoginSitePage { // Update the sites list. this.sites = await this.sitesProvider.findSites(search); - // UI tweaks. - this.sites.forEach((site) => { - site.noProtocolUrl = CoreUrl.removeProtocol(site.url); - site.country = this.utils.getCountryName(site.countrycode); - }); + // Add UI tweaks. + this.sites = this.extendCoreLoginSiteInfo(this.sites); this.hasSites = !!this.sites.length; } else { @@ -132,6 +164,34 @@ export class CoreLoginSitePage { }, 1000); } + /** + * Extend info of Login Site Info to get UI tweaks. + * + * @param sites Sites list. + * @return Sites list with extended info. + */ + protected extendCoreLoginSiteInfo(sites: CoreLoginSiteInfoExtended[]): CoreLoginSiteInfoExtended[] { + return sites.map((site) => { + site.noProtocolUrl = this.siteFinderSettings.displayurl && site.url ? CoreUrl.removeProtocol(site.url) : ''; + + const name = this.siteFinderSettings.displaysitename ? site.name : ''; + const alias = this.siteFinderSettings.displayalias && site.alias ? site.alias : ''; + + // Set title with parenthesis if both name and alias are present. + site.title = name && alias ? name + ' (' + alias + ')' : name + alias; + + const country = this.siteFinderSettings.displaycountry && site.countrycode ? + this.utils.getCountryName(site.countrycode) : ''; + const city = this.siteFinderSettings.displaycity && site.city ? + site.city : ''; + + // Separate location with hiphen if both country and city are present. + site.location = city && country ? city + ' - ' + country : city + country; + + return site; + }); + } + /** * Try to connect to a site. * @@ -224,7 +284,8 @@ export class CoreLoginSitePage { this.filteredSites = this.fixedSites; } else { this.filteredSites = this.fixedSites.filter((site) => { - return site.name.toLowerCase().indexOf(newValue) > -1 || site.url.toLowerCase().indexOf(newValue) > -1; + return site.title.toLowerCase().indexOf(newValue) > -1 || site.noProtocolUrl.toLowerCase().indexOf(newValue) > -1 || + site.location.toLowerCase().indexOf(newValue) > -1; }); } } diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index 9e5ea3630..7c1857924 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -21,7 +21,7 @@ import { CoreConfigProvider } from '@providers/config'; import { CoreEventsProvider } from '@providers/events'; import { CoreInitDelegate } from '@providers/init'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreLoginSiteInfo } from '@providers/sites'; import { CoreWSProvider } from '@providers/ws'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreTextUtilsProvider } from '@providers/utils/text'; @@ -464,7 +464,7 @@ export class CoreLoginHelperProvider { * * @return Fixed site or list of fixed sites. */ - getFixedSites(): string | any[] { + getFixedSites(): string | CoreLoginSiteInfo[] { return CoreConfigConstants.siteurl; }