|
@@ -22,14 +22,13 @@ abstract class GridRowFieldDelegate {
|
|
|
|
|
|
class GridRowCache {
|
|
class GridRowCache {
|
|
final String gridId;
|
|
final String gridId;
|
|
- final RowsNotifier _rowNotifier;
|
|
|
|
|
|
+ final RowsNotifier _rowsNotifier;
|
|
final GridRowListener _rowsListener;
|
|
final GridRowListener _rowsListener;
|
|
final GridRowFieldDelegate _fieldDelegate;
|
|
final GridRowFieldDelegate _fieldDelegate;
|
|
-
|
|
|
|
- List<GridRow> get clonedRows => _rowNotifier.clonedRows;
|
|
|
|
|
|
+ List<GridRow> get clonedRows => _rowsNotifier.clonedRows;
|
|
|
|
|
|
GridRowCache({required this.gridId, required GridRowFieldDelegate fieldDelegate})
|
|
GridRowCache({required this.gridId, required GridRowFieldDelegate fieldDelegate})
|
|
- : _rowNotifier = RowsNotifier(
|
|
|
|
|
|
+ : _rowsNotifier = RowsNotifier(
|
|
rowBuilder: (rowOrder) {
|
|
rowBuilder: (rowOrder) {
|
|
return GridRow(
|
|
return GridRow(
|
|
gridId: gridId,
|
|
gridId: gridId,
|
|
@@ -42,16 +41,16 @@ class GridRowCache {
|
|
_rowsListener = GridRowListener(gridId: gridId),
|
|
_rowsListener = GridRowListener(gridId: gridId),
|
|
_fieldDelegate = fieldDelegate {
|
|
_fieldDelegate = fieldDelegate {
|
|
//
|
|
//
|
|
- fieldDelegate.onFieldChanged(() => _rowNotifier.fieldDidChange());
|
|
|
|
|
|
+ fieldDelegate.onFieldChanged(() => _rowsNotifier.fieldDidChange());
|
|
|
|
|
|
// listen on the row update
|
|
// listen on the row update
|
|
_rowsListener.rowsUpdateNotifier.addPublishListener((result) {
|
|
_rowsListener.rowsUpdateNotifier.addPublishListener((result) {
|
|
result.fold(
|
|
result.fold(
|
|
(changesets) {
|
|
(changesets) {
|
|
for (final changeset in changesets) {
|
|
for (final changeset in changesets) {
|
|
- _rowNotifier.deleteRows(changeset.deletedRows);
|
|
|
|
- _rowNotifier.insertRows(changeset.insertedRows);
|
|
|
|
- _rowNotifier.updateRows(changeset.updatedRows);
|
|
|
|
|
|
+ _rowsNotifier.deleteRows(changeset.deletedRows);
|
|
|
|
+ _rowsNotifier.insertRows(changeset.insertedRows);
|
|
|
|
+ _rowsNotifier.updateRows(changeset.updatedRows);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
(err) => Log.error(err),
|
|
(err) => Log.error(err),
|
|
@@ -62,14 +61,14 @@ class GridRowCache {
|
|
|
|
|
|
Future<void> dispose() async {
|
|
Future<void> dispose() async {
|
|
await _rowsListener.stop();
|
|
await _rowsListener.stop();
|
|
- _rowNotifier.dispose();
|
|
|
|
|
|
+ _rowsNotifier.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
void addListener({
|
|
void addListener({
|
|
void Function(List<GridRow>, GridRowChangeReason)? onChanged,
|
|
void Function(List<GridRow>, GridRowChangeReason)? onChanged,
|
|
bool Function()? listenWhen,
|
|
bool Function()? listenWhen,
|
|
}) {
|
|
}) {
|
|
- _rowNotifier.addListener(() {
|
|
|
|
|
|
+ _rowsNotifier.addListener(() {
|
|
if (onChanged == null) {
|
|
if (onChanged == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -78,7 +77,7 @@ class GridRowCache {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- onChanged(clonedRows, _rowNotifier._changeReason);
|
|
|
|
|
|
+ onChanged(clonedRows, _rowsNotifier._changeReason);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -87,7 +86,7 @@ class GridRowCache {
|
|
void Function(GridCellMap)? onUpdated,
|
|
void Function(GridCellMap)? onUpdated,
|
|
bool Function()? listenWhen,
|
|
bool Function()? listenWhen,
|
|
}) {
|
|
}) {
|
|
- listenrHandler() {
|
|
|
|
|
|
+ listenrHandler() async {
|
|
if (onUpdated == null) {
|
|
if (onUpdated == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -97,14 +96,14 @@ class GridRowCache {
|
|
}
|
|
}
|
|
|
|
|
|
notify() {
|
|
notify() {
|
|
- final row = _rowNotifier.rowDataWithId(rowId);
|
|
|
|
|
|
+ final row = _rowsNotifier.rowDataWithId(rowId);
|
|
if (row != null) {
|
|
if (row != null) {
|
|
- final GridCellMap cellDataMap = _makeCellDataMap(rowId, row);
|
|
|
|
|
|
+ final GridCellMap cellDataMap = _makeGridCells(rowId, row);
|
|
onUpdated(cellDataMap);
|
|
onUpdated(cellDataMap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- _rowNotifier._changeReason.whenOrNull(
|
|
|
|
|
|
+ _rowsNotifier._changeReason.whenOrNull(
|
|
update: (indexs) {
|
|
update: (indexs) {
|
|
if (indexs[rowId] != null) {
|
|
if (indexs[rowId] != null) {
|
|
notify();
|
|
notify();
|
|
@@ -114,11 +113,40 @@ class GridRowCache {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- _rowNotifier.addListener(listenrHandler);
|
|
|
|
|
|
+ _rowsNotifier.addListener(listenrHandler);
|
|
return listenrHandler;
|
|
return listenrHandler;
|
|
}
|
|
}
|
|
|
|
|
|
- GridCellMap _makeCellDataMap(String rowId, Row? row) {
|
|
|
|
|
|
+ void removeRowListener(VoidCallback callback) {
|
|
|
|
+ _rowsNotifier.removeListener(callback);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ GridCellMap loadGridCells(String rowId) {
|
|
|
|
+ final Row? data = _rowsNotifier.rowDataWithId(rowId);
|
|
|
|
+ if (data == null) {
|
|
|
|
+ _loadRow(rowId);
|
|
|
|
+ }
|
|
|
|
+ return _makeGridCells(rowId, data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void resetRows(List<GridBlockOrder> blocks) {
|
|
|
|
+ final rowOrders = blocks.expand((block) => block.rowOrders).toList();
|
|
|
|
+ _rowsNotifier.reset(rowOrders);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Future<void> _loadRow(String rowId) async {
|
|
|
|
+ final payload = RowIdentifierPayload.create()
|
|
|
|
+ ..gridId = gridId
|
|
|
|
+ ..rowId = rowId;
|
|
|
|
+
|
|
|
|
+ final result = await GridEventGetRow(payload).send();
|
|
|
|
+ result.fold(
|
|
|
|
+ (rowData) => _rowsNotifier.rowData = rowData,
|
|
|
|
+ (err) => Log.error(err),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ GridCellMap _makeGridCells(String rowId, Row? row) {
|
|
var cellDataMap = GridCellMap.new();
|
|
var cellDataMap = GridCellMap.new();
|
|
for (final field in _fieldDelegate.fields) {
|
|
for (final field in _fieldDelegate.fields) {
|
|
if (field.visibility) {
|
|
if (field.visibility) {
|
|
@@ -132,33 +160,6 @@ class GridRowCache {
|
|
}
|
|
}
|
|
return cellDataMap;
|
|
return cellDataMap;
|
|
}
|
|
}
|
|
-
|
|
|
|
- void removeRowListener(VoidCallback callback) {
|
|
|
|
- _rowNotifier.removeListener(callback);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- GridCellMap loadCellData(String rowId) {
|
|
|
|
- final Row? data = _rowNotifier.rowDataWithId(rowId);
|
|
|
|
- if (data == null) {
|
|
|
|
- final payload = RowIdentifierPayload.create()
|
|
|
|
- ..gridId = gridId
|
|
|
|
- ..rowId = rowId;
|
|
|
|
-
|
|
|
|
- GridEventGetRow(payload).send().then((result) {
|
|
|
|
- result.fold(
|
|
|
|
- (rowData) => _rowNotifier.rowData = rowData,
|
|
|
|
- (err) => Log.error(err),
|
|
|
|
- );
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return _makeCellDataMap(rowId, data);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void updateWithBlock(List<GridBlockOrder> blocks) {
|
|
|
|
- final rowOrders = blocks.expand((block) => block.rowOrders).toList();
|
|
|
|
- _rowNotifier.reset(rowOrders);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
class RowsNotifier extends ChangeNotifier {
|
|
class RowsNotifier extends ChangeNotifier {
|