chore: support more number format

This commit is contained in:
appflowy 2022-05-01 23:11:44 +08:00
parent 5c4a681909
commit cf05d7da41
8 changed files with 483 additions and 66 deletions

View File

@ -6,6 +6,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flowy_sdk/log.dart';
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show Field;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@ -29,11 +30,12 @@ class FieldEditor extends FlowyOverlayDelegate {
BuildContext context, {
AnchorDirection anchorDirection = AnchorDirection.bottomWithLeftAligned,
}) {
Log.trace("Show $identifier()");
FlowyOverlay.of(context).remove(identifier());
FlowyOverlay.of(context).insertWithAnchor(
widget: OverlayContainer(
child: _FieldEditorWidget(_fieldEditorBloc, fieldContextLoader),
constraints: BoxConstraints.loose(const Size(220, 400)),
constraints: BoxConstraints.loose(const Size(280, 400)),
),
identifier: identifier(),
anchorContext: context,
@ -68,7 +70,7 @@ class _FieldEditorWidget extends StatelessWidget {
child: BlocBuilder<FieldEditorBloc, FieldEditorState>(
builder: (context, state) {
return state.field.fold(
() => const SizedBox(width: 200),
() => const SizedBox(),
(field) => ListView(
shrinkWrap: true,
children: [

View File

@ -146,7 +146,7 @@ class _FieldSwitcherState extends State<FieldSwitcher> {
FlowyOverlay.of(context).insertWithAnchor(
widget: OverlayContainer(
child: child,
constraints: BoxConstraints.loose(const Size(340, 400)),
constraints: BoxConstraints.loose(const Size(460, 440)),
),
identifier: identifier,
anchorContext: context,

View File

@ -50,13 +50,23 @@ class NumberTypeOptionWidget extends TypeOptionWidget {
listener: (context, state) => dataDelegate.didUpdateTypeOptionData(state.typeOption.writeToBuffer()),
builder: (context, state) {
return FlowyButton(
text: FlowyText.medium(LocaleKeys.grid_field_numberFormat.tr(), fontSize: 12),
text: Row(
children: [
FlowyText.medium(LocaleKeys.grid_field_numberFormat.tr(), fontSize: 12),
// const HSpace(6),
const Spacer(),
FlowyText.regular(state.typeOption.format.title(), fontSize: 12),
],
),
padding: GridSize.typeOptionContentInsets,
hoverColor: theme.hover,
onTap: () {
final list = NumberFormatList(onSelected: (format) {
context.read<NumberTypeOptionBloc>().add(NumberTypeOptionEvent.didSelectFormat(format));
});
final list = NumberFormatList(
onSelected: (format) {
context.read<NumberTypeOptionBloc>().add(NumberTypeOptionEvent.didSelectFormat(format));
},
selectedFormat: state.typeOption.format,
);
overlayDelegate.showOverlay(context, list);
},
rightIcon: svgWidget("grid/more", color: theme.iconColor),
@ -72,12 +82,14 @@ typedef _SelectNumberFormatCallback = Function(NumberFormat format);
class NumberFormatList extends StatelessWidget {
final _SelectNumberFormatCallback onSelected;
const NumberFormatList({required this.onSelected, Key? key}) : super(key: key);
final NumberFormat selectedFormat;
const NumberFormatList({required this.selectedFormat, required this.onSelected, Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final cells = NumberFormat.values.map((format) {
return NumberFormatCell(
isSelected: format == selectedFormat,
format: format,
onSelected: (format) {
onSelected(format);
@ -86,7 +98,7 @@ class NumberFormatList extends StatelessWidget {
}).toList();
return SizedBox(
width: 120,
width: 180,
child: ListView.separated(
shrinkWrap: true,
controller: ScrollController(),
@ -108,19 +120,30 @@ class NumberFormatList extends StatelessWidget {
class NumberFormatCell extends StatelessWidget {
final NumberFormat format;
final bool isSelected;
final Function(NumberFormat format) onSelected;
const NumberFormatCell({required this.format, required this.onSelected, Key? key}) : super(key: key);
const NumberFormatCell({
required this.isSelected,
required this.format,
required this.onSelected,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = context.watch<AppTheme>();
Widget? checkmark;
if (isSelected) {
checkmark = svgWidget("grid/checkmark");
}
return SizedBox(
height: GridSize.typeOptionItemHeight,
child: FlowyButton(
text: FlowyText.medium(format.title(), fontSize: 12),
hoverColor: theme.hover,
onTap: () => onSelected(format),
leftIcon: svgWidget(format.iconName(), color: theme.iconColor),
rightIcon: checkmark,
),
);
}
@ -129,31 +152,95 @@ class NumberFormatCell extends StatelessWidget {
extension NumberFormatExtension on NumberFormat {
String title() {
switch (this) {
case NumberFormat.CNY:
return "Yen";
case NumberFormat.ArgentinePeso:
return "Argentine peso";
case NumberFormat.Baht:
return "Baht";
case NumberFormat.CanadianDollar:
return "Canadian dollar";
case NumberFormat.ChileanPeso:
return "Chilean peso";
case NumberFormat.ColombianPeso:
return "Colombian peso";
case NumberFormat.DanishKrone:
return "Danish krone";
case NumberFormat.Dirham:
return "Dirham";
case NumberFormat.EUR:
return "Euro";
case NumberFormat.Forint:
return "Forint";
case NumberFormat.Franc:
return "Franc";
case NumberFormat.HongKongDollar:
return "Hone Kong dollar";
case NumberFormat.Koruna:
return "Koruna";
case NumberFormat.Krona:
return "Krona";
case NumberFormat.Leu:
return "Leu";
case NumberFormat.Lira:
return "Lira";
case NumberFormat.MexicanPeso:
return "Mexican Peso";
case NumberFormat.NewTaiwanDollar:
return "New Taiwan dollar";
case NumberFormat.NewZealandDollar:
return "New Zealand dollar";
case NumberFormat.NorwegianKrone:
return "Norwegian krone";
case NumberFormat.Number:
return "Numbers";
return "Number";
case NumberFormat.Percent:
return "Percent";
case NumberFormat.PhilippinePeso:
return "Percent";
case NumberFormat.Pound:
return "Pound";
case NumberFormat.Rand:
return "Rand";
case NumberFormat.Real:
return "Real";
case NumberFormat.Ringgit:
return "Ringgit";
case NumberFormat.Riyal:
return "Riyal";
case NumberFormat.Ruble:
return "Ruble";
case NumberFormat.Rupee:
return "Rupee";
case NumberFormat.Rupiah:
return "Rupiah";
case NumberFormat.Shekel:
return "Skekel";
case NumberFormat.USD:
return "US Dollar";
case NumberFormat.UruguayanPeso:
return "Uruguayan peso";
case NumberFormat.Won:
return "Uruguayan peso";
case NumberFormat.Yen:
return "Yen";
case NumberFormat.Yuan:
return "Yuan";
default:
throw UnimplementedError;
}
}
String iconName() {
switch (this) {
case NumberFormat.CNY:
return "grid/field/yen";
case NumberFormat.EUR:
return "grid/field/euro";
case NumberFormat.Number:
return "grid/field/numbers";
case NumberFormat.USD:
return "grid/field/us_dollar";
default:
throw UnimplementedError;
}
}
// String iconName() {
// switch (this) {
// case NumberFormat.CNY:
// return "grid/field/yen";
// case NumberFormat.EUR:
// return "grid/field/euro";
// case NumberFormat.Number:
// return "grid/field/numbers";
// case NumberFormat.USD:
// return "grid/field/us_dollar";
// default:
// throw UnimplementedError;
// }
// }
}

View File

@ -12,14 +12,78 @@ import 'package:protobuf/protobuf.dart' as $pb;
class NumberFormat extends $pb.ProtobufEnum {
static const NumberFormat Number = NumberFormat._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Number');
static const NumberFormat USD = NumberFormat._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'USD');
static const NumberFormat CNY = NumberFormat._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CNY');
static const NumberFormat EUR = NumberFormat._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EUR');
static const NumberFormat CanadianDollar = NumberFormat._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CanadianDollar');
static const NumberFormat EUR = NumberFormat._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EUR');
static const NumberFormat Pound = NumberFormat._(5, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Pound');
static const NumberFormat Yen = NumberFormat._(6, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Yen');
static const NumberFormat Ruble = NumberFormat._(7, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Ruble');
static const NumberFormat Rupee = NumberFormat._(8, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Rupee');
static const NumberFormat Won = NumberFormat._(9, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Won');
static const NumberFormat Yuan = NumberFormat._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Yuan');
static const NumberFormat Real = NumberFormat._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Real');
static const NumberFormat Lira = NumberFormat._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Lira');
static const NumberFormat Rupiah = NumberFormat._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Rupiah');
static const NumberFormat Franc = NumberFormat._(14, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Franc');
static const NumberFormat HongKongDollar = NumberFormat._(15, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'HongKongDollar');
static const NumberFormat NewZealandDollar = NumberFormat._(16, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NewZealandDollar');
static const NumberFormat Krona = NumberFormat._(17, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Krona');
static const NumberFormat NorwegianKrone = NumberFormat._(18, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NorwegianKrone');
static const NumberFormat MexicanPeso = NumberFormat._(19, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'MexicanPeso');
static const NumberFormat Rand = NumberFormat._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Rand');
static const NumberFormat NewTaiwanDollar = NumberFormat._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NewTaiwanDollar');
static const NumberFormat DanishKrone = NumberFormat._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DanishKrone');
static const NumberFormat Baht = NumberFormat._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Baht');
static const NumberFormat Forint = NumberFormat._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Forint');
static const NumberFormat Koruna = NumberFormat._(25, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Koruna');
static const NumberFormat Shekel = NumberFormat._(26, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Shekel');
static const NumberFormat ChileanPeso = NumberFormat._(27, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ChileanPeso');
static const NumberFormat PhilippinePeso = NumberFormat._(28, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PhilippinePeso');
static const NumberFormat Dirham = NumberFormat._(29, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Dirham');
static const NumberFormat ColombianPeso = NumberFormat._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ColombianPeso');
static const NumberFormat Riyal = NumberFormat._(31, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Riyal');
static const NumberFormat Ringgit = NumberFormat._(32, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Ringgit');
static const NumberFormat Leu = NumberFormat._(33, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Leu');
static const NumberFormat ArgentinePeso = NumberFormat._(34, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ArgentinePeso');
static const NumberFormat UruguayanPeso = NumberFormat._(35, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UruguayanPeso');
static const NumberFormat Percent = NumberFormat._(36, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Percent');
static const $core.List<NumberFormat> values = <NumberFormat> [
Number,
USD,
CNY,
CanadianDollar,
EUR,
Pound,
Yen,
Ruble,
Rupee,
Won,
Yuan,
Real,
Lira,
Rupiah,
Franc,
HongKongDollar,
NewZealandDollar,
Krona,
NorwegianKrone,
MexicanPeso,
Rand,
NewTaiwanDollar,
DanishKrone,
Baht,
Forint,
Koruna,
Shekel,
ChileanPeso,
PhilippinePeso,
Dirham,
ColombianPeso,
Riyal,
Ringgit,
Leu,
ArgentinePeso,
UruguayanPeso,
Percent,
];
static final $core.Map<$core.int, NumberFormat> _byValue = $pb.ProtobufEnum.initByValue(values);

View File

@ -14,13 +14,45 @@ const NumberFormat$json = const {
'2': const [
const {'1': 'Number', '2': 0},
const {'1': 'USD', '2': 1},
const {'1': 'CNY', '2': 2},
const {'1': 'EUR', '2': 3},
const {'1': 'CanadianDollar', '2': 2},
const {'1': 'EUR', '2': 4},
const {'1': 'Pound', '2': 5},
const {'1': 'Yen', '2': 6},
const {'1': 'Ruble', '2': 7},
const {'1': 'Rupee', '2': 8},
const {'1': 'Won', '2': 9},
const {'1': 'Yuan', '2': 10},
const {'1': 'Real', '2': 11},
const {'1': 'Lira', '2': 12},
const {'1': 'Rupiah', '2': 13},
const {'1': 'Franc', '2': 14},
const {'1': 'HongKongDollar', '2': 15},
const {'1': 'NewZealandDollar', '2': 16},
const {'1': 'Krona', '2': 17},
const {'1': 'NorwegianKrone', '2': 18},
const {'1': 'MexicanPeso', '2': 19},
const {'1': 'Rand', '2': 20},
const {'1': 'NewTaiwanDollar', '2': 21},
const {'1': 'DanishKrone', '2': 22},
const {'1': 'Baht', '2': 23},
const {'1': 'Forint', '2': 24},
const {'1': 'Koruna', '2': 25},
const {'1': 'Shekel', '2': 26},
const {'1': 'ChileanPeso', '2': 27},
const {'1': 'PhilippinePeso', '2': 28},
const {'1': 'Dirham', '2': 29},
const {'1': 'ColombianPeso', '2': 30},
const {'1': 'Riyal', '2': 31},
const {'1': 'Ringgit', '2': 32},
const {'1': 'Leu', '2': 33},
const {'1': 'ArgentinePeso', '2': 34},
const {'1': 'UruguayanPeso', '2': 35},
const {'1': 'Percent', '2': 36},
],
};
/// Descriptor for `NumberFormat`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List numberFormatDescriptor = $convert.base64Decode('CgxOdW1iZXJGb3JtYXQSCgoGTnVtYmVyEAASBwoDVVNEEAESBwoDQ05ZEAISBwoDRVVSEAM=');
final $typed_data.Uint8List numberFormatDescriptor = $convert.base64Decode('CgxOdW1iZXJGb3JtYXQSCgoGTnVtYmVyEAASBwoDVVNEEAESEgoOQ2FuYWRpYW5Eb2xsYXIQAhIHCgNFVVIQBBIJCgVQb3VuZBAFEgcKA1llbhAGEgkKBVJ1YmxlEAcSCQoFUnVwZWUQCBIHCgNXb24QCRIICgRZdWFuEAoSCAoEUmVhbBALEggKBExpcmEQDBIKCgZSdXBpYWgQDRIJCgVGcmFuYxAOEhIKDkhvbmdLb25nRG9sbGFyEA8SFAoQTmV3WmVhbGFuZERvbGxhchAQEgkKBUtyb25hEBESEgoOTm9yd2VnaWFuS3JvbmUQEhIPCgtNZXhpY2FuUGVzbxATEggKBFJhbmQQFBITCg9OZXdUYWl3YW5Eb2xsYXIQFRIPCgtEYW5pc2hLcm9uZRAWEggKBEJhaHQQFxIKCgZGb3JpbnQQGBIKCgZLb3J1bmEQGRIKCgZTaGVrZWwQGhIPCgtDaGlsZWFuUGVzbxAbEhIKDlBoaWxpcHBpbmVQZXNvEBwSCgoGRGlyaGFtEB0SEQoNQ29sb21iaWFuUGVzbxAeEgkKBVJpeWFsEB8SCwoHUmluZ2dpdBAgEgcKA0xldRAhEhEKDUFyZ2VudGluZVBlc28QIhIRCg1VcnVndWF5YW5QZXNvECMSCwoHUGVyY2VudBAk');
@$core.Deprecated('Use numberTypeOptionDescriptor instead')
const NumberTypeOption$json = const {
'1': 'NumberTypeOption',

View File

@ -329,8 +329,40 @@ impl ::protobuf::reflect::ProtobufValue for NumberTypeOption {
pub enum NumberFormat {
Number = 0,
USD = 1,
CNY = 2,
EUR = 3,
CanadianDollar = 2,
EUR = 4,
Pound = 5,
Yen = 6,
Ruble = 7,
Rupee = 8,
Won = 9,
Yuan = 10,
Real = 11,
Lira = 12,
Rupiah = 13,
Franc = 14,
HongKongDollar = 15,
NewZealandDollar = 16,
Krona = 17,
NorwegianKrone = 18,
MexicanPeso = 19,
Rand = 20,
NewTaiwanDollar = 21,
DanishKrone = 22,
Baht = 23,
Forint = 24,
Koruna = 25,
Shekel = 26,
ChileanPeso = 27,
PhilippinePeso = 28,
Dirham = 29,
ColombianPeso = 30,
Riyal = 31,
Ringgit = 32,
Leu = 33,
ArgentinePeso = 34,
UruguayanPeso = 35,
Percent = 36,
}
impl ::protobuf::ProtobufEnum for NumberFormat {
@ -342,8 +374,40 @@ impl ::protobuf::ProtobufEnum for NumberFormat {
match value {
0 => ::std::option::Option::Some(NumberFormat::Number),
1 => ::std::option::Option::Some(NumberFormat::USD),
2 => ::std::option::Option::Some(NumberFormat::CNY),
3 => ::std::option::Option::Some(NumberFormat::EUR),
2 => ::std::option::Option::Some(NumberFormat::CanadianDollar),
4 => ::std::option::Option::Some(NumberFormat::EUR),
5 => ::std::option::Option::Some(NumberFormat::Pound),
6 => ::std::option::Option::Some(NumberFormat::Yen),
7 => ::std::option::Option::Some(NumberFormat::Ruble),
8 => ::std::option::Option::Some(NumberFormat::Rupee),
9 => ::std::option::Option::Some(NumberFormat::Won),
10 => ::std::option::Option::Some(NumberFormat::Yuan),
11 => ::std::option::Option::Some(NumberFormat::Real),
12 => ::std::option::Option::Some(NumberFormat::Lira),
13 => ::std::option::Option::Some(NumberFormat::Rupiah),
14 => ::std::option::Option::Some(NumberFormat::Franc),
15 => ::std::option::Option::Some(NumberFormat::HongKongDollar),
16 => ::std::option::Option::Some(NumberFormat::NewZealandDollar),
17 => ::std::option::Option::Some(NumberFormat::Krona),
18 => ::std::option::Option::Some(NumberFormat::NorwegianKrone),
19 => ::std::option::Option::Some(NumberFormat::MexicanPeso),
20 => ::std::option::Option::Some(NumberFormat::Rand),
21 => ::std::option::Option::Some(NumberFormat::NewTaiwanDollar),
22 => ::std::option::Option::Some(NumberFormat::DanishKrone),
23 => ::std::option::Option::Some(NumberFormat::Baht),
24 => ::std::option::Option::Some(NumberFormat::Forint),
25 => ::std::option::Option::Some(NumberFormat::Koruna),
26 => ::std::option::Option::Some(NumberFormat::Shekel),
27 => ::std::option::Option::Some(NumberFormat::ChileanPeso),
28 => ::std::option::Option::Some(NumberFormat::PhilippinePeso),
29 => ::std::option::Option::Some(NumberFormat::Dirham),
30 => ::std::option::Option::Some(NumberFormat::ColombianPeso),
31 => ::std::option::Option::Some(NumberFormat::Riyal),
32 => ::std::option::Option::Some(NumberFormat::Ringgit),
33 => ::std::option::Option::Some(NumberFormat::Leu),
34 => ::std::option::Option::Some(NumberFormat::ArgentinePeso),
35 => ::std::option::Option::Some(NumberFormat::UruguayanPeso),
36 => ::std::option::Option::Some(NumberFormat::Percent),
_ => ::std::option::Option::None
}
}
@ -352,8 +416,40 @@ impl ::protobuf::ProtobufEnum for NumberFormat {
static values: &'static [NumberFormat] = &[
NumberFormat::Number,
NumberFormat::USD,
NumberFormat::CNY,
NumberFormat::CanadianDollar,
NumberFormat::EUR,
NumberFormat::Pound,
NumberFormat::Yen,
NumberFormat::Ruble,
NumberFormat::Rupee,
NumberFormat::Won,
NumberFormat::Yuan,
NumberFormat::Real,
NumberFormat::Lira,
NumberFormat::Rupiah,
NumberFormat::Franc,
NumberFormat::HongKongDollar,
NumberFormat::NewZealandDollar,
NumberFormat::Krona,
NumberFormat::NorwegianKrone,
NumberFormat::MexicanPeso,
NumberFormat::Rand,
NumberFormat::NewTaiwanDollar,
NumberFormat::DanishKrone,
NumberFormat::Baht,
NumberFormat::Forint,
NumberFormat::Koruna,
NumberFormat::Shekel,
NumberFormat::ChileanPeso,
NumberFormat::PhilippinePeso,
NumberFormat::Dirham,
NumberFormat::ColombianPeso,
NumberFormat::Riyal,
NumberFormat::Ringgit,
NumberFormat::Leu,
NumberFormat::ArgentinePeso,
NumberFormat::UruguayanPeso,
NumberFormat::Percent,
];
values
}
@ -386,9 +482,22 @@ static file_descriptor_proto_data: &'static [u8] = b"\
\x06format\x18\x01\x20\x01(\x0e2\r.NumberFormatR\x06format\x12\x14\n\x05\
scale\x18\x02\x20\x01(\rR\x05scale\x12\x16\n\x06symbol\x18\x03\x20\x01(\
\tR\x06symbol\x12#\n\rsign_positive\x18\x04\x20\x01(\x08R\x0csignPositiv\
e\x12\x12\n\x04name\x18\x05\x20\x01(\tR\x04name*5\n\x0cNumberFormat\x12\
\n\n\x06Number\x10\0\x12\x07\n\x03USD\x10\x01\x12\x07\n\x03CNY\x10\x02\
\x12\x07\n\x03EUR\x10\x03b\x06proto3\
e\x12\x12\n\x04name\x18\x05\x20\x01(\tR\x04name*\xf8\x03\n\x0cNumberForm\
at\x12\n\n\x06Number\x10\0\x12\x07\n\x03USD\x10\x01\x12\x12\n\x0eCanadia\
nDollar\x10\x02\x12\x07\n\x03EUR\x10\x04\x12\t\n\x05Pound\x10\x05\x12\
\x07\n\x03Yen\x10\x06\x12\t\n\x05Ruble\x10\x07\x12\t\n\x05Rupee\x10\x08\
\x12\x07\n\x03Won\x10\t\x12\x08\n\x04Yuan\x10\n\x12\x08\n\x04Real\x10\
\x0b\x12\x08\n\x04Lira\x10\x0c\x12\n\n\x06Rupiah\x10\r\x12\t\n\x05Franc\
\x10\x0e\x12\x12\n\x0eHongKongDollar\x10\x0f\x12\x14\n\x10NewZealandDoll\
ar\x10\x10\x12\t\n\x05Krona\x10\x11\x12\x12\n\x0eNorwegianKrone\x10\x12\
\x12\x0f\n\x0bMexicanPeso\x10\x13\x12\x08\n\x04Rand\x10\x14\x12\x13\n\
\x0fNewTaiwanDollar\x10\x15\x12\x0f\n\x0bDanishKrone\x10\x16\x12\x08\n\
\x04Baht\x10\x17\x12\n\n\x06Forint\x10\x18\x12\n\n\x06Koruna\x10\x19\x12\
\n\n\x06Shekel\x10\x1a\x12\x0f\n\x0bChileanPeso\x10\x1b\x12\x12\n\x0ePhi\
lippinePeso\x10\x1c\x12\n\n\x06Dirham\x10\x1d\x12\x11\n\rColombianPeso\
\x10\x1e\x12\t\n\x05Riyal\x10\x1f\x12\x0b\n\x07Ringgit\x10\x20\x12\x07\n\
\x03Leu\x10!\x12\x11\n\rArgentinePeso\x10\"\x12\x11\n\rUruguayanPeso\x10\
#\x12\x0b\n\x07Percent\x10$b\x06proto3\
";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -10,6 +10,38 @@ message NumberTypeOption {
enum NumberFormat {
Number = 0;
USD = 1;
CNY = 2;
EUR = 3;
CanadianDollar = 2;
EUR = 4;
Pound = 5;
Yen = 6;
Ruble = 7;
Rupee = 8;
Won = 9;
Yuan = 10;
Real = 11;
Lira = 12;
Rupiah = 13;
Franc = 14;
HongKongDollar = 15;
NewZealandDollar = 16;
Krona = 17;
NorwegianKrone = 18;
MexicanPeso = 19;
Rand = 20;
NewTaiwanDollar = 21;
DanishKrone = 22;
Baht = 23;
Forint = 24;
Koruna = 25;
Shekel = 26;
ChileanPeso = 27;
PhilippinePeso = 28;
Dirham = 29;
ColombianPeso = 30;
Riyal = 31;
Ringgit = 32;
Leu = 33;
ArgentinePeso = 34;
UruguayanPeso = 35;
Percent = 36;
}

View File

@ -7,9 +7,8 @@ use flowy_grid_data_model::entities::{
};
use lazy_static::lazy_static;
use rust_decimal::Decimal;
use rusty_money::iso::{Currency, CNY, EUR, USD};
use rusty_money::iso::*;
use serde::{Deserialize, Serialize};
use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder};
@ -88,16 +87,14 @@ impl CellDataOperation for NumberTypeOption {
let cell_data = type_option_cell_data.data;
match self.format {
NumberFormat::Number => {
NumberFormat::Number | NumberFormat::Percent => {
if cell_data.parse::<i64>().is_ok() {
cell_data
} else {
String::new()
}
}
NumberFormat::USD => self.money_from_str(&cell_data, USD),
NumberFormat::CNY => self.money_from_str(&cell_data, CNY),
NumberFormat::EUR => self.money_from_str(&cell_data, EUR),
_ => self.money_from_str(&cell_data, self.format.currency()),
}
} else {
String::new()
@ -170,8 +167,40 @@ impl NumberTypeOption {
pub enum NumberFormat {
Number = 0,
USD = 1,
CNY = 2,
EUR = 3,
CanadianDollar = 2,
EUR = 4,
Pound = 5,
Yen = 6,
Ruble = 7,
Rupee = 8,
Won = 9,
Yuan = 10,
Real = 11,
Lira = 12,
Rupiah = 13,
Franc = 14,
HongKongDollar = 15,
NewZealandDollar = 16,
Krona = 17,
NorwegianKrone = 18,
MexicanPeso = 19,
Rand = 20,
NewTaiwanDollar = 21,
DanishKrone = 22,
Baht = 23,
Forint = 24,
Koruna = 25,
Shekel = 26,
ChileanPeso = 27,
PhilippinePeso = 28,
Dirham = 29,
ColombianPeso = 30,
Riyal = 31,
Ringgit = 32,
Leu = 33,
ArgentinePeso = 34,
UruguayanPeso = 35,
Percent = 36,
}
impl std::default::Default for NumberFormat {
@ -181,22 +210,84 @@ impl std::default::Default for NumberFormat {
}
impl NumberFormat {
pub fn currency(&self) -> &'static Currency {
match self {
NumberFormat::Number => USD,
NumberFormat::USD => USD,
NumberFormat::CanadianDollar => USD,
NumberFormat::EUR => EUR,
NumberFormat::Pound => GIP,
NumberFormat::Yen => CNY,
NumberFormat::Ruble => RUB,
NumberFormat::Rupee => INR,
NumberFormat::Won => KRW,
NumberFormat::Yuan => CNY,
NumberFormat::Real => BRL,
NumberFormat::Lira => TRY,
NumberFormat::Rupiah => IDR,
NumberFormat::Franc => CHF,
NumberFormat::HongKongDollar => USD,
NumberFormat::NewZealandDollar => USD,
NumberFormat::Krona => SEK,
NumberFormat::NorwegianKrone => NOK,
NumberFormat::MexicanPeso => USD,
NumberFormat::Rand => ZAR,
NumberFormat::NewTaiwanDollar => USD,
NumberFormat::DanishKrone => DKK,
NumberFormat::Baht => THB,
NumberFormat::Forint => HUF,
NumberFormat::Koruna => CZK,
NumberFormat::Shekel => CZK,
NumberFormat::ChileanPeso => CLP,
NumberFormat::PhilippinePeso => PHP,
NumberFormat::Dirham => AED,
NumberFormat::ColombianPeso => COP,
NumberFormat::Riyal => SAR,
NumberFormat::Ringgit => MYR,
NumberFormat::Leu => RON,
NumberFormat::ArgentinePeso => ARS,
NumberFormat::UruguayanPeso => UYU,
NumberFormat::Percent => USD,
}
}
pub fn symbol(&self) -> String {
match self {
NumberFormat::Number => "".to_string(),
NumberFormat::USD => USD.symbol.to_string(),
NumberFormat::CNY => CNY.symbol.to_string(),
NumberFormat::CanadianDollar => format!("CA{}", USD.symbol.to_string()),
NumberFormat::EUR => EUR.symbol.to_string(),
}
}
#[allow(dead_code)]
pub fn code(&self) -> String {
match self {
NumberFormat::Number => "".to_string(),
NumberFormat::USD => USD.iso_alpha_code.to_string(),
NumberFormat::CNY => CNY.iso_alpha_code.to_string(),
NumberFormat::EUR => EUR.iso_alpha_code.to_string(),
NumberFormat::Pound => GIP.symbol.to_string(),
NumberFormat::Yen => CNY.symbol.to_string(),
NumberFormat::Ruble => RUB.iso_alpha_code.to_string(),
NumberFormat::Rupee => INR.symbol.to_string(),
NumberFormat::Won => KRW.symbol.to_string(),
NumberFormat::Yuan => format!("CN{}", CNY.symbol.to_string()),
NumberFormat::Real => BRL.symbol.to_string(),
NumberFormat::Lira => TRY.iso_alpha_code.to_string(),
NumberFormat::Rupiah => IDR.iso_alpha_code.to_string(),
NumberFormat::Franc => CHF.iso_alpha_code.to_string(),
NumberFormat::HongKongDollar => format!("HK{}", USD.symbol.to_string()),
NumberFormat::NewZealandDollar => format!("NZ{}", USD.symbol.to_string()),
NumberFormat::Krona => SEK.iso_alpha_code.to_string(),
NumberFormat::NorwegianKrone => NOK.iso_alpha_code.to_string(),
NumberFormat::MexicanPeso => format!("MX{}", USD.symbol.to_string()),
NumberFormat::Rand => ZAR.iso_alpha_code.to_string(),
NumberFormat::NewTaiwanDollar => format!("NT{}", USD.symbol.to_string()),
NumberFormat::DanishKrone => DKK.iso_alpha_code.to_string(),
NumberFormat::Baht => THB.iso_alpha_code.to_string(),
NumberFormat::Forint => HUF.iso_alpha_code.to_string(),
NumberFormat::Koruna => CZK.iso_alpha_code.to_string(),
NumberFormat::Shekel => CZK.symbol.to_string(),
NumberFormat::ChileanPeso => CLP.iso_alpha_code.to_string(),
NumberFormat::PhilippinePeso => PHP.symbol.to_string(),
NumberFormat::Dirham => AED.iso_alpha_code.to_string(),
NumberFormat::ColombianPeso => COP.iso_alpha_code.to_string(),
NumberFormat::Riyal => SAR.iso_alpha_code.to_string(),
NumberFormat::Ringgit => MYR.iso_alpha_code.to_string(),
NumberFormat::Leu => RON.iso_alpha_code.to_string(),
NumberFormat::ArgentinePeso => ARS.iso_alpha_code.to_string(),
NumberFormat::UruguayanPeso => UYU.iso_alpha_code.to_string(),
NumberFormat::Percent => "%".to_string(),
}
}
}
@ -250,7 +341,7 @@ mod tests {
assert_eq!(type_option.decode_cell_data(data(""), &field_meta), "".to_owned());
assert_eq!(type_option.decode_cell_data(data("abc"), &field_meta), "".to_owned());
}
NumberFormat::CNY => {
NumberFormat::Yen => {
assert_eq!(
type_option.decode_cell_data(data("18443"), &field_meta),
"¥18,443".to_owned()
@ -293,7 +384,7 @@ mod tests {
"$1,844.3".to_owned()
);
}
NumberFormat::CNY => {
NumberFormat::Yen => {
assert_eq!(
type_option.decode_cell_data(data("18443"), &field_meta),
"¥1,844.3".to_owned()
@ -332,7 +423,7 @@ mod tests {
"-$18,443".to_owned()
);
}
NumberFormat::CNY => {
NumberFormat::Yen => {
assert_eq!(
type_option.decode_cell_data(data("18443"), &field_meta),
"-¥18,443".to_owned()