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,27 +25,34 @@ 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, key: const Key("Builds on dashboard"),
child: APIBuilder<BuildsProvider, List<Build>, BuildsDTO>( dto: BuildsDTO(limit: 10),
key: const Key("Builds on dashboard"), interval: const Duration(seconds: 10),
dto: BuildsDTO(limit: 10), onLoad: () => const Text("no data"),
interval: const Duration(seconds: 10), onData: (t) {
onLoad: () => const Text("no data"), if (t.isEmpty) {
onData: (t) { return const TableInfo(title: "You have no builds yet");
return BuildsTable(data: t); } else {
}, return Column(
), crossAxisAlignment: CrossAxisAlignment.start,
), children: [
ElevatedButton( SizedBox(
onPressed: () { width: double.infinity, child: BuildsTable(data: t)),
context.push("/builds"); ElevatedButton(
onPressed: () {
context.push("/builds");
},
child: Text(
"List all Builds",
style: TextStyle(color: Colors.white.withOpacity(0.8)),
),
),
],
);
}
}, },
child: Text( ),
"List all Builds",
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
nrbuilds: nrbuilds, ? BuildsChart(
nrfailedbuilds: nrfailedbuilds, nrbuilds: nrbuilds,
nrActiveBuilds: nrEnqueuedBuilds), nrfailedbuilds: nrfailedbuilds,
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,29 +29,35 @@ 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( key: const Key("Packages on dashboard"),
width: double.infinity, interval: const Duration(seconds: 10),
child: APIBuilder<PackagesProvider, List<Package>, PackagesDTO>( dto: PackagesDTO(limit: 10),
key: const Key("Packages on dashboard"), onData: (data) {
interval: const Duration(seconds: 10), if (data.isEmpty) {
dto: PackagesDTO(limit: 10), return const TableInfo(title: "You have no packages yet");
onData: (data) { } else {
return PackagesTable(data: data); return Column(
}, crossAxisAlignment: CrossAxisAlignment.start,
onLoad: () => const Text("No data"), children: [
), SizedBox(
), width: double.infinity,
ElevatedButton( child: PackagesTable(data: data)),
onPressed: () { ElevatedButton(
context.push("/packages"); onPressed: () {
}, context.push("/packages");
child: Text( },
"List all Packages", child: Text(
style: TextStyle(color: Colors.white.withOpacity(0.8)), "List all Packages",
), 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) {
return BuildsTable(data: data); if (data.isEmpty) {
return const TableInfo(
title: "You have no builds yet");
} else {
return BuildsTable(data: data);
}
}), }),
) )
], ],