getNextIndicesForFunds method

  1. @override
Indices? getNextIndicesForFunds(
  1. String fellowship,
  2. String template
)

Get the next available indices for the given fellowship and template

fellowship A String label of the fellowship to get the next indices for template A String label of the template to get the next indices for Returns the next indices for the given fellowship and template if possible. Else null

Implementation

@override
m.Indices? getNextIndicesForFunds(String fellowship, String template) {
  final fellowshipResult = fellowshipsStore.findFirstSync(_instance,
      finder: Finder(filter: Filter.equals("name", fellowship)));

  final templateResult = templatesStore.findFirstSync(_instance,
      finder: Finder(filter: Filter.equals("name", template)));

  if (fellowshipResult != null && templateResult != null) {
    final x = fellowshipResult["x"]! as int;
    final y = templateResult["y"]! as int;
    final cartesianResult = cartesiansStore.findFirstSync(_instance,
        finder: Finder(
            filter: Filter.and([
              Filter.equals("x", x),
              Filter.equals("y", y),
            ]),
            sortOrders: [SortOrder("z", false)]));

    if (cartesianResult != null) {
      final z = (cartesianResult["z"]! as int) + 1;
      return m.Indices(x: x, y: y, z: z);
    } else {
      return m.Indices(x: x, y: y, z: 1);
    }
  }

  return null;
}