Skip to content

Commit db3388b

Browse files
authored
Merge branch 'CCExtractor:main' into main
2 parents 9942fa6 + 49bb285 commit db3388b

15 files changed

+689
-53
lines changed

lib/api_service.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,23 @@ String baseUrl = 'http://YOUR_IP:8000';
7171
String origin = 'http://localhost:8080';
7272

7373
Future<List<Tasks>> fetchTasks(String uuid, String encryptionSecret) async {
74-
String url =
75-
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
76-
77-
var response = await http.get(Uri.parse(url), headers: {
78-
"Content-Type": "application/json",
79-
}).timeout(const Duration(seconds: 10000));
80-
if (response.statusCode == 200) {
81-
List<dynamic> allTasks = jsonDecode(response.body);
82-
debugPrint(allTasks.toString());
83-
return allTasks.map((task) => Tasks.fromJson(task)).toList();
84-
} else {
85-
throw Exception('Failed to load tasks');
74+
try {
75+
String url =
76+
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
77+
78+
var response = await http.get(Uri.parse(url), headers: {
79+
"Content-Type": "application/json",
80+
}).timeout(const Duration(seconds: 10000));
81+
if (response.statusCode == 200) {
82+
List<dynamic> allTasks = jsonDecode(response.body);
83+
debugPrint(allTasks.toString());
84+
return allTasks.map((task) => Tasks.fromJson(task)).toList();
85+
} else {
86+
throw Exception('Failed to load tasks');
87+
}
88+
} catch (e) {
89+
debugPrint('Error fetching tasks: $e');
90+
return [];
8691
}
8792
}
8893

lib/app/modules/detailRoute/controllers/detail_route_controller.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class DetailRouteController extends GetxController {
3434
void setAttribute(String name, dynamic newValue) {
3535
modify.set(name, newValue);
3636
onEdit.value = true;
37+
if(name == 'start'){
38+
debugPrint('Start Value Changed to $newValue');
39+
startValue.value = newValue;
40+
}
3741
initValues();
3842
}
3943

@@ -82,7 +86,7 @@ class DetailRouteController extends GetxController {
8286
statusValue.value = modify.draft.status;
8387
entryValue.value = modify.draft.entry;
8488
modifiedValue.value = modify.draft.modified;
85-
startValue.value = modify.draft.start;
89+
startValue.value ??= null;
8690
endValue.value = modify.draft.end;
8791
dueValue.value = modify.draft.due;
8892
waitValue.value = modify.draft.wait;

lib/app/modules/home/controllers/home_controller.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,18 @@ class HomeController extends GetxController {
508508
final projectcontroller = TextEditingController();
509509
var due = Rxn<DateTime>();
510510
RxString dueString = ''.obs;
511-
RxString priority = 'M'.obs;
511+
final priorityList = ['L','X','M','H'];
512+
final priorityColors = [
513+
TaskWarriorColors.green,
514+
TaskWarriorColors.grey,
515+
TaskWarriorColors.yellow,
516+
TaskWarriorColors.red,
517+
518+
519+
520+
];
521+
RxString priority = 'X'.obs;
522+
512523
final tagcontroller = TextEditingController();
513524
RxList<String> tags = <String>[].obs;
514525
RxBool inThePast = false.obs;

lib/app/modules/home/views/add_task_bottom_sheet.dart

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -367,34 +367,52 @@ class AddTaskBottomSheet extends StatelessWidget {
367367
),
368368
textAlign: TextAlign.left,
369369
),
370+
const SizedBox(width: 2,),
370371
Obx(
371-
() => DropdownButton<String>(
372-
dropdownColor: AppSettings.isDarkMode
373-
? TaskWarriorColors.kdialogBackGroundColor
374-
: TaskWarriorColors.kLightDialogBackGroundColor,
375-
value: homeController.priority.value,
376-
elevation: 16,
377-
style: GoogleFonts.poppins(
378-
color: AppSettings.isDarkMode
379-
? TaskWarriorColors.white
380-
: TaskWarriorColors.black,
381-
),
382-
underline: Container(
383-
height: 1.5,
384-
color: AppSettings.isDarkMode
385-
? TaskWarriorColors.kdialogBackGroundColor
386-
: TaskWarriorColors.kLightDialogBackGroundColor,
387-
),
388-
onChanged: (String? newValue) {
389-
homeController.priority.value = newValue!;
390-
},
391-
items: <String>['H', 'M', 'L', 'None']
392-
.map<DropdownMenuItem<String>>((String value) {
393-
return DropdownMenuItem<String>(
394-
value: value,
395-
child: Text(' $value'),
396-
);
397-
}).toList(),
372+
() => Row(
373+
children: [
374+
for(int i=0;i<homeController.priorityList.length;i++)
375+
Padding(
376+
padding: const EdgeInsets.symmetric(horizontal: 2.5),
377+
child: GestureDetector(
378+
onTap: () {
379+
homeController.priority.value = homeController.priorityList[i];
380+
debugPrint(homeController.priority.value);
381+
},
382+
child: AnimatedContainer(
383+
duration: const Duration(milliseconds: 100),
384+
height: 30,
385+
width: 37,
386+
decoration: BoxDecoration(
387+
388+
borderRadius: BorderRadius.circular(8),
389+
border: Border.all(
390+
color: homeController.priority.value == homeController.priorityList[i]
391+
? AppSettings.isDarkMode
392+
? TaskWarriorColors.kLightPrimaryBackgroundColor
393+
: TaskWarriorColors.kprimaryBackgroundColor
394+
: AppSettings.isDarkMode
395+
? TaskWarriorColors.kprimaryBackgroundColor
396+
: TaskWarriorColors.kLightPrimaryBackgroundColor,
397+
)
398+
),
399+
child: Center(
400+
child: Text(
401+
homeController.priorityList[i],
402+
textAlign: TextAlign.center,
403+
style: GoogleFonts.poppins(
404+
fontWeight: FontWeight.bold,
405+
fontSize: 17,
406+
color: homeController.priorityColors[i]
407+
),
408+
),
409+
),
410+
),
411+
412+
),
413+
)
414+
415+
],
398416
),
399417
)
400418
],

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ packages:
106106
source: hosted
107107
version: "7.2.11"
108108
built_collection:
109-
dependency: transitive
109+
dependency: "direct main"
110110
description:
111111
name: built_collection
112112
sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100"

pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ dev_dependencies:
6969
build_runner: null
7070
flutter_gen_runner: null
7171
flutter_lints: 4.0.0
72+
http_mock_adapter: ^0.3.0
73+
sqflite_common_ffi: ^2.0.0
7274

7375
flutter_gen:
7476
output: lib/app/utils/gen/

test/api_service_test.dart

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
import 'dart:convert';
2+
3+
import 'package:flutter/services.dart';
4+
import 'package:flutter_test/flutter_test.dart';
5+
import 'package:mockito/annotations.dart';
6+
import 'package:mockito/mockito.dart';
7+
import 'package:http/http.dart' as http;
8+
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
9+
import 'package:taskwarrior/api_service.dart';
10+
import 'package:taskwarrior/app/utils/taskchampion/credentials_storage.dart';
11+
12+
import 'api_service_test.mocks.dart';
13+
14+
class MockCredentialsStorage extends Mock implements CredentialsStorage {}
15+
16+
class MockMethodChannel extends Mock implements MethodChannel {}
17+
18+
@GenerateMocks([MockMethodChannel, http.Client])
19+
void main() {
20+
TestWidgetsFlutterBinding.ensureInitialized();
21+
22+
databaseFactory = databaseFactoryFfi;
23+
MockClient mockClient = MockClient();
24+
25+
setUpAll(() {
26+
sqfliteFfiInit();
27+
});
28+
29+
group('Tasks model', () {
30+
test('fromJson creates Tasks object', () {
31+
final json = {
32+
'id': 1,
33+
'description': 'Task 1',
34+
'project': 'Project 1',
35+
'status': 'pending',
36+
'uuid': '123',
37+
'urgency': 5.0,
38+
'priority': 'H',
39+
'due': '2024-12-31',
40+
'end': null,
41+
'entry': '2024-01-01',
42+
'modified': '2024-11-01',
43+
};
44+
45+
final task = Tasks.fromJson(json);
46+
47+
expect(task.id, 1);
48+
expect(task.description, 'Task 1');
49+
expect(task.project, 'Project 1');
50+
expect(task.status, 'pending');
51+
expect(task.uuid, '123');
52+
expect(task.urgency, 5.0);
53+
expect(task.priority, 'H');
54+
expect(task.due, '2024-12-31');
55+
expect(task.entry, '2024-01-01');
56+
expect(task.modified, '2024-11-01');
57+
});
58+
59+
test('toJson converts Tasks object to JSON', () {
60+
final task = Tasks(
61+
id: 1,
62+
description: 'Task 1',
63+
project: 'Project 1',
64+
status: 'pending',
65+
uuid: '123',
66+
urgency: 5.0,
67+
priority: 'H',
68+
due: '2024-12-31',
69+
end: null,
70+
entry: '2024-01-01',
71+
modified: '2024-11-01',
72+
);
73+
74+
final json = task.toJson();
75+
76+
expect(json['id'], 1);
77+
expect(json['description'], 'Task 1');
78+
expect(json['project'], 'Project 1');
79+
expect(json['status'], 'pending');
80+
expect(json['uuid'], '123');
81+
expect(json['urgency'], 5.0);
82+
expect(json['priority'], 'H');
83+
expect(json['due'], '2024-12-31');
84+
});
85+
});
86+
87+
group('fetchTasks', () {
88+
test('Fetch data successfully', () async {
89+
final responseJson = jsonEncode({'data': 'Mock data'});
90+
when(mockClient.get(
91+
Uri.parse(
92+
'$baseUrl/tasks?email=email&origin=$origin&UUID=123&encryptionSecret=secret'),
93+
headers: {
94+
"Content-Type": "application/json",
95+
})).thenAnswer((_) async => http.Response(responseJson, 200));
96+
97+
final result = await fetchTasks('123', 'secret');
98+
99+
expect(result, isA<List<Tasks>>());
100+
});
101+
102+
test('fetchTasks returns empty array', () async {
103+
const uuid = '123';
104+
const encryptionSecret = 'secret';
105+
106+
expect(await fetchTasks(uuid, encryptionSecret), isEmpty);
107+
});
108+
});
109+
110+
group('TaskDatabase', () {
111+
late TaskDatabase taskDatabase;
112+
113+
setUp(() async {
114+
taskDatabase = TaskDatabase();
115+
await taskDatabase.open();
116+
});
117+
118+
test('insertTask adds a task to the database', () async {
119+
final task = Tasks(
120+
id: 1,
121+
description: 'Task 1',
122+
project: 'Project 1',
123+
status: 'pending',
124+
uuid: '123',
125+
urgency: 5.0,
126+
priority: 'H',
127+
due: '2024-12-31',
128+
end: null,
129+
entry: '2024-01-01',
130+
modified: '2024-11-01',
131+
);
132+
133+
await taskDatabase.insertTask(task);
134+
135+
final tasks = await taskDatabase.fetchTasksFromDatabase();
136+
137+
expect(tasks.length, 1);
138+
expect(tasks[0].description, 'Task 1');
139+
});
140+
141+
test('deleteAllTasksInDB removes all tasks', () async {
142+
final task = Tasks(
143+
id: 1,
144+
description: 'Task 1',
145+
project: 'Project 1',
146+
status: 'pending',
147+
uuid: '123',
148+
urgency: 5.0,
149+
priority: 'H',
150+
due: '2024-12-31',
151+
end: null,
152+
entry: '2024-01-01',
153+
modified: '2024-11-01',
154+
);
155+
156+
await taskDatabase.insertTask(task);
157+
await taskDatabase.deleteAllTasksInDB();
158+
159+
final tasks = await taskDatabase.fetchTasksFromDatabase();
160+
161+
expect(tasks.length, 0);
162+
});
163+
});
164+
}

0 commit comments

Comments
 (0)