Skip to content

Commit

Permalink
style: dart format
Browse files Browse the repository at this point in the history
  • Loading branch information
denysvitali committed Apr 5, 2024
1 parent 37009e2 commit c37daa7
Show file tree
Hide file tree
Showing 42 changed files with 712 additions and 589 deletions.
34 changes: 17 additions & 17 deletions lib/api/bucket_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ class BucketAPIService extends APIService implements BucketService {
return client
.put('/projects/$projectId/buckets', body: bucket.toJSON())
.then((response) {
if (response == null) return null;
return Bucket.fromJSON(response.body);
});
if (response == null) return null;
return Bucket.fromJSON(response.body);
});
}

@override
Future delete(int projectId, int bucketId) {
return client
.delete('/projects/$projectId/buckets/$bucketId');
return client.delete('/projects/$projectId/buckets/$bucketId');
}

/* Not implemented in the Vikunja API
Expand All @@ -35,13 +34,13 @@ class BucketAPIService extends APIService implements BucketService {
@override
Future<Response?> getAllByList(int projectId,
[Map<String, List<String>>? queryParameters]) {
return client
.get('/projects/$projectId/buckets', queryParameters)
.then((response) => response != null ? new Response(
convertList(response.body, (result) => Bucket.fromJSON(result)),
response.statusCode,
response.headers
) : null);
return client.get('/projects/$projectId/buckets', queryParameters).then(
(response) => response != null
? new Response(
convertList(response.body, (result) => Bucket.fromJSON(result)),
response.statusCode,
response.headers)
: null);
}

@override
Expand All @@ -51,10 +50,11 @@ class BucketAPIService extends APIService implements BucketService {
@override
Future<Bucket?> update(Bucket bucket) {
return client
.post('/projects/${bucket.projectId}/buckets/${bucket.id}', body: bucket.toJSON())
.post('/projects/${bucket.projectId}/buckets/${bucket.id}',
body: bucket.toJSON())
.then((response) {
if (response == null) return null;
return Bucket.fromJSON(response.body);
});
if (response == null) return null;
return Bucket.fromJSON(response.body);
});
}
}
}
17 changes: 8 additions & 9 deletions lib/api/label_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@ class LabelTaskAPIService extends APIService implements LabelTaskService {
.then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
});
}

@override
Future<Label?> delete(LabelTask lt) async {
return client
.delete('/tasks/${lt.task!.id}/labels/${lt.label.id}')
.then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
if (response == null) return null;
return Label.fromJson(response.body);
});
}

@override
Future<List<Label>?> getAll(LabelTask lt, {String? query}) async {
String? params =
query == null ? null : '?s=' + Uri.encodeQueryComponent(query);

return client.get('/tasks/${lt.task!.id}/labels$params').then(
(label) {
if (label == null) return null;
return convertList(label, (result) => Label.fromJson(result));
});
return client.get('/tasks/${lt.task!.id}/labels$params').then((label) {
if (label == null) return null;
return convertList(label, (result) => Label.fromJson(result));
});
}
}
11 changes: 5 additions & 6 deletions lib/api/label_task_bulk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ class LabelTaskBulkAPIService extends APIService

@override
Future<List<Label>?> update(Task task, List<Label>? labels) {
if(labels == null)
labels = [];
if (labels == null) labels = [];
return client
.post('/tasks/${task.id}/labels/bulk',
body: LabelTaskBulk(labels: labels).toJSON())
.then((response) {
if (response == null) return null;
return convertList(
response.body['labels'], (result) => Label.fromJson(result));
});
if (response == null) return null;
return convertList(
response.body['labels'], (result) => Label.fromJson(result));
});
}
}
49 changes: 20 additions & 29 deletions lib/api/labels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,43 @@ class LabelAPIService extends APIService implements LabelService {

@override
Future<Label?> create(Label label) {
return client
.put('/labels', body: label.toJSON())
.then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
return client.put('/labels', body: label.toJSON()).then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
}

@override
Future<Label?> delete(Label label) {
return client
.delete('/labels/${label.id}')
.then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
return client.delete('/labels/${label.id}').then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
}

@override
Future<Label?> get(int labelID) {
return client
.get('/labels/$labelID')
.then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
return client.get('/labels/$labelID').then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
}

@override
Future<List<Label>?> getAll({String? query}) {
String params =
query == null ? '' : '?s=' + Uri.encodeQueryComponent(query);
return client.get('/labels$params').then(
(response) {
if (response == null) return null;
return convertList(response.body, (result) => Label.fromJson(result));
});
return client.get('/labels$params').then((response) {
if (response == null) return null;
return convertList(response.body, (result) => Label.fromJson(result));
});
}

@override
Future<Label?> update(Label label) {
return client
.post('/labels/${label.id}', body: label)
.then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
return client.post('/labels/${label.id}', body: label).then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
}
}
4 changes: 2 additions & 2 deletions lib/api/namespace_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class NamespaceAPIService extends APIService implements NamespaceService {
return client
.post('/namespaces/${ns.id}', body: ns.toJSON())
.then((response) {
if (response == null) return null;
return Namespace.fromJson(response.body);
if (response == null) return null;
return Namespace.fromJson(response.body);
});
}
}
3 changes: 1 addition & 2 deletions lib/api/server_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class ServerAPIService extends APIService implements ServerService {
@override
Future<Server?> getInfo() {
return client.get('/info').then((value) {
if(value == null)
return null;
if (value == null) return null;
return Server.fromJson(value.body);
});
}
Expand Down
93 changes: 45 additions & 48 deletions lib/api/task_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,77 +14,77 @@ class TaskAPIService extends APIService implements TaskService {
return client
.put('/projects/$projectId/tasks', body: task.toJSON())
.then((response) {
if (response == null) return null;
return Task.fromJson(response.body);
});
if (response == null) return null;
return Task.fromJson(response.body);
});
}

@override
Future<Task?> get(int listId) {
return client
.get('/project/$listId/tasks')
.then((response) {
if (response == null) return null;
return Task.fromJson(response.body);
});
return client.get('/project/$listId/tasks').then((response) {
if (response == null) return null;
return Task.fromJson(response.body);
});
}

@override
Future delete(int taskId) {
return client
.delete('/tasks/$taskId');
return client.delete('/tasks/$taskId');
}

@override
Future<Task?> update(Task task) {
return client
.post('/tasks/${task.id}', body: task.toJSON())
.then((response) {
if (response == null) return null;
return Task.fromJson(response.body);
});
if (response == null) return null;
return Task.fromJson(response.body);
});
}

@override
Future<List<Task>?> getAll() {
return client
.get('/tasks/all')
.then((response) {
int page_n = 0;
if (response == null) return null;
if (response.headers["x-pagination-total-pages"] != null) {
page_n = int.parse(response.headers["x-pagination-total-pages"]!);
} else {
return Future.value(response.body);
}
return client.get('/tasks/all').then((response) {
int page_n = 0;
if (response == null) return null;
if (response.headers["x-pagination-total-pages"] != null) {
page_n = int.parse(response.headers["x-pagination-total-pages"]!);
} else {
return Future.value(response.body);
}

List<Future<void>> futureList = [];
List<Task> taskList = [];
List<Future<void>> futureList = [];
List<Task> taskList = [];

for(int i = 0; i < page_n; i++) {
Map<String, List<String>> paramMap = {
"page": [i.toString()]
};
futureList.add(client.get('/tasks/all', paramMap).then((pageResponse) {convertList(pageResponse?.body, (result) {taskList.add(Task.fromJson(result));});}));
}
return Future.wait(futureList).then((value) {
return taskList;
for (int i = 0; i < page_n; i++) {
Map<String, List<String>> paramMap = {
"page": [i.toString()]
};
futureList.add(client.get('/tasks/all', paramMap).then((pageResponse) {
convertList(pageResponse?.body, (result) {
taskList.add(Task.fromJson(result));
});
}));
}
return Future.wait(futureList).then((value) {
return taskList;
});
});
}

@override
Future<Response?> getAllByProject(int projectId,
[Map<String, List<String>>? queryParameters]) {
return client
.get('/projects/$projectId/tasks', queryParameters).then(
(response) {
return response != null ?
new Response(
convertList(response.body, (result) => Task.fromJson(result)),
response.statusCode,
response.headers) : null;
});
.get('/projects/$projectId/tasks', queryParameters)
.then((response) {
return response != null
? new Response(
convertList(response.body, (result) => Task.fromJson(result)),
response.statusCode,
response.headers)
: null;
});
}

@override
Expand All @@ -93,16 +93,13 @@ class TaskAPIService extends APIService implements TaskService {
//optionString = "?sort_by[]=due_date&sort_by[]=id&order_by[]=asc&order_by[]=desc&filter_by[]=done&filter_value[]=false&filter_comparator[]=equals&filter_concat=and&filter_include_nulls=false&page=1";
//print(optionString);

return client
.get('/tasks/all', optionsMap)
.then((response) {
if (response == null) return null;
return convertList(response.body, (result) => Task.fromJson(result));
return client.get('/tasks/all', optionsMap).then((response) {
if (response == null) return null;
return convertList(response.body, (result) => Task.fromJson(result));
});
}

@override
// TODO: implement maxPages
int get maxPages => maxPages;

}
4 changes: 2 additions & 2 deletions lib/api/version_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:convert';
import 'package:http/http.dart';
import 'package:url_launcher/url_launcher.dart';


class VersionChecker {
GlobalKey<ScaffoldMessengerState> snackbarKey;
VersionChecker(this.snackbarKey);
Expand Down Expand Up @@ -46,7 +45,8 @@ class VersionChecker {
content: Text("New version available: $latest"),
action: SnackBarAction(
label: "View on Github",
onPressed: () => launchUrl(Uri.parse(repo), mode: LaunchMode.externalApplication)),
onPressed: () => launchUrl(Uri.parse(repo),
mode: LaunchMode.externalApplication)),
);
snackbarKey.currentState?.showSnackBar(snackBar);
}
Expand Down
Loading

0 comments on commit c37daa7

Please sign in to comment.