getTasksForApp static method

Future<List<ModelsJsonTask>> getTasksForApp(
  1. AppModel appModel,
  2. AppBarModel appBarModel,
  3. HomeMenuModel homeMenuModel,
  4. DrawerModel leftDrawerModel,
  5. DrawerModel rightDrawerModel,
  6. List<DialogModel> dialogs,
  7. List<PageModel> pages,
  8. List<AbstractModelWithInformation> container,
)

Implementation

static Future<List<ModelsJsonTask>> getTasksForApp(
    AppModel appModel,
    AppBarModel appBarModel,
    HomeMenuModel homeMenuModel,
    DrawerModel leftDrawerModel,
    DrawerModel rightDrawerModel,
    List<DialogModel> dialogs,
    List<PageModel> pages,
    List<AbstractModelWithInformation> container) async {
  List<ModelsJsonTask> tasks = [];

  //Set<MenuDefModel> menuDefModels = <MenuDefModel>{};

  List<PluginWithComponents> pluginsWithComponents;
  tasks.add(() async {
    container.add(ModelWithInformation(JsonConsts.app, appModel));
  });

  tasks.add(() async {
    container.add(ModelDocumentIDsWithInformation(
        dialogRepository(appId: appModel.documentID)!,
        JsonConsts.dialogs,
        dialogs.map((e) => e.documentID).toList()));
  });
  tasks.add(() async {
    container.add(ModelDocumentIDsWithInformation(
        pageRepository(appId: appModel.documentID)!,
        JsonConsts.pages,
        pages.map((e) => e.documentID).toList()));
  });

  // add all instances of all plugins
  pluginsWithComponents = retrievePluginsWithComponents();
  for (var pluginsWithComponent in pluginsWithComponents) {
    var pluginName = pluginsWithComponent.name;
    for (var componentSpec in pluginsWithComponent.componentSpec) {
      var repository =
          componentSpec.retrieveRepository(appId: appModel.documentID)
              as RepositoryBase<ModelBase, EntityBase>;

      tasks.add(() async {
        print("Dumping ${componentSpec.name}");
        var allValues = <ModelBase>[];
        var countDown = 3;
        while (countDown >= 0) {
          var values = await repository.valuesList(privilegeLevel: countDown);
          allValues.addAll(values.map((e) => e!).toList());
          countDown--;
        }

        if (allValues.isNotEmpty) {
          var componentName = componentSpec.name;
          var fullName = "$pluginName-$componentName";
          container.add(ModelDocumentIDsWithInformation(repository, fullName,
              allValues.map((e) => e.documentID).toList()));
        }
      });
    }
  }
  return tasks;
}