add table infos when no pkgs or builds are there yet

This commit is contained in:
lukas-heiligenbrunner 2024-02-25 19:40:21 +01:00
parent 9bb1e2add4
commit 68d88469c1
6 changed files with 139 additions and 74 deletions

View File

@ -3,15 +3,15 @@ import 'package:flutter/material.dart';
class BuildsChart extends StatefulWidget { class BuildsChart extends StatefulWidget {
const BuildsChart({ const BuildsChart({
Key? key, super.key,
required this.nrbuilds, required this.nrbuilds,
required this.nrfailedbuilds, required this.nrfailedbuilds,
required this.nrActiveBuilds, required this.nrEnqueuedBuilds,
}) : super(key: key); });
final int nrbuilds; final int nrbuilds;
final int nrfailedbuilds; final int nrfailedbuilds;
final int nrActiveBuilds; final int nrEnqueuedBuilds;
@override @override
_BuildsChartState createState() => _BuildsChartState(); _BuildsChartState createState() => _BuildsChartState();
@ -88,10 +88,10 @@ class _BuildsChartState extends State<BuildsChart> {
color: const Color(0xff0a7005), color: const Color(0xff0a7005),
value: (widget.nrbuilds - value: (widget.nrbuilds -
widget.nrfailedbuilds - widget.nrfailedbuilds -
widget.nrActiveBuilds) widget.nrEnqueuedBuilds)
.toDouble(), .toDouble(),
title: title:
"${((widget.nrbuilds - widget.nrfailedbuilds - widget.nrActiveBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", "${((widget.nrbuilds - widget.nrfailedbuilds - widget.nrEnqueuedBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%",
radius: radius, radius: radius,
titleStyle: TextStyle( titleStyle: TextStyle(
fontSize: fontSize, fontSize: fontSize,
@ -101,9 +101,9 @@ class _BuildsChartState extends State<BuildsChart> {
case 2: case 2:
return PieChartSectionData( return PieChartSectionData(
color: const Color(0xFF0044AA), color: const Color(0xFF0044AA),
value: (widget.nrActiveBuilds).toDouble(), value: (widget.nrEnqueuedBuilds).toDouble(),
title: title:
"${((widget.nrActiveBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", "${((widget.nrEnqueuedBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%",
radius: radius, radius: radius,
titleStyle: TextStyle( titleStyle: TextStyle(
fontSize: fontSize, fontSize: fontSize,

View File

@ -5,17 +5,11 @@ import 'package:aurcache/providers/api/builds_provider.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../constants/color_constants.dart'; import '../../constants/color_constants.dart';
import '../table_info.dart';
class RecentBuilds extends StatefulWidget { class RecentBuilds extends StatelessWidget {
const RecentBuilds({ const RecentBuilds({super.key});
Key? key,
}) : super(key: key);
@override
State<RecentBuilds> createState() => _RecentBuildsState();
}
class _RecentBuildsState extends State<RecentBuilds> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -31,18 +25,20 @@ class _RecentBuildsState extends State<RecentBuilds> {
"Recent Builds", "Recent Builds",
style: Theme.of(context).textTheme.subtitle1, style: Theme.of(context).textTheme.subtitle1,
), ),
SizedBox( APIBuilder<BuildsProvider, List<Build>, BuildsDTO>(
width: double.infinity,
child: APIBuilder<BuildsProvider, List<Build>, BuildsDTO>(
key: const Key("Builds on dashboard"), key: const Key("Builds on dashboard"),
dto: BuildsDTO(limit: 10), dto: BuildsDTO(limit: 10),
interval: const Duration(seconds: 10), interval: const Duration(seconds: 10),
onLoad: () => const Text("no data"), onLoad: () => const Text("no data"),
onData: (t) { onData: (t) {
return BuildsTable(data: t); if (t.isEmpty) {
}, return const TableInfo(title: "You have no builds yet");
), } else {
), return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: double.infinity, child: BuildsTable(data: t)),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
context.push("/builds"); context.push("/builds");
@ -51,7 +47,12 @@ class _RecentBuildsState extends State<RecentBuilds> {
"List all Builds", "List all Builds",
style: TextStyle(color: Colors.white.withOpacity(0.8)), style: TextStyle(color: Colors.white.withOpacity(0.8)),
), ),
) ),
],
);
}
},
),
], ],
), ),
); );

View File

