forked from vikunja/app
Started adding methods to be able to correctly modify labels on a list
This commit is contained in:
parent
4d6390331b
commit
3f634065ca
|
@ -0,0 +1,17 @@
|
|||
import 'package:vikunja_app/api/client.dart';
|
||||
import 'package:vikunja_app/api/service.dart';
|
||||
import 'package:vikunja_app/models/label.dart';
|
||||
import 'package:vikunja_app/models/task.dart';
|
||||
import 'package:vikunja_app/service/services.dart';
|
||||
|
||||
class LabelTaskBulkAPIService extends APIService
|
||||
implements LabelTaskBulkService {
|
||||
LabelTaskBulkAPIService(Client client) : super(client);
|
||||
|
||||
@override
|
||||
Future<Label> update(Task task, List<Label> labels) {
|
||||
return client
|
||||
.post('/tasks/${task.id}/labels/bulk', body: labels.map((l) => l.toJSON()).toList())
|
||||
.then((labels) { print(labels.toString());});
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:vikunja_app/api/client.dart';
|
||||
import 'package:vikunja_app/api/label_task.dart';
|
||||
import 'package:vikunja_app/api/label_task_bulk.dart';
|
||||
import 'package:vikunja_app/api/labels.dart';
|
||||
import 'package:vikunja_app/api/list_implementation.dart';
|
||||
import 'package:vikunja_app/api/namespace_implementation.dart';
|
||||
|
@ -52,6 +53,8 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
|
|||
|
||||
LabelTaskService get labelTaskService => new LabelTaskAPIService(client);
|
||||
|
||||
LabelTaskBulkAPIService get labelTaskBulkService => new LabelTaskBulkAPIService(client);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
|
|
@ -32,7 +32,7 @@ class Label {
|
|||
'id': id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'hex_color': color.value.toRadixString(16).padLeft(8, '0').substring(2),
|
||||
'hex_color': color?.value == null ? null : color.value.toRadixString(16).padLeft(8, '0').substring(2),
|
||||
'created_by': createdBy?.toJSON(),
|
||||
'updated': updated?.millisecondsSinceEpoch,
|
||||
'created': created?.millisecondsSinceEpoch,
|
||||
|
|
|
@ -298,9 +298,11 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||
endDate: _endDate,
|
||||
priority: _priority,
|
||||
repeatAfter: _repeatAfter,
|
||||
labels: _labels,
|
||||
);
|
||||
|
||||
// update the labels
|
||||
VikunjaGlobal.of(context).labelTaskBulkService.update(updatedTask, _labels);
|
||||
|
||||
VikunjaGlobal.of(context).taskService.update(updatedTask).then((_) {
|
||||
setState(() => _loading = false);
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
|
@ -326,6 +328,8 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||
.labelService
|
||||
.getAll(query: query)
|
||||
.then((labels) {
|
||||
// Only show those labels which aren't already added to the task
|
||||
labels.removeWhere((labelToRemove) => _labels.contains(labelToRemove));
|
||||
_suggestedLabels = labels;
|
||||
return labels.map((label) => label.title).toList();
|
||||
});
|
||||
|
@ -338,7 +342,6 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||
_labels.add(label);
|
||||
}
|
||||
});
|
||||
// TODO: really add the label to the list
|
||||
}
|
||||
|
||||
// FIXME: Move the following two functions to an extra class or type.
|
||||
|
|
|
@ -48,4 +48,8 @@ abstract class LabelTaskService {
|
|||
Future<List<Label>> getAll(LabelTask lt, {String query});
|
||||
Future<Label> create(LabelTask lt);
|
||||
Future<Label> delete(LabelTask lt);
|
||||
}
|
||||
|
||||
abstract class LabelTaskBulkService {
|
||||
Future<Label> update(Task task, List<Label> labels);
|
||||
}
|
Loading…
Reference in New Issue