mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
chore: Merge pull request 'feat(location): Make flag getter a part of server provider location object' (#238) from country-flag into master
Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/pulls/238 Reviewed-by: Inex Code <inex.code@selfprivacy.org>
This commit is contained in:
commit
c0dbf4454c
|
@ -36,6 +36,43 @@ class DigitalOceanLocation {
|
||||||
|
|
||||||
static DigitalOceanLocation fromJson(final Map<String, dynamic> json) =>
|
static DigitalOceanLocation fromJson(final Map<String, dynamic> json) =>
|
||||||
_$DigitalOceanLocationFromJson(json);
|
_$DigitalOceanLocationFromJson(json);
|
||||||
|
|
||||||
|
String get flag {
|
||||||
|
String emoji = '';
|
||||||
|
|
||||||
|
switch (slug.substring(0, 3)) {
|
||||||
|
case 'fra':
|
||||||
|
emoji = '🇩🇪';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'ams':
|
||||||
|
emoji = '🇳🇱';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'sgp':
|
||||||
|
emoji = '🇸🇬';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'lon':
|
||||||
|
emoji = '🇬🇧';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'tor':
|
||||||
|
emoji = '🇨🇦';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'blr':
|
||||||
|
emoji = '🇮🇳';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'nyc':
|
||||||
|
case 'sfo':
|
||||||
|
emoji = '🇺🇸';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return emoji;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
|
|
|
@ -135,6 +135,24 @@ class HetznerLocation {
|
||||||
|
|
||||||
static HetznerLocation fromJson(final Map<String, dynamic> json) =>
|
static HetznerLocation fromJson(final Map<String, dynamic> json) =>
|
||||||
_$HetznerLocationFromJson(json);
|
_$HetznerLocationFromJson(json);
|
||||||
|
|
||||||
|
String get flag {
|
||||||
|
String emoji = '';
|
||||||
|
switch (country.substring(0, 2)) {
|
||||||
|
case 'DE':
|
||||||
|
emoji = '🇩🇪';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'FI':
|
||||||
|
emoji = '🇫🇮';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'US':
|
||||||
|
emoji = '🇺🇸';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return emoji;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Volume is a highly-available, scalable, and SSD-based block storage for Servers.
|
/// A Volume is a highly-available, scalable, and SSD-based block storage for Servers.
|
||||||
|
|
|
@ -3,13 +3,11 @@ class ServerProviderLocation {
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.identifier,
|
required this.identifier,
|
||||||
this.description,
|
this.description,
|
||||||
this.flag,
|
this.flag = '',
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
final String identifier;
|
final String identifier;
|
||||||
final String? description;
|
final String? description;
|
||||||
|
final String flag;
|
||||||
/// as emoji
|
|
||||||
final String? flag;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,43 +293,6 @@ class DigitalOceanServerProvider extends ServerProvider {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
String? getEmojiFlag(final String query) {
|
|
||||||
String? emoji;
|
|
||||||
|
|
||||||
switch (query.toLowerCase().substring(0, 3)) {
|
|
||||||
case 'fra':
|
|
||||||
emoji = '🇩🇪';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'ams':
|
|
||||||
emoji = '🇳🇱';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sgp':
|
|
||||||
emoji = '🇸🇬';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'lon':
|
|
||||||
emoji = '🇬🇧';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'tor':
|
|
||||||
emoji = '🇨🇦';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'blr':
|
|
||||||
emoji = '🇮🇳';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'nyc':
|
|
||||||
case 'sfo':
|
|
||||||
emoji = '🇺🇸';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return emoji;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GenericResult<List<ServerProviderLocation>>>
|
Future<GenericResult<List<ServerProviderLocation>>>
|
||||||
getAvailableLocations() async {
|
getAvailableLocations() async {
|
||||||
|
@ -351,7 +314,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
||||||
location = ServerProviderLocation(
|
location = ServerProviderLocation(
|
||||||
title: rawLocation.slug,
|
title: rawLocation.slug,
|
||||||
description: rawLocation.name,
|
description: rawLocation.name,
|
||||||
flag: getEmojiFlag(rawLocation.slug),
|
flag: rawLocation.flag,
|
||||||
identifier: rawLocation.slug,
|
identifier: rawLocation.slug,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -662,8 +625,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
||||||
ServerMetadataEntity(
|
ServerMetadataEntity(
|
||||||
type: MetadataType.location,
|
type: MetadataType.location,
|
||||||
trId: 'server.location',
|
trId: 'server.location',
|
||||||
value:
|
value: '${droplet['region']['name']}',
|
||||||
'${droplet['region']['name']} ${getEmojiFlag(droplet['region']['slug'].toString()) ?? ''}',
|
|
||||||
),
|
),
|
||||||
ServerMetadataEntity(
|
ServerMetadataEntity(
|
||||||
type: MetadataType.other,
|
type: MetadataType.other,
|
||||||
|
|
|
@ -335,26 +335,6 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String? getEmojiFlag(final String query) {
|
|
||||||
String? emoji;
|
|
||||||
|
|
||||||
switch (query.toLowerCase()) {
|
|
||||||
case 'de':
|
|
||||||
emoji = '🇩🇪';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'fi':
|
|
||||||
emoji = '🇫🇮';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'us':
|
|
||||||
emoji = '🇺🇸';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return emoji;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GenericResult<bool>> trySetServerLocation(
|
Future<GenericResult<bool>> trySetServerLocation(
|
||||||
final String location,
|
final String location,
|
||||||
|
@ -396,7 +376,7 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
location = ServerProviderLocation(
|
location = ServerProviderLocation(
|
||||||
title: rawLocation.city,
|
title: rawLocation.city,
|
||||||
description: rawLocation.description,
|
description: rawLocation.description,
|
||||||
flag: getEmojiFlag(rawLocation.country),
|
flag: rawLocation.flag,
|
||||||
identifier: rawLocation.name,
|
identifier: rawLocation.name,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -107,7 +107,7 @@ class SelectLocationPage extends StatelessWidget {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'${location.flag ?? ''} ${location.title}',
|
'${location.flag} ${location.title}',
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.titleMedium,
|
.titleMedium,
|
||||||
|
|
Loading…
Reference in a new issue