display api stuff in frontend
This commit is contained in:
parent
6faa995b19
commit
ce7a260760
@ -20,6 +20,5 @@ pub fn build_api() -> Vec<Route> {
|
|||||||
version_del,
|
version_del,
|
||||||
build_output,
|
build_output,
|
||||||
list_builds,
|
list_builds,
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use rocket::http::uri::Segments;
|
|||||||
use rocket::http::{ContentType, Method, Status};
|
use rocket::http::{ContentType, Method, Status};
|
||||||
use rocket::route::{Handler, Outcome};
|
use rocket::route::{Handler, Outcome};
|
||||||
use rocket::{Data, Request, Response, Route};
|
use rocket::{Data, Request, Response, Route};
|
||||||
use rust_embed::{RustEmbed};
|
use rust_embed::RustEmbed;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
|
@ -115,34 +115,37 @@ pub async fn build_output(
|
|||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
pub struct ListBuildsModel {
|
pub struct ListBuildsModel {
|
||||||
id: i32,
|
id: i32,
|
||||||
pkg_id: i32,
|
pkg_name: String,
|
||||||
version_id: i32,
|
version: String,
|
||||||
status: Option<i32>,
|
status: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[openapi(tag = "test")]
|
#[openapi(tag = "test")]
|
||||||
#[get("/builds?<pkgid>")]
|
#[get("/builds?<pkgid>")]
|
||||||
pub async fn list_builds(
|
pub async fn list_builds(
|
||||||
db: &State<DatabaseConnection>,
|
db: &State<DatabaseConnection>,
|
||||||
pkgid: i32,
|
pkgid: Option<i32>,
|
||||||
) -> Result<Json<Vec<ListBuildsModel>>, NotFound<String>> {
|
) -> Result<Json<Vec<ListBuildsModel>>, NotFound<String>> {
|
||||||
let db = db as &DatabaseConnection;
|
let db = db as &DatabaseConnection;
|
||||||
|
|
||||||
let build = Builds::find()
|
let basequery = Builds::find()
|
||||||
|
.join_rev(JoinType::InnerJoin, packages::Relation::Builds.def())
|
||||||
|
.join_rev(JoinType::InnerJoin, versions::Relation::Builds.def())
|
||||||
|
.select_only()
|
||||||
|
.column_as(builds::Column::Id, "id")
|
||||||
|
.column(builds::Column::Status)
|
||||||
|
.column_as(packages::Column::Name, "pkg_name")
|
||||||
|
.column(versions::Column::Version);
|
||||||
|
|
||||||
|
let build = match pkgid {
|
||||||
|
None => basequery.into_model::<ListBuildsModel>().all(db),
|
||||||
|
Some(pkgid) => basequery
|
||||||
.filter(builds::Column::PkgId.eq(pkgid))
|
.filter(builds::Column::PkgId.eq(pkgid))
|
||||||
.all(db)
|
.into_model::<ListBuildsModel>()
|
||||||
|
.all(db),
|
||||||
|
}
|
||||||
.await
|
.await
|
||||||
.map_err(|e| NotFound(e.to_string()))?;
|
.map_err(|e| NotFound(e.to_string()))?;
|
||||||
|
|
||||||
Ok(Json(
|
Ok(Json(build))
|
||||||
build
|
|
||||||
.iter()
|
|
||||||
.map(|x| ListBuildsModel {
|
|
||||||
id: x.id,
|
|
||||||
status: x.status,
|
|
||||||
pkg_id: x.pkg_id,
|
|
||||||
version_id: x.version_id,
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
mod add;
|
mod add;
|
||||||
pub mod backend;
|
pub mod backend;
|
||||||
mod list;
|
|
||||||
mod remove;
|
|
||||||
#[cfg(feature = "static")]
|
#[cfg(feature = "static")]
|
||||||
pub mod embed;
|
pub mod embed;
|
||||||
|
mod list;
|
||||||
|
mod remove;
|
||||||
|
@ -71,7 +71,6 @@ pub async fn init(db: DatabaseConnection, tx: Sender<Action>) {
|
|||||||
|
|
||||||
new_build.status = Set(Some(1));
|
new_build.status = Set(Some(1));
|
||||||
let _ = new_build.update(&db).await;
|
let _ = new_build.update(&db).await;
|
||||||
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = set_pkg_status(
|
let _ = set_pkg_status(
|
||||||
@ -82,7 +81,7 @@ pub async fn init(db: DatabaseConnection, tx: Sender<Action>) {
|
|||||||
.await;
|
.await;
|
||||||
let _ = version_model.update(&db).await;
|
let _ = version_model.update(&db).await;
|
||||||
|
|
||||||
new_build.status = Set(Some(1));
|
new_build.status = Set(Some(2));
|
||||||
let _ = new_build.update(&db).await;
|
let _ = new_build.update(&db).await;
|
||||||
|
|
||||||
println!("Error: {e}")
|
println!("Error: {e}")
|
||||||
|
@ -17,6 +17,30 @@ pub struct Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {}
|
pub enum Relation {
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::versions::Entity",
|
||||||
|
from = "Column::VersionId",
|
||||||
|
to = "super::versions::Column::Id"
|
||||||
|
)]
|
||||||
|
Versions,
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::packages::Entity",
|
||||||
|
from = "Column::PkgId",
|
||||||
|
to = "super::packages::Column::Id"
|
||||||
|
)]
|
||||||
|
Packages,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::versions::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Versions.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::packages::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Packages.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
@ -14,16 +14,24 @@ pub struct Model {
|
|||||||
pub status: i32,
|
pub status: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
#[sea_orm(has_many = "super::versions::Entity")]
|
#[sea_orm(has_many = "super::versions::Entity")]
|
||||||
Versions,
|
Versions,
|
||||||
|
#[sea_orm(has_many = "super::builds::Entity")]
|
||||||
|
Builds,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
impl Related<super::versions::Entity> for Entity {
|
impl Related<super::versions::Entity> for Entity {
|
||||||
fn to() -> RelationDef {
|
fn to() -> RelationDef {
|
||||||
Relation::Versions.def()
|
Relation::Versions.def()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Related<super::builds::Entity> for crate::db::versions::Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
crate::db::versions::Relation::Builds.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,6 +23,8 @@ pub enum Relation {
|
|||||||
to = "super::packages::Column::Id"
|
to = "super::packages::Column::Id"
|
||||||
)]
|
)]
|
||||||
Packages,
|
Packages,
|
||||||
|
#[sea_orm(has_many = "super::builds::Entity")]
|
||||||
|
Builds,
|
||||||
}
|
}
|
||||||
|
|
||||||
// `Related` trait has to be implemented by hand
|
// `Related` trait has to be implemented by hand
|
||||||
@ -32,4 +34,10 @@ impl Related<super::packages::Entity> for Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// impl Related<super::builds::Entity> for Entity {
|
||||||
|
// fn to() -> RelationDef {
|
||||||
|
// Relation::Builds.def()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
@ -6,6 +6,8 @@ mod pkgbuild;
|
|||||||
mod repo;
|
mod repo;
|
||||||
|
|
||||||
use crate::api::backend;
|
use crate::api::backend;
|
||||||
|
#[cfg(feature = "static")]
|
||||||
|
use crate::api::embed::CustomHandler;
|
||||||
use crate::builder::types::Action;
|
use crate::builder::types::Action;
|
||||||
use crate::db::migration::Migrator;
|
use crate::db::migration::Migrator;
|
||||||
use rocket::config::Config;
|
use rocket::config::Config;
|
||||||
@ -16,8 +18,6 @@ use sea_orm::{Database, DatabaseConnection};
|
|||||||
use sea_orm_migration::MigratorTrait;
|
use sea_orm_migration::MigratorTrait;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
#[cfg(feature = "static")]
|
|
||||||
use crate::api::embed::CustomHandler;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let t = tokio::runtime::Runtime::new().unwrap();
|
let t = tokio::runtime::Runtime::new().unwrap();
|
||||||
@ -56,7 +56,6 @@ fn main() {
|
|||||||
.manage(db)
|
.manage(db)
|
||||||
.manage(tx)
|
.manage(tx)
|
||||||
.mount("/", backend::build_api())
|
.mount("/", backend::build_api())
|
||||||
|
|
||||||
.mount(
|
.mount(
|
||||||
"/docs/",
|
"/docs/",
|
||||||
make_swagger_ui(&SwaggerUIConfig {
|
make_swagger_ui(&SwaggerUIConfig {
|
||||||
@ -67,9 +66,7 @@ fn main() {
|
|||||||
#[cfg(feature = "static")]
|
#[cfg(feature = "static")]
|
||||||
let rock = rock.mount("/", CustomHandler {});
|
let rock = rock.mount("/", CustomHandler {});
|
||||||
|
|
||||||
let rock = rock
|
let rock = rock.launch().await;
|
||||||
.launch()
|
|
||||||
.await;
|
|
||||||
match rock {
|
match rock {
|
||||||
Ok(_) => println!("Rocket shut down gracefully."),
|
Ok(_) => println!("Rocket shut down gracefully."),
|
||||||
Err(err) => println!("Rocket had an error: {}", err),
|
Err(err) => println!("Rocket had an error: {}", err),
|
||||||
|
4
frontend/lib/api/API.dart
Normal file
4
frontend/lib/api/API.dart
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
/// use this variable to access global api
|
||||||
|
final ApiClient API = ApiClient();
|
16
frontend/lib/api/api_client.dart
Normal file
16
frontend/lib/api/api_client.dart
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
class ApiClient {
|
||||||
|
static const String _apiBase = kDebugMode ? "http://localhost:8081" : "";
|
||||||
|
final Dio _dio = Dio(BaseOptions(baseUrl: _apiBase));
|
||||||
|
|
||||||
|
String? token;
|
||||||
|
DateTime? tokenValidUntil;
|
||||||
|
|
||||||
|
ApiClient();
|
||||||
|
|
||||||
|
Dio getRawClient() {
|
||||||
|
return _dio;
|
||||||
|
}
|
||||||
|
}
|
13
frontend/lib/api/builds.dart
Normal file
13
frontend/lib/api/builds.dart
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import '../core/models/build.dart';
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
extension BuildsAPI on ApiClient {
|
||||||
|
Future<List<Build>> listAllBuilds() async {
|
||||||
|
final resp = await getRawClient().get("/builds");
|
||||||
|
|
||||||
|
final responseObject = resp.data as List;
|
||||||
|
final List<Build> packages =
|
||||||
|
responseObject.map((e) => Build.fromJson(e)).toList(growable: false);
|
||||||
|
return packages;
|
||||||
|
}
|
||||||
|
}
|
22
frontend/lib/api/packages.dart
Normal file
22
frontend/lib/api/packages.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import '../core/models/package.dart';
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
extension PackagesAPI on ApiClient {
|
||||||
|
Future<List<Package>> listPackages() async {
|
||||||
|
final resp = await getRawClient().get("/packages/list");
|
||||||
|
print(resp.data);
|
||||||
|
|
||||||
|
// todo error handling
|
||||||
|
|
||||||
|
final responseObject = resp.data as List;
|
||||||
|
final List<Package> packages =
|
||||||
|
responseObject.map((e) => Package.fromJson(e)).toList(growable: false);
|
||||||
|
return packages;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> addPackage({bool force = false, required String name}) async {
|
||||||
|
final resp = await getRawClient().post("/packages/add", data: {'force_build': force, 'name': name});
|
||||||
|
print(resp.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
frontend/lib/core/models/build.dart
Normal file
19
frontend/lib/core/models/build.dart
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
class Build {
|
||||||
|
final int id;
|
||||||
|
final String pkg_name;
|
||||||
|
final String version;
|
||||||
|
final int status;
|
||||||
|
|
||||||
|
Build(
|
||||||
|
{required this.id,required this.pkg_name, required this.version,
|
||||||
|
required this.status});
|
||||||
|
|
||||||
|
factory Build.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Build(
|
||||||
|
id: json["id"] as int,
|
||||||
|
status: json["status"] as int,
|
||||||
|
pkg_name: json["pkg_name"] as String,
|
||||||
|
version: json["version"] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
21
frontend/lib/core/models/package.dart
Normal file
21
frontend/lib/core/models/package.dart
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
class Package {
|
||||||
|
final int id;
|
||||||
|
final String name;
|
||||||
|
final int count;
|
||||||
|
final int status;
|
||||||
|
|
||||||
|
Package(
|
||||||
|
{required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.count,
|
||||||
|
required this.status});
|
||||||
|
|
||||||
|
factory Package.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Package(
|
||||||
|
id: json["id"] as int,
|
||||||
|
count: json["count"] as int,
|
||||||
|
status: json["status"] as int,
|
||||||
|
name: json["name"] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -28,14 +28,15 @@ class _ChartState extends State<Chart> {
|
|||||||
aspectRatio: 1,
|
aspectRatio: 1,
|
||||||
child: PieChart(
|
child: PieChart(
|
||||||
PieChartData(
|
PieChartData(
|
||||||
pieTouchData:
|
pieTouchData: PieTouchData(
|
||||||
PieTouchData(touchCallback: (pieTouchResponse, touchresponse) {
|
touchCallback: (pieTouchResponse, touchresponse) {
|
||||||
setState(() {
|
setState(() {
|
||||||
// final desiredTouch = pieTouchResponse.touchInput
|
// final desiredTouch = pieTouchResponse.touchInput
|
||||||
// is! PointerExitEvent &&
|
// is! PointerExitEvent &&
|
||||||
// pieTouchResponse.touchInput is! PointerUpEvent;
|
// pieTouchResponse.touchInput is! PointerUpEvent;
|
||||||
if (touchresponse?.touchedSection != null) {
|
if (touchresponse?.touchedSection != null) {
|
||||||
touchedIndex = touchresponse!.touchedSection!.touchedSectionIndex;
|
touchedIndex = touchresponse!
|
||||||
|
.touchedSection!.touchedSectionIndex;
|
||||||
} else {
|
} else {
|
||||||
touchedIndex = -1;
|
touchedIndex = -1;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import 'package:aurcache/api/packages.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
|
||||||
|
import '../../../api/API.dart';
|
||||||
import '../../../core/constants/color_constants.dart';
|
import '../../../core/constants/color_constants.dart';
|
||||||
import '../../../responsive.dart';
|
import '../../../responsive.dart';
|
||||||
|
|
||||||
@ -31,7 +33,7 @@ class Header extends StatelessWidget {
|
|||||||
height: 8,
|
height: 8,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
"Welcome to AURCentral",
|
"Welcome to your Build server",
|
||||||
style: Theme.of(context).textTheme.subtitle2,
|
style: Theme.of(context).textTheme.subtitle2,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -82,29 +84,35 @@ class ProfileCard extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SearchField extends StatelessWidget {
|
class SearchField extends StatelessWidget {
|
||||||
const SearchField({
|
SearchField({
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final controller = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return TextField(
|
return TextField(
|
||||||
|
controller: controller,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: "Search",
|
hintText: "Search",
|
||||||
fillColor: secondaryColor,
|
fillColor: secondaryColor,
|
||||||
filled: true,
|
filled: true,
|
||||||
border: OutlineInputBorder(
|
border: const OutlineInputBorder(
|
||||||
borderSide: BorderSide.none,
|
borderSide: BorderSide.none,
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||||
),
|
),
|
||||||
suffixIcon: InkWell(
|
suffixIcon: InkWell(
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
// todo this is only temporary -> add this to a proper page
|
||||||
|
API.addPackage(name: controller.text);
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.all(defaultPadding * 0.75),
|
padding: EdgeInsets.all(defaultPadding * 0.75),
|
||||||
margin: EdgeInsets.symmetric(horizontal: defaultPadding / 2),
|
margin: EdgeInsets.symmetric(horizontal: defaultPadding / 2),
|
||||||
decoration: BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
color: greenColor,
|
color: greenColor,
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||||
),
|
),
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
"assets/icons/Search.svg",
|
"assets/icons/Search.svg",
|
||||||
|
@ -30,8 +30,7 @@ class MiniInformation extends StatelessWidget {
|
|||||||
defaultPadding / (Responsive.isMobile(context) ? 2 : 1),
|
defaultPadding / (Responsive.isMobile(context) ? 2 : 1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {},
|
||||||
},
|
|
||||||
icon: Icon(Icons.add),
|
icon: Icon(Icons.add),
|
||||||
label: Text(
|
label: Text(
|
||||||
"Add New",
|
"Add New",
|
||||||
@ -68,7 +67,7 @@ class InformationCard extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GridView.builder(
|
return GridView.builder(
|
||||||
physics: NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: dailyDatas.length,
|
itemCount: dailyDatas.length,
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
@ -21,10 +21,10 @@ class _MiniInformationWidgetState extends State<MiniInformationWidget> {
|
|||||||
@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,
|
||||||
|
@ -1,12 +1,45 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:aurcache/api/builds.dart';
|
||||||
|
import 'package:aurcache/core/models/build.dart';
|
||||||
|
import 'package:aurcache/screens/dashboard/components/your_packages.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../api/API.dart';
|
||||||
import '../../../core/constants/color_constants.dart';
|
import '../../../core/constants/color_constants.dart';
|
||||||
|
import '../../../core/models/package.dart';
|
||||||
|
|
||||||
class RecentBuilds extends StatelessWidget {
|
class RecentBuilds extends StatefulWidget {
|
||||||
const RecentBuilds({
|
const RecentBuilds({
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RecentBuilds> createState() => _RecentBuildsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecentBuildsState extends State<RecentBuilds> {
|
||||||
|
late Future<List<Build>> dataFuture;
|
||||||
|
Timer? timer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
dataFuture = API.listAllBuilds();
|
||||||
|
|
||||||
|
timer = Timer.periodic(
|
||||||
|
const Duration(seconds: 10),
|
||||||
|
(Timer t) => setState(() {
|
||||||
|
dataFuture = API.listAllBuilds();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
timer?.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@ -24,10 +57,14 @@ class RecentBuilds extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: DataTable(
|
child: FutureBuilder(
|
||||||
|
future: dataFuture,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
return DataTable(
|
||||||
horizontalMargin: 0,
|
horizontalMargin: 0,
|
||||||
columnSpacing: defaultPadding,
|
columnSpacing: defaultPadding,
|
||||||
columns: [
|
columns: const [
|
||||||
DataColumn(
|
DataColumn(
|
||||||
label: Text("Build ID"),
|
label: Text("Build ID"),
|
||||||
),
|
),
|
||||||
@ -41,24 +78,28 @@ class RecentBuilds extends StatelessWidget {
|
|||||||
label: Text("Status"),
|
label: Text("Status"),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
rows: List.generate(
|
rows: snapshot.data!.map((e) => recentUserDataRow(e)).toList(),
|
||||||
7,
|
);
|
||||||
(index) => recentUserDataRow(),
|
} else {
|
||||||
),
|
return Text("no data");
|
||||||
),
|
}
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataRow recentUserDataRow() {
|
DataRow recentUserDataRow(Build build) {
|
||||||
return DataRow(
|
return DataRow(
|
||||||
cells: [
|
cells: [
|
||||||
DataCell(Text("1")),
|
DataCell(Text(build.id.toString())),
|
||||||
DataCell(Text("Resources")),
|
DataCell(Text(build.pkg_name)),
|
||||||
DataCell(Text("v1.2.3")),
|
DataCell(Text(build.version)),
|
||||||
DataCell(Icon(Icons.watch_later_outlined, color: Color(0xFF9D8D00),)),
|
DataCell(Icon(
|
||||||
|
switchSuccessIcon(build.status),
|
||||||
|
color: switchSuccessColor(build.status),
|
||||||
|
)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../../../core/constants/color_constants.dart';
|
|
||||||
|
|
||||||
class RecentUsers extends StatelessWidget {
|
|
||||||
const RecentUsers({
|
|
||||||
Key? key,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
padding: EdgeInsets.all(defaultPadding),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: secondaryColor,
|
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"Your Packages",
|
|
||||||
style: Theme.of(context).textTheme.subtitle1,
|
|
||||||
),
|
|
||||||
SingleChildScrollView(
|
|
||||||
//scrollDirection: Axis.horizontal,
|
|
||||||
child: SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: DataTable(
|
|
||||||
horizontalMargin: 0,
|
|
||||||
columnSpacing: defaultPadding,
|
|
||||||
columns: [
|
|
||||||
DataColumn(
|
|
||||||
label: Text("Package ID"),
|
|
||||||
),
|
|
||||||
DataColumn(
|
|
||||||
label: Text("Package Name"),
|
|
||||||
),
|
|
||||||
DataColumn(
|
|
||||||
label: Text("Number of versions"),
|
|
||||||
),
|
|
||||||
DataColumn(
|
|
||||||
label: Text("Status"),
|
|
||||||
),
|
|
||||||
DataColumn(
|
|
||||||
label: Text("Action"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
rows: List.generate(
|
|
||||||
7,
|
|
||||||
(index) => recentUserDataRow(context),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DataRow recentUserDataRow(BuildContext context) {
|
|
||||||
return DataRow(
|
|
||||||
cells: [
|
|
||||||
DataCell(Text("1")),
|
|
||||||
DataCell(Text("Resources")),
|
|
||||||
DataCell(Text("2")),
|
|
||||||
DataCell(Icon(Icons.watch_later_outlined, color: Color(0xFF9D8D00),)),
|
|
||||||
DataCell(
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
TextButton(
|
|
||||||
child: Text('View', style: TextStyle(color: greenColor)),
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 6,
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
child: Text("Delete", style: TextStyle(color: Colors.redAccent)),
|
|
||||||
onPressed: () {
|
|
||||||
|
|
||||||
},
|
|
||||||
// Delete
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
import 'package:aurcache/screens/dashboard/components/user_details_mini_card.dart';
|
import 'package:aurcache/screens/dashboard/components/chart_card.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../../core/constants/color_constants.dart';
|
import '../../../core/constants/color_constants.dart';
|
||||||
|
162
frontend/lib/screens/dashboard/components/your_packages.dart
Normal file
162
frontend/lib/screens/dashboard/components/your_packages.dart
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:aurcache/api/packages.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../api/API.dart';
|
||||||
|
import '../../../core/constants/color_constants.dart';
|
||||||
|
import '../../../core/models/package.dart';
|
||||||
|
|
||||||
|
class YourPackages extends StatefulWidget {
|
||||||
|
const YourPackages({
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<YourPackages> createState() => _YourPackagesState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _YourPackagesState extends State<YourPackages> {
|
||||||
|
late Future<List<Package>> dataFuture;
|
||||||
|
Timer? timer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
dataFuture = API.listPackages();
|
||||||
|
|
||||||
|
timer = Timer.periodic(
|
||||||
|
const Duration(seconds: 10),
|
||||||
|
(Timer t) => setState(() {
|
||||||
|
dataFuture = API.listPackages();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
timer?.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(defaultPadding),
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: secondaryColor,
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Your Packages",
|
||||||
|
style: Theme.of(context).textTheme.subtitle1,
|
||||||
|
),
|
||||||
|
SingleChildScrollView(
|
||||||
|
//scrollDirection: Axis.horizontal,
|
||||||
|
child: SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: FutureBuilder(
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
return DataTable(
|
||||||
|
horizontalMargin: 0,
|
||||||
|
columnSpacing: defaultPadding,
|
||||||
|
columns: const [
|
||||||
|
DataColumn(
|
||||||
|
label: Text("Package ID"),
|
||||||
|
),
|
||||||
|
DataColumn(
|
||||||
|
label: Text("Package Name"),
|
||||||
|
),
|
||||||
|
DataColumn(
|
||||||
|
label: Text("Number of versions"),
|
||||||
|
),
|
||||||
|
DataColumn(
|
||||||
|
label: Text("Status"),
|
||||||
|
),
|
||||||
|
DataColumn(
|
||||||
|
label: Text("Action"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
rows: snapshot.data!
|
||||||
|
.map((e) => buildDataRow(e))
|
||||||
|
.toList(growable: false),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return const Text("No data");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
future: dataFuture,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataRow buildDataRow(Package package) {
|
||||||
|
return DataRow(
|
||||||
|
cells: [
|
||||||
|
DataCell(Text(package.id.toString())),
|
||||||
|
DataCell(Text(package.name)),
|
||||||
|
DataCell(Text(package.count.toString())),
|
||||||
|
DataCell(IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
switchSuccessIcon(package.status),
|
||||||
|
color: switchSuccessColor(package.status),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
// todo open build info with logs
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
DataCell(
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('View', style: TextStyle(color: greenColor)),
|
||||||
|
onPressed: () {},
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 6,
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
child: const Text("Delete",
|
||||||
|
style: TextStyle(color: Colors.redAccent)),
|
||||||
|
onPressed: () {},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IconData switchSuccessIcon(int status) {
|
||||||
|
switch (status) {
|
||||||
|
case 0:
|
||||||
|
return Icons.watch_later_outlined;
|
||||||
|
case 1:
|
||||||
|
return Icons.check_circle_outline;
|
||||||
|
case 2:
|
||||||
|
return Icons.cancel_outlined;
|
||||||
|
default:
|
||||||
|
return Icons.question_mark_outlined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Color switchSuccessColor(int status) {
|
||||||
|
switch (status) {
|
||||||
|
case 0:
|
||||||
|
return const Color(0xFF9D8D00);
|
||||||
|
case 1:
|
||||||
|
return const Color(0xFF0A6900);
|
||||||
|
case 2:
|
||||||
|
return const Color(0xff760707);
|
||||||
|
default:
|
||||||
|
return const Color(0xFF9D8D00);
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ import '../../responsive.dart';
|
|||||||
import 'components/header.dart';
|
import 'components/header.dart';
|
||||||
import 'components/mini_information_card.dart';
|
import 'components/mini_information_card.dart';
|
||||||
import 'components/recent_builds.dart';
|
import 'components/recent_builds.dart';
|
||||||
import 'components/recent_users.dart';
|
import 'components/your_packages.dart';
|
||||||
import 'components/user_details_widget.dart';
|
import 'components/user_details_widget.dart';
|
||||||
|
|
||||||
class DashboardScreen extends StatelessWidget {
|
class DashboardScreen extends StatelessWidget {
|
||||||
@ -29,7 +29,7 @@ class DashboardScreen extends StatelessWidget {
|
|||||||
flex: 5,
|
flex: 5,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
RecentUsers(),
|
YourPackages(),
|
||||||
SizedBox(height: defaultPadding),
|
SizedBox(height: defaultPadding),
|
||||||
RecentBuilds(),
|
RecentBuilds(),
|
||||||
if (Responsive.isMobile(context))
|
if (Responsive.isMobile(context))
|
||||||
|
@ -15,7 +15,7 @@ class SideMenu extends StatelessWidget {
|
|||||||
// it enables scrolling
|
// it enables scrolling
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
DrawerHeader(
|
const DrawerHeader(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
@ -29,7 +29,7 @@ class SideMenu extends StatelessWidget {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: defaultPadding,
|
height: defaultPadding,
|
||||||
),
|
),
|
||||||
Text("AUR Build Server")
|
Text("AURCache")
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
DrawerListTile(
|
DrawerListTile(
|
||||||
|
@ -65,6 +65,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.6"
|
version: "1.0.6"
|
||||||
|
dio:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: dio
|
||||||
|
sha256: "797e1e341c3dd2f69f2dad42564a6feff3bfb87187d05abb93b9609e6f1645c3"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.4.0"
|
||||||
equatable:
|
equatable:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -36,12 +36,9 @@ dependencies:
|
|||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
fl_chart: ^0.66.0
|
fl_chart: ^0.66.0
|
||||||
# flutter_icons:
|
|
||||||
# git:
|
|
||||||
# url: https://github.com/DaveatCor/flutter_icons_fork.git
|
|
||||||
# branch: master
|
|
||||||
flutter_svg: ^2.0.9
|
flutter_svg: ^2.0.9
|
||||||
google_fonts: ^6.1.0
|
google_fonts: ^6.1.0
|
||||||
|
dio: ^5.3.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
Reference in New Issue
Block a user