Skip to content

Commit

Permalink
feat: Adding season partition (closes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Mar 4, 2024
1 parent 37a337a commit b783686
Show file tree
Hide file tree
Showing 43 changed files with 467 additions and 223 deletions.
5 changes: 5 additions & 0 deletions wrestling_scoreboard_client/lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
"participatingTeams": "Teilnehmende Mannschaften",
"league": "Liga",
"leagues": "Ligen",
"season": "Saison",
"seasonPartition": "Saison-Abschnitt",
"seasonPartitions": "Season-Abschnitte",
"seasonFirstHalf": "Hinrunde",
"seasonSecondHalf": "Rückrunde",
"competitions": "Turniere",
"match": "Begegnung",
"matches": "Begegnungen",
Expand Down
5 changes: 5 additions & 0 deletions wrestling_scoreboard_client/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
"participatingTeams": "Participating Teams",
"league": "League",
"leagues": "Leagues",
"season": "Season",
"seasonPartition": "Season Partition",
"seasonPartitions": "Season Partitions",
"seasonFirstHalf": "First Half",
"seasonSecondHalf": "Second Half",
"competitions": "Competitions",
"match": "Match",
"matches": "Matches",
Expand Down
2 changes: 1 addition & 1 deletion wrestling_scoreboard_client/lib/localization/gender.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:wrestling_scoreboard_common/common.dart';

Expand Down
16 changes: 16 additions & 0 deletions wrestling_scoreboard_client/lib/localization/season.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

extension SeasonLocalization on int {
String asSeasonPartition(BuildContext context, int? seasonPartitions) {
final localizations = AppLocalizations.of(context)!;
if (seasonPartitions == 2) {
if (this == 0) {
return localizations.seasonFirstHalf;
} else {
return localizations.seasonSecondHalf;
}
}
return (this + 1).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ League _leagueMenRPW = League(
name: 'Real Pro Wrestling',
startDate: DateTime(2021),
boutConfig: const BoutConfig(id: 1),
seasonPartitions: 2,
);
League _leagueJnRPW = League(
id: 2,
name: 'Real Pro Wrestling Jn',
startDate: DateTime(2021),
boutConfig: const BoutConfig(id: 2),
seasonPartitions: 2,
);
League _leagueNational = League(
id: 3,
name: 'National League',
startDate: DateTime(2021),
boutConfig: const BoutConfig(id: 3),
seasonPartitions: 2,
);

Club _homeClub = const Club(id: 1, name: 'Springfield Wrestlers');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wrestling_scoreboard_client/localization/date_time.dart';
import 'package:wrestling_scoreboard_client/provider/network_provider.dart';
import 'package:wrestling_scoreboard_client/view/screens/edit/bout_config_edit.dart';
import 'package:wrestling_scoreboard_client/localization/date_time.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class LeagueEdit extends BoutConfigEdit {
Expand All @@ -17,11 +18,13 @@ class LeagueEdit extends BoutConfigEdit {

class LeagueEditState extends BoutConfigEditState<LeagueEdit> {
String? _name;
late int _seasonPartitions;
late DateTime _startDate;

@override
void initState() {
_startDate = widget.league?.startDate ?? DateTime.now();
_seasonPartitions = widget.league?.seasonPartitions ?? 1;
super.initState();
}

Expand Down Expand Up @@ -70,12 +73,33 @@ class LeagueEditState extends BoutConfigEditState<LeagueEdit> {
initialValue: _startDate.toDateString(context),
),
),
ListTile(
leading: const Icon(Icons.sunny_snowing),
title: TextFormField(
initialValue: widget.league?.seasonPartitions.toString() ?? '',
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(vertical: 20),
labelText: localizations.seasonPartitions,
),
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.allow(RegExp(r'^\d'))],
onSaved: (String? value) {
_seasonPartitions = int.tryParse(value ?? '') ?? 1;
if (_seasonPartitions < 1) _seasonPartitions = 1;
},
),
),
]);
}

