mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-05 00:50:49 +08:00
feat: seperate active and archived activities
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
"polaris/log"
|
||||
"polaris/pkg/utils"
|
||||
"strconv"
|
||||
@@ -18,9 +19,16 @@ type Activity struct {
|
||||
}
|
||||
|
||||
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
||||
q := c.Query("status")
|
||||
his := s.db.GetHistories()
|
||||
var activities = make([]Activity, 0, len(his))
|
||||
for _, h := range his {
|
||||
if q == "active" && (h.Status != history.StatusRunning && h.Status != history.StatusUploading) {
|
||||
continue //active downloads
|
||||
} else if q == "archive" && (h.Status == history.StatusRunning || h.Status == history.StatusUploading) {
|
||||
continue //archived downloads
|
||||
}
|
||||
|
||||
a := Activity{
|
||||
History: h,
|
||||
}
|
||||
|
||||
@@ -5,39 +5,88 @@ import 'package:ui/providers/activity.dart';
|
||||
import 'package:ui/utils.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
|
||||
class ActivityPage extends ConsumerWidget {
|
||||
class ActivityPage extends ConsumerStatefulWidget {
|
||||
const ActivityPage({super.key});
|
||||
static const route = "/activities";
|
||||
|
||||
const ActivityPage({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
var activitiesWatcher = ref.watch(activitiesDataProvider);
|
||||
_ActivityPageState createState() => _ActivityPageState();
|
||||
}
|
||||
|
||||
return activitiesWatcher.when(
|
||||
data: (activities) {
|
||||
return SingleChildScrollView(
|
||||
child: PaginatedDataTable(
|
||||
rowsPerPage: 10,
|
||||
columns: const [
|
||||
DataColumn(label: Text("#"), numeric: true),
|
||||
DataColumn(label: Text("名称")),
|
||||
DataColumn(label: Text("开始时间")),
|
||||
DataColumn(label: Text("状态")),
|
||||
DataColumn(label: Text("操作"))
|
||||
],
|
||||
source: ActivityDataSource(
|
||||
activities: activities, onDelete: onDelete(ref)),
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
with TickerProviderStateMixin {
|
||||
late TabController _nestedTabController;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_nestedTabController = new TabController(length: 2, vsync: this);
|
||||
}
|
||||
|
||||
Function(int) onDelete(WidgetRef ref) {
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_nestedTabController.dispose();
|
||||
}
|
||||
|
||||
int selectedTab = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TabBar(
|
||||
controller: _nestedTabController,
|
||||
isScrollable: true,
|
||||
onTap: (value) {
|
||||
setState(() {
|
||||
selectedTab = value;
|
||||
});
|
||||
},
|
||||
tabs: const <Widget>[
|
||||
Tab(
|
||||
text: "下载中",
|
||||
),
|
||||
Tab(
|
||||
text: "历史记录",
|
||||
),
|
||||
],
|
||||
),
|
||||
Builder(builder: (context) {
|
||||
var activitiesWatcher = ref.watch(activitiesDataProvider("active"));
|
||||
if (selectedTab == 1) {
|
||||
activitiesWatcher = ref.watch(activitiesDataProvider("archive"));
|
||||
}
|
||||
|
||||
return activitiesWatcher.when(
|
||||
data: (activities) {
|
||||
return SingleChildScrollView(
|
||||
child: PaginatedDataTable(
|
||||
rowsPerPage: 10,
|
||||
columns: const [
|
||||
DataColumn(label: Text("#"), numeric: true),
|
||||
DataColumn(label: Text("名称")),
|
||||
DataColumn(label: Text("开始时间")),
|
||||
DataColumn(label: Text("状态")),
|
||||
DataColumn(label: Text("操作"))
|
||||
],
|
||||
source: ActivityDataSource(
|
||||
activities: activities,
|
||||
onDelete: selectedTab == 0 ? onDelete() : null),
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
})
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Function(int) onDelete() {
|
||||
return (id) {
|
||||
ref
|
||||
.read(activitiesDataProvider.notifier)
|
||||
.read(activitiesDataProvider("active").notifier)
|
||||
.deleteActivity(id)
|
||||
.whenComplete(() => Utils.showSnakeBar("删除成功"))
|
||||
.onError((error, trace) => Utils.showSnakeBar("删除失败:$error"));
|
||||
@@ -47,8 +96,8 @@ class ActivityPage extends ConsumerWidget {
|
||||
|
||||
class ActivityDataSource extends DataTableSource {
|
||||
List<Activity> activities;
|
||||
Function(int) onDelete;
|
||||
ActivityDataSource({required this.activities, required this.onDelete});
|
||||
Function(int)? onDelete;
|
||||
ActivityDataSource({required this.activities, this.onDelete});
|
||||
|
||||
@override
|
||||
int get rowCount => activities.length;
|
||||
@@ -96,11 +145,13 @@ class ActivityDataSource extends DataTableSource {
|
||||
progressColor: Colors.green,
|
||||
);
|
||||
}()),
|
||||
DataCell(Tooltip(
|
||||
message: "删除任务",
|
||||
child: IconButton(
|
||||
onPressed: () => onDelete(activity.id!),
|
||||
icon: const Icon(Icons.delete))))
|
||||
onDelete != null
|
||||
? DataCell(Tooltip(
|
||||
message: "删除任务",
|
||||
child: IconButton(
|
||||
onPressed: () => onDelete!(activity.id!),
|
||||
icon: const Icon(Icons.delete))))
|
||||
: const DataCell(Text(""))
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/providers/server_response.dart';
|
||||
|
||||
var activitiesDataProvider =
|
||||
AsyncNotifierProvider.autoDispose<ActivityData, List<Activity>>(
|
||||
AsyncNotifierProvider.autoDispose.family<ActivityData, List<Activity>, String>(
|
||||
ActivityData.new);
|
||||
|
||||
var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
@@ -24,14 +24,18 @@ var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
},
|
||||
);
|
||||
|
||||
class ActivityData extends AutoDisposeAsyncNotifier<List<Activity>> {
|
||||
class ActivityData
|
||||
extends AutoDisposeFamilyAsyncNotifier<List<Activity>, String> {
|
||||
@override
|
||||
FutureOr<List<Activity>> build() async {
|
||||
Timer(
|
||||
const Duration(seconds: 5), ref.invalidateSelf); //Periodically Refresh
|
||||
FutureOr<List<Activity>> build(String arg) async {
|
||||
if (arg == "active") {
|
||||
//refresh active downloads
|
||||
Timer(const Duration(seconds: 5),
|
||||
ref.invalidateSelf); //Periodically Refresh
|
||||
}
|
||||
|
||||
final dio = await APIs.getDio();
|
||||
var resp = await dio.get(APIs.activityUrl);
|
||||
var resp = await dio.get(APIs.activityUrl, queryParameters: {"status": arg});
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
|
||||
Reference in New Issue
Block a user