feat: displayCount
This commit is contained in:
@@ -20,6 +20,7 @@ class StatisticDao extends DatabaseAccessor<AppDatabase>
|
||||
id: statistic.id,
|
||||
type: statistic.type.name,
|
||||
timeframe: Value(statistic.timeframe?.name),
|
||||
displayCount: Value(statistic.displayCount),
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
@@ -59,12 +60,13 @@ class StatisticDao extends DatabaseAccessor<AppDatabase>
|
||||
return Statistic(
|
||||
type: StatisticType.values.firstWhere((type) => type.name == row.type),
|
||||
scopes: scopes,
|
||||
id: row.id,
|
||||
timeframe: Timeframe.values.firstWhereOrNull(
|
||||
(t) => t.name == row.timeframe,
|
||||
),
|
||||
selectedGroups: groups,
|
||||
selectedGames: games,
|
||||
displayCount: row.displayCount,
|
||||
id: row.id,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
@@ -73,9 +75,9 @@ class StatisticDao extends DatabaseAccessor<AppDatabase>
|
||||
/// Retrieves all statistics from the database, including their associated groups and games.
|
||||
Future<List<Statistic>> getAllStatistics() async {
|
||||
final query = select(statisticTable);
|
||||
final rows = await query.get();
|
||||
final result = await query.get();
|
||||
return Future.wait(
|
||||
rows.map((row) async {
|
||||
result.map((row) async {
|
||||
final groups = await db.statisticGroupDao.getGroupsForStatistic(row.id);
|
||||
final games = await db.statisticGameDao.getGamesForStatistic(row.id);
|
||||
|
||||
@@ -84,17 +86,29 @@ class StatisticDao extends DatabaseAccessor<AppDatabase>
|
||||
(type) => type.name == row.type,
|
||||
),
|
||||
scopes: [],
|
||||
id: row.id,
|
||||
timeframe: Timeframe.values.firstWhereOrNull(
|
||||
(t) => t.name == row.timeframe,
|
||||
),
|
||||
selectedGroups: groups,
|
||||
selectedGames: games,
|
||||
displayCount: row.displayCount,
|
||||
id: row.id,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/* Update */
|
||||
|
||||
Future<bool> updateDisplayCount(String statisticId, int displayCount) async {
|
||||
final rowsUpdated =
|
||||
await (update(statisticTable)
|
||||
..where((tbl) => tbl.id.equals(statisticId)))
|
||||
.write(StatisticTableCompanion(displayCount: Value(displayCount)));
|
||||
|
||||
return rowsUpdated > 0;
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
|
||||
Future<bool> deleteStatistic(String statisticId) async {
|
||||
|
||||
@@ -2767,8 +2767,20 @@ class $StatisticTableTable extends StatisticTable
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
);
|
||||
static const VerificationMeta _displayCountMeta = const VerificationMeta(
|
||||
'displayCount',
|
||||
);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [id, type, timeframe];
|
||||
late final GeneratedColumn<int> displayCount = GeneratedColumn<int>(
|
||||
'display_count',
|
||||
aliasedName,
|
||||
false,
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: false,
|
||||
defaultValue: const Constant(5),
|
||||
);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [id, type, timeframe, displayCount];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@override
|
||||
@@ -2800,6 +2812,15 @@ class $StatisticTableTable extends StatisticTable
|
||||
timeframe.isAcceptableOrUnknown(data['timeframe']!, _timeframeMeta),
|
||||
);
|
||||
}
|
||||
if (data.containsKey('display_count')) {
|
||||
context.handle(
|
||||
_displayCountMeta,
|
||||
displayCount.isAcceptableOrUnknown(
|
||||
data['display_count']!,
|
||||
_displayCountMeta,
|
||||
),
|
||||
);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -2821,6 +2842,10 @@ class $StatisticTableTable extends StatisticTable
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}timeframe'],
|
||||
),
|
||||
displayCount: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.int,
|
||||
data['${effectivePrefix}display_count'],
|
||||
)!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2835,10 +2860,12 @@ class StatisticTableData extends DataClass
|
||||
final String id;
|
||||
final String type;
|
||||
final String? timeframe;
|
||||
final int displayCount;
|
||||
const StatisticTableData({
|
||||
required this.id,
|
||||
required this.type,
|
||||
this.timeframe,
|
||||
required this.displayCount,
|
||||
});
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
@@ -2848,6 +2875,7 @@ class StatisticTableData extends DataClass
|
||||
if (!nullToAbsent || timeframe != null) {
|
||||
map['timeframe'] = Variable<String>(timeframe);
|
||||
}
|
||||
map['display_count'] = Variable<int>(displayCount);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -2858,6 +2886,7 @@ class StatisticTableData extends DataClass
|
||||
timeframe: timeframe == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(timeframe),
|
||||
displayCount: Value(displayCount),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2870,6 +2899,7 @@ class StatisticTableData extends DataClass
|
||||
id: serializer.fromJson<String>(json['id']),
|
||||
type: serializer.fromJson<String>(json['type']),
|
||||
timeframe: serializer.fromJson<String?>(json['timeframe']),
|
||||
displayCount: serializer.fromJson<int>(json['displayCount']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
@@ -2879,6 +2909,7 @@ class StatisticTableData extends DataClass
|
||||
'id': serializer.toJson<String>(id),
|
||||
'type': serializer.toJson<String>(type),
|
||||
'timeframe': serializer.toJson<String?>(timeframe),
|
||||
'displayCount': serializer.toJson<int>(displayCount),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2886,16 +2917,21 @@ class StatisticTableData extends DataClass
|
||||
String? id,
|
||||
String? type,
|
||||
Value<String?> timeframe = const Value.absent(),
|
||||
int? displayCount,
|
||||
}) => StatisticTableData(
|
||||
id: id ?? this.id,
|
||||
type: type ?? this.type,
|
||||
timeframe: timeframe.present ? timeframe.value : this.timeframe,
|
||||
displayCount: displayCount ?? this.displayCount,
|
||||
);
|
||||
StatisticTableData copyWithCompanion(StatisticTableCompanion data) {
|
||||
return StatisticTableData(
|
||||
id: data.id.present ? data.id.value : this.id,
|
||||
type: data.type.present ? data.type.value : this.type,
|
||||
timeframe: data.timeframe.present ? data.timeframe.value : this.timeframe,
|
||||
displayCount: data.displayCount.present
|
||||
? data.displayCount.value
|
||||
: this.displayCount,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2904,37 +2940,42 @@ class StatisticTableData extends DataClass
|
||||
return (StringBuffer('StatisticTableData(')
|
||||
..write('id: $id, ')
|
||||
..write('type: $type, ')
|
||||
..write('timeframe: $timeframe')
|
||||
..write('timeframe: $timeframe, ')
|
||||
..write('displayCount: $displayCount')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(id, type, timeframe);
|
||||
int get hashCode => Object.hash(id, type, timeframe, displayCount);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is StatisticTableData &&
|
||||
other.id == this.id &&
|
||||
other.type == this.type &&
|
||||
other.timeframe == this.timeframe);
|
||||
other.timeframe == this.timeframe &&
|
||||
other.displayCount == this.displayCount);
|
||||
}
|
||||
|
||||
class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
|
||||
final Value<String> id;
|
||||
final Value<String> type;
|
||||
final Value<String?> timeframe;
|
||||
final Value<int> displayCount;
|
||||
final Value<int> rowid;
|
||||
const StatisticTableCompanion({
|
||||
this.id = const Value.absent(),
|
||||
this.type = const Value.absent(),
|
||||
this.timeframe = const Value.absent(),
|
||||
this.displayCount = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
});
|
||||
StatisticTableCompanion.insert({
|
||||
required String id,
|
||||
required String type,
|
||||
this.timeframe = const Value.absent(),
|
||||
this.displayCount = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
}) : id = Value(id),
|
||||
type = Value(type);
|
||||
@@ -2942,12 +2983,14 @@ class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
|
||||
Expression<String>? id,
|
||||
Expression<String>? type,
|
||||
Expression<String>? timeframe,
|
||||
Expression<int>? displayCount,
|
||||
Expression<int>? rowid,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
if (id != null) 'id': id,
|
||||
if (type != null) 'type': type,
|
||||
if (timeframe != null) 'timeframe': timeframe,
|
||||
if (displayCount != null) 'display_count': displayCount,
|
||||
if (rowid != null) 'rowid': rowid,
|
||||
});
|
||||
}
|
||||
@@ -2956,12 +2999,14 @@ class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
|
||||
Value<String>? id,
|
||||
Value<String>? type,
|
||||
Value<String?>? timeframe,
|
||||
Value<int>? displayCount,
|
||||
Value<int>? rowid,
|
||||
}) {
|
||||
return StatisticTableCompanion(
|
||||
id: id ?? this.id,
|
||||
type: type ?? this.type,
|
||||
timeframe: timeframe ?? this.timeframe,
|
||||
displayCount: displayCount ?? this.displayCount,
|
||||
rowid: rowid ?? this.rowid,
|
||||
);
|
||||
}
|
||||
@@ -2978,6 +3023,9 @@ class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
|
||||
if (timeframe.present) {
|
||||
map['timeframe'] = Variable<String>(timeframe.value);
|
||||
}
|
||||
if (displayCount.present) {
|
||||
map['display_count'] = Variable<int>(displayCount.value);
|
||||
}
|
||||
if (rowid.present) {
|
||||
map['rowid'] = Variable<int>(rowid.value);
|
||||
}
|
||||
@@ -2990,6 +3038,7 @@ class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
|
||||
..write('id: $id, ')
|
||||
..write('type: $type, ')
|
||||
..write('timeframe: $timeframe, ')
|
||||
..write('displayCount: $displayCount, ')
|
||||
..write('rowid: $rowid')
|
||||
..write(')'))
|
||||
.toString();
|
||||
@@ -7516,6 +7565,7 @@ typedef $$StatisticTableTableCreateCompanionBuilder =
|
||||
required String id,
|
||||
required String type,
|
||||
Value<String?> timeframe,
|
||||
Value<int> displayCount,
|
||||
Value<int> rowid,
|
||||
});
|
||||
typedef $$StatisticTableTableUpdateCompanionBuilder =
|
||||
@@ -7523,6 +7573,7 @@ typedef $$StatisticTableTableUpdateCompanionBuilder =
|
||||
Value<String> id,
|
||||
Value<String> type,
|
||||
Value<String?> timeframe,
|
||||
Value<int> displayCount,
|
||||
Value<int> rowid,
|
||||
});
|
||||
|
||||
@@ -7645,6 +7696,11 @@ class $$StatisticTableTableFilterComposer
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<int> get displayCount => $composableBuilder(
|
||||
column: $table.displayCount,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
Expression<bool> statisticScopeTableRefs(
|
||||
Expression<bool> Function($$StatisticScopeTableTableFilterComposer f) f,
|
||||
) {
|
||||
@@ -7744,6 +7800,11 @@ class $$StatisticTableTableOrderingComposer
|
||||
column: $table.timeframe,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<int> get displayCount => $composableBuilder(
|
||||
column: $table.displayCount,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
}
|
||||
|
||||
class $$StatisticTableTableAnnotationComposer
|
||||
@@ -7764,6 +7825,11 @@ class $$StatisticTableTableAnnotationComposer
|
||||
GeneratedColumn<String> get timeframe =>
|
||||
$composableBuilder(column: $table.timeframe, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<int> get displayCount => $composableBuilder(
|
||||
column: $table.displayCount,
|
||||
builder: (column) => column,
|
||||
);
|
||||
|
||||
Expression<T> statisticScopeTableRefs<T extends Object>(
|
||||
Expression<T> Function($$StatisticScopeTableTableAnnotationComposer a) f,
|
||||
) {
|
||||
@@ -7880,11 +7946,13 @@ class $$StatisticTableTableTableManager
|
||||
Value<String> id = const Value.absent(),
|
||||
Value<String> type = const Value.absent(),
|
||||
Value<String?> timeframe = const Value.absent(),
|
||||
Value<int> displayCount = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) => StatisticTableCompanion(
|
||||
id: id,
|
||||
type: type,
|
||||
timeframe: timeframe,
|
||||
displayCount: displayCount,
|
||||
rowid: rowid,
|
||||
),
|
||||
createCompanionCallback:
|
||||
@@ -7892,11 +7960,13 @@ class $$StatisticTableTableTableManager
|
||||
required String id,
|
||||
required String type,
|
||||
Value<String?> timeframe = const Value.absent(),
|
||||
Value<int> displayCount = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) => StatisticTableCompanion.insert(
|
||||
id: id,
|
||||
type: type,
|
||||
timeframe: timeframe,
|
||||
displayCount: displayCount,
|
||||
rowid: rowid,
|
||||
),
|
||||
withReferenceMapper: (p0) => p0
|
||||
|
||||
@@ -4,6 +4,7 @@ class StatisticTable extends Table {
|
||||
TextColumn get id => text()();
|
||||
TextColumn get type => text()();
|
||||
TextColumn get timeframe => text().nullable()();
|
||||
IntColumn get displayCount => integer().withDefault(const Constant(5))();
|
||||
|
||||
@override
|
||||
Set<Column<Object>> get primaryKey => {id};
|
||||
|
||||
@@ -10,14 +10,16 @@ class Statistic {
|
||||
final Timeframe? timeframe;
|
||||
final List<Group>? selectedGroups;
|
||||
final List<Game>? selectedGames;
|
||||
final int displayCount;
|
||||
|
||||
Statistic({
|
||||
required this.type,
|
||||
required this.scopes,
|
||||
String? id,
|
||||
this.timeframe,
|
||||
this.selectedGroups,
|
||||
this.selectedGames,
|
||||
this.displayCount = 5,
|
||||
String? id,
|
||||
}) : id = id ?? const Uuid().v4();
|
||||
|
||||
@override
|
||||
|
||||
@@ -21,7 +21,6 @@ Widget buildStatisticTile({
|
||||
required List<Player> players,
|
||||
required BuildContext context,
|
||||
double? width,
|
||||
int itemCount = 5,
|
||||
}) {
|
||||
final filteredMatches = _getFilterMatches(statistic, matches);
|
||||
final filteredPlayers = _getFilteredPlayers(
|
||||
@@ -46,7 +45,6 @@ Widget buildStatisticTile({
|
||||
title: translateStatisticTypeToString(statistic.type, context),
|
||||
width: width ?? MediaQuery.sizeOf(context).width * 0.95,
|
||||
values: values,
|
||||
itemCount: itemCount,
|
||||
barColor: _getStatisticColor(statistic),
|
||||
statistic: statistic,
|
||||
);
|
||||
@@ -297,7 +295,6 @@ Widget buildSkeletonStatisticTile({required BuildContext context}) {
|
||||
title: 'Skeleton title',
|
||||
width: MediaQuery.sizeOf(context).width * 0.95,
|
||||
values: values,
|
||||
itemCount: count,
|
||||
barColor: _colorPalette[Random().nextInt(_colorPalette.length)],
|
||||
statistic: Statistic(
|
||||
type: StatisticType.totalMatches,
|
||||
|
||||
@@ -26,7 +26,6 @@ class StatisticsTile extends StatelessWidget {
|
||||
required this.title,
|
||||
required this.width,
|
||||
required this.values,
|
||||
required this.itemCount,
|
||||
required this.barColor,
|
||||
required this.statistic,
|
||||
});
|
||||
@@ -43,9 +42,6 @@ class StatisticsTile extends StatelessWidget {
|
||||
/// A list of tuples containing labels and their corresponding numeric values.
|
||||
final List<(Player, num)> values;
|
||||
|
||||
/// The maximum number of items to display.
|
||||
final int itemCount;
|
||||
|
||||
/// The color of the bars representing the values.
|
||||
final Color barColor;
|
||||
|
||||
@@ -74,7 +70,7 @@ class StatisticsTile extends StatelessWidget {
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final maxBarWidth = constraints.maxWidth * 0.8;
|
||||
final displayCount = min(values.length, itemCount);
|
||||
final displayCount = min(values.length, statistic.displayCount);
|
||||
final displayValues = values.take(displayCount).toList();
|
||||
final maxVal = displayValues.isNotEmpty
|
||||
? displayValues.fold<num>(
|
||||
|
||||
Reference in New Issue
Block a user