Merge pull request #2104 from crazyserver/MOBILE-3091

MOBILE-3091 signup: Sort countries by name
main
Juan Leyva 2019-10-01 11:17:32 +02:00 committed by GitHub
commit fc41cbf29f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -31,7 +31,7 @@
<ion-label stacked core-mark-required="true">{{ 'core.wheredoyoulive' | translate }}</ion-label> <ion-label stacked core-mark-required="true">{{ 'core.wheredoyoulive' | translate }}</ion-label>
<ion-select name="country" formControlName="country" [placeholder]="'core.login.selectacountry' | translate"> <ion-select name="country" formControlName="country" [placeholder]="'core.login.selectacountry' | translate">
<ion-option value="">{{ 'core.login.selectacountry' | translate }}</ion-option> <ion-option value="">{{ 'core.login.selectacountry' | translate }}</ion-option>
<ion-option *ngFor="let key of countriesKeys" [value]="key">{{countries[key]}}</ion-option> <ion-option *ngFor="let country of countries" [value]="country.code">{{country.name}}</ion-option>
</ion-select> </ion-select>
</ion-item> </ion-item>
@ -103,7 +103,7 @@
<ion-label stacked id="core-login-signup-country">{{ 'core.user.country' | translate }}</ion-label> <ion-label stacked id="core-login-signup-country">{{ 'core.user.country' | translate }}</ion-label>
<ion-select name="country" formControlName="country" aria-labelledby="core-login-signup-country" [placeholder]="'core.login.selectacountry' | translate"> <ion-select name="country" formControlName="country" aria-labelledby="core-login-signup-country" [placeholder]="'core.login.selectacountry' | translate">
<ion-option value="">{{ 'core.login.selectacountry' | translate }}</ion-option> <ion-option value="">{{ 'core.login.selectacountry' | translate }}</ion-option>
<ion-option *ngFor="let key of countriesKeys" [value]="key">{{countries[key]}}</ion-option> <ion-option *ngFor="let country of countries" [value]="country.code">{{country.name}}</ion-option>
</ion-select> </ion-select>
</ion-item> </ion-item>

View File

@ -43,7 +43,6 @@ export class CoreLoginEmailSignupPage {
authInstructions: string; authInstructions: string;
settings: any; settings: any;
countries: any; countries: any;
countriesKeys: any[];
categories: any[]; categories: any[];
settingsLoaded = false; settingsLoaded = false;
captcha = { captcha = {
@ -177,9 +176,8 @@ export class CoreLoginEmailSignupPage {
}); });
} }
return this.utils.getCountryList().then((countries) => { return this.utils.getCountryListSorted().then((countries) => {
this.countries = countries; this.countries = countries;
this.countriesKeys = Object.keys(countries);
}); });
}); });
} }

View File

@ -623,6 +623,25 @@ export class CoreUtilsProvider {
}); });
} }
/**
* Get list of countries with their code and translated name. Sorted by the name of the country.
*
* @return Promise resolved with the list of countries.
*/
getCountryListSorted(): Promise<any[]> {
// Get the keys of the countries.
return this.getCountryList().then((countries) => {
// Sort translations.
const sortedCountries = [];
Object.keys(countries).sort((a, b) => countries[a].localeCompare(countries[b])).forEach((key) => {
sortedCountries.push({code: key, name: countries[key]});
});
return sortedCountries;
});
}
/** /**
* Get the list of language keys of the countries. * Get the list of language keys of the countries.
* *