Tasks
This commit is contained in:
parent
c46da0b8f7
commit
8ea15b9c1d
|
|
@ -3,6 +3,22 @@ import 'package:built_collection/built_collection.dart';
|
|||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||
import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart';
|
||||
|
||||
var memoizedTaskList = memo2(
|
||||
(BuiltMap<int, TaskEntity> taskMap, int clientId) =>
|
||||
taskList(taskMap, clientId));
|
||||
|
||||
List<int> taskList(BuiltMap<int, TaskEntity> taskMap, int clientId) {
|
||||
final list = taskMap.keys.where((taskId) {
|
||||
final task = taskMap[taskId];
|
||||
return task.isActive && task.clientId == clientId;
|
||||
}).toList();
|
||||
|
||||
list.sort((idA, idB) =>
|
||||
taskMap[idA].listDisplayName.compareTo(taskMap[idB].listDisplayName));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
var memoizedDropdownTaskList = memo2(
|
||||
(BuiltMap<int, TaskEntity> taskMap, BuiltList<int> taskList) =>
|
||||
dropdownTasksSelector(taskMap, taskList));
|
||||
|
|
@ -83,11 +99,8 @@ var memoizedTaskStatsForClient = memo4((int clientId,
|
|||
String archivedLabel) =>
|
||||
taskStatsForClient(clientId, taskMap, activeLabel, archivedLabel));
|
||||
|
||||
String taskStatsForClient(
|
||||
int clientId,
|
||||
BuiltMap<int, TaskEntity> taskMap,
|
||||
String activeLabel,
|
||||
String archivedLabel) {
|
||||
String taskStatsForClient(int clientId, BuiltMap<int, TaskEntity> taskMap,
|
||||
String activeLabel, String archivedLabel) {
|
||||
int countActive = 0;
|
||||
int countArchived = 0;
|
||||
taskMap.forEach((taskId, task) {
|
||||
|
|
@ -114,7 +127,6 @@ String taskStatsForClient(
|
|||
return str;
|
||||
}
|
||||
|
||||
|
||||
var memoizedTaskStatsForProject = memo4((int projectId,
|
||||
BuiltMap<int, TaskEntity> taskMap,
|
||||
String activeLabel,
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ class _InvoiceEditState extends State<InvoiceEdit>
|
|||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return InvoiceItemSelector(
|
||||
clientId: invoice.clientId,
|
||||
onItemsSelected: (items) {
|
||||
viewModel.onItemsAdded(items);
|
||||
_controller.animateTo(kItemScreen);
|
||||
|
|
|
|||
|
|
@ -3,16 +3,19 @@ import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
|
|||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/product/product_selectors.dart';
|
||||
import 'package:invoiceninja_flutter/redux/task/task_selectors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
|
||||
class InvoiceItemSelector extends StatefulWidget {
|
||||
const InvoiceItemSelector({
|
||||
@required this.clientId,
|
||||
this.onItemsSelected,
|
||||
});
|
||||
|
||||
final Function(List<InvoiceItemEntity>) onItemsSelected;
|
||||
final int clientId;
|
||||
|
||||
@override
|
||||
_InvoiceItemSelectorState createState() => new _InvoiceItemSelectorState();
|
||||
|
|
@ -136,7 +139,7 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
|
|||
);
|
||||
}
|
||||
|
||||
Widget _entityList(EntityType entityType) {
|
||||
Widget _productList() {
|
||||
final state = StoreProvider.of<AppState>(context).state;
|
||||
final matches =
|
||||
memoizedProductList(state.productState.map).where((entityId) {
|
||||
|
|
@ -186,6 +189,56 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
|
|||
);
|
||||
}
|
||||
|
||||
Widget _taskList() {
|
||||
final state = StoreProvider.of<AppState>(context).state;
|
||||
final matches =
|
||||
memoizedTaskList(state.taskState.map, widget.clientId).where((entityId) {
|
||||
final entity = state.taskState.map[entityId];
|
||||
return entity.isActive && entity.matchesFilter(_filter);
|
||||
}).toList();
|
||||
|
||||
//matches.sort((idA, idB) =>
|
||||
//state.productState.map[idA].compareTo(state.productState.map[idB]));
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: matches.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final int entityId = matches[index];
|
||||
final entity = state.taskState.map[entityId];
|
||||
final String subtitle = entity.matchesFilterValue(_filter);
|
||||
return ListTile(
|
||||
dense: true,
|
||||
leading: Checkbox(
|
||||
activeColor: Theme.of(context).accentColor,
|
||||
value: _selected.contains(entityId),
|
||||
onChanged: (bool value) => _toggleEntity(entity),
|
||||
),
|
||||
title: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(entity.listDisplayName),
|
||||
),
|
||||
entity.listDisplayAmount != null
|
||||
? Text(formatNumber(entity.listDisplayAmount, context,
|
||||
formatNumberType: entity.listDisplayAmountType))
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
subtitle: subtitle != null ? Text(subtitle, maxLines: 2) : null,
|
||||
onTap: () {
|
||||
if (_selected.isNotEmpty) {
|
||||
_toggleEntity(entity);
|
||||
} else {
|
||||
_selected.add(entity);
|
||||
_onItemsSelected(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Material(
|
||||
|
|
@ -212,8 +265,8 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
|
|||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: <Widget>[
|
||||
_entityList(EntityType.product),
|
||||
_entityList(EntityType.task),
|
||||
_productList(),
|
||||
_taskList(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in New Issue