mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add pin
This commit is contained in:
@@ -51,4 +51,12 @@ class Api {
|
|||||||
static Future<HttpResponse<NullResponse>> delTask(String cron) async {
|
static Future<HttpResponse<NullResponse>> delTask(String cron) async {
|
||||||
return await Http.delete<NullResponse>(Url.ADD_TASK, [cron]);
|
return await Http.delete<NullResponse>(Url.ADD_TASK, [cron]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<HttpResponse<NullResponse>> pinTask(String cron) async {
|
||||||
|
return await Http.put<NullResponse>(Url.PIN_TASK, [cron]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<HttpResponse<NullResponse>> unpinTask(String cron) async {
|
||||||
|
return await Http.put<NullResponse>(Url.UNPIN_TASK, [cron]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ class Url {
|
|||||||
static const STOP_TASKS = "/api/crons/stop";
|
static const STOP_TASKS = "/api/crons/stop";
|
||||||
static const TASK_DETAIL = "/api/crons/";
|
static const TASK_DETAIL = "/api/crons/";
|
||||||
static const ADD_TASK = "/api/crons";
|
static const ADD_TASK = "/api/crons";
|
||||||
|
static const PIN_TASK = "/api/crons/pin";
|
||||||
|
static const UNPIN_TASK = "/api/crons/unpin";
|
||||||
|
|
||||||
static INTIME_LOG(String cronId) {
|
static INTIME_LOG(String cronId) {
|
||||||
return "/api/crons/$cronId/log";
|
return "/api/crons/$cronId/log";
|
||||||
|
|||||||
@@ -157,10 +157,9 @@ class TaskItemCell extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: Container(
|
child: Container(
|
||||||
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.searchBarBg() : Colors.transparent,
|
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.searchBarBg() : Colors.transparent,
|
||||||
margin: const EdgeInsets.only(bottom: 7, top: 7),
|
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 15,
|
horizontal: 15,
|
||||||
vertical: 5,
|
vertical: 8,
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -204,7 +203,7 @@ class TaskItemCell extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 5,
|
height: 8,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
bean.schedule ?? "",
|
bean.schedule ?? "",
|
||||||
@@ -324,6 +323,7 @@ class TaskItemCell extends StatelessWidget {
|
|||||||
child: Text(bean.isPinned! == 0 ? "置顶" : "取消置顶"),
|
child: Text(bean.isPinned! == 0 ? "置顶" : "取消置顶"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
pinTask();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -331,6 +331,10 @@ class TaskItemCell extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pinTask() {
|
||||||
|
ref.read(taskProvider).pinTask(bean.sId!, bean.isPinned!);
|
||||||
|
}
|
||||||
|
|
||||||
void delTask(BuildContext context, WidgetRef ref) {
|
void delTask(BuildContext context, WidgetRef ref) {
|
||||||
showCupertinoDialog(
|
showCupertinoDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:qinglong_app/base/base_viewmodel.dart';
|
import 'package:qinglong_app/base/base_viewmodel.dart';
|
||||||
import 'package:qinglong_app/base/http/api.dart';
|
import 'package:qinglong_app/base/http/api.dart';
|
||||||
import 'package:qinglong_app/base/http/http.dart';
|
import 'package:qinglong_app/base/http/http.dart';
|
||||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||||
import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart';
|
|
||||||
|
|
||||||
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
||||||
|
|
||||||
@@ -42,6 +38,9 @@ class TaskViewModel extends BaseViewModel {
|
|||||||
list.sort((a, b) {
|
list.sort((a, b) {
|
||||||
return a.status!.compareTo(b.status!);
|
return a.status!.compareTo(b.status!);
|
||||||
});
|
});
|
||||||
|
list.sort((a, b) {
|
||||||
|
return b.isPinned!.compareTo(a.isPinned!);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> runCrons(String cron) async {
|
Future<void> runCrons(String cron) async {
|
||||||
@@ -85,4 +84,28 @@ class TaskViewModel extends BaseViewModel {
|
|||||||
bean.command = result.command;
|
bean.command = result.command;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pinTask(String sId, int isPinned) async {
|
||||||
|
if (isPinned == 1) {
|
||||||
|
HttpResponse<NullResponse> response = await Api.unpinTask(sId);
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
list.firstWhere((element) => element.sId == sId).isPinned = 0;
|
||||||
|
sortList();
|
||||||
|
success();
|
||||||
|
} else {
|
||||||
|
failToast(response.message, notify: true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
HttpResponse<NullResponse> response = await Api.pinTask(sId);
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
list.firstWhere((element) => element.sId == sId).isPinned = 1;
|
||||||
|
sortList();
|
||||||
|
success();
|
||||||
|
} else {
|
||||||
|
failToast(response.message, notify: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user