1
0
mirror of https://github.com/go-vikunja/app synced 2024-10-04 21:28:30 +00:00

changed how options are used, fixed "only show tasks with due date"

This commit is contained in:
Benimautner 2023-07-24 00:00:37 +02:00
parent 6b276e511d
commit c4885b4d41
4 changed files with 46 additions and 42 deletions

@ -92,7 +92,7 @@ class TaskAPIService extends APIService implements TaskService {
Future<List<Task>?> getByOptions(TaskServiceOptions options) {
String optionString = options.getOptions();
return client
.get('/tasks/all?$optionString')
.get('/tasks/all$optionString')
.then((response) {
if (response == null) return null;
return convertList(response.body, (result) => Task.fromJson(result));

@ -9,6 +9,8 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart'as
import 'package:rxdart/subjects.dart' as rxSub;
import 'package:vikunja_app/service/services.dart';
import '../models/task.dart';
class NotificationClass {
final int? id;
final String? title;
@ -120,30 +122,18 @@ class NotificationClass {
}
Future<void> scheduleDueNotifications(TaskService taskService) async {
final tasks = await taskService.getByOptions(new TaskServiceOptions(newOptions: [
TaskServiceOption<TaskServiceOptionFilterBy>("filter_by", [
TaskServiceOptionFilterBy.done,
TaskServiceOptionFilterBy.due_date
]),
TaskServiceOption<TaskServiceOptionFilterComparator>(
"filter_comparator", [
TaskServiceOptionFilterComparator.equals,
TaskServiceOptionFilterComparator.greater
]),
TaskServiceOption<TaskServiceOptionFilterConcat>(
"filter_concat", TaskServiceOptionFilterConcat.and),
TaskServiceOption<TaskServiceOptionFilterValue>("filter_value", [
TaskServiceOptionFilterValue.enum_false,
DateTime.now().toUtc().toIso8601String()
]),
]));
Future<void> scheduleDueNotifications(TaskService taskService,
{List<Task>? tasks}) async {
if (tasks == null)
tasks = await taskService.getAll();
if (tasks == null) {
print("did not receive tasks on notification update");
return;
}
await notificationsPlugin.cancelAll();
for (final task in tasks) {
if(task.done)
continue;
for (final reminder in task.reminderDates) {
scheduleNotification(
"Reminder",

@ -224,19 +224,26 @@ class LandingPageState extends State<LandingPage>
.settingsManager
.getLandingPageOnlyDueDateTasks()
.then((showOnlyDueDateTasks) {
if (!showOnlyDueDateTasks) {
return VikunjaGlobal.of(context).taskService.getAll().then((value) => _handleTaskList(value));
} else {
return VikunjaGlobal
.of(context)
.taskService
.getByOptions(TaskServiceOptions())
.then<Future<void>?>((taskList) => _handleTaskList(taskList));
}
});
return VikunjaGlobal
.of(context)
.taskService
.getByOptions(TaskServiceOptions(
newOptions: [
TaskServiceOption<TaskServiceOptionFilterBy>("filter_by", "done"),
TaskServiceOption<TaskServiceOptionFilterValue>("filter_value", "false"),
],
clearOther: true
))
.then<Future<void>?>((taskList) => _handleTaskList(taskList, showOnlyDueDateTasks));
}).onError((error, stackTrace) {print("error");});
}
Future<void> _handleTaskList(List<Task>? taskList) {
Future<void> _handleTaskList(List<Task>? taskList, bool showOnlyDueDateTasks) {
if(showOnlyDueDateTasks)
taskList?.removeWhere((element) => element.dueDate == null || element.dueDate!.year == 0001);
taskList?.forEach((element) {print(element.dueDate);});
if (taskList != null && taskList.isEmpty) {
setState(() {
landingPageStatus = PageStatus.empty;

@ -73,9 +73,10 @@ class TaskServiceOption<T> {
}
}
List<TaskServiceOption> defaultOptions = [
final List<TaskServiceOption> defaultOptions = [
TaskServiceOption<TaskServiceOptionSortBy>("sort_by",
[TaskServiceOptionSortBy.due_date, TaskServiceOptionSortBy.id]),
[TaskServiceOptionSortBy.due_date,
TaskServiceOptionSortBy.id]),
TaskServiceOption<TaskServiceOptionOrderBy>(
"order_by", TaskServiceOptionOrderBy.asc),
TaskServiceOption<TaskServiceOptionFilterBy>("filter_by", [
@ -84,7 +85,7 @@ List<TaskServiceOption> defaultOptions = [
]),
TaskServiceOption<TaskServiceOptionFilterValue>("filter_value", [
TaskServiceOptionFilterValue.enum_false,
'0001-01-02T00:00:00.000Z'
'1970-01-01T00:00:00.000Z'
]),
TaskServiceOption<TaskServiceOptionFilterComparator>(
"filter_comparator", [
@ -96,15 +97,20 @@ List<TaskServiceOption> defaultOptions = [
];
class TaskServiceOptions {
List<TaskServiceOption>? options;
List<TaskServiceOption> options = [];
TaskServiceOptions({List<TaskServiceOption>? newOptions}) {
options = [...defaultOptions];
TaskServiceOptions({List<TaskServiceOption>? newOptions, bool clearOther = false}) {
if(!clearOther)
options = new List<TaskServiceOption>.from(defaultOptions);
if (newOptions != null) {
for (TaskServiceOption custom_option in newOptions) {
int index = options!.indexWhere((element) => element.name == custom_option.name);
options!.removeAt(index);
options!.insert(index, custom_option);
int index = options.indexWhere((element) => element.name == custom_option.name);
if(index > -1) {
options.removeAt(index);
} else {
index = options.length;
}
options.insert(index, custom_option);
}
}
}
@ -112,8 +118,8 @@ class TaskServiceOptions {
String getOptions() {
String result = '';
if (options == null) return '';
for (TaskServiceOption option in options!) {
if (options.length == 0) return '';
for (TaskServiceOption option in options) {
dynamic value = option.getValue();
if (value is List) {
for (dynamic valueEntry in value) {
@ -124,7 +130,8 @@ class TaskServiceOptions {
}
}
if (result.startsWith('&')) result.substring(1);
if (result.startsWith('&')) result = result.substring(1);
result = "?" + result;
return result;
}
}