Skip to content

Commit

Permalink
dashboard ui update (badges & groupings)
Browse files Browse the repository at this point in the history
  • Loading branch information
CJBuchel committed Nov 25, 2024
1 parent ff36191 commit 6ed787b
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 146 deletions.
2 changes: 1 addition & 1 deletion tms_client/lib/views/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:echo_tree_flutter/widgets/echo_tree_lifetime_widget.dart';
import 'package:flutter/material.dart';
import 'package:tms/views/dashboard/dashboard_info_banner.dart';
import 'package:tms/views/dashboard/integrity_overview.dart';
import 'package:tms/views/dashboard/integrity_overview/integrity_overview.dart';
import 'package:tms/views/dashboard/scoring_overview/scoring_overview.dart';
import 'package:tms/views/dashboard/timers_overview.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import 'package:flutter/material.dart';
import 'package:tms/generated/infra/database_schemas/tournament_integrity_message.dart';
import 'package:tms/widgets/expandable/expandable_tile.dart';
import 'package:tms/widgets/integrity_checks/icon_tooltip_integrity_check.dart';

class IntegrityMessageTile extends StatelessWidget {
final List<TournamentIntegrityMessage> messages;
final ExpansionController _expansionController = ExpansionController(isExpanded: false);

IntegrityMessageTile({
Key? key,
required this.messages,
}) : super(key: key);

Widget _tile(BuildContext context, TournamentIntegrityMessage m) {
return ListTile(
leading: IconTooltipIntegrityCheck(messages: [m]),
title: Text(
m.integrityCode.getMessage(),
overflow: TextOverflow.ellipsis,
),
subtitle: Row(
children: [
// code
Text(
m.integrityCode.getStringifiedCode(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: m.integrityCode.when(
error: (_) => Colors.red,
warning: (_) => Colors.orange,
),
),
),
// team (if applicable)
if (m.teamNumber != null) ...[
const SizedBox(width: 10),
Text(
"Team ${m.teamNumber}",
style: const TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
],
// match (if applicable)
if (m.matchNumber != null) ...[
const SizedBox(width: 10),
Text(
"Match ${m.matchNumber}",
style: const TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
],
// session (if applicable)
if (m.sessionNumber != null) ...[
const SizedBox(width: 10),
Text(
"Session ${m.sessionNumber}",
style: const TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
],
],
),
);
}

@override
Widget build(BuildContext context) {
if (messages.length > 1) {
return Badge.count(
count: messages.length,
backgroundColor: Colors.red,
child: ExpandableTile(
controller: _expansionController,
header: Padding(
padding: const EdgeInsets.all(15),
child: Row(
children: [
IconTooltipIntegrityCheck(messages: messages),
const SizedBox(width: 10),
// code
Text(
messages.first.integrityCode.getStringifiedCode(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: messages.first.integrityCode.when(
error: (_) => Colors.red,
warning: (_) => Colors.orange,
),
),
),
const SizedBox(width: 10),
Text(
messages.first.integrityCode.getMessage(),
style: const TextStyle(fontSize: 16),
),
const Spacer(),
ValueListenableBuilder(
valueListenable: _expansionController,
builder: (context, isExpanded, _) {
return Icon(
isExpanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
);
},
),
],
),
),
body: Column(
children: messages.map((m) => _tile(context, m)).toList(),
),
),
);
} else if (messages.isNotEmpty) {
return _tile(context, messages.first);
} else {
return const SizedBox();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@ import 'package:provider/provider.dart';
import 'package:tms/generated/infra/database_schemas/tournament_integrity_message.dart';
import 'package:tms/providers/tournament_integrity_provider.dart';
import 'package:tms/utils/color_modifiers.dart';
import 'package:tms/utils/logger.dart';
import 'package:tms/widgets/integrity_checks/icon_tooltip_integrity_check.dart';
import 'package:tms/views/dashboard/integrity_overview/integrity_message_tile.dart';

class IntegrityOverview extends StatelessWidget {
const IntegrityOverview({Key? key}) : super(key: key);

List<List<TournamentIntegrityMessage>> _splitMessagesByCode(List<TournamentIntegrityMessage> messages) {
Map<String, List<TournamentIntegrityMessage>> groupedMessages = {};

for (var message in messages) {
String code = message.integrityCode.getStringifiedCode();
if (!groupedMessages.containsKey(code)) {
groupedMessages[code] = [];
}
groupedMessages[code]?.add(message);
}

return groupedMessages.values.toList();
}

@override
Widget build(BuildContext context) {
return Selector<TournamentIntegrityProvider, List<TournamentIntegrityMessage>>(
Expand All @@ -22,6 +35,8 @@ class IntegrityOverview extends StatelessWidget {
mainColor = Colors.orange;
}

final groupedMessages = _splitMessagesByCode(integrityMessages);

return Container(
margin: const EdgeInsets.fromLTRB(10, 10, 10, 0),
decoration: BoxDecoration(
Expand Down Expand Up @@ -61,8 +76,7 @@ class IntegrityOverview extends StatelessWidget {
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
children: integrityMessages.map((m) {
TmsLogger().d(m.toJsonString());
children: groupedMessages.map((mGroup) {
return Container(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
Expand All @@ -72,61 +86,7 @@ class IntegrityOverview extends StatelessWidget {
border: Border.all(color: Colors.black),
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
child: ListTile(
leading: IconTooltipIntegrityCheck(messages: [m]),
title: Text(
m.integrityCode.getMessage(),
overflow: TextOverflow.ellipsis,
),
subtitle: Row(
children: [
// code
Text(
m.integrityCode.getStringifiedCode(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: m.integrityCode.when(
error: (_) => Colors.red,
warning: (_) => Colors.orange,
),
),
),
// team (if applicable)
if (m.teamNumber != null) ...[
const SizedBox(width: 10),
Text(
"Team ${m.teamNumber}",
style: const TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
],
// match (if applicable)
if (m.matchNumber != null) ...[
const SizedBox(width: 10),
Text(
"Match ${m.matchNumber}",
style: const TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
],
// session (if applicable)
if (m.sessionNumber != null) ...[
const SizedBox(width: 10),
Text(
"Session ${m.sessionNumber}",
style: const TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
],
],
),
),
child: IntegrityMessageTile(messages: mGroup),
);
}).toList(),
),
Expand Down
Loading

0 comments on commit 6ed787b

Please sign in to comment.