@override
Future<void> handleNested(BoutConfig dataObject) async {
await (await ref.read(dataManagerNotifierProvider)).createOrUpdateSingle(
League(id: widget.league?.id, name: _name!, startDate: _startDate, boutConfig: dataObject));
await (await ref.read(dataManagerNotifierProvider)).createOrUpdateSingle(League(
id: widget.league?.id,
name: _name!,
startDate: _startDate,
boutConfig: dataObject,
seasonPartitions: _seasonPartitions,
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wrestling_scoreboard_client/localization/season.dart';
import 'package:wrestling_scoreboard_client/provider/network_provider.dart';
import 'package:wrestling_scoreboard_client/view/screens/edit/weight_class_edit.dart';
import 'package:wrestling_scoreboard_client/view/widgets/toggle_buttons.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class LeagueWeightClassEdit extends WeightClassEdit {
Expand All @@ -19,6 +21,13 @@ class LeagueWeightClassEdit extends WeightClassEdit {

class LeagueWeightClassEditState extends WeightClassEditState<LeagueWeightClassEdit> {
int _pos = 0;
late int _seasonPartition;

@override
void initState() {
super.initState();
_seasonPartition = widget.leagueWeightClass?.seasonPartition ?? 0;
}

@override
Widget build(BuildContext context) {
Expand All @@ -39,13 +48,29 @@ class LeagueWeightClassEditState extends WeightClassEditState<LeagueWeightClassE
},
),
),
if (widget.initialLeague.seasonPartitions > 1)
ListTile(
leading: const Icon(Icons.sunny_snowing),
title: IndexedToggleButtons(
label: localizations.seasonPartition,
onPressed: (e) => setState(() => _seasonPartition = e),
selected: _seasonPartition,
numOptions: widget.initialLeague.seasonPartitions,
getTitle: (e) => e.asSeasonPartition(context, widget.initialLeague.seasonPartitions),
),
),
]);
}

@override
Future<void> handleNested(weightClass) async {
var leagueWeightClass = LeagueWeightClass(
id: widget.leagueWeightClass?.id, league: widget.initialLeague, pos: _pos, weightClass: weightClass);
id: widget.leagueWeightClass?.id,
league: widget.initialLeague,
pos: _pos,
weightClass: weightClass,
seasonPartition: _seasonPartition,
);
leagueWeightClass = leagueWeightClass
.copyWithId(await (await ref.read(dataManagerNotifierProvider)).createOrUpdateSingle(leagueWeightClass));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wrestling_scoreboard_client/localization/date_time.dart';
import 'package:wrestling_scoreboard_client/localization/season.dart';
import 'package:wrestling_scoreboard_client/provider/network_provider.dart';
import 'package:wrestling_scoreboard_client/view/widgets/dropdown.dart';
import 'package:wrestling_scoreboard_client/view/widgets/edit.dart';
import 'package:wrestling_scoreboard_client/localization/date_time.dart';
import 'package:wrestling_scoreboard_client/view/widgets/toggle_buttons.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class TeamMatchEdit extends ConsumerStatefulWidget {
Expand Down Expand Up @@ -36,6 +38,7 @@ class TeamMatchEditState extends ConsumerState<TeamMatchEdit> {
Team? _homeTeam;
Team? _guestTeam;
League? _league;
int? _seasonPartition;
late DateTime _date;

@override
Expand All @@ -45,6 +48,8 @@ class TeamMatchEditState extends ConsumerState<TeamMatchEdit> {
_guestTeam = widget.teamMatch?.guest.team ?? widget.initialGuestTeam;
_date = widget.teamMatch?.date ?? DateTime.now();
_league = widget.teamMatch?.league ?? widget.initialLeague;
// Set initial season partition to 0, if match has a league.
_seasonPartition = widget.teamMatch?.seasonPartition ?? (_league != null ? 0 : null);
}

@override
Expand Down Expand Up @@ -163,6 +168,17 @@ class TeamMatchEditState extends ConsumerState<TeamMatchEdit> {
},
),
),
if (_league != null && _league!.seasonPartitions > 1)
ListTile(
leading: const Icon(Icons.sunny_snowing),
title: IndexedToggleButtons(
label: localizations.seasonPartition,
onPressed: (e) => setState(() => _seasonPartition = e),
selected: _seasonPartition,
numOptions: _league!.seasonPartitions,
getTitle: (e) => e.asSeasonPartition(context, _league!.seasonPartitions),
),
),
];

