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

View File

@ -5,17 +5,11 @@ import 'package:aurcache/providers/api/builds_provider.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../constants/color_constants.dart';
import '../table_info.dart';
class RecentBuilds extends StatefulWidget {
const RecentBuilds({
Key? key,
}) : super(key: key);
class RecentBuilds extends StatelessWidget {
const RecentBuilds({super.key});
@override
State<RecentBuilds> createState() => _RecentBuildsState();
}
class _RecentBuildsState extends State<RecentBuilds> {
@override
Widget build(BuildContext context) {
return Container(
@ -31,18 +25,20 @@ class _RecentBuildsState extends State<RecentBuilds> {
"Recent Builds",
style: Theme.of(context).textTheme.subtitle1,
),
SizedBox(
width: double.infinity,
child: APIBuilder<BuildsProvider, List<Build>, BuildsDTO>(
APIBuilder<BuildsProvider, List<Build>, BuildsDTO>(
key: const Key("Builds on dashboard"),
dto: BuildsDTO(limit: 10),
interval: const Duration(seconds: 10),
onLoad: () => const Text("no data"),
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(
onPressed: () {
context.push("/builds");
@ -51,7 +47,12 @@ class _RecentBuildsState extends State<RecentBuilds> {
"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),
BuildsChart(
nrbuilds > 0
? BuildsChart(
nrbuilds: nrbuilds,
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(
color: const Color(0xff0a7005),
title: "Successful Builds",

View File

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