这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 120 additions & 67 deletions lib/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
Expand All @@ -19,38 +20,73 @@ class Tasks {
final String? end;
final String entry;
final String? modified;

Tasks({
required this.id,
required this.description,
required this.project,
required this.status,
required this.uuid,
required this.urgency,
required this.priority,
required this.due,
required this.end,
required this.entry,
required this.modified,
});
final List<dynamic>? tags;

Tasks(
{required this.id,
required this.description,
required this.project,
required this.status,
required this.uuid,
required this.urgency,
required this.priority,
required this.due,
required this.end,
required this.entry,
required this.modified,
required this.tags});

factory Tasks.fromJson(Map<String, dynamic> json) {
return Tasks(
id: json['id'],
description: json['description'],
project: json['project'],
status: json['status'],
uuid: json['uuid'],
urgency: json['urgency'].toDouble(),
priority: json['priority'],
due: json['due'],
end: json['end'],
entry: json['entry'],
modified: json['modified'],
);
id: json['id'],
description: json['description'],
project: json['project'],
status: json['status'],
uuid: json['uuid'],
urgency: json['urgency'].toDouble(),
priority: json['priority'],
due: json['due'],
end: json['end'],
entry: json['entry'],
modified: json['modified'],
tags: json['tags']);
}
factory Tasks.fromDbJson(Map<String, dynamic> json) {
debugPrint("FROM: $json");
return Tasks(
id: json['id'],
description: json['description'],
project: json['project'],
status: json['status'],
uuid: json['uuid'],
urgency: json['urgency'].toDouble(),
priority: json['priority'],
due: json['due'],
end: json['end'],
entry: json['entry'],
modified: json['modified'],
tags: json['tags'].toString().split(' '));
}

Map<String, dynamic> toJson() {
debugPrint("TAGS: $tags");
return {
'id': id,
'description': description,
'project': project,
'status': status,
'uuid': uuid,
'urgency': urgency,
'priority': priority,
'due': due,
'end': end,
'entry': entry,
'modified': modified,
'tags': tags
};
}

Map<String, dynamic> toDbJson() {
return {
'id': id,
'description': description,
Expand All @@ -63,9 +99,11 @@ class Tasks {
'end': end,
'entry': entry,
'modified': modified,
'tags': tags != null ? tags?.join(" ") : ""
};
}
}

String origin = 'http://localhost:8080';

