set pkg to build state when already existing and starting build

add active builds to right cake graph
This commit is contained in:
lukas-heiligenbrunner 2023-12-30 10:43:46 +01:00
parent 600c2057fe
commit 695f451763
6 changed files with 55 additions and 16 deletions

View File

@ -28,7 +28,7 @@ pub async fn package_add(
) -> Result<(), BadRequest<String>> { ) -> Result<(), BadRequest<String>> {
let db = db as &DatabaseConnection; 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())) .filter(packages::Column::Name.eq(input.name.clone()))
.one(db) .one(db)
.await .await
@ -37,6 +37,7 @@ pub async fn package_add(
None => { None => {
let new_package = packages::ActiveModel { let new_package = packages::ActiveModel {
name: Set(input.name.clone()), name: Set(input.name.clone()),
status: Set(0),
..Default::default() ..Default::default()
}; };
@ -58,7 +59,7 @@ pub async fn package_add(
None => { None => {
let new_version = versions::ActiveModel { let new_version = versions::ActiveModel {
version: Set(pkg.version.clone()), version: Set(pkg.version.clone()),
package_id: Set(pkt_model.id.clone().unwrap()), package_id: Set(pkg_model.id.clone().unwrap()),
..Default::default() ..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( let _ = tx.send(Action::Build(
pkg.name, pkg.name,
pkg.version, pkg.version,

View File

@ -12,8 +12,6 @@ use rocket_okapi::{openapi, JsonSchema};
use sea_orm::PaginatorTrait; use sea_orm::PaginatorTrait;
use sea_orm::{ColumnTrait, QueryFilter}; use sea_orm::{ColumnTrait, QueryFilter};
use sea_orm::{DatabaseConnection, EntityTrait, FromQueryResult, QuerySelect, RelationTrait}; use sea_orm::{DatabaseConnection, EntityTrait, FromQueryResult, QuerySelect, RelationTrait};
use std::path::PathBuf;
use std::{fs, io};
#[derive(Serialize, JsonSchema)] #[derive(Serialize, JsonSchema)]
#[serde(crate = "rocket::serde")] #[serde(crate = "rocket::serde")]

View File

@ -6,10 +6,12 @@ class BuildsChart extends StatefulWidget {
Key? key, Key? key,
required this.nrbuilds, required this.nrbuilds,
required this.nrfailedbuilds, required this.nrfailedbuilds,
required this.nrActiveBuilds,
}) : super(key: key); }) : super(key: key);
final int nrbuilds; final int nrbuilds;
final int nrfailedbuilds; final int nrfailedbuilds;
final int nrActiveBuilds;
@override @override
_BuildsChartState createState() => _BuildsChartState(); _BuildsChartState createState() => _BuildsChartState();
@ -36,6 +38,7 @@ class _BuildsChartState extends State<BuildsChart> {
pieTouchData: PieTouchData( pieTouchData: PieTouchData(
touchCallback: (pieTouchResponse, touchresponse) { touchCallback: (pieTouchResponse, touchresponse) {
setState(() { setState(() {
// todo hover gesture not working properly
if (touchresponse?.touchedSection != null) { if (touchresponse?.touchedSection != null) {
touchedIndex = touchresponse! touchedIndex = touchresponse!
.touchedSection!.touchedSectionIndex; .touchedSection!.touchedSectionIndex;
@ -63,7 +66,7 @@ class _BuildsChartState extends State<BuildsChart> {
} }
List<PieChartSectionData> showingSections() { List<PieChartSectionData> showingSections() {
return List.generate(2, (i) { return List.generate(3, (i) {
final isTouched = i == touchedIndex; final isTouched = i == touchedIndex;
final fontSize = isTouched ? 25.0 : 16.0; final fontSize = isTouched ? 25.0 : 16.0;
final radius = isTouched ? 60.0 : 50.0; final radius = isTouched ? 60.0 : 50.0;
@ -83,9 +86,24 @@ class _BuildsChartState extends State<BuildsChart> {
case 1: case 1:
return PieChartSectionData( return PieChartSectionData(
color: const Color(0xff0a7005), color: const Color(0xff0a7005),
value: (widget.nrbuilds - widget.nrfailedbuilds).toDouble(), value: (widget.nrbuilds -
widget.nrfailedbuilds -
widget.nrActiveBuilds)
.toDouble(),
title: 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, radius: radius,
titleStyle: TextStyle( titleStyle: TextStyle(
fontSize: fontSize, fontSize: fontSize,

View File

@ -42,10 +42,10 @@ class _RecentBuildsState extends State<RecentBuilds> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.all(defaultPadding), padding: const EdgeInsets.all(defaultPadding),
decoration: BoxDecoration( decoration: const BoxDecoration(
color: secondaryColor, color: secondaryColor,
borderRadius: const BorderRadius.all(Radius.circular(10)), borderRadius: BorderRadius.all(Radius.circular(10)),
), ),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -97,9 +97,12 @@ class _RecentBuildsState extends State<RecentBuilds> {
DataCell(Text(build.id.toString())), DataCell(Text(build.id.toString())),
DataCell(Text(build.pkg_name)), DataCell(Text(build.pkg_name)),
DataCell(Text(build.version)), DataCell(Text(build.version)),
DataCell(Icon( DataCell(IconButton(
icon: Icon(
switchSuccessIcon(build.status), switchSuccessIcon(build.status),
color: switchSuccessColor(build.status), color: switchSuccessColor(build.status),
),
onPressed: () {},
)), )),
], ],
); );

View File

@ -9,10 +9,12 @@ class SidePanel extends StatelessWidget {
Key? key, Key? key,
required this.nrbuilds, required this.nrbuilds,
required this.nrfailedbuilds, required this.nrfailedbuilds,
required this.nrActiveBuilds,
}) : super(key: key); }) : super(key: key);
final int nrbuilds; final int nrbuilds;
final int nrfailedbuilds; final int nrfailedbuilds;
final int nrActiveBuilds;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -33,7 +35,10 @@ class SidePanel extends StatelessWidget {
), ),
), ),
const SizedBox(height: defaultPadding), const SizedBox(height: defaultPadding),
BuildsChart(nrbuilds: nrbuilds, nrfailedbuilds: nrfailedbuilds), BuildsChart(
nrbuilds: nrbuilds,
nrfailedbuilds: nrfailedbuilds,
nrActiveBuilds: nrActiveBuilds),
ChartCard( ChartCard(
color: const Color(0xff0a7005), color: const Color(0xff0a7005),
title: "Successful Builds", title: "Successful Builds",
@ -48,6 +53,13 @@ class SidePanel extends StatelessWidget {
"${(nrfailedbuilds * 100 / nrbuilds).toStringAsFixed(2)}%", "${(nrfailedbuilds * 100 / nrbuilds).toStringAsFixed(2)}%",
subtitle: nrfailedbuilds.toString(), subtitle: nrfailedbuilds.toString(),
), ),
ChartCard(
color: const Color(0xff9d8d00),
title: "Active Builds",
textRight:
"${(nrActiveBuilds * 100 / nrbuilds).toStringAsFixed(2)}%",
subtitle: nrActiveBuilds.toString(),
),
], ],
), ),
); );

View File

@ -49,7 +49,8 @@ class DashboardScreen extends StatelessWidget {
if (Responsive.isMobile(context)) if (Responsive.isMobile(context))
SidePanel( SidePanel(
nrbuilds: stats.total_builds, 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, flex: 2,
child: SidePanel( child: SidePanel(
nrbuilds: stats.total_builds, nrbuilds: stats.total_builds,
nrfailedbuilds: stats.failed_builds), nrfailedbuilds: stats.failed_builds,
nrActiveBuilds: stats.active_builds),
), ),
], ],
) )