Skip to content

Commit

Permalink
feat: Show match-up list in the league page (closes #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Nov 29, 2023
1 parent 1ebc749 commit 01eacea
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:wrestling_scoreboard_client/ui/edit/league_edit.dart';
import 'package:wrestling_scoreboard_client/ui/edit/league_team_participation_edit.dart';
import 'package:wrestling_scoreboard_client/ui/edit/league_weight_class_edit.dart';
import 'package:wrestling_scoreboard_client/ui/overview/league_weight_class_overview.dart';
import 'package:wrestling_scoreboard_client/ui/overview/shared/matches_widget.dart';
import 'package:wrestling_scoreboard_client/ui/overview/team_overview.dart';
import 'package:wrestling_scoreboard_client/util/date_time.dart';
import 'package:wrestling_scoreboard_client/util/network/data_provider.dart';
Expand Down Expand Up @@ -87,6 +88,7 @@ class LeagueOverview extends StatelessWidget {
);
},
),
MatchesWidget<League>(filterObject: data),
ManyConsumer<LeagueWeightClass, League>(
filterObject: data,
builder: (BuildContext context, List<LeagueWeightClass> leagueWeightClasses) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart';
import 'package:wrestling_scoreboard_client/ui/edit/team_match_edit.dart';
import 'package:wrestling_scoreboard_client/ui/match/match_sequence.dart';
import 'package:wrestling_scoreboard_client/util/date_time.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class MatchesWidget<T extends DataObject?> extends StatelessWidget {
final T? filterObject;

const MatchesWidget({super.key, required this.filterObject});

@override
Widget build(BuildContext context) {
final localizations = AppLocalizations.of(context)!;
return ManyConsumer<TeamMatch, T>(
filterObject: filterObject,
builder: (BuildContext context, List<TeamMatch> matches) {
return ListGroup(
header: HeadingItem(
title: localizations.matches,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () =>
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
TeamMatchEdit(
initialHomeTeam: filterObject is Team ? filterObject as Team : null,
initialGuestTeam: filterObject is Team ? filterObject as Team : null,
),
),
),
),
),
items: matches.map(
(e) =>
SingleConsumer<TeamMatch>(
id: e.id!,
initialData: e,
builder: (context, match) =>
ListTile(
title: RichText(
text: TextSpan(
text: '${match!.date.toDateString(context)}, ${match.no ?? 'no ID'}, ',
children: [
TextSpan(
text: match.home.team.name,
style: match.home.team == filterObject
? const TextStyle(color: Colors.red, fontWeight: FontWeight.bold)
: null),
const TextSpan(text: ' - '),
TextSpan(
text: match.guest.team.name,
style: match.guest.team == filterObject
? const TextStyle(color: Colors.blue, fontWeight: FontWeight.bold)
: null),
],
),
),
leading: const Icon(Icons.event),
onTap: () => handleSelectedMatch(match, context),
),
),
),
);
},
);
}

handleSelectedMatch(TeamMatch match, BuildContext context) async {
Navigator.push(context, MaterialPageRoute(builder: (context) => MatchSequence(match)));
}
}
61 changes: 3 additions & 58 deletions wrestling_scoreboard_client/lib/ui/overview/team_overview.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import 'package:wrestling_scoreboard_common/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart';
import 'package:wrestling_scoreboard_client/ui/components/info.dart';
import 'package:wrestling_scoreboard_client/ui/edit/team_edit.dart';
import 'package:wrestling_scoreboard_client/ui/edit/team_match_edit.dart';
import 'package:wrestling_scoreboard_client/ui/match/match_sequence.dart';
import 'package:wrestling_scoreboard_client/util/date_time.dart';
import 'package:wrestling_scoreboard_client/ui/overview/shared/matches_widget.dart';
import 'package:wrestling_scoreboard_client/util/network/data_provider.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class TeamOverview<T extends DataObject> extends StatelessWidget {
final Team filterObject;
Expand Down Expand Up @@ -47,62 +45,9 @@ class TeamOverview<T extends DataObject> extends StatelessWidget {
),
body: GroupedList(items: [
description,
ManyConsumer<TeamMatch, Team>(
filterObject: data,
builder: (BuildContext context, List<TeamMatch> matches) {
return ListGroup(
header: HeadingItem(
title: localizations.matches,
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TeamMatchEdit(
initialHomeTeam: data,
initialGuestTeam: data,
),
),
),
),
),
items: matches.map(
(e) => SingleConsumer<TeamMatch>(
id: e.id!,
initialData: e,
builder: (context, match) => ListTile(
title: RichText(
text: TextSpan(
text: '${match!.date.toDateString(context)}, ${match.no ?? 'no ID'}, ',
children: [
TextSpan(
text: match.home.team.name,
style: match.home.team == data
? const TextStyle(color: Colors.red, fontWeight: FontWeight.bold)
: null),
const TextSpan(text: ' - '),
TextSpan(
text: match.guest.team.name,
style: match.guest.team == data
? const TextStyle(color: Colors.blue, fontWeight: FontWeight.bold)
: null),
],
),
),
leading: const Icon(Icons.event),
onTap: () => handleSelectedMatch(match, context),
),
),
),
);
},
),
MatchesWidget<Team>(filterObject: data),
]),
);
});
}