@ -35,10 +35,34 @@ class SidePanel extends StatelessWidget {
), ),
), ),
const SizedBox(height: defaultPadding), const SizedBox(height: defaultPadding),
BuildsChart( nrbuilds > 0
? BuildsChart(
nrbuilds: nrbuilds, nrbuilds: nrbuilds,
nrfailedbuilds: nrfailedbuilds, nrfailedbuilds: nrfailedbuilds,
nrActiveBuilds: nrEnqueuedBuilds), nrEnqueuedBuilds: nrEnqueuedBuilds)
: const SizedBox(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 15,
),
Icon(
Icons.info_outline_rounded,
size: 42,
),
SizedBox(
height: 15,
),
Text("Add Packages to view Graph"),
SizedBox(
height: 30,
)
],
),
),
SideCard( SideCard(
color: const Color(0xff0a7005), color: const Color(0xff0a7005),
title: "Successful Builds", title: "Successful Builds",

View File

@ -1,21 +1,19 @@
import 'dart:ffi';
import 'package:aurcache/components/api/APIBuilder.dart'; import 'package:aurcache/components/api/APIBuilder.dart';
import 'package:aurcache/components/packages_table.dart'; import 'package:aurcache/components/packages_table.dart';
import 'package:aurcache/providers/api/packages_provider.dart'; import 'package:aurcache/providers/api/packages_provider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../constants/color_constants.dart'; import '../../constants/color_constants.dart';
import '../../models/package.dart'; import '../../models/package.dart';
import '../table_info.dart';
class YourPackages extends StatefulWidget { class YourPackages extends StatelessWidget {
const YourPackages({ const YourPackages({super.key});
Key? key,
}) : super(key: key);
@override
State<YourPackages> createState() => _YourPackagesState();
}
class _YourPackagesState extends State<YourPackages> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -31,19 +29,20 @@ class _YourPackagesState extends State<YourPackages> {
"Your Packages", "Your Packages",
style: Theme.of(context).textTheme.subtitle1, style: Theme.of(context).textTheme.subtitle1,
), ),
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ APIBuilder<PackagesProvider, List<Package>, PackagesDTO>(
SizedBox(
width: double.infinity,
child: APIBuilder<PackagesProvider, List<Package>, PackagesDTO>(
key: const Key("Packages on dashboard"), key: const Key("Packages on dashboard"),
interval: const Duration(seconds: 10), interval: const Duration(seconds: 10),
dto: PackagesDTO(limit: 10), dto: PackagesDTO(limit: 10),
onData: (data) { onData: (data) {
return PackagesTable(data: data); if (data.isEmpty) {
}, return const TableInfo(title: "You have no packages yet");
onLoad: () => const Text("No data"), } else {
), return Column(
), crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: double.infinity,
child: PackagesTable(data: data)),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
context.push("/packages"); context.push("/packages");
@ -53,7 +52,12 @@ class _YourPackagesState extends State<YourPackages> {
style: TextStyle(color: Colors.white.withOpacity(0.8)), style: TextStyle(color: Colors.white.withOpacity(0.8)),
), ),
) )
]), ],
);
}
},
onLoad: () => const CircularProgressIndicator(),
),
], ],
), ),
); );

View File

@ -0,0 +1,30 @@
import 'package:flutter/material.dart';
class TableInfo extends StatelessWidget {
const TableInfo({super.key, required this.title});
final String title;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 5,
),
const Divider(),
const SizedBox(
height: 15,
),
const Icon(
Icons.info_outline_rounded,
size: 42,
),
const SizedBox(
height: 15,
),
Text(title),
],
);
}
}

View File

@ -1,5 +1,6 @@
import 'package:aurcache/components/builds_table.dart'; import 'package:aurcache/components/builds_table.dart';
import 'package:aurcache/components/api/APIBuilder.dart'; import 'package:aurcache/components/api/APIBuilder.dart';
import 'package:aurcache/components/table_info.dart';
import 'package:aurcache/providers/api/builds_provider.dart'; import 'package:aurcache/providers/api/builds_provider.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -43,7 +44,12 @@ class BuildsScreen extends StatelessWidget {
interval: const Duration(seconds: 10), interval: const Duration(seconds: 10),
onLoad: () => const Text("no data"), onLoad: () => const Text("no data"),
onData: (data) { onData: (data) {
if (data.isEmpty) {
return const TableInfo(
title: "You have no builds yet");
} else {
return BuildsTable(data: data); return BuildsTable(data: data);
}
}), }),
) )
], ],