Search in sources :

Example 1 with Observable

use of org.activityinfo.observable.Observable in project activityinfo by bedatadriven.

the class LookupViewModel method select.

public void select(LookupKey lookupKey, String keyChoice) {
    Map<LookupKey, String> newSelectedKeys = new HashMap<>();
    for (Map.Entry<LookupKey, Observable<Optional<String>>> entry : selectedKeys.entrySet()) {
        Optional<String> selectedKey = entry.getValue().get();
        if (selectedKey.isPresent()) {
            newSelectedKeys.put(entry.getKey(), selectedKey.get());
        }
    }
    newSelectedKeys.put(lookupKey, keyChoice);
    // Clear the child choices
    clearChildChoices(lookupKey, newSelectedKeys);
    model.updateIfNotEqual(new LookupModel(newSelectedKeys));
}
Also used : LookupModel(org.activityinfo.ui.client.lookup.model.LookupModel) LookupKey(org.activityinfo.model.formTree.LookupKey) Observable(org.activityinfo.observable.Observable)

Example 2 with Observable

use of org.activityinfo.observable.Observable in project activityinfo by bedatadriven.

the class OfflineStore method getCachedMetadata.

/**
 * Try to load a cached FormSchema from the offline store.
 */
public Observable<FormMetadata> getCachedMetadata(ResourceId formId) {
    Observable<FormClass> schema = new ObservableTask<>(new SchemaQuery(database, formId), new FormChangeWatcher(eventBus, change -> change.isFormChanged(formId)));
    Observable<FormMetadataObject> metadata = new ObservableTask<>(new MetadataQuery(database, formId), new FormChangeWatcher(eventBus, change -> change.isFormChanged(formId)));
    return Observable.transform(schema, metadata, (s, m) -> FormMetadata.of(m.getVersion(), s, m.getPermissions()));
}
Also used : ObservableTask(org.activityinfo.ui.client.store.tasks.ObservableTask) FormTreeLoader(org.activityinfo.ui.client.store.FormTreeLoader) java.util(java.util) Json(org.activityinfo.json.Json) ObservableTree(org.activityinfo.observable.ObservableTree) Function2(org.activityinfo.promise.Function2) IDBTransaction(org.activityinfo.indexedb.IDBTransaction) Promise(org.activityinfo.promise.Promise) org.activityinfo.model.form(org.activityinfo.model.form) FormChange(org.activityinfo.ui.client.store.FormChange) Level(java.util.logging.Level) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) OfflineDatabase(org.activityinfo.indexedb.OfflineDatabase) ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef) JsonValue(org.activityinfo.json.JsonValue) RecordUpdate(org.activityinfo.model.resource.RecordUpdate) FormChangeWatcher(org.activityinfo.ui.client.store.http.FormChangeWatcher) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) FormChangeEvent(org.activityinfo.ui.client.store.FormChangeEvent) EventBus(com.google.gwt.event.shared.EventBus) IDBFactory(org.activityinfo.indexedb.IDBFactory) StatefulValue(org.activityinfo.observable.StatefulValue) Logger(java.util.logging.Logger) ObservableTask(org.activityinfo.ui.client.store.tasks.ObservableTask) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) SimpleEventBus(com.google.gwt.event.shared.SimpleEventBus) RecordTransaction(org.activityinfo.model.resource.RecordTransaction) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Observable(org.activityinfo.observable.Observable) Maybe(org.activityinfo.promise.Maybe) FormTree(org.activityinfo.model.formTree.FormTree) FormChangeWatcher(org.activityinfo.ui.client.store.http.FormChangeWatcher)

Example 3 with Observable

use of org.activityinfo.observable.Observable in project activityinfo by bedatadriven.

the class Snapshot method compute.