return Form(
Expand Down Expand Up @@ -210,6 +226,7 @@ class TeamMatchEditState extends ConsumerState<TeamMatchEdit> {
guest: guest,
date: _date,
league: _league,
seasonPartition: _seasonPartition,
),
);
navigator.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:wrestling_scoreboard_client/localization/date_time.dart';
import 'package:wrestling_scoreboard_client/localization/season.dart';
import 'package:wrestling_scoreboard_client/localization/wrestling_style.dart';
import 'package:wrestling_scoreboard_client/provider/network_provider.dart';
import 'package:wrestling_scoreboard_client/view/screens/edit/team_match/league_edit.dart';
Expand Down Expand Up @@ -52,7 +53,12 @@ class LeagueOverview extends ConsumerWidget {
// '${localizations.injuryDurationInSecs}: ${data.boutConfig.injuryDuration.inSeconds}',
subtitle: localizations.periodDurationInSecs, // Start date
icon: Icons.timer,
)
),
ContentItem(
title: data.seasonPartitions.toString(),
subtitle: localizations.seasonPartitions,
icon: Icons.sunny_snowing,
),
],
);
return Scaffold(
Expand Down Expand Up @@ -117,7 +123,8 @@ class LeagueOverview extends ConsumerWidget {
initialData: e,
builder: (context, data) {
return ContentItem(
title: '${data.weightClass.name} ${data.weightClass.style.localize(context)}',
title:
'${data.weightClass.name} ${data.weightClass.style.localize(context)} ${data.seasonPartition == null ? '' : '(${data.seasonPartition!.asSeasonPartition(context, data.league.seasonPartitions)})'}',
icon: Icons.fitness_center,
onTap: () => handleSelectedWeightClass(data, context));
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wrestling_scoreboard_client/localization/season.dart';
import 'package:wrestling_scoreboard_client/provider/network_provider.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/screens/edit/team_match/league_weight_class_edit.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/weight_class_overview.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class LeagueWeightClassOverview extends WeightClassOverview {
Expand All @@ -22,16 +24,25 @@ class LeagueWeightClassOverview extends WeightClassOverview {
id: id,
initialData: leagueWeightClass,
builder: (context, data) {
return buildOverview(context, ref,
classLocale: localizations.weightClass,
editPage: LeagueWeightClassEdit(
leagueWeightClass: data,
initialLeague: data.league,
return buildOverview(
context,
ref,
classLocale: localizations.weightClass,
editPage: LeagueWeightClassEdit(
leagueWeightClass: data,
initialLeague: data.league,
),
onDelete: () async => (await ref.read(dataManagerNotifierProvider)).deleteSingle<LeagueWeightClass>(data),
tiles: [
ContentItem(
title: data.seasonPartition?.asSeasonPartition(context, data.league.seasonPartitions) ?? '-',
subtitle: localizations.seasonPartition,
icon: Icons.sunny_snowing,
),
onDelete: () async => (await ref.read(dataManagerNotifierProvider)).deleteSingle<LeagueWeightClass>(data),
tiles: [],
dataId: data.weightClass.id!,
initialData: data.weightClass);
],
dataId: data.weightClass.id!,
initialData: data.weightClass,
);
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:wrestling_scoreboard_client/localization/bout_utils.dart';
import 'package:wrestling_scoreboard_client/localization/date_time.dart';
import 'package:wrestling_scoreboard_client/localization/season.dart';
import 'package:wrestling_scoreboard_client/provider/network_provider.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_client/view/widgets/info.dart';
import 'package:wrestling_scoreboard_client/services/network/data_manager.dart';
import 'package:wrestling_scoreboard_client/view/screens/display/match/match_display.dart';
import 'package:wrestling_scoreboard_client/view/screens/edit/lineup_edit.dart';
import 'package:wrestling_scoreboard_client/view/screens/edit/team_match/team_match_bout_edit.dart';
import 'package:wrestling_scoreboard_client/view/screens/edit/team_match/team_match_edit.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/common.dart';
import 'package:wrestling_scoreboard_client/view/screens/overview/team_match/team_match_bout_overview.dart';
import 'package:wrestling_scoreboard_client/localization/date_time.dart';
import 'package:wrestling_scoreboard_client/services/network/data_manager.dart';
import 'package:wrestling_scoreboard_client/view/widgets/consumer.dart';
import 'package:wrestling_scoreboard_client/view/widgets/grouped_list.dart';
import 'package:wrestling_scoreboard_client/view/widgets/info.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class TeamMatchOverview extends ConsumerWidget {
Expand Down Expand Up @@ -98,6 +99,12 @@ class TeamMatchOverview extends ConsumerWidget {
subtitle: localizations.league,
icon: Icons.emoji_events,
),
ContentItem(
title: match.seasonPartition?.asSeasonPartition(context, match.league?.seasonPartitions) ??
'-',
subtitle: localizations.seasonPartition,
icon: Icons.sunny_snowing,
),
]),
ListGroup(
header: HeadingItem(title: localizations.persons),
Expand Down Expand Up @@ -211,12 +218,14 @@ class TeamMatchOverview extends ConsumerWidget {
handleSelectedLineup(
Lineup lineup, League league, TeamMatch match, NavigatorState navigator, DataManager dataManager) async {
final participations = await dataManager.readMany<Participation, Lineup>(filterObject: lineup);
final weightClasses = await dataManager.readMany<WeightClass, League>(filterObject: league);
final weightClasses = (await dataManager.readMany<LeagueWeightClass, League>(filterObject: league))
.where((element) => element.seasonPartition == match.seasonPartition)
.toList();
navigator.push(
MaterialPageRoute(
builder: (context) {
return LineupEdit(
weightClasses: weightClasses,
weightClasses: weightClasses.map((e) => e.weightClass).toList(),
participations: participations,
lineup: lineup,
onSubmitGenerate: () {
Expand Down
Loading

0 comments on commit b783686

Please sign in to comment.