1
0
mirror of https://github.com/go-vikunja/app synced 2024-06-01 02:06:51 +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

View File

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

View File

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

View File

@ -224,19 +224,26 @@ class LandingPageState extends State<LandingPage>
.settingsManager .settingsManager
.getLandingPageOnlyDueDateTasks() .getLandingPageOnlyDueDateTasks()
.then((showOnlyDueDateTasks) { .then((showOnlyDueDateTasks) {
if (!showOnlyDueDateTasks) { return VikunjaGlobal
return VikunjaGlobal.of(context).taskService.getAll().then((value) => _handleTaskList(value)); .of(context)
} else { .taskService
return VikunjaGlobal .getByOptions(TaskServiceOptions(
.of(context) newOptions: [
.taskService TaskServiceOption<TaskServiceOptionFilterBy>("filter_by", "done"),
.getByOptions(TaskServiceOptions()) TaskServiceOption<TaskServiceOptionFilterValue>("filter_value", "false"),
.then<Future<void>?>((taskList) => _handleTaskList(taskList)); ],
} 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) { if (taskList != null && taskList.isEmpty) {
setState(() { setState(() {
landingPageStatus = PageStatus.empty; landingPageStatus = PageStatus.empty;

View File

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