2023-12-29 17:13:51 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:aurcache/api/packages.dart';
|
2024-01-01 16:11:05 +00:00
|
|
|
import 'package:aurcache/components/api/APIBuilder.dart';
|
2023-12-30 21:23:42 +00:00
|
|
|
import 'package:aurcache/providers/packages_provider.dart';
|
2023-12-29 17:13:51 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-12-30 21:23:42 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2023-12-29 17:13:51 +00:00
|
|
|
|
2023-12-29 23:45:33 +00:00
|
|
|
import '../../api/API.dart';
|
|
|
|
import '../../constants/color_constants.dart';
|
|
|
|
import '../../models/package.dart';
|
2023-12-30 21:23:42 +00:00
|
|
|
import '../../providers/builds_provider.dart';
|
|
|
|
import '../../providers/stats_provider.dart';
|
|
|
|
import '../confirm_popup.dart';
|
2023-12-29 17:13:51 +00:00
|
|
|
|
|
|
|
class YourPackages extends StatefulWidget {
|
|
|
|
const YourPackages({
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<YourPackages> createState() => _YourPackagesState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _YourPackagesState extends State<YourPackages> {
|
|
|
|
@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,
|
2023-12-30 21:23:42 +00:00
|
|
|
child: APIBuilder<PackagesProvider, List<Package>, Object>(
|
2024-01-01 16:11:05 +00:00
|
|
|
key: Key("Packages on dashboard"),
|
2023-12-30 21:23:42 +00:00
|
|
|
interval: const Duration(seconds: 10),
|
|
|
|
onData: (data) {
|
|
|
|
return DataTable(
|
2023-12-29 17:13:51 +00:00
|
|
|
horizontalMargin: 0,
|
|
|
|
columnSpacing: defaultPadding,
|
|
|
|
columns: const [
|
|
|
|
DataColumn(
|
|
|
|
label: Text("Package ID"),
|
|
|
|
),
|
|
|
|
DataColumn(
|
|
|
|
label: Text("Package Name"),
|
|
|
|
),
|
|
|
|
DataColumn(
|
2024-01-01 22:07:52 +00:00
|
|
|
label: Text("Version"),
|
|
|
|
),
|
|
|
|
DataColumn(
|
|
|
|
label: Text("Up-To-Date"),
|
2023-12-29 17:13:51 +00:00
|
|
|
),
|
|
|
|
DataColumn(
|
|
|
|
label: Text("Status"),
|
|
|
|
),
|
|
|
|
DataColumn(
|
|
|
|
label: Text("Action"),
|
|
|
|
),
|
|
|
|
],
|
2023-12-30 21:23:42 +00:00
|
|
|
rows: data
|
2023-12-29 17:13:51 +00:00
|
|
|
.map((e) => buildDataRow(e))
|
2023-12-30 21:23:42 +00:00
|
|
|
.toList(growable: false));
|
2023-12-29 17:13:51 +00:00
|
|
|
},
|
2023-12-30 21:23:42 +00:00
|
|
|
onLoad: () => const Text("No data"),
|
2023-12-29 17:13:51 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
DataRow buildDataRow(Package package) {
|
|
|
|
return DataRow(
|
|
|
|
cells: [
|
|
|
|
DataCell(Text(package.id.toString())),
|
|
|
|
DataCell(Text(package.name)),
|
2024-01-01 22:07:52 +00:00
|
|
|
DataCell(Text(package.latest_version.toString())),
|
|
|
|
DataCell(IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
package.outofdate ? Icons.update : Icons.verified,
|
|
|
|
color: package.outofdate ? Color(0xFF6B43A4) : Color(0xFF0A6900),
|
|
|
|
),
|
|
|
|
onPressed: package.outofdate
|
|
|
|
? () {
|
|
|
|
// todo open build info with logs
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
)),
|
2023-12-29 17:13:51 +00:00
|
|
|
DataCell(IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
switchSuccessIcon(package.status),
|
|
|
|
color: switchSuccessColor(package.status),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
2024-01-01 22:07:52 +00:00
|
|
|
//context.push("/build/${package.latest_version_id}");
|
2023-12-29 17:13:51 +00:00
|
|
|
},
|
|
|
|
)),
|
|
|
|
DataCell(
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
TextButton(
|
|
|
|
child: const Text('View', style: TextStyle(color: greenColor)),
|
2023-12-30 21:23:42 +00:00
|
|
|
onPressed: () {
|
|
|
|
context.push("/package/${package.id}");
|
|
|
|
},
|
2023-12-29 17:13:51 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 6,
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
child: const Text("Delete",
|
|
|
|
style: TextStyle(color: Colors.redAccent)),
|
2023-12-30 21:23:42 +00:00
|
|
|
onPressed: () async {
|
|
|
|
final confirmResult =
|
|
|
|
await showDeleteConfirmationDialog(context);
|
|
|
|
if (!confirmResult) return;
|
|
|
|
|
|
|
|
final succ = await API.deletePackage(package.id);
|
|
|
|
if (succ) {
|
|
|
|
Provider.of<PackagesProvider>(context, listen: false)
|
|
|
|
.refresh(context);
|
|
|
|
Provider.of<BuildsProvider>(context, listen: false)
|
|
|
|
.refresh(context);
|
|
|
|
Provider.of<StatsProvider>(context, listen: false)
|
|
|
|
.refresh(context);
|
|
|
|
}
|
|
|
|
},
|
2023-12-29 17:13:51 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2024-01-02 22:05:03 +00:00
|
|
|
case 3:
|
|
|
|
return Icons.pause_circle_outline;
|
2023-12-29 17:13:51 +00:00
|
|
|
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);
|
2024-01-02 22:05:03 +00:00
|
|
|
case 3:
|
|
|
|
return const Color(0xFF0044AA);
|
2023-12-29 17:13:51 +00:00
|
|
|
default:
|
|
|
|
return const Color(0xFF9D8D00);
|
|
|
|
}
|
|
|
|
}
|