Future<List<Tasks>> fetchTasks(String uuid, String encryptionSecret) async {
Expand Down Expand Up @@ -99,8 +137,8 @@ Future<void> updateTasksInDatabase(List<Tasks> tasks) async {
//add tasks without UUID to the server and delete them from database
for (var task in tasksWithoutUUID) {
try {
await addTaskAndDeleteFromDatabase(
task.description, task.project!, task.due!, task.priority!);
await addTaskAndDeleteFromDatabase(task.description, task.project!,
task.due!, task.priority!, task.tags != null ? task.tags! : []);
} catch (e) {
debugPrint('Failed to add task without UUID to server: $e');
}
Expand Down Expand Up @@ -222,15 +260,16 @@ Future<void> completeTask(String email, String taskUuid) async {
}
}

Future<void> addTaskAndDeleteFromDatabase(
String description, String project, String due, String priority) async {
Future<void> addTaskAndDeleteFromDatabase(String description, String project,
String due, String priority, List<dynamic> tags) async {
var baseUrl = await CredentialsStorage.getApiUrl();
String apiUrl = '$baseUrl/add-task';
var c = await CredentialsStorage.getClientId();
var e = await CredentialsStorage.getEncryptionSecret();
debugPrint("Database Adding Tags $tags $description");
debugPrint(c);
debugPrint(e);
await http.post(
var res = await http.post(
Uri.parse(apiUrl),
headers: {
'Content-Type': 'text/plain',
Expand All @@ -243,9 +282,10 @@ Future<void> addTaskAndDeleteFromDatabase(
'project': project,
'due': due,
'priority': priority,
'tags': tags
}),
);

debugPrint('Database res ${res.body}');
var taskDatabase = TaskDatabase();
await taskDatabase.open();
await taskDatabase._database!.delete(
Expand Down Expand Up @@ -305,9 +345,11 @@ class TaskDatabase {
var databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'tasks.db');

_database = await openDatabase(path, version: 1,
_database = await openDatabase(path,
version: 1,
onOpen: (db) async => await addTagsColumnIfNeeded(db),
onCreate: (Database db, version) async {
await db.execute('''
await db.execute('''
CREATE TABLE Tasks (
uuid TEXT PRIMARY KEY,
id INTEGER,
Expand All @@ -322,7 +364,16 @@ class TaskDatabase {
modified TEXT
)
''');
});
});
}

Future<void> addTagsColumnIfNeeded(Database db) async {
try {
await db.rawQuery("SELECT tags FROM Tasks LIMIT 0");
} catch (e) {
await db.execute("ALTER TABLE Tasks ADD COLUMN tags TEXT");
debugPrint("Added Column tags");
}
}

Future<void> ensureDatabaseIsOpen() async {
Expand All @@ -335,20 +386,21 @@ class TaskDatabase {
await ensureDatabaseIsOpen();

final List<Map<String, dynamic>> maps = await _database!.query('Tasks');
debugPrint("Database fetch ${maps.last}");
var a = List.generate(maps.length, (i) {
return Tasks(
id: maps[i]['id'],
description: maps[i]['description'],
project: maps[i]['project'],
status: maps[i]['status'],
uuid: maps[i]['uuid'],
urgency: maps[i]['urgency'],
priority: maps[i]['priority'],
due: maps[i]['due'],
end: maps[i]['end'],
entry: maps[i]['entry'],
modified: maps[i]['modified'],
);
id: maps[i]['id'],
description: maps[i]['description'],
project: maps[i]['project'],
status: maps[i]['status'],
uuid: maps[i]['uuid'],
urgency: maps[i]['urgency'],
priority: maps[i]['priority'],
due: maps[i]['due'],
end: maps[i]['end'],
entry: maps[i]['entry'],
modified: maps[i]['modified'],
tags: maps[i]['tags'] != null ? maps[i]['tags'].split(' ') : []);
});
// debugPrint('Tasks from db');
// debugPrint(a.toString());
Expand Down Expand Up @@ -377,20 +429,21 @@ class TaskDatabase {

Future<void> insertTask(Tasks task) async {
await ensureDatabaseIsOpen();

await _database!.insert(
debugPrint("Database Insert");
var dbi = await _database!.insert(
'Tasks',
task.toJson(),
task.toDbJson(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
debugPrint("Database Insert ${task.toDbJson()} $dbi");
}

Future<void> updateTask(Tasks task) async {
await ensureDatabaseIsOpen();

await _database!.update(
'Tasks',
task.toJson(),
task.toDbJson(),
where: 'uuid = ?',
whereArgs: [task.uuid],
);
Expand All @@ -406,7 +459,7 @@ class TaskDatabase {
);

if (maps.isNotEmpty) {
return Tasks.fromJson(maps.first);
return Tasks.fromDbJson(maps.first);
} else {
return null;
}
Expand Down Expand Up @@ -473,7 +526,7 @@ class TaskDatabase {
);

return List.generate(maps.length, (i) {
return Tasks.fromJson(maps[i]);
return Tasks.fromDbJson(maps[i]);
});
}

Expand All @@ -483,21 +536,21 @@ class TaskDatabase {
where: 'project = ?',
whereArgs: [project],
);

debugPrint("DB Stored for $maps");
return List.generate(maps.length, (i) {
return Tasks(
uuid: maps[i]['uuid'],
id: maps[i]['id'],
description: maps[i]['description'],
project: maps[i]['project'],
status: maps[i]['status'],
urgency: maps[i]['urgency'],
priority: maps[i]['priority'],
due: maps[i]['due'],
end: maps[i]['end'],
entry: maps[i]['entry'],
modified: maps[i]['modified'],
);
uuid: maps[i]['uuid'],
id: maps[i]['id'],
description: maps[i]['description'],
project: maps[i]['project'],
status: maps[i]['status'],
urgency: maps[i]['urgency'],
priority: maps[i]['priority'],
due: maps[i]['due'],
end: maps[i]['end'],
entry: maps[i]['entry'],
modified: maps[i]['modified'],
tags: maps[i]['tags'].toString().split(' '));
});
}

Expand All @@ -520,7 +573,7 @@ class TaskDatabase {
whereArgs: ['%$query%', '%$query%'],
);
return List.generate(maps.length, (i) {
return Tasks.fromJson(maps[i]);
return Tasks.fromDbJson(maps[i]);
});
}

Expand Down
15 changes: 9 additions & 6 deletions lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import 'package:taskwarrior/app/models/storage.dart';
import 'package:taskwarrior/app/models/storage/client.dart';
import 'package:taskwarrior/app/models/tag_meta_data.dart';
import 'package:taskwarrior/app/modules/home/controllers/widget.controller.dart';
import 'package:taskwarrior/app/modules/home/views/add_task_bottom_sheet.dart';
import 'package:taskwarrior/app/modules/home/views/add_task_to_taskc_bottom_sheet.dart';
import 'package:taskwarrior/app/modules/home/views/add_task_bottom_sheet_new.dart';
import 'package:taskwarrior/app/modules/splash/controllers/splash_controller.dart';
import 'package:taskwarrior/app/routes/app_pages.dart';
import 'package:taskwarrior/app/services/tag_filter.dart';
Expand All @@ -32,6 +31,7 @@ import 'package:taskwarrior/app/utils/taskfunctions/projects.dart';
import 'package:taskwarrior/app/utils/taskfunctions/query.dart';
import 'package:taskwarrior/app/utils/taskfunctions/tags.dart';
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';
import 'package:textfield_tags/textfield_tags.dart';
import 'package:taskwarrior/app/utils/themes/theme_extension.dart';
import 'package:tutorial_coach_mark/tutorial_coach_mark.dart';

Expand All @@ -46,11 +46,13 @@ class HomeController extends GetxController {
final RxSet<String> selectedTags = <String>{}.obs;
final RxList<Task> queriedTasks = <Task>[].obs;
final RxList<Task> searchedTasks = <Task>[].obs;
final RxList<DateTime?> selectedDates = List<DateTime?>.filled(4, null).obs;
final RxMap<String, TagMetadata> pendingTags = <String, TagMetadata>{}.obs;
final RxMap<String, ProjectNode> projects = <String, ProjectNode>{}.obs;
final RxBool sortHeaderVisible = false.obs;
final RxBool searchVisible = false.obs;
final TextEditingController searchController = TextEditingController();
final StringTagController stringTagController = StringTagController();
late RxBool serverCertExists;
final Rx<SupportedLanguage> selectedLanguage = SupportedLanguage.english.obs;
final ScrollController scrollController = ScrollController();
Expand Down Expand Up @@ -323,7 +325,8 @@ class HomeController extends GetxController {
Future<void> synchronize(BuildContext context, bool isDialogNeeded) async {
try {
final connectivityResult = await Connectivity().checkConnectivity();
TaskwarriorColorTheme tColors = Theme.of(context).extension<TaskwarriorColorTheme>()!;
TaskwarriorColorTheme tColors =
Theme.of(context).extension<TaskwarriorColorTheme>()!;
if (connectivityResult == ConnectivityResult.none) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
Expand Down Expand Up @@ -705,9 +708,9 @@ class HomeController extends GetxController {
}

void showAddDialogAfterWidgetClick() {
Widget showDialog = taskchampion.value
? AddTaskToTaskcBottomSheet(homeController: this)
: AddTaskBottomSheet(homeController: this);
Widget showDialog = Material(
child: AddTaskBottomSheet(
homeController: this, forTaskC: taskchampion.value));
Get.dialog(showDialog);
}
}
Loading