From 695f451763b1ef8e00e6f58d3ace808ac4348384 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Sat, 30 Dec 2023 10:43:46 +0100 Subject: [PATCH] set pkg to build state when already existing and starting build add active builds to right cake graph --- backend/src/api/add.rs | 10 ++++++-- backend/src/api/list.rs | 2 -- .../components/dashboard/builds_chart.dart | 24 ++++++++++++++++--- .../components/dashboard/recent_builds.dart | 15 +++++++----- .../lib/components/dashboard/side_panel.dart | 14 ++++++++++- frontend/lib/screens/dashboard_screen.dart | 6 +++-- 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/backend/src/api/add.rs b/backend/src/api/add.rs index 08c37c9..6855a47 100644 --- a/backend/src/api/add.rs +++ b/backend/src/api/add.rs @@ -28,7 +28,7 @@ pub async fn package_add( ) -> Result<(), BadRequest> { let db = db as &DatabaseConnection; - let pkt_model = match Packages::find() + let mut pkg_model = match Packages::find() .filter(packages::Column::Name.eq(input.name.clone())) .one(db) .await @@ -37,6 +37,7 @@ pub async fn package_add( None => { let new_package = packages::ActiveModel { name: Set(input.name.clone()), + status: Set(0), ..Default::default() }; @@ -58,7 +59,7 @@ pub async fn package_add( None => { let new_version = versions::ActiveModel { version: Set(pkg.version.clone()), - package_id: Set(pkt_model.id.clone().unwrap()), + package_id: Set(pkg_model.id.clone().unwrap()), ..Default::default() }; @@ -75,6 +76,11 @@ pub async fn package_add( } }; + if pkg_model.status.unwrap() != 0 { + pkg_model.status = Set(0); + pkg_model.save(db).await.expect("todo error message"); + } + let _ = tx.send(Action::Build( pkg.name, pkg.version, diff --git a/backend/src/api/list.rs b/backend/src/api/list.rs index 6fa40cc..7b1cc27 100644 --- a/backend/src/api/list.rs +++ b/backend/src/api/list.rs @@ -12,8 +12,6 @@ use rocket_okapi::{openapi, JsonSchema}; use sea_orm::PaginatorTrait; use sea_orm::{ColumnTrait, QueryFilter}; use sea_orm::{DatabaseConnection, EntityTrait, FromQueryResult, QuerySelect, RelationTrait}; -use std::path::PathBuf; -use std::{fs, io}; #[derive(Serialize, JsonSchema)] #[serde(crate = "rocket::serde")] diff --git a/frontend/lib/components/dashboard/builds_chart.dart b/frontend/lib/components/dashboard/builds_chart.dart index 8f271d0..052f37b 100644 --- a/frontend/lib/components/dashboard/builds_chart.dart +++ b/frontend/lib/components/dashboard/builds_chart.dart @@ -6,10 +6,12 @@ class BuildsChart extends StatefulWidget { Key? key, required this.nrbuilds, required this.nrfailedbuilds, + required this.nrActiveBuilds, }) : super(key: key); final int nrbuilds; final int nrfailedbuilds; + final int nrActiveBuilds; @override _BuildsChartState createState() => _BuildsChartState(); @@ -36,6 +38,7 @@ class _BuildsChartState extends State { pieTouchData: PieTouchData( touchCallback: (pieTouchResponse, touchresponse) { setState(() { + // todo hover gesture not working properly if (touchresponse?.touchedSection != null) { touchedIndex = touchresponse! .touchedSection!.touchedSectionIndex; @@ -63,7 +66,7 @@ class _BuildsChartState extends State { } List showingSections() { - return List.generate(2, (i) { + return List.generate(3, (i) { final isTouched = i == touchedIndex; final fontSize = isTouched ? 25.0 : 16.0; final radius = isTouched ? 60.0 : 50.0; @@ -83,9 +86,24 @@ class _BuildsChartState extends State { case 1: return PieChartSectionData( color: const Color(0xff0a7005), - value: (widget.nrbuilds - widget.nrfailedbuilds).toDouble(), + value: (widget.nrbuilds - + widget.nrfailedbuilds - + widget.nrActiveBuilds) + .toDouble(), title: - "${((widget.nrbuilds - widget.nrfailedbuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", + "${((widget.nrbuilds - widget.nrfailedbuilds - widget.nrActiveBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", + radius: radius, + titleStyle: TextStyle( + fontSize: fontSize, + fontWeight: FontWeight.bold, + color: const Color(0xffffffff)), + ); + case 2: + return PieChartSectionData( + color: const Color(0xff9d8d00), + value: (widget.nrActiveBuilds).toDouble(), + title: + "${((widget.nrActiveBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", radius: radius, titleStyle: TextStyle( fontSize: fontSize, diff --git a/frontend/lib/components/dashboard/recent_builds.dart b/frontend/lib/components/dashboard/recent_builds.dart index e23a9c7..dd23dab 100644 --- a/frontend/lib/components/dashboard/recent_builds.dart +++ b/frontend/lib/components/dashboard/recent_builds.dart @@ -42,10 +42,10 @@ class _RecentBuildsState extends State { @override Widget build(BuildContext context) { return Container( - padding: EdgeInsets.all(defaultPadding), - decoration: BoxDecoration( + padding: const EdgeInsets.all(defaultPadding), + decoration: const BoxDecoration( color: secondaryColor, - borderRadius: const BorderRadius.all(Radius.circular(10)), + borderRadius: BorderRadius.all(Radius.circular(10)), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -97,9 +97,12 @@ class _RecentBuildsState extends State { DataCell(Text(build.id.toString())), DataCell(Text(build.pkg_name)), DataCell(Text(build.version)), - DataCell(Icon( - switchSuccessIcon(build.status), - color: switchSuccessColor(build.status), + DataCell(IconButton( + icon: Icon( + switchSuccessIcon(build.status), + color: switchSuccessColor(build.status), + ), + onPressed: () {}, )), ], ); diff --git a/frontend/lib/components/dashboard/side_panel.dart b/frontend/lib/components/dashboard/side_panel.dart index 37a21f8..bdaa6a9 100644 --- a/frontend/lib/components/dashboard/side_panel.dart +++ b/frontend/lib/components/dashboard/side_panel.dart @@ -9,10 +9,12 @@ class SidePanel extends StatelessWidget { Key? key, required this.nrbuilds, required this.nrfailedbuilds, + required this.nrActiveBuilds, }) : super(key: key); final int nrbuilds; final int nrfailedbuilds; + final int nrActiveBuilds; @override Widget build(BuildContext context) { @@ -33,7 +35,10 @@ class SidePanel extends StatelessWidget { ), ), const SizedBox(height: defaultPadding), - BuildsChart(nrbuilds: nrbuilds, nrfailedbuilds: nrfailedbuilds), + BuildsChart( + nrbuilds: nrbuilds, + nrfailedbuilds: nrfailedbuilds, + nrActiveBuilds: nrActiveBuilds), ChartCard( color: const Color(0xff0a7005), title: "Successful Builds", @@ -48,6 +53,13 @@ class SidePanel extends StatelessWidget { "${(nrfailedbuilds * 100 / nrbuilds).toStringAsFixed(2)}%", subtitle: nrfailedbuilds.toString(), ), + ChartCard( + color: const Color(0xff9d8d00), + title: "Active Builds", + textRight: + "${(nrActiveBuilds * 100 / nrbuilds).toStringAsFixed(2)}%", + subtitle: nrActiveBuilds.toString(), + ), ], ), ); diff --git a/frontend/lib/screens/dashboard_screen.dart b/frontend/lib/screens/dashboard_screen.dart index a5520c2..b7e8065 100644 --- a/frontend/lib/screens/dashboard_screen.dart +++ b/frontend/lib/screens/dashboard_screen.dart @@ -49,7 +49,8 @@ class DashboardScreen extends StatelessWidget { if (Responsive.isMobile(context)) SidePanel( nrbuilds: stats.total_builds, - nrfailedbuilds: stats.failed_builds), + nrfailedbuilds: stats.failed_builds, + nrActiveBuilds: stats.active_builds), ], ), ), @@ -61,7 +62,8 @@ class DashboardScreen extends StatelessWidget { flex: 2, child: SidePanel( nrbuilds: stats.total_builds, - nrfailedbuilds: stats.failed_builds), + nrfailedbuilds: stats.failed_builds, + nrActiveBuilds: stats.active_builds), ), ], )