mirror of
https://github.com/go-vikunja/app
synced 2024-06-01 02:06:51 +00:00
switched checkbox detection to regex, also moved it to helper function
This commit is contained in:
parent
1d6a9eb777
commit
e73daab38e
|
@ -136,27 +136,22 @@ class _BucketTaskCardState extends State<BucketTaskCard> with AutomaticKeepAlive
|
|||
backgroundColor: label.color,
|
||||
));
|
||||
});
|
||||
if (widget.task.description.isNotEmpty) {
|
||||
final uncompletedTaskCount = '* [ ]'.allMatches(widget.task.description).length;
|
||||
final completedTaskCount = '* [x]'.allMatches(widget.task.description).length;
|
||||
final taskCount = uncompletedTaskCount + completedTaskCount;
|
||||
if (taskCount > 0) {
|
||||
final iconSize = (theme.textTheme.labelLarge.fontSize ?? 14) + 2;
|
||||
labelRow.children.add(Chip(
|
||||
avatar: Container(
|
||||
constraints: BoxConstraints(maxHeight: iconSize, maxWidth: iconSize),
|
||||
child: CircularProgressIndicator(
|
||||
value: uncompletedTaskCount == 0
|
||||
? 1 : uncompletedTaskCount.toDouble() / taskCount.toDouble(),
|
||||
backgroundColor: Colors.grey,
|
||||
) ,
|
||||
if (widget.task.hasCheckboxes) {
|
||||
final checkboxStatistics = widget.task.checkboxStatistics;
|
||||
final iconSize = (theme.textTheme.labelLarge.fontSize ?? 14) + 2;
|
||||
labelRow.children.add(Chip(
|
||||
avatar: Container(
|
||||
constraints: BoxConstraints(maxHeight: iconSize, maxWidth: iconSize),
|
||||
child: CircularProgressIndicator(
|
||||
value: checkboxStatistics.checked / checkboxStatistics.total,
|
||||
backgroundColor: Colors.grey,
|
||||
),
|
||||
label: Text(
|
||||
(uncompletedTaskCount == 0 ? '' : '$completedTaskCount of ')
|
||||
+ '$taskCount tasks'
|
||||
),
|
||||
));
|
||||
}
|
||||
),
|
||||
label: Text(
|
||||
(checkboxStatistics.checked == checkboxStatistics.total ? '' : '${checkboxStatistics.checked} of ')
|
||||
+ '${checkboxStatistics.total} tasks'
|
||||
),
|
||||
));
|
||||
}
|
||||
if (widget.task.attachments != null && widget.task.attachments.isNotEmpty) {
|
||||
labelRow.children.add(Chip(
|
||||
|
|
|
@ -5,47 +5,53 @@ import 'package:vikunja_app/components/date_extension.dart';
|
|||
import 'package:vikunja_app/models/label.dart';
|
||||
import 'package:vikunja_app/models/user.dart';
|
||||
import 'package:vikunja_app/models/taskAttachment.dart';
|
||||
import 'package:vikunja_app/utils/checkboxes_in_text.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class Task {
|
||||
int id, parentTaskId, priority, listId, bucketId;
|
||||
DateTime created, updated, dueDate, startDate, endDate;
|
||||
List<DateTime> reminderDates;
|
||||
String title, description, identifier;
|
||||
bool done;
|
||||
Color color;
|
||||
double kanbanPosition;
|
||||
User createdBy;
|
||||
Duration repeatAfter;
|
||||
List<Task> subtasks;
|
||||
List<Label> labels;
|
||||
List<TaskAttachment> attachments;
|
||||
bool loading = false;
|
||||
final int id, parentTaskId, priority, listId, bucketId;
|
||||
final DateTime created, updated, dueDate, startDate, endDate;
|
||||
final List<DateTime> reminderDates;
|
||||
final String title, description, identifier;
|
||||
final bool done;
|
||||
final Color color;
|
||||
final double kanbanPosition;
|
||||
final User createdBy;
|
||||
final Duration repeatAfter;
|
||||
final List<Task> subtasks;
|
||||
final List<Label> labels;
|
||||
final List<TaskAttachment> attachments;
|
||||
// TODO: add position(?)
|
||||
|
||||
Task(
|
||||
{@required this.id,
|
||||
this.title,
|
||||
this.description,
|
||||
this.identifier,
|
||||
this.done = false,
|
||||
this.reminderDates,
|
||||
this.dueDate,
|
||||
this.startDate,
|
||||
this.endDate,
|
||||
this.parentTaskId,
|
||||
this.priority,
|
||||
this.repeatAfter,
|
||||
this.color,
|
||||
this.kanbanPosition,
|
||||
this.subtasks,
|
||||
this.labels,
|
||||
this.attachments,
|
||||
this.created,
|
||||
this.updated,
|
||||
this.createdBy,
|
||||
this.listId,
|
||||
this.bucketId});
|
||||
// // TODO: use `late final` once upgraded to current dart version
|
||||
CheckboxStatistics _checkboxStatistics;
|
||||
|
||||
bool loading = false;
|
||||
|
||||
Task({
|
||||
@required this.id,
|
||||
this.title,
|
||||
this.description,
|
||||
this.identifier,
|
||||
this.done = false,
|
||||
this.reminderDates,
|
||||
this.dueDate,
|
||||
this.startDate,
|
||||
this.endDate,
|
||||
this.parentTaskId,
|
||||
this.priority,
|
||||
this.repeatAfter,
|
||||
this.color,
|
||||
this.kanbanPosition,
|
||||
this.subtasks,
|
||||
this.labels,
|
||||
this.attachments,
|
||||
this.created,
|
||||
this.updated,
|
||||
this.createdBy,
|
||||
this.listId,
|
||||
this.bucketId,
|
||||
});
|
||||
|
||||
Task.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
|
@ -117,6 +123,24 @@ class Task {
|
|||
? color.computeLuminance() > 0.5 ? Colors.black : Colors.white
|
||||
: null;
|
||||
|
||||
CheckboxStatistics get checkboxStatistics {
|
||||
if (_checkboxStatistics != null)
|
||||
return _checkboxStatistics;
|
||||
if (description.isEmpty)
|
||||
return null;
|
||||
|
||||
_checkboxStatistics = getCheckboxStatistics(description);
|
||||
return _checkboxStatistics;
|
||||
}
|
||||
|
||||
bool get hasCheckboxes {
|
||||
final checkboxStatistics = this.checkboxStatistics;
|
||||
if (checkboxStatistics != null && checkboxStatistics.total != 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
Task copyWith({
|
||||
int id, int parentTaskId, int priority, int listId, int bucketId,
|
||||
DateTime created, DateTime updated, DateTime dueDate, DateTime startDate, DateTime endDate,
|
||||
|
|
51
lib/utils/checkboxes_in_text.dart
Normal file
51
lib/utils/checkboxes_in_text.dart
Normal file
|
@ -0,0 +1,51 @@
|
|||
import 'package:meta/meta.dart';
|
||||
|
||||
class CheckboxStatistics {
|
||||
final int total;
|
||||
final int checked;
|
||||
|
||||
const CheckboxStatistics({
|
||||
@required this.total,
|
||||
@required this.checked,
|
||||
});
|
||||
}
|
||||
|
||||
class MatchedCheckboxes {
|
||||
final Iterable<Match> checked;
|
||||
final Iterable<Match> unchecked;
|
||||
|
||||
const MatchedCheckboxes({
|
||||
@required this.checked,
|
||||
@required this.unchecked,
|
||||
});
|
||||
}
|
||||
|
||||
MatchedCheckboxes getCheckboxesInText(String text) {
|
||||
const checkedString = '[x]';
|
||||
final checked = <Match>[];
|
||||
final unchecked = <Match>[];
|
||||
|
||||
final matches = RegExp(r'[*-] \[[ x]]').allMatches(text);
|
||||
|
||||
for (final match in matches) {
|
||||
if (match[0].endsWith(checkedString))
|
||||
checked.add(match);
|
||||
else
|
||||
unchecked.add(match);
|
||||
}
|
||||
|
||||
return MatchedCheckboxes(
|
||||
checked: checked,
|
||||
unchecked: unchecked,
|
||||
);
|
||||
}
|
||||
|
||||
CheckboxStatistics getCheckboxStatistics(String text) {
|
||||
final checkboxes = getCheckboxesInText(text);
|
||||
|
||||
return CheckboxStatistics(
|
||||
total: checkboxes.checked.length + checkboxes.unchecked.length,
|
||||
checked: checkboxes.checked.length,
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user