handleSelectedMatch(TeamMatch match, BuildContext context) async {
Navigator.push(context, MaterialPageRoute(builder: (context) => MatchSequence(match)));
}
}
36 changes: 6 additions & 30 deletions wrestling_scoreboard_client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,22 +285,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.8.1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "04be76c4a4bb50f14904e64749237e541e7c7bcf7ec0b196907322ab5d2fc739"
url: "https://pub.dev"
source: hosted
version: "9.0.16"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: b06739349ec2477e943055aea30172c5c7000225f79dad4702e2ec0eda79a6ff
url: "https://pub.dev"
source: hosted
version: "1.0.5"
lints:
dependency: transitive
description:
Expand All @@ -321,18 +305,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.10.0"
nested:
dependency: transitive
description:
Expand Down Expand Up @@ -626,22 +610,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
name: web
sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.4.0"
version: "0.3.0"
web_socket_channel:
dependency: "direct main"
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:wrestling_scoreboard_server/controllers/entity_controller.dart';
import 'package:wrestling_scoreboard_server/controllers/league_team_participation_controller.dart';
import 'package:wrestling_scoreboard_server/controllers/league_weight_class_controller.dart';
import 'package:wrestling_scoreboard_server/controllers/team_controller.dart';
import 'package:wrestling_scoreboard_server/controllers/team_match_controller.dart';
import 'package:wrestling_scoreboard_server/controllers/weight_class_controller.dart';
import 'package:shelf/shelf.dart';

Expand Down Expand Up @@ -45,4 +46,9 @@ class LeagueController extends EntityController<League> {
return EntityController.handleRequestManyOfController(LeagueTeamParticipationController(),
isRaw: isRaw(request), conditions: ['league_id = @id'], substitutionValues: {'id': id});
}

Future<Response> requestTeamMatchs(Request request, String id) async {
return EntityController.handleRequestManyOfController(TeamMatchController(),
isRaw: isRaw(request), conditions: ['league_id = @id'], substitutionValues: {'id': id});
}
}
15 changes: 8 additions & 7 deletions wrestling_scoreboard_server/lib/routes/api_route.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:wrestling_scoreboard_server/controllers/league_team_participation_controller.dart';
import 'package:wrestling_scoreboard_server/controllers/league_weight_class_controller.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:wrestling_scoreboard_server/controllers/league_team_participation_controller.dart';
import 'package:wrestling_scoreboard_server/controllers/league_weight_class_controller.dart';

import '../controllers/bout_config_controller.dart';
import '../controllers/club_controller.dart';
Expand Down Expand Up @@ -45,12 +45,12 @@ class ApiRoute {
router.get('/fights', fightController.requestMany);
router.get('/fight/<id|[0-9]+>', fightController.requestSingle);
router.get('/fight/<id|[0-9]+>/fight_actions', fightController.requestFightActions);

final fightActionController = FightActionController();
router.post('/fight_action', fightActionController.postSingle);
router.get('/fight_actions', fightActionController.requestMany);
router.get('/fight_action/<id|[0-9]+>', fightActionController.requestSingle);

final leagueController = LeagueController();
router.post('/league', leagueController.postSingle);
router.get('/leagues', leagueController.requestMany);
Expand All @@ -59,6 +59,7 @@ class ApiRoute {
router.get('/league/<id|[0-9]+>/weight_classs', leagueController.requestWeightClasses);
router.get('/league/<id|[0-9]+>/league_weight_classs', leagueController.requestLeagueWeightClasses);
router.get('/league/<id|[0-9]+>/league_team_participations', leagueController.requestLeagueTeamParticipations);
router.get('/league/<id|[0-9]+>/team_matchs', leagueController.requestTeamMatchs);

final leagueWeightClassController = LeagueWeightClassController();
router.post('/league_weight_class', leagueWeightClassController.postSingle);
Expand All @@ -80,7 +81,7 @@ class ApiRoute {
router.post('/membership', membershipController.postSingle);
router.get('/memberships', membershipController.requestMany);
router.get('/membership/<id|[0-9]+>', membershipController.requestSingle);

final participantStateController = ParticipantStateController();
router.post('/participant_state', participantStateController.postSingle);
router.get('/participant_states', participantStateController.requestMany);
Expand All @@ -101,15 +102,15 @@ class ApiRoute {
router.get('/teams', teamController.requestMany);
router.get('/team/<id|[0-9]+>', teamController.requestSingle);
router.get('/team/<id|[0-9]+>/team_matchs', teamController.requestTeamMatches);

final matchController = TeamMatchController();
router.post('/team_match', matchController.postSingle);
router.get('/team_matchs', matchController.requestMany);
router.get('/team_matches', matchController.requestMany);
router.get('/team_match/<id|[0-9]+>', matchController.requestSingle);
router.post('/team_match/<id|[0-9]+>/fights/generate', matchController.generateFights);
router.get('/team_match/<id|[0-9]+>/fights', matchController.requestFights);

final teamMatchFightController = TeamMatchFightController();
router.post('/team_match_fight', teamMatchFightController.postSingle);
router.get('/team_match_fights', teamMatchFightController.requestMany);
Expand Down

0 comments on commit 01eacea

Please sign in to comment.