public static Observable<Snapshot> compute(Observable<Set<ResourceId>> offlineForms, HttpStore httpStore) {
    // We start with the "offlineForm" set which contains the set
    // of forms the user has explicitly asked to cache.
    // In order to find the related forms, we need the complete form trees of each of the
    // selected forms.
    Observable<List<FormTree>> formTrees = flatMap(offlineForms, httpStore::getFormTree);
    // Together, all the related forms constitute the set of forms we need for
    // a complete offline snapshot
    Observable<Set<ResourceId>> completeSet = formTrees.transform(trees -> {
        Set<ResourceId> set = new HashSet<>();
        for (FormTree tree : trees) {
            for (FormMetadata form : tree.getForms()) {
                if (!isBuiltinForm(form.getId())) {
                    set.add(form.getId());
                }
            }
        }
        return set;
    });
    // Now need fetch the latest version numbers of each of these forms
    Observable<List<FormMetadata>> metadata = flatMap(completeSet, httpStore::getFormMetadata);
    // And finally fetch any difference between our current snapshot and the latest version of the new snapshot
    return metadata.join(forms -> {
        List<Observable<FormSyncSet>> recordSets = new ArrayList<>();
        for (FormMetadata form : forms) {
            recordSets.add(httpStore.getVersionRange(form.getId(), 0, form.getVersion()));
        }
        return Observable.flatten(recordSets).transform(x -> new Snapshot(forms, x));
    });
}
Also used : HashSet(java.util.HashSet) FormSyncSet(org.activityinfo.model.form.FormSyncSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Observable(org.activityinfo.observable.Observable) FormMetadata(org.activityinfo.model.form.FormMetadata) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 4 with Observable

use of org.activityinfo.observable.Observable in project activityinfo by bedatadriven.

the class TableViewModel method getEffectiveSubTable.

public Observable<EffectiveTableModel> getEffectiveSubTable(final ResourceId subFormId) {
    Observable<EffectiveTableModel> effectiveSubTable = effectiveSubTables.get(subFormId);
    if (effectiveSubTable == null) {
        final TableModel subModel = ImmutableTableModel.builder().formId(subFormId).build();
        effectiveSubTable = formTree.transform(tree -> tree.subTree(subFormId)).transform(subTree -> new EffectiveTableModel(formStore, subTree, subModel, Optional.of(getSelectedRecordRef())));
        effectiveSubTables.put(subFormId, effectiveSubTable);
    }
    return effectiveSubTable;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) FormSource(org.activityinfo.store.query.shared.FormSource) ParsedFormula(org.activityinfo.analysis.ParsedFormula) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResourceId(org.activityinfo.model.resource.ResourceId) TableModel(org.activityinfo.model.analysis.TableModel) Optional(com.google.common.base.Optional) ColumnModel(org.activityinfo.model.query.ColumnModel) Map(java.util.Map) RecordTree(org.activityinfo.model.formTree.RecordTree) RecordRef(org.activityinfo.model.type.RecordRef) Nullable(javax.annotation.Nullable) SymbolNode(org.activityinfo.model.formula.SymbolNode) Function(com.google.common.base.Function) StatefulValue(org.activityinfo.observable.StatefulValue) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) TableColumn(org.activityinfo.model.analysis.TableColumn) Logger(java.util.logging.Logger) FormulaNode(org.activityinfo.model.formula.FormulaNode) List(java.util.List) ColumnSet(org.activityinfo.model.query.ColumnSet) Observable(org.activityinfo.observable.Observable) ImmutableTableColumn(org.activityinfo.model.analysis.ImmutableTableColumn) FormTree(org.activityinfo.model.formTree.FormTree) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel)

Aggregations

Observable (org.activityinfo.observable.Observable)4 FormTree (org.activityinfo.model.formTree.FormTree)3 ResourceId (org.activityinfo.model.resource.ResourceId)3 Function (com.google.common.base.Function)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Logger (java.util.logging.Logger)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 RecordRef (org.activityinfo.model.type.RecordRef)2 StatefulValue (org.activityinfo.observable.StatefulValue)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 EventBus (com.google.gwt.event.shared.EventBus)1 SimpleEventBus (com.google.gwt.event.shared.SimpleEventBus)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 java.util (java.util)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1